Fix 'Disable Ocean' not resetting ocean heights correctly on disable (#2404)

This commit is contained in:
thehorizon84 2023-11-11 00:02:43 +01:00 committed by GitHub
parent eca00ef3b6
commit a3125ab60c

View File

@ -4,27 +4,46 @@
namespace big namespace big
{ {
static std::vector<float> original_heights;
struct quad_info
{
uint64_t m_quad_pool;
short m_quad_count;
};
struct ocean_quad
{
private:
char pad_0[0x8];
public:
int m_opacity;
private:
char pad_1[0x8];
public:
float m_height;
};
class modify_ocean : looped_command class modify_ocean : looped_command
{ {
using looped_command::looped_command; using looped_command::looped_command;
struct quad_info virtual void on_enable() override
{ {
uint64_t m_quad_pool; if (auto ocean_quads = reinterpret_cast<quad_info*>(g_pointers->m_gta.m_ocean_quads))
short m_quad_count; {
}; for (uint64_t i = 0; i < ocean_quads->m_quad_count; i++)
{
const auto index = ocean_quads->m_quad_pool + (i * 0x1C);
const auto quad = reinterpret_cast<ocean_quad*>(index);
struct ocean_quad original_heights.push_back(quad->m_height);
{ }
private: }
char pad_0[0x8]; }
public:
int m_opacity;
private:
char pad_1[0x8];
public:
float m_height;
};
virtual void on_tick() override virtual void on_tick() override
{ {
@ -39,7 +58,7 @@ namespace big
if (g.world.ocean.disable_ocean) if (g.world.ocean.disable_ocean)
quad->m_height = -10000.f; quad->m_height = -10000.f;
else else
quad->m_height = 0.f; quad->m_height = original_heights[i];
// Change the ocean's opacity (alpha) // Change the ocean's opacity (alpha)
if (g.world.ocean.ocean_opacity == 100) if (g.world.ocean.ocean_opacity == 100)
@ -61,10 +80,12 @@ namespace big
const auto index = ocean_quads->m_quad_pool + (i * 0x1C); const auto index = ocean_quads->m_quad_pool + (i * 0x1C);
const auto quad = reinterpret_cast<ocean_quad*>(index); const auto quad = reinterpret_cast<ocean_quad*>(index);
quad->m_height = 0.f; quad->m_height = original_heights[i];
quad->m_opacity = 0x1A1A1A1A; quad->m_opacity = 0x1A1A1A1A;
} }
} }
original_heights.clear();
} }
}; };