From 405db740ee9b0c31136cd3f5a556c260d3dc7b19 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Mon, 8 Jul 2024 12:10:11 -0600 Subject: [PATCH] Fix more bugs --- src/features/mgr.cpp | 13 ++++-- src/features/vehicle/indicators.cpp | 2 +- src/features/vehicle/lights.cpp | 6 +-- src/features/vehicle/sirens.cpp | 5 +- src/features/vehicle/spotlights.cpp | 2 +- src/features/weapon/bodystate.cpp | 72 ++++++++++++++--------------- src/pch.h | 5 +- 7 files changed, 54 insertions(+), 51 deletions(-) diff --git a/src/features/mgr.cpp b/src/features/mgr.cpp index d3aaba8..9634112 100644 --- a/src/features/mgr.cpp +++ b/src/features/mgr.cpp @@ -49,8 +49,8 @@ void FeatureMgr::Initialize() { CTaskSimpleJetPack *pTask = pPed->m_pIntelligence->GetTaskJetPack(); if (pTask && pTask->m_pJetPackClump) { Add(static_cast(&pPed->m_aWeapons[pPed->m_nActiveWeaponSlot]), - (RwFrame *)pTask->m_pJetPackClump->object.parent, eModelEntityType::Weapon); - Process(static_cast(&pPed->m_aWeapons[pPed->m_nActiveWeaponSlot]), eModelEntityType::Weapon); + (RwFrame *)pTask->m_pJetPackClump->object.parent, eModelEntityType::Jetpack); + Process(static_cast(&pPed->m_aWeapons[pPed->m_nActiveWeaponSlot]), eModelEntityType::Jetpack); } // weapons @@ -58,7 +58,7 @@ void FeatureMgr::Initialize() { if (pWeapon) { eWeaponType weaponType = pWeapon->m_eWeaponType; CWeaponInfo* pWeaponInfo = CWeaponInfo::GetWeaponInfo(weaponType, pPed->GetWeaponSkill(weaponType)); - if (pWeaponInfo) { + if (pWeaponInfo && pWeaponInfo->m_nModelId1 > 0) { CWeaponModelInfo* pWeaponModelInfo = static_cast(CModelInfo::GetModelInfo(pWeaponInfo->m_nModelId1)); if (pWeaponModelInfo && pWeaponModelInfo->m_pRwClump) { Add(static_cast(&pPed->m_aWeapons[pPed->m_nActiveWeaponSlot]), @@ -167,6 +167,8 @@ void FeatureMgr::Add(void *ptr, RwFrame* frame, eModelEntityType type) { int model = 0; if (type == eModelEntityType::Weapon) { model = static_cast(ptr)->m_eWeaponType; + } else if (type == eModelEntityType::Jetpack) { + model = 370; } else { model = static_cast(ptr)->m_nModelIndex; } @@ -180,6 +182,8 @@ void FeatureMgr::Process(void *ptr, eModelEntityType type) { int model = 0; if (type == eModelEntityType::Weapon) { model = static_cast(ptr)->m_eWeaponType; + } else if (type == eModelEntityType::Jetpack) { + model = 370; } else { model = static_cast(ptr)->m_nModelIndex; } @@ -189,5 +193,4 @@ void FeatureMgr::Process(void *ptr, eModelEntityType type) { m_FunctionTable[e.id](ptr, e.m_pFrame, type); } } -} - +} \ No newline at end of file diff --git a/src/features/vehicle/indicators.cpp b/src/features/vehicle/indicators.cpp index d6d221a..e2b8159 100644 --- a/src/features/vehicle/indicators.cpp +++ b/src/features/vehicle/indicators.cpp @@ -14,7 +14,7 @@ CVector2D GetCarPathLinkPosition(CCarPathLinkAddress &address) { void DrawTurnlight(CVehicle *pVeh, eDummyPos pos, bool leftSide) { int idx = pos == eDummyPos::Front ? 0 : 1; CVector posn = - reinterpret_cast(CModelInfo::ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[idx]; + reinterpret_cast(CModelInfo__ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[idx]; if (posn.x == 0.0f) posn.x = 0.15f; if (leftSide) posn.x *= -1.0f; diff --git a/src/features/vehicle/lights.cpp b/src/features/vehicle/lights.cpp index 1ab64f4..369727a 100644 --- a/src/features/vehicle/lights.cpp +++ b/src/features/vehicle/lights.cpp @@ -132,7 +132,7 @@ void Lights::Initialize() { !automobile->m_damageManager.GetLightStatus(eLights::LIGHT_FRONT_RIGHT)) { if (data.m_bFogLightsOn && materials[model][eLightState::FogLight].size() != 0) { renderLights(pVeh, eLightState::FogLight, vehicleAngle, cameraAngle); - CVector posn = reinterpret_cast(CModelInfo::ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[0]; + CVector posn = reinterpret_cast(CModelInfo__ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[0]; posn.x = 0.0f; posn.y += 3.35f; @@ -175,14 +175,14 @@ void Lights::Initialize() { if (showTailLights) { if (!automobile->m_damageManager.GetLightStatus(eLights::LIGHT_REAR_LEFT)) { - CVector posn = reinterpret_cast(CModelInfo::ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[1]; + CVector posn = reinterpret_cast(CModelInfo__ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[1]; if (posn.x == 0.0f) posn.x = 0.15f; posn.x *= -1.0f; Common::RegisterShadow(pVeh, posn, TL_SHADOW_R, TL_SHADOW_G, TL_SHADOW_B, 180.0f, 0.0f); } if (!automobile->m_damageManager.GetLightStatus(eLights::LIGHT_REAR_RIGHT)) { - CVector posn = reinterpret_cast(CModelInfo::ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[1]; + CVector posn = reinterpret_cast(CModelInfo__ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[1]; if (posn.x == 0.0f) posn.x = 0.15f; Common::RegisterShadow(pVeh, posn, TL_SHADOW_R, TL_SHADOW_G, TL_SHADOW_B, 180.0f, 0.0f); } diff --git a/src/features/vehicle/sirens.cpp b/src/features/vehicle/sirens.cpp index 2a66189..b4c2e18 100644 --- a/src/features/vehicle/sirens.cpp +++ b/src/features/vehicle/sirens.cpp @@ -961,7 +961,7 @@ void VehicleSirens::enableMaterial(VehicleMaterial* material, VehicleSirenMateri }; void VehicleSirens::enableDummy(int id, VehicleSirenDummy* dummy, CVehicle* vehicle, float vehicleAngle, float cameraAngle, VehicleSirenMaterial* material, eCoronaFlareType type, uint64_t time) { - CVector position = reinterpret_cast(CModelInfo::ms_modelInfoPtrs[vehicle->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[0]; + CVector position = reinterpret_cast(CModelInfo__ms_modelInfoPtrs[vehicle->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[0]; position.x = dummy->Position.x; position.y = dummy->Position.y; @@ -1051,13 +1051,12 @@ void VehicleSirens::enableShadow(CVehicle* vehicle, VehicleSirenDummy* dummy, Ve alpha, material->Color.red, material->Color.green, material->Color.blue, 2.0f, false, 1.0f, 0, true); }; - VehicleSiren::VehicleSiren(CVehicle* _vehicle) { vehicle = _vehicle; int model = vehicle->m_nModelIndex; - CVehicleModelInfo* modelInfo = reinterpret_cast(CModelInfo::ms_modelInfoPtrs[model]); + CVehicleModelInfo* modelInfo = reinterpret_cast(CModelInfo__ms_modelInfoPtrs[model]); if (modelInfo->m_nVehicleType == eVehicleType::VEHICLE_HELI || modelInfo->m_nVehicleType == eVehicleType::VEHICLE_PLANE) this->Mute = true; diff --git a/src/features/vehicle/spotlights.cpp b/src/features/vehicle/spotlights.cpp index c2ba8ad..a92d124 100644 --- a/src/features/vehicle/spotlights.cpp +++ b/src/features/vehicle/spotlights.cpp @@ -115,7 +115,7 @@ void SpotLight::OnVehicleRender(CVehicle *pVeh) { 2.0f, 0.0f, 0.0f, 2.0f, 128, 128, 128, 0.0f);*/ - /*CVector Pos = CModelInfo::ms_modelInfoPtrs[Vehicle->m_nModelIndex]->m_pColModel->m_boundBox.m_vecMin; + /*CVector Pos = CModelInfo__ms_modelInfoPtrs[Vehicle->m_nModelIndex]->m_pColModel->m_boundBox.m_vecMin; CVector center = Vehicle->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f)); diff --git a/src/features/weapon/bodystate.cpp b/src/features/weapon/bodystate.cpp index a0c89e3..ea28533 100644 --- a/src/features/weapon/bodystate.cpp +++ b/src/features/weapon/bodystate.cpp @@ -10,45 +10,43 @@ void BodyState::Process(void* ptr, RwFrame* frame, eModelEntityType type) { CWeapon *pWeapon = static_cast(ptr); xData &data = wepData.Get(pWeapon); std::string name = GetFrameNodeName(frame); - if (NODE_FOUND(name, "x_body_state")) { - bool isMuscle = GetStatValue(23) == 1000; - bool isFat = GetStatValue(21) == 1000; - bool isSlim = !(isMuscle && isFat); - CPlayerPed *pPlayer = FindPlayerPed(); - if (!pPlayer) { - return; - } + bool isMuscle = GetStatValue(23) == 1000; + bool isFat = GetStatValue(21) == 1000; + bool isSlim = !(isMuscle && isFat); + CPlayerPed *pPlayer = FindPlayerPed(); + if (!pPlayer) { + return; + } - bool isPlus = false; - if (NODE_FOUND(name, "_zen")) { - bool isLarge = pPlayer->m_pPlayerData->m_pPedClothesDesc->m_anModelKeys[0] != 3139216588; // hoodyA model - bool isUniform = pPlayer->m_pPlayerData->m_pPedClothesDesc->m_anTextureKeys[17] != 0; // default outfit - isPlus = isLarge && !isUniform; - } + bool isPlus = false; + if (NODE_FOUND(name, "_zen")) { + bool isLarge = pPlayer->m_pPlayerData->m_pPedClothesDesc->m_anModelKeys[0] != 3139216588; // hoodyA model + bool isUniform = pPlayer->m_pPlayerData->m_pPedClothesDesc->m_anTextureKeys[17] != 0; // default outfit + isPlus = isLarge && !isUniform; + } - eBodyState bodyState = eBodyState::Slim; - if (isMuscle && isFat) bodyState = eBodyState::MuscleFat; - else if (isMuscle) bodyState = (isPlus? eBodyState::MusclePlus : eBodyState::Muscle); - else if (isFat) bodyState = (isPlus? eBodyState::FatPlus : eBodyState::Fat); - else if (isSlim) bodyState = (isPlus? eBodyState::SlimPlus : eBodyState::Slim); - - if (bodyState != data.prevBodyState) { - Util::HideAllChilds(frame); - if (isFat && isMuscle) { - Util::ShowChildWithName(frame, "muscle_fat"); - } - else if (isFat) { - Util::ShowChildWithName(frame, isPlus? "fat+" : "fat"); - } else if (isMuscle) { - Util::ShowChildWithName(frame, isPlus? "muscle+" : "muscle"); - } else if (isSlim) { - Util::ShowChildWithName(frame, isPlus? "slim+" : "slim"); - } - auto play = FindPlayerPed(); - if (play && play->m_nWeaponModelId == PARACHUTE_MODEL) { - plugin::Call<0x4395B0>(); - } - data.prevBodyState = bodyState; + eBodyState bodyState = eBodyState::Slim; + if (isMuscle && isFat) bodyState = eBodyState::MuscleFat; + else if (isMuscle) bodyState = (isPlus? eBodyState::MusclePlus : eBodyState::Muscle); + else if (isFat) bodyState = (isPlus? eBodyState::FatPlus : eBodyState::Fat); + else if (isSlim) bodyState = (isPlus? eBodyState::SlimPlus : eBodyState::Slim); + + if (bodyState != data.prevBodyState) { + Util::HideAllChilds(frame); + if (isFat && isMuscle) { + Util::ShowChildWithName(frame, "muscle_fat"); + } + else if (isFat) { + Util::ShowChildWithName(frame, isPlus? "fat+" : "fat"); + } else if (isMuscle) { + Util::ShowChildWithName(frame, isPlus? "muscle+" : "muscle"); + } else if (isSlim) { + Util::ShowChildWithName(frame, isPlus? "slim+" : "slim"); + } + auto play = FindPlayerPed(); + if (play && play->m_nWeaponModelId == PARACHUTE_MODEL) { + plugin::Call<0x4395B0>(); } + data.prevBodyState = bodyState; } } \ No newline at end of file diff --git a/src/pch.h b/src/pch.h index 9906228..bd0de3f 100644 --- a/src/pch.h +++ b/src/pch.h @@ -6,6 +6,8 @@ #include #include +#include + #include "bass.h" #include "json.hpp" #include "ini.hpp" @@ -21,6 +23,7 @@ enum class eModelEntityType { Object, Vehicle, Weapon, + Jetpack, }; #define MOD_DATA_PATH(x) PLUGIN_PATH((char*)("ModelExtras/"x)) @@ -51,7 +54,7 @@ static inline ThiscallEvent , PRIORITY_BEFORE, ArgPick2N, void(CPed*, int)> weaponRemoveEvent; - +static CBaseModelInfo ** CModelInfo__ms_modelInfoPtrs = reinterpret_cast(plugin::patch::GetPointer(0x403DA7)); #define PRINT_LINEBREAK \ gLogger->set_pattern("%v"); \ gLogger->info(""); \