Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP S&L and AutoSave #24

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Ext/Event/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "Body.h"
#include <Spawner/ProtocolZero.h>
#include <Spawner/Spawner.h>

#include <Helpers/Macro.h>
#include <EventClass.h>
Expand All @@ -35,6 +36,9 @@ void EventExt::RespondEvent()
case EventTypeExt::ResponseTime2:
ProtocolZero::HandleResponseTime2(this);
break;
case EventTypeExt::SaveGame:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is a valid approach, the game already has a save event. You can send that and just replace its execution code in EventClass::Execute

Spawner::RespondToSaveGame(this);
break;
}
}

Expand All @@ -44,6 +48,8 @@ size_t EventExt::GetDataSize(EventTypeExt type)
{
case EventTypeExt::ResponseTime2:
return sizeof(EventExt::ResponseTime2);
case EventTypeExt::SaveGame:
return sizeof(EventExt::SaveGame);
}

return 0;
Expand Down
6 changes: 5 additions & 1 deletion src/Ext/Event/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ enum class EventTypeExt : uint8_t
// Ares used Events 0x60 and 0x61

ResponseTime2 = 0x30,
SaveGame = 0x31,

FIRST = ResponseTime2,
LAST = ResponseTime2
LAST = SaveGame
};

#pragma pack(push, 1)
Expand All @@ -49,6 +50,9 @@ class EventExt
char MaxAhead;
uint8_t LatencyLevel;
} ResponseTime2;

struct SaveGame
{} SaveGame;
};

bool AddEvent();
Expand Down
12 changes: 8 additions & 4 deletions src/Spawner/Spawner.Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ void SpawnerConfig::LoadFromINIFile(CCINIClass* pINI)
MultiByteToWideChar(CP_UTF8, 0, Main::readBuffer, strlen(Main::readBuffer), UIGameMode, std::size(UIGameMode));
}

// SaveGame Options
LoadSaveGame = pINI->ReadBool(pSettingsSection, "LoadSaveGame", LoadSaveGame);
/* SavedGameDir */ pINI->ReadString(pSettingsSection, "SavedGameDir", SavedGameDir, SavedGameDir, sizeof(SavedGameDir));
/* SaveGameName */ pINI->ReadString(pSettingsSection, "SaveGameName", SaveGameName, SaveGameName, sizeof(SaveGameName));
{// SaveGame Options
LoadSaveGame = pINI->ReadBool(pSettingsSection, "LoadSaveGame", LoadSaveGame);
/* SavedGameDir */ pINI->ReadString(pSettingsSection, "SavedGameDir", SavedGameDir, SavedGameDir, sizeof(SavedGameDir));
/* SaveGameName */ pINI->ReadString(pSettingsSection, "SaveGameName", SaveGameName, SaveGameName, sizeof(SaveGameName));
AutoSaveCount = pINI->ReadInteger(pSettingsSection, "AutoSaveCount", AutoSaveCount);
AutoSaveInterval = pINI->ReadInteger(pSettingsSection, "AutoSaveInterval", AutoSaveInterval);
NextAutoSaveNumber = pINI->ReadInteger(pSettingsSection, "NextAutoSaveNumber", NextAutoSaveNumber);
}

{ // Scenario Options
Seed = pINI->ReadInteger(pSettingsSection, "Seed", Seed);
Expand Down
6 changes: 6 additions & 0 deletions src/Spawner/Spawner.Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class SpawnerConfig
bool LoadSaveGame;
char SavedGameDir[MAX_PATH]; // Nested paths are also supported, e.g. "Saved Games\\Yuri's Revenge"
char SaveGameName[60];
int AutoSaveCount;
int AutoSaveInterval;
int NextAutoSaveNumber;

// Scenario Options
int Seed;
Expand Down Expand Up @@ -161,6 +164,9 @@ class SpawnerConfig
, LoadSaveGame { false }
, SavedGameDir { "Saved Games" }
, SaveGameName { "" }
, AutoSaveCount { 5 }
, AutoSaveInterval { 7200 }
, NextAutoSaveNumber { 0 }

// Scenario Options
, Seed { 0 }
Expand Down
41 changes: 41 additions & 0 deletions src/Spawner/Spawner.Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,44 @@ DEFINE_HOOK(0x4FC57C, HouseClass__MPlayerDefeated_CheckAliveAndHumans, 0x7)
}

#pragma endregion MPlayerDefeated

#pragma region Save&Load

DEFINE_HOOK_AGAIN(0x624271, SomeFunc_InterceptMainLoop, 0x5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While patching at the call sites is valid, with the number of extensions YR has it might be a better idea to patch in at the end of the function itself perhaps.

DEFINE_HOOK_AGAIN(0x623D72, SomeFunc_InterceptMainLoop, 0x5);
DEFINE_HOOK_AGAIN(0x62314E, SomeFunc_InterceptMainLoop, 0x5);
DEFINE_HOOK_AGAIN(0x60D407, SomeFunc_InterceptMainLoop, 0x5);
DEFINE_HOOK_AGAIN(0x608206, SomeFunc_InterceptMainLoop, 0x5);
DEFINE_HOOK(0x48CE8A, SomeFunc_InterceptMainLoop, 0x5)
{
/**
* Main loop.
*/
reinterpret_cast<void(__fastcall*)()>(0x55D360)();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehhh... How about adding the function to YRpp maybe.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno how to commit it. XD

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


/**
* After loop.
*/
Spawner::After_Main_Loop();
return R->Origin() + 0x5;
}

DEFINE_HOOK(0x52DAED, Game_Start_ResetGlobal, 0x7)
{
Spawner::DoSave = false;
Spawner::NextAutoSaveFrame = -1;
Spawner::NextAutoSaveNumber = 0;
return 0;
}

DEFINE_HOOK(0x686B20, INIClass_ReadScenario_AutoSave, 0x6)
{
/**
* Schedule the next autosave.
*/
Spawner::NextAutoSaveFrame = Unsorted::CurrentFrame;
Spawner::NextAutoSaveFrame += Spawner::GetConfig()->AutoSaveInterval;
return 0;
}

#pragma endregion
Loading
Loading