Skip to content

Commit

Permalink
progress on #55
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhumbert committed Aug 21, 2022
1 parent 54cc6d9 commit 4adff76
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build/r6/scripts/let_there_be_flight.reds
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Let There Be Flight
// (C) 2022 Jack Humbert
// https://github.com/jackhumbert/let_there_be_flight
// This file was automatically generated on 2022-08-20 03:28:26.4982273
// This file was automatically generated on 2022-08-20 16:42:17.9271975

// FlightAudio.reds

Expand Down
2 changes: 1 addition & 1 deletion build/r6/tweaks/let_there_be_flight.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Let There Be Flight
# (C) 2022 Jack Humbert
# https://github.com/jackhumbert/let_there_be_flight
# This file was automatically generated on 2022-08-20 03:28:26.7497884
# This file was automatically generated on 2022-08-20 16:42:18.0689030

# thrusters.yaml

Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions src/red4ext/FlightSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void UpdateComponents(RED4ext::Unk2 *unk2, float *deltaTime, void *unkStruct) {
auto vehicle = reinterpret_cast<RED4ext::vehicle::BaseObject *>(fc->entity.GetPtr());
//auto activeProp = fcc->GetProperty("hasUpdate");
if (fc->hasUpdate && vehicle->physicsData) {
// removes Asleep/0x10
vehicle->SetPhysicsState(0x10u, 1u);
// auto onUpdate = fcc->GetFunction("OnUpdate");
// auto args = RED4ext::CStackType(rtti->GetType("Float"), &deltaTime);
Expand Down
40 changes: 23 additions & 17 deletions src/red4ext/VehiclePhysicsUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <RED4ext/RED4ext.hpp>
#include <spdlog/spdlog.h>
#include "VehiclePhysicsUpdate.hpp"
#include "FlightComponent.hpp"

// main vehicle physics update
uintptr_t __fastcall VehiclePhysicsUpdate(RED4ext::vehicle::Physics *, float);
Expand Down Expand Up @@ -61,24 +62,12 @@ uint64_t __fastcall UpdateAnimValueForCName(RED4ext::vehicle::BaseObject *vehicl
return call(vehicle->unk570, name, value);
}


RED4ext::ent::IComponent *GetFlightComponent(RED4ext::vehicle::Physics *p) {
auto rtti = RED4ext::CRTTISystem::Get();
auto fcc = rtti->GetClass("FlightComponent");
for (auto const &c : p->parent->componentsStorage.components) {
if (c.GetPtr()->GetType() == fcc) {
return c.GetPtr();
}
}
return NULL;
}

RED4ext::ent::IComponent *GetFlightComponent(RED4ext::vehicle::BaseObject *v) {
FlightComponent *GetFlightComponent(RED4ext::vehicle::BaseObject *v) {
auto rtti = RED4ext::CRTTISystem::Get();
auto fcc = rtti->GetClass("FlightComponent");
for (auto const &c : v->componentsStorage.components) {
if (c.GetPtr()->GetType() == fcc) {
return c.GetPtr();
return (FlightComponent*)c.GetPtr();
}
}
return NULL;
Expand Down Expand Up @@ -143,8 +132,6 @@ uintptr_t __fastcall VehiclePhysicsUpdate(RED4ext::vehicle::Physics *p, float de
return VehiclePhysicsUpdate_Original(p, deltaTime);
}


// update with pid
void __fastcall ProcessAirResistance(RED4ext::vehicle::WheeledPhysics *a1, float deltaTime);

// 48 8B C4 53 48 81 EC A0 00 00 00 0F 29 70 E8 48 8B D9 0F 29 78 D8 44 0F 29 40 C8 44 0F 29 48 B8
Expand Down Expand Up @@ -196,7 +183,7 @@ void __fastcall AirControlProcess(RED4ext::vehicle::AirControl *ac, float deltaT
uintptr_t __fastcall VehicleHelperUpdate(RED4ext::vehicle::WheeledPhysics *p, float deltaTime) {
auto rtti = RED4ext::CRTTISystem::Get();
auto fcc = rtti->GetClass("FlightComponent");
auto fc = GetFlightComponent(p);
auto fc = GetFlightComponent(p->parent);
if (fc) {
auto activeProp = fcc->GetProperty("active");
auto size = p->driveHelpers.size;
Expand Down Expand Up @@ -277,6 +264,22 @@ uintptr_t __fastcall BikeAnimationUpdate(RED4ext::vehicle::BikePhysics *a1) {
return og;
}

void __fastcall FourWheelTorque(RED4ext::vehicle::WheeledPhysics *physics, unsigned __int8 rearWheelIndex,
unsigned __int8 frontWheelIndex, float a4, RED4ext::Transform *transform);

// 40 53 48 81 EC A0 00 00 00 44 0F B6 D2 4C 8D 89 D0 05 00 00 41 0F B6 C0 48 8B D9 4D 69 C2 30 01
constexpr uintptr_t FourWheelTorqueAddr = 0x1D0E8D0;
decltype(&FourWheelTorque) FourWheelTorque_Original;

void __fastcall FourWheelTorque(RED4ext::vehicle::WheeledPhysics *physics,
unsigned __int8 rearWheelIndex, unsigned __int8 frontWheelIndex,
float a4, RED4ext::Transform *transform) {
auto fc = GetFlightComponent(physics->parent);
if (!fc->hasUpdate) {
FourWheelTorque_Original(physics, rearWheelIndex, frontWheelIndex, a4, transform);
}
}

struct VehiclePhysicsUpdateModule : FlightModule {
void Load(const RED4ext::Sdk *aSdk, RED4ext::PluginHandle aHandle) {
while (!aSdk->hooking->Attach(aHandle, RED4EXT_OFFSET_TO_ADDR(VehiclePhysicsUpdateAddr), &VehiclePhysicsUpdate,
Expand All @@ -296,6 +299,8 @@ struct VehiclePhysicsUpdateModule : FlightModule {
reinterpret_cast<void **>(&AnimationUpdate_Original)));
while (!aSdk->hooking->Attach(aHandle, RED4EXT_OFFSET_TO_ADDR(RED4ext::vehicle::BikePhysics::AnimationUpdateAddr), &BikeAnimationUpdate,
reinterpret_cast<void **>(&BikeAnimationUpdate_Original)));
while (!aSdk->hooking->Attach(aHandle, RED4EXT_OFFSET_TO_ADDR(FourWheelTorqueAddr), &FourWheelTorque,
reinterpret_cast<void **>(&FourWheelTorque_Original)));
}
void Unload(const RED4ext::Sdk *aSdk, RED4ext::PluginHandle aHandle) {
aSdk->hooking->Detach(aHandle, RED4EXT_OFFSET_TO_ADDR(ProcessAirResistanceAddr));
Expand All @@ -306,6 +311,7 @@ struct VehiclePhysicsUpdateModule : FlightModule {
aSdk->hooking->Detach(aHandle, RED4EXT_OFFSET_TO_ADDR(VehicleUpdateOrientationWithPIDAddr));
aSdk->hooking->Detach(aHandle, RED4EXT_OFFSET_TO_ADDR(AnimationUpdateAddr));
aSdk->hooking->Detach(aHandle, RED4EXT_OFFSET_TO_ADDR(RED4ext::vehicle::BikePhysics::AnimationUpdateAddr));
aSdk->hooking->Detach(aHandle, RED4EXT_OFFSET_TO_ADDR(FourWheelTorqueAddr));
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/red4ext/VehiclePhysicsUpdate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
#include <RED4ext/RED4ext.hpp>
#include <spdlog/spdlog.h>

RED4ext::ent::IComponent *GetFlightComponent(RED4ext::vehicle::BaseObject *v);
struct FlightComponent;

FlightComponent *GetFlightComponent(RED4ext::vehicle::BaseObject *v);

0 comments on commit 4adff76

Please sign in to comment.