using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("PlayerHeightandWeight.Tests")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("PlayerHeightandWeight")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PlayerHeightandWeight")]
[assembly: AssemblyTitle("PlayerHeightandWeight")]
[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 PlayerHeightandWeight
{
internal sealed class ConfigurationManagerAttributes
{
public bool? ShowRangeAsPercent;
public bool? HideDefaultButton;
public int? Order;
public Action<ConfigEntryBase> CustomDrawer;
}
internal sealed class HeightRange : AcceptableValueRange<float>
{
internal HeightRange()
: base(0.4f, 5f)
{
}
public override object Clamp(object value)
{
float num = (float)value;
if (float.IsNaN(num) || float.IsInfinity(num))
{
return 1.1f;
}
return (float)Math.Round((float)base.Clamp((object)num), 2, MidpointRounding.AwayFromZero);
}
}
[BepInPlugin("DogEggz.PlayerHeightandWeight", "Player Height and Weight", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
public const string Guid = "DogEggz.PlayerHeightandWeight";
public const string Name = "Player Height and Weight";
public const string Version = "1.0.0";
internal static Plugin Instance;
internal static ManualLogSource Log;
internal static volatile int CurrentWeight = 160;
internal static bool WeightPatched;
internal ConfigEntry<float> StandingHeight;
internal ConfigEntry<int> Weight;
internal readonly CompanionMods Companions = new CompanionMods();
private readonly CollisionHeight collision = new CollisionHeight();
private readonly CameraHeight camera = new CameraHeight();
private Harmony harmony;
private volatile bool refreshWeight;
private volatile bool runtimeEnabled = true;
private bool crouching;
internal string Status = "Waiting for the player.";
internal bool OwnsHeight
{
get
{
if (((Behaviour)this).isActiveAndEnabled)
{
return Companions.HeightSupported;
}
return false;
}
}
private bool NormalMovement
{
get
{
if (GameState.playing && !GameState.currentlyLoading && Object.op_Implicit((Object)(object)Refs.charController) && ((Collider)Refs.charController).enabled && !Object.op_Implicit((Object)(object)GameState.inBed) && !GameState.sleeping && !GameState.recovering && !Object.op_Implicit((Object)(object)GameState.currentShipyard))
{
return !Companions.ModelHoldsControl();
}
return false;
}
}
private void Awake()
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Expected O, but got Unknown
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Expected O, but got Unknown
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Expected O, but got Unknown
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Expected O, but got Unknown
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
StandingHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Standing collision height", 1.1f, new ConfigDescription("Movement capsule height, 0.40–5.00 game units. Default 1.10. First-person camera follows applied height; feet stay fixed and the model is not resized. Growth waits for clearance. NANDTweaks crouching is preserved.", (AcceptableValueBase)(object)new HeightRange(), new object[1]
{
new ConfigurationManagerAttributes
{
ShowRangeAsPercent = false,
Order = 3
}
}));
Weight = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Player weight (pounds)", 160, new ConfigDescription("Player weight aboard the occupied boat, including its effect on boat balance. Default 160. Applies live. Does not change jumping or Player Model ragdoll masses.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), new object[1]
{
new ConfigurationManagerAttributes
{
ShowRangeAsPercent = false,
Order = 2
}
}));
((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Collision status", "", new ConfigDescription("Shows the actual applied height, including clearance or compatibility delays.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
Order = 1,
HideDefaultButton = true,
CustomDrawer = delegate
{
GUILayout.Label(Status, Array.Empty<GUILayoutOption>());
}
}
}));
Weight.SettingChanged += WeightChanged;
CurrentWeight = Weight.Value;
harmony = new Harmony("DogEggz.PlayerHeightandWeight");
try
{
Companions.Initialize(harmony);
harmony.PatchAll(Assembly.GetExecutingAssembly());
((BaseUnityPlugin)this).Logger.LogInfo((object)("Player Height and Weight 1.0.0 loaded. Height support: " + Companions.HeightSupported + "; weight patch: " + WeightPatched));
}
catch (Exception ex)
{
harmony.UnpatchSelf();
Companions.HeightSupported = false;
Companions.Failure = "Patch initialization failed; check the BepInEx log.";
CurrentWeight = 160;
((BaseUnityPlugin)this).Logger.LogError((object)ex);
}
refreshWeight = true;
}
private void OnEnable()
{
runtimeEnabled = true;
if (Weight != null)
{
CurrentWeight = Weight.Value;
refreshWeight = true;
}
}
private void WeightChanged(object sender, EventArgs args)
{
refreshWeight = true;
}
private void Update()
{
if (!Companions.HeightSupported)
{
Status = Companions.Failure;
}
else
{
ApplyHeight();
}
if (!OwnsHeight || !NormalMovement || BoatCamera.on)
{
camera.Restore();
}
if (refreshWeight && GameState.playing && !GameState.currentlyLoading)
{
refreshWeight = false;
CurrentWeight = (runtimeEnabled ? Weight.Value : 160);
RefreshOccupiedBoat();
}
}
internal void ReadCrouch(bool value)
{
crouching = value;
ApplyHeight();
}
internal void ApplyCamera(HeadBob bob, PlayerCrouching stance)
{
if (!((Object)(object)((Component)bob).transform != (Object)(object)Refs.ovrCameraRig))
{
if (!OwnsHeight || !NormalMovement || BoatCamera.on || !Object.op_Implicit((Object)(object)stance))
{
camera.Restore();
return;
}
ApplyHeight();
camera.Apply(((Component)bob).transform, stance, Refs.charController, collision, Companions.NandCrouchEnabled);
}
}
internal void ApplyHeight()
{
if (OwnsHeight)
{
collision.Capture(Refs.charController);
if (!GameState.playing || GameState.currentlyLoading || !Object.op_Implicit((Object)(object)Refs.charController))
{
Status = "Waiting for the player.";
return;
}
if (!NormalMovement)
{
Status = collision.AppliedText + " — waiting for normal movement.";
return;
}
bool flag = crouching && Companions.NandCrouchEnabled;
bool flag2 = collision.Apply(StandingHeight.Value, flag);
Status = collision.AppliedText + ((!flag2) ? " — waiting for overhead clearance." : (flag ? " (crouching)" : ""));
}
}
private static void RefreshOccupiedBoat()
{
if (Object.op_Implicit((Object)(object)GameState.currentBoat) && Object.op_Implicit((Object)(object)GameState.currentBoat.parent))
{
BoatMass component = ((Component)GameState.currentBoat.parent).GetComponent<BoatMass>();
if (Object.op_Implicit((Object)(object)component))
{
component.UpdateMass();
}
}
}
private void OnDisable()
{
runtimeEnabled = false;
CurrentWeight = 160;
camera.Restore();
collision.Restore();
if (GameState.playing && !GameState.currentlyLoading)
{
RefreshOccupiedBoat();
}
}
private void OnDestroy()
{
if (Weight != null)
{
Weight.SettingChanged -= WeightChanged;
}
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
camera.Restore();
collision.Restore();
CurrentWeight = 160;
Instance = null;
}
}
[HarmonyPatch(typeof(PlayerCrouching), "Update")]
internal static class CrouchStatePatch
{
[HarmonyAfter(new string[] { "com.nandbrew.nandtweaks" })]
private static void Postfix(PlayerCrouching __instance, bool ___crouching)
{
if ((Object)(object)((Component)__instance).transform == (Object)(object)Refs.ovrCameraRig)
{
Plugin.Instance?.ReadCrouch(___crouching);
}
}
}
[HarmonyPatch(typeof(HeadBob), "Update")]
internal static class CameraHeightPatch
{
[HarmonyAfter(new string[] { "com.nandbrew.nandtweaks", "com.diamondminer99.playermodel" })]
private static void Postfix(HeadBob __instance, PlayerCrouching ___crouching)
{
Plugin.Instance?.ApplyCamera(__instance, ___crouching);
}
}
[HarmonyPatch(typeof(OVRPlayerController), "UpdateController")]
internal static class BeforeMovementPatch
{
private static void Prefix(OVRPlayerController __instance)
{
if (Object.op_Implicit((Object)(object)Refs.charController) && (Object)(object)((Component)__instance).gameObject == (Object)(object)((Component)Refs.charController).gameObject)
{
Plugin.Instance?.ApplyHeight();
}
}
}
internal static class HeightGeometry
{
internal static float Target(float standing, float radius, float originalStep, bool crouching)
{
if (float.IsNaN(standing) || float.IsInfinity(standing))
{
standing = 1.1f;
}
standing = Math.Max(0.4f, Math.Min(5f, standing));
float val = (crouching ? Math.Min(standing, Math.Max(0.5f, originalStep + 0.1f)) : standing);
return Math.Max(radius * 2f, val);
}
internal static float CenterY(float originalCenter, float originalHeight, float height)
{
return originalCenter + (height - originalHeight) * 0.5f;
}
internal static float Step(float originalStep, float height)
{
return Math.Min(originalStep, height * 0.5f);
}
}
internal sealed class CollisionHeight
{
private CharacterController controller;
private float originalHeight;
private Vector3 originalCenter;
private float originalStep;
private readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[32];
internal float OriginalHeight => originalHeight;
internal float OriginalCrouchHeight => Math.Max(0.5f, originalStep + 0.1f);
internal float AcceptedStandingHeight { get; private set; }
internal bool GrowthBlocked { get; private set; }
internal float AppliedHeight
{
get
{
if (!Object.op_Implicit((Object)(object)controller))
{
return originalHeight;
}
return controller.height;
}
}
internal float FeetGap => originalHeight * 0.5f - originalCenter.y;
internal string AppliedText
{
get
{
if (!Object.op_Implicit((Object)(object)controller))
{
return "Waiting for the player.";
}
return "Applied collision height: " + controller.height.ToString("F2");
}
}
internal unsafe void Capture(CharacterController value)
{
//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_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)
if ((Object)(object)controller == (Object)(object)value)
{
return;
}
Restore();
controller = value;
if (Object.op_Implicit((Object)(object)controller))
{
originalHeight = controller.height;
originalCenter = controller.center;
originalStep = controller.stepOffset;
AcceptedStandingHeight = originalHeight;
GrowthBlocked = false;
ManualLogSource log = Plugin.Log;
if (log != null)
{
string[] obj = new string[6]
{
"Captured player capsule: height=",
originalHeight.ToString(),
", center=",
null,
null,
null
};
Vector3 val = originalCenter;
obj[3] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
obj[4] = ", step=";
obj[5] = originalStep.ToString();
log.LogInfo((object)string.Concat(obj));
}
}
}
internal bool Apply(float standing, bool crouching)
{
//IL_005a: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: 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)
if (!Object.op_Implicit((Object)(object)controller))
{
return false;
}
float num = HeightGeometry.Target(standing, controller.radius, originalStep, crouching);
GrowthBlocked = num > controller.height + 0.0001f && !CanGrow(num);
if (GrowthBlocked)
{
return false;
}
Vector3 val = originalCenter;
val.y = HeightGeometry.CenterY(originalCenter.y, originalHeight, num);
float num2 = HeightGeometry.Step(originalStep, num);
if (!Mathf.Approximately(controller.stepOffset, num2))
{
controller.stepOffset = num2;
}
if (!Mathf.Approximately(controller.height, num))
{
controller.height = num;
}
Vector3 val2 = controller.center - val;
if (((Vector3)(ref val2)).sqrMagnitude > 1E-08f)
{
controller.center = val;
}
float val3 = HeightGeometry.Target(standing, controller.radius, originalStep, crouching: false);
AcceptedStandingHeight = (crouching ? Math.Min(AcceptedStandingHeight, val3) : controller.height);
return true;
}
private bool CanGrow(float height)
{
//IL_000d: 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_002a: 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_0048: 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_0056: 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_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
Transform transform = ((Component)controller).transform;
Vector3 lossyScale = transform.lossyScale;
float num = Mathf.Abs(lossyScale.y);
float num2 = controller.radius * Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Abs(lossyScale.z));
Vector3 up = transform.up;
Vector3 val = transform.TransformPoint(controller.center) + up * Mathf.Max(0f, controller.height * num * 0.5f - num2);
float num3 = Mathf.Max(0.01f, num2 - controller.skinWidth * Mathf.Max(num, 1f));
int num4 = 0;
for (int i = 0; i < 32; i++)
{
if (!Physics.GetIgnoreLayerCollision(((Component)transform).gameObject.layer, i))
{
num4 |= 1 << i;
}
}
int num5 = Physics.SphereCastNonAlloc(val, num3, up, hits, (height - controller.height) * num, num4, (QueryTriggerInteraction)1);
if (num5 == hits.Length)
{
return false;
}
for (int j = 0; j < num5; j++)
{
Collider collider = ((RaycastHit)(ref hits[j])).collider;
if (Object.op_Implicit((Object)(object)collider) && !((Object)(object)collider == (Object)(object)controller) && !((Component)collider).transform.IsChildOf(transform) && (!Object.op_Implicit((Object)(object)Refs.observerMirror) || !((Component)collider).transform.IsChildOf(((Component)Refs.observerMirror).transform)) && !Physics.GetIgnoreCollision((Collider)(object)controller, collider))
{
return false;
}
}
return true;
}
internal void Restore()
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)controller))
{
controller.stepOffset = Mathf.Min(originalStep, controller.height * 0.5f);
controller.height = originalHeight;
controller.center = originalCenter;
controller.stepOffset = originalStep;
AcceptedStandingHeight = originalHeight;
GrowthBlocked = false;
}
}
}
internal static class CameraGeometry
{
internal static float Baseline(float initialHead, float originalHeight, float standingHeight, float appliedHeight, float originalCrouch, bool nand, float head)
{
float num = initialHead * standingHeight / originalHeight;
float num2 = (nand ? 0.5f : 0.2f);
float val = (nand ? (0.5f * Math.Min(appliedHeight, Math.Min(standingHeight, originalCrouch)) / originalCrouch) : (0.2f * standingHeight / originalHeight));
val = Math.Min(num, val);
float num3 = ((initialHead > num2 + 0.0001f) ? Math.Max(0f, Math.Min(1f, (initialHead - head) / (initialHead - num2))) : 0f);
return num + (val - num) * num3;
}
internal static float WithBob(float baseline, float bob, float ratio, float floor)
{
return Math.Max(floor, baseline + bob * Math.Max(0f, Math.Min(1f, ratio)));
}
internal static float BlockedLimit(float initialHead, float originalHeight, float appliedHeight, float originalCrouch, bool nand)
{
return appliedHeight * Math.Max(initialHead / originalHeight, nand ? (0.5f / originalCrouch) : 0f);
}
}
internal sealed class CameraTransition
{
private bool initialized;
private bool blocked;
private bool recovering;
private float last;
internal float Apply(float target, bool growthBlocked, float deltaTime)
{
if (!initialized)
{
last = target;
initialized = true;
}
if (growthBlocked)
{
last = Math.Min(last, target);
blocked = true;
recovering = false;
}
else
{
if (blocked)
{
recovering = true;
blocked = false;
}
if (recovering && target > last + 0.001f)
{
last += (target - last) * Math.Max(0f, Math.Min(1f, deltaTime * 9f));
}
else
{
last = target;
recovering = false;
}
}
return last;
}
internal void Reset()
{
initialized = (blocked = (recovering = false));
last = 0f;
}
}
internal sealed class CameraHeight
{
private static readonly FieldRef<PlayerCrouching, float> InitialHead = AccessTools.FieldRefAccess<PlayerCrouching, float>("initialHeight");
private readonly CameraTransition transition = new CameraTransition();
private Transform rig;
private CharacterController controller;
private float initialHead;
private Vector3 lastRaw;
private Vector3 lastOutput;
private bool wrote;
internal void Apply(Transform target, PlayerCrouching stance, CharacterController owner, CollisionHeight collision, bool nand)
{
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: 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_0101: 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_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: 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)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)rig != (Object)(object)target || (Object)(object)controller != (Object)(object)owner)
{
Restore();
rig = target;
controller = owner;
initialHead = InitialHead.Invoke(stance);
}
if (!float.IsNaN(initialHead) && !float.IsInfinity(initialHead) && !(initialHead <= 0.2f) && !(collision.OriginalHeight <= 0f))
{
float currentHeadHeight = stance.GetCurrentHeadHeight();
Vector3 localPosition = target.localPosition;
float num = CameraGeometry.Baseline(initialHead, collision.OriginalHeight, collision.AcceptedStandingHeight, collision.AppliedHeight, collision.OriginalCrouchHeight, nand, currentHeadHeight);
if (collision.GrowthBlocked)
{
num = Math.Min(num, CameraGeometry.BlockedLimit(initialHead, collision.OriginalHeight, collision.AppliedHeight, collision.OriginalCrouchHeight, nand));
}
num = transition.Apply(num, collision.GrowthBlocked, Time.deltaTime);
Vector3 localPosition2 = localPosition;
localPosition2.y = CameraGeometry.WithBob(num, localPosition.y - currentHeadHeight, collision.AcceptedStandingHeight / collision.OriginalHeight, 0f - collision.FeetGap + 0.05f);
lastRaw = localPosition;
lastOutput = localPosition2;
wrote = true;
target.localPosition = localPosition2;
}
}
internal void Restore()
{
//IL_001b: 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_0026: 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_0041: Unknown result type (might be due to invalid IL or missing references)
if (wrote && Object.op_Implicit((Object)(object)rig))
{
Vector3 val = rig.localPosition - lastOutput;
if (((Vector3)(ref val)).sqrMagnitude < 1E-10f)
{
rig.localPosition = lastRaw;
}
}
wrote = false;
rig = null;
controller = null;
transition.Reset();
}
}
internal sealed class CompanionMods
{
internal const string NandGuid = "com.nandbrew.nandtweaks";
internal const string ModelGuid = "com.diamondminer99.playermodel";
internal bool HeightSupported = true;
internal string Failure;
private ConfigEntry<bool> nandCrouch;
private Func<bool> seated;
private Func<bool> downed;
private Func<bool> seatRising;
internal bool NandCrouchEnabled
{
get
{
if (nandCrouch != null)
{
return nandCrouch.Value;
}
return false;
}
}
internal void Initialize(Harmony harmony)
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Expected O, but got Unknown
if (Chainloader.PluginInfos.TryGetValue("com.nandbrew.nandtweaks", out var value))
{
Assembly assembly = ((object)value.Instance).GetType().Assembly;
MethodInfo methodInfo = FindNandColliderPatch(assembly, value.Metadata.Version);
nandCrouch = (assembly.GetType("NANDTweaks.Plugin")?.GetField("crouchPatch", BindingFlags.Static | BindingFlags.NonPublic))?.GetValue(null) as ConfigEntry<bool>;
if (methodInfo == null || nandCrouch == null)
{
Fail("Height override unavailable: unsupported NANDTweaks collider patch. Weight still works.");
return;
}
harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(CompanionMods), "NandColliderPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.Log.LogInfo((object)("NANDTweaks " + value.Metadata.Version?.ToString() + " collider adapter installed; camera clamp preserved."));
}
if (!Chainloader.PluginInfos.TryGetValue("com.diamondminer99.playermodel", out var value2))
{
return;
}
Assembly assembly2 = ((object)value2.Instance).GetType().Assembly;
Type type = assembly2.GetType("SailwindPlayerModel.Seating");
seated = Getter(type, "IsSeated");
downed = Getter(assembly2.GetType("SailwindPlayerModel.Downed"), "HoldsView");
MethodInfo instance = type?.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public)?.GetGetMethod();
FieldInfo rising = type?.GetField("_rising", BindingFlags.Instance | BindingFlags.NonPublic);
if (seated == null || downed == null || instance == null || rising == null)
{
Fail("Height override unavailable: unsupported Player Model control-state interface. Weight still works.");
return;
}
seatRising = delegate
{
object obj = instance.Invoke(null, null);
return obj != null && (bool)rising.GetValue(obj);
};
Plugin.Log.LogInfo((object)("Player Model " + value2.Metadata.Version?.ToString() + " seating/ragdoll guards installed."));
}
internal static MethodInfo FindNandColliderPatch(Assembly assembly, Version version)
{
if (version != new Version(1, 7, 5))
{
return null;
}
MethodInfo methodInfo = assembly.GetType("NANDTweaks.Patches.PlayerCrouchingPatch")?.GetMethod("Patch2", BindingFlags.Static | BindingFlags.Public);
ParameterInfo[] array = methodInfo?.GetParameters();
if (!(methodInfo != null) || !(methodInfo.ReturnType == typeof(void)) || array.Length != 2 || !(array[0].ParameterType == typeof(bool)) || !(array[1].ParameterType == typeof(float)))
{
return null;
}
return methodInfo;
}
private static Func<bool> Getter(Type type, string property)
{
MethodInfo methodInfo = type?.GetProperty(property, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetGetMethod(nonPublic: true);
if (!(methodInfo == null) && !(methodInfo.ReturnType != typeof(bool)))
{
return (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), methodInfo);
}
return null;
}
internal bool ModelHoldsControl()
{
Func<bool> func = seated;
if (func == null || !func())
{
Func<bool> func2 = downed;
if (func2 == null || !func2())
{
return seatRising?.Invoke() ?? false;
}
}
return true;
}
private void Fail(string message)
{
HeightSupported = false;
Failure = message;
Plugin.Log.LogWarning((object)message);
}
private static bool NandColliderPrefix()
{
if (!((Object)(object)Plugin.Instance == (Object)null))
{
return !Plugin.Instance.OwnsHeight;
}
return true;
}
}
[HarmonyPatch(typeof(BoatMass), "UpdateMass")]
internal static class PlayerWeightPatch
{
internal static float ReadWeight()
{
return Plugin.CurrentWeight;
}
internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> code = instructions.ToList();
int[] array = (from i in Enumerable.Range(0, code.Count)
where code[i].opcode == OpCodes.Ldc_R4 && code[i].operand is float num2 && num2 == 160f
select i).ToArray();
FieldInfo fieldInfo = AccessTools.Field(typeof(BoatMass), "selfMass");
if (array.Length != 2 || array[1] + 1 >= code.Count || array[1] != array[0] + 6 || code[array[0] + 1].opcode != OpCodes.Ldarg_0 || !CodeInstructionExtensions.LoadsField(code[array[0] + 2], fieldInfo, false) || code[array[0] + 3].opcode != OpCodes.Div || code[array[1] + 1].opcode != OpCodes.Add)
{
Plugin.WeightPatched = false;
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogError((object)"Player weight patch did not match BoatMass.UpdateMass; vanilla weight retained.");
}
return code;
}
MethodInfo operand = AccessTools.Method(typeof(PlayerWeightPatch), "ReadWeight", (Type[])null, (Type[])null);
int[] array2 = array;
foreach (int index in array2)
{
code[index].opcode = OpCodes.Call;
code[index].operand = operand;
}
Plugin.WeightPatched = true;
return code;
}
}
}