From 0d45f2fc23b5479f575022739b6d6a7457e8a53c Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Thu, 27 Jun 2019 01:30:59 +0300 Subject: Added Gangs --- src/control/Gangs.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/control/Gangs.h | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 src/control/Gangs.cpp create mode 100644 src/control/Gangs.h (limited to 'src/control') diff --git a/src/control/Gangs.cpp b/src/control/Gangs.cpp new file mode 100644 index 00000000..2cb8a8a1 --- /dev/null +++ b/src/control/Gangs.cpp @@ -0,0 +1,71 @@ +#include "common.h" +#include "patcher.h" +#include "Gangs.h" + +CGangInfo(&CGangs::Gang)[TOTAL_GANGS] = *(CGangInfo(*)[9])*(uintptr*)0x6EDF78; + +void CGangs::Initialize(void) +{ + Gang[GANG_MAFIA].m_nVehicleMI = MI_MAFIA; + Gang[GANG_TRIAD].m_nVehicleMI = MI_BELLYUP; + Gang[GANG_DIABLOS].m_nVehicleMI = MI_DIABLOS; + Gang[GANG_YAKUZA].m_nVehicleMI = MI_YAKUZA; + Gang[GANG_YARDIE].m_nVehicleMI = MI_YARDIE; + Gang[GANG_COLUMB].m_nVehicleMI = MI_COLUMB; + Gang[GANG_HOODS].m_nVehicleMI = MI_HOODS; + Gang[GANG_7].m_nVehicleMI = -1; + Gang[GANG_8].m_nVehicleMI = -1; +} + +void CGangs::SetGangVehicleModel(int16 gang, int model) +{ + GetGangInfo(gang)->m_nVehicleMI = model; +} + +void CGangs::SetGangWeapons(int16 gang, eWeaponType weapon1, eWeaponType weapon2) +{ + CGangInfo *gi = GetGangInfo(gang); + gi->m_Weapon1 = weapon1; + gi->m_Weapon2 = weapon2; +} + +void CGangs::SetGangPedModelOverride(int16 gang, int8 ovrd) +{ + GetGangInfo(gang)->m_nPedModelOverride = ovrd; +} + +int8 CGangs::GetGangPedModelOverride(int16 gang) +{ + return GetGangInfo(gang)->m_nPedModelOverride; +} + +void CGangs::SaveAllGangData(uint8 *buffer, uint32 *size) +{ + tGangSaveData *data = (tGangSaveData*)buffer; + data->tag[0] = 'G'; + data->tag[1] = 'N'; + data->tag[2] = 'G'; + data->tag[3] = '\0'; + data->size = *size = sizeof(tGangSaveData); + for (int i = 0; i < TOTAL_GANGS; i++) + data->gangs[i] = *GetGangInfo(i); + buffer += sizeof(tGangSaveData); +} + +void CGangs::LoadAllGangData(uint8 *buffer, uint32 size) +{ + Initialize(); + tGangSaveData* data = (tGangSaveData*)buffer; + for (int i = 0; i < TOTAL_GANGS; i++) + *GetGangInfo(i) = data->gangs[i]; +} + +STARTPATCHES +InjectHook(0x4C3FB0, CGangs::Initialize, PATCH_JUMP); +InjectHook(0x4C4010, CGangs::SetGangVehicleModel, PATCH_JUMP); +InjectHook(0x4C4030, CGangs::SetGangWeapons, PATCH_JUMP); +InjectHook(0x4C4050, CGangs::SetGangPedModelOverride, PATCH_JUMP); +InjectHook(0x4C4070, CGangs::GetGangPedModelOverride, PATCH_JUMP); +InjectHook(0x4C4080, CGangs::SaveAllGangData, PATCH_JUMP); +InjectHook(0x4C4100, CGangs::LoadAllGangData, PATCH_JUMP); +ENDPATCHES diff --git a/src/control/Gangs.h b/src/control/Gangs.h new file mode 100644 index 00000000..1d735cfe --- /dev/null +++ b/src/control/Gangs.h @@ -0,0 +1,62 @@ +#pragma once + +#include "common.h" +#include "Weapon.h" +#include "ModelIndices.h" + +struct CGangInfo +{ + int32 m_nVehicleMI; + int8 m_nPedModelOverride; + int8 field_5; + int16 field_6; + eWeaponType m_Weapon1; + eWeaponType m_Weapon2; + + CGangInfo() : + m_nVehicleMI(MI_BUS), + m_nPedModelOverride(-1), + m_Weapon1(WEAPONTYPE_UNARMED), + m_Weapon2(WEAPONTYPE_UNARMED) + {} +}; + +static_assert(sizeof(CGangInfo) == 0x10, "CGangInfo: error"); + +class CGangs +{ +public: + enum { + GANG_MAFIA = 0, + GANG_TRIAD, + GANG_DIABLOS, + GANG_YAKUZA, + GANG_YARDIE, + GANG_COLUMB, + GANG_HOODS, + GANG_7, + GANG_8, + TOTAL_GANGS + }; + static void Initialize(void); + static void SetGangVehicleModel(int16, int); + static void SetGangWeapons(int16, eWeaponType, eWeaponType); + static void SetGangPedModelOverride(int16, int8); + static int8 GetGangPedModelOverride(int16); + static void SaveAllGangData(uint8 *, uint32 *); + static void LoadAllGangData(uint8 *, uint32); + +private: + static CGangInfo* GetGangInfo(int16 gang) { return &Gang[gang]; } + + static CGangInfo(&Gang)[TOTAL_GANGS]; +}; + +struct tGangSaveData +{ + char tag[4]; + int32 size; + CGangInfo gangs[CGangs::TOTAL_GANGS]; +}; + +static_assert(sizeof(tGangSaveData) == 0x98, "tGangSaveData: error"); \ No newline at end of file -- cgit v1.2.3 From 969d4ac48d20f641a90e0b61105ec65766c52c3d Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Thu, 27 Jun 2019 01:33:46 +0300 Subject: fixed newline --- src/control/Gangs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/control') diff --git a/src/control/Gangs.h b/src/control/Gangs.h index 1d735cfe..96066a3e 100644 --- a/src/control/Gangs.h +++ b/src/control/Gangs.h @@ -59,4 +59,4 @@ struct tGangSaveData CGangInfo gangs[CGangs::TOTAL_GANGS]; }; -static_assert(sizeof(tGangSaveData) == 0x98, "tGangSaveData: error"); \ No newline at end of file +static_assert(sizeof(tGangSaveData) == 0x98, "tGangSaveData: error"); -- cgit v1.2.3 From 1c7fee4b9fc1684f83b62705573a34218b3159d3 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Thu, 27 Jun 2019 23:45:06 +0300 Subject: Changed save/load in CGang --- src/control/Gangs.cpp | 46 +++++++++++++++++++++++++++++++++------------- src/control/Gangs.h | 13 ++----------- 2 files changed, 35 insertions(+), 24 deletions(-) (limited to 'src/control') diff --git a/src/control/Gangs.cpp b/src/control/Gangs.cpp index 2cb8a8a1..80ecd816 100644 --- a/src/control/Gangs.cpp +++ b/src/control/Gangs.cpp @@ -2,7 +2,7 @@ #include "patcher.h" #include "Gangs.h" -CGangInfo(&CGangs::Gang)[TOTAL_GANGS] = *(CGangInfo(*)[9])*(uintptr*)0x6EDF78; +CGangInfo(&CGangs::Gang)[NUM_GANGS] = *(CGangInfo(*)[9])*(uintptr*)0x6EDF78; void CGangs::Initialize(void) { @@ -41,23 +41,43 @@ int8 CGangs::GetGangPedModelOverride(int16 gang) void CGangs::SaveAllGangData(uint8 *buffer, uint32 *size) { - tGangSaveData *data = (tGangSaveData*)buffer; - data->tag[0] = 'G'; - data->tag[1] = 'N'; - data->tag[2] = 'G'; - data->tag[3] = '\0'; - data->size = *size = sizeof(tGangSaveData); - for (int i = 0; i < TOTAL_GANGS; i++) - data->gangs[i] = *GetGangInfo(i); - buffer += sizeof(tGangSaveData); + buffer[0] = 'G'; + buffer[1] = 'N'; + buffer[2] = 'G'; + buffer[3] = '\0'; + *size = 8 + NUM_GANGS * 16; + *(uint32*)(buffer + 4) = *size - 8; + buffer += 8; + for (int i = 0; i < NUM_GANGS; i++) { + *(uint32*)(buffer) = GetGangInfo(i)->m_nVehicleMI; + *(int8*)(buffer + 4) = GetGangInfo(i)->m_nPedModelOverride; + *(int8*)(buffer + 5) = GetGangInfo(i)->field_5; + *(int16*)(buffer + 6) = GetGangInfo(i)->field_6; + *(eWeaponType*)(buffer + 8) = GetGangInfo(i)->m_Weapon1; + *(eWeaponType*)(buffer + 12) = GetGangInfo(i)->m_Weapon2; + buffer += 16; + } } void CGangs::LoadAllGangData(uint8 *buffer, uint32 size) { Initialize(); - tGangSaveData* data = (tGangSaveData*)buffer; - for (int i = 0; i < TOTAL_GANGS; i++) - *GetGangInfo(i) = data->gangs[i]; + assert(size == 8 + NUM_GANGS * 16); + assert(buffer[0] == 'G'); + assert(buffer[1] == 'N'); + assert(buffer[2] == 'G'); + assert(buffer[3] == '\0'); + assert(*(uint32*)(buffer + 4) == size - 8); + buffer += 8; + for (int i = 0; i < NUM_GANGS; i++){ + GetGangInfo(i)->m_nVehicleMI = *(uint32*)(buffer); + GetGangInfo(i)->m_nPedModelOverride = *(int8*)(buffer + 4); + GetGangInfo(i)->field_5 = *(int8*)(buffer + 5); + GetGangInfo(i)->field_6 = *(int16*)(buffer + 6); + GetGangInfo(i)->m_Weapon1 = *(eWeaponType*)(buffer + 8); + GetGangInfo(i)->m_Weapon2 = *(eWeaponType*)(buffer + 12); + buffer += 16; + } } STARTPATCHES diff --git a/src/control/Gangs.h b/src/control/Gangs.h index 96066a3e..db14ca64 100644 --- a/src/control/Gangs.h +++ b/src/control/Gangs.h @@ -36,7 +36,7 @@ public: GANG_HOODS, GANG_7, GANG_8, - TOTAL_GANGS + NUM_GANGS }; static void Initialize(void); static void SetGangVehicleModel(int16, int); @@ -49,14 +49,5 @@ public: private: static CGangInfo* GetGangInfo(int16 gang) { return &Gang[gang]; } - static CGangInfo(&Gang)[TOTAL_GANGS]; + static CGangInfo(&Gang)[NUM_GANGS]; }; - -struct tGangSaveData -{ - char tag[4]; - int32 size; - CGangInfo gangs[CGangs::TOTAL_GANGS]; -}; - -static_assert(sizeof(tGangSaveData) == 0x98, "tGangSaveData: error"); -- cgit v1.2.3