Skip to content

Commit

Permalink
more mesh control
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhumbert committed Feb 23, 2023
1 parent ea8b22d commit 7a3eca7
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 98 deletions.
159 changes: 111 additions & 48 deletions build/r6/scripts/let_there_be_flight/let_there_be_flight.packed.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 2023-02-23 04:49:14.3090946
// This file was automatically generated on 2023-02-23 17:04:25.9728444

// FlightAudio.reds

Expand Down Expand Up @@ -1486,6 +1486,12 @@ public native class FlightComponent extends GameComponent {

// FlightConfiguration.reds

enum FlightVehicleType {
Streetkid = 0,
Nomad = 1,
Corpo = 2
}

public abstract native class IFlightConfiguration extends IScriptable {
@runtimeProperty("offset", "0x40")
public native let component: ref<FlightComponent>;
Expand All @@ -1499,11 +1505,32 @@ public abstract native class IFlightConfiguration extends IScriptable {
@runtimeProperty("offset", "0x68")
public native let flightCameraOffset: Vector3; // 0, 0, 0

public func OnSetup(vehicle: ref<VehicleObject>) {
public let type: FlightVehicleType = FlightVehicleType.Corpo;

public func OnSetup(vehicle: ref<VehicleObject>) {
// switch (vehicle.currentAppearance) {
// case n"thorton_galena_nomad_player_01":
// this.type = FlightVehicleType.Nomad;
// break;
// case n"chevalier_emperor__basic_police":
// this.type = FlightVehicleType.Corpo;
// break;
// case n"quadra_type66__basic_poor_03":
// case n"arch_nemesis_basic_jackie":
// case n"mahir_supron__basic_urban_02":
// case n"thorton_galena__basic_player_01":
// default:
// this.type = FlightVehicleType.Streetkid;
// break;
// }
}
}

public func CreateEmptyThruster() -> ref<MeshComponent> {
let mc = new MeshComponent();
return mc;
}

public func CreateCorpoThruster() -> ref<MeshComponent> {
let mc = new PhysicalMeshComponent();
mc.SetMesh(r"user\\jackhumbert\\meshes\\engine_corpo.mesh");
Expand All @@ -1522,14 +1549,21 @@ public func CreateNomadThruster() -> ref<MeshComponent> {
return mc;
}


public class CarFlightConfiguration extends IFlightConfiguration {
public func OnSetup(vehicle: ref<VehicleObject>) {
// FlightLog.Info("[CarFlightConfiguration] OnSetup");
ArrayPush(this.thrusters, new FlightThrusterFL().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterFR().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterBL().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterBR().Create(vehicle, CreateCorpoThruster()));
super.OnSetup(vehicle);

if (Equals(this.type, FlightVehicleType.Corpo)) {
ArrayPush(this.thrusters, new FlightThrusterFL().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterFR().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterBL().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterBR().Create(vehicle, CreateCorpoThruster()));
} else {
ArrayPush(this.thrusters, new FlightThrusterFL().Create(vehicle, CreateNomadThruster()));
ArrayPush(this.thrusters, new FlightThrusterFR().Create(vehicle, CreateNomadThruster()));
ArrayPush(this.thrusters, new FlightThrusterBL().Create(vehicle, CreateNomadThruster()));
ArrayPush(this.thrusters, new FlightThrusterBR().Create(vehicle, CreateNomadThruster()));
}

for thruster in this.thrusters {
vehicle.AddComponent(thruster.meshComponent);
Expand All @@ -1540,26 +1574,42 @@ public class CarFlightConfiguration extends IFlightConfiguration {

public class SixWheelCarFlightConfiguration extends CarFlightConfiguration {
public func OnSetup(vehicle: ref<VehicleObject>) {
ArrayPush(this.thrusters, new FlightThrusterFL().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterFR().Create(vehicle, CreateCorpoThruster()));
// ArrayPush(this.thrusters, new FlightThrusterFLB().Create());
// ArrayPush(this.thrusters, new FlightThrusterFRB().Create());
ArrayPush(this.thrusters, new FlightThrusterBL().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterBR().Create(vehicle, CreateCorpoThruster()));
super.OnSetup(vehicle);

for thruster in this.thrusters {
vehicle.AddComponent(thruster.meshComponent);
thruster.OnSetup(this.component);
}
ArrayPush(this.thrusters, new FlightThrusterFLB().Create(vehicle, CreateNomadThruster()));
ArrayPush(this.thrusters, new FlightThrusterFRB().Create(vehicle, CreateNomadThruster()));

vehicle.AddComponent(this. thrusters[4].meshComponent);
this.thrusters[4].OnSetup(this.component);

vehicle.AddComponent(this. thrusters[5].meshComponent);
this.thrusters[5].OnSetup(this.component);
}
}

public class BikeFlightConfiguration extends IFlightConfiguration {
public func OnSetup(vehicle: ref<VehicleObject>) {
super.OnSetup(vehicle);

this.flightCameraOffset = new Vector3(0.0, 1.0, 0.5);

ArrayPush(this.thrusters, new FlightThrusterFront().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterBack().Create(vehicle, CreateCorpoThruster()));
ArrayPush(this.thrusters, new FlightThrusterFront().Create(vehicle, CreateEmptyThruster()));
ArrayPush(this.thrusters, new FlightThrusterBack().Create(vehicle, CreateEmptyThruster()));

let mesh: ref<MeshComponent>;
mesh = CreateNomadThruster();
// mesh.visualScale = new Vector3(1.0, 0.5, 1.0);
// mesh.SetLocalPosition(new Vector4(0.0, 0.0, -0.2, 1.0));
mesh.SetLocalOrientation(new Quaternion(0.0, 0.0, 0.707, -0.707));
mesh.SetParentTransform(this.thrusters[0].meshComponent.name, n"None");
vehicle.AddComponent(mesh);

mesh = CreateNomadThruster();
// mesh.visualScale = new Vector3(1.0, 0.5, 1.0);
// mesh.SetLocalPosition(new Vector4(0.0, 0.0, -0.2, 1.0));
mesh.SetLocalOrientation(new Quaternion(0.0, 0.0, -0.707, -0.707));
mesh.SetParentTransform(this.thrusters[1].meshComponent.name, n"None");
vehicle.AddComponent(mesh);

for thruster in this.thrusters {
vehicle.AddComponent(thruster.meshComponent);
Expand Down Expand Up @@ -3974,7 +4024,7 @@ public class FlightThrusterFront extends IFlightThruster {
angle = 0.0;
}
angle *= (1.0 - AbsF(this.torque.Y) * 0.5);
return ClampF(angle, -this.maxThrusterAnglePitch, this.maxThrusterAnglePitch);
return -ClampF(angle, -this.maxThrusterAnglePitch, this.maxThrusterAnglePitch);
}

public func GetYaw() -> Float {
Expand Down Expand Up @@ -4180,11 +4230,13 @@ public class FlightThrusterBL extends IFlightThruster {
// FRONT LEFT B

public class FlightThrusterFLB extends IFlightThruster {
public func Create() -> ref<IFlightThruster> {
this.boneName = n"swingarm_front_left_b";
this.slotName = n"thruster_front_left_b";
this.meshName = n"ThrusterFLB";
this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0);
public func Create(vehicle: ref<VehicleObject>, meshComponent: ref<MeshComponent>) -> ref<IFlightThruster> {
this.vehicle = vehicle;
this.vehicle.AddSlot(n"swingarm_front_left_b", n"thruster_front_left_b", new Vector3(0.0, 0.0, 0.0), new Quaternion(0.0, 0.0, 0.0, 1.0));

this.meshComponent = meshComponent;
this.meshComponent.name = n"ThrusterFLB";
this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_front_left_b");

this.isFront = true;
this.isB = true;
Expand All @@ -4208,11 +4260,13 @@ public class FlightThrusterFLB extends IFlightThruster {
// FRONT LEFT B

public class FlightThrusterFRB extends IFlightThruster {
public func Create() -> ref<IFlightThruster> {
this.boneName = n"swingarm_front_right_b";
this.slotName = n"thruster_front_right_b";
this.meshName = n"ThrusterFRB";
this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0);
public func Create(vehicle: ref<VehicleObject>, meshComponent: ref<MeshComponent>) -> ref<IFlightThruster> {
this.vehicle = vehicle;
this.vehicle.AddSlot(n"swingarm_front_right_b", n"thruster_front_right_b", new Vector3(0.0, 0.0, 0.0), new Quaternion(0.0, 0.0, 0.0, 1.0));

this.meshComponent = meshComponent;
this.meshComponent.name = n"ThrusterFRB";
this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_front_right_b");

this.isFront = true;
this.isRight = true;
Expand Down Expand Up @@ -6017,24 +6071,24 @@ public class BouncyEffector extends Effector {
// }


@wrapMethod(QuickHackDescriptionGameController)
protected cb func OnQuickHackDataChanged(value: Variant) -> Bool {
wrappedMethod(value);
this.m_selectedData = FromVariant<ref<QuickhackData>>(value);
if IsDefined(this.m_selectedData) {
let title: String = GetLocalizedText(this.m_selectedData.m_title);
if StrLen(title) == 0 {
title = ToString(this.m_selectedData.m_title);
}
inkTextRef.SetText(this.m_subHeader, title);
// @wrapMethod(QuickHackDescriptionGameController)
// protected cb func OnQuickHackDataChanged(value: Variant) -> Bool {
// wrappedMethod(value);
// this.m_selectedData = FromVariant<ref<QuickhackData>>(value);
// if IsDefined(this.m_selectedData) {
// let title: String = GetLocalizedText(this.m_selectedData.m_title);
// if StrLen(title) == 0 {
// title = ToString(this.m_selectedData.m_title);
// }
// inkTextRef.SetText(this.m_subHeader, title);

let description: String = GetLocalizedText(this.m_selectedData.m_description);
if StrLen(description) == 0 {
description = ToString(this.m_selectedData.m_description);
}
inkTextRef.SetText(this.m_description, description);
}
}
// let description: String = GetLocalizedText(this.m_selectedData.m_description);
// if StrLen(description) == 0 {
// description = ToString(this.m_selectedData.m_description);
// }
// inkTextRef.SetText(this.m_description, description);
// }
// }

// vehicleTPPCameraComponent.reds

Expand Down Expand Up @@ -6395,6 +6449,14 @@ public native func SetBlurDimension(effectName: CName, blurDimension : inkEBlurD

// Entity

@addField(Entity)
@runtimeProperty("offset", "0x50")
public native let currentAppearance: CName;

@addField(Entity)
@runtimeProperty("offset", "0x138")
public native let entityTags: array<CName>;

@addMethod(Entity)
public native func AddComponent(component: ref<IComponent>);

Expand All @@ -6413,6 +6475,7 @@ public native let appearanceName: CName;

// IPlacedComponent

// bindName is component name - can be SlotComponent like vehicle_slots
@addMethod(IPlacedComponent)
public native func SetParentTransform(bindName: CName, slotName: CName);

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 2023-02-23 04:49:14.3646377
# This file was automatically generated on 2023-02-23 17:04:27.5158096

# quickhacks.yaml

Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions src/red4ext/Addresses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define CreateCRTTIRaRefTypeFromClassAddr 0x200920
#define ProcessScriptTypesAddr 0x277560
#define LoadResRefTAddr 0x204A90
#define LookupLocalizedStringAddr 0x6FA540
#define CGameFramework_Systems_120_128_130Addr 0x13A19A0
#define CClass_AddEventCallbackTypeAddr 0x1F96B0
#define CClass_SetupScriptCallbacksAddr 0x1F9790
Expand Down
2 changes: 2 additions & 0 deletions src/red4ext/EntityAddComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ void __fastcall Entity_InitializeComponents_Hook(RED4ext::ent::Entity *entity, v
fc->entity = entity;
auto fch = RED4ext::Handle<FlightComponent>(fc);
vehicle->componentsStorage.components.EmplaceBack(fch);

//vehicle->entityTags.tags;

//FlightWeapons::AddWeapons(vehicle);

Expand Down
34 changes: 34 additions & 0 deletions src/red4ext/GetLocalizedText.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "Addresses.hpp"
#include "FlightModule.hpp"

// Vehicle Speed Unlimiter

struct GetLocalizedTextFixer : FlightModule {
void Load(const RED4ext::Sdk *aSdk, RED4ext::PluginHandle aHandle);
void Unload(const RED4ext::Sdk *aSdk, RED4ext::PluginHandle aHandle);
static RED4ext::CString *__fastcall LookupLocalizedString(__int64, RED4ext::CString *result, char *locKey);
};

decltype(&GetLocalizedTextFixer::LookupLocalizedString) LookupLocalizedString_Original;

RED4ext::CString *__fastcall GetLocalizedTextFixer::LookupLocalizedString(__int64 db, RED4ext::CString *result,
char *locKey) {
auto og = LookupLocalizedString_Original(db, result, locKey);
if (result->length == 0) {
result = new RED4ext::CString(locKey);
}
return result;
}

void GetLocalizedTextFixer::Load(const RED4ext::Sdk *aSdk, RED4ext::PluginHandle aHandle) {
while (!aSdk->hooking->Attach(aHandle, RED4EXT_OFFSET_TO_ADDR(LookupLocalizedStringAddr),
&LookupLocalizedString, reinterpret_cast<void **>(&LookupLocalizedString_Original)))
;
}

void GetLocalizedTextFixer::Unload(const RED4ext::Sdk *aSdk, RED4ext::PluginHandle aHandle) {
aSdk->hooking->Detach(aHandle, RED4EXT_OFFSET_TO_ADDR(PhysicsStructUpdateAddr));
aSdk->hooking->Detach(aHandle, RED4EXT_OFFSET_TO_ADDR(PhysicsUnkStructVelocityUpdateAddr));
}

REGISTER_FLIGHT_MODULE(GetLocalizedTextFixer);
11 changes: 10 additions & 1 deletion src/red4ext/Signatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,13 @@ using ProcessScriptTypes = bool __fastcall (uint32_t *version, ScriptData *scrip
// 1.6 RVA: 0x204390
// 1.61 RVA: 0x204940
/// @pattern 48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 60 41 0F B6 D8 48 8B FA 48 8B F1 48 C7 44 24 20 00 00
using LoadResRefT = void * (void *, void*, bool);
using LoadResRefT = void * (void *, void*, bool);

// 1.52 RVA: 0x9A4290 / 10109584
// 1.62 RVA: 0x9AE2D0 / 10150608
/// @pattern 48 89 5C 24 08 48 89 74 24 10 57 48 81 EC A0 00 00 00 48 8D 4C 24 30 49 8B F0 48 8B FA E8
//using GetLocalizedTextScripts = void __fastcall (void *, RED4ext::CStackFrame *, RED4ext::CString *);

// 1.62 RVA: 0x6FA540 / 7316800
/// @pattern 40 53 48 83 EC 30 F2 41 0F 10 00 48 8B DA 41 8B 40 08 4C 8D 44 24 20 44 0F B6 89 39 04 00 00 F2
using LookupLocalizedString = RED4ext::CString * __fastcall (__int64, RED4ext::CString * result, char * locKey);
Binary file modified src/red4ext/build/release/bin/flight_control.pdb
Binary file not shown.
1 change: 1 addition & 0 deletions src/red4ext/flight_control.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<ClCompile Include="FlightThruster.cpp" />
<ClCompile Include="FlightWeapons.cpp" />
<ClCompile Include="FxResource.cpp" />
<ClCompile Include="GetLocalizedText.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="FlightAudio.cpp" />
<ClCompile Include="FmodHelper.hpp" />
Expand Down
Loading

0 comments on commit 7a3eca7

Please sign in to comment.