Skip to content

Commit

Permalink
Merge pull request #3 from gta-chaos-mod/3.0
Browse files Browse the repository at this point in the history
Some Crash fix from gta-chaos-mod
  • Loading branch information
AthallahDzaki authored Aug 28, 2024
2 parents bc916e9 + ec0e41e commit 8c95e1f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SpawnFireAroundPlayerEffect : public EffectBase
p.y += inst->Random (-5.0f, 5.0f);
p.z = CWorld::FindGroundZForCoord (p.x, p.y);
auto *fire
= gFireManager.StartFire (p, 1.0f, 0, player, 6000, 0, 1);
= gFireManager.StartFire (p, 1.0f, 0, nullptr, 6000, 0, 1);
fireCoords.emplace_back (fire);
spawnFireTimer -= SPAWN_FIRE_TIME;
}
Expand All @@ -60,8 +60,7 @@ class SpawnFireAroundPlayerEffect : public EffectBase
if (pointInRadius (ped->GetPosition (), fire->m_vecPosition,
1.5f))
{
gFireManager.StartFire (ped, fire->m_pEntityCreator,
1.0f, 0, 500, 0);
gFireManager.StartFire (ped, nullptr, 1.0f, 0, 500, 0);
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/gtasa/effects/custom/vehicle/CustomVehicleSpawnsEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CustomVehicleSpawnsEffect : public EffectBase
HOOK_ARGS (inst, Hooked_RandomizeTrafficCars, signed int (int *),
0x43022A);

// CCarCtrl::ChooseCarModelToLoad
HOOK (inst, Hooked_RandomizeCarToLoad, signed int (int *), 0x40B4CB,
0x40B596, 0x40B62F, 0x40ED07);

Expand All @@ -54,6 +55,22 @@ class CustomVehicleSpawnsEffect : public EffectBase
HOOK_METHOD_ARGS (inst, Hooked_RandomizeRoadblocks,
CVehicle * (CVehicle *, int, char, char), 0x462217,
0x4998F0, 0x42B909);

// Firetruck occupants
HOOK_ARGS (inst, Hooked_FixFiretruckAndAmbulanceOccupants,
void (uint8_t *), 0x42BC1A, 0x42BBFB);
}

static void
Hooked_FixFiretruckAndAmbulanceOccupants (auto &&cb, uint8_t *vehicle)
{
LoadCarModel ();

// 13 is some ped type I think?
// TODO: Figure out what 13 *is* and see if we can have it be emergency
// or fireman instead - for now this should fix crashes though
CCarCtrl::SetUpDriverAndPassengersForVehicle ((CVehicle *) vehicle, 13,
0, 0, 0, 99);
}

static bool
Expand Down
19 changes: 9 additions & 10 deletions src/gtasa/util/GameHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class GameHandler

static inline bool didTryLoadAutoSave = false;

static inline int lastMissionsPassed = -1;
static inline int lastSaved = 0;
static inline int lastQuickSave = 0;
static inline int lastMissionsPassed = -1;
static inline std::chrono::steady_clock::time_point lastSaved
= std::chrono::steady_clock::now ();
static inline std::chrono::steady_clock::time_point lastQuickSave
= std::chrono::steady_clock::now ();

static inline CStuntJump *&currentStuntJump = *(CStuntJump **) 0xA9A88C;

Expand Down Expand Up @@ -133,8 +135,6 @@ class GameHandler
if (!CONFIG ("Chaos.AutosaveAfterMissionPassed", true)) return;

int missionsPassed = GameUtil::GetRealMissionsPassed ();
int currentTime = std::max (CTimer::m_snTimeInMillisecondsNonClipped,
(unsigned int) lastMissionsPassed);

if (lastMissionsPassed == -1)
{
Expand All @@ -145,6 +145,7 @@ class GameHandler
lastMissionsPassed = missionsPassed;
}

auto currentTime = std::chrono::steady_clock::now ();
if (missionsPassed > lastMissionsPassed && lastSaved < currentTime
&& !CTheScripts::IsPlayerOnAMission ())
{
Expand All @@ -158,7 +159,7 @@ class GameHandler

EffectHandler::HandleFunction (json);

lastSaved = currentTime + 1000;
lastSaved = currentTime + std::chrono::milliseconds{10000};
}
}

Expand All @@ -167,13 +168,12 @@ class GameHandler
{
if (!CONFIG ("Chaos.QuickSave", false)) return;

int currentTime = std::max (CTimer::m_snTimeInMillisecondsNonClipped,
(unsigned int) lastQuickSave);
auto currentTime = std::chrono::steady_clock::now ();

if (!FrontEndMenuManager.m_bMenuActive && KeyPressed (VK_F7)
&& lastQuickSave < currentTime)
{
lastQuickSave = currentTime + 1000;
lastQuickSave = currentTime + std::chrono::milliseconds{10000};

nlohmann::json json;

Expand Down Expand Up @@ -249,7 +249,6 @@ class GameHandler
Hooked_CTheScripts_Load (auto &&cb)
{
lastMissionsPassed = -1;
lastSaved = 0;

return cb ();
}
Expand Down

0 comments on commit 8c95e1f

Please sign in to comment.