Skip to content

Commit

Permalink
Fix more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Jul 8, 2024
1 parent bb22f54 commit 405db74
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 51 deletions.
13 changes: 8 additions & 5 deletions src/features/mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ void FeatureMgr::Initialize() {
CTaskSimpleJetPack *pTask = pPed->m_pIntelligence->GetTaskJetPack();
if (pTask && pTask->m_pJetPackClump) {
Add(static_cast<void*>(&pPed->m_aWeapons[pPed->m_nActiveWeaponSlot]),
(RwFrame *)pTask->m_pJetPackClump->object.parent, eModelEntityType::Weapon);
Process(static_cast<void*>(&pPed->m_aWeapons[pPed->m_nActiveWeaponSlot]), eModelEntityType::Weapon);
(RwFrame *)pTask->m_pJetPackClump->object.parent, eModelEntityType::Jetpack);
Process(static_cast<void*>(&pPed->m_aWeapons[pPed->m_nActiveWeaponSlot]), eModelEntityType::Jetpack);
}

// weapons
CWeapon *pWeapon = &pPed->m_aWeapons[pPed->m_nActiveWeaponSlot];
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<CWeaponModelInfo*>(CModelInfo::GetModelInfo(pWeaponInfo->m_nModelId1));
if (pWeaponModelInfo && pWeaponModelInfo->m_pRwClump) {
Add(static_cast<void*>(&pPed->m_aWeapons[pPed->m_nActiveWeaponSlot]),
Expand Down Expand Up @@ -167,6 +167,8 @@ void FeatureMgr::Add(void *ptr, RwFrame* frame, eModelEntityType type) {
int model = 0;
if (type == eModelEntityType::Weapon) {
model = static_cast<CWeapon*>(ptr)->m_eWeaponType;
} else if (type == eModelEntityType::Jetpack) {
model = 370;
} else {
model = static_cast<CEntity*>(ptr)->m_nModelIndex;
}
Expand All @@ -180,6 +182,8 @@ void FeatureMgr::Process(void *ptr, eModelEntityType type) {
int model = 0;
if (type == eModelEntityType::Weapon) {
model = static_cast<CWeapon*>(ptr)->m_eWeaponType;
} else if (type == eModelEntityType::Jetpack) {
model = 370;
} else {
model = static_cast<CEntity*>(ptr)->m_nModelIndex;
}
Expand All @@ -189,5 +193,4 @@ void FeatureMgr::Process(void *ptr, eModelEntityType type) {
m_FunctionTable[e.id](ptr, e.m_pFrame, type);
}
}
}

}
2 changes: 1 addition & 1 deletion src/features/vehicle/indicators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CVehicleModelInfo*>(CModelInfo::ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[idx];
reinterpret_cast<CVehicleModelInfo*>(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;
Expand Down
6 changes: 3 additions & 3 deletions src/features/vehicle/lights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CVehicleModelInfo *>(CModelInfo::ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[0];
CVector posn = reinterpret_cast<CVehicleModelInfo *>(CModelInfo__ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[0];
posn.x = 0.0f;
posn.y += 3.35f;

Expand Down Expand Up @@ -175,14 +175,14 @@ void Lights::Initialize() {

if (showTailLights) {
if (!automobile->m_damageManager.GetLightStatus(eLights::LIGHT_REAR_LEFT)) {
CVector posn = reinterpret_cast<CVehicleModelInfo *>(CModelInfo::ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[1];
CVector posn = reinterpret_cast<CVehicleModelInfo *>(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<CVehicleModelInfo *>(CModelInfo::ms_modelInfoPtrs[pVeh->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[1];
CVector posn = reinterpret_cast<CVehicleModelInfo *>(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);
}
Expand Down
5 changes: 2 additions & 3 deletions src/features/vehicle/sirens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CVehicleModelInfo*>(CModelInfo::ms_modelInfoPtrs[vehicle->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[0];
CVector position = reinterpret_cast<CVehicleModelInfo*>(CModelInfo__ms_modelInfoPtrs[vehicle->m_nModelIndex])->m_pVehicleStruct->m_avDummyPos[0];

position.x = dummy->Position.x;
position.y = dummy->Position.y;
Expand Down Expand Up @@ -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<CVehicleModelInfo*>(CModelInfo::ms_modelInfoPtrs[model]);
CVehicleModelInfo* modelInfo = reinterpret_cast<CVehicleModelInfo*>(CModelInfo__ms_modelInfoPtrs[model]);

if (modelInfo->m_nVehicleType == eVehicleType::VEHICLE_HELI || modelInfo->m_nVehicleType == eVehicleType::VEHICLE_PLANE)
this->Mute = true;
Expand Down
2 changes: 1 addition & 1 deletion src/features/vehicle/spotlights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
72 changes: 35 additions & 37 deletions src/features/weapon/bodystate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,43 @@ void BodyState::Process(void* ptr, RwFrame* frame, eModelEntityType type) {
CWeapon *pWeapon = static_cast<CWeapon*>(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;
}
}
5 changes: 4 additions & 1 deletion src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <CModelInfo.h>
#include <regex>

#include <plugin.h>

#include "bass.h"
#include "json.hpp"
#include "ini.hpp"
Expand All @@ -21,6 +23,7 @@ enum class eModelEntityType {
Object,
Vehicle,
Weapon,
Jetpack,
};

#define MOD_DATA_PATH(x) PLUGIN_PATH((char*)("ModelExtras/"x))
Expand Down Expand Up @@ -51,7 +54,7 @@ static inline ThiscallEvent <AddressList<//0x43D821, H_CALL,
0x63072E, H_CALL,
// 0x5E6483, H_CALL,
0x6348FC, H_CALL>, PRIORITY_BEFORE, ArgPick2N<CPed*, 0, int, 1>, void(CPed*, int)> weaponRemoveEvent;

static CBaseModelInfo ** CModelInfo__ms_modelInfoPtrs = reinterpret_cast<CBaseModelInfo **>(plugin::patch::GetPointer(0x403DA7));
#define PRINT_LINEBREAK \
gLogger->set_pattern("%v"); \
gLogger->info(""); \
Expand Down

0 comments on commit 405db74

Please sign in to comment.