Decompiled source of StatMultiplier v1.4.0

StatMultiplier.dll

Decompiled 3 weeks ago
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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
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("GeneralMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GeneralMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("96629134-eb8c-4fef-b686-c7f1ca5c70c6")]
[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")]
[BepInPlugin("com.reckss.erenshor.statmultiplier", "Erenshor Stat & Combat Tweaks", "1.4.0")]
public class StatMultiplierPlugin : BaseUnityPlugin
{
	private static ConfigEntry<float> StrMultiplier;

	private static ConfigEntry<float> EndMultiplier;

	private static ConfigEntry<float> DexMultiplier;

	private static ConfigEntry<float> AgiMultiplier;

	private static ConfigEntry<float> IntMultiplier;

	private static ConfigEntry<float> WisMultiplier;

	private static ConfigEntry<float> ChaMultiplier;

	private static ConfigEntry<float> ResMultiplier;

	private static ConfigEntry<float> MaxHPMultiplier;

	private static ConfigEntry<float> MaxManaMultiplier;

	private static ConfigEntry<float> ACMultiplier;

	private static ConfigEntry<float> MRMultiplier;

	private static ConfigEntry<float> ERMultiplier;

	private static ConfigEntry<float> PRMultiplier;

	private static ConfigEntry<float> VRMultiplier;

	private static ConfigEntry<float> TwoHandedDamageMultiplier;

	private static readonly FieldInfo fStr = AccessTools.Field(typeof(Stats), "CurrentStr");

	private static readonly FieldInfo fEnd = AccessTools.Field(typeof(Stats), "CurrentEnd");

	private static readonly FieldInfo fDex = AccessTools.Field(typeof(Stats), "CurrentDex");

	private static readonly FieldInfo fAgi = AccessTools.Field(typeof(Stats), "CurrentAgi");

	private static readonly FieldInfo fInt = AccessTools.Field(typeof(Stats), "CurrentInt");

	private static readonly FieldInfo fWis = AccessTools.Field(typeof(Stats), "CurrentWis");

	private static readonly FieldInfo fCha = AccessTools.Field(typeof(Stats), "CurrentCha");

	private static readonly FieldInfo fRes = AccessTools.Field(typeof(Stats), "CurrentRes");

	private static readonly FieldInfo fMaxHP = AccessTools.Field(typeof(Stats), "CurrentMaxHP");

	private static readonly FieldInfo fMaxMana = AccessTools.Field(typeof(Stats), "CurrentMaxMana");

	private static readonly FieldInfo fAC = AccessTools.Field(typeof(Stats), "CurrentAC");

	private static readonly FieldInfo fMR = AccessTools.Field(typeof(Stats), "CurrentMR");

	private static readonly FieldInfo fER = AccessTools.Field(typeof(Stats), "CurrentER");

	private static readonly FieldInfo fPR = AccessTools.Field(typeof(Stats), "CurrentPR");

	private static readonly FieldInfo fVR = AccessTools.Field(typeof(Stats), "CurrentVR");

	private void Awake()
	{
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Expected O, but got Unknown
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Expected O, but got Unknown
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Expected O, but got Unknown
		StrMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "Strength", 1f, "Strength multiplier");
		EndMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "Endurance", 1f, "Endurance multiplier");
		DexMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "Dexterity", 1f, "Dexterity multiplier");
		AgiMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "Agility", 1f, "Agility multiplier");
		IntMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "Intelligence", 1f, "Intelligence multiplier");
		WisMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "Wisdom", 1f, "Wisdom multiplier");
		ChaMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "Charisma", 1f, "Charisma multiplier");
		ResMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "Resistance", 1f, "Resistance multiplier");
		MaxHPMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "MaxHP", 1f, "Max HP multiplier");
		MaxManaMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "MaxMana", 1f, "Max Mana multiplier");
		ACMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "ArmorClass", 1f, "Armor Class multiplier");
		MRMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "MagicResist", 1f, "Magic Resist multiplier");
		ERMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "ElementResist", 1f, "Elemental Resist multiplier");
		PRMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "PhysicalResist", 1f, "Physical Resist multiplier");
		VRMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Multipliers", "VoidResist", 1f, "Void Resist multiplier");
		TwoHandedDamageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "TwoHandedDamageMultiplier", 1.5f, "Multiplier for two-handed auto-attack damage (replaces hard-coded 1.5×).");
		Harmony val = new Harmony("com.reckss.erenshor.statmultiplier");
		val.Patch((MethodBase)AccessTools.Method(typeof(Stats), "CalcStats", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(StatMultiplierPlugin), "CalcStats_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(PlayerCombat), "DoAuto", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(StatMultiplierPlugin), "DoAuto_Transpiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static void CalcStats_Postfix(Stats __instance)
	{
		if ((Object)(object)__instance.Myself != (Object)null && !__instance.Myself.isNPC && ((Object)((Component)__instance.Myself).transform).name == "Player")
		{
			Mul(fStr, StrMultiplier.Value);
			Mul(fEnd, EndMultiplier.Value);
			Mul(fDex, DexMultiplier.Value);
			Mul(fAgi, AgiMultiplier.Value);
			Mul(fInt, IntMultiplier.Value);
			Mul(fWis, WisMultiplier.Value);
			Mul(fCha, ChaMultiplier.Value);
			Mul(fRes, ResMultiplier.Value);
			Mul(fMaxHP, MaxHPMultiplier.Value);
			Mul(fMaxMana, MaxManaMultiplier.Value);
			Mul(fAC, ACMultiplier.Value);
			Mul(fMR, MRMultiplier.Value);
			Mul(fER, ERMultiplier.Value);
			Mul(fPR, PRMultiplier.Value);
			Mul(fVR, VRMultiplier.Value);
		}
		void Mul(FieldInfo fi, float m)
		{
			int num = (int)fi.GetValue(__instance);
			fi.SetValue(__instance, Mathf.RoundToInt((float)num * m));
		}
	}

	public static IEnumerable<CodeInstruction> DoAuto_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		FieldInfo operand = AccessTools.Field(typeof(StatMultiplierPlugin), "TwoHandedDamageMultiplier");
		MethodInfo getMethod = AccessTools.Property(typeof(ConfigEntry<float>), "Value").GetGetMethod();
		for (int i = 0; i < list.Count; i++)
		{
			CodeInstruction val = list[i];
			if (val.opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)val.operand, 1.5f))
			{
				val.opcode = OpCodes.Ldsfld;
				val.operand = operand;
				list.Insert(i + 1, new CodeInstruction(OpCodes.Callvirt, (object)getMethod));
				i++;
			}
		}
		return list.AsEnumerable();
	}
}