Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BerserkerEnemies v1.3.4
BerserkerEnemies/BerserkerEnemies.dll
Decompiled 11 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using BerserkerEnemies; using HarmonyLib; using Photon.Pun; using Photon.Realtime; using REPOLib.Modules; using UnityEngine; using UnityEngine.Animations; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("BerserkerEnemies")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BerserkerEnemies")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("8ebbf84f-d225-4b22-b9af-ebd8768167b2")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] internal class ModPatch { public static bool enableBerserker = true; public static int startingLevel = 9; public static int minHealth = 400; public static int maxHealth = 5000; public static int berserkerHealth = 2000; public static bool enableHealthScaling = true; public static int healthScalingFactor = 20; public static bool berserkerUnkillable = false; public static bool canBeStunned = true; public static bool enableAnimal = true; public static bool enableApexPredator = true; public static bool enableBowtie = true; public static bool enableChef = true; public static bool enableClown = true; public static bool enableHeadman = true; public static bool enableHidden = true; public static bool enableHuntsman = true; public static bool enableMentalist = true; public static bool enableReaper = true; public static bool enableRobe = true; public static bool enableRugrat = true; public static bool enableShadowChild = true; public static bool enableSpewer = true; public static bool enableTrudge = true; public static bool enableUpscream = true; public static bool containModded = true; public static bool enableGusher = true; public static bool enableRoaster = true; public static bool enableDroid = true; public static bool enableDestroyer = true; public static bool enableSoldier = true; public static bool enableFreddyFazbear = true; public static bool enableBaldi = true; public static bool enableMoon = true; public static bool enableRobot = true; public static bool enableRollingGiant = true; public static bool enableZombie = true; public static bool enableDriller = true; public static int maxBerserkersAllowed = 1; public static float berserkerSpawnChance = 10f; public static float berserkerSpawnChancePerLevel = 5f; public static bool enableBerserkerScaling = false; public static bool forceSpawnWhenScaling = false; public static int berserkerScalingLevel = 10; public static int maxScalingBerserkers = 3; public static BerserkerManager berserkerScript; public static EnemyParent _berserkerChosen; public static bool showDebugLogs = false; public static bool _masterUnkillable = false; public static bool _masterCanBeStunned = true; public static AssetBundle _assetBundle = null; public static (float, float) _orbValue = (0f, 0f); private static (float, float) currentBerserkerValuable = (0f, 0f); private static float minimumOrbValue = 8000f; private static float minOrbValueSubtract = 1000f; private static float maximumOrbValue = 50000f; private static float maxOrbValueSubtract = 10000f; public static List<int> enemyIndexes = new List<int>(); [HarmonyPatch(typeof(LevelGenerator), "GenerateDone")] [HarmonyPostfix] public static void GenerateDonePostfix(LevelGenerator __instance) { if (!SemiFunc.RunIsLevel()) { return; } _berserkerChosen = null; berserkerScript = ((Component)LevelGenerator.Instance).gameObject.GetComponent<BerserkerManager>(); if ((Object)(object)berserkerScript == (Object)null) { berserkerScript = ((Component)LevelGenerator.Instance).gameObject.AddComponent<BerserkerManager>(); } PhotonView component = ((Component)LevelGenerator.Instance).GetComponent<PhotonView>(); if (!enableBerserker || RunManager.instance.levelsCompleted + 1 < startingLevel || !SemiFunc.IsMasterClientOrSingleplayer()) { return; } List<string> enemyTypes = GetEnemyTypes(); if (enableHealthScaling) { berserkerHealth = CalculateHealthScaling(berserkerHealth); } currentBerserkerValuable = CalculateOrbValue(berserkerHealth); float num = Mathf.Clamp(berserkerSpawnChance + (float)(RunManager.instance.levelsCompleted + 1 - startingLevel) * berserkerSpawnChancePerLevel, 0f, 100f); if (showDebugLogs) { Log.Info($"Current level: {RunManager.instance.levelsCompleted + 1} - Base chance: {berserkerSpawnChance}% - Level chance: {num}%"); } int num2 = 0; if (enableBerserkerScaling) { maxBerserkersAllowed = GetScalingBerserkers(); if (showDebugLogs) { Log.Info($"Level {RunManager.instance.levelsCompleted + 1} allows {maxBerserkersAllowed} berserker(s) out of {maxScalingBerserkers} maximum."); } } List<EnemyParent> enemiesSpawned = EnemyDirector.instance.enemiesSpawned; foreach (EnemyParent item in enemiesSpawned) { if (num2 >= maxBerserkersAllowed) { continue; } float num3 = Random.Range(0, 100); if (enableBerserkerScaling && forceSpawnWhenScaling) { num = 100f; } if (showDebugLogs) { if (enableBerserkerScaling && forceSpawnWhenScaling) { Log.Info($"Enemy: {item.enemyName} - Chance: Ignoring chance of spawn. Bypass by Increment is enabled - Berserker? {num3 <= num && enemyTypes.Contains(item.enemyName)} - Is in list? {enemyTypes.Contains(item.enemyName)}"); } else { Log.Info($"Enemy: {item.enemyName} - Chance {num3}% of {num}% - Berserker? {num3 <= num && enemyTypes.Contains(item.enemyName)} - Is in list? {enemyTypes.Contains(item.enemyName)}"); } } if (!(num3 <= num) || !enemyTypes.Contains(item.enemyName)) { continue; } Log.Info("Berserker Spawned!"); _berserkerChosen = item; enemyIndexes.Add(((Component)item).transform.GetSiblingIndex()); ((Component)_berserkerChosen).GetComponent<BerserkerController>().isBerserkerFlag = true; num2++; if (SemiFunc.IsMultiplayer()) { if ((Object)(object)component != (Object)null) { component.RPC("StartBerserker", (RpcTarget)0, new object[2] { berserkerHealth, ((Component)item).transform.GetSiblingIndex() }); component.RPC("GetCanBeStunnedFromMaster", (RpcTarget)1, new object[1] { canBeStunned }); component.RPC("GetUnkillableVariableFromMaster", (RpcTarget)1, new object[1] { berserkerUnkillable }); component.RPC("GetOrbValuableFromMaster", (RpcTarget)1, new object[2] { currentBerserkerValuable.Item1, currentBerserkerValuable.Item2 }); } if (showDebugLogs) { if (SemiFunc.IsMasterClient()) { Log.Info($"Berserker: {item.enemyName} - Health: {berserkerHealth} - Unkillable? {berserkerUnkillable} - Can be stunned? {canBeStunned} - Orb value range: {currentBerserkerValuable.Item2} - {currentBerserkerValuable.Item1}"); } else { Log.Info($"Berserker: {item.enemyName} - Health: {berserkerHealth} - Unkillable? {_masterUnkillable} - Can be stunned? {_masterCanBeStunned} - Orb value range: {_orbValue.Item2} - {_orbValue.Item1}"); } } } else { berserkerScript.StartBerserker(berserkerHealth, ((Component)item).transform.GetSiblingIndex()); if (showDebugLogs) { Log.Info($"Berserker: {item.enemyName} - Health: {berserkerHealth} - Unkillable? {berserkerUnkillable} - Can be stunned? {canBeStunned} - Orb value range: {currentBerserkerValuable.Item2} - {currentBerserkerValuable.Item1}"); } } if (!containModded || !(_berserkerChosen.enemyName == "Soldier")) { continue; } List<EnemyParent> list = EnemyDirector.instance.enemiesSpawned.Where((EnemyParent ghost) => ghost.enemyName == "Soldier Ghost").ToList(); foreach (EnemyParent item2 in list) { EnemyParent val = (_berserkerChosen = item2); enemyIndexes.Add(((Component)val).transform.GetSiblingIndex()); ((Component)_berserkerChosen).GetComponent<BerserkerController>().isBerserkerFlag = true; if (SemiFunc.IsMultiplayer()) { if ((Object)(object)component != (Object)null) { component.RPC("StartBerserker", (RpcTarget)0, new object[2] { berserkerHealth, ((Component)val).transform.GetSiblingIndex() }); component.RPC("GetCanBeStunnedFromMaster", (RpcTarget)1, new object[1] { canBeStunned }); component.RPC("GetUnkillableVariableFromMaster", (RpcTarget)1, new object[1] { berserkerUnkillable }); component.RPC("GetOrbValuableFromMaster", (RpcTarget)1, new object[2] { currentBerserkerValuable.Item1, currentBerserkerValuable.Item2 }); } } else { berserkerScript.StartBerserker(berserkerHealth, ((Component)val).transform.GetSiblingIndex()); } } } if ((Object)(object)_berserkerChosen == (Object)null) { Log.Info("Berserker not spawned!"); } } [HarmonyPatch(typeof(HurtCollider), "EnemyHurt")] [HarmonyPrefix] private static bool EnemyHurt(ref bool __result, HurtCollider __instance, Enemy _enemy) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Expected O, but got Unknown //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Expected O, but got Unknown //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0337: Expected O, but got Unknown //IL_033a: Unknown result type (might be due to invalid IL or missing references) //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_03df: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Unknown result type (might be due to invalid IL or missing references) //IL_03f0: Unknown result type (might be due to invalid IL or missing references) FieldInfo fieldInfo = AccessTools.Field(typeof(Enemy), "EnemyParent"); EnemyParent val = (EnemyParent)fieldInfo.GetValue(_enemy); BerserkerController componentInMainParent = ModPatch.GetComponentInMainParent<BerserkerController>(((Component)_enemy).transform); if (!enableBerserker || !componentInMainParent.isBerserkerFlag) { return true; } FieldInfo fieldInfo2 = AccessTools.Field(typeof(Enemy), "HasHealth"); FieldInfo fieldInfo3 = AccessTools.Field(typeof(Enemy), "Health"); FieldInfo fieldInfo4 = AccessTools.Field(typeof(Enemy), "HasStateDespawn"); FieldInfo fieldInfo5 = AccessTools.Field(typeof(Enemy), "HasStateStunned"); FieldInfo fieldInfo6 = AccessTools.Field(typeof(Enemy), "StateStunned"); FieldInfo fieldInfo7 = AccessTools.Field(typeof(Enemy), "HasRigidbody"); FieldInfo fieldInfo8 = AccessTools.Field(typeof(Enemy), "Rigidbody"); EnemyRigidbody val2 = (EnemyRigidbody)fieldInfo8.GetValue(_enemy); FieldInfo fieldInfo9 = AccessTools.Field(typeof(EnemyRigidbody), "physGrabObject"); FieldInfo fieldInfo10 = AccessTools.Field(typeof(HurtCollider), "applyForce"); FieldInfo fieldInfo11 = AccessTools.Field(typeof(HurtCollider), "applyTorque"); EnemyHealth val3 = (EnemyHealth)fieldInfo3.GetValue(_enemy); FieldInfo fieldInfo12 = AccessTools.Field(typeof(EnemyHealth), "healthCurrent"); if ((Object)(object)_enemy == (Object)(object)__instance.enemyHost) { __result = false; return false; } if (!__instance.enemyLogic) { __result = false; return false; } bool flag = false; bool masterUnkillable = berserkerUnkillable; if (SemiFunc.IsMultiplayer() && SemiFunc.IsNotMasterClient()) { masterUnkillable = _masterUnkillable; } if (__instance.enemyKill && !masterUnkillable) { if ((bool)fieldInfo2.GetValue(_enemy)) { val3.Hurt((int)fieldInfo12.GetValue(val3), ((Component)__instance).transform.forward); } else if ((bool)fieldInfo4.GetValue(_enemy)) { val.SpawnedTimerSet(0f); _enemy.CurrentState = (EnemyState)11; flag = true; } } if (!flag) { bool masterCanBeStunned = canBeStunned; if (SemiFunc.IsMultiplayer() && SemiFunc.IsNotMasterClient()) { masterCanBeStunned = _masterCanBeStunned; } if (__instance.enemyStun && (bool)fieldInfo5.GetValue(_enemy) && _enemy.Type <= __instance.enemyStunType && masterCanBeStunned) { EnemyStateStunned val4 = (EnemyStateStunned)fieldInfo6.GetValue(_enemy); val4.Set(__instance.enemyStunTime); } if (__instance.enemyFreezeTime > 0f) { _enemy.Freeze(__instance.enemyFreezeTime); } if ((bool)fieldInfo7.GetValue(_enemy) && !masterUnkillable) { MethodInfo method = typeof(HurtCollider).GetMethod("PhysObjectHurt", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(__instance, new object[6] { (object)(PhysGrabObject)fieldInfo9.GetValue(val2), __instance.enemyImpact, __instance.enemyHitForce, __instance.enemyHitTorque, true, false }); if (__instance.enemyFreezeTime > 0f) { val2.FreezeForces((Vector3)fieldInfo10.GetValue(__instance), (Vector3)fieldInfo11.GetValue(__instance)); } } if (__instance.enemyDamage > 0 && (bool)fieldInfo2.GetValue(_enemy) && !masterUnkillable) { Vector3 val5 = (Vector3)fieldInfo10.GetValue(__instance); val3.Hurt(__instance.enemyDamage, ((Vector3)(ref val5)).normalized); } } __result = true; return false; } [HarmonyPatch(typeof(EnemyParent), "SpawnRPC")] [HarmonyPostfix] private static void SpawnRPCPostfix(EnemyParent __instance) { if ((Object)(object)((Component)__instance).gameObject.GetComponent<BerserkerController>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<BerserkerController>(); if (showDebugLogs) { Log.Info("BerserkerController added to enemy " + __instance.enemyName + "!"); } } } [HarmonyPatch(typeof(EnemyParent), "Despawn")] [HarmonyPrefix] public static bool DespawnPrefix(EnemyParent __instance) { //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Expected O, but got Unknown //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) if (enableBerserker) { BerserkerController berserkerController = ((Component)__instance).GetComponent<BerserkerController>(); if ((Object)(object)berserkerController == (Object)null) { berserkerController = ((Component)__instance).gameObject.AddComponent<BerserkerController>(); if (showDebugLogs) { Log.Info("BerserkerController added to enemy " + __instance.enemyName + "!"); } } if (Object.op_Implicit((Object)(object)berserkerScript)) { if ((Object)(object)berserkerController != (Object)null) { if (berserkerController.isBerserkerFlag) { if (GameManager.Multiplayer() && !PhotonNetwork.IsMasterClient) { return false; } FieldInfo fieldInfo = AccessTools.Field(typeof(EnemyParent), "Enemy"); Enemy val = (Enemy)fieldInfo.GetValue(__instance); if ((Object)(object)val != (Object)null) { FieldInfo fieldInfo2 = AccessTools.Field(typeof(EnemyDirector), "despawnedTimeMultiplier"); val.CurrentState = (EnemyState)11; __instance.DespawnedTimer = Random.Range(__instance.DespawnedTimeMin, __instance.DespawnedTimeMax) * (float)fieldInfo2.GetValue(EnemyDirector.instance); __instance.DespawnedTimer = Mathf.Max(__instance.DespawnedTimer, 1f); FieldInfo fieldInfo3 = AccessTools.Field(typeof(Enemy), "HasRigidbody"); if ((bool)fieldInfo3.GetValue(val)) { FieldInfo fieldInfo4 = AccessTools.Field(typeof(Enemy), "Rigidbody"); EnemyRigidbody val2 = (EnemyRigidbody)fieldInfo4.GetValue(val); FieldInfo fieldInfo5 = AccessTools.Field(typeof(EnemyRigidbody), "grabbed"); FieldInfo fieldInfo6 = AccessTools.Field(typeof(EnemyRigidbody), "grabStrengthTimer"); fieldInfo5.SetValue(val2, false); fieldInfo6.SetValue(val2, 0f); val2.GrabRelease(); } if (GameManager.Multiplayer()) { ((Component)__instance).GetComponent<PhotonView>().RPC("DespawnRPC", (RpcTarget)0, Array.Empty<object>()); } else { MethodInfo method = typeof(EnemyParent).GetMethod("DespawnRPC", BindingFlags.Instance | BindingFlags.NonPublic); if (method != null) { method.Invoke(__instance, new object[0]); } } FieldInfo fieldInfo7 = AccessTools.Field(typeof(Enemy), "HasHealth"); EnemyHealth component = ((Component)val).GetComponent<EnemyHealth>(); FieldInfo fieldInfo8 = AccessTools.Field(typeof(EnemyHealth), "healthCurrent"); if (!(bool)fieldInfo7.GetValue(val) || (int)fieldInfo8.GetValue(component) > 0) { return false; } GameObject val3 = _assetBundle.LoadAsset<GameObject>("Enemy Valuable - Berserker"); Transform val4 = val.CustomValuableSpawnTransform; if (!Object.op_Implicit((Object)(object)val4)) { val4 = val.CenterTransform; } val3 = (SemiFunc.IsMultiplayer() ? NetworkPrefabs.SpawnNetworkPrefab("Enemy Valuable - Berserker", val4.position, Quaternion.identity, (byte)0, (object[])null) : Object.Instantiate<GameObject>(val3, val4.position, Quaternion.identity)); (float, float) orbValue = currentBerserkerValuable; if (SemiFunc.IsMultiplayer() && SemiFunc.IsNotMasterClient()) { orbValue = _orbValue; } ScriptableObject obj = _assetBundle.LoadAsset<ScriptableObject>("Value - Berserker"); Value val5 = (Value)(object)((obj is Value) ? obj : null); (val5.valueMax, val5.valueMin) = orbValue; if (!canBeStunned) { val5.valueMax += 2000f; val5.valueMin += 2000f; if (showDebugLogs) { Log.Info("Added bonus orb value for non-stunnable Berserker!"); } } val3.GetComponent<ValuableObject>().valuePreset = val5; __instance.DespawnedTimer *= 3f; return false; } Log.Warn("CurrentEnemy is null! Dropping default valuable!"); return true; } if (showDebugLogs) { Log.Info("Enemy " + __instance.enemyName + " is not Berserker!"); } return true; } Log.Warn("BerserkerController not found in enemy " + __instance.enemyName + "!"); } } return true; } public static int CalculateHealthScaling(int _berserkerHealth) { return _berserkerHealth + (RunManager.instance.levelsCompleted + 1 - startingLevel) * (SemiFunc.PlayerGetAll().Count * healthScalingFactor); } public static (float, float) CalculateOrbValue(int _berserkerHealth) { int num = maxHealth; if (enableHealthScaling) { num += (RunManager.instance.levelsCompleted + 1 - startingLevel) * (SemiFunc.PlayerGetAll().Count * healthScalingFactor); } float num2 = Mathf.InverseLerp((float)minHealth, (float)num, (float)_berserkerHealth); float num3 = Mathf.Lerp(maxOrbValueSubtract, maximumOrbValue, num2); float item = num3 - Mathf.Lerp(minOrbValueSubtract, minimumOrbValue, num2); return (num3, item); } public static int GetScalingBerserkers() { int num = RunManager.instance.levelsCompleted + 1; int num2 = num - startingLevel; int num3 = num2 / berserkerScalingLevel; int num4 = maxBerserkersAllowed + num3; if (num4 > maxScalingBerserkers) { num4 = maxScalingBerserkers; } return num4; } public static T GetComponentInChildrenRecursive<T>(Transform obj) where T : Component { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown foreach (Transform item in obj) { Transform val = item; T component = ((Component)val).GetComponent<T>(); if ((Object)(object)component != (Object)null) { return component; } component = GetComponentInChildrenRecursive<T>(val); if ((Object)(object)component != (Object)null) { return component; } } return default(T); } public static T GetComponentInMainParent<T>(Transform obj) where T : Component { Transform parent = obj.parent; T result = default(T); while ((Object)(object)parent != (Object)null) { T component = ((Component)parent).GetComponent<T>(); if ((Object)(object)component != (Object)null) { result = component; } parent = parent.parent; } return result; } public static List<string> GetEnemyTypes() { List<string> list = new List<string>(); if (enableAnimal) { list.Add("Animal"); } if (enableApexPredator) { list.Add("Apex Predator"); } if (enableBowtie) { list.Add("Bowtie"); } if (enableChef) { list.Add("Chef"); } if (enableClown) { list.Add("Clown"); } if (enableHeadman) { list.Add("Headman"); } if (enableHuntsman) { list.Add("Huntsman"); } if (enableMentalist) { list.Add("Mentalist"); } if (enableReaper) { list.Add("Reaper"); } if (enableRobe) { list.Add("Robe"); } if (enableRugrat) { list.Add("Rugrat"); } if (enableShadowChild) { list.Add("Shadow Child"); } if (enableSpewer) { list.Add("Spewer"); } if (enableTrudge) { list.Add("Trudge"); } if (enableUpscream) { list.Add("Upscream"); } if (containModded) { if (enableGusher) { list.Add("Gusher"); } if (enableRoaster) { list.Add("Roaster"); } if (enableDroid) { list.Add("Lost droid"); } if (enableDestroyer) { list.Add("Lost Destroyer"); } if (enableSoldier) { list.Add("Soldier"); } if (enableFreddyFazbear) { list.Add("Freddy Fazbear"); } if (enableBaldi) { list.Add("Baldi"); } if (enableMoon) { list.Add("The Moon"); } if (enableRobot) { list.Add("Robot"); } if (enableRollingGiant) { list.Add("Rolling Giant"); } if (enableZombie) { list.Add("Zombie"); } if (enableDriller) { list.Add("Driller"); } } return list; } public static Texture2D LoadEmbeddedTexture(string resourceName) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown Assembly executingAssembly = Assembly.GetExecutingAssembly(); using (Stream stream = executingAssembly.GetManifestResourceStream(resourceName)) { if (stream == null) { Log.Warn("Resource " + resourceName + " not found!"); return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (ImageConversion.LoadImage(val, array)) { ((Texture)val).filterMode = (FilterMode)2; ((Texture)val).wrapMode = (TextureWrapMode)1; return val; } } return null; } } internal class BerserkerManager : MonoBehaviourPunCallbacks { [CompilerGenerated] private sealed class <DelayedStartBerserker>d__10 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public Player newPlayer; public BerserkerManager <>4__this; private List<int>.Enumerator <>s__1; private int <index>5__2; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <DelayedStartBerserker>d__10(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>s__1 = default(List<int>.Enumerator); <>1__state = -2; } private bool MoveNext() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitUntil((Func<bool>)(() => SemiFunc.LevelGenDone())); <>1__state = 1; return true; case 1: <>1__state = -1; if (ModPatch.enemyIndexes.Count > 0) { <>s__1 = ModPatch.enemyIndexes.GetEnumerator(); try { while (<>s__1.MoveNext()) { <index>5__2 = <>s__1.Current; ((MonoBehaviourPun)<>4__this).photonView.RPC("SyncBerserkerToPlayer", (RpcTarget)5, new object[7] { newPlayer.ActorNumber, ModPatch.berserkerHealth, <index>5__2, ModPatch.canBeStunned, ModPatch.berserkerUnkillable, ModPatch._orbValue.Item1, ModPatch._orbValue.Item2 }); } } finally { ((IDisposable)<>s__1).Dispose(); } <>s__1 = default(List<int>.Enumerator); } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static BerserkerManager instance; public EnemyParent berserkerChosen; private static Transform berserkerChosenTransform; private static ParticleSystem berserkerParticlesObjPS; private List<(int health, int index)> pendingBerserkers = new List<(int, int)>(); private bool levelReady = false; public string DEBUG_ENEMY_NAME = ""; private void Awake() { instance = this; } private void Update() { //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Invalid comparison between Unknown and I4 //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Invalid comparison between Unknown and I4 //IL_014f: Unknown result type (might be due to invalid IL or missing references) if (!ModPatch.enableBerserker || EnemyDirector.instance.enemiesSpawned.Count <= 0) { return; } if (!levelReady && SemiFunc.LevelGenDone()) { levelReady = true; StartPendingBerserkers(); } for (int i = 0; i < EnemyDirector.instance.enemiesSpawned.Count; i++) { Enemy val = null; try { val = GetBerserkerEnemyScript(((Component)EnemyDirector.instance.enemiesSpawned[i]).transform); } catch { continue; } if ((Object)(object)val != (Object)null) { EnemyParent componentInMainParent = ModPatch.GetComponentInMainParent<EnemyParent>(((Component)val).transform); if ((Object)(object)componentInMainParent != (Object)null) { try { if (componentInMainParent.enemyName == "Freddy Fazbear") { val = GetBerserkerEnemyScript(((Component)componentInMainParent).transform); if ((Object)(object)val != (Object)null && ((Component)((Component)val).transform.parent).gameObject.activeInHierarchy) { GameObject gameObject = ((Component)((Component)val).transform.parent.GetChild(2).GetChild(3).GetChild(0) .GetChild(3)).gameObject; if ((Object)(object)gameObject != (Object)null && (Object)(object)berserkerParticlesObjPS != (Object)null) { if (gameObject.transform.localPosition.z > 0f) { if (berserkerParticlesObjPS.isPlaying) { berserkerParticlesObjPS.Stop(); } } else if (berserkerParticlesObjPS.isStopped) { berserkerParticlesObjPS.Play(); } } } } } catch (Exception arg) { Log.Warn($"Error while processing Freddy Fazbear: {arg}"); } try { if (!(componentInMainParent.enemyName == "Spewer")) { continue; } val = GetBerserkerEnemyScript(((Component)componentInMainParent).transform); if (!((Object)(object)val != (Object)null) || !((Component)((Component)val).transform.parent).gameObject.activeInHierarchy) { continue; } EnemySlowMouth component = ((Component)val).GetComponent<EnemySlowMouth>(); if (!((Object)(object)berserkerParticlesObjPS != (Object)null)) { continue; } if ((int)component.currentState == 9 || (int)component.currentState == 10) { if (berserkerParticlesObjPS.isPlaying) { berserkerParticlesObjPS.Stop(); } } else if (berserkerParticlesObjPS.isStopped) { berserkerParticlesObjPS.Play(); } } catch (Exception arg2) { Log.Warn($"Error while processing Spewer: {arg2}"); } } else if (ModPatch.showDebugLogs) { Log.Warn("EnemyParent script is null!"); } } else if (ModPatch.showDebugLogs) { Log.Warn("Enemy script is null!"); } } } public override void OnPlayerEnteredRoom(Player newPlayer) { if (PhotonNetwork.IsMasterClient && SemiFunc.RunIsLevel() && ModPatch.enableBerserker) { Log.Info(newPlayer.NickName + " joined! Sending berserker data..."); ((MonoBehaviour)this).StartCoroutine(DelayedStartBerserker(newPlayer)); } } [IteratorStateMachine(typeof(<DelayedStartBerserker>d__10))] public IEnumerator DelayedStartBerserker(Player newPlayer) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <DelayedStartBerserker>d__10(0) { <>4__this = this, newPlayer = newPlayer }; } [PunRPC] public void SyncBerserkerToPlayer(int actorNumber, int berserkerHealth, int enemyIndex, bool canBeStunned, bool unkillable, float orbValueMax, float orbValueMin) { if (PhotonNetwork.LocalPlayer.ActorNumber == actorNumber) { ModPatch._masterCanBeStunned = canBeStunned; ModPatch._masterUnkillable = unkillable; ModPatch._orbValue = (orbValueMax, orbValueMin); pendingBerserkers.Add((berserkerHealth, enemyIndex)); if (levelReady) { StartPendingBerserkers(); } } } private void StartPendingBerserkers() { foreach (var pendingBerserker in pendingBerserkers) { StartBerserker(pendingBerserker.health, pendingBerserker.index); } pendingBerserkers.Clear(); } [PunRPC] public void GetCanBeStunnedFromMaster(bool _canBeStunned) { ModPatch._masterCanBeStunned = _canBeStunned; } [PunRPC] public void GetUnkillableVariableFromMaster(bool _masterUnkillable) { ModPatch._masterUnkillable = _masterUnkillable; } [PunRPC] public void GetOrbValuableFromMaster(float _valueMax, float _valueMin) { ModPatch._orbValue = (_valueMax, _valueMin); } [PunRPC] public void StartBerserker(int berserkerHealth, int enemyIndex) { List<EnemyParent> enemiesSpawned = EnemyDirector.instance.enemiesSpawned; berserkerChosen = enemiesSpawned[enemyIndex]; if ((Object)(object)berserkerChosen != (Object)null) { if ((Object)(object)((Component)berserkerChosen).GetComponent<BerserkerController>() == (Object)null) { ((Component)berserkerChosen).gameObject.AddComponent<BerserkerController>(); } if (!((Component)berserkerChosen).gameObject.GetComponent<BerserkerController>().isBerserkerFlag) { ((Component)berserkerChosen).gameObject.AddComponent<BerserkerController>().isBerserkerFlag = true; } if (ModPatch.showDebugLogs) { Log.Info("Setting up Berserker " + berserkerChosen.enemyName + " properties..."); } else { Log.Info("Setting up Berserker properties..."); } berserkerChosenTransform = ((Component)berserkerChosen).transform; SetBerserkerValues(berserkerChosen, berserkerChosenTransform, berserkerHealth); SetBerserkerGrabForce(berserkerChosenTransform); if (((Component)berserkerChosenTransform).GetComponent<EnemyParent>().enemyName != "Hidden") { SetBerserkerGlow(berserkerChosenTransform); SetBerserkerSmoke(berserkerChosenTransform); } else if (((Component)berserkerChosenTransform).GetComponent<EnemyParent>().enemyName == "Hidden") { SetUpHidden(berserkerChosenTransform); } Log.Info("Berserker configured!"); } else if (ModPatch.showDebugLogs) { Log.Warn("Berserker Chosen is null!"); } } private static void SetBerserkerValues(EnemyParent enemyParent, Transform enemy, int _masterHealth) { int num = ModPatch.berserkerHealth; if (SemiFunc.IsMultiplayer() && SemiFunc.IsNotMasterClient()) { num = _masterHealth; } bool flag = ModPatch.berserkerUnkillable; if (SemiFunc.IsMultiplayer() && SemiFunc.IsNotMasterClient()) { flag = ModPatch._masterUnkillable; } EnemyHealth berserkerHealthScript = GetBerserkerHealthScript(enemy); if ((Object)(object)berserkerHealthScript != (Object)null) { FieldInfo fieldInfo = AccessTools.Field(typeof(EnemyHealth), "healthCurrent"); fieldInfo.SetValue(berserkerHealthScript, num); berserkerHealthScript.health = num; if (flag) { berserkerHealthScript.impactHurt = false; berserkerHealthScript.objectHurt = false; berserkerHealthScript.objectHurtStun = false; } } bool flag2 = ModPatch.canBeStunned; if (SemiFunc.IsMultiplayer() && SemiFunc.IsNotMasterClient()) { flag2 = ModPatch._masterCanBeStunned; } if (ModPatch.showDebugLogs && flag2) { Log.Info("Berserker can be stunned!"); } Enemy berserkerEnemyScript = GetBerserkerEnemyScript(enemy); if ((Object)(object)berserkerEnemyScript != (Object)null && !flag2) { FieldInfo fieldInfo2 = AccessTools.Field(typeof(Enemy), "HasStateStunned"); fieldInfo2.SetValue(berserkerEnemyScript, false); if (ModPatch.showDebugLogs) { Log.Info("Berserker " + enemyParent.enemyName + " - Stunned state removed!"); } } EnemyRigidbody berserkerRigidbodyScript = GetBerserkerRigidbodyScript(enemy); if ((Object)(object)berserkerRigidbodyScript != (Object)null && !flag2) { berserkerRigidbodyScript.grabStun = false; berserkerRigidbodyScript.stunFromFall = false; if (ModPatch.showDebugLogs) { Log.Info($"Berserker {enemyParent.enemyName} - Grab Stun: {berserkerRigidbodyScript.grabStun}"); } Log.Info($"Berserker {enemyParent.enemyName} - Stun From Fall: {berserkerRigidbodyScript.stunFromFall}"); } } private static void SetBerserkerGlow(Transform enemy) { Renderer[] componentsInChildren = ((Component)enemy).GetComponentsInChildren<Renderer>(true); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { Material[] materials = val.materials; foreach (Material val2 in materials) { if ((Object)(object)val2 == (Object)null || (Object)(object)val2.shader == (Object)null) { continue; } string name = ((Object)val2.shader).name; switch (name) { default: if (!(name == "Orton/Hurtable Alpha Clip")) { if (name == "Standard") { Texture texture = val2.GetTexture("_MainTex"); Shader shader = Shader.Find("Hurtable/Hurtable"); if (Application.isEditor) { shader = Shader.Find("Patcher/Hurtable/Hurtable"); } val2.shader = shader; if (val2.HasProperty("_AlbedoTexture")) { val2.SetTexture("_AlbedoTexture", texture); } ApplyFresnel(val2); } break; } goto case "Hurtable/Hurtable"; case "Hurtable/Hurtable": case "Hurtable/Hurtable Alpha Clip": case "Patcher/Hurtable/Hurtable": case "Patcher/Hurtable/Hurtable Alpha Clip": case "Ortong/Hurtable": case "Orton/Hurtable/Hurtable Freddy": ApplyFresnel(val2); break; } } } } private static void ApplyFresnel(Material mat) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) mat.SetFloat("_FresnelAmount", 1f); mat.SetFloat("_FresnelScale", 1f); mat.SetFloat("_FresnelPower", 5f); mat.SetFloat("_FresnelBias", 0f); mat.SetColor("_FresnelColor", Color.red); mat.SetFloat("_FresnelEmission", 1f); } private static void SetBerserkerGrabForce(Transform enemy) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown GrabForce val = ScriptableObject.CreateInstance<GrabForce>(); val.amount = 1E+10f; ((Object)val).name = "Grab Force - Berserker"; foreach (Transform item in enemy) { Transform berserkerGrabForce = item; EnemyRigidbody component = ((Component)enemy).gameObject.GetComponent<EnemyRigidbody>(); if ((Object)(object)component != (Object)null && (Object)(object)component.grabForceNeeded != (Object)(object)val) { component.grabForceNeeded = val; } SetBerserkerGrabForce(berserkerGrabForce); } } private static Transform GetBerserkerParticleParent(Transform enemy) { Transform result = null; Animator componentInChildrenRecursive = ModPatch.GetComponentInChildrenRecursive<Animator>(enemy); if ((Object)(object)componentInChildrenRecursive != (Object)null) { result = ((Component)componentInChildrenRecursive).transform; } return result; } private static void SetBerserkerSmoke(Transform enemy) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) Transform berserkerParticleParent = GetBerserkerParticleParent(enemy); GameObject val = ModPatch._assetBundle.LoadAsset<GameObject>("BerserkerAura"); GameObject val2 = Object.Instantiate<GameObject>(val); berserkerParticlesObjPS = val2.GetComponent<ParticleSystem>(); if ((Object)(object)berserkerParticleParent != (Object)null) { val2.transform.SetParent(berserkerParticleParent, false); } Vector3 val3 = Vector3.zero; if (((Component)enemy).GetComponent<EnemyParent>().enemyName == "Robe" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Reaper" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Clown" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Huntsman" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Soldier" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Soldier Ghost" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Lost droid" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Lost Destroyer" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Zombie") { val3 += new Vector3(0f, 1f, 0f); } else if (((Component)enemy).GetComponent<EnemyParent>().enemyName == "Trudge" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Gusher" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Roaster" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Freddy Fazbear" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Shadow Child" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Rolling Giant" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Robot" || ((Component)enemy).GetComponent<EnemyParent>().enemyName == "Driller") { val3 += new Vector3(0f, 1.5f, 0f); } val2.transform.localPosition = val3; val2.transform.localRotation = Quaternion.identity; } private static Enemy GetBerserkerEnemyScript(Transform enemy) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown foreach (Transform item in enemy) { Transform val = item; if (((Object)val).name == "Controller") { Enemy component = ((Component)val).GetComponent<Enemy>(); if ((Object)(object)component != (Object)null) { return component; } } Enemy berserkerEnemyScript = GetBerserkerEnemyScript(val); if ((Object)(object)berserkerEnemyScript != (Object)null) { return berserkerEnemyScript; } } return null; } private static EnemyRigidbody GetBerserkerRigidbodyScript(Transform enemy) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown foreach (Transform item in enemy) { Transform val = item; if (((Object)val).name == "Rigidbody") { EnemyRigidbody component = ((Component)val).GetComponent<EnemyRigidbody>(); if ((Object)(object)component != (Object)null) { return component; } } EnemyRigidbody berserkerRigidbodyScript = GetBerserkerRigidbodyScript(val); if ((Object)(object)berserkerRigidbodyScript != (Object)null) { return berserkerRigidbodyScript; } } return null; } private static EnemyHealth GetBerserkerHealthScript(Transform enemy) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown foreach (Transform item in enemy) { Transform val = item; if (((Object)val).name == "Controller") { EnemyHealth component = ((Component)val).GetComponent<EnemyHealth>(); if ((Object)(object)component != (Object)null) { return component; } } EnemyHealth berserkerHealthScript = GetBerserkerHealthScript(val); if ((Object)(object)berserkerHealthScript != (Object)null) { return berserkerHealthScript; } } return null; } private static void SetUpHidden(Transform enemy) { //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) GameObject val = ModPatch._assetBundle.LoadAsset<GameObject>("Berserker Hidden Breath"); GameObject val2 = ModPatch._assetBundle.LoadAsset<GameObject>("Berserker Hidden Breath Constant"); GameObject val3 = ModPatch._assetBundle.LoadAsset<GameObject>("Berserker Hidden Breath Fast"); GameObject val4 = ModPatch._assetBundle.LoadAsset<GameObject>("Berserker Hidden Foot Shape Left"); GameObject val5 = ModPatch._assetBundle.LoadAsset<GameObject>("Berserker Hidden Foot Shape Right"); ((Component)enemy.GetChild(0).GetChild(0)).gameObject.SetActive(false); ((Component)enemy.GetChild(0).GetChild(1)).gameObject.SetActive(false); ((Component)enemy.GetChild(0).GetChild(2)).gameObject.SetActive(false); ((Component)enemy.GetChild(0).GetChild(3)).gameObject.SetActive(false); ((Component)enemy.GetChild(0).GetChild(4)).gameObject.SetActive(false); GameObject val6 = Object.Instantiate<GameObject>(val, enemy.GetChild(0).GetChild(0).position, enemy.GetChild(0).GetChild(0).rotation, enemy.GetChild(0)); val6.transform.SetSiblingIndex(0); ParentConstraint component = val6.GetComponent<ParentConstraint>(); ConstraintSource val7 = default(ConstraintSource); ((ConstraintSource)(ref val7)).sourceTransform = enemy.GetChild(1).GetChild(1).GetChild(6) .GetChild(0); ((ConstraintSource)(ref val7)).weight = 1f; component.SetSource(0, val7); val6.GetComponent<ParentConstraint>().translationAtRest = new Vector3(0f, 1.826f, -2.702927f); GameObject val8 = Object.Instantiate<GameObject>(val3, enemy.GetChild(0).GetChild(1).position, enemy.GetChild(0).GetChild(1).rotation, enemy.GetChild(0)); val8.transform.SetSiblingIndex(1); ParentConstraint component2 = val8.GetComponent<ParentConstraint>(); val7 = default(ConstraintSource); ((ConstraintSource)(ref val7)).sourceTransform = enemy.GetChild(1).GetChild(1).GetChild(6) .GetChild(0); ((ConstraintSource)(ref val7)).weight = 1f; component2.SetSource(0, val7); val8.GetComponent<ParentConstraint>().translationAtRest = new Vector3(0f, 1.826f, -2.702927f); GameObject val9 = Object.Instantiate<GameObject>(val2, enemy.GetChild(0).GetChild(2).position, enemy.GetChild(0).GetChild(2).rotation, enemy.GetChild(0)); val9.transform.SetSiblingIndex(2); ParentConstraint component3 = val9.GetComponent<ParentConstraint>(); val7 = default(ConstraintSource); ((ConstraintSource)(ref val7)).sourceTransform = enemy.GetChild(1).GetChild(1).GetChild(6) .GetChild(0); ((ConstraintSource)(ref val7)).weight = 1f; component3.SetSource(0, val7); val9.GetComponent<ParentConstraint>().translationAtRest = new Vector3(0f, 1.826f, -2.702927f); GameObject val10 = Object.Instantiate<GameObject>(val5, enemy.GetChild(0).GetChild(3).position, enemy.GetChild(0).GetChild(3).rotation, enemy.GetChild(0)); val10.transform.SetSiblingIndex(3); GameObject val11 = Object.Instantiate<GameObject>(val4, enemy.GetChild(0).GetChild(4).position, enemy.GetChild(0).GetChild(4).rotation, enemy.GetChild(0)); val11.transform.SetSiblingIndex(4); EnemyHiddenAnim component4 = ((Component)enemy.GetChild(1).GetChild(1).GetChild(6)).GetComponent<EnemyHiddenAnim>(); component4.particleBreath = val6.GetComponent<ParticleSystem>(); component4.particleBreathFast = val8.GetComponent<ParticleSystem>(); component4.particleBreathConstant = val9.GetComponent<ParticleSystem>(); component4.particleFootstepShapeLeft = val11.GetComponent<ParticleSystem>(); component4.particleFootstepShapeRight = val10.GetComponent<ParticleSystem>(); } } public class BerserkerController : MonoBehaviourPun { public bool isBerserkerFlag = false; } namespace BerserkerEnemies; [BepInPlugin("FNKTLabs.BerserkerEnemies", "Berserker Enemies", "1.3.4")] public class ModBase : BaseUnityPlugin { private const string modGUID = "FNKTLabs.BerserkerEnemies"; public const string modName = "Berserker Enemies"; private const string modVersion = "1.3.4"; private Harmony _harmony = new Harmony("FNKTLabs.BerserkerEnemies"); public static ConfigEntry<bool> config_EnableBerserker; public static ConfigEntry<int> config_StartingLevel; public static ConfigEntry<int> config_BerserkerHealth; public static ConfigEntry<bool> config_EnableHealthScaling; public static ConfigEntry<int> config_HealthScalingFactor; public static ConfigEntry<bool> config_BerserkerUnkillable; public static ConfigEntry<bool> config_CanBeStunned; public static ConfigEntry<int> config_MaxBerserkers; public static ConfigEntry<float> config_berserkerSpawnChance; public static ConfigEntry<float> config_berserkerSpawnChancePerLevel; public static ConfigEntry<bool> config_EnableBerserkerScaling; public static ConfigEntry<int> config_BerserkerScalingLevel; public static ConfigEntry<int> config_MaxScalingBerserkers; public static ConfigEntry<bool> config_ForceSpawnWhenScaling; public static ConfigEntry<bool> config_enableAnimal; public static ConfigEntry<bool> config_enableApexPredator; public static ConfigEntry<bool> config_enableChef; public static ConfigEntry<bool> config_enableClown; public static ConfigEntry<bool> config_enableBowtie; public static ConfigEntry<bool> config_enableMentalist; public static ConfigEntry<bool> config_enableHeadman; public static ConfigEntry<bool> config_enableHuntsman; public static ConfigEntry<bool> config_enableReaper; public static ConfigEntry<bool> config_enableRobe; public static ConfigEntry<bool> config_enableRugrat; public static ConfigEntry<bool> config_enableShadowChild; public static ConfigEntry<bool> config_enableSpewer; public static ConfigEntry<bool> config_enableTrudge; public static ConfigEntry<bool> config_enableUpscream; public static ConfigEntry<bool> config_enableDestroyer; public static ConfigEntry<bool> config_enableDroid; public static ConfigEntry<bool> config_enableGusher; public static ConfigEntry<bool> config_enableRoaster; public static ConfigEntry<bool> config_enableSoldier; public static ConfigEntry<bool> config_enableFreddyFazbear; public static ConfigEntry<bool> config_enableBaldi; public static ConfigEntry<bool> config_enableZeldaMoon; public static ConfigEntry<bool> config_enableRetermninator; public static ConfigEntry<bool> config_enableRollinGiant; public static ConfigEntry<bool> config_enableMCZombie; public static ConfigEntry<bool> config_enableDrillerKiller; public static ConfigEntry<bool> config_showDebugLogs; public void Awake() { Log.Init(((BaseUnityPlugin)this).Logger); Log.Info("BerserkerEnemies loaded!"); _harmony.PatchAll(typeof(ModBase)); _harmony.PatchAll(typeof(ModPatch)); ConfigFile(); SetUpBundle(); } public void SetUpBundle() { string directoryName = Path.GetDirectoryName(typeof(ModBase).Assembly.Location); string text = Path.Combine(directoryName, "berserker_enemies"); if (!File.Exists(text)) { Log.Error("AssetBundle not found: " + text); return; } AssetBundle val = AssetBundle.LoadFromFile(text); if ((Object)(object)val == (Object)null) { Log.Error("Failed to load AssetBundle from: " + text); return; } ModPatch._assetBundle = val; GameObject val2 = val.LoadAsset<GameObject>("Enemy Valuable - Berserker"); NetworkPrefabs.RegisterNetworkPrefab(((Object)val2).name, val2); Log.Info("AssetBundle loaded successfully!"); } public void ConfigFile() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Expected O, but got Unknown //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Expected O, but got Unknown //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Expected O, but got Unknown //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Expected O, but got Unknown //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Expected O, but got Unknown //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Expected O, but got Unknown //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Expected O, but got Unknown //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02f2: Expected O, but got Unknown //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Expected O, but got Unknown //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Expected O, but got Unknown //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Expected O, but got Unknown config_EnableBerserker = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, new ConfigDescription("Enable or disable the Berserker enemy.", (AcceptableValueBase)null, Array.Empty<object>())); ModPatch.enableBerserker = config_EnableBerserker.Value; config_showDebugLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Debug Logs", false, new ConfigDescription("Enable or disable debug logs.", (AcceptableValueBase)null, Array.Empty<object>())); ModPatch.showDebugLogs = config_showDebugLogs.Value; config_BerserkerUnkillable = ((BaseUnityPlugin)this).Config.Bind<bool>("Berserkers Settings", "Unkillable", false, new ConfigDescription("If enabled, the Berserker cannot be killed.", (AcceptableValueBase)null, Array.Empty<object>())); ModPatch.berserkerUnkillable = config_BerserkerUnkillable.Value; config_CanBeStunned = ((BaseUnityPlugin)this).Config.Bind<bool>("Berserkers Settings", "Stunnable", true, new ConfigDescription("If enabled, the Berserker can be stunned.", (AcceptableValueBase)null, Array.Empty<object>())); ModPatch.canBeStunned = config_CanBeStunned.Value; config_BerserkerHealth = ((BaseUnityPlugin)this).Config.Bind<int>("Health Settings", "Health", 2000, new ConfigDescription("Base health of the Berserker.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(ModPatch.minHealth, ModPatch.maxHealth), Array.Empty<object>())); ModPatch.berserkerHealth = config_BerserkerHealth.Value; config_EnableHealthScaling = ((BaseUnityPlugin)this).Config.Bind<bool>("Health Settings", "Scaling", false, new ConfigDescription("Enable health scaling based on level and player count.", (AcceptableValueBase)null, Array.Empty<object>())); ModPatch.enableHealthScaling = config_EnableHealthScaling.Value; config_HealthScalingFactor = ((BaseUnityPlugin)this).Config.Bind<int>("Health Settings", "Scale Factor", 10, new ConfigDescription("Health = base + (level × players × factor).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 100), Array.Empty<object>())); ModPatch.healthScalingFactor = config_HealthScalingFactor.Value; config_MaxBerserkers = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn Settings", "Max Berserkers", 1, new ConfigDescription("Max number of Berserkers at once.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), Array.Empty<object>())); ModPatch.maxBerserkersAllowed = config_MaxBerserkers.Value; config_StartingLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn Settings", "Starting Level", 9, new ConfigDescription("Min level required for spawn.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>())); ModPatch.startingLevel = config_StartingLevel.Value; config_berserkerSpawnChance = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Settings", "Chance", 10f, new ConfigDescription("Base spawn chance in percent.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); ModPatch.berserkerSpawnChance = config_berserkerSpawnChance.Value; config_berserkerSpawnChancePerLevel = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Settings", "Extra Chance Per Level", 5f, new ConfigDescription("Extra spawn chance per level.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), Array.Empty<object>())); ModPatch.berserkerSpawnChancePerLevel = config_berserkerSpawnChancePerLevel.Value; config_EnableBerserkerScaling = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawn Settings", "Scaling", false, new ConfigDescription("Enable dynamic increase of Berserker limit based on level.", (AcceptableValueBase)null, Array.Empty<object>())); ModPatch.enableBerserkerScaling = config_EnableBerserkerScaling.Value; config_ForceSpawnWhenScaling = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawn Settings", "Bypass Spawn Chance", false, new ConfigDescription("Always spawn a Berserker when scaling is enabled, ignoring spawn chance.", (AcceptableValueBase)null, Array.Empty<object>())); ModPatch.forceSpawnWhenScaling = config_ForceSpawnWhenScaling.Value; config_BerserkerScalingLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn Settings", "Scaling Step", 10, new ConfigDescription("Levels required to allow 1 more Berserker.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 20), Array.Empty<object>())); ModPatch.berserkerScalingLevel = config_BerserkerScalingLevel.Value; config_MaxScalingBerserkers = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn Settings", "Max Scaled Berserkers", 3, new ConfigDescription("Maximum number of Berserkers when scaling is enabled.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>())); ModPatch.maxScalingBerserkers = config_MaxScalingBerserkers.Value; config_enableAnimal = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Animal", true, (ConfigDescription)null); ModPatch.enableAnimal = config_enableAnimal.Value; config_enableApexPredator = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Apex Predator", true, (ConfigDescription)null); ModPatch.enableApexPredator = config_enableApexPredator.Value; config_enableBowtie = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Bowtie", true, (ConfigDescription)null); ModPatch.enableBowtie = config_enableBowtie.Value; config_enableChef = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Chef", true, (ConfigDescription)null); ModPatch.enableChef = config_enableChef.Value; config_enableClown = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Clown", true, (ConfigDescription)null); ModPatch.enableClown = config_enableClown.Value; config_enableHeadman = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Headman", true, (ConfigDescription)null); ModPatch.enableHeadman = config_enableHeadman.Value; config_enableHuntsman = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Huntsman", true, (ConfigDescription)null); ModPatch.enableHuntsman = config_enableHuntsman.Value; config_enableMentalist = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Mentalist", true, (ConfigDescription)null); ModPatch.enableMentalist = config_enableMentalist.Value; config_enableReaper = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Reaper", true, (ConfigDescription)null); ModPatch.enableReaper = config_enableReaper.Value; config_enableRobe = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Robe", true, (ConfigDescription)null); ModPatch.enableRobe = config_enableRobe.Value; config_enableRugrat = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Rugrat", true, (ConfigDescription)null); ModPatch.enableRugrat = config_enableRugrat.Value; config_enableShadowChild = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Shadow Child", true, (ConfigDescription)null); ModPatch.enableShadowChild = config_enableShadowChild.Value; config_enableSpewer = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Spewer", true, (ConfigDescription)null); ModPatch.enableSpewer = config_enableSpewer.Value; config_enableTrudge = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Trudge", true, (ConfigDescription)null); ModPatch.enableTrudge = config_enableTrudge.Value; config_enableUpscream = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Upscream", true, (ConfigDescription)null); ModPatch.enableUpscream = config_enableUpscream.Value; List<string> list = ListPluginFiles(); if (list.Contains("WesleysEnemies.dll")) { ModPatch.containModded = true; config_enableDestroyer = ((BaseUnityPlugin)this).Config.Bind<bool>("Wesleys Enemies", "Destroyer", true, (ConfigDescription)null); ModPatch.enableDestroyer = config_enableDestroyer.Value; config_enableDroid = ((BaseUnityPlugin)this).Config.Bind<bool>("Wesleys Enemies", "Droid", true, (ConfigDescription)null); ModPatch.enableDroid = config_enableDroid.Value; config_enableGusher = ((BaseUnityPlugin)this).Config.Bind<bool>("Wesleys Enemies", "Gusher", true, (ConfigDescription)null); ModPatch.enableGusher = config_enableGusher.Value; config_enableRoaster = ((BaseUnityPlugin)this).Config.Bind<bool>("Wesleys Enemies", "Roaster", true, (ConfigDescription)null); ModPatch.enableRoaster = config_enableRoaster.Value; config_enableSoldier = ((BaseUnityPlugin)this).Config.Bind<bool>("Wesleys Enemies", "The Soldier", true, (ConfigDescription)null); ModPatch.enableSoldier = config_enableSoldier.Value; } if (list.Contains("FreddyEnemy.dll")) { ModPatch.containModded = true; config_enableFreddyFazbear = ((BaseUnityPlugin)this).Config.Bind<bool>("Freddy Enemy", "Freddy Fazbear", true, (ConfigDescription)null); ModPatch.enableFreddyFazbear = config_enableFreddyFazbear.Value; } if (list.Contains("BaldiEnemy.dll")) { ModPatch.containModded = true; config_enableBaldi = ((BaseUnityPlugin)this).Config.Bind<bool>("Baldi Enemy", "Baldi", true, (ConfigDescription)null); ModPatch.enableBaldi = config_enableBaldi.Value; } if (list.Contains("Zelda_Moon_Mod.repobundle")) { ModPatch.containModded = true; config_enableZeldaMoon = ((BaseUnityPlugin)this).Config.Bind<bool>("Zelda Moon Mod", "The Moon", true, (ConfigDescription)null); ModPatch.enableMoon = config_enableZeldaMoon.Value; } if (list.Contains("RETEMINATOR.repobundle")) { ModPatch.containModded = true; config_enableRetermninator = ((BaseUnityPlugin)this).Config.Bind<bool>("RETERMINATOR", "Robot", true, (ConfigDescription)null); ModPatch.enableRobot = config_enableRetermninator.Value; } if (list.Contains("Rolling_Giant_Enemy.repobundle")) { ModPatch.containModded = true; config_enableRollinGiant = ((BaseUnityPlugin)this).Config.Bind<bool>("Rolling Giant Enemy", "Rolling Giant", true, (ConfigDescription)null); ModPatch.enableRollingGiant = config_enableRollinGiant.Value; } if (list.Contains("MCZombieMod.dll")) { ModPatch.containModded = true; config_enableMCZombie = ((BaseUnityPlugin)this).Config.Bind<bool>("Minecraft Zombie Mod", "Zombie", true, (ConfigDescription)null); ModPatch.enableZombie = config_enableMCZombie.Value; } if (list.Contains("DrillerKiller.dll")) { ModPatch.containModded = true; config_enableDrillerKiller = ((BaseUnityPlugin)this).Config.Bind<bool>("Driller Killer", "Driller Killer", true, (ConfigDescription)null); ModPatch.enableDriller = config_enableDrillerKiller.Value; } } public static List<string> ListPluginFiles() { if (config_showDebugLogs.Value) { Log.Info("Checking mods..."); } List<string> list = new List<string>(); string pluginPath = Paths.PluginPath; if (!Directory.Exists(pluginPath)) { Log.Error("Folder " + pluginPath + " not found!"); return null; } string[] files = Directory.GetFiles(pluginPath, "*.dll", SearchOption.AllDirectories); string[] files2 = Directory.GetFiles(pluginPath, "*.repobundle", SearchOption.AllDirectories); string[] array = files.Concat(files2).ToArray(); string[] array2 = array; foreach (string path in array2) { string fileName = Path.GetFileName(path); if (config_showDebugLogs.Value) { Log.Info("Mod found: " + fileName); } list.Add(fileName); } return list; } } public static class Log { public static ManualLogSource Source; public static void Init(ManualLogSource logger) { Source = logger; } public static void Info(object msg) { ManualLogSource source = Source; if (source != null) { source.LogInfo(msg); } } public static void Warn(object msg) { ManualLogSource source = Source; if (source != null) { source.LogWarning(msg); } } public static void Error(object msg) { ManualLogSource source = Source; if (source != null) { source.LogError(msg); } } }