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

Reversed IsEngineOn, GetSiren and GetBeaconLightsOn #90

Merged
merged 10 commits into from
Feb 5, 2024
2 changes: 1 addition & 1 deletion code/client/src/core/modules/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace MafiaMP::Core::Modules {
metadata.radioStationId = vehicle->GetRadioStation();
metadata.rimColor = {rimColor.r, rimColor.g, rimColor.b, rimColor.a};
metadata.rust = vehicle->GetVehicleRust();
metadata.sirenOn = vehicle->GetSiren();
metadata.sirenOn = vehicle->IsSiren();
metadata.steer = vehicle->GetSteer();
metadata.tireColor = {tireColor.r, tireColor.g, tireColor.b, tireColor.a};
metadata.velocity = {vehicleVelocity.x, vehicleVelocity.y, vehicleVelocity.z};
Expand Down
9 changes: 8 additions & 1 deletion code/client/src/core/ui/vehicle_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace MafiaMP::Core::UI {

if (currentCar) {
auto currentVehicle = currentCar->GetVehicle();
ImGui::Text("Car Ptr: %p", currentCar);
ImGui::Text("Vehicle Ptr: %p", currentVehicle);
Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not anymore :-)


auto position = currentCar->GetPos();
if (ImGui::DragFloat3("Pos", (float *)&position, 0.1f, -4500.0f, 4500.0f)) {
Expand Down Expand Up @@ -90,7 +92,7 @@ namespace MafiaMP::Core::UI {
currentVehicle->SetHorn(horn);
}

bool siren = currentVehicle->GetSiren();
bool siren = currentVehicle->IsSiren();
if (ImGui::Checkbox("Siren", &siren)) {
currentVehicle->SetSiren(siren);
}
Expand All @@ -100,6 +102,11 @@ namespace MafiaMP::Core::UI {
currentVehicle->SetBeaconLightsOn(beaconsLight);
}

bool isEngineOn = currentCar->IsEngineOn();
if (ImGui::Checkbox("Engine", &isEngineOn)) {
currentVehicle->SetEngineOn(isEngineOn, isEngineOn);
}
Comment on lines +105 to +108
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, getter is on Car and setter on Vehicle?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly


SDK::ue::sys::math::C_Vector4 color1, color2;
currentVehicle->GetVehicleColor(&color1, &color2);

Expand Down
7 changes: 7 additions & 0 deletions code/client/src/sdk/entities/c_car.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ namespace SDK {
void ExplodeCar(float, bool);

C_Vehicle *GetVehicle() {
// TODO: move to class fields
return reinterpret_cast<C_Vehicle *>((uintptr_t)this + 0xF8);
}

bool IsEngineOn() const {
// TODO: move to class fields
uint64_t flags = *reinterpret_cast<uint64_t *>((uintptr_t)this + 0x1280);
return (flags >> 2) & 1;
}
};
} // namespace SDK
8 changes: 8 additions & 0 deletions code/client/src/sdk/entities/c_vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ namespace SDK {
hook::this_call(gPatterns.C_Vehicle__SetSiren, this, on);
}

bool C_Vehicle::IsSiren() {
return hook::this_call<bool>(gPatterns.C_Vehicle__IsSiren, this);
}

void C_Vehicle::SetSteer(float steer) {
hook::this_call(gPatterns.C_Vehicle__SetSteer, this, steer);
}
Expand Down Expand Up @@ -146,6 +150,10 @@ namespace SDK {
return (m_pRadioSound && m_pRadioSound->IsRadioOn());
}

bool C_Vehicle::IsAnyLightOn() {
return hook::this_call<bool>(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<void *>(reinterpret_cast<uint64_t>(this) + 0x268);
Expand Down
19 changes: 11 additions & 8 deletions code/client/src/sdk/entities/c_vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <cstdint>

namespace SDK {
enum E_VehicleFlags {
BEACON_LIGHTS = 0x40,
};

class C_Vehicle {
public:
void AddVehicleFlags(uint64_t);
Expand All @@ -30,19 +34,14 @@ namespace SDK {
}

void SetEngineOn(bool on, bool arg2);
bool IsEngineOn() const {
return false; // TODO: implement me
}

void SetPower(float power);
float GetPower() const {
return m_fPower;
}

void SetSiren(bool on);
bool GetSiren() const {
return false; // TODO: implement me
}
bool IsSiren();

void SetSteer(float steer);
float GetSteer() const {
Expand Down Expand Up @@ -96,7 +95,7 @@ namespace SDK {

void SetBeaconLightsOn(bool on);
bool GetBeaconLightsOn() {
return false; // TODO: implement me
return (m_uFlags & E_VehicleFlags::BEACON_LIGHTS) != 0;
}
void SetSearchLightsOn(bool on);

Expand All @@ -107,6 +106,8 @@ namespace SDK {

void Damage(bool arg1);

bool IsAnyLightOn();

bool IsRadioOn();
void EnableRadio(bool enable);
void TurnRadioOn(bool on);
Expand Down Expand Up @@ -145,7 +146,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
2 changes: 2 additions & 0 deletions code/client/src/sdk/patterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -371,6 +372,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<uint64_t>(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 ? ? ? ?");
Expand Down
2 changes: 2 additions & 0 deletions code/client/src/sdk/patterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -326,6 +327,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;
Expand Down
4 changes: 4 additions & 0 deletions code/client/src/sdk/wrappers/c_human_2_car_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ namespace SDK {
return GetSeatID(pActor) == 0;
}

bool C_Human2CarWrapper::IsEngineOn() {
return hook::this_call<bool>(gPatterns.C_Human2CarWrapper__IsEngineOn, this);
}

unsigned int C_Human2CarWrapper::GetSeatID(C_Actor *pActor) {
return hook::this_call<unsigned int>(gPatterns.C_Human2CarWrapper__GetSeatID, this, pActor);
}
Expand Down
1 change: 1 addition & 0 deletions code/client/src/sdk/wrappers/c_human_2_car_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace SDK {
C_Car *m_pUsedCar; // 0018 - 0020
public:
bool IsDriver(C_Actor *);
bool IsEngineOn();
unsigned int GetSeatID(C_Actor *);
};
}
Loading