Skip to content

Commit

Permalink
Retain /players # across games and loads
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishimura-Katsuo committed Sep 23, 2020
1 parent 35b4404 commit 7efe264
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion features/ExperienceMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ REMOTEREF(DWORD, PlayerCountOverride, 0x883d70);

void __fastcall SetPlayerCount(DWORD count) {
PlayerCountOverride = count > 1 ? count : 1;
gamelog << "Difficulty (players) set to " << count << std::endl;
gamelog << "Difficulty (players) set to " << count << " and saved." << std::endl;
Settings["PlayerCountOverride"] = PlayerCountOverride;
SaveSettings();
}

int __fastcall ExperienceHook(int exp) {
Expand All @@ -25,6 +27,7 @@ int __fastcall ExperienceHook(int exp) {
namespace ExperienceMod {

class : public Feature {
bool ingame = false;
public:
void init() {
// Rewrite players count modification and leave to our handler - 42 bytes total
Expand All @@ -36,6 +39,32 @@ namespace ExperienceMod {
<< NOP_TO(0x47c50e);

MemoryPatch(0x57e501) << ASM::MOV_ECX_EAX << ASM::MOV_ECX_EAX << CALL(ExperienceHook) << BYTESEQ{ 0xc2, 0x08, 0x00 };

AutomapInfoHooks.push_back([]() -> std::wstring {
wchar_t ret[256] = L"Players 1";

if (PlayerCountOverride > 1) {
swprintf_s(ret, L"Players %d", PlayerCountOverride);
}

return ret;
});
}

void gameLoop() {
if (!ingame || PlayerCountOverride != Settings["PlayerCountOverride"]) {
PlayerCountOverride = Settings["PlayerCountOverride"];

if (PlayerCountOverride > 1) {
gamelog << "Difficulty (players) set to " << PlayerCountOverride << "." << std::endl;
}
}

ingame = true;
}

void oogLoop() {
ingame = false;
}
} feature;

Expand Down
2 changes: 1 addition & 1 deletion features/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class : public Feature {

AutomapInfoHooks.push_back([]() -> std::wstring {
return version;
});
});

AutomapInfoHooks.push_back([]() -> std::wstring {
DWORD elapsed = GetTickCount() - gamestart, seconds = (elapsed / 1000) % 60, minutes = (elapsed / 60000) % 60;
Expand Down

0 comments on commit 7efe264

Please sign in to comment.