From 50f6da2a13450b7069327754f76fbfbb785e257b Mon Sep 17 00:00:00 2001 From: Itms Date: Tue, 21 Oct 2025 20:41:10 +0200 Subject: [PATCH] Use the PYROGENESIS_VERSION macro instead of a global Reviewed-At: https://gitea.wildfiregames.com/0ad/0ad/pulls/8222 --- source/lib/build_version.h | 5 +++++ source/lobby/XmppClient.cpp | 2 +- source/main.cpp | 2 +- source/network/NetProtocol.h | 2 +- source/network/scripting/JSInterface_Network.cpp | 4 ++-- source/ps/CLogger.cpp | 4 ++-- source/ps/Pyrogenesis.cpp | 4 +--- source/ps/Pyrogenesis.h | 3 ++- source/ps/Replay.cpp | 2 +- source/ps/SavedGame.cpp | 2 +- source/ps/VisualReplay.cpp | 2 +- source/ps/scripting/JSInterface_Mod.cpp | 2 +- 12 files changed, 19 insertions(+), 15 deletions(-) diff --git a/source/lib/build_version.h b/source/lib/build_version.h index 0dffa25b3e..304359034c 100644 --- a/source/lib/build_version.h +++ b/source/lib/build_version.h @@ -20,6 +20,11 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#ifndef INCLUDED_BUILDVERSION +#define INCLUDED_BUILDVERSION + #define PYROGENESIS_VERSION "0.28.0" #define PYROGENESIS_VERSION_WORD 0,28,0,0 extern wchar_t build_version[]; + +#endif // INCLUDED_BUILDVERSION diff --git a/source/lobby/XmppClient.cpp b/source/lobby/XmppClient.cpp index d3606f3152..8f39534750 100644 --- a/source/lobby/XmppClient.cpp +++ b/source/lobby/XmppClient.cpp @@ -130,7 +130,7 @@ XmppClient::XmppClient(const ScriptInterface* scriptInterface, const std::string m_client->registerConnectionListener(this); m_client->setPresence(gloox::Presence::Available, -1); - m_client->disco()->setVersion("Pyrogenesis", engine_version); + m_client->disco()->setVersion("Pyrogenesis", PYROGENESIS_VERSION); m_client->disco()->setIdentity("client", "bot"); m_client->setCompression(false); diff --git a/source/main.cpp b/source/main.cpp index 547713fe06..184509f411 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -561,7 +561,7 @@ static void RunGameOrAtlas(const std::span argv) if (args.Has("version")) { - debug_printf("Pyrogenesis %s\n", engine_version); + debug_printf("Pyrogenesis %s\n", PYROGENESIS_VERSION); return; } diff --git a/source/network/NetProtocol.h b/source/network/NetProtocol.h index 3fbcf1ed9f..54f1a967f2 100644 --- a/source/network/NetProtocol.h +++ b/source/network/NetProtocol.h @@ -44,7 +44,7 @@ Message CreateHandshake() { handshake.m_Magic = PS_PROTOCOL_MAGIC; handshake.m_ProtocolVersion = PS_PROTOCOL_VERSION; - handshake.m_EngineVersion = engine_version; + handshake.m_EngineVersion = PYROGENESIS_VERSION; for (const Mod::ModData* mod : Mod::Instance().GetEnabledModsData()) { diff --git a/source/network/scripting/JSInterface_Network.cpp b/source/network/scripting/JSInterface_Network.cpp index 9ab9682d88..c3247cf167 100644 --- a/source/network/scripting/JSInterface_Network.cpp +++ b/source/network/scripting/JSInterface_Network.cpp @@ -128,7 +128,7 @@ void StartNetworkHost(const CStrW& playerName, const u16 serverPort, const CStr& * TODO: it should be possible to implement SRP or something along those lines to completely protect from this, * but the cost/benefit ratio is probably not worth it. */ - CStr hashedPass = HashCryptographically(password, hostJID + password + engine_version); + CStr hashedPass = HashCryptographically(password, hostJID + password + PYROGENESIS_VERSION); g_NetServer->SetPassword(hashedPass); g_NetClient->SetHostJID(hostJID); g_NetClient->SetGamePassword(hashedPass); @@ -176,7 +176,7 @@ void StartNetworkJoinLobby(const CStrW& playerName, const CStr& hostJID, const C ENSURE(!g_NetServer); ENSURE(!g_Game); - CStr hashedPass = HashCryptographically(password, hostJID + password + engine_version); + CStr hashedPass = HashCryptographically(password, hostJID + password + PYROGENESIS_VERSION); g_Game = new CGame(true); g_NetClient = new CNetClient(g_Game); g_NetClient->SetUserName(playerName); diff --git a/source/ps/CLogger.cpp b/source/ps/CLogger.cpp index f382aba64f..79c640bd1e 100644 --- a/source/ps/CLogger.cpp +++ b/source/ps/CLogger.cpp @@ -77,8 +77,8 @@ CLogger::CLogger(std::ostream& mainLog, std::ostream& interestingLog, const bool m_InterestingLog{interestingLog}, m_UseDebugPrintf{useDebugPrintf} { - m_MainLog << html_header0 << engine_version << ") Main log" << html_header1; - m_InterestingLog << html_header0 << engine_version << ") Main log (warnings and errors only)" << html_header1; + m_MainLog << html_header0 << PYROGENESIS_VERSION << ") Main log" << html_header1; + m_InterestingLog << html_header0 << PYROGENESIS_VERSION << ") Main log (warnings and errors only)" << html_header1; } CLogger::~CLogger() diff --git a/source/ps/Pyrogenesis.cpp b/source/ps/Pyrogenesis.cpp index 6126287242..15d2228151 100644 --- a/source/ps/Pyrogenesis.cpp +++ b/source/ps/Pyrogenesis.cpp @@ -19,14 +19,12 @@ #include "Pyrogenesis.h" -#include "lib/build_version.h" #include "lib/path.h" #include "lib/sysdep/sysdep.h" #include #include -const char* engine_version = PYROGENESIS_VERSION; const char* main_window_name = "0 A.D."; // convert contents of file from char to wchar_t and @@ -59,7 +57,7 @@ static void AppendAsciiFile(FILE* out, const OsPath& pathname) void psBundleLogs(FILE* f) { fwprintf(f, L"Build Version: %ls\n\n", build_version); - fwprintf(f, L"Engine Version: %hs\n\n", engine_version); + fwprintf(f, L"Engine Version: %hs\n\n", PYROGENESIS_VERSION); fwprintf(f, L"System info:\n\n"); OsPath path1 = psLogDir()/"system_info.txt"; diff --git a/source/ps/Pyrogenesis.h b/source/ps/Pyrogenesis.h index 63be0f17fd..5fcd0e462b 100644 --- a/source/ps/Pyrogenesis.h +++ b/source/ps/Pyrogenesis.h @@ -24,12 +24,13 @@ Standard declarations which are included in all projects. #ifndef INCLUDED_PYROGENESIS #define INCLUDED_PYROGENESIS +#include + #include class Path; using OsPath = Path; -extern const char* engine_version; extern const char* main_window_name; extern void psBundleLogs(FILE* f); // set during InitVfs diff --git a/source/ps/Replay.cpp b/source/ps/Replay.cpp index 404e3ae99a..6f49f6bc12 100644 --- a/source/ps/Replay.cpp +++ b/source/ps/Replay.cpp @@ -80,7 +80,7 @@ void CReplayLogger::StartGame(JS::MutableHandleValue attribs) Script::SetProperty(rq, attribs, "timestamp", (double)std::time(nullptr)); // Add engine version and currently loaded mods for sanity checks when replaying - Script::SetProperty(rq, attribs, "engine_version", engine_version); + Script::SetProperty(rq, attribs, "engine_version", PYROGENESIS_VERSION); JS::RootedValue mods(rq.cx); Script::ToJSVal(rq, &mods, g_Mods.GetEnabledModsData()); Script::SetProperty(rq, attribs, "mods", mods); diff --git a/source/ps/SavedGame.cpp b/source/ps/SavedGame.cpp index 7148fb21f6..793fb349ff 100644 --- a/source/ps/SavedGame.cpp +++ b/source/ps/SavedGame.cpp @@ -112,7 +112,7 @@ Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation Script::CreateObject( rq, &metadata, - "engine_version", engine_version, + "engine_version", PYROGENESIS_VERSION, "time", static_cast(now), "playerID", g_Game->GetPlayerID(), "mods", mods, diff --git a/source/ps/VisualReplay.cpp b/source/ps/VisualReplay.cpp index d32d52a1a2..d1d3701e79 100644 --- a/source/ps/VisualReplay.cpp +++ b/source/ps/VisualReplay.cpp @@ -61,7 +61,7 @@ const u8 minimumReplayDuration = 3; OsPath VisualReplay::GetDirectoryPath() { - return Paths(g_CmdLineArgs).UserData() / "replays" / engine_version; + return Paths(g_CmdLineArgs).UserData() / "replays" / PYROGENESIS_VERSION; } OsPath VisualReplay::GetCacheFilePath() diff --git a/source/ps/scripting/JSInterface_Mod.cpp b/source/ps/scripting/JSInterface_Mod.cpp index f42b8b2752..2d6443c949 100644 --- a/source/ps/scripting/JSInterface_Mod.cpp +++ b/source/ps/scripting/JSInterface_Mod.cpp @@ -135,7 +135,7 @@ JS::Value GetEngineInfo(const ScriptInterface& scriptInterface) Script::CreateObject( rq, &metainfo, - "engine_version", engine_version, + "engine_version", PYROGENESIS_VERSION, "mods", mods); Script::DeepFreezeObject(rq, metainfo);