using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalPhysics.Patches;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalPhysics")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4b33d3d630846f08fff97bad5f84290a764a64a0")]
[assembly: AssemblyProduct("LethalPhysics")]
[assembly: AssemblyTitle("LethalPhysics")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class KickIfModNotInstalled
{
private static readonly string MOD_GUID = "com.jacobot5.LethalPhysics";
[HarmonyPostfix]
[HarmonyPatch("SetSingleton")]
private static void RegisterPrefab()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject(MOD_GUID + " Prefab");
((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
Object.DontDestroyOnLoad((Object)(object)val);
NetworkObject obj = val.AddComponent<NetworkObject>();
typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, GetHash(MOD_GUID));
NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
static uint GetHash(string value)
{
return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
}
}
}
namespace LethalPhysics
{
[BepInPlugin("com.jacobot5.LethalPhysics", "LethalPhysics", "2.1.0")]
public class LethalPhysicsMod : BaseUnityPlugin
{
public const string modGUID = "com.jacobot5.LethalPhysics";
public const string modName = "LethalPhysics";
public const string modVersion = "2.1.0";
public static ConfigEntry<bool> configGravityOnMoons;
public static ConfigEntry<float> configMoonGravityLevel;
public static ConfigEntry<float> configShotgunKnockback;
private readonly Harmony harmony = new Harmony("com.jacobot5.LethalPhysics");
private static LethalPhysicsMod Instance;
public static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("com.jacobot5.LethalPhysics");
mls.LogInfo((object)"LethalPhysics has awoken.");
configGravityOnMoons = ((BaseUnityPlugin)this).Config.Bind<bool>("Gravity", "GravityOnMoons", true, "Whether or not to enable gravity on moons.");
configMoonGravityLevel = ((BaseUnityPlugin)this).Config.Bind<float>("Gravity", "MoonGravityLevel", 5f, "Moon gravity constant. 5 is default. Only applies when GravityOnMoons = true. Not recommended to set to 0; use GravityOnMoons = false instead.");
harmony.PatchAll(typeof(LethalPhysicsMod));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(GrabbableObjectPatch));
harmony.PatchAll(typeof(KickIfModNotInstalled));
}
}
}
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_008f: 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_003a: 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_00b6: 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_00d3: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: 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_0118: 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)
bool flag = StartOfRound.Instance?.inShipPhase ?? false;
if (flag || !LethalPhysicsMod.configGravityOnMoons.Value)
{
if (__instance.isFallingFromJump)
{
if (__instance.jetpackControls || (__instance.thisController.velocity.y >= 0f - jumpVelocityThreshhold && __instance.thisController.velocity.y <= jumpVelocityThreshhold))
{
__instance.isFallingFromJump = 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 (__instance.isJumping)
{
__instance.fallValue = 25f / LethalPhysicsMod.configMoonGravityLevel.Value;
}
if (__instance.isFallingFromJump)
{
__instance.fallValue -= Time.deltaTime;
}
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}