From ffd21598adc3566d92baecbecc2b87606916c504 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Sun, 6 Jul 2025 10:55:55 +0200 Subject: [PATCH 1/2] [ZH] Fix ThingTemplate copies to prevent mismatch with mod map and quickstart --- .../Include/Common/SparseMatchFinder.h | 27 +++++++++++++++++-- .../GameEngine/Include/Common/ThingTemplate.h | 5 ++++ .../GameEngine/Include/GameLogic/ArmorSet.h | 3 --- .../GameEngine/Include/GameLogic/WeaponSet.h | 3 --- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h b/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h index 3f1f696617..468b0aafa9 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h @@ -42,8 +42,14 @@ #undef SPARSEMATCH_DEBUG #endif +typedef UnsignedInt SparseMatchFinderFlags; +enum SparseMatchFinderFlags_ CPP_11(: SparseMatchFinderFlags) +{ + SparseMatchFinderFlags_NoCopy = 1<<0, +}; + //------------------------------------------------------------------------------------------------- -template +template class SparseMatchFinder { private: @@ -185,9 +191,26 @@ class SparseMatchFinder return result; } - //------------------------------------------------------------------------------------------------- public: + + //------------------------------------------------------------------------------------------------- + SparseMatchFinder() {} + SparseMatchFinder(const SparseMatchFinder& other) + { + *this = other; + } + + //------------------------------------------------------------------------------------------------- + SparseMatchFinder& operator=(const SparseMatchFinder& other) + { + if ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0 && this != &other) + { + m_bestMatches = other.m_bestMatches; + } + return *this; + } + //------------------------------------------------------------------------------------------------- void clear() { diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h index 2764437135..6d8610b98c 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h @@ -698,6 +698,11 @@ class ThingTemplate : public Overridable //Code renderer handles these states now. //AsciiString m_inventoryImage[ INV_IMAGE_NUM_IMAGES ]; ///< portrait inventory pictures + // TheSuperHackers @bugfix Caball009/xezon 06/07/2025 No longer copy SparseMatchFinder to prevent copied instances linking to unrelated data. + // This avoids mismatching in certain maps, for example those that spawn units with veterancy. + typedef SparseMatchFinder WeaponTemplateSetFinder; + typedef SparseMatchFinder ArmorTemplateSetFinder; + // ---- STL-sized things std::vector m_prereqInfo; ///< the unit Prereqs for this tech std::vector m_buildVariations; /**< if we build a unit of this type via script or ui, randomly choose one diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h index c84618fb05..2302b98071 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h @@ -97,7 +97,4 @@ class ArmorTemplateSet //------------------------------------------------------------------------------------------------- typedef std::vector ArmorTemplateSetVector; -//------------------------------------------------------------------------------------------------- -typedef SparseMatchFinder ArmorTemplateSetFinder; - #endif // _ArmorSet_H_ diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h index d1313382ce..88fc69a34c 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h @@ -166,9 +166,6 @@ class WeaponTemplateSet //------------------------------------------------------------------------------------------------- typedef std::vector WeaponTemplateSetVector; -//------------------------------------------------------------------------------------------------- -typedef SparseMatchFinder WeaponTemplateSetFinder; - //------------------------------------------------------------------------------------------------- enum WeaponChoiceCriteria CPP_11(: Int) { From 92e3e3602eca02558121d1254289fefe33b83ca6 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Sun, 6 Jul 2025 22:25:25 +0200 Subject: [PATCH 2/2] Use CONSTEXPR --- .../Code/GameEngine/Include/Common/SparseMatchFinder.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h b/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h index 468b0aafa9..d75be6064b 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h @@ -204,9 +204,12 @@ class SparseMatchFinder //------------------------------------------------------------------------------------------------- SparseMatchFinder& operator=(const SparseMatchFinder& other) { - if ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0 && this != &other) + if CONSTEXPR ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0) { - m_bestMatches = other.m_bestMatches; + if (this != &other) + { + m_bestMatches = other.m_bestMatches; + } } return *this; }