From b14681891dce4b0060308d6a477a22c4f0b77edd Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Tue, 10 Aug 2021 21:09:35 +0200 Subject: Fix 8706dcd9: [Script] Byte-swap grfids to match normal expectations. --- src/script/api/script_newgrf.cpp | 8 +++++++- src/script/api/script_newgrf.hpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/script/api') diff --git a/src/script/api/script_newgrf.cpp b/src/script/api/script_newgrf.cpp index 387093092..9cdeeb191 100644 --- a/src/script/api/script_newgrf.cpp +++ b/src/script/api/script_newgrf.cpp @@ -19,13 +19,15 @@ ScriptNewGRFList::ScriptNewGRFList() { for (auto c = _grfconfig; c != nullptr; c = c->next) { if (!HasBit(c->flags, GCF_STATIC)) { - this->AddItem(c->ident.grfid); + this->AddItem(BSWAP32(c->ident.grfid)); } } } /* static */ bool ScriptNewGRF::IsLoaded(uint32 grfid) { + grfid = BSWAP32(grfid); // Match people's expectations. + for (auto c = _grfconfig; c != nullptr; c = c->next) { if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) { return true; @@ -37,6 +39,8 @@ ScriptNewGRFList::ScriptNewGRFList() /* static */ uint32 ScriptNewGRF::GetVersion(uint32 grfid) { + grfid = BSWAP32(grfid); // Match people's expectations. + for (auto c = _grfconfig; c != nullptr; c = c->next) { if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) { return c->version; @@ -48,6 +52,8 @@ ScriptNewGRFList::ScriptNewGRFList() /* static */ char *ScriptNewGRF::GetName(uint32 grfid) { + grfid = BSWAP32(grfid); // Match people's expectations. + for (auto c = _grfconfig; c != nullptr; c = c->next) { if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) { return ::stredup(c->GetName()); diff --git a/src/script/api/script_newgrf.hpp b/src/script/api/script_newgrf.hpp index 73f870cc1..d1a9336ec 100644 --- a/src/script/api/script_newgrf.hpp +++ b/src/script/api/script_newgrf.hpp @@ -45,7 +45,7 @@ public: static uint32 GetVersion(uint32 grfid); /** - * Get the BridgeID of a bridge at a given tile. + * Get the name of a loaded NewGRF. * @param grfid The NewGRF to query. * @pre ScriptNewGRF::IsLoaded(grfid). * @return The name of the NewGRF or nullptr if no name is defined. -- cgit v1.2.3-70-g09d2