Skip to content

Commit 753d111

Browse files
authored
Add IO::IniFile stub (#107)
* Add `StreamCompressionZLib.h` include to `Spore/IO.h` * Rename `Stream(De)CompressionZLib::Dispose` to `_dtor` Also fix a "missing" include which broke `ASSERT_SIZE` for both while generating fully valid objects in runtime (triple-checked in x32dbg). * Add `IO::IniFile` stub * Add missing aliases * Remove `IO::_stub` method, a leftover from earlier tests
1 parent 110a82d commit 753d111

8 files changed

Lines changed: 214 additions & 11 deletions

File tree

‎Spore ModAPI/SourceCode/DLL/AddressesIO.cpp‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <Spore\IO\StreamNull.h>
1313
#include <Spore\IO\StreamCompressionZLib.h>
1414
#include <Spore\IO\XmlWriter.h>
15+
#include <Spore\IO\IniFile.h>
1516

1617
namespace Addresses(IO)
1718
{
@@ -243,7 +244,8 @@ namespace IO
243244
DefineAddress(SetCompressionHint, SelectAddress(0x672830, 0x67D2A0));
244245
DefineAddress(Open, SelectAddress(0x672AA0, 0x67D510));
245246
// destructor; private for ModAPI
246-
DefineAddress(Dispose, SelectAddress(0x67DC30, 0x67DAD0));
247+
DefineAddress(_dtor, SelectAddress(0x67DC30, 0x67DAD0));
248+
DefineAddressAlias(Dispose, _dtor);
247249
}
248250

249251
namespace Addresses(StreamDecompressionZLib)
@@ -266,7 +268,38 @@ namespace IO
266268
DefineAddress(SetBufferSize, SelectAddress(0x672960, 0x67D3E0));
267269
DefineAddress(Open, SelectAddress(0x672DC0, 0x67D850));
268270
// destructor; private for ModAPI
269-
DefineAddress(Dispose, SelectAddress(0x67DCE0, 0x67DB80));
271+
DefineAddress(_dtor, SelectAddress(0x67DCE0, 0x67DB80));
272+
DefineAddressAlias(Dispose, _dtor);
273+
}
274+
275+
namespace Addresses(IniFile)
276+
{
277+
DefineAddress(GetOption, SelectAddress(0x90c410, 0x932fc0));
278+
DefineAddress(SetOption, SelectAddress(0x90c430, 0x932fe0));
279+
DefineAddress(GetPath, SelectAddress(0x959f70, 0x6e6560));
280+
DefineAddress(SetPath, SelectAddress(0x90c460, 0x933010));
281+
DefineAddress(GetStream, SelectAddress(0x90c4d0, 0x933080));
282+
DefineAddress(SetStream, SelectAddress(0x90c4e0, 0x933090));
283+
DefineAddress(Close, SelectAddress(0x90e5a0, 0x934ff0));
284+
DefineAddress(ReadEntry, SelectAddress(0x90cc10, 0x933820));
285+
DefineAddress(ReadEntryToBuffer, SelectAddress(0x90d410, 0x933eb0));
286+
DefineAddress(ReadEntryFormatted, SelectAddress(0x90cca0, 0x9338b0));
287+
DefineAddress(WriteEntry, SelectAddress(0x90d9d0, 0x934420));
288+
DefineAddress(WriteEntryFormatted, SelectAddress(0x90c810, 0x9333c0));
289+
DefineAddress(ReadBinary, SelectAddress(0x90c8f0, 0x9334a0));
290+
DefineAddress(WriteBinary, SelectAddress(0x90ca60, 0x933610));
291+
DefineAddress(EnumSections, SelectAddress(0x90e220, 0x934c70));
292+
DefineAddress(EnumEntries, SelectAddress(0x90ea80, 0x9354d0));
293+
DefineAddress(SectionExists, SelectAddress(0x90d6d0, 0x934170));
294+
DefineAddress(Open, SelectAddress(0x90c540, 0x9330f0));
295+
DefineAddress(GetEncoding, SelectAddress(0x90c670, 0x933220));
296+
DefineAddress(LoadSectionNames, SelectAddress(0x90e610, 0x935060));
297+
DefineAddress(GetFileLine8To8, SelectAddress(0x90cfb0, 0x933b40));
298+
DefineAddress(GetFileLine16To16, SelectAddress(0x90d0c0, 0x933c50));
299+
DefineAddress(GetFileLine, SelectAddress(0x90cdc0, 0x933950));
300+
DefineAddress(ConvertAndWriteStream, SelectAddress(0x90cb20, 0x9336d0));
301+
// stub
302+
DefineAddress(_vftable, SelectAddress(0x1407fc8, 0x143e980));
270303
}
271304
}
272305
#endif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#ifndef MODAPI_DLL_EXPORT
2+
3+
#include <Spore\IO\IniFile.h>
4+
5+
namespace IO
6+
{
7+
IniFile::IniFile(const wchar_t* pPath, int optionFlags)
8+
: mFileStream((char*)nullptr)
9+
, mpStream(nullptr)
10+
, mnEncodingSrc(8)
11+
, mbFileIsOpenForWriting(false)
12+
, mbReadEntryCacheReady(false)
13+
, mbLeaveFileOpenBetweenOperations(optionFlags & 1)
14+
, mSectionPositionMap()
15+
, mSectionNameMap()
16+
{
17+
*(void**)this = (void*)GetAddress(IniFile, _vftable);
18+
mPath[0] = L'\0';
19+
IniFile::SetPath(pPath);
20+
}
21+
22+
IniFile::IniFile(IStream* pStream)
23+
: mFileStream((char*)nullptr)
24+
, mnEncodingSrc(8)
25+
, mbFileIsOpenForWriting(false)
26+
, mbReadEntryCacheReady(false)
27+
, mbLeaveFileOpenBetweenOperations(true)
28+
, mSectionPositionMap()
29+
, mSectionNameMap()
30+
, mpStream(pStream)
31+
{
32+
*(void**)this = (void*)GetAddress(IniFile, _vftable);
33+
mPath[0] = L'\0';
34+
}
35+
36+
auto_METHOD_VIRTUAL_const(IniFile, IniFile, int, GetOption, Args(Options option), Args(option));
37+
auto_METHOD_VIRTUAL_VOID(IniFile, IniFile, SetOption, Args(Options option, int value), Args(option, value));
38+
auto_METHOD_VIRTUAL_const_(IniFile, IniFile, wchar_t const*, GetPath);
39+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, SetPath, Args(const wchar_t* pPath), Args(pPath));
40+
auto_METHOD_VIRTUAL_const_(IniFile, IniFile, IStream*, GetStream);
41+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, SetStream, Args(IStream* pStream), Args(pStream));
42+
auto_METHOD_VIRTUAL_(IniFile, IniFile, bool, Close);
43+
auto_METHOD_VIRTUAL(IniFile, IniFile, int, ReadEntry, Args(const wchar_t* pSection, const wchar_t* pKey, eastl::basic_string<wchar_t>& sValue), Args(pSection, pKey, sValue));
44+
auto_METHOD_VIRTUAL(IniFile, IniFile, int, ReadEntryToBuffer, Args(const wchar_t* pSection, const wchar_t* pKey, wchar_t* pValue, uint32_t nValueLength), Args(pSection, pKey, pValue, nValueLength));
45+
// Stub, do not detour.
46+
int __cdecl IniFile::ReadEntryFormatted(const wchar_t* pSection, const wchar_t* pKey, const wchar_t* pValueFormat, ...) { return 0; }
47+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, WriteEntry, Args(const wchar_t* pSection, const wchar_t* pKey, const wchar_t* pValue), Args(pSection, pKey, pValue));
48+
// Stub, do not detour.
49+
bool __cdecl IniFile::WriteEntryFormatted(const wchar_t* pSection, const wchar_t* pKey, const wchar_t* kValueFormat, ...) { return 0; }
50+
auto_METHOD_VIRTUAL(IniFile, IniFile, int, ReadBinary, Args(const wchar_t* pSection, const wchar_t* pKey, void* pData, uint32_t nDataLength), Args(pSection, pKey, pData, nDataLength));
51+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, WriteBinary, Args(const wchar_t* pSection, const wchar_t* pKey, const void* pData, uint32_t nDataLength), Args(pSection, pKey, pData, nDataLength));
52+
auto_METHOD_VIRTUAL(IniFile, IniFile, int, EnumSections, Args(EnumCallback_t pCallback, void* pContext), Args(pCallback, pContext));
53+
auto_METHOD_VIRTUAL(IniFile, IniFile, int, EnumEntries, Args(const wchar_t* pSection, EnumCallback_t pCallback, void* pContext), Args(pSection, pCallback, pContext));
54+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, SectionExists, Args(const wchar_t* pSection), Args(pSection));
55+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, Open, Args(int nAccessFlags), Args(nAccessFlags));
56+
auto_METHOD_VIRTUAL_(IniFile, IniFile, int, GetEncoding);
57+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, LoadSectionNames, Args(int nAccessFlags), Args(nAccessFlags));
58+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, GetFileLine8To8, Args(eastl::basic_string<char>& sLine), Args(sLine));
59+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, GetFileLine16To16, Args(eastl::basic_string<wchar_t>& sLine), Args(sLine));
60+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, GetFileLine, Args(eastl::basic_string<wchar_t>& sLine), Args(sLine));
61+
auto_METHOD_VIRTUAL(IniFile, IniFile, bool, ConvertAndWriteStream, Args(const wchar_t* pchar, uint32_t count), Args(pchar, count));
62+
}
63+
64+
#endif

‎Spore ModAPI/SourceCode/IO/StreamDefinitions.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ namespace IO
418418

419419
StreamCompressionZLib::~StreamCompressionZLib()
420420
{
421-
Dispose();
421+
_dtor();
422422
}
423423

424424
auto_METHOD_(StreamCompressionZLib, int, AddRef);
@@ -446,7 +446,7 @@ namespace IO
446446
auto_METHOD(StreamCompressionZLib, bool, Open, Args(IStream* pOutputStream, int nHint), Args(pOutputStream, nHint));
447447

448448
// destructor, private for ModAPI
449-
auto_METHOD_VOID_(StreamCompressionZLib, Dispose);
449+
auto_METHOD_VOID_(StreamCompressionZLib, _dtor);
450450

451451
StreamDecompressionZLib::StreamDecompressionZLib(IStream* pInputStream)
452452
: mpInputStream(NULL),
@@ -461,7 +461,7 @@ namespace IO
461461

462462
StreamDecompressionZLib::~StreamDecompressionZLib()
463463
{
464-
Dispose();
464+
_dtor();
465465
}
466466

467467
auto_METHOD_(StreamDecompressionZLib, int, AddRef);
@@ -488,7 +488,7 @@ namespace IO
488488
auto_METHOD(StreamDecompressionZLib, bool, Open, Args(IStream* pInputStream), Args(pInputStream));
489489

490490
// destructor, private for ModAPI
491-
auto_METHOD_VOID_(StreamDecompressionZLib, Dispose);
491+
auto_METHOD_VOID_(StreamDecompressionZLib, _dtor);
492492

493493
/////////////////////////////////
494494

‎Spore ModAPI/Spore ModAPI.vcxproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@
330330
<ClInclude Include="Spore\Editors\cSPEditorVerbTrayCollection.h" />
331331
<ClInclude Include="Spore\Editors\cSPEditorVerbIcon.h" />
332332
<ClInclude Include="Spore\Editors\cSPEditorVerbIconTray.h" />
333+
<ClInclude Include="Spore\IO\IniFile.h" />
333334
<ClInclude Include="Spore\IO\StreamCompressionZLib.h" />
334335
<ClInclude Include="Spore\UI\cSPUIPropertyLayout.h" />
335336
<ClInclude Include="Spore\Editors\cSPVerbIconRollover.h" />
@@ -1014,6 +1015,7 @@
10141015
<ClCompile Include="SourceCode\Graphics\ThumbnailManager.cpp" />
10151016
<ClCompile Include="SourceCode\Graphics\RenderTargets.cpp" />
10161017
<ClCompile Include="SourceCode\Graphics\GeneratedMesh.cpp" />
1018+
<ClCompile Include="SourceCode\IO\IniFile.cpp" />
10171019
<ClCompile Include="SourceCode\OpenSSL.cpp" />
10181020
<ClCompile Include="SourceCode\Pollinator\Pollinator.cpp" />
10191021
<ClCompile Include="SourceCode\RenderWare\Raster.cpp" />

‎Spore ModAPI/Spore ModAPI.vcxproj.filters‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,9 @@
22892289
<ClInclude Include="Spore\IO\StreamCompressionZLib.h">
22902290
<Filter>Header Files</Filter>
22912291
</ClInclude>
2292+
<ClInclude Include="Spore\IO\IniFile.h">
2293+
<Filter>Header Files</Filter>
2294+
</ClInclude>
22922295
</ItemGroup>
22932296
<ItemGroup>
22942297
<ClCompile Include="SourceCode\Allocator.cpp">
@@ -2783,6 +2786,9 @@
27832786
<ClCompile Include="SourceCode\UI\cSPUIPropertyLayout.cpp">
27842787
<Filter>Source Files</Filter>
27852788
</ClCompile>
2789+
<ClCompile Include="SourceCode\IO\IniFile.cpp">
2790+
<Filter>Source Files</Filter>
2791+
</ClCompile>
27862792
</ItemGroup>
27872793
<ItemGroup>
27882794
<Natvis Include="EASTL.natvis" />

‎Spore ModAPI/Spore/IO.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <Spore\IO\StreamFixedMemory.h>
4444
#include <Spore\IO\StreamMemory.h>
4545
#include <Spore\IO\StreamNull.h>
46+
#include <Spore\IO\StreamCompressionZLib.h>
4647
#include <Spore\IO\XmlWriter.h>
4748

4849
/// @namespace IO

‎Spore ModAPI/Spore/IO/IniFile.h‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#pragma once
2+
3+
#include <EASTL\map.h>
4+
#include "FileStream.h"
5+
6+
namespace IO
7+
{
8+
///
9+
/// A class that is used to read, parse, and write INI configuration files.
10+
/// Stub, do not detour.
11+
///
12+
class IniFile
13+
{
14+
public:
15+
enum Options
16+
{
17+
kOptionNone,
18+
kOptionLeaveFileOpen
19+
};
20+
21+
typedef bool(*EnumCallback_t)(wchar_t*, wchar_t*, void*);
22+
23+
IniFile(const wchar_t* pPath, int optionFlags);
24+
IniFile(IStream* pStream);
25+
26+
/* 00h */ virtual ~IniFile() final = default;
27+
/* 04h */ virtual int GetOption(Options option) const;
28+
/* 08h */ virtual void SetOption(Options option, int value);
29+
/* 0Ch */ virtual wchar_t const* GetPath() const;
30+
/* 10h */ virtual bool SetPath(const wchar_t* pPath);
31+
/* 14h */ virtual class IStream* GetStream() const;
32+
/* 18h */ virtual bool SetStream(IStream* pStream);
33+
/* 1Ch */ virtual bool Close();
34+
/* 20h */ virtual int ReadEntry(const wchar_t* pSection, const wchar_t* pKey, class eastl::basic_string<wchar_t>& sValue);
35+
/* 24h */ virtual int ReadEntryToBuffer(const wchar_t* pSection, const wchar_t* pKey, wchar_t* pValue, uint32_t nValueLength);
36+
// Stub, do not detour.
37+
/* 28h */ virtual int ReadEntryFormatted(const wchar_t* pSection, const wchar_t* pKey, const wchar_t* pValueFormat, ...);
38+
/* 2Ch */ virtual bool WriteEntry(const wchar_t* pSection, const wchar_t* pKey, const wchar_t* pValue);
39+
// Stub, do not detour.
40+
/* 30h */ virtual bool WriteEntryFormatted(const wchar_t* pSection, const wchar_t* pKey, const wchar_t* kValueFormat, ...);
41+
/* 34h */ virtual int ReadBinary(const wchar_t* pSection, const wchar_t* pKey, void* pData, uint32_t nDataLength);
42+
/* 38h */ virtual bool WriteBinary(const wchar_t* pSection, const wchar_t* pKey, const void* pData, uint32_t nDataLength);
43+
/* 3Ch */ virtual int EnumSections(EnumCallback_t pCallback, void* pContext);
44+
/* 40h */ virtual int EnumEntries(const wchar_t* pSection, EnumCallback_t pCallback, void* pContext);
45+
/* 44h */ virtual bool SectionExists(const wchar_t* pSection);
46+
protected:
47+
/* 48h */ virtual bool Open(int nAccessFlags);
48+
/* 4Ch */ virtual int GetEncoding();
49+
/* 50h */ virtual bool LoadSectionNames(int nAccessFlags);
50+
/* 54h */ virtual bool GetFileLine8To8(class eastl::basic_string<char>& sLine);
51+
/* 58h */ virtual bool GetFileLine16To16(class eastl::basic_string<wchar_t>& sLine);
52+
/* 5Ch */ virtual bool GetFileLine(class eastl::basic_string<wchar_t>& sLine);
53+
/* 60h */ virtual bool ConvertAndWriteStream(const wchar_t* pchar, uint32_t count);
54+
55+
/* 04h */ wchar_t mPath[260];
56+
/* 20Ch */ FileStream mFileStream;
57+
/* 438h */ IStream* mpStream;
58+
/* 43Ch */ int mnEncodingSrc;
59+
/* 440h */ bool mbFileIsOpenForWriting;
60+
/* 441h */ bool mbLeaveFileOpenBetweenOperations;
61+
/* 442h */ bool mbReadEntryCacheReady;
62+
/* 444h */ eastl::map<eastl::basic_string<wchar_t>, long, eastl::less<eastl::basic_string<wchar_t>>> mSectionPositionMap;
63+
/* 460h */ eastl::map<eastl::basic_string<wchar_t>, eastl::basic_string<wchar_t>, eastl::less<eastl::basic_string<wchar_t>>> mSectionNameMap;
64+
};
65+
ASSERT_SIZE(IniFile, 0x47C);
66+
67+
namespace Addresses(IniFile)
68+
{
69+
DeclareAddress(GetOption);
70+
DeclareAddress(SetOption);
71+
DeclareAddress(GetPath);
72+
DeclareAddress(SetPath);
73+
DeclareAddress(GetStream);
74+
DeclareAddress(SetStream);
75+
DeclareAddress(Close);
76+
DeclareAddress(ReadEntry);
77+
DeclareAddress(ReadEntryToBuffer);
78+
DeclareAddress(ReadEntryFormatted);
79+
DeclareAddress(WriteEntry);
80+
DeclareAddress(WriteEntryFormatted);
81+
DeclareAddress(ReadBinary);
82+
DeclareAddress(WriteBinary);
83+
DeclareAddress(EnumSections);
84+
DeclareAddress(EnumEntries);
85+
DeclareAddress(SectionExists);
86+
DeclareAddress(Open);
87+
DeclareAddress(GetEncoding);
88+
DeclareAddress(LoadSectionNames);
89+
DeclareAddress(GetFileLine8To8);
90+
DeclareAddress(GetFileLine16To16);
91+
DeclareAddress(GetFileLine);
92+
DeclareAddress(ConvertAndWriteStream);
93+
// stub
94+
DeclareAddress(_vftable);
95+
}
96+
}

‎Spore ModAPI/Spore/IO/StreamCompressionZLib.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

3-
#include <Spore\IO\IStream.h>
3+
#include "IStream.h"
4+
#include <Spore/Object.h>
45

56
#define StreamCompressionZLibPtr eastl::intrusive_ptr<IO::StreamCompressionZLib>
67
#define StreamDecompressionZLibPtr eastl::intrusive_ptr<IO::StreamDecompressionZLib>
@@ -68,7 +69,7 @@ namespace IO
6869
/* 2Ch */ size_t mInputSize;
6970
// destructor, private for ModAPI
7071
private:
71-
virtual void Dispose();
72+
virtual void _dtor();
7273
};
7374
ASSERT_SIZE(StreamCompressionZLib, 0x30);
7475

@@ -93,7 +94,7 @@ namespace IO
9394
DeclareAddress(SetCompressionHint);
9495
DeclareAddress(Open);
9596
// destructor, private for ModAPI
96-
DeclareAddress(Dispose);
97+
DeclareAddress(_dtor);
9798
}
9899

99100
class StreamDecompressionZLib : public IStream, public RefCountTemplateAtomic
@@ -140,7 +141,7 @@ namespace IO
140141
/* 20h */ size_t mnInputBufferSize;
141142
// destructor, private for ModAPI
142143
private:
143-
virtual void Dispose();
144+
virtual void _dtor();
144145
};
145146
ASSERT_SIZE(StreamDecompressionZLib, 0x24);
146147

@@ -164,6 +165,6 @@ namespace IO
164165
DeclareAddress(SetBufferSize);
165166
DeclareAddress(Open);
166167
// destructor, private for ModAPI
167-
DeclareAddress(Dispose);
168+
DeclareAddress(_dtor);
168169
}
169170
}

0 commit comments

Comments
 (0)