Skip to content

Commit d3b814d

Browse files
CrimRecyaNetsuNegiCoronia
authored
[Minor] Fix some INI reading (#1726)
- Fix `Spawner.LimitRange` - Fix `IronCurtainColor`, `ForceShieldColor` and `BerserkColor` - Remove unnecessary `pINI->GetSection(pSection)` judgments and their hooks. --------- Co-authored-by: NetsuNegi39 <[email protected]> Co-authored-by: Coronia <[email protected]>
1 parent d86c159 commit d3b814d

File tree

24 files changed

+71
-83
lines changed

24 files changed

+71
-83
lines changed

src/Ext/AnimType/Body.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ DEFINE_HOOK(0x42898A, AnimTypeClass_Save_Suffix, 0x3)
237237
return 0;
238238
}
239239

240-
DEFINE_HOOK_AGAIN(0x4287E9, AnimTypeClass_LoadFromINI, 0xA)
240+
//DEFINE_HOOK_AGAIN(0x4287E9, AnimTypeClass_LoadFromINI, 0xA)// Section dont exist!
241241
DEFINE_HOOK(0x4287DC, AnimTypeClass_LoadFromINI, 0xA)
242242
{
243243
GET(AnimTypeClass*, pItem, ESI);

src/Ext/BuildingType/Body.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
135135
const char* pSection = pThis->ID;
136136
const char* pArtSection = pThis->ImageFile;
137137
auto pArtINI = &CCINIClass::INI_Art;
138-
139-
if (!pINI->GetSection(pSection))
140-
return;
141-
142138
INI_EX exINI(pINI);
143139
INI_EX exArtINI(pArtINI);
144140

@@ -424,7 +420,7 @@ DEFINE_HOOK(0x46536A, BuildingTypeClass_Save_Suffix, 0x7)
424420
return 0;
425421
}
426422

427-
DEFINE_HOOK_AGAIN(0x464A56, BuildingTypeClass_LoadFromINI, 0xA)
423+
//DEFINE_HOOK_AGAIN(0x464A56, BuildingTypeClass_LoadFromINI, 0xA)// Section dont exist!
428424
DEFINE_HOOK(0x464A49, BuildingTypeClass_LoadFromINI, 0xA)
429425
{
430426
GET(BuildingTypeClass*, pItem, EBP);

src/Ext/BulletType/Body.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ void BulletTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
2626
{
2727
auto pThis = this->OwnerObject();
2828
const char* pSection = pThis->ID;
29-
30-
if (!pINI->GetSection(pSection))
31-
return;
32-
3329
INI_EX exINI(pINI);
3430

3531
this->Armor.Read(exINI, pSection, "Armor");
@@ -231,7 +227,7 @@ DEFINE_HOOK(0x46C74A, BulletTypeClass_Save_Suffix, 0x3)
231227
return 0;
232228
}
233229

234-
DEFINE_HOOK_AGAIN(0x46C429, BulletTypeClass_LoadFromINI, 0xA)
230+
//DEFINE_HOOK_AGAIN(0x46C429, BulletTypeClass_LoadFromINI, 0xA)// Section dont exist!
235231
DEFINE_HOOK(0x46C41C, BulletTypeClass_LoadFromINI, 0xA)
236232
{
237233
GET(BulletTypeClass*, pItem, ESI);

src/Ext/OverlayType/Body.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ DEFINE_HOOK(0x5FEC2A, OverlayTypeClass_Save_Suffix, 0x6)
118118
return 0;
119119
}
120120

121-
DEFINE_HOOK_AGAIN(0x5FEA11, OverlayTypeClass_LoadFromINI, 0xA)
122-
DEFINE_HOOK(0x5FEA1E, OverlayTypeClass_LoadFromINI, 0xA)
121+
//DEFINE_HOOK_AGAIN(0x5FEA1E, OverlayTypeClass_LoadFromINI, 0xA)// Section dont exist!
122+
DEFINE_HOOK(0x5FEA11, OverlayTypeClass_LoadFromINI, 0xA)
123123
{
124124
GET(OverlayTypeClass*, pItem, ESI);
125125
GET_STACK(CCINIClass*, pINI, STACK_OFFSET(0x28C, 0x4));

src/Ext/ParticleSystemType/Body.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ void ParticleSystemTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
1717
{
1818
auto pThis = this->OwnerObject();
1919
const char* pSection = pThis->ID;
20-
21-
if (!pINI->GetSection(pSection))
22-
return;
23-
2420
INI_EX exINI(pINI);
2521

2622
this->AdjustTargetCoordsOnRotation.Read(exINI, pSection, "AdjustTargetCoordsOnRotation");
@@ -102,8 +98,8 @@ DEFINE_HOOK(0x644844, ParticleSystemTypeClass_Save_Suffix, 0x5)
10298
return 0;
10399
}
104100

105-
DEFINE_HOOK_AGAIN(0x644615, ParticleSystemTypeClass_LoadFromINI, 0x5)
106-
DEFINE_HOOK(0x644620, ParticleSystemTypeClass_LoadFromINI, 0x5)
101+
//DEFINE_HOOK_AGAIN(0x644620, ParticleSystemTypeClass_LoadFromINI, 0x5)// Section dont exist!
102+
DEFINE_HOOK(0x644615, ParticleSystemTypeClass_LoadFromINI, 0x5)
107103
{
108104
GET(ParticleSystemTypeClass*, pItem, ESI);
109105
GET(CCINIClass*, pINI, EBX);

src/Ext/ParticleType/Body.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ void ParticleTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
1717
{
1818
auto pThis = this->OwnerObject();
1919
const char* pSection = pThis->ID;
20-
21-
if (!pINI->GetSection(pSection))
22-
return;
23-
2420
INI_EX exINI(pINI);
2521

2622
this->Gas_MaxDriftSpeed.Read(exINI, pSection, "Gas.MaxDriftSpeed");

src/Ext/Rules/Body.cpp

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <FPSCounter.h>
55
#include <GameOptionsClass.h>
66

7+
#include <Ext/TechnoType/Body.h>
78
#include <New/Type/RadTypeClass.h>
89
#include <New/Type/ShieldTypeClass.h>
910
#include <New/Type/LaserTrailTypeClass.h>
@@ -47,6 +48,16 @@ void RulesExt::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
4748

4849
void RulesExt::LoadAfterTypeData(RulesClass* pThis, CCINIClass* pINI)
4950
{
51+
for (const auto& pTechnoType : TechnoTypeClass::Array)
52+
{
53+
if (const auto pTechnoTypeExt = TechnoTypeExt::ExtMap.Find(pTechnoType))
54+
{
55+
// Spawner range
56+
if (pTechnoTypeExt->Spawner_LimitRange)
57+
pTechnoTypeExt->CalculateSpawnerRange();
58+
}
59+
}
60+
5061
if (pINI == CCINIClass::INI_Rules)
5162
Data->InitializeAfterTypeData(pThis);
5263

@@ -66,11 +77,6 @@ void RulesExt::ExtData::LoadFromINIFile(CCINIClass* pINI)
6677

6778
void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
6879
{
69-
RulesExt::ExtData* pData = RulesExt::Global();
70-
71-
if (!pData)
72-
return;
73-
7480
INI_EX exINI(pINI);
7581

7682
this->Storage_TiberiumIndex.Read(exINI, GameStrings::General, "Storage.TiberiumIndex");
@@ -316,26 +322,29 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
316322
}
317323
}
318324

319-
// this runs between the before and after type data loading methods for rules ini
320-
void RulesExt::ExtData::InitializeAfterTypeData(RulesClass* const pThis)
321-
{
322-
// tint color
323-
this->TintColorIronCurtain = GeneralUtils::GetColorFromColorAdd(RulesClass::Instance->IronCurtainColor);
324-
this->TintColorForceShield = GeneralUtils::GetColorFromColorAdd(RulesClass::Instance->ForceShieldColor);
325-
this->TintColorBerserk = GeneralUtils::GetColorFromColorAdd(RulesClass::Instance->BerserkColor);
326-
}
327-
328325
// this should load everything that TypeData is not dependant on
329326
// i.e. InfantryElectrocuted= can go here since nothing refers to it
330327
// but [GenericPrerequisites] have to go earlier because they're used in parsing TypeData
331328
void RulesExt::ExtData::LoadAfterTypeData(RulesClass* pThis, CCINIClass* pINI)
332329
{
333-
RulesExt::ExtData* pData = RulesExt::Global();
330+
INI_EX exINI(pINI);
334331

335-
if (!pData)
336-
return;
332+
}
337333

338-
INI_EX exINI(pINI);
334+
// this runs between the before and after type data loading methods for rules ini
335+
void RulesExt::ExtData::InitializeAfterTypeData(RulesClass* const pThis)
336+
{
337+
338+
}
339+
340+
void RulesExt::ExtData::InitializeAfterAllLoaded()
341+
{
342+
const auto pRules = RulesClass::Instance;
343+
344+
// tint color
345+
this->TintColorIronCurtain = GeneralUtils::GetColorFromColorAdd(pRules->IronCurtainColor);
346+
this->TintColorForceShield = GeneralUtils::GetColorFromColorAdd(pRules->ForceShieldColor);
347+
this->TintColorBerserk = GeneralUtils::GetColorFromColorAdd(pRules->BerserkColor);
339348
}
340349

341350
// =============================
@@ -657,6 +666,12 @@ DEFINE_HOOK(0x679CAF, RulesData_LoadAfterTypeData, 0x5)
657666
return 0;
658667
}
659668

669+
DEFINE_HOOK(0x668F6A, RulesData_InitializeAfterAllLoaded, 0x5)
670+
{
671+
RulesExt::Global()->InitializeAfterAllLoaded();
672+
return 0;
673+
}
674+
660675
// Reenable obsolete [JumpjetControls] in RA2/YR
661676
// Author: Uranusian
662677
DEFINE_HOOK(0x7115AE, TechnoTypeClass_CTOR_JumpjetControls, 0xA)

src/Ext/Rules/Body.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ class RulesExt
423423
virtual void LoadAfterTypeData(RulesClass* pThis, CCINIClass* pINI);
424424
virtual void InitializeConstants() override;
425425
void InitializeAfterTypeData(RulesClass* pThis);
426+
void InitializeAfterAllLoaded();
426427

427428
virtual void InvalidatePointer(void* ptr, bool bRemoved) override { }
428429

src/Ext/SWType/Body.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,10 @@ void SWTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
9494
{
9595
auto pThis = this->OwnerObject();
9696
const char* pSection = pThis->ID;
97-
98-
if (!pINI->GetSection(pSection))
99-
{
100-
return;
101-
}
97+
INI_EX exINI(pINI);
10298

10399
this->TypeID.Read(pINI, pSection, "Type");
104100

105-
INI_EX exINI(pINI);
106-
107101
// from ares
108102
this->Money_Amount.Read(exINI, pSection, "Money.Amount");
109103
this->EVA_Impatient.Read(exINI, pSection, "EVA.Impatient");
@@ -334,7 +328,7 @@ DEFINE_HOOK(0x6CE8EA, SuperWeaponTypeClass_Save_Suffix, 0x3)
334328
return 0;
335329
}
336330

337-
DEFINE_HOOK_AGAIN(0x6CEE50, SuperWeaponTypeClass_LoadFromINI, 0xA)
331+
//DEFINE_HOOK_AGAIN(0x6CEE50, SuperWeaponTypeClass_LoadFromINI, 0xA)// Section dont exist!
338332
DEFINE_HOOK(0x6CEE43, SuperWeaponTypeClass_LoadFromINI, 0xA)
339333
{
340334
GET(SuperWeaponTypeClass*, pItem, EBP);

src/Ext/Side/Body.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ void SideExt::ExtData::LoadFromINIFile(CCINIClass* pINI)
1818
const char* pSection = pThis->ID;
1919

2020
if (!pINI->GetSection(pSection))
21-
{
2221
return;
23-
}
2422

2523
INI_EX exINI(pINI);
2624
this->Sidebar_GDIPositions.Read(exINI, pSection, "Sidebar.GDIPositions");

0 commit comments

Comments
 (0)