Decompiled source of Realistic Body v1.0.1

RealisticBody.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RealisticBody")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RealisticBody")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0f5c5154-f645-43db-a07d-8790e1a6695c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RealisticBody;

public class BodyState
{
	public float legThickness;

	public float upperSpineSize;

	public float neckSize;

	public Vector3 twoHandedOffset;

	public Vector3 oneHandedOffset;

	public Vector3 shieldOffset;

	public Vector3 atgeirOffset;

	public static BodyState Modified = new BodyState(0.3f, 2f, 0.5f, new Vector3(0.004f, 0.007f, -0.0045f), new Vector3(0.004f, 0.007f, -0.0045f), new Vector3(-0.0002f, 0.0002f, -0.005f), new Vector3(0.0017f, -0.0045f, -0.0045f));

	public static BodyState Default = new BodyState(1f, 1f, 1f, Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero);

	public BodyState(float legThickness, float upperSpineSize, float neckSize, Vector3 twoHandedOffset, Vector3 oneHandedOffset, Vector3 shieldOffset, Vector3 atgeirOffset)
	{
		//IL_001e: 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)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		this.legThickness = legThickness;
		this.upperSpineSize = upperSpineSize;
		this.neckSize = neckSize;
		this.twoHandedOffset = twoHandedOffset;
		this.oneHandedOffset = oneHandedOffset;
		this.shieldOffset = shieldOffset;
		this.atgeirOffset = atgeirOffset;
	}

	public static BodyState GetBodyState(Player player)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: 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_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
		Transform val = ((Component)player).transform.Find("Visual/Armature/Hips");
		Transform val2 = val.Find("LeftUpLeg");
		Transform val3 = val.Find("RightUpLeg");
		Transform val4 = val.Find("Spine/Spine1/Spine2");
		Transform val5 = val.Find("Spine/Spine1/Spine2/Neck");
		Transform val6 = val.Find("Spine/Spine1/BackTwohanded_attach");
		Transform val7 = val.Find("Spine/Spine1/BackOneHanded_attach");
		Transform val8 = val.Find("Spine/Spine1/BackShield_attach");
		Transform val9 = val.Find("Spine/Spine1/BackAtgeir_attach");
		return new BodyState(val2.localScale.x, val4.localScale.x, val5.localScale.x, val6.localPosition, val7.localPosition, val8.localPosition, val9.localPosition);
	}

	public static void SetBodyState(Player player, BodyState bodyState)
	{
		//IL_0089: 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_00bd: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: 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_00ff: 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)
		Transform val = ((Component)player).transform.Find("Visual/Armature/Hips");
		Transform val2 = val.Find("LeftUpLeg");
		Transform val3 = val.Find("RightUpLeg");
		Transform val4 = val.Find("Spine/Spine1/Spine2");
		Transform val5 = val.Find("Spine/Spine1/Spine2/Neck");
		Transform val6 = val.Find("Spine/Spine1/BackTwohanded_attach");
		Transform val7 = val.Find("Spine/Spine1/BackOneHanded_attach");
		Transform val8 = val.Find("Spine/Spine1/BackShield_attach");
		Transform val9 = val.Find("Spine/Spine1/BackAtgeir_attach");
		val2.localScale = new Vector3(bodyState.legThickness, 1f, bodyState.legThickness);
		val3.localScale = new Vector3(bodyState.legThickness, 1f, bodyState.legThickness);
		val4.localScale = Vector3.one * bodyState.upperSpineSize;
		val5.localScale = Vector3.one * bodyState.neckSize;
		val6.localPosition = bodyState.twoHandedOffset;
		val7.localPosition = bodyState.oneHandedOffset;
		val8.localPosition = bodyState.shieldOffset;
		val9.localPosition = bodyState.atgeirOffset;
	}

	public override bool Equals(object obj)
	{
		//IL_003c: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		return obj is BodyState bodyState && legThickness == bodyState.legThickness && upperSpineSize == bodyState.upperSpineSize && neckSize == bodyState.neckSize && ((Vector3)(ref twoHandedOffset)).Equals(bodyState.twoHandedOffset) && ((Vector3)(ref oneHandedOffset)).Equals(bodyState.oneHandedOffset) && ((Vector3)(ref shieldOffset)).Equals(bodyState.shieldOffset) && ((Vector3)(ref atgeirOffset)).Equals(bodyState.atgeirOffset);
	}
}
[BepInPlugin("VilemMakovicka.RealisticBody", "RealisticBody", "1.0")]
[BepInProcess("valheim.exe")]
public class RealisticBody : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "OnEnable")]
	public static class MyValheimComponent_OnEnable_Patch
	{
		[HarmonyPostfix]
		public static void Postfix(Player __instance)
		{
			try
			{
				BodyState.Default = BodyState.GetBodyState(__instance);
			}
			catch (Exception ex)
			{
				Debug.LogError((object)ex.Message);
			}
			try
			{
				BodyState.SetBodyState(__instance, BodyState.Modified);
			}
			catch (Exception ex2)
			{
				Debug.LogError((object)ex2.Message);
			}
		}
	}

	[HarmonyPatch(typeof(Player), "Update")]
	public static class MyValheimComponent_Update_Patch
	{
		[HarmonyPostfix]
		public static void Postfix(Player __instance)
		{
			if (UnityInput.Current.GetKeyDown((KeyCode)117))
			{
				BodyState.SetBodyState(__instance, BodyState.GetBodyState(__instance).Equals(BodyState.Default) ? BodyState.Modified : BodyState.Default);
				Debug.Log((object)"Changing player state");
			}
		}
	}

	private readonly Harmony harmony = new Harmony("VilemMakovicka.RealisticBody");

	private void Awake()
	{
		try
		{
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogMessage((object)"Patched successfully.");
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)$"Failed to patch! => {arg}");
		}
	}
}