Skip to content

Commit 554a6d9

Browse files
committed
First git release, v2.3.1
0 parents  commit 554a6d9

File tree

483 files changed

+54069
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

483 files changed

+54069
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Debug - Disk
2+
Debug - Steam
3+
Debug - Steam Patched
4+
Release - Disk
5+
Release - Steam
6+
Release - Steam Patched

Miscellaneous.dox

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
///
3+
/// @page miscellaneous Miscellaneous
4+
///
5+
/// This page contains generral information about some objects that are sued globally in the ModAPI.
6+
///
7+
/// @tableofcontents
8+
///
9+
/// @section eastl EASTL, containers and the STL
10+
///
11+
/// In C++, when you want to create a vector, you normally include the <vector.h> class and use a std::vector.
12+
/// In Spore, that is different; Spore uses its own containers included in the EASTL (which is included in the ModAPI).
13+
/// Instead of including <vector.h>, you need to include <EASTL\vector.h>; instead of std::vector, you must use eastl::vector
14+
/// (note that most ModAPI headers have a "using namespace eastl" directive, making the 'eastl::' part unnecessary most of the times).
15+
///
16+
/// @section objects Objects and memory management
17+
///
18+
/// Memory management in C++ can be a bit troubling. Spore and the ModAPI use a method for all its classes known as
19+
/// reference counting. Basically, instead of using naked pointers, like IEffect*, you wrap them into an
20+
/// eastl::intrusive_ptr<IEffect>. Everytime the pointer is assigned, it will increase or decrease the reference count
21+
/// accordingly; when the reference count reaches 0, the object will delete itself.
22+
/// ~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
23+
/// intrusive_ptr<Window> pEffect = new Window();
24+
/// // you don't have to worry about deleting the object
25+
/// ~~~~~~~~~~~~~~~~~~~~~~~
26+
/// Most methods don't take intrusive_ptrs as parameters, but normal pointers. To get the pointer value, use the .get() method:
27+
/// ~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
28+
/// intrusive_ptr<App::PropertyList> pProp;
29+
/// ...
30+
/// bool bValue = false;
31+
/// // The first parameter is an App::PropertyList*
32+
/// App::Property::GetBool(pProp.get(), 0x00B13042, bValue);
33+
/// ~~~~~~~~~~~~~~~~~~~~~~~
34+
/// You must be aware, however, of cyclic intrusion. Imagine that object A has an intrusive_ptr member that points to object B,
35+
/// and object B has an intrusive_ptr member that points to object A. Those objects would never be deleted because they
36+
/// would always have another object pointing to them. Therefore, you must be aware of the structure of your objects when
37+
/// using intrusive_ptrs.
38+
///
39+
/// Most interfaces and classes in the ModAPI declare an AddRef() and Release() method, which are necessary for reference
40+
/// counting and therefore automatic memory management. Some classes have already defined its implementation; sometimes,
41+
/// however, you will have to implement them. Here is a simple example of how they work:
42+
/// ~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
43+
/// // assuming 'MyClass' has an int member called 'mnRefCount', which must be initialized to 0 in the constructor.
44+
/// int AddRef()
45+
/// {
46+
/// mnRefCount++;
47+
/// return mnRefCount;
48+
/// }
49+
/// int Release()
50+
/// {
51+
/// mnRefCount--;
52+
/// if (mnRefCount == 0) delete this;
53+
/// return mnRefCount;
54+
/// }
55+
/// ~~~~~~~~~~~~~~~~~~~~~~~
56+
///
57+
/// The class Object is a standard class that is the base of a lot of classes in the ModAPI. It is reference counted.
58+
/// An interesting thing is the Object::Cast() and object_cast. Dynamic casting is not used in Spore, but this is the alternative.
59+
/// Classes that inherit the Object class define a Cast method which can be used to dynamically cast an object to another type.
60+
/// The Cast method takes an uint32_t as a paramter; that type identifier is a static member called 'TYPE' in most of the
61+
/// classes that support this type of casting. For example:
62+
/// ~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
63+
/// // All mean the same
64+
/// auto pImageDrawable = object_cast<UTFWin::IImageDrawable>(pDrawable);
65+
/// UTFWin::IImageDrawable* pImageDrawable = object_cast<UTFWin::IImageDrawable>(pDrawable);
66+
/// UTFWin::IImageDrawable* pImageDrawable = (UTFWin::IImageDrawable*) pDrawable->Cast(UTFWin::IImageDrawable::TYPE);
67+
/// ~~~~~~~~~~~~~~~~~~~~~~~
68+
/// If 'pDrawable' is of type IImageDrawable, that will be returned; otherwise, Cast must return nullptr. That can be
69+
/// used to check in runtime whether an object is of an specific type.
70+
///
71+
/// Using the "ModAPI Object" item template will create a new Object class that supports casting and reference counting,
72+
/// with a unique TYPE value.
73+
///
74+
/// @section resource_keys IDs and resource keys
75+
///
76+
/// If you look at Spore files, you will always end up seeing something like #4f803d98. That's an hexadecimal integer number;
77+
/// to simplify, we usually call them hashes. They are used to identify files, types, etc, so they are often called IDs as well.
78+
/// Even if you see a normal name, that's just the string representation of an ID. To get the hash ID from a certain name, use the
79+
/// id() function inside the Hash.h header.
80+
/// ~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
81+
/// // We want to get the effect "SG_ufo_scan_HitGround", but we don't know what ID that is.
82+
/// uint32_t effectID = id("SG_ufo_scan_HitGround");
83+
/// ~~~~~~~~~~~~~~~~~~~~~~~
84+
///
85+
/// The ResourceKey class is very common. If you have had a look inside .package files in Spore, you will have noticed
86+
/// that a file always has three things: the name of the file, the extension, and the folder. In technical terms, those
87+
/// are the instance ID, type ID and group ID, respectively. To identify a file, Spore uses the ResourceKey struct,
88+
/// which just contains those three IDs.
89+
///
90+
/// @section math The Math namespace
91+
///
92+
/// The ModAPI contains a namespace called Math with multiple classes that represent mathematical objects such as vectors,
93+
/// matrices and colors. Apart from some specific methods, these are just containers with no functionalities; therefore,
94+
/// you will probably need other libraries in order to make advanced operations with these types.
95+
///
96+
/// @section localization Localization
97+
///
98+
/// Spore supports multiple languages. In order to use localized strings (i.e. text that depends on the current language
99+
/// of the game) you need to use the LocalizedString class in the LocalizedString.h header. Localized texts are identified by
100+
/// a table ID and an instance ID. The table ID is the ID of a .locale file in the locale~ folder, which contains the translation.
101+
/// The instance ID is the specific ID of that translation inside that file.
102+
///

ModAPI.dox

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
///
2+
/// @page modapi ModAPI Utils and the main function
3+
///
4+
/// This page contains information about the utilities contained in the ModAPI and the main function required in the mod.
5+
///
6+
/// @section modapi_tutorial1 Initialization functions
7+
///
8+
/// The ModAPI namespace contains multiple classes and utilities, but most of them are deprecated and should not be used.
9+
/// The only one that can be used (and that can be very useful) are **initialization functions**. Those are functions that are
10+
/// executed after the game starts, when most systems in the game have already been initialized (but the game hasn't opened yet).
11+
///
12+
/// Initialization functions take no arguments and must return a bool value (which is currently ignored; you can interpret it
13+
/// as whether the initialization was correct or not). This is an example:
14+
/// ~~~~~~~~~~~~~~~~~{.cpp}
15+
/// bool CheatInitialization()
16+
/// {
17+
/// App::ICheatManager::Get()->AddCheat("pCheat", new MyCheat());
18+
/// return true;
19+
/// }
20+
/// ~~~~~~~~~~~~~~~~~
21+
///
22+
/// Then you just need to add the initialization function in the DllMain method (more on this later), like this:
23+
/// ~~~~~~~~~~~~~~~~~{.cpp}
24+
/// ModAPI::ModAPIUtils::AddInitFunction(CheatInitialization);
25+
/// ~~~~~~~~~~~~~~~~~
26+
///
27+
/// @section modapi_tutorial2 The main function
28+
///
29+
/// When you create a new mod .dll you should have a dllmain.cpp file that contains the main function of the DLL.
30+
/// This method must contain the DllMain function, which looks something like this:
31+
/// ~~~~~~~~~~~~~~~~~{.cpp}
32+
/// BOOL APIENTRY DllMain( HMODULE hModule,
33+
/// DWORD ul_reason_for_call,
34+
/// LPVOID lpReserved
35+
/// )
36+
/// {
37+
///
38+
/// switch (ul_reason_for_call)
39+
/// {
40+
/// case DLL_PROCESS_ATTACH:
41+
/// // This line is always necessary
42+
/// ModAPI::ModAPIUtils::InitModAPI();
43+
/// // The rest of the code goes here
44+
///
45+
/// case DLL_THREAD_ATTACH:
46+
/// case DLL_THREAD_DETACH:
47+
/// case DLL_PROCESS_DETACH:
48+
/// break;
49+
/// }
50+
/// return TRUE;
51+
/// }
52+
/// ~~~~~~~~~~~~~~~~~
53+
///
54+
/// There's not much you can do in the DllMain function; you must keep in mind that this is executed when the DLL is loaded,
55+
/// and when that happens nothing in Spore has been executed. Therefore, you cannot use any function that uses anything in
56+
/// Spore here; instead, you must use an initialization function like it has been explained before.
57+
///
58+
/// You can only do two things in the DllMain function. You cannot do these things anywhere else:
59+
/// - Add initialization functions.
60+
/// - Detour methods.
61+
///

ModAPI/CompiledStateBuilder.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include "CompiledStateBuilder.h"
2+
3+
using namespace ModAPI;
4+
5+
CompiledStateBuilder::CompiledStateBuilder()
6+
: offset(0), size(0), bufferSize(BUFFER_SIZE)
7+
{
8+
buffer = new char[BUFFER_SIZE];
9+
}
10+
11+
CompiledStateBuilder::~CompiledStateBuilder()
12+
{
13+
delete buffer;
14+
}
15+
16+
int CompiledStateBuilder::GetSize()
17+
{
18+
return size;
19+
}
20+
21+
void CompiledStateBuilder::CopyBuffer(char* dst)
22+
{
23+
memcpy(dst, buffer, size);
24+
}
25+
26+
void CompiledStateBuilder::CheckBufferSize(int extraSize)
27+
{
28+
if (offset + extraSize > bufferSize)
29+
{
30+
bufferSize += BUFFER_SIZE;
31+
char* newBuffer = new char[bufferSize];
32+
33+
CopyBuffer(newBuffer);
34+
delete buffer;
35+
36+
buffer = newBuffer;
37+
}
38+
}
39+
40+
//void CompiledStateBuilder::WriteBool(bool value)
41+
//{
42+
// CheckBufferSize(sizeof(value));
43+
// IncrementSize(sizeof(value));
44+
//
45+
// *(bool*)(buffer + offset) = value;
46+
// offset += sizeof(value);
47+
//}
48+
//
49+
//void CompiledStateBuilder::WriteChar(char value)
50+
//{
51+
// CheckBufferSize(sizeof(value));
52+
// IncrementSize(sizeof(value));
53+
//
54+
// *(char*)(buffer + offset) = value;
55+
// offset += sizeof(value);
56+
//}
57+
//
58+
//void CompiledStateBuilder::WriteShort(short value)
59+
//{
60+
// CheckBufferSize(sizeof(value));
61+
// IncrementSize(sizeof(value));
62+
//
63+
// *(short*)(buffer + offset) = value;
64+
// offset += sizeof(value);
65+
//}
66+
//
67+
//void CompiledStateBuilder::WriteInt(int value)
68+
//{
69+
// CheckBufferSize(sizeof(value));
70+
// IncrementSize(sizeof(value));
71+
//
72+
// *(int*)(buffer + offset) = value;
73+
// offset += sizeof(value);
74+
//}
75+
//
76+
//void CompiledStateBuilder::WriteFloat(float value)
77+
//{
78+
// CheckBufferSize(sizeof(value));
79+
// IncrementSize(sizeof(value));
80+
//
81+
// *(float*)(buffer + offset) = value;
82+
// offset += sizeof(value);
83+
//}
84+
85+
86+
int CompiledStateBuilder::GetOffset()
87+
{
88+
return offset;
89+
}
90+
91+
void CompiledStateBuilder::SetOffset(int offset)
92+
{
93+
this->offset = offset;
94+
}

ModAPI/CompiledStateBuilder.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/****************************************************************************
2+
* Copyright (C) 2019 Eric Mor
3+
*
4+
* This file is part of Spore ModAPI.
5+
*
6+
* Spore ModAPI is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
****************************************************************************/
19+
#pragma once
20+
21+
#include "MaterialConfig.h"
22+
23+
namespace ModAPI
24+
{
25+
class CompiledStateBuilder
26+
{
27+
public:
28+
CompiledStateBuilder();
29+
~CompiledStateBuilder();
30+
31+
/*void WriteBool(bool value);
32+
void WriteChar(char value);
33+
void WriteShort(short value);
34+
void WriteInt(int value);
35+
void WriteFloat(float value);*/
36+
37+
template <typename T>
38+
void Write(T value)
39+
{
40+
CheckBufferSize(sizeof(T));
41+
IncrementSize(sizeof(T));
42+
43+
*(T*)(buffer + offset) = value;
44+
offset += sizeof(T);
45+
}
46+
47+
void CopyBuffer(char* dst);
48+
49+
int GetOffset();
50+
void SetOffset(int offset);
51+
52+
int GetSize();
53+
54+
static const int BUFFER_SIZE = 512;
55+
56+
private:
57+
char* buffer;
58+
int offset;
59+
int size;
60+
int bufferSize;
61+
62+
void CheckBufferSize(int extraSize);
63+
64+
inline void IncrementSize(int extraSize)
65+
{
66+
if (offset == size)
67+
{
68+
size += extraSize;
69+
}
70+
}
71+
};
72+
}

0 commit comments

Comments
 (0)