Skip to content

Commit

Permalink
rename all entries
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Mar 9, 2024
1 parent dbe94f7 commit 825aaa8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
41 changes: 23 additions & 18 deletions src/Misc/SavedGamesInSubdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ DEFINE_HOOK(0x67FD26, LoadOptionsClass_ReadSaveInfo_SGInSubdir, 0x5)
namespace SavedGames
{
//issue #18
struct CampaignID
struct CustomMissionID
{
static constexpr wchar_t* SaveName = L"Campaign ID";
static constexpr wchar_t* SaveName = L"CustomMissionID";

int Number;
explicit CampaignID() :
Number { SessionClass::IsCampaign() ? Spawner::GetConfig()->CampaignID : 0 }
explicit CustomMissionID() :
Number { Spawner::GetConfig()->CustomMissionID }
{
}

Expand All @@ -186,7 +186,7 @@ namespace SavedGames
return Number;
}

CampaignID(noinit_t()) { }
CustomMissionID(noinit_t()) { }
};

// More fun
Expand Down Expand Up @@ -265,30 +265,30 @@ namespace SavedGames

}

DEFINE_HOOK(0x559921, LoadOptionsClass_FillList_FilterFile, 0x6)
DEFINE_HOOK(0x559921, LoadOptionsClass_FillList_FilterFiles, 0x6)
{
GET(FileEntryClass*, pEntry, EBP);
enum { NullThisEntry = 0x559959 };

if (pEntry->IsWrongVersion || !pEntry->IsValid)
{
GameDelete(pEntry);
return NullThisEntry;
};

static OLECHAR buffer[0x200] {};
static OLECHAR wNameBuffer[0x200] {};
SavedGames::FormatPath(Main::readBuffer, pEntry->Filename.data());
MultiByteToWideChar(0, 0, Main::readBuffer, -1, buffer, 64);
MultiByteToWideChar(0, 0, Main::readBuffer, -1, wNameBuffer, 64);
IStorage* pStorage = nullptr;
bool should_delete = false;
if (SUCCEEDED(StgOpenStorage(buffer, NULL,
if (SUCCEEDED(StgOpenStorage(wNameBuffer, NULL,
STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
0, 0, &pStorage)
))
{
using namespace SavedGames;
auto id = ReadFromStorage<CampaignID>(pStorage);
auto id = SavedGames::ReadFromStorage<SavedGames::CustomMissionID>(pStorage);

if ((Spawner::GetConfig()->CampaignID == 0) != (!id.has_value() || id->Number == 0))
if ((Spawner::GetConfig()->CustomMission) != (id.has_value()))
should_delete = true;
}

Expand Down Expand Up @@ -320,8 +320,8 @@ DEFINE_HOOK(0x67D2E3, SaveGame_AdditionalInfoForClient, 0x6)

if (pStorage)
{
if (CampaignID {} != 0)
AppendToStorage<CampaignID>(pStorage);
if (SessionClass::IsCampaign() && Spawner::GetConfig()->CustomMission)
AppendToStorage<CustomMissionID>(pStorage);
if (AppendToStorage<ExtraMetaInfo>(pStorage))
Debug::Log("[Spawner] Extra meta info appended on sav file\n");
}
Expand All @@ -341,13 +341,18 @@ DEFINE_HOOK(0x67E4DC, LoadGame_AdditionalInfoForClient, 0x7)
0,0,&pStorage)
))
{
if (auto id = ReadFromStorage<CampaignID>(pStorage))
if (auto id = ReadFromStorage<CustomMissionID>(pStorage))
{
int num = id.value().Number;
Debug::Log("[Spawner] sav file CampaignID = %d\n", num);
Spawner::GetConfig()->CampaignID = num;
int num = id->Number;
Debug::Log("[Spawner] sav file CustomMissionID = %d\n", num);
Spawner::GetConfig()->CustomMission = true;
Spawner::GetConfig()->CustomMissionID = num;
ScenarioClass::Instance->EndOfGame = true;
}
else
{
Spawner::GetConfig()->CustomMission = false;
}

if (auto info = ReadFromStorage<ExtraMetaInfo>(pStorage))
{
Expand Down
3 changes: 2 additions & 1 deletion src/Spawner/Spawner.Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void SpawnerConfig::LoadFromINIFile(CCINIClass* pINI)
LoadSaveGame = pINI->ReadBool(pSettingsSection, "LoadSaveGame", LoadSaveGame);
/* SavedGameDir */ pINI->ReadString(pSettingsSection, "SavedGameDir", SavedGameDir, SavedGameDir, sizeof(SavedGameDir));
/* SaveGameName */ pINI->ReadString(pSettingsSection, "SaveGameName", SaveGameName, SaveGameName, sizeof(SaveGameName));
CampaignID = pINI->ReadInteger(pSettingsSection, "CampaignID", 0);
CustomMission = pINI->ReadBool(pSettingsSection, "CustomMission", false);
CustomMissionID = pINI->ReadInteger(pSettingsSection, "CustomMissionID", 0);

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

// Scenario Options
int Seed;
Expand Down Expand Up @@ -162,7 +163,8 @@ class SpawnerConfig
, LoadSaveGame { false }
, SavedGameDir { "Saved Games" }
, SaveGameName { "" }
, CampaignID { 0 }
, CustomMission { false }
, CustomMissionID { 0 }

// Scenario Options
, Seed { 0 }
Expand Down
10 changes: 8 additions & 2 deletions src/Spawner/Spawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ProtocolZero.LatencyLevel.h"
#include <Utilities/Debug.h>
#include <Utilities/DumperTypes.h>
#include <Utilities/Patch.h>

#include <GameOptionsClass.h>
#include <GameStrings.h>
Expand Down Expand Up @@ -294,12 +295,17 @@ bool Spawner::StartNewScenario(const char* pScenarioName)
if (SessionClass::IsCampaign())
{
pGameModeOptions->Crates = true;

// Blame Starkku's Phobos PR #1145 for having to rename MISSIONMD.INI to this
if (Spawner::Config->CustomMission)
Patch::Apply_RAW(0x839724, "Spawn.ini");

bool result = ScenarioClass::StartScenario(pScenarioName, 1, 0);

if (Spawner::Config->CampaignID)
if (Spawner::Config->CustomMission)
ScenarioClass::Instance->EndOfGame = true;

return result;
return result;
}
else if (SessionClass::IsSkirmish())
{
Expand Down

0 comments on commit 825aaa8

Please sign in to comment.