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

Enable command line argument to produce an archive checksum to the headless/normal engines #1904

Merged
merged 5 commits into from
Feb 16, 2025
Merged
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
2 changes: 2 additions & 0 deletions rts/Game/PreGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ void CPreGame::StartServer(const std::string& setupscript)
sha512::dump_digest(mapChecksum, mapChecksumHex);
sha512::dump_digest(modChecksum, modChecksumHex);

archiveScanner->WriteCache(); // write the cache, useful in case the game loading crashes afterwards

LOG("[PreGame::%s]\n\tmod-checksum=%s\n\tmap-checksum=%s", __func__, modChecksumHex.data(), mapChecksumHex.data());
LOG("[PreGame::%s] Game/Map archives checksum acquisition took = %ld microseconds", __func__, (spring_gettime() - connectTimer).toMilliSecsi());

Expand Down
1 change: 0 additions & 1 deletion rts/Game/UI/InfoConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void CInfoConsole::InitStatic() {

void CInfoConsole::KillStatic() {
RECOIL_DETAILED_TRACY_ZONE;
assert(infoConsole != nullptr);
spring::SafeDestruct(infoConsole);
std::fill(std::begin(infoConsoleMem), std::end(infoConsoleMem), std::byte{0});
}
Expand Down
2 changes: 1 addition & 1 deletion rts/Rendering/Textures/Bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ CBitmap& CBitmap::operator=(CBitmap&& bmp) noexcept
bool CBitmap::CanBeKilled()
{
RECOIL_DETAILED_TRACY_ZONE;
return ITexMemPool::texMemPool->NoCurrentAllocations();
return !ITexMemPool::texMemPool || ITexMemPool::texMemPool->NoCurrentAllocations();
}

void CBitmap::InitPool(size_t size)
Expand Down
12 changes: 7 additions & 5 deletions rts/System/FileSystem/FileSystemInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ bool FileSystemInitializer::Initialize()
return true;

SetupThreadReg();
InitializeTry();
ClearThreadReg();

return (initSuccess && !initFailure);
}

void FileSystemInitializer::InitializeTry()
{
try {
Platform::SetOrigCWD();

Expand All @@ -86,11 +93,6 @@ bool FileSystemInitializer::Initialize()

ErrorMessageBox("", "Spring: caught generic exception", MBF_OK | MBF_EXCL);
}

// in case of an exception, ErrorMessageBox takes care of this
ClearThreadReg();

return (initSuccess && !initFailure);
}

void FileSystemInitializer::Cleanup(bool deallocConfigHandler)
Expand Down
1 change: 1 addition & 0 deletions rts/System/FileSystem/FileSystemInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FileSystemInitializer {
static void PreInitializeConfigHandler(const std::string& configSource = "", const std::string& configName = "", const bool safemode = false);
static void InitializeLogOutput(const std::string& filename = "");
static bool Initialize();
static void InitializeTry();
static void InitializeThr(bool* retPtr) { *retPtr = Initialize(); }
static void Cleanup(bool deallocConfigHandler = true);
static void Reload();
Expand Down
20 changes: 20 additions & 0 deletions rts/System/SpringApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ DEFINE_string (map, "", "Specify the m
DEFINE_string (menu, "", "Specify a lua menu archive to be used by spring");
DEFINE_string (name, "", "Set your player name");
DEFINE_bool (oldmenu, false, "Start the old menu");
DEFINE_string_EX(calc_checksum, "calc-checksum", "", "Calculate named archive checksum and write to cache, cant run in parallel");

/* Startscript sets the listening port number. Replays use the entire startscript, including the port number.
* So normally if two games were originally played on the same port number, you can't watch their replays in
Expand Down Expand Up @@ -544,6 +545,25 @@ void SpringApp::ParseCmdLine(int argc, char* argv[])
AILibraryManager::OutputSkirmishAIInfo();
exit(spring::EXIT_CODE_SUCCESS);
}
else if (!FLAGS_calc_checksum.empty()) {
ConsolePrintInitialize(FLAGS_config, FLAGS_safemode);
try {
FileSystemInitializer::InitializeTry();
archiveScanner->ResetNumFilesHashed();

const std::string archive = archiveScanner->ArchiveFromName(FLAGS_calc_checksum);
const auto cs = archiveScanner->GetArchiveCompleteChecksumBytes(archive);

sha512::hex_digest hexCs = { 0 };
sha512::dump_digest(cs, hexCs);

LOG("Archive \"%s\", checksum = \"%s\"", FLAGS_calc_checksum.c_str(), hexCs.data());
FileSystemInitializer::Cleanup();
exit(spring::EXIT_CODE_SUCCESS);
}
CATCH_SPRING_ERRORS
exit(spring::EXIT_CODE_CRASHED);
}

CTextureAtlas::SetDebug(FLAGS_textureatlas);

Expand Down
Loading