Skip to content

Commit 8a04a69

Browse files
authored
Added StateManager (#56)
1 parent 8eaa436 commit 8a04a69

File tree

9 files changed

+105
-33
lines changed

9 files changed

+105
-33
lines changed

Spore ModAPI/SourceCode/App/App.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <Spore\App\cSporeApp.h>
88
#include <Spore\App\cArithmeticaResource.h>
99
#include <Spore\App\ConfigManager.h>
10+
#include <Spore\App\IStateManager.h>
1011
#endif
1112
#include <Spore\App\CommandLine.h>
1213

@@ -80,8 +81,14 @@ namespace App
8081
{
8182
return *(PropertyList**)GetAddress(App, sPreferencesPropList);
8283
}
84+
85+
//// StateManager ////
86+
87+
auto_STATIC_METHOD_(IStateManager, IStateManager*, Get);
88+
8389
#endif
8490

91+
8592
auto_METHOD(CommandLine, eastl::string16&, Get, Args(int i), Args(i));
8693

8794
auto_METHOD(CommandLine, int, FindSwitch,
@@ -91,4 +98,4 @@ namespace App
9198
CommandLine* GetAppCommandLine() {
9299
return *(CommandLine**)GetAddress(App, sAppCommandLine);
93100
}
94-
}
101+
}

Spore ModAPI/SourceCode/DLL/AddressesApp.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <Spore\App\JobManager.h>
2121
#include <Spore\App\cJob.h>
2222
#include <Spore\App\cMouseCamera.h>
23-
//#include <Spore\App\IStateManager.h>
23+
#include <Spore\App\IStateManager.h>
2424
#include <Spore\App\Property.h>
2525
#include <Spore\App\PropertyList.h>
2626
#include <Spore\App\ScenarioMode.h>
@@ -596,6 +596,10 @@ namespace App
596596
{
597597
DefineAddress(Get, SelectAddress(0x67DE50, 0x67DCF0));
598598
}
599+
600+
namespace Addresses(IStateManager) {
601+
DefineAddress(Get, SelectAddress(0x67DE40, 0x67DCE0));
602+
}
599603
}
600604

601605
namespace Addresses(App)

Spore ModAPI/Spore/App/IGameModeManager.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ namespace App
4242
/// Called when the current mode is exited. The message data is the App::OnModeExitMessage class.
4343
kMsgOnModeExit = 0x212D3E7,
4444
/// Called after the current mode is entered. The message data is the App::OnModeEnterMessage class.
45-
kMsgOnModeEnter = 0x22D1ADC
45+
kMsgOnModeEnter = 0x22D1ADC,
46+
// Changes the current game mode. The message data is the App::SetGameModeMessage class.
47+
kMsgSetGameModeByName = 0xE11333,
48+
49+
// 0xD3C602
4650
};
4751

4852
// not public, so user can't access the fields
@@ -78,6 +82,22 @@ namespace App
7882
}
7983
};
8084

85+
class SetGameModeMessage : StandardMessage
86+
{
87+
public:
88+
static const uint32_t ID = kMsgSetGameModeByName;
89+
90+
inline SetGameModeMessage(const char* gameModeName)
91+
{
92+
id = ID;
93+
SetString(0, gameModeName);
94+
}
95+
96+
inline const eastl::string& GetGameModeName() {
97+
return params[0].str->value;
98+
}
99+
};
100+
81101
///
82102
/// A manager that takes care of game modes; check IGameMode for more information.
83103
/// The manager has a vector with all the modes and keeps track of the active mode.
Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
#pragma once
22

3-
//#error "Not supported yet"
4-
//
5-
//#include <Spore\Internal.h>
6-
//
7-
//namespace App
8-
//{
9-
// //TODO PLACEHOLDER, ctor at loc_7E56F0
10-
// class IStateManager
11-
// {
12-
// public:
13-
// static IStateManager* Get();
14-
// };
15-
//
16-
// inline IStateManager* StateManager() {
17-
// return IStateManager::Get();
18-
// }
19-
//
20-
// namespace Addresses(IStateManager) {
21-
// DeclareAddress(Get);
22-
// }
23-
//}
3+
#include <Spore\Object.h>
4+
#include <Spore\App\CommandLine.h>
5+
#include <EASTL\vector.h>
6+
7+
#define StateManager (*App::IStateManager::Get())
8+
9+
namespace App
10+
{
11+
class IStateManager
12+
: public Object
13+
{
14+
public:
15+
static const uint32_t TYPE = 0xBE9741;
16+
17+
static IStateManager* Get();
18+
19+
/* 10h */ virtual bool Init(const char* cheatName) = 0;
20+
/* 14h */ virtual bool Shutdown() = 0;
21+
/* 18h */ virtual void Update() = 0;
22+
/* 1Ch */ virtual bool LoadConfigFile(uint32_t instanceID, uint32_t groupID, App::CommandLine* commandLine, bool) = 0;
23+
/* 20h */ virtual bool LoadConfigFileFromDisk(const char16_t* path, App::CommandLine* commandLine, bool) = 0;
24+
/* 24h */ virtual bool IsValidState(uint32_t stateID) = 0;
25+
/* 28h */ virtual bool SwitchToState(uint32_t stateID) = 0;
26+
/// Always returns 0!!
27+
/* 2Ch */ virtual uint32_t CurrentState() = 0;
28+
/* 30h */ virtual const eastl::vector<uint32_t>& PreviousStates() = 0;
29+
/* 34h */ virtual bool StateOccurredPreviously(uint32_t stateID) = 0;
30+
/* 38h */ virtual uint32_t StateIDFromName(const char* name) = 0;
31+
/* 3Ch */ virtual const char* CurrentStateName() = 0;
32+
/* 40h */ virtual bool ResetToDefaultState() = 0;
33+
};
34+
35+
namespace Addresses(IStateManager) {
36+
DeclareAddress(Get); // 0x67DE40 0x67DCE0
37+
}
38+
}

Spore ModAPI/Spore/App/StandardMessage.h

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,23 @@
2121

2222
#include <Spore\Object.h>
2323
#include <cinttypes>
24+
#include <EASTL\string.h>
25+
26+
#define RefCountedStringPtr eastl::intrusive_ptr<App::RefCountedString>
2427

2528
namespace App
2629
{
27-
class StandardMessage : public MultithreadObject
30+
class RefCountedString
31+
: public DefaultRefCounted
32+
{
33+
public:
34+
inline RefCountedString(const char* str) : value(str) {}
35+
36+
eastl::string value;
37+
};
38+
39+
class StandardMessage
40+
: public MultithreadObject
2841
{
2942
public:
3043
union MessageParameter
@@ -42,6 +55,7 @@ namespace App
4255
double _double;
4356
Object* object;
4457
void* ptr;
58+
RefCountedString* str;
4559
};
4660

4761
StandardMessage();
@@ -53,13 +67,23 @@ namespace App
5367
/* 38h */ uint32_t objectFlags;
5468
/* 3Ch */ int field_3C;
5569

56-
void SetObject(size_t nIndex, Object* pObject);
70+
void SetObject(size_t index, Object* object);
71+
72+
void SetString(size_t index, const char* str);
5773
};
5874

59-
inline void StandardMessage::SetObject(size_t nIndex, Object* pObject)
75+
inline void StandardMessage::SetObject(size_t index, Object* object)
6076
{
61-
params[nIndex].object = pObject;
62-
objectFlags |= (1 << nIndex);
63-
if (pObject) pObject->AddRef();
77+
if ((objectFlags & (1 >> index)) && params[index].object) {
78+
params[index].object->Release();
79+
}
80+
params[index].object = object;
81+
objectFlags |= (1 << index);
82+
if (object) object->AddRef();
6483
}
84+
85+
inline void StandardMessage::SetString(size_t index, const char* str)
86+
{
87+
SetObject(index, (Object*)new RefCountedString(str));
88+
; }
6589
}

Spore ModAPI/Spore/BasicIncludes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <Spore\App\cSporeApp.h>
4545
#include <Spore\App\cArithmeticaResource.h>
4646
#include <Spore\App\ConfigManager.h>
47+
#include <Spore\App\IStateManager.h>
4748

4849
#include <Spore\Audio\AudioSystem.h>
4950

Spore ModAPI/Spore/Simulator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <Spore\Simulator\SubSystem\PlantSpeciesManager.h>
3535
#include <Spore\Simulator\SubSystem\AnimalSpeciesManager.h>
3636
#include <Spore\Simulator\SubSystem\SpaceGfx.h>
37+
#include <Spore\Simulator\SubSystem\SpaceTrading.h>
3738

3839
#include <Spore\Simulator\cGameData.h>
3940
#include <Spore\Simulator\cGonzagoSimulator.h>

Spore ModAPI/Spore/Simulator/SimulatorEnums.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ namespace Simulator
330330
/// Space tools in `spacetools~` (`0x30608F0B`) group
331331
Tool = 2,
332332
CargoSlot = 3,
333-
/// Objects in `spacetrading~` (`0x34D97FA`) group
333+
/// Objects in `spacetrading~` (`0x34D97FA`, GroupIDs::SpaceTrading_) group
334334
TradingObject = 4,
335335
/// Objects in `multiDelivery_mision_objects~` (`0x037D494E`) group
336336
MultiDeliveryObject = 5,

Spore ModAPI/Spore/Simulator/cSpaceInventoryItem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ namespace Simulator
8787
/// @param instanceIDcddc
8888
static void CreateMultiDeliveryObject(cSpaceInventoryItemPtr& dst, const ResourceKey& itemID, uint32_t instanceID);
8989

90-
/// Creates a trading object, which is an inventory item from GroupIDs::SpaceTrading.
90+
/// Creates a trading object, which is an inventory item from GroupIDs::SpaceTrading_.
9191
/// @param[out] dst Pointer where the new object will be written.
92-
/// @param itemID Key to the item configuration in GroupIDs::SpaceTrading
92+
/// @param itemID Key to the item configuration in GroupIDs::SpaceTrading_
9393
/// @param itemCount Number of items to create
9494
/// @param itemCost Cost of the object
9595
static void CreateTradingObject(cSpaceInventoryItemPtr& dst, const ResourceKey& itemID, int itemCount, float itemCost);

0 commit comments

Comments
 (0)