From 11c4e8562920b60e364afcab8a80daca66ff6f47 Mon Sep 17 00:00:00 2001 From: Explooosion-code <61145047+Explooosion-code@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:41:18 +0200 Subject: [PATCH 1/4] feat(extra-natives/five): implement [GET/SET]_PASSENGER_WEIGHT --- .../src/VehicleExtraNatives.cpp | 24 +++++++++++++++++++ ext/native-decls/GetPassengerWeight.md | 15 ++++++++++++ ext/native-decls/SetPassengerWeight.md | 15 ++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 ext/native-decls/GetPassengerWeight.md create mode 100644 ext/native-decls/SetPassengerWeight.md diff --git a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp index ad48c06cdd..45ec7b816f 100644 --- a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp +++ b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp @@ -236,6 +236,8 @@ static void writeVehicleMemory(fx::ScriptContext& context, std::string_view nn) } } +static float* PassengerWeightPtr; + static int StreamRenderGfxPtrOffset; static int HandlingDataPtrOffset; static int DrawHandlerPtrOffset; @@ -753,6 +755,11 @@ static HookFunction initFunction([]() VehicleRollBiasOffset = VehiclePitchBiasOffset - 4; } + { + auto location = hook::get_pattern("F3 0F 59 3D ? ? ? ? F3 0F 58 3D ? ? ? ? 48 85 C9", 4); + PassengerWeightPtr = hook::get_address(location); + } + { std::initializer_list list = { { "44 38 ? ? ? ? 02 74 ? F3 0F 10 1D", 13 }, @@ -1518,6 +1525,23 @@ static HookFunction initFunction([]() ResetFlyThroughWindscreenParams(); }); + fx::ScriptEngine::RegisterNativeHandler("SET_PASSENGER_WEIGHT", [](fx::ScriptContext& context) + { + float weight = context.GetArgument(0); + + if (weight < 0.0) + { + weight = 0.0; + } + + *PassengerWeightPtr = weight; + }); + + fx::ScriptEngine::RegisterNativeHandler("GET_PASSENGER_WEIGHT", [](fx::ScriptContext& context) + { + context.SetResult(* PassengerWeightPtr); + }); + static struct : jitasm::Frontend { static bool ShouldSkipRepairFunc(fwEntity* VehPointer) diff --git a/ext/native-decls/GetPassengerWeight.md b/ext/native-decls/GetPassengerWeight.md new file mode 100644 index 0000000000..6c8f015fe0 --- /dev/null +++ b/ext/native-decls/GetPassengerWeight.md @@ -0,0 +1,15 @@ +--- +ns: CFX +apiset: client +game: gta5 +--- +## GET_PASSENGER_WEIGHT + +```c +float GET_PASSENGER_WEIGHT(); +``` + +A getter for [SET_PASSENGER_WEIGHT](#_0x58e530aa). + +## Return value +Returns the weight of each passenger (not counting the driver) as a percentage of vehicle mass. \ No newline at end of file diff --git a/ext/native-decls/SetPassengerWeight.md b/ext/native-decls/SetPassengerWeight.md new file mode 100644 index 0000000000..f07413b1e9 --- /dev/null +++ b/ext/native-decls/SetPassengerWeight.md @@ -0,0 +1,15 @@ +--- +ns: CFX +apiset: client +game: gta5 +--- +## SET_PASSENGER_WEIGHT + +```c +void SET_PASSENGER_WEIGHT(float weight); +``` + +## Parameters +* **weight**: Weight of each passenger (not counting the driver) as a percentage of vehicle mass. Is applied to all vehicles + +## Return value \ No newline at end of file From 341dcc54a196faf9c6ee59bbebd40bbacde4253e Mon Sep 17 00:00:00 2001 From: Explooosion-code <61145047+Explooosion-code@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:16:19 +0200 Subject: [PATCH 2/4] tweak(extra-natives/five): Change native name: PASSENGER_WEIGHT -> GLOBAL_PASSENGER_MASS_MULTIPLIER tweak(native-docs): Add information aboud default value feat(extra-natives/five): Reset passenger mass OnKillNetwork tweak(extra-natives/five): Change native name PASSENGER_WEIGHT -> GLOBAL_PASSENGER_MASS_MULTIPLIER --- .../src/VehicleExtraNatives.cpp | 18 +++++++++++------- .../GetGlobalPassengerMassMultiplier.md | 15 +++++++++++++++ ext/native-decls/GetPassengerWeight.md | 15 --------------- .../SetGlobalPassengerMassMultiplier.md | 15 +++++++++++++++ ext/native-decls/SetPassengerWeight.md | 15 --------------- 5 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 ext/native-decls/GetGlobalPassengerMassMultiplier.md delete mode 100644 ext/native-decls/GetPassengerWeight.md create mode 100644 ext/native-decls/SetGlobalPassengerMassMultiplier.md delete mode 100644 ext/native-decls/SetPassengerWeight.md diff --git a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp index 45ec7b816f..366950ae82 100644 --- a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp +++ b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp @@ -236,7 +236,7 @@ static void writeVehicleMemory(fx::ScriptContext& context, std::string_view nn) } } -static float* PassengerWeightPtr; +static float* PassengerMassPtr; static int StreamRenderGfxPtrOffset; static int HandlingDataPtrOffset; @@ -757,7 +757,7 @@ static HookFunction initFunction([]() { auto location = hook::get_pattern("F3 0F 59 3D ? ? ? ? F3 0F 58 3D ? ? ? ? 48 85 C9", 4); - PassengerWeightPtr = hook::get_address(location); + PassengerMassPtr = hook::get_address(location); } { @@ -1525,7 +1525,7 @@ static HookFunction initFunction([]() ResetFlyThroughWindscreenParams(); }); - fx::ScriptEngine::RegisterNativeHandler("SET_PASSENGER_WEIGHT", [](fx::ScriptContext& context) + fx::ScriptEngine::RegisterNativeHandler("SET_GLOBAL_PASSENGER_MASS_MULTIPLIER", [](fx::ScriptContext& context) { float weight = context.GetArgument(0); @@ -1533,13 +1533,15 @@ static HookFunction initFunction([]() { weight = 0.0; } - - *PassengerWeightPtr = weight; + trace("Setting weight %.6f was %.6f\n", weight, *PassengerMassPtr); + *PassengerMassPtr = weight; }); - fx::ScriptEngine::RegisterNativeHandler("GET_PASSENGER_WEIGHT", [](fx::ScriptContext& context) + fx::ScriptEngine::RegisterNativeHandler("GET_GLOBAL_PASSENGER_MASS_MULTIPLIER", [](fx::ScriptContext& context) { - context.SetResult(* PassengerWeightPtr); + trace("Weight is %.6f\n", *PassengerMassPtr); + + context.SetResult(*PassengerMassPtr); }); static struct : jitasm::Frontend @@ -1619,6 +1621,8 @@ static HookFunction initFunction([]() g_isFuelConsumptionOn = false; g_globalFuelConsumptionMultiplier = 1.f; + + *PassengerMassPtr = 0.05f; }); fx::ScriptEngine::RegisterNativeHandler("SET_VEHICLE_AUTO_REPAIR_DISABLED", [](fx::ScriptContext& context) diff --git a/ext/native-decls/GetGlobalPassengerMassMultiplier.md b/ext/native-decls/GetGlobalPassengerMassMultiplier.md new file mode 100644 index 0000000000..db229af498 --- /dev/null +++ b/ext/native-decls/GetGlobalPassengerMassMultiplier.md @@ -0,0 +1,15 @@ +--- +ns: CFX +apiset: client +game: gta5 +--- +## GET_GLOBAL_PASSENGER_MASS_MULTIPLIER + +```c +float GET_GLOBAL_PASSENGER_MASS_MULTIPLIER(); +``` + +A getter for [SET_GLOBAL_PASSENGER_MASS_MULTIPLIER](#_0x1c47f6ac). + +## Return value +Returns the mass of each passenger (not counting the driver) as a percentage of vehicle mass. Default value is 0.05 \ No newline at end of file diff --git a/ext/native-decls/GetPassengerWeight.md b/ext/native-decls/GetPassengerWeight.md deleted file mode 100644 index 6c8f015fe0..0000000000 --- a/ext/native-decls/GetPassengerWeight.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -ns: CFX -apiset: client -game: gta5 ---- -## GET_PASSENGER_WEIGHT - -```c -float GET_PASSENGER_WEIGHT(); -``` - -A getter for [SET_PASSENGER_WEIGHT](#_0x58e530aa). - -## Return value -Returns the weight of each passenger (not counting the driver) as a percentage of vehicle mass. \ No newline at end of file diff --git a/ext/native-decls/SetGlobalPassengerMassMultiplier.md b/ext/native-decls/SetGlobalPassengerMassMultiplier.md new file mode 100644 index 0000000000..12a9ef4d2f --- /dev/null +++ b/ext/native-decls/SetGlobalPassengerMassMultiplier.md @@ -0,0 +1,15 @@ +--- +ns: CFX +apiset: client +game: gta5 +--- +## SET_GLOBAL_PASSENGER_MASS_MULTIPLIER + +```c +void SET_GLOBAL_PASSENGER_MASS_MULTIPLIER(float massMul); +``` + +## Parameters +* **massMul**: Weight of each passenger (not counting the driver) as a percentage of vehicle mass. Is applied to all vehicles. Default value is 0.05 + +## Return value \ No newline at end of file diff --git a/ext/native-decls/SetPassengerWeight.md b/ext/native-decls/SetPassengerWeight.md deleted file mode 100644 index f07413b1e9..0000000000 --- a/ext/native-decls/SetPassengerWeight.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -ns: CFX -apiset: client -game: gta5 ---- -## SET_PASSENGER_WEIGHT - -```c -void SET_PASSENGER_WEIGHT(float weight); -``` - -## Parameters -* **weight**: Weight of each passenger (not counting the driver) as a percentage of vehicle mass. Is applied to all vehicles - -## Return value \ No newline at end of file From afd796ce90d803d63b882d5cf15b75d509740edb Mon Sep 17 00:00:00 2001 From: Explooosion-code <61145047+Explooosion-code@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:03:24 +0200 Subject: [PATCH 3/4] chore(extra-natives/five): Remove debug traces --- code/components/extra-natives-five/src/VehicleExtraNatives.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp index 366950ae82..9f4872d232 100644 --- a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp +++ b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp @@ -1533,14 +1533,11 @@ static HookFunction initFunction([]() { weight = 0.0; } - trace("Setting weight %.6f was %.6f\n", weight, *PassengerMassPtr); *PassengerMassPtr = weight; }); fx::ScriptEngine::RegisterNativeHandler("GET_GLOBAL_PASSENGER_MASS_MULTIPLIER", [](fx::ScriptContext& context) { - trace("Weight is %.6f\n", *PassengerMassPtr); - context.SetResult(*PassengerMassPtr); }); From da422e47d3b679c45ac74f5abcca8d33363cf845 Mon Sep 17 00:00:00 2001 From: Explooosion-code <61145047+Explooosion-code@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:12:39 +0200 Subject: [PATCH 4/4] tweak(native-docs): Remove unused return value --- ext/native-decls/SetGlobalPassengerMassMultiplier.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ext/native-decls/SetGlobalPassengerMassMultiplier.md b/ext/native-decls/SetGlobalPassengerMassMultiplier.md index 12a9ef4d2f..c8ddb59150 100644 --- a/ext/native-decls/SetGlobalPassengerMassMultiplier.md +++ b/ext/native-decls/SetGlobalPassengerMassMultiplier.md @@ -10,6 +10,4 @@ void SET_GLOBAL_PASSENGER_MASS_MULTIPLIER(float massMul); ``` ## Parameters -* **massMul**: Weight of each passenger (not counting the driver) as a percentage of vehicle mass. Is applied to all vehicles. Default value is 0.05 - -## Return value \ No newline at end of file +* **massMul**: Weight of each passenger (not counting the driver) as a percentage of vehicle mass. Is applied to all vehicles. Default value is 0.05 \ No newline at end of file