Skip to content

Commit

Permalink
Merge pull request #1915 from Disquse/fivem/ragdoll-network-checks
Browse files Browse the repository at this point in the history
Various network check bypass variables for FiveM
  • Loading branch information
blattersturm committed Apr 18, 2023
2 parents f426350 + e1db50f commit 24c3d1a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 21 deletions.
66 changes: 66 additions & 0 deletions code/components/extra-natives-five/src/PatchNetworkChecks.cpp
@@ -0,0 +1,66 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#include "StdInc.h"
#include <Hooking.h>
#include <nutsnbolts.h>
#include <GameInit.h>
#include <CoreConsole.h>

static bool* g_flyThroughWindscreenDisabled;
static bool* g_playerRagdollOnCollisionDisabled;
static bool* g_playerJumpRagdollControlDisabled;

static bool isFlyThroughWindscreenEnabledConVar = false;
static bool isPlayerRagdollOnCollisionEnabledConVar = false;
static bool isPlayerJumpRagdollControlEnabledConVar = false;

static bool* isNetworkGame;

static HookFunction hookFunction([]()
{
isNetworkGame = hook::get_address<bool*>(hook::get_pattern("24 07 3C 03 75 12 40 38 35 ? ? ? ? 75 09 83", 9));

static ConVar<bool> enableFlyThroughWindscreen("game_enableFlyThroughWindscreen", ConVar_Replicated, false, &isFlyThroughWindscreenEnabledConVar);
static ConVar<bool> enablePlayerRagdollOnCollision("game_enablePlayerRagdollOnCollision", ConVar_Replicated, false, &isPlayerRagdollOnCollisionEnabledConVar);
static ConVar<bool> enablePlayerJumpRagdollControl("game_enablePlayerJumpRagdollControl", ConVar_Replicated, false, &isPlayerJumpRagdollControlEnabledConVar);

// replace netgame check for fly through windscreen with our variable
{
g_flyThroughWindscreenDisabled = (bool*)hook::AllocateStubMemory(1);
auto location = hook::get_pattern<uint32_t>("45 33 ED 44 38 2D ? ? ? ? 4D", 6);
hook::put<int32_t>(location, (intptr_t)g_flyThroughWindscreenDisabled - (intptr_t)location - 4);
}

// replace netgame check for ragdoll on collision with our variable
{
g_playerRagdollOnCollisionDisabled = (bool*)hook::AllocateStubMemory(1);
auto location = hook::get_pattern<uint32_t>("0F 45 C8 84 C9 0F 84", -18);
hook::put<int32_t>(location, (intptr_t)g_playerRagdollOnCollisionDisabled - (intptr_t)location - 4);
}

// replace netgame check for jump ragdoll control with our variable
{
g_playerJumpRagdollControlDisabled = (bool*)hook::AllocateStubMemory(1);
auto location = hook::get_pattern<uint32_t>("C1 E8 03 A8 01 0F 85 ? ? ? ? F6 83 ? ? ? ? 80", -17);
hook::put<int32_t>(location, (intptr_t)g_playerJumpRagdollControlDisabled - (intptr_t)location - 4 - 1);
}

OnKillNetworkDone.Connect([]()
{
enableFlyThroughWindscreen.GetHelper()->SetValue("false");
enablePlayerRagdollOnCollision.GetHelper()->SetValue("false");
enablePlayerJumpRagdollControl.GetHelper()->SetValue("false");
});

OnMainGameFrame.Connect([]()
{
*g_flyThroughWindscreenDisabled = *isNetworkGame && !isFlyThroughWindscreenEnabledConVar;
*g_playerRagdollOnCollisionDisabled = *isNetworkGame && !isPlayerRagdollOnCollisionEnabledConVar;
*g_playerJumpRagdollControlDisabled = *isNetworkGame && !isPlayerJumpRagdollControlEnabledConVar;
});
});
21 changes: 0 additions & 21 deletions code/components/extra-natives-five/src/VehicleExtraNatives.cpp
Expand Up @@ -112,9 +112,6 @@ static std::vector<FlyThroughWindscreenParam> g_flyThroughWindscreenParams{};

static std::map<fwEntity*, VehicleXenonLightsColor> g_vehicleXenonLightsColors{};

static bool* g_flyThroughWindscreenDisabled;
static bool isFlyThroughWindscreenEnabledConVar = false;

template<typename T>
inline static T readValue(fwEntity* ptr, int offset)
{
Expand Down Expand Up @@ -447,12 +444,8 @@ TrainDoor* GetTrainDoor(fwEntity* train, uint32_t index)
return &(*((TrainDoor**)(((char*)train) + TrainDoorArrayPointerOffset)))[index];
}

static bool* isNetworkGame;

static HookFunction initFunction([]()
{
isNetworkGame = hook::get_address<bool*>(hook::get_pattern("24 07 3C 03 75 12 40 38 35 ? ? ? ? 75 09 83", 9));

{
ModelInfoPtrOffset = *hook::get_pattern<uint8_t>("48 8B 40 ? 0F B6 80 ? ? ? ? 83 E0 1F", 3);
GravityOffset = *hook::get_pattern<uint32_t>("0F C6 F6 00 F3 0F 59 05", -4);
Expand Down Expand Up @@ -615,15 +608,6 @@ static HookFunction initFunction([]()
hook::nop(location, 14);
}

{
// replace netgame check for fly through windscreen with our variable
g_flyThroughWindscreenDisabled = (bool*)hook::AllocateStubMemory(1);
static ConVar<bool> enableFlyThroughWindscreen("game_enableFlyThroughWindscreen", ConVar_Replicated, false, &isFlyThroughWindscreenEnabledConVar);

auto location = hook::get_pattern<uint32_t>("45 33 ED 44 38 2D ? ? ? ? 4D", 6);
hook::put<int32_t>(location, (intptr_t)g_flyThroughWindscreenDisabled - (intptr_t)location - 4);
}

{
auto location = hook::get_pattern<char>("F3 44 0F 11 4C 24 ? E8 ? ? ? ? EB 7A");
VehicleDamageStructOffset = *(uint32_t*)(location - 11);
Expand Down Expand Up @@ -1343,11 +1327,6 @@ static HookFunction initFunction([]()
}
});

OnMainGameFrame.Connect([]()
{
*g_flyThroughWindscreenDisabled = *isNetworkGame && !isFlyThroughWindscreenEnabledConVar;
});

OnKillNetworkDone.Connect([]()
{
g_skipRepairVehicles.clear();
Expand Down

0 comments on commit 24c3d1a

Please sign in to comment.