using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalPhysics.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LethalPhysics")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalPhysics")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("94f05109-45d5-4285-857d-e26079d71719")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LethalPhysics
{
[BepInPlugin("jacobot5.LethalPhysics", "LethalPhysics", "1.2.0")]
public class LethalPhysicsMod : BaseUnityPlugin
{
private const string modGUID = "jacobot5.LethalPhysics";
private const string modName = "LethalPhysics";
private const string modVersion = "1.2.0";
public static ConfigEntry<bool> configGravityOnMoons;
public static ConfigEntry<float> configMoonGravityLevel;
public static ConfigEntry<float> configShotgunKnockback;
private readonly Harmony harmony = new Harmony("jacobot5.LethalPhysics");
private static LethalPhysicsMod Instance;
public static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("jacobot5.LethalPhysics");
mls.LogInfo((object)"LethalPhysics has awoken.");
configGravityOnMoons = ((BaseUnityPlugin)this).Config.Bind<bool>("General.Toggles", "GravityOnMoons", true, "Whether or not to enable gravity on moons.");
configMoonGravityLevel = ((BaseUnityPlugin)this).Config.Bind<float>("General.Toggles", "MoonGravityLevel", 5f, "Moon gravity constant. 5 is default. Only applies when GravityOnMoons = true. Not recommended to set to 0; use GravityOnMoons = false instead.");
configShotgunKnockback = ((BaseUnityPlugin)this).Config.Bind<float>("General.Toggles", "ShotgunKnockback", 8f, "How much knockback is applied when player shoots the Shotgun in zero gravity. Default 8.");
harmony.PatchAll(typeof(LethalPhysicsMod));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(GrabbableObjectPatch));
harmony.PatchAll(typeof(ShotgunItemPatch));
}
}
}
namespace LethalPhysics.Patches
{
[HarmonyPatch(typeof(GrabbableObject))]
internal class GrabbableObjectPatch
{
[HarmonyPatch("FallWithCurve")]
[HarmonyPrefix]
private static bool ItemZeroGravityPatch()
{
StartOfRound instance = StartOfRound.Instance;
if ((instance != null && instance.inShipPhase) || !LethalPhysicsMod.configGravityOnMoons.Value)
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
private static float gravityConstant = -0.15f;
private static float jumpVelocityThreshhold = 0.05f;
private static float velocityThreshhold = 0.1f;
private static float maxExternalForces = 4.7f;
private static float flyAwayBounds = 200f;
private static float maxJumpFallValue = 4.2f;
private static Vector3 homePos = new Vector3(3.866463f, 0f, -14.225f);
private static Vector3 savedExternalForces;
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static bool NewtonsFirstLaw(PlayerControllerB __instance)
{
//IL_0001: 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)
savedExternalForces = __instance.externalForces;
if (__instance.externalForces.x >= maxExternalForces)
{
savedExternalForces.x = maxExternalForces;
}
if (__instance.externalForces.x <= 0f - maxExternalForces)
{
savedExternalForces.x = 0f - maxExternalForces;
}
if (__instance.externalForces.y >= maxExternalForces)
{
savedExternalForces.y = maxExternalForces;
}
if (__instance.externalForces.y <= 0f - maxExternalForces)
{
savedExternalForces.y = 0f - maxExternalForces;
}
if (__instance.externalForces.z >= maxExternalForces)
{
savedExternalForces.z = maxExternalForces;
}
if (__instance.externalForces.z <= 0f - maxExternalForces)
{
savedExternalForces.z = 0f - maxExternalForces;
}
return true;
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void PlayerZeroGravityPatch(PlayerControllerB __instance)
{
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: 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_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: 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_011c: 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_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: 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_0146: Unknown result type (might be due to invalid IL or missing references)
bool flag = StartOfRound.Instance?.inShipPhase ?? false;
FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerControllerB), "isFallingFromJump");
bool flag2 = false;
if (fieldInfo != null)
{
flag2 = (bool)fieldInfo.GetValue(__instance);
}
FieldInfo fieldInfo2 = AccessTools.Field(typeof(PlayerControllerB), "isJumping");
bool flag3 = false;
if (fieldInfo2 != null)
{
flag3 = (bool)fieldInfo2.GetValue(__instance);
}
if (flag || !LethalPhysicsMod.configGravityOnMoons.Value)
{
if (flag2)
{
if (__instance.jetpackControls || (__instance.thisController.velocity.y >= 0f - jumpVelocityThreshhold && __instance.thisController.velocity.y <= jumpVelocityThreshhold))
{
fieldInfo.SetValue(__instance, false);
}
__instance.fallValue = maxJumpFallValue;
}
else
{
__instance.fallValue = gravityConstant;
}
__instance.takingFallDamage = false;
Vector3 val = __instance.thisController.velocity;
if (((Vector3)(ref val)).magnitude <= velocityThreshhold || __instance.thisController.isGrounded)
{
__instance.externalForces = Vector3.zero;
}
else
{
__instance.externalForces = savedExternalForces;
}
if (((Component)__instance.thisController).transform.position.y > flyAwayBounds)
{
if (flag)
{
__instance.TeleportPlayer(homePos, false, 0f, false, true);
return;
}
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
Vector3 zero = Vector3.zero;
val = default(Vector3);
localPlayerController.KillPlayer(zero, true, (CauseOfDeath)0, 0, val);
}
}
else if (LethalPhysicsMod.configMoonGravityLevel.Value != 5f)
{
if (flag3)
{
__instance.fallValue = 25f / LethalPhysicsMod.configMoonGravityLevel.Value;
}
if (flag2)
{
__instance.fallValue -= Time.deltaTime;
}
}
}
}
[HarmonyPatch(typeof(ShotgunItem))]
internal class ShotgunItemPatch
{
[HarmonyPatch("ItemActivate")]
[HarmonyPostfix]
private static void KnockbackPatch(ShotgunItem __instance)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: 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)
StartOfRound instance = StartOfRound.Instance;
if (((instance != null && instance.inShipPhase) || !LethalPhysicsMod.configGravityOnMoons.Value) && (Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController && !__instance.safetyOn)
{
PlayerControllerB playerHeldBy = ((GrabbableObject)__instance).playerHeldBy;
playerHeldBy.externalForces += ((Component)__instance).transform.forward * (0f - LethalPhysicsMod.configShotgunKnockback.Value);
}
}
}
}