Decompiled source of SlimViking v1.0.0

Plugins/SlimViking.dll

Decompiled 2 days ago
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 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("SlimViking")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SlimViking")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("87483ae2-7913-4cce-9054-48613de658a7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MyBepInExPlugin;

[BepInPlugin("com.Durinson.SlimViking", "Slim viking", "1.0.0")]
public class Main : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "Awake")]
	public static class PlayerAwakePatch
	{
		private static void Postfix(Player __instance)
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			FieldInfo field = typeof(Character).GetField("m_collider", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field == null)
			{
				logger.LogWarning((object)"Could not find m_collider field");
				return;
			}
			object? value = field.GetValue(__instance);
			CapsuleCollider val = (CapsuleCollider)((value is CapsuleCollider) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				logger.LogWarning((object)"Collider was null");
				return;
			}
			float num = ColliderRadius.Value;
			float value2 = ColliderHeight.Value;
			float num2 = value2 / 2f - 0.01f;
			if (num >= num2)
			{
				logger.LogWarning((object)$"Radius {num} is too large for height {value2}. Clamping.");
				num = num2;
			}
			val.radius = num;
			val.height = value2;
			val.center = new Vector3(0f, val.height / 2f, 0f);
		}
	}

	private const string pluginGUID = "com.Durinson.SlimViking";

	private const string pluginName = "Slim viking";

	private const string pluginVersion = "1.0.0";

	private readonly Harmony HarmonyInstance = new Harmony("com.Durinson.SlimViking");

	public static ManualLogSource logger = Logger.CreateLogSource("Slim viking");

	public static ConfigEntry<float> ColliderRadius;

	public static ConfigEntry<float> ColliderHeight;

	public void Awake()
	{
		logger.LogInfo((object)"Slim viking loaded");
		ColliderRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Collider", "Radius", 0.2f, "Player capsule collider radius");
		ColliderHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Collider", "Height", 1.85f, "Player capsule collider height");
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		HarmonyInstance.PatchAll(executingAssembly);
	}
}