Skip to content

Commit

Permalink
Add CrateTypeClass
Browse files Browse the repository at this point in the history
  • Loading branch information
ZivDero committed Dec 5, 2024
1 parent 11c7911 commit 91faad5
Show file tree
Hide file tree
Showing 34 changed files with 2,033 additions and 641 deletions.
2 changes: 1 addition & 1 deletion src/extensions/aircraft/aircraftext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
* A fake class for implementing new member functions which allow
* access to the "this" pointer of the intended class.
*
* @note: This must not contain a constructor or deconstructor!
* @note: This must not contain a constructor or destructor!
* @note: All functions must be prefixed with "_" to prevent accidental virtualization.
*/
static class AircraftClassExt final : public AircraftClass
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/building/buildingext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* A fake class for implementing new member functions which allow
* access to the "this" pointer of the intended class.
*
* @note: This must not contain a constructor or deconstructor!
* @note: This must not contain a constructor or destructor!
* @note: All functions must be prefixed with "_" to prevent accidental virtualization.
*/
static class BuildingClassExt final : public BuildingClass
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/bullet/bulletext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* A fake class for implementing new member functions which allow
* access to the "this" pointer of the intended class.
*
* @note: This must not contain a constructor or deconstructor!
* @note: This must not contain a constructor or destructor!
* @note: All functions must be prefixed with "_" to prevent accidental virtualization.
*/
static class BulletClassExt final : public BulletClass
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/cargo/cargoext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* A fake class for implementing new member functions which allow
* access to the "this" pointer of the intended class.
*
* @note: This must not contain a constructor or deconstructor!
* @note: This must not contain a constructor or destructor!
* @note: All functions must be prefixed with "_" to prevent accidental virtualization.
*/
static class CargoClassExt final : public CargoClass
Expand Down
46 changes: 46 additions & 0 deletions src/extensions/ccini/cciniext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "fatal.h"
#include "debughandler.h"
#include "asserthandler.h"
#include "cratetype.h"

#include "hooker.h"
#include "hooker_macros.h"
Expand All @@ -64,6 +65,10 @@ static class CCINIClassExt final : public CCINIClass
ArmorType _Get_ArmorType(const char *section, const char *entry, const ArmorType defvalue);
bool _Put_ArmorType(const char *section, const char *entry, ArmorType value);


CrateType _Get_CrateType(const char *section, const char *entry, const CrateType defvalue);
bool _Put_CrateType(const char *section, const char *entry, CrateType value);

ActionType _Get_ActionType(const char *section, const char *entry, const ActionType defvalue);
};

Expand Down Expand Up @@ -255,6 +260,45 @@ bool CCINIClassExt::_Put_ArmorType(const char *section, const char *entry, Armor
}


/**
* Fetches the crate type from the INI database.
*
* @author: ZivDero
*/
CrateType CCINIClassExt::_Get_CrateType(const char *section, const char *entry, const CrateType defvalue)
{
char buffer[1024];

if (INIClass::Get_String(section, entry, nullptr, buffer, sizeof(buffer)) > 0) {

/**
* Vanilla crate names need to be preserved even
* if the crates have been renamed (which we do).
*/
for (int i = 0; i < CRATE_COUNT; i++) {
if (std::strcmp(buffer, CrateNames[i]) == 0) {
return static_cast<CrateType>(i);
}
}

return CrateTypeClass::From_Name(buffer);
}

return defvalue;
}


/**
* Store the crate type to the INI database.
*
* @author: ZivDero
*/
bool CCINIClassExt::_Put_CrateType(const char *section, const char *entry, CrateType value)
{
return Put_String(section, entry, CrateTypeClass::Name_From(value));
}


/**
* #issue-391
*
Expand Down Expand Up @@ -311,6 +355,8 @@ void CCINIClassExtension_Hooks()
Patch_Jump(0x0044B360, &CCINIClassExt::_Put_TheaterType);
Patch_Jump(0x0044AF50, &CCINIClassExt::_Get_ArmorType);
Patch_Jump(0x0044AFA0, &CCINIClassExt::_Put_ArmorType);
Patch_Jump(0x0044B490, &CCINIClassExt::_Get_CrateType);
Patch_Jump(0x0044B4E0, &CCINIClassExt::_Put_CrateType);

// Put this here as it was only called in INIClass::Get_ArmorType.
Patch_Jump(0x00681320, &ArmorTypeClass::From_Name);
Expand Down
Loading

0 comments on commit 91faad5

Please sign in to comment.