diff --git a/build/r6/scripts/let_there_be_flight/let_there_be_flight.packed.reds b/build/r6/scripts/let_there_be_flight/let_there_be_flight.packed.reds index d78334cc..a11306ea 100644 --- a/build/r6/scripts/let_there_be_flight/let_there_be_flight.packed.reds +++ b/build/r6/scripts/let_there_be_flight/let_there_be_flight.packed.reds @@ -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-22 04:16:50.6035886 +// This file was automatically generated on 2023-02-23 04:49:14.3090946 // FlightAudio.reds @@ -1499,52 +1499,70 @@ public abstract native class IFlightConfiguration extends IScriptable { @runtimeProperty("offset", "0x68") public native let flightCameraOffset: Vector3; // 0, 0, 0 - public func OnSetup() { + public func OnSetup(vehicle: ref) { } } -// public class FlightConfiguration extends IFlightConfiguration { +public func CreateCorpoThruster() -> ref { + let mc = new PhysicalMeshComponent(); + mc.SetMesh(r"user\\jackhumbert\\meshes\\engine_corpo.mesh"); + mc.meshApperance = n"default"; + mc.motionBlurScale = 0.1; + mc.LODMode = entMeshComponentLODMode.Appearance; + return mc; +} + +public func CreateNomadThruster() -> ref { + let mc = new PhysicalMeshComponent(); + mc.SetMesh(r"user\\jackhumbert\\meshes\\engine_nomad.mesh"); + mc.meshApperance = n"default"; + mc.motionBlurScale = 0.1; + mc.LODMode = entMeshComponentLODMode.Appearance; + return mc; +} -// } public class CarFlightConfiguration extends IFlightConfiguration { - public func OnSetup() { + public func OnSetup(vehicle: ref) { // FlightLog.Info("[CarFlightConfiguration] OnSetup"); - ArrayPush(this.thrusters, new FlightThrusterFL().Create()); - ArrayPush(this.thrusters, new FlightThrusterFR().Create()); - ArrayPush(this.thrusters, new FlightThrusterBL().Create()); - ArrayPush(this.thrusters, new FlightThrusterBR().Create()); + 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())); for thruster in this.thrusters { + vehicle.AddComponent(thruster.meshComponent); thruster.OnSetup(this.component); } } } public class SixWheelCarFlightConfiguration extends CarFlightConfiguration { - public func OnSetup() { - ArrayPush(this.thrusters, new FlightThrusterFL().Create()); - ArrayPush(this.thrusters, new FlightThrusterFR().Create()); - ArrayPush(this.thrusters, new FlightThrusterFLB().Create()); - ArrayPush(this.thrusters, new FlightThrusterFRB().Create()); - ArrayPush(this.thrusters, new FlightThrusterBL().Create()); - ArrayPush(this.thrusters, new FlightThrusterBR().Create()); + public func OnSetup(vehicle: ref) { + 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())); for thruster in this.thrusters { + vehicle.AddComponent(thruster.meshComponent); thruster.OnSetup(this.component); } } } public class BikeFlightConfiguration extends IFlightConfiguration { - public func OnSetup() { + public func OnSetup(vehicle: ref) { this.flightCameraOffset = new Vector3(0.0, 1.0, 0.5); - ArrayPush(this.thrusters, new FlightThrusterFront().Create()); - ArrayPush(this.thrusters, new FlightThrusterBack().Create()); + ArrayPush(this.thrusters, new FlightThrusterFront().Create(vehicle, CreateCorpoThruster())); + ArrayPush(this.thrusters, new FlightThrusterBack().Create(vehicle, CreateCorpoThruster())); for thruster in this.thrusters { + vehicle.AddComponent(thruster.meshComponent); thruster.OnSetup(this.component); } } @@ -3620,6 +3638,9 @@ public abstract native class IFlightThruster extends IScriptable { @runtimeProperty("offset", "0x90") public native let meshComponent: ref; + @runtimeProperty("offset", "0xA0") + public native let vehicle: ref; + public let parentSlotName: CName; public let radiusName: CName; public let deviationName: CName; @@ -3657,8 +3678,6 @@ public abstract native class IFlightThruster extends IScriptable { this.mainFxRes = Cast(this.mainResRef); this.retroFxRes = Cast(this.retroResRef); - // let vehicleComponent = this.flightComponent.GetVehicle().GetVehicleComponent(); - // this.meshComponent = vehicleComponent.FindComponentByName(this.meshName) as MeshComponent; this.meshComponent.visualScale = new Vector3(0.0, 0.0, 0.0); this.meshComponent.Toggle(false); @@ -3751,11 +3770,10 @@ public abstract native class IFlightThruster extends IScriptable { } public func SetOGComponents() { - this.ogComponents = this.flightComponent.GetVehicle().GetComponentsUsingSlot(this.parentSlotName); + this.ogComponents = this.vehicle.GetComponentsUsingSlot(this.parentSlotName); } public func Start() { - let vehicle = this.flightComponent.GetVehicle(); let effectTransform: WorldTransform; let wt = new WorldTransform(); @@ -3763,16 +3781,16 @@ public abstract native class IFlightThruster extends IScriptable { this.HideOGComponents(); WorldTransform.SetPosition(effectTransform, this.flightComponent.stats.d_position); - this.mainFx = GameInstance.GetFxSystem(vehicle.GetGame()).SpawnEffect(this.mainFxRes, effectTransform); + this.mainFx = GameInstance.GetFxSystem(this.vehicle.GetGame()).SpawnEffect(this.mainFxRes, effectTransform); this.mainFx.SetBlackboardValue(n"thruster_amount", 0.0); - this.mainFx.AttachToComponent(vehicle, entAttachmentTarget.Transform, this.meshName, wt); + this.mainFx.AttachToComponent(this.vehicle, entAttachmentTarget.Transform, this.meshComponent.name, wt); this.meshComponent.Toggle(true); let wt_retro: WorldTransform; WorldTransform.SetOrientation(wt_retro, EulerAngles.ToQuat(new EulerAngles(0.0, 0.0, -90.0))); - this.retroFx = GameInstance.GetFxSystem(vehicle.GetGame()).SpawnEffect(this.retroFxRes, effectTransform); - // this.retroFx.AttachToSlot(this.component.GetVehicle(), entAttachmentTarget.Transform, n"Base", wt_retro); - this.retroFx.AttachToComponent(vehicle, entAttachmentTarget.Transform, this.meshName, wt_retro); + this.retroFx = GameInstance.GetFxSystem(this.vehicle.GetGame()).SpawnEffect(this.retroFxRes, effectTransform); + // this.retroFx.AttachToSlot(this.component.Getthis.Vehicle(), entAttachmentTarget.Transform, n"Base", wt_retro); + this.retroFx.AttachToComponent(this.vehicle, entAttachmentTarget.Transform, this.meshComponent.name, wt_retro); // FlightAudio.Get().StartWithPitch(this.id, "vehicle3_TPP", this.audioPitch); FlightAudio.Get().StartWithPitch(this.id, "vehicle3_TPP", this.flightComponent.GetPitch()); @@ -3824,14 +3842,14 @@ public abstract native class IFlightThruster extends IScriptable { this.animDeviation = LerpF(this.boneLerpAmount, this.animDeviation, animDeviationCenter + amount * animDeviationScale); // this.animDeviation = animDeviationCenter + amount * animDeviationScale; // this.animRadius = animRadiusCenter + amount * animRadiusScale; - // AnimationControllerComponent.SetInputFloatToReplicate(this.flightComponent.GetVehicle(), this.deviationName, this.animDeviation); - // AnimationControllerComponent.SetInputFloatToReplicate(this.flightComponent.GetVehicle(), this.GetRadiusName(), this.animRadius); + // AnimationControllerComponent.SetInputFloatToReplicate(this.vehicle, this.deviationName, this.animDeviation); + // AnimationControllerComponent.SetInputFloatToReplicate(this.vehicle, this.GetRadiusName(), this.animRadius); let acc = this.flightComponent.FindComponentByName(n"AnimationController") as AnimationControllerComponent; if IsDefined(acc) { acc.SetInputFloat(this.deviationName, this.animDeviation); } - // AnimationControllerComponent.SetInputFloat(this.flightComponent.GetVehicle(), this.deviationName, this.animDeviation); + // AnimationControllerComponent.SetInputFloat(this.vehicle, this.deviationName, this.animDeviation); // acc.SetInputFloat(this.GetRadiusName(), this.animRadius); @@ -3902,13 +3920,16 @@ public abstract native class IFlightThruster extends IScriptable { } } +// FRONT + public class FlightThrusterFront extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"suspension_front_offset"; - this.slotName = n"thruster_front"; - this.meshName = n"ThrusterF"; - this.relativePosition = new Vector3(0.0, 0.0, -0.5); - this.relativeRotation = new Quaternion(0.22627002, 0.0, 0.0, -0.974064708); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"suspension_front_offset", n"thruster_front", new Vector3(0.0, 0.0, -0.5), new Quaternion(0.22627002, 0.0, 0.0, -0.974064708)); + + this.meshComponent = meshComponent; + this.meshComponent.name = n"ThrusterF"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_front"); this.isFront = true; this.parentSlotName = n"wheel_front_spring"; @@ -3933,7 +3954,7 @@ public class FlightThrusterFront extends IFlightThruster { if IsDefined(comp) { ArrayPush(this.ogComponents, comp); } - let comps = this.flightComponent.GetVehicle().GetComponentsUsingSlot(n"wheel_front_rot_set"); + let comps = this.vehicle.GetComponentsUsingSlot(n"wheel_front_rot_set"); for c in comps { ArrayPush(this.ogComponents, c); } @@ -3953,7 +3974,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 { @@ -3973,13 +3994,16 @@ public class FlightThrusterFront extends IFlightThruster { } } +// BACK + public class FlightThrusterBack extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"suspension_back"; - this.slotName = n"thruster_back"; - this.meshName = n"ThrusterB"; - this.relativePosition = new Vector3(0.0, 0.0, -0.5); - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"suspension_back", n"thruster_back", new Vector3(0.0, 0.0, -0.5), new Quaternion(0.0, 0.0, 0.0, 1.0)); + + this.meshComponent = meshComponent; + this.meshComponent.name = n"ThrusterB"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_back"); this.parentSlotName = n"axel_back"; this.radiusName = n"None"; @@ -4007,7 +4031,7 @@ public class FlightThrusterBack extends IFlightThruster { if IsDefined(comp) { ArrayPush(this.ogComponents, comp); } - let comps = this.flightComponent.GetVehicle().GetComponentsUsingSlot(n"axel_back_wheel"); + let comps = this.vehicle.GetComponentsUsingSlot(n"axel_back_wheel"); for c in comps { ArrayPush(this.ogComponents, c); } @@ -4039,12 +4063,16 @@ public class FlightThrusterBack extends IFlightThruster { } } +// FRONT LEFT + public class FlightThrusterFL extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"swingarm_front_left"; - this.slotName = n"thruster_front_left"; - this.meshName = n"ThrusterFL"; - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"swingarm_front_left", n"thruster_front_left", 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"ThrusterFL"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_front_left"); this.isFront = true; this.parentSlotName = n"wheel_front_left"; @@ -4065,11 +4093,13 @@ public class FlightThrusterFL extends IFlightThruster { } public class FlightThrusterFR extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"swingarm_front_right"; - this.slotName = n"thruster_front_right"; - this.meshName = n"ThrusterFR"; - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"swingarm_front_right", n"thruster_front_right", 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"ThrusterFR"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_front_right"); this.isFront = true; this.isRight = true; @@ -4090,12 +4120,16 @@ public class FlightThrusterFR extends IFlightThruster { } } +// BACK RIGHT + public class FlightThrusterBR extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"swingarm_back_right"; - this.slotName = n"thruster_back_right"; - this.meshName = n"ThrusterBR"; - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"swingarm_back_right", n"thruster_back_right", 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"ThrusterBR"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_back_right"); this.isRight = true; this.parentSlotName = n"wheel_back_right"; @@ -4115,12 +4149,16 @@ public class FlightThrusterBR extends IFlightThruster { } } +// BACK LEFT + public class FlightThrusterBL extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"swingarm_back_left"; - this.slotName = n"thruster_back_left"; - this.meshName = n"ThrusterBL"; - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"swingarm_back_left", n"thruster_back_left", 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"ThrusterBL"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_back_left"); this.parentSlotName = n"wheel_back_left"; this.radiusName = n"veh_rad_w_b_l"; @@ -4139,6 +4177,8 @@ public class FlightThrusterBL extends IFlightThruster { } } +// FRONT LEFT B + public class FlightThrusterFLB extends IFlightThruster { public func Create() -> ref { this.boneName = n"swingarm_front_left_b"; @@ -4165,6 +4205,8 @@ public class FlightThrusterFLB extends IFlightThruster { } } +// FRONT LEFT B + public class FlightThrusterFRB extends IFlightThruster { public func Create() -> ref { this.boneName = n"swingarm_front_right_b"; @@ -6351,9 +6393,107 @@ public native func SetBlurDimension(effectName: CName, blurDimension : inkEBlurD // _MeshComponent.reds +// Entity + +@addMethod(Entity) +public native func AddComponent(component: ref); + +@addMethod(Entity) +public native func AddSlot(boneName: CName, slotName: CName, relativePosition: Vector3, relativeRotation: Quaternion); + +// IComponent + +@addField(IComponent) +@runtimeProperty("offset", "0x40") +public native let name: CName; + +@addField(IComponent) +@runtimeProperty("offset", "0x48") +public native let appearanceName: CName; + +// IPlacedComponent + +@addMethod(IPlacedComponent) +public native func SetParentTransform(bindName: CName, slotName: CName); + +// MeshComponent + +@addMethod(MeshComponent) +public native func SetMesh(mesh: ResRef); + @addField(MeshComponent) +@runtimeProperty("offset", "0x178") public native let visualScale: Vector3; +enum ERenderObjectType { + ROT_Static = 0, + ROT_Terrain = 1, + ROT_Road = 2, + ROT_CustomCharacter1 = 12, + ROT_CustomCharacter2 = 13, + ROT_CustomCharacter3 = 14, + ROT_MainPlayer = 15, + ROT_NoAO = 16, + ROT_NoLighting = 17, + ROT_NoTXAA = 18, + ROT_Skinned = 20, + ROT_Character = 21, + ROT_Foliage = 22, + ROT_Grass = 23, + ROT_Vehicle = 24, + ROT_Weapon = 25, + ROT_Particle = 26, + ROT_Enemy = 27, +} + +@addField(MeshComponent) +@runtimeProperty("offset", "0x188") +public native let objectTypeID: ERenderObjectType; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x190") +public native let meshApperance: CName; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x198") +public native let chunkMask: Uint64; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1A4") +public native let motionBlurScale: Float; + +enum entMeshComponentLODMode { + AlwaysVisible = 0, + Appearance = 1, + AppearanceProxy = 2, +} + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1A8") +public native let LODMode: entMeshComponentLODMode; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1AB") +public native let order: Uint8; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1AC") +public native let castShadows: Bool; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1AD") +public native let castLocalShadows: Bool; + +// PhysicalMeshComponent + +@addField(PhysicalMeshComponent) +@runtimeProperty("offset", "0x228") +public native let visibilityAnimationParam: CName; + +@addField(PhysicalMeshComponent) +@runtimeProperty("offset", "0x23A") +public native let startInactive: Bool; + // _Transitions.reds // VehicleTransition diff --git a/build/r6/tweaks/let_there_be_flight.yaml b/build/r6/tweaks/let_there_be_flight.yaml index 3de8ac10..cc30487b 100644 --- a/build/r6/tweaks/let_there_be_flight.yaml +++ b/build/r6/tweaks/let_there_be_flight.yaml @@ -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-22 04:16:50.7239554 +# This file was automatically generated on 2023-02-23 04:49:14.3646377 # quickhacks.yaml diff --git a/build/red4ext/plugins/let_there_be_flight/let_there_be_flight.dll b/build/red4ext/plugins/let_there_be_flight/let_there_be_flight.dll index 830273a8..011fdd17 100644 Binary files a/build/red4ext/plugins/let_there_be_flight/let_there_be_flight.dll and b/build/red4ext/plugins/let_there_be_flight/let_there_be_flight.dll differ diff --git a/src/red4ext/Addresses.hpp b/src/red4ext/Addresses.hpp index 01511773..856f44f5 100644 --- a/src/red4ext/Addresses.hpp +++ b/src/red4ext/Addresses.hpp @@ -19,6 +19,7 @@ #define CreateCRTTIArrayTypeFromClassAddr 0x200660 #define CreateCRTTIHandleTypeFromClassAddr 0x200750 #define CreateCRTTIWeakHandleTypeFromClassAddr 0x200AF0 +#define CreateCRTTIRaRefTypeFromClassAddr 0x200920 #define ProcessScriptTypesAddr 0x277560 #define LoadResRefTAddr 0x204A90 #define CGameFramework_Systems_120_128_130Addr 0x13A19A0 diff --git a/src/red4ext/EntityAddComponent.cpp b/src/red4ext/EntityAddComponent.cpp index 10b519b1..4b5cabb5 100644 --- a/src/red4ext/EntityAddComponent.cpp +++ b/src/red4ext/EntityAddComponent.cpp @@ -155,6 +155,7 @@ void __fastcall Entity_InitializeComponents_Hook(RED4ext::ent::Entity *entity, v auto fc = (FlightComponent *)FlightComponent::GetRTTIType()->CreateInstance(true); fc->name = "flightComponent"; + fc->entity = entity; auto fch = RED4ext::Handle(fc); vehicle->componentsStorage.components.EmplaceBack(fch); @@ -264,12 +265,12 @@ void __fastcall Entity_InitializeComponents_Hook(RED4ext::ent::Entity *entity, v auto handle = RED4ext::Handle(configuration); configuration->ref = RED4ext::WeakHandle(*reinterpret_cast *>(&handle)); configuration->unk30 = configurationCls; - + configuration->component = RED4ext::Handle(fc); fc->configuration = handle; - configuration->Setup(fc); + configuration->Setup(vehicle); configuration->AddSlots(vs); - configuration->AddMeshes(entity, vcc); + //configuration->AddMeshes(entity, vcc); } else { spdlog::info("Looked for class '{}'", className); } @@ -516,8 +517,8 @@ struct EntityAddComponentModule : FlightModule { &IPlacedComponentUpdateHardTransformBinding, {.isNative = true})); - auto mc = rtti->GetClass("entMeshComponent"); - mc->props.EmplaceBack(RED4ext::CProperty::Create(rtti->GetType("Vector3"), "visualScale", nullptr, 0x178)); + //auto mc = rtti->GetClass("entMeshComponent"); + //mc->props.EmplaceBack(RED4ext::CProperty::Create(rtti->GetType("Vector3"), "visualScale", nullptr, 0x178)); } }; diff --git a/src/red4ext/FlightConfiguration.cpp b/src/red4ext/FlightConfiguration.cpp index ae039f20..0b123e93 100644 --- a/src/red4ext/FlightConfiguration.cpp +++ b/src/red4ext/FlightConfiguration.cpp @@ -1,12 +1,15 @@ #include "FlightConfiguration.hpp" #include -void IFlightConfiguration::Setup(FlightComponent * component) { - this->component = RED4ext::Handle(component); +void IFlightConfiguration::Setup(RED4ext::vehicle::BaseObject * vehicle) { this->thrusters = RED4ext::DynArray>(new RED4ext::Memory::DefaultAllocator()); auto onInit = GetType()->GetFunction("OnSetup"); if (onInit) { - auto stack = RED4ext::CStack(this, nullptr, 0, nullptr, 0); + auto rtti = RED4ext::CRTTISystem::Get(); + RED4ext::CStackType args[1]; + auto handle = RED4ext::Handle(vehicle); + args[0] = RED4ext::CStackType(rtti->GetType("handle:vehicleBaseObject"), &handle); + auto stack = RED4ext::CStack(this, args, 1, nullptr, 0); onInit->Execute(&stack); } } @@ -21,16 +24,16 @@ void IFlightConfiguration::AddSlots(RED4ext::ent::SlotComponent *slotComponent) slotComponent->slots.EmplaceBack(*slot); slotComponent->slotIndexLookup.Emplace(slot->slotName, slotComponent->slots.size - 1); - for (auto thruster : thrusters) { - auto slot = reinterpret_cast(rtti->GetClass("entSlot")->CreateInstance()); - slot->boneName = thruster->boneName; - slot->slotName = thruster->slotName; - slot->relativePosition = thruster->relativePosition; - slot->relativeRotation = thruster->relativeRotation; - //slot->relativeRotation = RED4ext::Quaternion(0.0, 0.0, 0.0, 1.0); - slotComponent->slots.EmplaceBack(*slot); - slotComponent->slotIndexLookup.Emplace(slot->slotName, slotComponent->slots.size - 1); - } + //for (auto thruster : thrusters) { + // auto slot = reinterpret_cast(rtti->GetClass("entSlot")->CreateInstance()); + // slot->boneName = thruster->boneName; + // slot->slotName = thruster->slotName; + // slot->relativePosition = thruster->relativePosition; + // slot->relativeRotation = thruster->relativeRotation; + // //slot->relativeRotation = RED4ext::Quaternion(0.0, 0.0, 0.0, 1.0); + // slotComponent->slots.EmplaceBack(*slot); + // slotComponent->slotIndexLookup.Emplace(slot->slotName, slotComponent->slots.size - 1); + //} } void IFlightConfiguration::AddMeshes(RED4ext::ent::Entity *entity, RED4ext::ent::VisualControllerComponent *vcc) { diff --git a/src/red4ext/FlightConfiguration.hpp b/src/red4ext/FlightConfiguration.hpp index b073c56d..da8ebf67 100644 --- a/src/red4ext/FlightConfiguration.hpp +++ b/src/red4ext/FlightConfiguration.hpp @@ -20,7 +20,7 @@ class IFlightConfiguration : public Engine::RTTIClass meshComponent; + RED4ext::Handle vehicle; private: friend Descriptor; @@ -35,4 +36,5 @@ RED4EXT_ASSERT_OFFSET(IFlightThruster, relativePosition, 0x60); RED4EXT_ASSERT_OFFSET(IFlightThruster, relativeRotation, 0x70); RED4EXT_ASSERT_OFFSET(IFlightThruster, meshPath, 0x80); RED4EXT_ASSERT_OFFSET(IFlightThruster, meshName, 0x88); -RED4EXT_ASSERT_OFFSET(IFlightThruster, meshComponent, 0x90); \ No newline at end of file +RED4EXT_ASSERT_OFFSET(IFlightThruster, meshComponent, 0x90); +RED4EXT_ASSERT_OFFSET(IFlightThruster, vehicle, 0xA0); \ No newline at end of file diff --git a/src/red4ext/MeshComponent.cpp b/src/red4ext/MeshComponent.cpp new file mode 100644 index 00000000..4765677a --- /dev/null +++ b/src/red4ext/MeshComponent.cpp @@ -0,0 +1,80 @@ +#include "MeshComponent.hpp" +#include +#include +#include + +void MeshComponent::SetMesh(RED4ext::ResRef mesh) { + this->mesh.path = mesh.resource.path; +} + +void IPlacedComponent::SetParentTransform(RED4ext::CName bindName, RED4ext::CName slotName) { + auto rtti = RED4ext::CRTTISystem::Get(); + auto htb = (RED4ext::ent::HardTransformBinding *)rtti->GetClass("entHardTransformBinding")->CreateInstance(); + htb->bindName = bindName; + htb->slotName = slotName; + this->parentTransform = RED4ext::Handle(htb); +} + +void Entity::AddComponent(RED4ext::Handle componentToAdd) { + RED4ext::ent::VisualControllerComponent *vcc = NULL; + auto rtti = RED4ext::CRTTISystem::Get(); + + for (auto const &handle : this->componentsStorage.components) { + auto component = handle.GetPtr(); + if (component->GetNativeType() == rtti->GetClass("entVisualControllerComponent")) { + vcc = reinterpret_cast(component); + break; + } + } + + if (vcc != NULL) { + if (componentToAdd->GetNativeType() == rtti->GetClass("entMeshComponent")) { + auto meshComponent = (RED4ext::ent::MeshComponent *)componentToAdd.instance; + this->componentsStorage.components.EmplaceBack(componentToAdd); + auto vcd = reinterpret_cast( + rtti->GetClass("entVisualControllerDependency")->CreateInstance()); + vcd->appearanceName = meshComponent->meshAppearance; + vcd->componentName = meshComponent->name; + vcd->mesh.path = meshComponent->mesh.path; + vcc->appearanceDependency.EmplaceBack(*vcd); + + if (vcc->resourcePaths.size) { + for (int i = 0; i < vcc->resourcePaths.size; i++) { + if (vcc->resourcePaths[i] == meshComponent->mesh.path) { + break; + } else if (vcc->resourcePaths[i] > meshComponent->mesh.path) { + vcc->resourcePaths.Emplace(&vcc->resourcePaths[i], meshComponent->mesh.path); + break; + } + } + } else { + vcc->resourcePaths.EmplaceBack(meshComponent->mesh.path); + } + } + } +} + +void Entity::AddSlot(RED4ext::CName boneName, RED4ext::CName slotName, RED4ext::Vector3 relativePosition, RED4ext::Quaternion relativeRotation) { + RED4ext::ent::SlotComponent *slotComponent = NULL; + auto rtti = RED4ext::CRTTISystem::Get(); + + for (auto const &handle : this->componentsStorage.components) { + auto component = handle.GetPtr(); + if (component->GetNativeType() == rtti->GetClass("entSlotComponent")) { + if (component->name == "vehicle_slots") { + slotComponent = reinterpret_cast(component); + break; + } + } + } + + if (slotComponent != NULL) { + auto slot = reinterpret_cast(rtti->GetClass("entSlot")->CreateInstance()); + slot->boneName = boneName; + slot->slotName = slotName; + slot->relativePosition = relativePosition; + slot->relativeRotation = relativeRotation; + slotComponent->slots.EmplaceBack(*slot); + slotComponent->slotIndexLookup.Emplace(slot->slotName, slotComponent->slots.size - 1); + } +} \ No newline at end of file diff --git a/src/red4ext/MeshComponent.hpp b/src/red4ext/MeshComponent.hpp new file mode 100644 index 00000000..63d213de --- /dev/null +++ b/src/red4ext/MeshComponent.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include "Engine/RTTIExpansion.hpp" +#include +#include +#include + +class MeshComponent : public Engine::RTTIExpansion { +public: + void SetMesh(RED4ext::ResRef mesh); + +private: + friend Descriptor; + + inline static void OnExpand(Descriptor *aType, RED4ext::CRTTISystem *) { + aType->AddFunction<&MeshComponent::SetMesh>("SetMesh"); + } +}; + + +class IPlacedComponent : public Engine::RTTIExpansion { +public: + void SetParentTransform(RED4ext::CName bindName, RED4ext::CName slotName); + +private: + friend Descriptor; + + inline static void OnExpand(Descriptor *aType, RED4ext::CRTTISystem *) { + aType->AddFunction<&IPlacedComponent::SetParentTransform>("SetParentTransform"); + } +}; + + +class Entity : public Engine::RTTIExpansion { +public: + void AddComponent(RED4ext::Handle component); + void AddSlot(RED4ext::CName boneName, RED4ext::CName slotName, RED4ext::Vector3 relativePosition, + RED4ext::Quaternion relativeRotation); + private: + friend Descriptor; + + inline static void OnExpand(Descriptor *aType, RED4ext::CRTTISystem *) { + aType->AddFunction<&Entity::AddComponent>("AddComponent"); + aType->AddFunction<&Entity::AddSlot>("AddSlot"); + } +}; \ No newline at end of file diff --git a/src/red4ext/RuntimeProperties.cpp b/src/red4ext/RuntimeProperties.cpp index ea57003a..02b0cde7 100644 --- a/src/red4ext/RuntimeProperties.cpp +++ b/src/red4ext/RuntimeProperties.cpp @@ -42,6 +42,11 @@ RED4ext::CRTTIHandleType **__fastcall CreateCRTTIHandleTypeFromClass(RED4ext::CR return call(a1, a2); } +RED4ext::CRTTIResourceAsyncReferenceType **__fastcall CreateCRTTIRaRefTypeFromClass(RED4ext::CRTTIResourceAsyncReferenceType **a1, RED4ext::CBaseRTTIType *a2) { + RED4ext::RelocFunc call(CreateCRTTIRaRefTypeFromClassAddr); + return call(a1, a2); +} + bool __fastcall ProcessScriptTypes(uint32_t* version, ScriptData* scriptData, void* scriptLogger); decltype(&ProcessScriptTypes) ProcessScriptTypes_Original; @@ -54,14 +59,21 @@ bool __fastcall ProcessScriptTypes(uint32_t* version, ScriptData* scriptData, vo auto cstr = offsetStr->c_str(); char* p; auto offsetValue = strtoul(cstr, &p, 16); + RED4ext::CName typeName = prop->type->name; if (*p == 0) { spdlog::info("{}.{} at 0x{:X} {}", scriptClass->name.ToString(), prop->name.ToString(), offsetValue, prop->type->name.ToString()); if (prop->flags.isNative) { + auto customTypeStr = prop->runtimeProperties.Get("type"); + if (customTypeStr) { + spdlog::info("Custom type: {}", customTypeStr->c_str()); + typeName = RED4ext::CName(customTypeStr->c_str()); + //prop->type->name = typeName; + } auto rtti = RED4ext::CRTTISystem::Get(); auto rttiClass = rtti->GetClassByScriptName(scriptClass->name); - auto rttiType = rtti->GetType(prop->type->name); + auto rttiType = rtti->GetType(typeName); if (!rttiType) { - std::string typeStr(prop->type->name.ToString()); + std::string typeStr(typeName.ToString()); auto del = typeStr.find(":"); if (del != -1) { auto outerTypeStr = typeStr.substr(0, del); @@ -88,10 +100,22 @@ bool __fastcall ProcessScriptTypes(uint32_t* version, ScriptData* scriptData, vo CreateCRTTIArrayTypeFromClass(&whType, innerInnerType); rtti->RegisterType(whType); innerType = whType; + } else if (innerTypeStr.starts_with("raRef")) { + RED4ext::CRTTIResourceAsyncReferenceType *whType; + CreateCRTTIRaRefTypeFromClass(&whType, innerInnerType); + rtti->RegisterType(whType); + innerType = whType; } } } if (innerType) { + //if (customTypeStr) { + // //innerScriptType = ScriptType(); + // ScriptClass *innerScriptCls = (ScriptClass*)malloc(0x90); + // innerScriptCls->rttiType = (RED4ext::CClass*)innerType; + // innerScriptCls->name = RED4ext::CName(innerTypeStr.c_str()); + // prop->type->innerType = innerScriptCls; + //} if (outerTypeStr.starts_with("wref")) { RED4ext::CRTTIWeakHandleType *whType; CreateCRTTIWeakHandleTypeFromClass(&whType, innerType); @@ -107,12 +131,20 @@ bool __fastcall ProcessScriptTypes(uint32_t* version, ScriptData* scriptData, vo CreateCRTTIArrayTypeFromClass(&whType, innerType); rtti->RegisterType(whType); rttiType = whType; + } else if (innerTypeStr.starts_with("raRef")) { + RED4ext::CRTTIResourceAsyncReferenceType *whType; + CreateCRTTIRaRefTypeFromClass(&whType, innerType); + rtti->RegisterType(whType); + innerType = whType; } } else { spdlog::warn("could not find inner type '{}' in '{}'", innerTypeStr, typeStr); } } } + //if (customTypeStr) { + // prop->type->rttiType = rttiType; + //} if (rttiType) { rttiClass->props.PushBack( RED4ext::CProperty::Create(rttiType, prop->name.ToString(), nullptr, offsetValue)); diff --git a/src/red4ext/ScriptDefinitions/ScriptDefinitions.hpp b/src/red4ext/ScriptDefinitions/ScriptDefinitions.hpp index 2aabe5aa..9ca045fa 100644 --- a/src/red4ext/ScriptDefinitions/ScriptDefinitions.hpp +++ b/src/red4ext/ScriptDefinitions/ScriptDefinitions.hpp @@ -50,6 +50,7 @@ struct ScriptType : ScriptDefinition { uint32_t unk28; EScriptType type; }; +RED4EXT_ASSERT_SIZE(ScriptType, 0x30); struct ScriptPropertyFlags { uint16_t isNative : 1; diff --git a/src/red4ext/Signatures.hpp b/src/red4ext/Signatures.hpp index 32a262fe..db49548a 100644 --- a/src/red4ext/Signatures.hpp +++ b/src/red4ext/Signatures.hpp @@ -126,6 +126,13 @@ using CreateCRTTIHandleTypeFromClass = RED4ext::CRTTIHandleType **__fastcall(RED /// @nth 4/7 using CreateCRTTIWeakHandleTypeFromClass = RED4ext::CRTTIWeakHandleType **__fastcall (RED4ext::CRTTIWeakHandleType **a1, RED4ext::CBaseRTTIType *a2); + +// 1.62 RVA: 0x200920 / 2099488 +/// @pattern 48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 30 48 8B FA 48 8B F1 BA 28 00 00 00 48 8D 4C 24 20 E8 +/// @nth 2/7 +using CreateCRTTIRaRefTypeFromClass = RED4ext::CRTTIResourceAsyncReferenceType **__fastcall (RED4ext::CRTTIResourceAsyncReferenceType **a1, + RED4ext::CBaseRTTIType *a2); + struct ScriptData; // 1.52 RVA: 0x273160 / 2568544 diff --git a/src/red4ext/build/release/bin/flight_control.pdb b/src/red4ext/build/release/bin/flight_control.pdb index 5eb3f49e..9dc6985d 100644 Binary files a/src/red4ext/build/release/bin/flight_control.pdb and b/src/red4ext/build/release/bin/flight_control.pdb differ diff --git a/src/red4ext/flight_control.vcxproj b/src/red4ext/flight_control.vcxproj index 68c700fa..3fa6ada5 100644 --- a/src/red4ext/flight_control.vcxproj +++ b/src/red4ext/flight_control.vcxproj @@ -129,6 +129,7 @@ + @@ -150,6 +151,7 @@ + diff --git a/src/redscript/let_there_be_flight/FlightConfiguration.reds b/src/redscript/let_there_be_flight/FlightConfiguration.reds index e212871d..4c4ca693 100644 --- a/src/redscript/let_there_be_flight/FlightConfiguration.reds +++ b/src/redscript/let_there_be_flight/FlightConfiguration.reds @@ -11,52 +11,70 @@ public abstract native class IFlightConfiguration extends IScriptable { @runtimeProperty("offset", "0x68") public native let flightCameraOffset: Vector3; // 0, 0, 0 - public func OnSetup() { + public func OnSetup(vehicle: ref) { } } -// public class FlightConfiguration extends IFlightConfiguration { +public func CreateCorpoThruster() -> ref { + let mc = new PhysicalMeshComponent(); + mc.SetMesh(r"user\\jackhumbert\\meshes\\engine_corpo.mesh"); + mc.meshApperance = n"default"; + mc.motionBlurScale = 0.1; + mc.LODMode = entMeshComponentLODMode.Appearance; + return mc; +} + +public func CreateNomadThruster() -> ref { + let mc = new PhysicalMeshComponent(); + mc.SetMesh(r"user\\jackhumbert\\meshes\\engine_nomad.mesh"); + mc.meshApperance = n"default"; + mc.motionBlurScale = 0.1; + mc.LODMode = entMeshComponentLODMode.Appearance; + return mc; +} -// } public class CarFlightConfiguration extends IFlightConfiguration { - public func OnSetup() { + public func OnSetup(vehicle: ref) { // FlightLog.Info("[CarFlightConfiguration] OnSetup"); - ArrayPush(this.thrusters, new FlightThrusterFL().Create()); - ArrayPush(this.thrusters, new FlightThrusterFR().Create()); - ArrayPush(this.thrusters, new FlightThrusterBL().Create()); - ArrayPush(this.thrusters, new FlightThrusterBR().Create()); + 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())); for thruster in this.thrusters { + vehicle.AddComponent(thruster.meshComponent); thruster.OnSetup(this.component); } } } public class SixWheelCarFlightConfiguration extends CarFlightConfiguration { - public func OnSetup() { - ArrayPush(this.thrusters, new FlightThrusterFL().Create()); - ArrayPush(this.thrusters, new FlightThrusterFR().Create()); - ArrayPush(this.thrusters, new FlightThrusterFLB().Create()); - ArrayPush(this.thrusters, new FlightThrusterFRB().Create()); - ArrayPush(this.thrusters, new FlightThrusterBL().Create()); - ArrayPush(this.thrusters, new FlightThrusterBR().Create()); + public func OnSetup(vehicle: ref) { + 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())); for thruster in this.thrusters { + vehicle.AddComponent(thruster.meshComponent); thruster.OnSetup(this.component); } } } public class BikeFlightConfiguration extends IFlightConfiguration { - public func OnSetup() { + public func OnSetup(vehicle: ref) { this.flightCameraOffset = new Vector3(0.0, 1.0, 0.5); - ArrayPush(this.thrusters, new FlightThrusterFront().Create()); - ArrayPush(this.thrusters, new FlightThrusterBack().Create()); + ArrayPush(this.thrusters, new FlightThrusterFront().Create(vehicle, CreateCorpoThruster())); + ArrayPush(this.thrusters, new FlightThrusterBack().Create(vehicle, CreateCorpoThruster())); for thruster in this.thrusters { + vehicle.AddComponent(thruster.meshComponent); thruster.OnSetup(this.component); } } diff --git a/src/redscript/let_there_be_flight/FlightThruster.reds b/src/redscript/let_there_be_flight/FlightThruster.reds index 8f1a56be..7030a034 100644 --- a/src/redscript/let_there_be_flight/FlightThruster.reds +++ b/src/redscript/let_there_be_flight/FlightThruster.reds @@ -24,6 +24,9 @@ public abstract native class IFlightThruster extends IScriptable { @runtimeProperty("offset", "0x90") public native let meshComponent: ref; + @runtimeProperty("offset", "0xA0") + public native let vehicle: ref; + public let parentSlotName: CName; public let radiusName: CName; public let deviationName: CName; @@ -61,8 +64,6 @@ public abstract native class IFlightThruster extends IScriptable { this.mainFxRes = Cast(this.mainResRef); this.retroFxRes = Cast(this.retroResRef); - // let vehicleComponent = this.flightComponent.GetVehicle().GetVehicleComponent(); - // this.meshComponent = vehicleComponent.FindComponentByName(this.meshName) as MeshComponent; this.meshComponent.visualScale = new Vector3(0.0, 0.0, 0.0); this.meshComponent.Toggle(false); @@ -155,11 +156,10 @@ public abstract native class IFlightThruster extends IScriptable { } public func SetOGComponents() { - this.ogComponents = this.flightComponent.GetVehicle().GetComponentsUsingSlot(this.parentSlotName); + this.ogComponents = this.vehicle.GetComponentsUsingSlot(this.parentSlotName); } public func Start() { - let vehicle = this.flightComponent.GetVehicle(); let effectTransform: WorldTransform; let wt = new WorldTransform(); @@ -167,16 +167,16 @@ public abstract native class IFlightThruster extends IScriptable { this.HideOGComponents(); WorldTransform.SetPosition(effectTransform, this.flightComponent.stats.d_position); - this.mainFx = GameInstance.GetFxSystem(vehicle.GetGame()).SpawnEffect(this.mainFxRes, effectTransform); + this.mainFx = GameInstance.GetFxSystem(this.vehicle.GetGame()).SpawnEffect(this.mainFxRes, effectTransform); this.mainFx.SetBlackboardValue(n"thruster_amount", 0.0); - this.mainFx.AttachToComponent(vehicle, entAttachmentTarget.Transform, this.meshName, wt); + this.mainFx.AttachToComponent(this.vehicle, entAttachmentTarget.Transform, this.meshComponent.name, wt); this.meshComponent.Toggle(true); let wt_retro: WorldTransform; WorldTransform.SetOrientation(wt_retro, EulerAngles.ToQuat(new EulerAngles(0.0, 0.0, -90.0))); - this.retroFx = GameInstance.GetFxSystem(vehicle.GetGame()).SpawnEffect(this.retroFxRes, effectTransform); - // this.retroFx.AttachToSlot(this.component.GetVehicle(), entAttachmentTarget.Transform, n"Base", wt_retro); - this.retroFx.AttachToComponent(vehicle, entAttachmentTarget.Transform, this.meshName, wt_retro); + this.retroFx = GameInstance.GetFxSystem(this.vehicle.GetGame()).SpawnEffect(this.retroFxRes, effectTransform); + // this.retroFx.AttachToSlot(this.component.Getthis.Vehicle(), entAttachmentTarget.Transform, n"Base", wt_retro); + this.retroFx.AttachToComponent(this.vehicle, entAttachmentTarget.Transform, this.meshComponent.name, wt_retro); // FlightAudio.Get().StartWithPitch(this.id, "vehicle3_TPP", this.audioPitch); FlightAudio.Get().StartWithPitch(this.id, "vehicle3_TPP", this.flightComponent.GetPitch()); @@ -228,14 +228,14 @@ public abstract native class IFlightThruster extends IScriptable { this.animDeviation = LerpF(this.boneLerpAmount, this.animDeviation, animDeviationCenter + amount * animDeviationScale); // this.animDeviation = animDeviationCenter + amount * animDeviationScale; // this.animRadius = animRadiusCenter + amount * animRadiusScale; - // AnimationControllerComponent.SetInputFloatToReplicate(this.flightComponent.GetVehicle(), this.deviationName, this.animDeviation); - // AnimationControllerComponent.SetInputFloatToReplicate(this.flightComponent.GetVehicle(), this.GetRadiusName(), this.animRadius); + // AnimationControllerComponent.SetInputFloatToReplicate(this.vehicle, this.deviationName, this.animDeviation); + // AnimationControllerComponent.SetInputFloatToReplicate(this.vehicle, this.GetRadiusName(), this.animRadius); let acc = this.flightComponent.FindComponentByName(n"AnimationController") as AnimationControllerComponent; if IsDefined(acc) { acc.SetInputFloat(this.deviationName, this.animDeviation); } - // AnimationControllerComponent.SetInputFloat(this.flightComponent.GetVehicle(), this.deviationName, this.animDeviation); + // AnimationControllerComponent.SetInputFloat(this.vehicle, this.deviationName, this.animDeviation); // acc.SetInputFloat(this.GetRadiusName(), this.animRadius); @@ -306,13 +306,16 @@ public abstract native class IFlightThruster extends IScriptable { } } +// FRONT + public class FlightThrusterFront extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"suspension_front_offset"; - this.slotName = n"thruster_front"; - this.meshName = n"ThrusterF"; - this.relativePosition = new Vector3(0.0, 0.0, -0.5); - this.relativeRotation = new Quaternion(0.22627002, 0.0, 0.0, -0.974064708); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"suspension_front_offset", n"thruster_front", new Vector3(0.0, 0.0, -0.5), new Quaternion(0.22627002, 0.0, 0.0, -0.974064708)); + + this.meshComponent = meshComponent; + this.meshComponent.name = n"ThrusterF"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_front"); this.isFront = true; this.parentSlotName = n"wheel_front_spring"; @@ -337,7 +340,7 @@ public class FlightThrusterFront extends IFlightThruster { if IsDefined(comp) { ArrayPush(this.ogComponents, comp); } - let comps = this.flightComponent.GetVehicle().GetComponentsUsingSlot(n"wheel_front_rot_set"); + let comps = this.vehicle.GetComponentsUsingSlot(n"wheel_front_rot_set"); for c in comps { ArrayPush(this.ogComponents, c); } @@ -357,7 +360,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 { @@ -377,13 +380,16 @@ public class FlightThrusterFront extends IFlightThruster { } } +// BACK + public class FlightThrusterBack extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"suspension_back"; - this.slotName = n"thruster_back"; - this.meshName = n"ThrusterB"; - this.relativePosition = new Vector3(0.0, 0.0, -0.5); - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"suspension_back", n"thruster_back", new Vector3(0.0, 0.0, -0.5), new Quaternion(0.0, 0.0, 0.0, 1.0)); + + this.meshComponent = meshComponent; + this.meshComponent.name = n"ThrusterB"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_back"); this.parentSlotName = n"axel_back"; this.radiusName = n"None"; @@ -411,7 +417,7 @@ public class FlightThrusterBack extends IFlightThruster { if IsDefined(comp) { ArrayPush(this.ogComponents, comp); } - let comps = this.flightComponent.GetVehicle().GetComponentsUsingSlot(n"axel_back_wheel"); + let comps = this.vehicle.GetComponentsUsingSlot(n"axel_back_wheel"); for c in comps { ArrayPush(this.ogComponents, c); } @@ -443,12 +449,16 @@ public class FlightThrusterBack extends IFlightThruster { } } +// FRONT LEFT + public class FlightThrusterFL extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"swingarm_front_left"; - this.slotName = n"thruster_front_left"; - this.meshName = n"ThrusterFL"; - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"swingarm_front_left", n"thruster_front_left", 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"ThrusterFL"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_front_left"); this.isFront = true; this.parentSlotName = n"wheel_front_left"; @@ -469,11 +479,13 @@ public class FlightThrusterFL extends IFlightThruster { } public class FlightThrusterFR extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"swingarm_front_right"; - this.slotName = n"thruster_front_right"; - this.meshName = n"ThrusterFR"; - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"swingarm_front_right", n"thruster_front_right", 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"ThrusterFR"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_front_right"); this.isFront = true; this.isRight = true; @@ -494,12 +506,16 @@ public class FlightThrusterFR extends IFlightThruster { } } +// BACK RIGHT + public class FlightThrusterBR extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"swingarm_back_right"; - this.slotName = n"thruster_back_right"; - this.meshName = n"ThrusterBR"; - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"swingarm_back_right", n"thruster_back_right", 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"ThrusterBR"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_back_right"); this.isRight = true; this.parentSlotName = n"wheel_back_right"; @@ -519,12 +535,16 @@ public class FlightThrusterBR extends IFlightThruster { } } +// BACK LEFT + public class FlightThrusterBL extends IFlightThruster { - public func Create() -> ref { - this.boneName = n"swingarm_back_left"; - this.slotName = n"thruster_back_left"; - this.meshName = n"ThrusterBL"; - this.relativeRotation = new Quaternion(0.0, 0.0, 0.0, 1.0); + public func Create(vehicle: ref, meshComponent: ref) -> ref { + this.vehicle = vehicle; + this.vehicle.AddSlot(n"swingarm_back_left", n"thruster_back_left", 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"ThrusterBL"; + this.meshComponent.SetParentTransform(n"vehicle_slots", n"thruster_back_left"); this.parentSlotName = n"wheel_back_left"; this.radiusName = n"veh_rad_w_b_l"; @@ -543,6 +563,8 @@ public class FlightThrusterBL extends IFlightThruster { } } +// FRONT LEFT B + public class FlightThrusterFLB extends IFlightThruster { public func Create() -> ref { this.boneName = n"swingarm_front_left_b"; @@ -569,6 +591,8 @@ public class FlightThrusterFLB extends IFlightThruster { } } +// FRONT LEFT B + public class FlightThrusterFRB extends IFlightThruster { public func Create() -> ref { this.boneName = n"swingarm_front_right_b"; diff --git a/src/redscript/let_there_be_flight/_MeshComponent.reds b/src/redscript/let_there_be_flight/_MeshComponent.reds index 34541d40..1c4e5390 100644 --- a/src/redscript/let_there_be_flight/_MeshComponent.reds +++ b/src/redscript/let_there_be_flight/_MeshComponent.reds @@ -1,2 +1,100 @@ +// Entity + +@addMethod(Entity) +public native func AddComponent(component: ref); + +@addMethod(Entity) +public native func AddSlot(boneName: CName, slotName: CName, relativePosition: Vector3, relativeRotation: Quaternion); + +// IComponent + +@addField(IComponent) +@runtimeProperty("offset", "0x40") +public native let name: CName; + +@addField(IComponent) +@runtimeProperty("offset", "0x48") +public native let appearanceName: CName; + +// IPlacedComponent + +@addMethod(IPlacedComponent) +public native func SetParentTransform(bindName: CName, slotName: CName); + +// MeshComponent + +@addMethod(MeshComponent) +public native func SetMesh(mesh: ResRef); + @addField(MeshComponent) -public native let visualScale: Vector3; \ No newline at end of file +@runtimeProperty("offset", "0x178") +public native let visualScale: Vector3; + +enum ERenderObjectType { + ROT_Static = 0, + ROT_Terrain = 1, + ROT_Road = 2, + ROT_CustomCharacter1 = 12, + ROT_CustomCharacter2 = 13, + ROT_CustomCharacter3 = 14, + ROT_MainPlayer = 15, + ROT_NoAO = 16, + ROT_NoLighting = 17, + ROT_NoTXAA = 18, + ROT_Skinned = 20, + ROT_Character = 21, + ROT_Foliage = 22, + ROT_Grass = 23, + ROT_Vehicle = 24, + ROT_Weapon = 25, + ROT_Particle = 26, + ROT_Enemy = 27, +} + +@addField(MeshComponent) +@runtimeProperty("offset", "0x188") +public native let objectTypeID: ERenderObjectType; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x190") +public native let meshApperance: CName; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x198") +public native let chunkMask: Uint64; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1A4") +public native let motionBlurScale: Float; + +enum entMeshComponentLODMode { + AlwaysVisible = 0, + Appearance = 1, + AppearanceProxy = 2, +} + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1A8") +public native let LODMode: entMeshComponentLODMode; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1AB") +public native let order: Uint8; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1AC") +public native let castShadows: Bool; + +@addField(MeshComponent) +@runtimeProperty("offset", "0x1AD") +public native let castLocalShadows: Bool; + +// PhysicalMeshComponent + +@addField(PhysicalMeshComponent) +@runtimeProperty("offset", "0x228") +public native let visibilityAnimationParam: CName; + +@addField(PhysicalMeshComponent) +@runtimeProperty("offset", "0x23A") +public native let startInactive: Bool; \ No newline at end of file