using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using On;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BetterDifficulty")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterDifficulty")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("836cc54f-8e8c-4c34-b9b4-b843f8664df4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BetterDifficulty;
[BepInPlugin("com.zetalasis.hardcoredifficulty", "HardcoreDifficulty", "1.0.0")]
public class BetterDifficulty : BaseUnityPlugin
{
internal static ManualLogSource logger;
private void Awake()
{
logger = ((BaseUnityPlugin)this).Logger;
LogDebug("BetterDifficulty loaded");
HookManager.InitHooks();
}
private void OnDestroy()
{
LevelDifficultyManager.instance = null;
LogDebug("OnDestroy called");
}
private void FixedUpdate()
{
if (LevelDifficultyManager.instance != null)
{
LevelDifficultyManager.instance.Update();
}
}
public static void LogDebug(string message)
{
}
}
public class HookManager
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static hook_Setup <>9__0_0;
public static hook_NavMeshSetup <>9__0_1;
public static hook_RunGetDifficultyMultiplier <>9__0_2;
public static hook_ctor <>9__0_3;
internal void <InitHooks>b__0_0(orig_Setup orig, EnvironmentDirector director)
{
orig.Invoke(director);
BetterDifficulty.LogDebug("Level Generator started!");
LevelDifficultyManager.instance = new LevelDifficulty(RunManager.instance.levelCurrent);
}
internal void <InitHooks>b__0_1(orig_NavMeshSetup orig, LevelGenerator generator)
{
orig.Invoke(generator);
BetterDifficulty.LogDebug("Level about to finish generating");
}
internal float <InitHooks>b__0_2(orig_RunGetDifficultyMultiplier orig)
{
float num = 0f;
if (LevelDifficultyManager.instance != null)
{
num = LevelDifficultyManager.instance.calculateDifficulty();
}
BetterDifficulty.LogDebug($"[SemiFunc::RunGetDifficultyMultiplier]: {num}");
return num;
}
internal void <InitHooks>b__0_3(orig_ctor orig, LevelGenerator generator)
{
orig.Invoke(generator);
FieldInfo fieldInfo = AccessTools.Field(typeof(LevelGenerator), "DebugLevelSize");
float num = (float)fieldInfo.GetValue(generator);
BetterDifficulty.LogDebug($"DebugLevelSize: {num}");
float num2 = LevelDifficultyManager.instance.calculateModules();
fieldInfo.SetValue(generator, num2);
BetterDifficulty.LogDebug($"Set DebugLevelSize to {num2}");
}
}
public static void InitHooks()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
//IL_0038: 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)
//IL_0043: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//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_008b: Expected O, but got Unknown
object obj = <>c.<>9__0_0;
if (obj == null)
{
hook_Setup val = delegate(orig_Setup orig, EnvironmentDirector director)
{
orig.Invoke(director);
BetterDifficulty.LogDebug("Level Generator started!");
LevelDifficultyManager.instance = new LevelDifficulty(RunManager.instance.levelCurrent);
};
<>c.<>9__0_0 = val;
obj = (object)val;
}
EnvironmentDirector.Setup += (hook_Setup)obj;
object obj2 = <>c.<>9__0_1;
if (obj2 == null)
{
hook_NavMeshSetup val2 = delegate(orig_NavMeshSetup orig, LevelGenerator generator)
{
orig.Invoke(generator);
BetterDifficulty.LogDebug("Level about to finish generating");
};
<>c.<>9__0_1 = val2;
obj2 = (object)val2;
}
LevelGenerator.NavMeshSetup += (hook_NavMeshSetup)obj2;
object obj3 = <>c.<>9__0_2;
if (obj3 == null)
{
hook_RunGetDifficultyMultiplier val3 = delegate
{
float num3 = 0f;
if (LevelDifficultyManager.instance != null)
{
num3 = LevelDifficultyManager.instance.calculateDifficulty();
}
BetterDifficulty.LogDebug($"[SemiFunc::RunGetDifficultyMultiplier]: {num3}");
return num3;
};
<>c.<>9__0_2 = val3;
obj3 = (object)val3;
}
SemiFunc.RunGetDifficultyMultiplier += (hook_RunGetDifficultyMultiplier)obj3;
object obj4 = <>c.<>9__0_3;
if (obj4 == null)
{
hook_ctor val4 = delegate(orig_ctor orig, LevelGenerator generator)
{
orig.Invoke(generator);
FieldInfo fieldInfo = AccessTools.Field(typeof(LevelGenerator), "DebugLevelSize");
float num = (float)fieldInfo.GetValue(generator);
BetterDifficulty.LogDebug($"DebugLevelSize: {num}");
float num2 = LevelDifficultyManager.instance.calculateModules();
fieldInfo.SetValue(generator, num2);
BetterDifficulty.LogDebug($"Set DebugLevelSize to {num2}");
};
<>c.<>9__0_3 = val4;
obj4 = (object)val4;
}
LevelGenerator.ctor += (hook_ctor)obj4;
new Harmony("com.zetalasis.betterdifficulty").PatchAll();
}
}
internal static class LevelDifficultyManager
{
public static LevelDifficulty instance;
}
public class LevelDifficulty
{
private Level level;
public bool isFrozen;
public bool shouldOverrideDifficultyMultiplier = true;
public float difficultyMultiplierOverride = 5f;
public LevelDifficulty(Level level, LevelDifficulty previousDifficulty = null)
{
this.level = level;
_ = isFrozen;
}
~LevelDifficulty()
{
level = null;
}
public void Update()
{
_ = level.HasEnemies;
}
public float calculateDifficulty()
{
BetterDifficulty.LogDebug("Calculating difficulty...");
if (!shouldOverrideDifficultyMultiplier)
{
BetterDifficulty.LogDebug("Difficulty multiplier not overwritten");
int num = (int)AccessTools.Field(typeof(RunManager), "levelsMax").GetValue(RunManager.instance);
float num2 = (float)RunManager.instance.levelsCompleted / (float)num;
BetterDifficulty.LogDebug($"Final difficulty: {num2}");
return num2;
}
BetterDifficulty.LogDebug($"Difficulty overwritten || SemiFunc::RunIsLevel: {SemiFunc.RunIsLevel()} || difficultyMultiplierOverride: {difficultyMultiplierOverride}");
if (SemiFunc.RunIsLevel())
{
return difficultyMultiplierOverride;
}
return 0f;
}
public float calculateModules()
{
return 1f + calculateDifficulty() / 5f;
}
}