Skip to content

Commit

Permalink
Implement CampaignID file filter from list
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Mar 9, 2024
1 parent 6378ce9 commit dbe94f7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
71 changes: 61 additions & 10 deletions src/Misc/SavedGamesInSubdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <HouseClass.h>
#include <AnimClass.h>
#include <LoadOptionsClass.h>

#include <filesystem>
#include <optional>
Expand Down Expand Up @@ -189,20 +190,20 @@ namespace SavedGames
};

// More fun
int HowManyTimesISavedForThisScenario = 0;

struct ExtraMetaInfo
{
static constexpr wchar_t* SaveName = L"Spawner extra info";
static constexpr wchar_t* SaveName = L"Spawner Extra Info";

int CurrentFrame;
int PlayerCount;
int SavedCount;
int TechnoCount;
int AnimCount;

explicit ExtraMetaInfo()
:CurrentFrame { Unsorted::CurrentFrame }
, PlayerCount { HouseClass::Array->Count }
, SavedCount { HowManyTimesISavedForThisScenario }
, TechnoCount { TechnoClass::Array->Count }
, AnimCount { AnimClass::Array->Count }
{
}

Expand Down Expand Up @@ -264,11 +265,58 @@ namespace SavedGames

}

DEFINE_HOOK(0x559921, LoadOptionsClass_FillList_FilterFile, 0x6)
{
GET(FileEntryClass*, pEntry, EBP);
enum { NullThisEntry = 0x559959 };
if (pEntry->IsWrongVersion || !pEntry->IsValid)
{
GameDelete(pEntry);
return NullThisEntry;
};

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

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

if (pStorage)
pStorage->Release();

if (should_delete)
{
GameDelete(pEntry);
return NullThisEntry;
}

return 0;
}

DEFINE_HOOK(0x683AFE, StartNewScenario_ClearCounter, 0x6)
{
SavedGames::HowManyTimesISavedForThisScenario = 0;
return 0;
}


// Write : A la fin
DEFINE_HOOK(0x67D2E3, GameSave_AdditionalInfoForClient, 0x6)
DEFINE_HOOK(0x67D2E3, SaveGame_AdditionalInfoForClient, 0x6)
{
GET_STACK(IStorage*, pStorage, STACK_OFFSET(0x4A0, -0x490));
using namespace SavedGames;
HowManyTimesISavedForThisScenario++;

if (pStorage)
{
Expand Down Expand Up @@ -298,14 +346,17 @@ DEFINE_HOOK(0x67E4DC, LoadGame_AdditionalInfoForClient, 0x7)
int num = id.value().Number;
Debug::Log("[Spawner] sav file CampaignID = %d\n", num);
Spawner::GetConfig()->CampaignID = num;
ScenarioClass::Instance->EndOfGame = true;
}

if (auto info = ReadFromStorage<ExtraMetaInfo>(pStorage))
{
Debug::Log("[Spawner] CurrentFrame = %d, TechnoCount = %d, AnimCount = %d \n"
, info.value().CurrentFrame
, info.value().TechnoCount
, info.value().AnimCount
Debug::Log("[Spawner] CurrentFrame = %d, TechnoCount = %d, HowManyTimesSaved = %d \n"
, info->CurrentFrame
, info->TechnoCount
, info->SavedCount
);
HowManyTimesISavedForThisScenario = info->SavedCount;
}
}
if (pStorage)
Expand Down
7 changes: 6 additions & 1 deletion src/Spawner/Spawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,12 @@ bool Spawner::StartNewScenario(const char* pScenarioName)
if (SessionClass::IsCampaign())
{
pGameModeOptions->Crates = true;
return ScenarioClass::StartScenario(pScenarioName, 1, 0);
bool result = ScenarioClass::StartScenario(pScenarioName, 1, 0);

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

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

0 comments on commit dbe94f7

Please sign in to comment.