Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "Monster Trucks" effect #3079

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChaosMod/ChaosMod.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<ClCompile Include="Effects\db\Screen\Shaders\ScreenShaderTnPanel.cpp" />
<ClCompile Include="Effects\db\Screen\Shaders\ScreenShaderWarpedCam.cpp" />
<ClCompile Include="Effects\db\Vehs\VehsCrumble.cpp" />
<ClCompile Include="Effects\db\Vehs\VehsMonterTrucks.cpp" />
<ClCompile Include="Effects\db\Vehs\VehsPropModels.cpp" />
<ClCompile Include="Effects\db\Vehs\VehsReplaceVehicle.cpp" />
<ClCompile Include="Effects\db\Peds\PedsGunsmoke.cpp" />
Expand Down
70 changes: 70 additions & 0 deletions ChaosMod/Effects/db/Vehs/VehsMonterTrucks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <stdafx.h>

#include "Memory/Vehicle.h"

struct VehicleData
{
float fRaise;
};

std::map<Hash, VehicleData> vehiclesMap;
std::map<Vehicle, Vector3> vehiclesCGMap;
Rylxnd marked this conversation as resolved.
Show resolved Hide resolved

static void OnStop()
{
for (auto const &[model, data] : vehiclesMap)
{
LoadModel(model);
Vehicle temp = CREATE_VEHICLE(model, 0.f, 0.f, -50.f, 0.f, true, false, true);
FREEZE_ENTITY_POSITION(temp, true);

Memory::SetVehicleRaise(temp, data.fRaise);

DELETE_ENTITY(&temp);
vehiclesMap.erase(model);
}

for (auto const &[veh, CG] : vehiclesCGMap)
{
SET_CGOFFSET(veh, CG.x, CG.y, CG.z);
}

vehiclesMap.clear();
vehiclesCGMap.clear();
}

static void OnTick()
{
for (Vehicle veh : GetAllVehs())
{
if (!DOES_ENTITY_EXIST(veh))
continue;

Hash vehModel = GET_ENTITY_MODEL(veh);
if (!vehiclesMap.contains(vehModel))
{
Memory::SetVehicleRaise(veh, 1.f);

_SET_VEHICLE_WHEELS_DEAL_DAMAGE(veh, true);

vehiclesMap.emplace(vehModel, VehicleData(0.f));
}

if (!vehiclesCGMap.contains(veh))
{
Vector3 ogCG = GET_CGOFFSET(veh);
SET_CGOFFSET(veh, ogCG.x, ogCG.y, ogCG.z - 1.2f);

vehiclesCGMap.emplace(veh, ogCG);
}
Rylxnd marked this conversation as resolved.
Show resolved Hide resolved
}
}

// clang-format off
Rylxnd marked this conversation as resolved.
Show resolved Hide resolved
REGISTER_EFFECT(nullptr, OnStop, OnTick, EffectInfo
{
.Name = "Monster Trucks",
.Id = "vehs_monster_trucks",
.IsTimed = true
}
);
94 changes: 94 additions & 0 deletions ChaosMod/Memory/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,98 @@ namespace Memory
Memory::SetVector3(vehicleMatrixAddress + 0x10, vehicleRightVec * scaleMultiplier);
Memory::SetVector3(vehicleMatrixAddress + 0x20, vehicleUpVec * scaleMultiplier);
}

inline void SetVehicleRaise(Vehicle vehicle, float height)
{
auto vehAddr = getScriptHandleBaseAddress(vehicle);
*reinterpret_cast<float *>(*reinterpret_cast<uintptr_t *>(vehAddr + 0x938) + 0xD0) = height;
}

inline void SetVehicleWheelSize(Vehicle vehicle, float size)
{
auto addr = hook::get_pattern<char>("44 0F 2F 43 48 45 8D");
auto vehAddr = getScriptHandleBaseAddress(vehicle);

auto drawHandlerPtrOffset = *(uint8_t *)(addr + 4);
auto streamRenderGfxPtrOffset = *hook::get_pattern<uint32_t>("4C 8D 48 ? 80 E1 01", -4);

auto drawHandler = *reinterpret_cast<uint64_t *>((uint64_t)vehAddr + drawHandlerPtrOffset);
auto streamRenderGfx = *reinterpret_cast<uint64_t *>(drawHandler + streamRenderGfxPtrOffset);

if (streamRenderGfx == 0)
{
return;
}

addr = hook::get_pattern<char>("48 89 01 B8 00 00 80 3F 66 44 89 51");
auto streamRenderWheelSizeOffset = *(uint8_t *)(addr + 20);

*reinterpret_cast<float *>(streamRenderGfx + streamRenderWheelSizeOffset) = size;
}

inline float GetVehicleWheelSize(Vehicle vehicle)
{
auto addr = hook::get_pattern<char>("44 0F 2F 43 48 45 8D");
auto vehAddr = getScriptHandleBaseAddress(vehicle);

auto drawHandlerPtrOffset = *(uint8_t *)(addr + 4);
auto streamRenderGfxPtrOffset = *hook::get_pattern<uint32_t>("4C 8D 48 ? 80 E1 01", -4);

auto drawHandler = *reinterpret_cast<uint64_t *>((uint64_t)vehAddr + drawHandlerPtrOffset);
auto streamRenderGfx = *reinterpret_cast<uint64_t *>(drawHandler + streamRenderGfxPtrOffset);

if (streamRenderGfx == 0)
{
return 0.f;
}

addr = hook::get_pattern<char>("48 89 01 B8 00 00 80 3F 66 44 89 51");
auto streamRenderWheelSizeOffset = *(uint8_t *)(addr + 20);

return *reinterpret_cast<float *>(streamRenderGfx + streamRenderWheelSizeOffset);
}

inline void SetVehicleWheelWidth(Vehicle vehicle, float width)
{
auto addr = hook::get_pattern<char>("44 0F 2F 43 48 45 8D");
auto vehAddr = getScriptHandleBaseAddress(vehicle);

auto drawHandlerPtrOffset = *(uint8_t *)(addr + 4);
auto streamRenderGfxPtrOffset = *hook::get_pattern<uint32_t>("4C 8D 48 ? 80 E1 01", -4);

auto drawHandler = *reinterpret_cast<uint64_t *>((uint64_t)vehAddr + drawHandlerPtrOffset);
auto streamRenderGfx = *reinterpret_cast<uint64_t *>(drawHandler + streamRenderGfxPtrOffset);

if (streamRenderGfx == 0)
{
return;
}

addr = hook::get_pattern<char>("48 89 01 B8 00 00 80 3F 66 44 89 51");
auto streamRenderWheelWidthOffset = *(uint32_t *)(addr + 23);

*reinterpret_cast<float *>(streamRenderGfx + streamRenderWheelWidthOffset) = width;
}

inline float GetVehicleWheelWidth(Vehicle vehicle)
{
auto addr = hook::get_pattern<char>("44 0F 2F 43 48 45 8D");
auto vehAddr = getScriptHandleBaseAddress(vehicle);

auto drawHandlerPtrOffset = *(uint8_t *)(addr + 4);
auto streamRenderGfxPtrOffset = *hook::get_pattern<uint32_t>("4C 8D 48 ? 80 E1 01", -4);

auto drawHandler = *reinterpret_cast<uint64_t *>((uint64_t)vehAddr + drawHandlerPtrOffset);
auto streamRenderGfx = *reinterpret_cast<uint64_t *>(drawHandler + streamRenderGfxPtrOffset);

if (streamRenderGfx == 0)
{
return 0.f;
}

addr = hook::get_pattern<char>("48 89 01 B8 00 00 80 3F 66 44 89 51");
auto streamRenderWheelWidthOffset = *(uint32_t *)(addr + 23);

return *reinterpret_cast<float *>(streamRenderGfx + streamRenderWheelWidthOffset);
}
}