using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2Cpp;
using Il2CppFusion;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Il2CppTMPro;
using Il2CppVehiclePhysics;
using JeepGlider;
using JoofOTHFramework;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Mod), "JeepGlider", "1.0.1", "Joof", null)]
[assembly: MelonGame("Funselektor", "over the hill")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("JeepGlider")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+477956a570c4f43ea556f0cabd470730f4a17c90")]
[assembly: AssemblyProduct("JeepGlider")]
[assembly: AssemblyTitle("JeepGlider")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace JeepGlider
{
[RegisterTypeInIl2Cpp]
public class Glider : MonoBehaviour
{
private class Rig
{
public Transform Root;
public Transform Frame;
public VehicleBase Car;
public NetworkObject Net;
public List<GameObject> Parts;
public CarAudioManager Audio;
public GameObject Holder;
public Mesh Sail;
public Transform Keel;
public Transform LeftEdge;
public Transform RightEdge;
public Transform Crossbar;
public Transform MastLeft;
public Transform MastRight;
public Vector3 Mount;
public float RoofWidth;
public bool Mounted;
public bool Open;
public bool HonkWas;
public float Pitch;
public TickState Tick;
public readonly History History = new History(128);
public float Opened = -1f;
public float Drawn = -1f;
public float LastToggle = float.NegativeInfinity;
public int TickedFrame = int.MinValue;
public bool TickLogged;
}
private readonly Dictionary<IntPtr, Rig> rigs = new Dictionary<IntPtr, Rig>();
private readonly Dictionary<IntPtr, Rig> byCar = new Dictionary<IntPtr, Rig>();
private readonly List<IntPtr> dead = new List<IntPtr>();
private static readonly Dictionary<IntPtr, (Transform Root, int Tries)> pending = new Dictionary<IntPtr, (Transform, int)>();
private const int RetryFrames = 10;
private const int MaxTries = 30;
private static readonly Dictionary<string, (Vector3 Mount, float Width)> roofs = new Dictionary<string, (Vector3, float)>();
private static Material sailMaterial;
private static Material tubeMaterial;
private static int steerId;
private static int inputChannel;
private static bool inputIds;
private const float ToggleCooldown = 0.4f;
private const float StickDeadZone = 0.15f;
private const int PitchSteps = 10;
private const int TickedRecently = 30;
internal static readonly Color Cream = new Color(1f, 0.953f, 0.886f);
internal static readonly Color Yellow = new Color(1f, 0.788f, 0.235f);
internal static readonly Color Brown = new Color(0.29f, 0.141f, 0.086f);
internal static Glider Instance { get; private set; }
public Glider(IntPtr ptr)
: base(ptr)
{
}
private void Awake()
{
Instance = this;
Core.DiagnosticsRequested += Diagnostics;
}
private void OnDestroy()
{
Core.DiagnosticsRequested -= Diagnostics;
if ((Object)(object)Instance == (Object)(object)this)
{
Instance = null;
}
}
internal static void CarReady(Transform root)
{
if ((Object)(object)root != (Object)null)
{
pending[((Il2CppObjectBase)root).Pointer] = (root, 0);
}
}
internal static string ModelName(string objectName)
{
string text = objectName.Replace("(Clone)", "").Trim();
if (!text.EndsWith("_Dummy"))
{
return text;
}
string text2 = text;
int length = "_Dummy".Length;
return text2.Substring(0, text2.Length - length);
}
private void LateUpdate()
{
try
{
Tick();
}
catch (Exception ex)
{
Mod.Log.Error((object)ex);
}
}
private void Tick()
{
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
bool value = Mod.Enabled.Value;
if (pending.Count > 0 && Time.frameCount % 10 == 0)
{
RigPending();
}
float deltaTime = Time.deltaTime;
dead.Clear();
foreach (var (item, rig2) in rigs)
{
if ((Object)(object)rig2.Root == (Object)null || (Object)(object)rig2.Holder == (Object)null || rig2.Parts.Exists((GameObject p) => (Object)(object)p == (Object)null))
{
Destroy(rig2);
dead.Add(item);
continue;
}
bool mounted = value && rig2.Parts.Exists((GameObject p) => p.activeInHierarchy);
NetworkObject net = rig2.Net;
bool flag = (Object)(object)net == (Object)null || net.HasInputAuthority;
bool flag2 = (Object)(object)rig2.Car != (Object)null && (flag || net.HasStateAuthority) && Time.frameCount - rig2.TickedFrame <= 30;
if (flag && mounted && (Object)(object)rig2.Car != (Object)null)
{
bool flag3 = (Object)(object)rig2.Audio != (Object)null && rig2.Audio.wasHonkPressedLastFrame;
if (flag3 && !rig2.HonkWas && Time.time - rig2.LastToggle > 0.4f)
{
rig2.Open = !rig2.Open;
rig2.LastToggle = Time.time;
Mod.Log.Msg("Glider " + (rig2.Open ? "opening" : "folding") + ((rig2.Open && !Net.Flies) ? " (looks only: the host doesn't have JeepGlider)" : ""));
}
rig2.HonkWas = flag3;
rig2.Pitch = ((rig2.Opened > 0f) ? ReadPitch() : 0f);
}
if (!mounted)
{
rig2.Open = false;
rig2.Pitch = 0f;
}
if (!flag)
{
Sync(rig2, ref mounted);
}
else if (!flag2 && (Object)(object)net != (Object)null)
{
NetworkRunner runner = HillNet.Runner;
if (runner != null)
{
bool flag4 = mounted && rig2.Open;
Net.SendOwn(net, runner.Tick.Raw, mounted, flag4, flag4 ? rig2.Pitch : 0f);
}
}
rig2.Mounted = mounted;
if (rig2.Holder.activeSelf != mounted)
{
rig2.Holder.SetActive(mounted);
}
if (!mounted)
{
rig2.Opened = 0f;
continue;
}
if (!flag2)
{
rig2.Opened = GliderMath.Animate(Mathf.Max(rig2.Opened, 0f), rig2.Open, Mod.OpenSeconds.Value, deltaTime);
}
if (rig2.Opened != rig2.Drawn)
{
Draw(rig2);
}
}
foreach (IntPtr item2 in dead)
{
if (rigs.Remove(item2, out var value2) && (Object)(object)value2.Car != (Object)null)
{
byCar.Remove(((Il2CppObjectBase)value2.Car).Pointer);
}
}
}
private static void Sync(Rig rig, ref bool mounted)
{
if (!((Object)(object)rig.Net == (Object)null) && !((Object)(object)HillNet.Runner == (Object)null))
{
Net.CarState carState = Net.For(rig.Net);
if (carState == null)
{
rig.Open = false;
rig.Pitch = 0f;
}
else
{
mounted = Mod.Enabled.Value && carState.Mounted;
rig.Open = mounted && carState.Open;
rig.Pitch = carState.Pitch;
}
}
}
private void RigPending()
{
if (!RoofItem.EnsureRegistered())
{
return;
}
foreach (KeyValuePair<IntPtr, (Transform, int)> item in new List<KeyValuePair<IntPtr, (Transform, int)>>(pending))
{
item.Deconstruct(out var key, out var value);
(Transform, int) tuple = value;
IntPtr key2 = key;
var (val, num) = tuple;
if ((Object)(object)val == (Object)null || TryRig(val))
{
pending.Remove(key2);
}
else if (num + 1 >= 30)
{
pending.Remove(key2);
Mod.Log.Warning("Couldn't find the roof of " + ((Object)val).name);
}
else
{
pending[key2] = (val, num + 1);
}
}
}
internal static void FixedTick(IntPtr car)
{
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
Glider instance = Instance;
if ((Object)(object)instance == (Object)null || !instance.byCar.TryGetValue(car, out var value))
{
return;
}
VehicleBase car2 = value.Car;
if ((Object)(object)car2 == (Object)null)
{
return;
}
NetworkObject net = value.Net;
bool flag = (Object)(object)net == (Object)null || net.HasInputAuthority;
if (!flag && !net.HasStateAuthority)
{
return;
}
value.TickedFrame = Time.frameCount;
if (!value.TickLogged && (Object)(object)net != (Object)null && !net.HasStateAuthority)
{
value.TickLogged = true;
Mod.Log.Msg("Our car " + ((Object)value.Root).name + " gets network ticks here (client prediction)");
}
NetworkRunner runner = ((SimulationBehaviour)car2).Runner;
float dt = (((Object)(object)runner != (Object)null) ? runner.DeltaTime : Time.fixedDeltaTime);
int tick = (((Object)(object)runner != (Object)null) ? runner.Tick.Raw : 0);
if ((Object)(object)runner != (Object)null && runner.IsResimulation && value.History.TryGet(tick, out var state))
{
value.Tick = state;
}
else
{
bool flag2;
float pitch;
if (flag)
{
flag2 = value.Mounted && value.Open;
pitch = (flag2 ? value.Pitch : 0f);
Net.SendOwn(net, tick, value.Mounted, flag2, pitch);
}
else
{
Timeline timeline = Net.TimelineFor(net);
timeline.Advance(tick, ((Object)(object)runner != (Object)null) ? (runner.TickRate * 2) : 0);
flag2 = value.Mounted && timeline.Open;
pitch = (flag2 ? timeline.Pitch : 0f);
}
float opened = (value.Mounted ? GliderMath.Animate(value.Tick.Opened, flag2, Mod.OpenSeconds.Value, dt) : 0f);
value.Tick = new TickState(flag2, pitch, opened);
value.History.Record(tick, value.Tick);
}
value.Opened = value.Tick.Opened;
if (value.Mounted && value.Tick.Opened > 0f)
{
Fly(value, car2, dt);
}
}
private static void Fly(Rig rig, VehicleBase v, float dt)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
if (!Mod.Enabled.Value || !Mod.Flight.Value || !Net.Flies)
{
return;
}
Rigidbody cachedRigidbody = v.cachedRigidbody;
if (!((Object)(object)cachedRigidbody == (Object)null) && !cachedRigidbody.isKinematic)
{
Airframe a = Mod.Airframe();
Transform transform = ((Component)cachedRigidbody).transform;
Body b = new Body(N(cachedRigidbody.velocity), N(transform.right), N(transform.up), N(transform.forward), cachedRigidbody.mass);
float open = GliderMath.Spread(rig.Tick.Opened);
Aero aero = GliderMath.Forces(a, b, open);
if (!(aero.Airspeed <= 0f))
{
cachedRigidbody.AddForce(U(aero.Force) * dt, (ForceMode)1);
float steer = ReadSteer(v);
float authority = GliderMath.Authority(a, open, aero.Airspeed, Grounded(v)) * Mod.Stability.Value;
Vector3 val = Vector3.Scale(U(GliderMath.Righting(a, aero, b, N(transform.InverseTransformDirection(cachedRigidbody.angularVelocity)), steer, GliderMath.Trim(a, rig.Tick.Pitch), authority)), cachedRigidbody.inertiaTensor);
cachedRigidbody.AddTorque(transform.TransformDirection(val) * dt, (ForceMode)1);
}
}
}
private static float ReadSteer(VehicleBase v)
{
if (!inputIds)
{
inputIds = true;
inputChannel = Channel.Input;
steerId = InputData.Steer;
}
DataBus data = v.data;
if (data != null)
{
return (float)data.Get(inputChannel, steerId) / 10000f;
}
return 0f;
}
private static float ReadPitch()
{
Gamepad current = Gamepad.current;
if (current == null)
{
return 0f;
}
float num = GliderMath.DeadZone(((InputControl<float>)(object)((Vector2Control)current.leftStick).y).ReadValue(), 0.15f);
return GliderMath.Quantize(Mod.InvertPitch.Value ? num : (0f - num), 10);
}
private static float Grounded(VehicleBase v)
{
Il2CppReferenceArray<WheelState> wheelState = v.m_wheelState;
if (wheelState == null || ((Il2CppArrayBase<WheelState>)(object)wheelState).Length == 0)
{
return 0f;
}
int num = 0;
foreach (WheelState item in (Il2CppArrayBase<WheelState>)(object)wheelState)
{
if (item != null && item.grounded)
{
num++;
}
}
return (float)num / (float)((Il2CppArrayBase<WheelState>)(object)wheelState).Length;
}
private bool TryRig(Transform root)
{
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Expected O, but got Unknown
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Expected O, but got Unknown
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
List<GameObject> list = RoofItem.PartObjects(root);
if (list.Count == 0)
{
return true;
}
if (rigs.TryGetValue(((Il2CppObjectBase)root).Pointer, out var value))
{
value.Parts = list;
return true;
}
VehicleBase componentInChildren = ((Component)root).GetComponentInChildren<VehicleBase>(true);
Rigidbody val = (((Object)(object)componentInChildren == (Object)null) ? null : (componentInChildren.cachedRigidbody ?? ((Component)componentInChildren).GetComponent<Rigidbody>()));
if ((Object)(object)componentInChildren != (Object)null && (Object)(object)val == (Object)null)
{
return false;
}
string key = ModelName(((Object)root).name);
Vector3 mount;
float width;
Transform val2;
if ((Object)(object)val != (Object)null)
{
if (!TryMeasureRoof(val, out mount, out width))
{
return false;
}
val2 = ((Component)val).transform;
roofs[key] = (root.InverseTransformPoint(val2.TransformPoint(mount)), width);
}
else
{
val2 = root;
if (roofs.TryGetValue(key, out (Vector3, float) value2))
{
(mount, width) = value2;
}
else if (!TryMeasureLooks(root, out mount, out width))
{
return false;
}
}
EnsureMaterials();
GameObject val3 = new GameObject("JeepGlider");
val3.transform.SetParent(val2, false);
Mesh val4 = new Mesh
{
name = "JeepGliderSail"
};
val4.MarkDynamic();
GameObject val5 = new GameObject("Sail");
val5.transform.SetParent(val3.transform, false);
val5.AddComponent<MeshFilter>().sharedMesh = val4;
((Renderer)val5.AddComponent<MeshRenderer>()).sharedMaterial = sailMaterial;
Rig rig = new Rig
{
Root = root,
Frame = val2,
Car = componentInChildren,
Net = ((Component)root).GetComponentInChildren<NetworkObject>(true),
Parts = list,
Audio = ((Component)root).GetComponentInChildren<CarAudioManager>(true),
Holder = val3,
Sail = val4,
Mount = mount,
RoofWidth = width,
Keel = Tube(val3, "Keel"),
LeftEdge = Tube(val3, "LeftEdge"),
RightEdge = Tube(val3, "RightEdge"),
Crossbar = Tube(val3, "Crossbar"),
MastLeft = Tube(val3, "MastLeft"),
MastRight = Tube(val3, "MastRight")
};
rig.Opened = 0f;
Draw(rig);
val3.SetActive(false);
rigs[((Il2CppObjectBase)root).Pointer] = rig;
if ((Object)(object)componentInChildren != (Object)null)
{
byCar[((Il2CppObjectBase)componentInChildren).Pointer] = rig;
}
Mod.Log.Msg($"Glider rigged on {((Object)root).name} (roof {mount.y:0.00} m up, {width:0.0} m wide)");
return true;
}
private static bool TryMeasureRoof(Rigidbody rb, out Vector3 mount, out float width)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
mount = default(Vector3);
width = 0f;
Transform transform = ((Component)rb).transform;
bool any = false;
Bounds box = default(Bounds);
foreach (Collider componentsInChild in ((Component)rb).GetComponentsInChildren<Collider>())
{
if (!((Object)(object)componentsInChild == (Object)null) && !componentsInChild.isTrigger && componentsInChild.enabled && !((Object)(object)componentsInChild.attachedRigidbody != (Object)(object)rb))
{
Encapsulate(ref box, ref any, transform, componentsInChild.bounds);
}
}
if (!any || ((Bounds)(ref box)).size.y < 0.3f)
{
return false;
}
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(((Bounds)(ref box)).center.x, ((Bounds)(ref box)).max.y, ((Bounds)(ref box)).center.z - ((Bounds)(ref box)).size.z * 0.08f);
float y = ((Bounds)(ref box)).max.y;
Vector3 val2 = transform.TransformPoint(val + Vector3.up);
float num = float.MaxValue;
foreach (RaycastHit item in (Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(val2, -transform.up, ((Bounds)(ref box)).size.y + 1f, -1, (QueryTriggerInteraction)1))
{
RaycastHit current2 = item;
if (!((Object)(object)((RaycastHit)(ref current2)).collider == (Object)null) && !((Object)(object)((RaycastHit)(ref current2)).collider.attachedRigidbody != (Object)(object)rb) && !(((RaycastHit)(ref current2)).distance >= num))
{
num = ((RaycastHit)(ref current2)).distance;
y = transform.InverseTransformPoint(((RaycastHit)(ref current2)).point).y;
}
}
mount = new Vector3(val.x, y, val.z);
width = ((Bounds)(ref box)).size.x;
return true;
}
private static bool TryMeasureLooks(Transform root, out Vector3 mount, out float width)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
mount = default(Vector3);
width = 0f;
bool any = false;
Bounds box = default(Bounds);
foreach (MeshRenderer componentsInChild in ((Component)root).GetComponentsInChildren<MeshRenderer>())
{
if ((Object)(object)componentsInChild != (Object)null && ((Renderer)componentsInChild).enabled)
{
Encapsulate(ref box, ref any, root, ((Renderer)componentsInChild).bounds);
}
}
if (!any || ((Bounds)(ref box)).size.y < 0.3f)
{
return false;
}
mount = new Vector3(((Bounds)(ref box)).center.x, ((Bounds)(ref box)).max.y - 0.05f, ((Bounds)(ref box)).center.z - ((Bounds)(ref box)).size.z * 0.08f);
width = ((Bounds)(ref box)).size.x;
return true;
}
private static void Encapsulate(ref Bounds box, ref bool any, Transform t, Bounds world)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < 8; i++)
{
Vector3 val = ((Bounds)(ref world)).center + Vector3.Scale(((Bounds)(ref world)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1))));
Vector3 val2 = t.InverseTransformPoint(val);
if (!any)
{
box = new Bounds(val2, Vector3.zero);
any = true;
}
else
{
((Bounds)(ref box)).Encapsulate(val2);
}
}
}
private static Transform Tube(GameObject holder, string name)
{
GameObject obj = GameObject.CreatePrimitive((PrimitiveType)2);
Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
((Object)obj).name = name;
obj.transform.SetParent(holder.transform, false);
((Renderer)obj.GetComponent<MeshRenderer>()).sharedMaterial = tubeMaterial;
return obj.transform;
}
private static void Draw(Rig rig)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_023b: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_0281: Unknown result type (might be due to invalid IL or missing references)
//IL_0286: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Unknown result type (might be due to invalid IL or missing references)
//IL_0292: Unknown result type (might be due to invalid IL or missing references)
//IL_0297: Unknown result type (might be due to invalid IL or missing references)
//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
rig.Drawn = rig.Opened;
float s = Mod.Span.Value / 10f;
float num = GliderMath.Rise(rig.Opened);
float spread = GliderMath.Spread(rig.Opened);
Vector3 val = rig.Mount + Vector3.up * Mathf.Lerp(0.18f, 1.5f * s, num);
Quaternion val2 = Quaternion.AngleAxis((0f - Mod.Airframe().TrimAngle) * 57.29578f * spread, Vector3.right);
Vector3 fwd = val2 * Vector3.forward;
Vector3 up = val2 * Vector3.up;
Vector3 right = Vector3.right;
Vector3 nose = val + fwd * (2.6f * s);
Vector3 val3 = val - fwd * (2f * s);
float half = Mathf.Lerp(3f, 62f, spread) * ((float)Math.PI / 180f);
float edge = 5.6f * s;
Vector3 val4 = Tip(-1f);
Vector3 val5 = Tip(1f);
BuildSail(rig.Sail, nose, val3, val4, val5, fwd, up, right, s, spread);
float num2 = 0.035f * Mathf.Sqrt(s);
Place(rig.Keel, nose, val3 + -fwd * 0.2f * s, num2);
Place(rig.LeftEdge, nose, val4, num2);
Place(rig.RightEdge, nose, val5, num2);
Place(rig.Crossbar, Vector3.Lerp(nose, val4, 0.55f) - up * 0.04f, Vector3.Lerp(nose, val5, 0.55f) - up * 0.04f, num2 * 0.9f);
float num3 = Mathf.Min(rig.RoofWidth * 0.35f, 0.7f);
Place(rig.MastLeft, rig.Mount - Vector3.right * num3, val, num2);
Place(rig.MastRight, rig.Mount + Vector3.right * num3, val, num2);
Vector3 Tip(float side)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
return nose + (-fwd * Mathf.Cos(half) + right * (side * Mathf.Sin(half))) * edge + up * (0.12f * s * spread);
}
}
private static void BuildSail(Mesh mesh, Vector3 nose, Vector3 tail, Vector3 tipL, Vector3 tipR, Vector3 fwd, Vector3 up, Vector3 right, float s, float spread)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
List<Vector3> list = new List<Vector3>();
List<Vector2> list2 = new List<Vector2>();
List<Vector3> list3 = new List<Vector3>();
List<int> list4 = new List<int>();
float num = Mathf.Max(Vector3.Distance(tipL, tipR) * 0.5f, 0.01f);
(Vector3, float)[] array = new(Vector3, float)[2]
{
(tipL, -1f),
(tipR, 1f)
};
for (int i = 0; i < array.Length; i++)
{
(Vector3, float) tuple = array[i];
Vector3 item = tuple.Item1;
float item2 = tuple.Item2;
Vector3 val = Vector3.Lerp(tail, item, 0.55f) + fwd * (0.6f * s * spread) - up * (0.1f * s * spread);
Vector3 val2 = (nose + item + val + tail) * 0.25f - up * (0.18f * s * spread);
Vector3[] array2 = (Vector3[])(object)new Vector3[4] { nose, item, val, tail };
for (int j = 0; j < 2; j++)
{
int count = list.Count;
Vector3 item3 = ((j == 0) ? up : (-up));
Vector3[] array3 = array2;
foreach (Vector3 val3 in array3)
{
list.Add(val3);
list2.Add(new Vector2(Mathf.Abs(Vector3.Dot(val3 - nose, right)) / num, 0.5f));
list3.Add(item3);
}
list.Add(val2);
list2.Add(new Vector2(Mathf.Abs(Vector3.Dot(val2 - nose, right)) / num, 0.5f));
list3.Add(item3);
for (int l = 0; l < 4; l++)
{
int item4 = count + l;
int item5 = count + (l + 1) % 4;
int item6 = count + 4;
if ((j == 1) ^ (item2 < 0f))
{
list4.Add(item4);
list4.Add(item6);
list4.Add(item5);
}
else
{
list4.Add(item4);
list4.Add(item5);
list4.Add(item6);
}
}
}
}
mesh.Clear();
mesh.vertices = Il2CppStructArray<Vector3>.op_Implicit(list.ToArray());
mesh.uv = Il2CppStructArray<Vector2>.op_Implicit(list2.ToArray());
mesh.normals = Il2CppStructArray<Vector3>.op_Implicit(list3.ToArray());
mesh.triangles = Il2CppStructArray<int>.op_Implicit(list4.ToArray());
mesh.RecalculateBounds();
}
private static void Place(Transform tube, Vector3 a, Vector3 b, float radius)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = b - a;
float magnitude = ((Vector3)(ref val)).magnitude;
tube.localPosition = (a + b) * 0.5f;
tube.localRotation = ((magnitude > 0.0001f) ? Quaternion.FromToRotation(Vector3.up, val / magnitude) : Quaternion.identity);
tube.localScale = new Vector3(radius * 2f, magnitude * 0.5f, radius * 2f);
}
private static void EnsureMaterials()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Expected O, but got Unknown
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)sailMaterial != (Object)null) || !((Object)(object)tubeMaterial != (Object)null))
{
Shader obj = Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Universal Render Pipeline/Simple Lit") ?? Shader.Find("Standard");
sailMaterial = new Material(obj)
{
name = "JeepGliderSail",
hideFlags = (HideFlags)32
};
Texture2D val = StripeTexture();
sailMaterial.mainTexture = (Texture)(object)val;
if (sailMaterial.HasProperty("_BaseMap"))
{
sailMaterial.SetTexture("_BaseMap", (Texture)(object)val);
}
if (sailMaterial.HasProperty("_BaseColor"))
{
sailMaterial.SetColor("_BaseColor", Color.white);
}
if (sailMaterial.HasProperty("_Smoothness"))
{
sailMaterial.SetFloat("_Smoothness", 0.35f);
}
if (sailMaterial.HasProperty("_Cull"))
{
sailMaterial.SetFloat("_Cull", 0f);
}
tubeMaterial = new Material(obj)
{
name = "JeepGliderTube",
hideFlags = (HideFlags)32
};
Color val2 = default(Color);
((Color)(ref val2))..ctor(0.55f, 0.57f, 0.6f);
tubeMaterial.color = val2;
if (tubeMaterial.HasProperty("_BaseColor"))
{
tubeMaterial.SetColor("_BaseColor", val2);
}
if (tubeMaterial.HasProperty("_Metallic"))
{
tubeMaterial.SetFloat("_Metallic", 0.8f);
}
if (tubeMaterial.HasProperty("_Smoothness"))
{
tubeMaterial.SetFloat("_Smoothness", 0.7f);
}
}
}
internal static Color Stripe(float u)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
if (!(u < 0.3f))
{
if (!(u < 0.45f))
{
if (!(u < 0.6f))
{
if (!(u < 0.8f))
{
return Brown;
}
return Cream;
}
return Yellow;
}
return Cream;
}
return Yellow;
}
private static Texture2D StripeTexture()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Expected O, but got Unknown
Color[] array = (Color[])(object)new Color[128];
for (int i = 0; i < 64; i++)
{
array[i] = (array[64 + i] = Stripe(((float)i + 0.5f) / 64f));
}
Texture2D val = new Texture2D(64, 2, (TextureFormat)4, false)
{
name = "JeepGliderStripes",
wrapMode = (TextureWrapMode)1,
filterMode = (FilterMode)1,
hideFlags = (HideFlags)32
};
val.SetPixels(Il2CppStructArray<Color>.op_Implicit(array));
val.Apply();
return val;
}
private static void Destroy(Rig rig)
{
if ((Object)(object)rig.Holder != (Object)null)
{
Object.Destroy((Object)(object)rig.Holder);
}
if ((Object)(object)rig.Sail != (Object)null)
{
Object.Destroy((Object)(object)rig.Sail);
}
}
private void Diagnostics()
{
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
//IL_030f: Unknown result type (might be due to invalid IL or missing references)
NetworkRunner runner = HillNet.Runner;
Mod.Log.Msg($"Diag: {rigs.Count} cars rigged, {pending.Count} waiting" + (((Object)(object)runner == (Object)null) ? ", offline" : $", network tick {runner.TickRate} Hz ({runner.DeltaTime * 1000f:0.#} ms), physics step {Time.fixedDeltaTime * 1000f:0.#} ms"));
foreach (Rig value3 in rigs.Values)
{
if (!((Object)(object)value3.Car == (Object)null) && !((Object)(object)value3.Root == (Object)null))
{
Rigidbody cachedRigidbody = value3.Car.cachedRigidbody;
NetworkObject net = value3.Net;
string value = (((Object)(object)net == (Object)null) ? "offline" : $"net id {net.Id.Raw}, input {net.HasInputAuthority}, state {net.HasStateAuthority}");
Instance log = Mod.Log;
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(99, 11);
defaultInterpolatedStringHandler.AppendLiteral("Diag: ");
defaultInterpolatedStringHandler.AppendFormatted(((Object)value3.Root).name);
defaultInterpolatedStringHandler.AppendLiteral(" (");
defaultInterpolatedStringHandler.AppendFormatted(value);
defaultInterpolatedStringHandler.AppendLiteral(") mounted ");
defaultInterpolatedStringHandler.AppendFormatted(value3.Mounted);
defaultInterpolatedStringHandler.AppendLiteral(", open ");
defaultInterpolatedStringHandler.AppendFormatted(value3.Open);
defaultInterpolatedStringHandler.AppendLiteral(" (");
defaultInterpolatedStringHandler.AppendFormatted(value3.Opened, "0.00");
defaultInterpolatedStringHandler.AppendLiteral("), pitch ");
defaultInterpolatedStringHandler.AppendFormatted(value3.Tick.Pitch, "0.0");
defaultInterpolatedStringHandler.AppendLiteral(", flies ");
defaultInterpolatedStringHandler.AppendFormatted(Net.Flies);
defaultInterpolatedStringHandler.AppendLiteral(", ");
defaultInterpolatedStringHandler.AppendLiteral("ticked ");
defaultInterpolatedStringHandler.AppendFormatted(Time.frameCount - value3.TickedFrame);
defaultInterpolatedStringHandler.AppendLiteral(" frames ago, kinematic ");
defaultInterpolatedStringHandler.AppendFormatted((Object)(object)cachedRigidbody != (Object)null && cachedRigidbody.isKinematic);
defaultInterpolatedStringHandler.AppendLiteral(", ");
defaultInterpolatedStringHandler.AppendLiteral("speed ");
float value2;
if (!((Object)(object)cachedRigidbody == (Object)null))
{
Vector3 velocity = cachedRigidbody.velocity;
value2 = ((Vector3)(ref velocity)).magnitude;
}
else
{
value2 = 0f;
}
defaultInterpolatedStringHandler.AppendFormatted(value2, "0.0");
defaultInterpolatedStringHandler.AppendLiteral(" m/s, grounded ");
defaultInterpolatedStringHandler.AppendFormatted(Grounded(value3.Car), "0.00");
log.Msg(defaultInterpolatedStringHandler.ToStringAndClear());
}
}
Net.Diagnostics(delegate(uint id)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
foreach (Rig value4 in rigs.Values)
{
if ((Object)(object)value4.Net != (Object)null && value4.Net.Id.Raw == id)
{
return true;
}
}
return false;
});
}
private static Vector3 N(Vector3 v)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
return new Vector3(v.x, v.y, v.z);
}
private static Vector3 U(Vector3 v)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
return new Vector3(v.X, v.Y, v.Z);
}
}
[HarmonyPatch(typeof(VehicleBase), "FixedUpdateNetwork")]
internal static class VehicleTick
{
private static void Postfix(VehicleBase __instance)
{
if (Core.Quitting)
{
return;
}
try
{
Glider.FixedTick(((Il2CppObjectBase)__instance).Pointer);
}
catch (Exception ex)
{
Mod.Log.Error(ex.ToString());
}
}
}
public readonly struct Airframe
{
public readonly float WingLoading;
public readonly float AspectRatio;
public readonly float Cl0;
public readonly float StallAngle;
public readonly float Cd0;
public readonly float Oswald;
public readonly float SideForce;
public readonly float TrimAngle;
public readonly float TrimDown;
public readonly float TrimUp;
public readonly float MaxBank;
public readonly float StabilityHz;
public readonly float DampingRatio;
private const float Deg = (float)Math.PI / 180f;
public static readonly Airframe Default = new Airframe(7f, 6f, 0.2f, (float)Math.PI / 12f, 0.05f, 0.8f, 0.6f, (float)Math.PI * 2f / 45f, 0.17453292f, (float)Math.PI / 30f, 0.61086524f, 1.2f, 0.8f);
public float LiftSlope => (float)Math.PI * 2f * AspectRatio / (AspectRatio + 2f);
public float InducedDrag => 1f / ((float)Math.PI * Oswald * AspectRatio);
public Airframe(float wingLoading, float aspectRatio, float cl0, float stallAngle, float cd0, float oswald, float sideForce, float trimAngle, float trimDown, float trimUp, float maxBank, float stabilityHz, float dampingRatio)
{
WingLoading = wingLoading;
AspectRatio = aspectRatio;
Cl0 = cl0;
StallAngle = stallAngle;
Cd0 = cd0;
Oswald = oswald;
SideForce = sideForce;
TrimAngle = trimAngle;
TrimDown = trimDown;
TrimUp = trimUp;
MaxBank = maxBank;
StabilityHz = stabilityHz;
DampingRatio = dampingRatio;
}
}
public readonly struct Body
{
public readonly Vector3 Velocity;
public readonly Vector3 Right;
public readonly Vector3 Up;
public readonly Vector3 Forward;
public readonly float Mass;
public Body(Vector3 velocity, Vector3 right, Vector3 up, Vector3 forward, float mass)
{
Velocity = velocity;
Right = right;
Up = up;
Forward = forward;
Mass = mass;
}
}
public readonly struct Aero
{
public readonly Vector3 Force;
public readonly float Alpha;
public readonly float Sideslip;
public readonly float Airspeed;
public readonly float Lift;
public readonly float Drag;
public static readonly Aero None;
public Aero(Vector3 force, float alpha, float sideslip, float airspeed, float lift, float drag)
{
Force = force;
Alpha = alpha;
Sideslip = sideslip;
Airspeed = airspeed;
Lift = lift;
Drag = drag;
}
}
public static class GliderMath
{
public const float Gravity = 9.81f;
public const float AirDensity = 1.225f;
public static float Area(Airframe a, float mass, float open)
{
return mass / a.WingLoading * Math.Clamp(open, 0f, 1f);
}
public static float LiftCoefficient(Airframe a, float alpha)
{
float a2 = Math.Clamp(a.Cl0 + a.LiftSlope * alpha, -1.4f, 1.4f);
float b = 2f * MathF.Sin(alpha) * MathF.Cos(alpha);
return Lerp(a2, b, PastStall(a, alpha));
}
public static float DragCoefficient(Airframe a, float alpha)
{
float num = Math.Clamp(a.Cl0 + a.LiftSlope * alpha, -1.4f, 1.4f);
float a2 = a.Cd0 + a.InducedDrag * num * num;
float b = a.Cd0 + 2f * MathF.Sin(alpha) * MathF.Sin(alpha);
return Lerp(a2, b, PastStall(a, alpha));
}
private static float PastStall(Airframe a, float alpha)
{
return SmoothStep(a.StallAngle, a.StallAngle + 0.15f, MathF.Abs(alpha));
}
public static Aero Forces(Airframe a, Body b, float open)
{
float num = Area(a, b.Mass, open);
float num2 = b.Velocity.Length();
if (num <= 0f || num2 < 0.5f)
{
return Aero.None;
}
float num3 = Vector3.Dot(b.Velocity, b.Right);
Vector3 vector = b.Velocity - b.Right * num3;
float num4 = vector.Length();
float alpha = MathF.Atan2(0f - Vector3.Dot(b.Velocity, b.Up), Vector3.Dot(b.Velocity, b.Forward));
float num5 = MathF.Asin(Math.Clamp(num3 / num2, -1f, 1f));
float num6 = LiftCoefficient(a, alpha);
float num7 = DragCoefficient(a, alpha);
float num8 = 0.6125f * num2 * num2;
Vector3 force = -b.Velocity / num2 * (num8 * num * num7) - b.Right * (num8 * num * a.SideForce * num5);
if (num4 > 0.1f)
{
Vector3 vector2 = Vector3.Normalize(Vector3.Cross(vector / num4, b.Right));
float num9 = 0.6125f * num4 * num4;
force += vector2 * (num9 * num * num6);
}
return new Aero(force, alpha, num5, num2, num6, num7);
}
public static float StallSpeed(Airframe a)
{
return MathF.Sqrt(19.62f * a.WingLoading / (1.225f * LiftCoefficient(a, a.StallAngle)));
}
public static float Authority(Airframe a, float open, float airspeed, float groundedFraction)
{
float num = airspeed / StallSpeed(a);
return Math.Clamp(open, 0f, 1f) * Math.Clamp(num * num, 0f, 1f) * (1f - Math.Clamp(groundedFraction, 0f, 1f));
}
public static float Trim(Airframe a, float pitch)
{
pitch = Math.Clamp(pitch, -1f, 1f);
return a.TrimAngle + pitch * ((pitch < 0f) ? a.TrimDown : a.TrimUp);
}
public static float DeadZone(float axis, float zone)
{
float num = MathF.Abs(axis);
if (num <= zone || zone >= 1f)
{
return 0f;
}
return (float)MathF.Sign(axis) * MathF.Min((num - zone) / (1f - zone), 1f);
}
public static float Quantize(float pitch, int steps)
{
return MathF.Round(Math.Clamp(pitch, -1f, 1f) * (float)steps) / (float)steps;
}
public static Vector3 Righting(Airframe a, Aero aero, Body b, Vector3 localAngularVelocity, float steer, float trim, float authority)
{
if (authority <= 0f)
{
return Vector3.Zero;
}
float num = (float)Math.PI * 2f * a.StabilityHz;
float num2 = num * num;
float num3 = 2f * a.DampingRatio * num;
float num4 = aero.Alpha - trim;
float num5 = MathF.Asin(Math.Clamp(b.Right.Y, -1f, 1f)) + Math.Clamp(steer, -1f, 1f) * a.MaxBank;
float sideslip = aero.Sideslip;
return (new Vector3(num2 * num4, num2 * sideslip, (0f - num2) * num5) - num3 * localAngularVelocity) * authority;
}
public static float Animate(float open, bool deployed, float seconds, float dt)
{
if (!(seconds <= 0f))
{
return Math.Clamp(open + (deployed ? dt : (0f - dt)) / seconds, 0f, 1f);
}
if (!deployed)
{
return 0f;
}
return 1f;
}
public static float Rise(float open)
{
return SmoothStep(0f, 0.35f, open);
}
public static float Spread(float open)
{
return SmoothStep(0.25f, 1f, open);
}
public static float Lerp(float a, float b, float t)
{
return a + (b - a) * t;
}
public static float SmoothStep(float from, float to, float x)
{
float num = Math.Clamp((x - from) / (to - from), 0f, 1f);
return num * num * (3f - 2f * num);
}
}
public class Mod : MelonMod
{
internal static Instance Log;
internal static MelonPreferences_Entry<bool> Enabled;
internal static MelonPreferences_Entry<bool> Flight;
internal static MelonPreferences_Entry<float> WingLoading;
internal static MelonPreferences_Entry<float> Stability;
internal static MelonPreferences_Entry<float> PitchRange;
internal static MelonPreferences_Entry<bool> InvertPitch;
internal static MelonPreferences_Entry<float> OpenSeconds;
internal static MelonPreferences_Entry<float> Span;
private GameObject host;
public override void OnInitializeMelon()
{
Log = ((MelonBase)this).LoggerInstance;
MelonPreferences_Category obj = MelonPreferences.CreateCategory("JeepGlider");
Enabled = obj.CreateEntry<bool>("Enabled", true, (string)null, "The JeepGlider roof cosmetic, free in the garage. Honk to open it, honk again to fold it. Other players see it if they have the mod too.", false, false, (ValueValidator)null, (string)null);
Flight = obj.CreateEntry<bool>("Flight", true, (string)null, "The open glider really flies the car. Off = looks only. In multiplayer the host needs JeepGlider too.", false, false, (ValueValidator)null, (string)null);
WingLoading = obj.CreateEntry<float>("WingLoading", 7f, (string)null, "Kilograms of car per square metre of sail. A real hang glider is about 7. Lower = floatier, slower, glides further.", false, false, (ValueValidator)null, (string)null);
Stability = obj.CreateEntry<float>("Stability", 1f, (string)null, "How firmly it holds its glide and banks with the steering. 0 = no help at all.", false, false, (ValueValidator)null, (string)null);
PitchRange = obj.CreateEntry<float>("PitchRange", 1f, (string)null, "How far the left stick's up and down pitches the glider. 0 = off. Above 1 lets pulling back stall it.", false, false, (ValueValidator)null, (string)null);
InvertPitch = obj.CreateEntry<bool>("InvertPitch", false, (string)null, "Off: stick forward dives, stick back pulls up, like a hang glider's bar. On: the other way round.", false, false, (ValueValidator)null, (string)null);
OpenSeconds = obj.CreateEntry<float>("OpenSeconds", 1.5f, (string)null, "How long it takes to open or fold.", false, false, (ValueValidator)null, (string)null);
Span = obj.CreateEntry<float>("Span", 10f, (string)null, "Wingspan of the model in metres. Only changes how it looks.", false, false, (ValueValidator)null, (string)null);
Net.Register();
}
internal static Airframe Airframe()
{
Airframe airframe = JeepGlider.Airframe.Default;
return new Airframe(Mathf.Max(WingLoading.Value, 0.5f), airframe.AspectRatio, airframe.Cl0, airframe.StallAngle, airframe.Cd0, airframe.Oswald, airframe.SideForce, airframe.TrimAngle, airframe.TrimDown * PitchRange.Value, airframe.TrimUp * PitchRange.Value, airframe.MaxBank, airframe.StabilityHz, airframe.DampingRatio);
}
public override void OnUpdate()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
HillNet.Tick();
if (!((Object)(object)host != (Object)null) && !Core.Quitting)
{
host = new GameObject("JeepGlider")
{
hideFlags = (HideFlags)61
};
Object.DontDestroyOnLoad((Object)(object)host);
host.AddComponent<Glider>();
}
}
}
internal static class Net
{
internal sealed class CarState
{
public uint Car { get; set; }
public int Tick { get; set; }
public bool Mounted { get; set; }
public bool Open { get; set; }
public float Pitch { get; set; }
}
internal const string Channel = "JeepGlider";
private static readonly Dictionary<uint, CarState> remote = new Dictionary<uint, CarState>();
private static readonly Dictionary<uint, Timeline> timelines = new Dictionary<uint, Timeline>();
private static readonly Dictionary<uint, int> owners = new Dictionary<uint, int>();
private static CarState own;
private static bool ownSent;
internal static bool Flies
{
get
{
if (!HillNet.IsAuthority)
{
return HillNet.HostHas("JeepGlider");
}
return true;
}
}
internal static void Register()
{
HillNet.Register<CarState>("JeepGlider", (Action<NetworkRunner, PlayerRef, CarState>)OnReceive);
HillNet.SessionReset += delegate
{
remote.Clear();
timelines.Clear();
owners.Clear();
ownSent = false;
};
HillNet.PlayerLeft += delegate(int id)
{
List<uint> list = new List<uint>();
foreach (var (item, num3) in owners)
{
if (num3 == id)
{
list.Add(item);
}
}
foreach (uint item2 in list)
{
owners.Remove(item2);
remote.Remove(item2);
timelines.Remove(item2);
HillNet.Broadcast("JeepGlider", (object)new CarState
{
Car = item2
}, int.MinValue);
}
};
HillNet.PlayerReady += delegate(PlayerRef player)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
if (own != null)
{
HillNet.SendTo(player, "JeepGlider", (object)own);
}
foreach (CarState value in remote.Values)
{
HillNet.SendTo(player, "JeepGlider", (object)value);
}
};
HillNet.HostReady += delegate
{
if (own != null)
{
ownSent = Send(HillNet.Runner, own);
}
};
}
internal static void SendOwn(NetworkObject car, int tick, bool mounted, bool open, float pitch)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
NetworkRunner runner = HillNet.Runner;
if (!((Object)(object)runner == (Object)null) && !((Object)(object)car == (Object)null))
{
uint raw = car.Id.Raw;
if (!ownSent || own == null || own.Car != raw || own.Mounted != mounted || own.Open != open || own.Pitch != pitch)
{
own = new CarState
{
Car = raw,
Tick = tick,
Mounted = mounted,
Open = open,
Pitch = pitch
};
ownSent = Send(runner, own);
}
}
}
private static bool Send(NetworkRunner runner, CarState s)
{
if ((Object)(object)runner == (Object)null)
{
return false;
}
if (runner.IsServer)
{
HillNet.Broadcast("JeepGlider", (object)s, int.MinValue);
return true;
}
if (!HillNet.HostHas("JeepGlider"))
{
return false;
}
HillNet.SendToHost("JeepGlider", (object)s);
return true;
}
internal static CarState For(NetworkObject car)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)car != (Object)null) || !remote.TryGetValue(car.Id.Raw, out var value))
{
return null;
}
return value;
}
internal static Timeline TimelineFor(NetworkObject car)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
uint raw = car.Id.Raw;
if (!timelines.TryGetValue(raw, out var value))
{
value = (timelines[raw] = new Timeline());
}
return value;
}
internal static void Diagnostics(Func<uint, bool> rigged)
{
NetworkRunner runner = HillNet.Runner;
if ((Object)(object)runner == (Object)null)
{
return;
}
Mod.Log.Msg($"Diag: {(runner.IsServer ? "host" : $"client, host has JeepGlider {HillNet.HostHas("JeepGlider")}")}, own {((own == null) ? "never sent" : $"car {own.Car} open {own.Open}, sent {ownSent}")}");
foreach (CarState value2 in remote.Values)
{
Mod.Log.Msg($"Diag: car {value2.Car} said mounted {value2.Mounted}, open {value2.Open} at tick {value2.Tick}; rigged here {rigged(value2.Car)}" + ((runner.IsServer && owners.TryGetValue(value2.Car, out var value)) ? $", player {value}" : ""));
}
}
private static void OnReceive(NetworkRunner runner, PlayerRef from, CarState s)
{
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
if (!remote.TryGetValue(s.Car, out var value) || value.Open != s.Open || value.Mounted != s.Mounted)
{
Mod.Log.Msg($"Car {s.Car}: glider {((!s.Mounted) ? "not mounted" : (s.Open ? "open" : "folded"))} (tick {s.Tick}{(runner.IsServer ? $", ours {runner.Tick.Raw}, player {((PlayerRef)(ref from)).PlayerId}" : "")})");
}
remote[s.Car] = s;
if (runner.IsServer)
{
if (!timelines.TryGetValue(s.Car, out var value2))
{
value2 = (timelines[s.Car] = new Timeline());
}
value2.Add(s.Tick, s.Mounted && s.Open, s.Pitch);
owners[s.Car] = ((PlayerRef)(ref from)).PlayerId;
HillNet.Broadcast("JeepGlider", (object)s, ((PlayerRef)(ref from)).PlayerId);
}
}
}
internal static class RoofItem
{
internal const uint Id = 1242980637u;
internal const string PartName = "JeepGlider_Roof";
internal const string Title = "JeepGlider";
internal const string Description = "A hang glider folded on the roof. Honk to open it and fly off the next ridge, honk again to fold it. Steer to bank, throttle to dive, brake to pull up.";
private static VehicleCosmetic part;
private static bool registered;
internal static bool EnsureRegistered()
{
if (registered)
{
return true;
}
InventoryItemsCatalog inventoryItemsCatalog = PlayerInventoryManager.InventoryItemsCatalog;
if ((Object)(object)inventoryItemsCatalog == (Object)null || inventoryItemsCatalog.IdToSO == null || inventoryItemsCatalog.IdToSO.Count == 0)
{
return false;
}
VehicleCosmetic val = PickTemplate(inventoryItemsCatalog);
if ((Object)(object)val == (Object)null)
{
return false;
}
if (inventoryItemsCatalog.IdToSO.ContainsKey(1242980637u))
{
Mod.Log.Warning($"Roof item: id {1242980637} is already in the catalog; replacing it");
}
part = Object.Instantiate<VehicleCosmetic>(val);
((Object)part).name = "JeepGlider_Roof";
((Object)part).hideFlags = (HideFlags)32;
((InventoryItemScriptableObject)part).ItemId = 1242980637u;
((InventoryItemScriptableObject)part).Price = 0;
part.CosmeticType = (CosmeticType)7;
((InventoryItemScriptableObject)part).Icon = Icon();
((VehiclePartSO)part).LinkedParts = new List<VehiclePartSO>();
((VehiclePartSO)part).Effects = new List<UpgradeEffect>();
inventoryItemsCatalog.IdToSO[1242980637u] = (InventoryItemScriptableObject)(object)part;
if (inventoryItemsCatalog.IdToName != null)
{
inventoryItemsCatalog.IdToName[1242980637u] = "JeepGlider_Roof";
}
if (inventoryItemsCatalog.NameToId != null)
{
inventoryItemsCatalog.NameToId["JeepGlider_Roof"] = 1242980637u;
}
int num = 0;
foreach (UpgradesLists item in Resources.FindObjectsOfTypeAll<UpgradesLists>())
{
if (item.Parts != null && HasRoofPart(item))
{
item.Parts.Add((VehiclePartSO)(object)part);
num++;
}
}
registered = true;
Mod.Log.Msg($"Roof item: registered {"JeepGlider_Roof"} (id {1242980637}, copied from {((Object)val).name}, in {num} upgrade lists)");
return true;
}
private static bool HasRoofPart(UpgradesLists ul)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Invalid comparison between Unknown and I4
Enumerator<VehiclePartSO> enumerator = ul.Parts.GetEnumerator();
while (enumerator.MoveNext())
{
VehiclePartSO current = enumerator.Current;
VehicleCosmetic val = ((current != null) ? ((Il2CppObjectBase)current).TryCast<VehicleCosmetic>() : null);
if ((Object)(object)val != (Object)null && (int)val.CosmeticType == 7 && ((InventoryItemScriptableObject)val).ItemId != 1242980637)
{
return true;
}
}
return false;
}
private static VehicleCosmetic PickTemplate(InventoryItemsCatalog catalog)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Invalid comparison between Unknown and I4
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
VehicleCosmetic val = null;
Enumerator<uint, InventoryItemScriptableObject> enumerator = catalog.IdToSO.GetEnumerator();
while (enumerator.MoveNext())
{
InventoryItemScriptableObject value = enumerator.Current.Value;
VehicleCosmetic val2 = ((value != null) ? ((Il2CppObjectBase)value).TryCast<VehicleCosmetic>() : null);
if (!((Object)(object)val2 == (Object)null) && (int)val2.CosmeticType == 7 && !((Object)val2).name.Contains("CatalogExcluded") && (int)((InventoryItemScriptableObject)val2).RequiredDlc == 0 && ((Object)(object)val == (Object)null || (((VehiclePartSO)val).LinkedParts != null && ((VehiclePartSO)val).LinkedParts.Count > 0 && (((VehiclePartSO)val2).LinkedParts == null || ((VehiclePartSO)val2).LinkedParts.Count == 0))))
{
val = val2;
}
}
return val;
}
internal static List<GameObject> PartObjects(Transform car)
{
List<GameObject> list = new List<GameObject>();
if (!registered || (Object)(object)car == (Object)null)
{
return list;
}
foreach (VehicleUpgradeObject componentsInChild in ((Component)car).GetComponentsInChildren<VehicleUpgradeObject>(true))
{
if (Is((InventoryItemScriptableObject)(object)componentsInChild.vehiclePartReference))
{
list.Add(((Component)componentsInChild).gameObject);
}
}
return list;
}
internal static void AddPartObject(Transform car)
{
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Invalid comparison between Unknown and I4
if (!EnsureRegistered() || (Object)(object)car == (Object)null || PartObjects(car).Count > 0)
{
return;
}
Transform val = null;
Transform val2 = null;
foreach (VehicleUpgradeObject componentsInChild in ((Component)car).GetComponentsInChildren<VehicleUpgradeObject>(true))
{
VehiclePartSO vehiclePartReference = componentsInChild.vehiclePartReference;
VehicleCosmetic val3 = ((vehiclePartReference != null) ? ((Il2CppObjectBase)vehiclePartReference).TryCast<VehicleCosmetic>() : null);
if (!((Object)(object)val3 == (Object)null) && !Is((InventoryItemScriptableObject)(object)val3))
{
if (val2 == null)
{
val2 = ((Component)componentsInChild).transform.parent;
}
if ((int)val3.CosmeticType == 7)
{
val = ((Component)componentsInChild).transform.parent;
break;
}
}
}
Transform val4 = val ?? val2;
if (!((Object)(object)val4 == (Object)null))
{
GameObject val5 = new GameObject("JeepGlider_Roof");
val5.SetActive(false);
val5.transform.SetParent(val4, false);
val5.AddComponent<VehicleUpgradeObject>().vehiclePartReference = (VehiclePartSO)(object)part;
Mod.Log.Msg("Roof item: part object added to " + ((Object)car).name);
}
}
internal static bool Is(InventoryItemScriptableObject item)
{
if ((Object)(object)item != (Object)null)
{
return item.ItemId == 1242980637;
}
return false;
}
private static Sprite Icon()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false)
{
name = "JeepGlider_Roof",
hideFlags = (HideFlags)32
};
val.SetPixels(Il2CppStructArray<Color>.op_Implicit(IconPixels(128)));
val.Apply();
Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f));
((Object)obj).name = "JeepGlider_Roof";
((Object)obj).hideFlags = (HideFlags)32;
return obj;
}
private static Color[] IconPixels(int n)
{
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
Color[] array = (Color[])(object)new Color[n * n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
float num = ((float)j + 0.5f) / (float)n - 0.5f;
float num2 = ((float)i + 0.5f) / (float)n;
float num3 = 0.88f;
float num4 = 0.22f + 0.25f * (1f - Mathf.Abs(num) / 0.48f);
float num5 = 0.48f * (num3 - num2) / (num3 - 0.22f);
float num6 = Mathf.Min(num5 - Mathf.Abs(num), num2 - num4);
if (!(num5 <= 0f) && !(num6 <= 0f))
{
Color val = Glider.Stripe(Mathf.Abs(num) / 0.48f);
if (num6 < 0.025f)
{
val = Color.Lerp(val, Glider.Brown, 0.8f);
}
val.a = Mathf.Clamp01(num6 * (float)n);
array[i * n + j] = val;
}
}
}
return array;
}
}
[HarmonyPatch(typeof(LocalVehicleCustomizationController), "InitParts")]
internal static class LocalInitPartsPatch
{
private static void Prefix(LocalVehicleCustomizationController __instance)
{
try
{
Transform root = ((Component)__instance).transform.root;
RoofItem.AddPartObject(root);
Glider.CarReady(root);
}
catch (Exception ex)
{
Mod.Log.Error((object)ex);
}
}
}
[HarmonyPatch(typeof(VehicleCustomizationController), "InitVehicleUpgrades")]
internal static class NetInitPartsPatch
{
private static void Prefix(VehicleCustomizationController __instance)
{
try
{
Transform root = ((Component)__instance).transform.root;
RoofItem.AddPartObject(root);
Glider.CarReady(root);
}
catch (Exception ex)
{
Mod.Log.Error((object)ex);
}
}
}
[HarmonyPatch]
internal static class AvailablePatch
{
private static IEnumerable<MethodBase> TargetMethods()
{
MethodInfo[] methods = typeof(InventoryUtility).GetMethods();
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.Name == "IsAvailableToBuy")
{
yield return methodInfo;
}
}
}
private static void Postfix(object[] __args, ref bool __result)
{
if (!__result && __args.Length != 0)
{
object obj = __args[0];
InventoryItemScriptableObject val = (InventoryItemScriptableObject)((obj is InventoryItemScriptableObject) ? obj : null);
if (val != null && RoofItem.Is(val))
{
__result = !Owned(val, __args);
}
}
}
private static bool Owned(InventoryItemScriptableObject item, object[] args)
{
if (args.Length >= 2)
{
object obj = args[1];
CarInfo val = (CarInfo)((obj is CarInfo) ? obj : null);
if (val == null)
{
if (!(args[1] is uint num))
{
return InventoryUtility.IsOwned(item);
}
return InventoryUtility.IsOwned(item, num);
}
return InventoryUtility.IsOwned(item, ((InventoryItemScriptableObject)val).ItemId);
}
return InventoryUtility.IsOwned(item);
}
}
[HarmonyPatch(typeof(StateMerchantMenu), "UpdateUpgradeDescription")]
internal static class DescriptionPatch
{
private static void Postfix(StateMerchantMenu __instance, UIMerchantButtonSelector button)
{
try
{
InventoryItemScriptableObject item = default(InventoryItemScriptableObject);
if (!((Object)(object)button == (Object)null) && __instance.buttonByInventoryItemSO.TryGetValue(button, ref item) && RoofItem.Is(item))
{
ContextUIMerchantMenu merchantMenuUIContext = __instance.merchantMenuUIContext;
if ((Object)(object)merchantMenuUIContext.DescriptionTitleText != (Object)null)
{
((TMP_Text)merchantMenuUIContext.DescriptionTitleText).text = "JeepGlider";
}
if ((Object)(object)merchantMenuUIContext.DescriptionText != (Object)null)
{
((TMP_Text)merchantMenuUIContext.DescriptionText).text = "A hang glider folded on the roof. Honk to open it and fly off the next ridge, honk again to fold it. Steer to bank, throttle to dive, brake to pull up.";
}
}
}
catch (Exception ex)
{
Mod.Log.Error((object)ex);
}
}
}
public readonly struct TickState
{
public readonly bool Open;
public readonly float Pitch;
public readonly float Opened;
public TickState(bool open, float pitch, float opened)
{
Open = open;
Pitch = pitch;
Opened = opened;
}
}
public sealed class Timeline
{
private readonly Queue<(int Tick, bool Open, float Pitch)> pending = new Queue<(int, bool, float)>();
public bool Open { get; private set; }
public float Pitch { get; private set; }
public void Add(int tick, bool open, float pitch)
{
pending.Enqueue((tick, open, pitch));
}
public void Advance(int tick, int maxLead)
{
while (pending.Count > 0)
{
(int, bool, float) tuple = pending.Peek();
if (tuple.Item1 > tick && tuple.Item1 - tick <= maxLead)
{
break;
}
pending.Dequeue();
Open = tuple.Item2;
Pitch = tuple.Item3;
}
}
public void Clear()
{
pending.Clear();
Open = false;
Pitch = 0f;
}
}
public sealed class History
{
private readonly int[] ticks;
private readonly TickState[] states;
public History(int size)
{
ticks = new int[size];
states = new TickState[size];
for (int i = 0; i < size; i++)
{
ticks[i] = int.MinValue;
}
}
public void Record(int tick, TickState state)
{
int num = Slot(tick);
ticks[num] = tick;
states[num] = state;
}
public bool TryGet(int tick, out TickState state)
{
int num = Slot(tick);
state = states[num];
return ticks[num] == tick;
}
private int Slot(int tick)
{
return (int)((uint)tick % (uint)ticks.Length);
}
}
}