Skip to content

Commit a6f7655

Browse files
authored
[GEN][ZH] Fix ThingTemplate copying to prevent multiplayer mismatch with original Shell Map and custom Maps (#1234)
1 parent 9527b54 commit a6f7655

File tree

8 files changed

+66
-16
lines changed

8 files changed

+66
-16
lines changed

Generals/Code/GameEngine/Include/Common/SparseMatchFinder.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@
4242
#undef SPARSEMATCH_DEBUG
4343
#endif
4444

45+
typedef UnsignedInt SparseMatchFinderFlags;
46+
enum SparseMatchFinderFlags_ CPP_11(: SparseMatchFinderFlags)
47+
{
48+
SparseMatchFinderFlags_NoCopy = 1<<0,
49+
};
50+
4551
//-------------------------------------------------------------------------------------------------
46-
template<class MATCHABLE, class BITSET>
52+
template<class MATCHABLE, class BITSET, SparseMatchFinderFlags FLAGS = 0>
4753
class SparseMatchFinder
4854
{
4955
private:
@@ -183,9 +189,29 @@ class SparseMatchFinder
183189
return result;
184190
}
185191

186-
//-------------------------------------------------------------------------------------------------
187192
public:
188193

194+
195+
//-------------------------------------------------------------------------------------------------
196+
SparseMatchFinder() {}
197+
SparseMatchFinder(const SparseMatchFinder& other)
198+
{
199+
*this = other;
200+
}
201+
202+
//-------------------------------------------------------------------------------------------------
203+
SparseMatchFinder& operator=(const SparseMatchFinder& other)
204+
{
205+
if CONSTEXPR ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0)
206+
{
207+
if (this != &other)
208+
{
209+
m_bestMatches = other.m_bestMatches;
210+
}
211+
}
212+
return *this;
213+
}
214+
189215
//-------------------------------------------------------------------------------------------------
190216
void clear()
191217
{

Generals/Code/GameEngine/Include/Common/ThingTemplate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,11 @@ class ThingTemplate : public Overridable
681681
//Code renderer handles these states now.
682682
//AsciiString m_inventoryImage[ INV_IMAGE_NUM_IMAGES ]; ///< portrait inventory pictures
683683

684+
// TheSuperHackers @bugfix Caball009/xezon 06/07/2025 No longer copy SparseMatchFinder to prevent copied instances linking to unrelated data.
685+
// This avoids mismatching in certain maps, for example those that spawn units with veterancy.
686+
typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags, SparseMatchFinderFlags_NoCopy> WeaponTemplateSetFinder;
687+
typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags, SparseMatchFinderFlags_NoCopy> ArmorTemplateSetFinder;
688+
684689
// ---- STL-sized things
685690
std::vector<ProductionPrerequisite> m_prereqInfo; ///< the unit Prereqs for this tech
686691
std::vector<AsciiString> m_buildVariations; /**< if we build a unit of this type via script or ui, randomly choose one

Generals/Code/GameEngine/Include/GameLogic/ArmorSet.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,4 @@ class ArmorTemplateSet
9494
//-------------------------------------------------------------------------------------------------
9595
typedef std::vector<ArmorTemplateSet> ArmorTemplateSetVector;
9696

97-
//-------------------------------------------------------------------------------------------------
98-
typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags> ArmorTemplateSetFinder;
99-
10097
#endif // _ArmorSet_H_

Generals/Code/GameEngine/Include/GameLogic/WeaponSet.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ class WeaponTemplateSet
146146
//-------------------------------------------------------------------------------------------------
147147
typedef std::vector<WeaponTemplateSet> WeaponTemplateSetVector;
148148

149-
//-------------------------------------------------------------------------------------------------
150-
typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags> WeaponTemplateSetFinder;
151-
152149
//-------------------------------------------------------------------------------------------------
153150
enum WeaponChoiceCriteria CPP_11(: Int)
154151
{

GeneralsMD/Code/GameEngine/Include/Common/SparseMatchFinder.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@
4242
#undef SPARSEMATCH_DEBUG
4343
#endif
4444

45+
typedef UnsignedInt SparseMatchFinderFlags;
46+
enum SparseMatchFinderFlags_ CPP_11(: SparseMatchFinderFlags)
47+
{
48+
SparseMatchFinderFlags_NoCopy = 1<<0,
49+
};
50+
4551
//-------------------------------------------------------------------------------------------------
46-
template<class MATCHABLE, class BITSET>
52+
template<class MATCHABLE, class BITSET, SparseMatchFinderFlags FLAGS = 0>
4753
class SparseMatchFinder
4854
{
4955
private:
@@ -185,9 +191,29 @@ class SparseMatchFinder
185191
return result;
186192
}
187193

188-
//-------------------------------------------------------------------------------------------------
189194
public:
190195

196+
197+
//-------------------------------------------------------------------------------------------------
198+
SparseMatchFinder() {}
199+
SparseMatchFinder(const SparseMatchFinder& other)
200+
{
201+
*this = other;
202+
}
203+
204+
//-------------------------------------------------------------------------------------------------
205+
SparseMatchFinder& operator=(const SparseMatchFinder& other)
206+
{
207+
if CONSTEXPR ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0)
208+
{
209+
if (this != &other)
210+
{
211+
m_bestMatches = other.m_bestMatches;
212+
}
213+
}
214+
return *this;
215+
}
216+
191217
//-------------------------------------------------------------------------------------------------
192218
void clear()
193219
{

GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,11 @@ class ThingTemplate : public Overridable
698698
//Code renderer handles these states now.
699699
//AsciiString m_inventoryImage[ INV_IMAGE_NUM_IMAGES ]; ///< portrait inventory pictures
700700

701+
// TheSuperHackers @bugfix Caball009/xezon 06/07/2025 No longer copy SparseMatchFinder to prevent copied instances linking to unrelated data.
702+
// This avoids mismatching in certain maps, for example those that spawn units with veterancy.
703+
typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags, SparseMatchFinderFlags_NoCopy> WeaponTemplateSetFinder;
704+
typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags, SparseMatchFinderFlags_NoCopy> ArmorTemplateSetFinder;
705+
701706
// ---- STL-sized things
702707
std::vector<ProductionPrerequisite> m_prereqInfo; ///< the unit Prereqs for this tech
703708
std::vector<AsciiString> m_buildVariations; /**< if we build a unit of this type via script or ui, randomly choose one

GeneralsMD/Code/GameEngine/Include/GameLogic/ArmorSet.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,4 @@ class ArmorTemplateSet
9797
//-------------------------------------------------------------------------------------------------
9898
typedef std::vector<ArmorTemplateSet> ArmorTemplateSetVector;
9999

100-
//-------------------------------------------------------------------------------------------------
101-
typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags> ArmorTemplateSetFinder;
102-
103100
#endif // _ArmorSet_H_

GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ class WeaponTemplateSet
166166
//-------------------------------------------------------------------------------------------------
167167
typedef std::vector<WeaponTemplateSet> WeaponTemplateSetVector;
168168

169-
//-------------------------------------------------------------------------------------------------
170-
typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags> WeaponTemplateSetFinder;
171-
172169
//-------------------------------------------------------------------------------------------------
173170
enum WeaponChoiceCriteria CPP_11(: Int)
174171
{

0 commit comments

Comments
 (0)