Skip to content
This repository has been archived by the owner on Aug 17, 2024. It is now read-only.

Commit

Permalink
Only conditionally patch lower-end full clutch
Browse files Browse the repository at this point in the history
This instruction was also executed for ped's vehicles and interfered
with their shifting: Clutch value was stuck to 0.1. This will only patch
if necessary: when the user fully depressed the clutch.
  • Loading branch information
ikt32 committed Feb 20, 2016
1 parent 0493cfc commit 451ac74
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 30 deletions.
69 changes: 55 additions & 14 deletions Gears/MemoryPatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#include "Logger.hpp"

namespace MemoryPatcher {
int total = 5;
int total = 4;
int patched = 0;

int t_S_LOW = 1;
int p_S_LOW = 0;

MemoryAccess mem;

uintptr_t clutchLowAddr = 0;
Expand All @@ -32,6 +35,9 @@ namespace MemoryPatcher {
if (clutchLowTemp) {
clutchLowAddr = clutchLowTemp;
patched++;
std::stringstream hexaddr;
hexaddr << std::hex << clutchLowAddr;
logger.Write("clutchLow @ " + hexaddr.str());
}
else {
logger.Write("Clutch_Normal not patched");
Expand All @@ -41,6 +47,9 @@ namespace MemoryPatcher {
if (clutchS01Temp && !clutchS01Addr) {
clutchS01Addr = clutchS01Temp;
patched++;
std::stringstream hexaddr;
hexaddr << std::hex << clutchS01Addr;
logger.Write("clutchS01 @ " + hexaddr.str());
}
else {
logger.Write("Clutch_Stationary_01 not patched");
Expand All @@ -50,6 +59,9 @@ namespace MemoryPatcher {
if (clutchS04Temp) {
clutchS04Addr = clutchS04Temp;
patched++;
std::stringstream hexaddr;
hexaddr << std::hex << clutchS04Addr;
logger.Write("clutchS04 @ " + hexaddr.str());
}
else {
logger.Write("Clutch_Stationary_04 not patched");
Expand All @@ -59,20 +71,14 @@ namespace MemoryPatcher {
if (throttleCutTemp) {
throttleCutAddr = throttleCutTemp;
patched++;
std::stringstream hexaddr;
hexaddr << std::hex << throttleCutAddr;
logger.Write("tCut @ " + hexaddr.str());
}
else {
logger.Write("Throttle_Redline not patched");
}

clutchStationaryLowTemp = PatchClutchStationaryLow();
if (clutchStationaryLowTemp) {
clutchStationaryLowAddr = clutchStationaryLowTemp;
patched++;
}
else {
logger.Write("Clutch_Stationary_Low not patched");
}

if (patched == total) {
logger.Write("Patching success");
return true;
Expand Down Expand Up @@ -123,21 +129,56 @@ namespace MemoryPatcher {
logger.Write("Throttle not restored");
}

if (patched == 0) {
logger.Write("Restore success");
return true;
}
else {
logger.Write("Restore failed");
return false;
}
}

bool PatchJustS_LOW() {
Logger logger("./Gears.log");
clutchStationaryLowTemp = PatchClutchStationaryLow();
if (clutchStationaryLowTemp) {
clutchStationaryLowAddr = clutchStationaryLowTemp;
p_S_LOW++;
std::stringstream hexaddr;
hexaddr << std::hex << clutchStationaryLowAddr;
logger.Write("clutchS_L @ " + hexaddr.str());
}
else {
logger.Write("Clutch_Stationary_Low not patched");
}
if (p_S_LOW == t_S_LOW) {
logger.Write("Patching ClutchSpecial success");
return true;
}
else {
logger.Write("Patching ClutchSpecial failed");
return false;
}
}

bool RestoreJustS_LOW() {
Logger logger("./Gears.log");
if (clutchStationaryLowAddr) {
RestoreClutchStationaryLow(clutchStationaryLowAddr);
clutchStationaryLowAddr = 0;
patched--;
p_S_LOW--;
}
else {
logger.Write("S_Low not restored");
}

if (patched == 0) {
logger.Write("Restore success");
if (p_S_LOW == 0) {
logger.Write("Restore ClutchSpecial success");
return true;
}
else {
logger.Write("Restore failed");
logger.Write("Restore ClutchSpecial failed");
return false;
}
}
Expand Down
5 changes: 5 additions & 0 deletions Gears/MemoryPatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
namespace MemoryPatcher
{
extern bool PatchInstructions();
extern bool PatchJustS_LOW();
extern bool RestoreInstructions();
extern bool RestoreJustS_LOW();

// Clutch disengage @ Low Speed High Gear
extern uintptr_t PatchClutchLow();
Expand Down Expand Up @@ -33,6 +35,9 @@ namespace MemoryPatcher
extern int total;
extern int patched;

extern int t_S_LOW;
extern int p_S_LOW;

extern MemoryAccess mem;

extern uintptr_t clutchLowAddr;
Expand Down
2 changes: 1 addition & 1 deletion Gears/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BOOL APIENTRY DllMain(HMODULE hInstance, DWORD reason, LPVOID lpReserved)
case DLL_PROCESS_DETACH:
logger.Write("Init shutdown");

bool success = MemoryPatcher::RestoreInstructions();
bool success = MemoryPatcher::RestoreInstructions() && MemoryPatcher::RestoreJustS_LOW();
if (success) {
logger.Write("Shut down script successfully");
}
Expand Down
46 changes: 31 additions & 15 deletions Gears/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Ped playerPed;

bool runOnceRan = false;
bool patched = false;
bool patchedSpecial = false;
int prevNotification = 0;

void showText(float x, float y, float scale, char * text) {
Expand Down Expand Up @@ -81,7 +82,7 @@ void toggleManual() {
VEHICLE::SET_VEHICLE_ENGINE_ON(vehicle, true, false, true);
}
if (settings.EnableManual) {
patched = MemoryPatcher::PatchInstructions();
//patched = MemoryPatcher::PatchInstructions();
}
else {
patched = !MemoryPatcher::RestoreInstructions();
Expand Down Expand Up @@ -124,27 +125,13 @@ void update() {
VEHICLE::IS_THIS_MODEL_A_QUADBIKE(model) ) )
return;

// check if player ped is driver
if (playerPed != VEHICLE::GET_PED_IN_VEHICLE_SEAT(vehicle, -1)) {
if (patched) {
logger.Write("Not a driver:");
patched = !MemoryPatcher::RestoreInstructions();
}
return;
}

// Patch clutch on game start
if (settings.EnableManual && !runOnceRan) {
logger.Write("Patching functions on start");
patched = MemoryPatcher::PatchInstructions();
runOnceRan = true;
}

if (!patched && settings.EnableManual) {
logger.Write("Re-patching functions");
patched = MemoryPatcher::PatchInstructions();
}

if (CONTROLS::IS_CONTROL_JUST_RELEASED(0, ControlEnter) || vehicle != prevVehicle) {
reInit();
}
Expand Down Expand Up @@ -194,6 +181,35 @@ void update() {
showDebugInfo();
}

// check if player ped is driver
if (playerPed != VEHICLE::GET_PED_IN_VEHICLE_SEAT(vehicle, -1)) {
if (patched) {
logger.Write("Not a driver:");
patched = !MemoryPatcher::RestoreInstructions();
}
return;
}

if (!patched && settings.EnableManual) {
logger.Write("Re-patching functions");
patched = MemoryPatcher::PatchInstructions();
}

// Special case for clutch used by all vehicles
// Only patch if user desires to have their clutch @ 0
if (controls.Clutchvalf > 0.9) {
if (!patchedSpecial) {
logger.Write("Patch low-end clutch");
patchedSpecial = MemoryPatcher::PatchJustS_LOW();
}
}
else {
if (patchedSpecial) {
logger.Write("Restoring low-end clutch");
patchedSpecial = !MemoryPatcher::RestoreJustS_LOW();
}
}

if (!settings.EnableManual ||
(!VEHICLE::IS_VEHICLE_DRIVEABLE(vehicle, false) &&
VEHICLE::GET_VEHICLE_ENGINE_HEALTH(vehicle) < -100.0f) )
Expand Down

0 comments on commit 451ac74

Please sign in to comment.