Skip to content

Commit

Permalink
properly remove Adventures101 mission by using a detour
Browse files Browse the repository at this point in the history
This fixes the mission popping up at your own empire.
The way we 'remove' it is by setting it to 'completed' before allowing
the game to choose a mission.

Thanks a lot to @emd4600 for all the help!
  • Loading branch information
Rosalie241 committed Jul 16, 2022
1 parent fe0b610 commit 92c5baa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 53 deletions.
79 changes: 27 additions & 52 deletions SporeNoMoreAdventures/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

#include <Windows.h>

using namespace Simulator;

//
// Helper functions
// Helper Functions
//

static void DisplayError(const char* fmt, ...)
Expand All @@ -31,68 +33,39 @@ static void DisplayError(const char* fmt, ...)
}

//
// Exported Functions
// Detoured Functions
//

void Initialize()
class cMissionManager
{
BOOL ret;
DWORD_PTR address = (DWORD_PTR)GetModuleHandle(nullptr) + 0xBEEDA2;

SIZE_T bytesWritten = 0;
SIZE_T bytesRead = 0;
const SIZE_T bytesSize = 31;
BYTE readBytes[bytesSize] = { 0 };
BYTE originalBytes[] =
{
0x8B, 0x44, 0x24, 0x40, 0x53, 0x55, 0x50, 0x68, 0xAC, 0x7F,
0xB5, 0x2A, 0x8B, 0xCE, 0xE8, 0x6B, 0xD6, 0xFF, 0xFF, 0x89,
0x44, 0x24, 0x14, 0x3B, 0xC3, 0x0F, 0x85, 0xF7, 0x01, 0x00,
0x00
};
BYTE replacementBytes[] =
{
0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
0x90
};

ret = ReadProcessMemory(GetCurrentProcess(), (LPVOID)address, readBytes, bytesSize, &bytesRead);
if (!ret)
{
DisplayError("ReadProcessMemory() Failed!");
return;
}
public:
// padding
int m1; int m2; int m3; int m4; int m5; int m6; int m7; int m8; int m9; int m10;
int m11; int m12; int m13; int m14; int m15; int m16; int m17; int m18; int m19;
int m20; int m21; int m22; int m23;

if (bytesRead != bytesSize)
{
DisplayError("bytesRead != bytesSize");
return;
}
// 0x5C
eastl::map<uint32_t, int> m_missionMap;
};

// make sure we aren't replacing random bytes,
// but the original bytes we expect
if (memcmp(readBytes, originalBytes, bytesSize) != 0)
member_detour(ChooseMissionFunctionDetour, cMissionManager, cMission*(cEmpire*, cPlanetRecord*))
{
cMission* detoured(cEmpire* cEmpire, cPlanetRecord* cPlanetRecord)
{
DisplayError("bytes don't match! Are you running a supported version of Spore?");
return;
}
// set mission Adventures101 to completed
m_missionMap[0x2AB57FAC] = 1;

ret = WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, replacementBytes, bytesSize, &bytesWritten);
if (!ret)
{
DisplayError("WriteProcessMemory() Failed!");
return;
return original_function(this, cEmpire, cPlanetRecord);
}
};

if (bytesWritten != bytesSize)
{
DisplayError("bytesWritten != sizeof(bytes)");
return;
}

//
// Exported Functions
//

void Initialize()
{
// This method is executed when the game starts, before the user interface is shown
// Here you can do things such as:
// - Add new cheats
Expand All @@ -109,6 +82,8 @@ void Dispose()

void AttachDetours()
{
ChooseMissionFunctionDetour::attach(Address(ModAPI::ChooseAddress(0xFEF450, 0xFEEBC0)));

// Call the attach() method on any detours you want to add
// For example: cViewer_SetRenderType_detour::attach(GetAddress(cViewer, SetRenderType));
}
Expand Down
3 changes: 2 additions & 1 deletion SporeNoMoreAdventures/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
// TODO: reference additional headers your program requires here

// This is used everywhere
#include <Spore\BasicIncludes.h>
#include <Spore\BasicIncludes.h>
#include <Spore\Simulator\cMission.h>

0 comments on commit 92c5baa

Please sign in to comment.