Decompiled source of BiomeScaling v1.1.1

plugins/gaakrin.biomescaling/BiomeScaling.dll

Decompiled a day ago
using System.Collections.Generic;
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("Biome Scaling")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Biome Scaling")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("64c3046c-52a6-4407-a8e6-c25981f4a465")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("gaakrin.biomescaling", "Biome Scaling", "1.1.1")]
public class BiomeScaling : BaseUnityPlugin
{
	public static Dictionary<Biome, BiomeLimits> Limits;

	private void Awake()
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Expected O, but got Unknown
		Limits = new Dictionary<Biome, BiomeLimits>
		{
			{
				(Biome)1,
				new BiomeLimits(24f)
			},
			{
				(Biome)8,
				new BiomeLimits(42f)
			},
			{
				(Biome)2,
				new BiomeLimits(60f)
			},
			{
				(Biome)4,
				new BiomeLimits(78f)
			},
			{
				(Biome)16,
				new BiomeLimits(96f)
			},
			{
				(Biome)512,
				new BiomeLimits(114f)
			}
		};
		Harmony val = new Harmony("gaakrin.biomescaling");
		val.PatchAll();
	}
}
public static class BiomeHpLimits
{
	public static readonly Dictionary<Biome, float> MaxHpByBiome = new Dictionary<Biome, float>
	{
		{
			(Biome)1,
			115f
		},
		{
			(Biome)8,
			145f
		},
		{
			(Biome)2,
			175f
		},
		{
			(Biome)4,
			195f
		},
		{
			(Biome)16,
			250f
		},
		{
			(Biome)512,
			270f
		}
	};
}
public static class BiomeDamageScaling
{
	public static readonly Dictionary<Biome, List<DamageTier>> BiomeTiers = new Dictionary<Biome, List<DamageTier>>
	{
		{
			(Biome)1,
			new List<DamageTier>
			{
				new DamageTier(30f)
			}
		},
		{
			(Biome)8,
			new List<DamageTier>
			{
				new DamageTier(50f)
			}
		},
		{
			(Biome)2,
			new List<DamageTier>
			{
				new DamageTier(75f)
			}
		},
		{
			(Biome)4,
			new List<DamageTier>
			{
				new DamageTier(100f)
			}
		},
		{
			(Biome)16,
			new List<DamageTier>
			{
				new DamageTier(125f)
			}
		},
		{
			(Biome)512,
			new List<DamageTier>
			{
				new DamageTier(150f)
			}
		}
	};

	public static float GetWeapon(Biome biome, float weaponDamage)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (!BiomeTiers.TryGetValue(biome, out var value))
		{
			return weaponDamage;
		}
		foreach (DamageTier item in value)
		{
			if (weaponDamage >= item.damageLimit)
			{
				return item.damageLimit;
			}
		}
		return weaponDamage;
	}
}
public class BiomeLimits
{
	public float maxArmor;

	public BiomeLimits(float armor)
	{
		maxArmor = armor;
	}
}
public class DamageTier
{
	public float damageLimit;

	public DamageTier(float limit)
	{
		damageLimit = limit;
	}
}
public static class EventHelper
{
	public static bool IsNearBase(Player player)
	{
		int value = Traverse.Create((object)player).Field("m_baseValue").GetValue<int>();
		return value >= 3;
	}
}
[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
public static class OnAttackTrigger
{
	[HarmonyPrefix]
	public static void Prefix(Attack __instance)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		Humanoid value = Traverse.Create((object)__instance).Field("m_character").GetValue<Humanoid>();
		Player val = (Player)(object)((value is Player) ? value : null);
		if ((Object)(object)val == (Object)null || EventHelper.IsNearBase(val))
		{
			return;
		}
		ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
		if (currentWeapon == null)
		{
			return;
		}
		Biome currentBiome = val.GetCurrentBiome();
		if (BiomeDamageScaling.BiomeTiers.TryGetValue(currentBiome, out var _))
		{
			float totalDamage = ((DamageTypes)(ref currentWeapon.m_shared.m_damages)).GetTotalDamage();
			float weapon = BiomeDamageScaling.GetWeapon(currentBiome, totalDamage);
			if (totalDamage > weapon)
			{
				float num = weapon / totalDamage;
				__instance.m_damageMultiplier *= num;
				__instance.m_forceMultiplier *= num;
				__instance.m_staggerMultiplier *= num;
				__instance.m_attackHitNoise *= num;
			}
		}
	}
}
[HarmonyPatch(typeof(Player), "UpdateFood")]
public static class PlayerHealth_UpdateFood
{
	private static void Postfix(Player __instance)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)__instance == (Object)null) && ((Character)__instance).IsPlayer() && !EventHelper.IsNearBase(__instance))
		{
			float maxHealth = ((Character)__instance).GetMaxHealth();
			Biome currentBiome = __instance.GetCurrentBiome();
			if (BiomeHpLimits.MaxHpByBiome.TryGetValue(currentBiome, out var value) && maxHealth > value)
			{
				((Character)__instance).SetMaxHealth(value);
			}
		}
	}
}
[HarmonyPatch(typeof(Player), "GetBodyArmor")]
public static class Player_GetBodyArmor
{
	private static void Postfix(Player __instance, ref float __result)
	{
		//IL_002b: 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)
		if ((Object)(object)__instance == (Object)null || !((Character)__instance).IsPlayer() || EventHelper.IsNearBase(__instance))
		{
			return;
		}
		Biome currentBiome = __instance.GetCurrentBiome();
		if (BiomeScaling.Limits.TryGetValue(currentBiome, out var value))
		{
			float maxArmor = value.maxArmor;
			if (__result > maxArmor)
			{
				__result = maxArmor;
			}
		}
	}
}