From 0a1ca23c343c175e5be276f6412eba0a28ec795b Mon Sep 17 00:00:00 2001 From: Segfault <5221072+Segfaultd@users.noreply.github.com> Date: Sat, 3 Feb 2024 20:40:34 +0100 Subject: [PATCH 1/7] Added missing getters / setters --- code/client/src/core/modules/vehicle.cpp | 2 +- code/client/src/core/ui/vehicle_debug.cpp | 8 +++++++- code/client/src/sdk/entities/c_vehicle.cpp | 8 ++++++++ code/client/src/sdk/entities/c_vehicle.h | 6 +++--- code/client/src/sdk/patterns.cpp | 1 + code/client/src/sdk/patterns.h | 1 + 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/code/client/src/core/modules/vehicle.cpp b/code/client/src/core/modules/vehicle.cpp index b0157259..b5ce8f5a 100644 --- a/code/client/src/core/modules/vehicle.cpp +++ b/code/client/src/core/modules/vehicle.cpp @@ -54,7 +54,7 @@ namespace MafiaMP::Core::Modules { metadata.power = vehicle->GetPower(); metadata.radioId = vehicle->GetRadioStation(); metadata.radioState = vehicle->IsRadioOn(); - metadata.sirenState = vehicle->GetSiren(); + metadata.sirenState = vehicle->IsSiren(); metadata.steer = vehicle->GetSteer(); metadata.velocity = {vehicleVelocity.x, vehicleVelocity.y, vehicleVelocity.z}; } diff --git a/code/client/src/core/ui/vehicle_debug.cpp b/code/client/src/core/ui/vehicle_debug.cpp index d5276f0a..fb9b7d27 100644 --- a/code/client/src/core/ui/vehicle_debug.cpp +++ b/code/client/src/core/ui/vehicle_debug.cpp @@ -21,6 +21,7 @@ namespace MafiaMP::Core::UI { if (currentCar) { auto currentVehicle = currentCar->GetVehicle(); + ImGui::Text("Vehicle Pointer: %p", currentVehicle); auto position = currentCar->GetPos(); if (ImGui::DragFloat3("Pos", (float *)&position, 0.1f, -4500.0f, 4500.0f)) { @@ -72,7 +73,7 @@ namespace MafiaMP::Core::UI { currentVehicle->SetHorn(horn); } - bool siren = currentVehicle->GetSiren(); + bool siren = currentVehicle->IsSiren(); if (ImGui::Checkbox("Siren", &siren)) { currentVehicle->SetSiren(siren); } @@ -82,6 +83,11 @@ namespace MafiaMP::Core::UI { currentVehicle->SetBeaconLightsOn(beaconsLight); } + bool isEngineOn = currentVehicle->IsEngineOn(); + if (ImGui::Checkbox("Engine", &isEngineOn)) { + currentVehicle->SetEngineOn(isEngineOn, isEngineOn); + } + SDK::ue::sys::math::C_Vector4 color1, color2; currentVehicle->GetVehicleColor(&color1, &color2); diff --git a/code/client/src/sdk/entities/c_vehicle.cpp b/code/client/src/sdk/entities/c_vehicle.cpp index 2a2ff680..ce081d28 100644 --- a/code/client/src/sdk/entities/c_vehicle.cpp +++ b/code/client/src/sdk/entities/c_vehicle.cpp @@ -43,6 +43,10 @@ namespace SDK { hook::this_call(gPatterns.C_Vehicle__SetSiren, this, on); } + bool C_Vehicle::IsSiren() { + return hook::this_call(gPatterns.C_Vehicle__IsSiren, this); + } + void C_Vehicle::SetSteer(float steer) { hook::this_call(gPatterns.C_Vehicle__SetSteer, this, steer); } @@ -141,6 +145,10 @@ namespace SDK { return (m_RadioSound && m_RadioSound->IsRadioOn()); } + bool C_Vehicle::IsAnyLightOn() { + return hook::this_call(gPatterns.C_Vehicle__IsAnyLightOn, this); + } + void C_Vehicle::EnableRadio(bool enable) { // NB: Need to shift to (I assume to a radio) interface void *shiftedThis = reinterpret_cast(reinterpret_cast(this) + 0x268); diff --git a/code/client/src/sdk/entities/c_vehicle.h b/code/client/src/sdk/entities/c_vehicle.h index d65831c5..eff657e2 100644 --- a/code/client/src/sdk/entities/c_vehicle.h +++ b/code/client/src/sdk/entities/c_vehicle.h @@ -40,9 +40,7 @@ namespace SDK { } void SetSiren(bool on); - bool GetSiren() const { - return false; - } + bool IsSiren(); void SetSteer(float steer); float GetSteer() const { @@ -107,6 +105,8 @@ namespace SDK { bool IsActive(int arg1 = 0); void Damage(bool arg1); + bool IsAnyLightOn(); + bool IsRadioOn(); void EnableRadio(bool enable); void TurnRadioOn(bool on); diff --git a/code/client/src/sdk/patterns.cpp b/code/client/src/sdk/patterns.cpp index 6b392db7..d12e9071 100644 --- a/code/client/src/sdk/patterns.cpp +++ b/code/client/src/sdk/patterns.cpp @@ -381,6 +381,7 @@ namespace SDK { gPatterns.C_Vehicle__EnableRadio = hook::get_opcode_address("E8 ? ? ? ? 49 8B 84 24 ? ? ? ? 49 8B F7"); gPatterns.C_Vehicle__GetSPZText = hook::get_opcode_address("E8 ? ? ? ? 49 8D 4F ? 48 8B D0"); gPatterns.C_Vehicle__IsActive = hook::get_opcode_address("E8 ? ? ? ? 84 C0 75 0A B2 01"); + gPatterns.C_Vehicle__IsAnyLightOn = reinterpret_cast(hook::get_pattern("48 8B 81 ? ? ? ? 48 8B 89 ? ? ? ? 48 3B C1 74 18 48 8B 10")); gPatterns.C_Vehicle__IsSiren = hook::get_opcode_address("E8 ? ? ? ? 0F B6 4D BF"); gPatterns.C_Vehicle__SetActive = hook::get_opcode_address("E8 ? ? ? ? F3 0F 59 35 ? ? ? ? 48 8D 8B ? ? ? ?"); gPatterns.C_Vehicle__SetAngularSpeed = hook::get_opcode_address(" E8 ? ? ? ? E9 ? ? ? ? 80 BD ? ? ? ? ? 0F 85 ? ? ? ?"); diff --git a/code/client/src/sdk/patterns.h b/code/client/src/sdk/patterns.h index 0b700e39..f1872752 100644 --- a/code/client/src/sdk/patterns.h +++ b/code/client/src/sdk/patterns.h @@ -317,6 +317,7 @@ namespace SDK { uint64_t C_Vehicle__EnableRadio = 0x0; uint64_t C_Vehicle__GetSPZText = 0x0; uint64_t C_Vehicle__IsActive = 0x0; + uint64_t C_Vehicle__IsAnyLightOn = 0x0; uint64_t C_Vehicle__IsSiren = 0x0; uint64_t C_Vehicle__SetActive = 0x0; uint64_t C_Vehicle__SetAngularSpeed = 0x0; From 5b3b3954a0ba7e06800232a252f3afefc35bb869 Mon Sep 17 00:00:00 2001 From: Segfault <5221072+Segfaultd@users.noreply.github.com> Date: Sat, 3 Feb 2024 21:37:49 +0100 Subject: [PATCH 2/7] Dump pointers first --- code/client/src/core/ui/vehicle_debug.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/code/client/src/core/ui/vehicle_debug.cpp b/code/client/src/core/ui/vehicle_debug.cpp index fb9b7d27..2558c8f5 100644 --- a/code/client/src/core/ui/vehicle_debug.cpp +++ b/code/client/src/core/ui/vehicle_debug.cpp @@ -21,7 +21,8 @@ namespace MafiaMP::Core::UI { if (currentCar) { auto currentVehicle = currentCar->GetVehicle(); - ImGui::Text("Vehicle Pointer: %p", currentVehicle); + ImGui::Text("Car Ptr: %p", currentCar); + ImGui::Text("Vehicle Ptr: %p", currentVehicle); auto position = currentCar->GetPos(); if (ImGui::DragFloat3("Pos", (float *)&position, 0.1f, -4500.0f, 4500.0f)) { @@ -131,9 +132,6 @@ namespace MafiaMP::Core::UI { ImGui::Text("Radio State: %s", currentVehicle->IsRadioOn() ? "On" : "Off"); ImGui::Text("Radio Station: %u", currentVehicle->GetRadioStation()); - ImGui::Text("Car Ptr: %p", currentCar); - ImGui::Text("Vehicle Ptr: %p", currentVehicle); - if (ImGui::Button("Restore")) { currentCar->RestoreCar(); } From a0294e607e0f7054bbd058c4426105629624c208 Mon Sep 17 00:00:00 2001 From: Segfault <5221072+Segfaultd@users.noreply.github.com> Date: Sat, 3 Feb 2024 22:44:25 +0100 Subject: [PATCH 3/7] Added C_Human2CarWrapper::IsEngineOn --- code/client/src/sdk/patterns.cpp | 1 + code/client/src/sdk/patterns.h | 1 + code/client/src/sdk/wrappers/c_human_2_car_wrapper.cpp | 4 ++++ code/client/src/sdk/wrappers/c_human_2_car_wrapper.h | 1 + 4 files changed, 7 insertions(+) diff --git a/code/client/src/sdk/patterns.cpp b/code/client/src/sdk/patterns.cpp index b95d4775..e2c88980 100644 --- a/code/client/src/sdk/patterns.cpp +++ b/code/client/src/sdk/patterns.cpp @@ -176,6 +176,7 @@ namespace SDK { // C_Human2CarWrapper gPatterns.C_Human2CarWrapper__GetSeatID = hook::get_opcode_address("E8 ? ? ? ? 3D ? ? ? ? 75 0E"); + gPatterns.C_Human2CarWrapper__IsEngineOn = hook::get_opcode_address("E8 ? ? ? ? 84 C0 75 16 44 8B 87 ? ? ? ?"); // C_HumanInventory gPatterns.C_HumanInventory__AddItem = hook::get_opcode_address("E8 ? ? ? ? E9 ? ? ? ? 41 8B D6"); diff --git a/code/client/src/sdk/patterns.h b/code/client/src/sdk/patterns.h index 2237585c..b89871ed 100644 --- a/code/client/src/sdk/patterns.h +++ b/code/client/src/sdk/patterns.h @@ -155,6 +155,7 @@ namespace SDK { // C_Human2CarWrapper uint64_t C_Human2CarWrapper__GetSeatID = 0x0; + uint64_t C_Human2CarWrapper__IsEngineOn = 0x0; // C_HumanInventory uint64_t C_HumanInventory__AddItem = 0x0; diff --git a/code/client/src/sdk/wrappers/c_human_2_car_wrapper.cpp b/code/client/src/sdk/wrappers/c_human_2_car_wrapper.cpp index b117f66b..6dba9d7c 100644 --- a/code/client/src/sdk/wrappers/c_human_2_car_wrapper.cpp +++ b/code/client/src/sdk/wrappers/c_human_2_car_wrapper.cpp @@ -7,6 +7,10 @@ namespace SDK { return GetSeatID(pActor) == 0; } + bool C_Human2CarWrapper::IsEngineOn() { + return hook::this_call(gPatterns.C_Human2CarWrapper__IsEngineOn, this); + } + unsigned int C_Human2CarWrapper::GetSeatID(C_Actor *pActor) { return hook::this_call(gPatterns.C_Human2CarWrapper__GetSeatID, this, pActor); } diff --git a/code/client/src/sdk/wrappers/c_human_2_car_wrapper.h b/code/client/src/sdk/wrappers/c_human_2_car_wrapper.h index 9593deb1..793ed9f5 100644 --- a/code/client/src/sdk/wrappers/c_human_2_car_wrapper.h +++ b/code/client/src/sdk/wrappers/c_human_2_car_wrapper.h @@ -10,6 +10,7 @@ namespace SDK { C_Car *m_pUsedCar; // 0018 - 0020 public: bool IsDriver(C_Actor *); + bool IsEngineOn(); unsigned int GetSeatID(C_Actor *); }; } From d46700bb1bab776b144227112f297ef966e09604 Mon Sep 17 00:00:00 2001 From: Segfault <5221072+Segfaultd@users.noreply.github.com> Date: Mon, 5 Feb 2024 19:48:12 +0100 Subject: [PATCH 4/7] reversed vehicle flags, fixed beacon lights getter --- code/client/src/sdk/entities/c_vehicle.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/client/src/sdk/entities/c_vehicle.h b/code/client/src/sdk/entities/c_vehicle.h index 6e4d672b..fe97b840 100644 --- a/code/client/src/sdk/entities/c_vehicle.h +++ b/code/client/src/sdk/entities/c_vehicle.h @@ -31,7 +31,7 @@ namespace SDK { void SetEngineOn(bool on, bool arg2); bool IsEngineOn() const { - return false; // TODO: implement me + return false; } void SetPower(float power); @@ -94,7 +94,7 @@ namespace SDK { void SetBeaconLightsOn(bool on); bool GetBeaconLightsOn() { - return false; // TODO: implement me + return (m_uFlags & 0x40) != 0; } void SetSearchLightsOn(bool on); @@ -145,7 +145,9 @@ namespace SDK { char pad7[0x8]; // 0C58 - 0C60 float m_fDirty; // 0C60 - 0C64 float m_fRust; // 0C64 - 0C68 - char pad8[0x890]; // 0C68 - 14F8 + char pad8[0x98]; // 0C68 - 0D00 + uint64_t m_uFlags; // 0D00 - 0D08 + char pad9[0x7F0]; // 0D08 - 14F8 ue::game::audio::radio::C_RadioSound *m_pRadioSound; // 14F8 - 1500 }; } // namespace SDK From d552ffde9a0c197e8c74909ee90ddbb95146c3f8 Mon Sep 17 00:00:00 2001 From: Segfault <5221072+Segfaultd@users.noreply.github.com> Date: Mon, 5 Feb 2024 19:59:26 +0100 Subject: [PATCH 5/7] Update c_vehicle.h --- code/client/src/sdk/entities/c_vehicle.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/client/src/sdk/entities/c_vehicle.h b/code/client/src/sdk/entities/c_vehicle.h index fe97b840..87bec6c3 100644 --- a/code/client/src/sdk/entities/c_vehicle.h +++ b/code/client/src/sdk/entities/c_vehicle.h @@ -9,6 +9,10 @@ #include namespace SDK { + enum E_VehicleFlags { + BEACON_LIGHTS = 0x40, + }; + class C_Vehicle { public: void AddVehicleFlags(uint64_t); @@ -94,7 +98,7 @@ namespace SDK { void SetBeaconLightsOn(bool on); bool GetBeaconLightsOn() { - return (m_uFlags & 0x40) != 0; + return (m_uFlags & E_VehicleFlags::BEACON_LIGHTS) != 0; } void SetSearchLightsOn(bool on); From 459e497d9ef9293b23286c6cebbcda76720f8f9b Mon Sep 17 00:00:00 2001 From: Segfault <5221072+Segfaultd@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:25:21 +0100 Subject: [PATCH 6/7] IsEngineOn --- code/client/src/core/ui/vehicle_debug.cpp | 2 +- code/client/src/sdk/entities/c_car.h | 5 +++++ code/client/src/sdk/entities/c_vehicle.h | 3 --- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/code/client/src/core/ui/vehicle_debug.cpp b/code/client/src/core/ui/vehicle_debug.cpp index 951461d2..953e0418 100644 --- a/code/client/src/core/ui/vehicle_debug.cpp +++ b/code/client/src/core/ui/vehicle_debug.cpp @@ -102,7 +102,7 @@ namespace MafiaMP::Core::UI { currentVehicle->SetBeaconLightsOn(beaconsLight); } - bool isEngineOn = currentVehicle->IsEngineOn(); + bool isEngineOn = currentCar->IsEngineOn(); if (ImGui::Checkbox("Engine", &isEngineOn)) { currentVehicle->SetEngineOn(isEngineOn, isEngineOn); } diff --git a/code/client/src/sdk/entities/c_car.h b/code/client/src/sdk/entities/c_car.h index 13fe43ce..b61bca19 100644 --- a/code/client/src/sdk/entities/c_car.h +++ b/code/client/src/sdk/entities/c_car.h @@ -54,5 +54,10 @@ namespace SDK { C_Vehicle *GetVehicle() { return reinterpret_cast((uintptr_t)this + 0xF8); } + + bool IsEngineOn() const { + uint64_t flags = *reinterpret_cast((uintptr_t)this + 0x1280); + return (flags >> 2) & 1; + } }; } // namespace SDK diff --git a/code/client/src/sdk/entities/c_vehicle.h b/code/client/src/sdk/entities/c_vehicle.h index 87bec6c3..70e65509 100644 --- a/code/client/src/sdk/entities/c_vehicle.h +++ b/code/client/src/sdk/entities/c_vehicle.h @@ -34,9 +34,6 @@ namespace SDK { } void SetEngineOn(bool on, bool arg2); - bool IsEngineOn() const { - return false; - } void SetPower(float power); float GetPower() const { From 651304cb5d5f41c5491a908be6c8672bd0d69f78 Mon Sep 17 00:00:00 2001 From: Segfault <5221072+Segfaultd@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:27:33 +0100 Subject: [PATCH 7/7] Update c_car.h --- code/client/src/sdk/entities/c_car.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/client/src/sdk/entities/c_car.h b/code/client/src/sdk/entities/c_car.h index b61bca19..555b3b7f 100644 --- a/code/client/src/sdk/entities/c_car.h +++ b/code/client/src/sdk/entities/c_car.h @@ -52,10 +52,12 @@ namespace SDK { void ExplodeCar(float, bool); C_Vehicle *GetVehicle() { + // TODO: move to class fields return reinterpret_cast((uintptr_t)this + 0xF8); } bool IsEngineOn() const { + // TODO: move to class fields uint64_t flags = *reinterpret_cast((uintptr_t)this + 0x1280); return (flags >> 2) & 1; }