Skip to content

Commit

Permalink
read id from sav file
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Feb 22, 2024
1 parent 72ce1a0 commit 4ab4af6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
62 changes: 52 additions & 10 deletions src/Misc/SavedGamesInSubdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
#include <Utilities/Macro.h>
#include <Spawner/Spawner.h>

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

#include <filesystem>
#include <optional>

namespace SavedGames
{
Expand Down Expand Up @@ -162,8 +166,6 @@ DEFINE_HOOK(0x67FD26, LoadOptionsClass_ReadSaveInfo_SGInSubdir, 0x5)
return 0;
}

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

namespace SavedGames
{
Expand All @@ -177,6 +179,11 @@ namespace SavedGames
{
}

operator uint64_t () const
{
return Number;
}

CampaignID(noinit_t()) { }
};

Expand Down Expand Up @@ -224,12 +231,12 @@ namespace SavedGames
return ret;
}

/*

template<typename T>
bool ReadFromStorage(IStorage* pStorage, const OLECHAR* name)
std::optional<T> ReadFromStorage(IStorage* pStorage, const OLECHAR* name)
{
IStream* pStream = nullptr;
bool ret = false;
bool hasValue = false;
HRESULT hr = pStorage->OpenStream(
name,
NULL,
Expand All @@ -238,18 +245,20 @@ namespace SavedGames
&pStream
);

T info;

if (SUCCEEDED(hr) && pStream != nullptr)
{
T info;
ULONG read = 0;
hr = pStream->Read(&info, sizeof(info), &read);
ret = SUCCEEDED(hr) && read == sizeof(info);
hasValue = SUCCEEDED(hr) && read == sizeof(info);

pStream->Release();
}

return ret;
return hasValue ? std::make_optional(info) : std::nullopt;
}
*/

}

// Write : A la fin
Expand All @@ -268,5 +277,38 @@ DEFINE_HOOK(0x67D2E3, GameSave_AdditionalInfoForClient, 0x6)

return 0;
}
// Read : TODO

// Read : Au debut
DEFINE_HOOK(0x67E4DC, LoadGame_AdditionalInfoForClient, 0x7)
{
LEA_STACK(const wchar_t*, filename, STACK_OFFSET(0x518, -0x4F4));
IStorage* pStorage = nullptr;
using namespace SavedGames;

if (SUCCEEDED(StgOpenStorage(filename,NULL,
STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
0,0,&pStorage)
))
{
if (auto id = ReadFromStorage<CampaignID>(pStorage, L"Campaign ID"))
{
uint64_t num = id.value().Number;
Debug::Log("[Spawner] sav file CampaignID = %d\n", num);
Spawner::GetConfig()->CampaignID = num;
}
if (auto info = ReadFromStorage<ExtraMetaInfo>(pStorage, L"Spawner extra info"))
{
Debug::Log("[Spawner] CurrentFrame = %d, TechnoCount = %d, AnimCount = %d \n"
, info.value().CurrentFrame
, info.value().TechnoCount
, info.value().AnimCount
);
}
}
if (pStorage)
pStorage->Release();

return 0;
}
// TODO : Refresh on starting next mission
// TODO : the requirement and solution on the client side needs better formulation
2 changes: 1 addition & 1 deletion src/Spawner/Spawner.Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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;
uint64_t CampaignID;

// Scenario Options
int Seed;
Expand Down

0 comments on commit 4ab4af6

Please sign in to comment.