From feff0e8a6b582d65c6f8ec5940039ff34ad3ae6c Mon Sep 17 00:00:00 2001 From: Otamaa Date: Mon, 8 Nov 2021 23:19:18 +0700 Subject: [PATCH 1/4] InitFeatures --- src/Ext/TerrainType/Body.cpp | 15 ++++++++++++++- src/Ext/TerrainType/Body.h | 7 +++++++ src/Ext/TerrainType/Hooks.cpp | 27 ++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Ext/TerrainType/Body.cpp b/src/Ext/TerrainType/Body.cpp index 95664371bb..62dc0abe1e 100644 --- a/src/Ext/TerrainType/Body.cpp +++ b/src/Ext/TerrainType/Body.cpp @@ -27,6 +27,9 @@ void TerrainTypeExt::ExtData::Serialize(T& Stm) .Process(this->SpawnsTiberium_Range) .Process(this->SpawnsTiberium_GrowthStage) .Process(this->SpawnsTiberium_CellsPerAnim) + .Process(this->DestroyAnim) + .Process(this->DestroySound) + .Process(this->TerrainStrength) ; } @@ -43,6 +46,10 @@ void TerrainTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->SpawnsTiberium_Range.Read(exINI, pSection, "SpawnsTiberium.Range"); this->SpawnsTiberium_GrowthStage.Read(exINI, pSection, "SpawnsTiberium.GrowthStage"); this->SpawnsTiberium_CellsPerAnim.Read(exINI, pSection, "SpawnsTiberium.CellsPerAnim"); + + this->DestroyAnim.Read(exINI, pSection, "DestroyAnim"); + this->DestroySound.Read(exINI, pSection, "DestroySound"); + this->TerrainStrength.Read(exINI, pSection, "Strength"); } void TerrainTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm) @@ -121,7 +128,10 @@ DEFINE_HOOK(0x71E25A, TerrainTypeClass_Save_Suffix, 0x5) return 0; } - + +//skip strength +DEFINE_LJMP(0x71DEC8, 0x71DEE2) + DEFINE_HOOK(0x71E0A6, TerrainTypeClass_LoadFromINI, 0x5) { GET(TerrainTypeClass*, pItem, ESI); @@ -129,6 +139,9 @@ DEFINE_HOOK(0x71E0A6, TerrainTypeClass_LoadFromINI, 0x5) TerrainTypeExt::ExtMap.LoadFromINI(pItem, pINI); + if (pItem->Strength == -1) + pItem->Strength = TerrainTypeExt::ExtMap.Find(pItem)->TerrainStrength.Get(RulesClass::Instance->TreeStrength); + return 0; } diff --git a/src/Ext/TerrainType/Body.h b/src/Ext/TerrainType/Body.h index d6f1f8b2bb..04d35c61f9 100644 --- a/src/Ext/TerrainType/Body.h +++ b/src/Ext/TerrainType/Body.h @@ -4,6 +4,7 @@ #include #include #include +#include class TerrainTypeExt { @@ -17,12 +18,18 @@ class TerrainTypeExt Valueable SpawnsTiberium_Range; Valueable SpawnsTiberium_GrowthStage; Valueable SpawnsTiberium_CellsPerAnim; + Valueable DestroyAnim; + ValueableIdx DestroySound; + Nullable TerrainStrength; ExtData(TerrainTypeClass* OwnerObject) : Extension(OwnerObject) , SpawnsTiberium_Type { 0 } , SpawnsTiberium_Range { 1 } , SpawnsTiberium_GrowthStage { { 3, 0 } } , SpawnsTiberium_CellsPerAnim { { 1, 0 } } + , DestroyAnim(nullptr) + , DestroySound(-1) + , TerrainStrength() { } virtual ~ExtData() = default; diff --git a/src/Ext/TerrainType/Hooks.cpp b/src/Ext/TerrainType/Hooks.cpp index 80ffe52407..4cd440c7c5 100644 --- a/src/Ext/TerrainType/Hooks.cpp +++ b/src/Ext/TerrainType/Hooks.cpp @@ -3,9 +3,11 @@ #include #include #include +#include +#include +#include #include -#include namespace TerrainTypeTemp { @@ -90,4 +92,27 @@ DEFINE_HOOK(0x71C8D7, TerrainTypeClass_Context_Unset, 0x5) TerrainTypeTemp::pCurrentExt = nullptr; return 0; +} + +//this one on Very end of it +//let everything play first +DEFINE_HOOK(0x71BB2C, TerrainClass_TakeDamage_NowDead_Add, 0x6) +{ + GET(TerrainClass*, pThis, ESI); + //saved for later usage ! + //REF_STACK(args_ReceiveDamage const, ReceiveDamageArgs, STACK_OFFS(0x3C, -0x4)); + + if (auto const pTerrainExt = TerrainTypeExt::ExtMap.Find(pThis->Type)) + { + auto const nCoords = pThis->GetCoords(); + auto const nSoundIndex = pTerrainExt->DestroySound.Get(); + + if (nSoundIndex != -1) + VocClass::PlayIndexAtPos(nSoundIndex, nCoords); + + if (auto const pAnimType = pTerrainExt->DestroyAnim.Get()) + GameCreate(pAnimType, nCoords); + } + + return 0; } \ No newline at end of file From d183e294eff7ae3cad4236e41e7a8c7b35e98294 Mon Sep 17 00:00:00 2001 From: Otamaa Date: Sat, 13 Nov 2021 21:36:25 +0700 Subject: [PATCH 2/4] `Strength` removed it is already part of `ObjectTypeClass::ReadINI` --- src/Ext/TerrainType/Body.cpp | 14 ++++---------- src/Ext/TerrainType/Body.h | 2 -- src/Ext/TerrainType/Hooks.cpp | 3 +-- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Ext/TerrainType/Body.cpp b/src/Ext/TerrainType/Body.cpp index 62dc0abe1e..e118b2063d 100644 --- a/src/Ext/TerrainType/Body.cpp +++ b/src/Ext/TerrainType/Body.cpp @@ -29,7 +29,6 @@ void TerrainTypeExt::ExtData::Serialize(T& Stm) .Process(this->SpawnsTiberium_CellsPerAnim) .Process(this->DestroyAnim) .Process(this->DestroySound) - .Process(this->TerrainStrength) ; } @@ -49,7 +48,9 @@ void TerrainTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->DestroyAnim.Read(exINI, pSection, "DestroyAnim"); this->DestroySound.Read(exINI, pSection, "DestroySound"); - this->TerrainStrength.Read(exINI, pSection, "Strength"); + + //Strength is already part of ObjecTypeClass::ReadIni Duh! + //this->TerrainStrength.Read(exINI, pSection, "Strength"); } void TerrainTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm) @@ -80,7 +81,6 @@ bool TerrainTypeExt::SaveGlobals(PhobosStreamWriter& Stm) // container TerrainTypeExt::ExtContainer::ExtContainer() : Container("TerrainTypeClass") { } - TerrainTypeExt::ExtContainer::~ExtContainer() = default; // ============================= @@ -127,10 +127,7 @@ DEFINE_HOOK(0x71E25A, TerrainTypeClass_Save_Suffix, 0x5) TerrainTypeExt::ExtMap.SaveStatic(); return 0; -} - -//skip strength -DEFINE_LJMP(0x71DEC8, 0x71DEE2) +} DEFINE_HOOK(0x71E0A6, TerrainTypeClass_LoadFromINI, 0x5) { @@ -139,9 +136,6 @@ DEFINE_HOOK(0x71E0A6, TerrainTypeClass_LoadFromINI, 0x5) TerrainTypeExt::ExtMap.LoadFromINI(pItem, pINI); - if (pItem->Strength == -1) - pItem->Strength = TerrainTypeExt::ExtMap.Find(pItem)->TerrainStrength.Get(RulesClass::Instance->TreeStrength); - return 0; } diff --git a/src/Ext/TerrainType/Body.h b/src/Ext/TerrainType/Body.h index 04d35c61f9..c4150b79f4 100644 --- a/src/Ext/TerrainType/Body.h +++ b/src/Ext/TerrainType/Body.h @@ -20,7 +20,6 @@ class TerrainTypeExt Valueable SpawnsTiberium_CellsPerAnim; Valueable DestroyAnim; ValueableIdx DestroySound; - Nullable TerrainStrength; ExtData(TerrainTypeClass* OwnerObject) : Extension(OwnerObject) , SpawnsTiberium_Type { 0 } @@ -29,7 +28,6 @@ class TerrainTypeExt , SpawnsTiberium_CellsPerAnim { { 1, 0 } } , DestroyAnim(nullptr) , DestroySound(-1) - , TerrainStrength() { } virtual ~ExtData() = default; diff --git a/src/Ext/TerrainType/Hooks.cpp b/src/Ext/TerrainType/Hooks.cpp index 4cd440c7c5..b019a8b810 100644 --- a/src/Ext/TerrainType/Hooks.cpp +++ b/src/Ext/TerrainType/Hooks.cpp @@ -94,8 +94,7 @@ DEFINE_HOOK(0x71C8D7, TerrainTypeClass_Context_Unset, 0x5) return 0; } -//this one on Very end of it -//let everything play first +//This one on Very end of it , let everything play first DEFINE_HOOK(0x71BB2C, TerrainClass_TakeDamage_NowDead_Add, 0x6) { GET(TerrainClass*, pThis, ESI); From 19beaae2b70c8eda4697682b1d90acfb91ca2ea5 Mon Sep 17 00:00:00 2001 From: Otamaa Date: Sun, 30 Jan 2022 17:09:33 +0700 Subject: [PATCH 3/4] Style Fix --- src/Ext/TerrainType/Body.h | 8 ++++---- src/Ext/TerrainType/Hooks.cpp | 7 ++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Ext/TerrainType/Body.h b/src/Ext/TerrainType/Body.h index c4150b79f4..88f879d6cd 100644 --- a/src/Ext/TerrainType/Body.h +++ b/src/Ext/TerrainType/Body.h @@ -18,16 +18,16 @@ class TerrainTypeExt Valueable SpawnsTiberium_Range; Valueable SpawnsTiberium_GrowthStage; Valueable SpawnsTiberium_CellsPerAnim; - Valueable DestroyAnim; - ValueableIdx DestroySound; + Nullable DestroyAnim; + NullableIdx DestroySound; ExtData(TerrainTypeClass* OwnerObject) : Extension(OwnerObject) , SpawnsTiberium_Type { 0 } , SpawnsTiberium_Range { 1 } , SpawnsTiberium_GrowthStage { { 3, 0 } } , SpawnsTiberium_CellsPerAnim { { 1, 0 } } - , DestroyAnim(nullptr) - , DestroySound(-1) + , DestroyAnim() + , DestroySound() { } virtual ~ExtData() = default; diff --git a/src/Ext/TerrainType/Hooks.cpp b/src/Ext/TerrainType/Hooks.cpp index b019a8b810..998f730f6e 100644 --- a/src/Ext/TerrainType/Hooks.cpp +++ b/src/Ext/TerrainType/Hooks.cpp @@ -104,12 +104,9 @@ DEFINE_HOOK(0x71BB2C, TerrainClass_TakeDamage_NowDead_Add, 0x6) if (auto const pTerrainExt = TerrainTypeExt::ExtMap.Find(pThis->Type)) { auto const nCoords = pThis->GetCoords(); - auto const nSoundIndex = pTerrainExt->DestroySound.Get(); + VocClass::PlayIndexAtPos(pTerrainExt->DestroySound.Get(-1), nCoords); - if (nSoundIndex != -1) - VocClass::PlayIndexAtPos(nSoundIndex, nCoords); - - if (auto const pAnimType = pTerrainExt->DestroyAnim.Get()) + if (auto const pAnimType = pTerrainExt->DestroyAnim.Get(nullptr)) GameCreate(pAnimType, nCoords); } From 782d5ea9a5c3d5cb3754fedbbb4571851350141a Mon Sep 17 00:00:00 2001 From: Starkku Date: Sun, 30 Jan 2022 13:19:50 +0200 Subject: [PATCH 4/4] Further style fix. --- src/Ext/TerrainType/Body.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ext/TerrainType/Body.h b/src/Ext/TerrainType/Body.h index 88f879d6cd..716da1887d 100644 --- a/src/Ext/TerrainType/Body.h +++ b/src/Ext/TerrainType/Body.h @@ -26,8 +26,8 @@ class TerrainTypeExt , SpawnsTiberium_Range { 1 } , SpawnsTiberium_GrowthStage { { 3, 0 } } , SpawnsTiberium_CellsPerAnim { { 1, 0 } } - , DestroyAnim() - , DestroySound() + , DestroyAnim {} + , DestroySound {} { } virtual ~ExtData() = default;