Skip to content

Commit

Permalink
FixParticleRendering: improve fireworks fix so DrawDistanceBehind isn…
Browse files Browse the repository at this point in the history
…'t required
  • Loading branch information
emoose committed Sep 18, 2024
1 parent e3fe8f5 commit 9f0a664
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 18 additions & 5 deletions src/hooks_bugfixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ class FixParticleRendering : public Hook
}
}

// Fix metropolis firework texture issue (https://github.com/emoose/OutRun2006Tweaks/issues/52)
// DispStage tries to draw object 0x630001, but since no CollNode list is passed it uses default CollNode 0, which likely causes road barriers to get drawn
// We'll fix this by making it draw stage object with CollNode list used by DrawDistanceBehind = 2 instead
// This seems to let it draw the fireworks properly, though this is a little hacky
// I'm not really sure if there's any other way to fix it, seems that a CollNode array is required for it to draw model correctly...
inline static SafetyHookMid midhook_fireworks{};
static void destination_fireworks(SafetyHookContext& ctx)
{
static uint16_t DrawDistBehind_equals_2_CollNodes[] =
{ 0, 4, 5, 6, 7, 0xB, 0xC, 0xD, 0xE, 0x12, 0x13, 0x14, 0x15, 0x1A, 0x1B, 0x1F, 0x20, 0x21, 0xFFFF };

Game::DrawObject_Internal(0x001a000a, 0, DrawDistBehind_equals_2_CollNodes, 0, -1, 0);

ctx.eip = (uintptr_t)Module::exe_ptr(0x4E190);
}

public:
std::string_view description() override
{
Expand All @@ -52,11 +68,8 @@ class FixParticleRendering : public Hook
constexpr int particle_draw_rect2_HookAddr = 0x19009;
midhook = safetyhook::create_mid(Module::exe_ptr(particle_draw_rect2_HookAddr), destination);

// Fix metropolis firework texture issue (https://github.com/emoose/OutRun2006Tweaks/issues/52)
// DispStage will draw object 0x630001 once goal is passed, but seems that model is for road barriers
// 0x630002 seems to be the right firework model
constexpr int DispStage_PatchAddr = 0x4E183 + 1;
Memory::VP::Patch(Module::exe_ptr<uint32_t>(DispStage_PatchAddr), 0x630002);
constexpr int DispStage_HookAddr = 0x4E179;
midhook_fireworks = safetyhook::create_mid(Module::exe_ptr(DispStage_HookAddr), destination_fireworks);

return !!midhook;
}
Expand Down
5 changes: 3 additions & 2 deletions src/hooks_framerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,15 @@ class ReplaceGameUpdateLoop : public Hook
}
}

// EventDisplay adds to sin_param every frame, if GetPauseFlag is false
// EventDisplay adds 0.10471975 to sin_param every frame, if GetPauseFlag is false
// This causes speed of flashing cars to change depending on framerate
// We'll update it similar to SetTweeningTable so it only increments if a game tick is being ran
// TODO: would probably be smoother to scale that 0.10471975 by deltatime instead
inline static SafetyHookMid EventDisplay_midhook = {};
static void EventDisplay_dest(SafetyHookContext& ctx)
{
if (*Game::sprani_num_ticks == 0)
ctx.eax = 1; // make func think that game is paused
ctx.eax = 1; // make func skip adding to sin_param
}

public:
Expand Down

0 comments on commit 9f0a664

Please sign in to comment.