using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using GravityKart;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("GravityKart")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany(null)]
[assembly: AssemblyProduct("GravityKart")]
[assembly: AssemblyCopyright("Created by Adi")]
[assembly: AssemblyTrademark(null)]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.5")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: MelonInfo(typeof(global::GravityKart.GravityKart), "GravityKart", "1.0.5", "Adi", null)]
[assembly: MelonGame(null, null)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.5.0")]
namespace GravityKart;
public static class BuildInfo
{
public const string Name = "GravityKart";
public const string Author = "Adi";
public const string Company = null;
public const string Version = "1.0.5";
public const string DownloadLink = null;
}
public class GravityKart : MelonMod
{
[HarmonyPatch(typeof(Seat), "Register")]
public static class SeatPatch
{
public static void Postfix(Seat __instance)
{
playerRbs = Il2CppArrayBase<Rigidbody>.op_Implicit(((Component)((Component)Player.RigManager).transform.root).GetComponentsInChildren<Rigidbody>());
playerMass = playerRbs.Sum((Rigidbody i) => i.mass);
}
}
[HarmonyPatch(typeof(Atv), "Start")]
public static class GoKartPatch
{
public static void Postfix(Atv __instance)
{
if ((Object)(object)((Component)__instance).GetComponent<GoKartMono>() == (Object)null)
{
((Behaviour)((Component)__instance).gameObject.AddComponent<GoKartMono>()).enabled = Enabled;
}
}
}
[RegisterTypeInIl2Cpp(false)]
public class GoKartMono : MonoBehaviour
{
private Atv atv;
public Rigidbody[] rbs;
public List<Rigidbody> constrainedRbs = new List<Rigidbody>();
public float kartMass;
private static float jumpCharge = 0.2f;
private bool isGrounded;
private Vector3 surfaceNormal;
private float gravityTransition;
private bool isGoKart;
private bool PlayerIsInKart
{
get
{
Seat driverSeat = atv.driverSeat;
return (Object)(object)((driverSeat != null) ? driverSeat._rig : null) == (Object)(object)Player.RigManager;
}
}
public GoKartMono(IntPtr ptr)
: base(ptr)
{
}
public void Awake()
{
atv = ((Component)this).GetComponent<Atv>();
rbs = Il2CppArrayBase<Rigidbody>.op_Implicit(((Component)((Component)atv).transform.root).gameObject.GetComponentsInChildren<Rigidbody>());
kartMass = rbs.Sum((Rigidbody i) => i.mass);
goKarts.Add(this);
isGoKart = ((Object)atv).name.Contains("gokart");
}
public void Update()
{
//IL_00af: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: 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_0111: 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_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: 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_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
if (!PlayerIsInKart || !Jumping || (!AffectOtherVehicles && !isGoKart))
{
return;
}
if (Player.RightController.GetAButton() || Player.LeftController.GetThumbStick())
{
jumpCharge += Time.deltaTime * 1.5f;
}
else
{
jumpCharge -= Time.deltaTime * 1.5f;
}
jumpCharge = Mathf.Clamp(jumpCharge, 0.2f, 1.25f);
if (isGrounded && (Player.RightController.GetAButtonUp() || Player.LeftController.GetThumbStickUp()))
{
float num = ((Vector3.Angle(atv.mainBody.velocity, ((Component)atv.mainBody).transform.forward) < 90f) ? 1f : (-1f));
Vector3 val = (((Component)atv).transform.up * 0.7f + ((Component)atv).transform.forward * 0.2f * num) * JumpForce * jumpCharge;
Rigidbody[] array = rbs;
for (int i = 0; i < array.Length; i++)
{
array[i].AddForce(val, (ForceMode)2);
}
array = playerRbs;
for (int i = 0; i < array.Length; i++)
{
array[i].AddForce(val, (ForceMode)2);
}
jumpCharge = 0.2f;
}
}
public void FixedUpdate()
{
//IL_0024: 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_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0503: Unknown result type (might be due to invalid IL or missing references)
//IL_0513: Unknown result type (might be due to invalid IL or missing references)
//IL_0518: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0200: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: 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_0240: 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_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0539: Unknown result type (might be due to invalid IL or missing references)
//IL_0549: Unknown result type (might be due to invalid IL or missing references)
//IL_054e: 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_00eb: 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_00a5: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: 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_0661: Unknown result type (might be due to invalid IL or missing references)
//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
//IL_05af: Unknown result type (might be due to invalid IL or missing references)
//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
//IL_05be: Unknown result type (might be due to invalid IL or missing references)
//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: 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_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: 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_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: 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_02c7: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: 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_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: 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_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0406: Unknown result type (might be due to invalid IL or missing references)
//IL_040b: Unknown result type (might be due to invalid IL or missing references)
//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
//IL_02f4: 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)
//IL_01d4: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
//IL_0431: Unknown result type (might be due to invalid IL or missing references)
//IL_0438: Unknown result type (might be due to invalid IL or missing references)
//IL_0325: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
//IL_033f: Unknown result type (might be due to invalid IL or missing references)
//IL_0344: Unknown result type (might be due to invalid IL or missing references)
//IL_0462: Unknown result type (might be due to invalid IL or missing references)
//IL_0467: Unknown result type (might be due to invalid IL or missing references)
//IL_0471: Unknown result type (might be due to invalid IL or missing references)
//IL_0476: Unknown result type (might be due to invalid IL or missing references)
//IL_0364: Unknown result type (might be due to invalid IL or missing references)
//IL_0369: Unknown result type (might be due to invalid IL or missing references)
//IL_0373: Unknown result type (might be due to invalid IL or missing references)
//IL_037d: Unknown result type (might be due to invalid IL or missing references)
//IL_0384: Unknown result type (might be due to invalid IL or missing references)
//IL_038f: Unknown result type (might be due to invalid IL or missing references)
//IL_0496: Unknown result type (might be due to invalid IL or missing references)
//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
if (!PlayerIsInKart || (!AffectOtherVehicles && !isGoKart))
{
return;
}
RaycastHit val = default(RaycastHit);
isGrounded = Physics.Raycast(((Component)atv).transform.position, -((Component)atv).transform.up, ref val, 0.45f, -135425);
Rigidbody[] array;
if (!isGrounded)
{
Vector3 val2 = Vector3.zero;
if (AutoWallMount)
{
if (Physics.Raycast(((Component)atv.mainBody).transform.position, ((Component)atv).transform.right, 1.3f, -135425))
{
val2 += ((Component)atv).transform.forward * randomMagicNumber;
}
else if (Physics.Raycast(((Component)atv.mainBody).transform.position, -((Component)atv).transform.right, 1.3f, -135425))
{
val2 += -((Component)atv).transform.forward * randomMagicNumber;
}
else
{
if (Physics.Raycast(((Component)atv.mainBody).transform.position, ((Component)atv).transform.forward, 1f, -135425))
{
val2 += -((Component)atv).transform.right * randomMagicNumber;
}
if (Physics.Raycast(((Component)atv.mainBody).transform.position, -((Component)atv).transform.forward, 1.3f, -135425))
{
val2 += ((Component)atv).transform.right * randomMagicNumber;
}
}
}
Vector2 thumbStickAxis = Player.LeftController.GetThumbStickAxis();
val2 += (((Component)atv).transform.forward * (0f - thumbStickAxis.x) + ((Component)atv).transform.right * thumbStickAxis.y) * InAir;
array = rbs;
for (int j = 0; j < array.Length; j++)
{
array[j].AddTorque(val2, (ForceMode)5);
}
}
if (isGrounded && atv._lastThrottleSet != 0f && WallClimbing)
{
RaycastHit val5 = default(RaycastHit);
if (atv._lastThrottleSet > 0.8f)
{
RaycastHit val3 = default(RaycastHit);
if (Physics.Raycast(((Component)atv.mainBody).transform.position, ((Component)atv).transform.forward, ref val3, 1.2f, -135425) && Vector3.Angle(((Component)atv).transform.up, ((RaycastHit)(ref val3)).normal) > climbAngle)
{
float num = Math.Abs(atv._lastThrottleSet);
Vector3 val4 = -((Component)atv).transform.up * (Physics.gravity.y / 1.5f);
array = rbs;
foreach (Rigidbody obj in array)
{
obj.AddTorque(-((Component)atv).transform.right * randomMagicNumber * 2.5f * num, (ForceMode)5);
obj.AddForce(val4, (ForceMode)5);
}
array = playerRbs;
for (int j = 0; j < array.Length; j++)
{
array[j].AddForce(val4, (ForceMode)5);
}
}
}
else if (atv._lastThrottleSet < -0.8f && Physics.Raycast(((Component)atv.mainBody).transform.position, -((Component)atv).transform.forward, ref val5, 1.3f, -135425) && Vector3.Angle(((Component)atv).transform.up, ((RaycastHit)(ref val5)).normal) > climbAngle)
{
float num2 = 2.5f * playerMass / kartMass;
Vector3 val6 = ((RaycastHit)(ref val5)).normal * Physics.gravity.y;
array = rbs;
foreach (Rigidbody obj2 in array)
{
obj2.AddTorque(((Component)atv).transform.right * randomMagicNumber * thingy * num2, (ForceMode)5);
obj2.AddForce(val6, (ForceMode)5);
}
array = playerRbs;
for (int j = 0; j < array.Length; j++)
{
array[j].AddForce(val6 * 1.5f, (ForceMode)5);
}
}
}
if (Vector3.Angle(Physics.gravity, -((Component)atv).transform.up) < 35f || !Physics.Raycast(((Component)atv.mainBody).transform.position, -((Component)atv).transform.up, 1.75f, -135425))
{
gravityTransition = Mathf.Clamp01(gravityTransition - Time.fixedDeltaTime / 2f);
return;
}
gravityTransition = Mathf.Clamp01(gravityTransition + Time.fixedDeltaTime * 4f);
Vector3 val7 = (((Component)atv).transform.up * Physics.gravity.y - Physics.gravity) * gravityTransition;
try
{
array = playerRbs;
for (int j = 0; j < array.Length; j++)
{
array[j].AddForce(val7, (ForceMode)5);
}
}
catch
{
Il2CppArrayBase<Rigidbody> componentsInChildren = ((Component)Player.RigManager).GetComponentsInChildren<Rigidbody>();
float num3 = ((IEnumerable<Rigidbody>)componentsInChildren).Sum((Rigidbody i) => i.mass);
if (num3 != 0f)
{
playerRbs = Il2CppArrayBase<Rigidbody>.op_Implicit(componentsInChildren);
playerMass = num3;
}
}
array = rbs;
for (int j = 0; j < array.Length; j++)
{
array[j].AddForce(val7, (ForceMode)5);
}
}
}
public static float randomMagicNumber = 35f;
public static float thingy = 2.9f;
private const int layerMask = -135425;
public static float climbAngle = 65f;
public static Rigidbody[] playerRbs;
public static float playerMass;
public static bool debug = false;
public static List<GoKartMono> goKarts = new List<GoKartMono>();
public static bool Enabled => Prefs.Enabled.Value;
public static bool Jumping => Prefs.Jumping.Value;
public static float JumpForce => 10f * Prefs.JumpForce.Value;
public static float InAir => 10f * Prefs.InAirTurn.Value;
public static bool AutoWallMount => Prefs.AutoWallMount.Value;
public static bool WallClimbing => Prefs.WallClimbing.Value;
public static bool AffectOtherVehicles => Prefs.AffectOtherVehicles.Value;
public override void OnInitializeMelon()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: 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_0195: Unknown result type (might be due to invalid IL or missing references)
Prefs.LoadPrefs();
Page obj = Page.Root.CreatePage("GravityKart", Color.white, 0, true);
obj.CreateBool("Enabled", Color.white, Enabled, (Action<bool>)delegate(bool value)
{
Prefs.Enabled.Value = value;
foreach (GoKartMono goKart in goKarts)
{
((Behaviour)goKart).enabled = value;
}
});
obj.CreateBool("Jumping", Color.white, Prefs.Jumping.Value, (Action<bool>)delegate(bool value)
{
Prefs.Jumping.Value = value;
});
obj.CreateFloat("Jump Force Multiplier", Color.white, Prefs.JumpForce.Value, 0.1f, float.MinValue, float.MaxValue, (Action<float>)delegate(float value)
{
Prefs.JumpForce.Value = value;
});
obj.CreateFloat("In-Air Rotation Speed", Color.white, Prefs.InAirTurn.Value, 0.1f, float.MinValue, float.MaxValue, (Action<float>)delegate(float value)
{
Prefs.InAirTurn.Value = value;
});
obj.CreateBool("WallClimbing", Color.white, Prefs.WallClimbing.Value, (Action<bool>)delegate(bool value)
{
Prefs.WallClimbing.Value = value;
});
obj.CreateBool("AutoWallMount", Color.white, Prefs.AutoWallMount.Value, (Action<bool>)delegate(bool value)
{
Prefs.AutoWallMount.Value = value;
});
obj.CreateBool("Affect Other Vehicles", Color.white, Prefs.AffectOtherVehicles.Value, (Action<bool>)delegate(bool value)
{
Prefs.AffectOtherVehicles.Value = value;
});
Hooking.OnSwitchAvatarPostfix += delegate
{
Il2CppArrayBase<Rigidbody> componentsInChildren = ((Component)Player.RigManager).GetComponentsInChildren<Rigidbody>();
float num = ((IEnumerable<Rigidbody>)componentsInChildren).Sum((Rigidbody i) => i.mass);
if (num != 0f)
{
playerRbs = Il2CppArrayBase<Rigidbody>.op_Implicit(componentsInChildren);
playerMass = num;
}
};
Hooking.OnLevelLoaded += delegate
{
goKarts.Clear();
};
}
}
public static class Prefs
{
public static MelonPreferences_Category Category { get; set; }
public static MelonPreferences_Entry<bool> Enabled { get; set; }
public static MelonPreferences_Entry<bool> Jumping { get; set; }
public static MelonPreferences_Entry<float> JumpForce { get; set; }
public static MelonPreferences_Entry<bool> WallClimbing { get; set; }
public static MelonPreferences_Entry<bool> AutoWallMount { get; set; }
public static MelonPreferences_Entry<float> InAirTurn { get; set; }
public static MelonPreferences_Entry<bool> AffectOtherVehicles { get; set; }
public static void LoadPrefs()
{
Category = MelonPreferences.CreateCategory("GravityKart");
Enabled = Category.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
Jumping = Category.CreateEntry<bool>("Jumping", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
JumpForce = Category.CreateEntry<float>("JumpForceMultiplier", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
WallClimbing = Category.CreateEntry<bool>("WallClimbing", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
AutoWallMount = Category.CreateEntry<bool>("AutoWallMount", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
InAirTurn = Category.CreateEntry<float>("In-AirRotationSpeed", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
AffectOtherVehicles = Category.CreateEntry<bool>("AffectOtherVehicles", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
}
}