Decompiled source of RevengeOfShalame v1.0.0

EvilShalame.dll

Decompiled 16 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 HarmonyLib;
using HutongGames.PlayMaker;
using MonoMod.RuntimeDetour;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("EvilShalame")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EvilShalame")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dbfb1655-0a85-4bdd-bc01-3fc1a9b76788")]
[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.akino.evilshalame", "Evil Shalame", "1.0")]
public class EvilShalame : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <CacheRoachPrefabNew>d__11 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public EvilShalame <>4__this;

		private AsyncOperationHandle<GameObject> <hornetPrefab>5__1;

		private GameObject <hornet>5__2;

		private MethodInfo <target>5__3;

		private Hook <unloadHook>5__4;

		private AsyncOperationHandle<SceneInstance> <process>5__5;

		private GameObject[] <rootObjects>5__6;

		private GameObject <foundObject>5__7;

		private GameObject[] <>s__8;

		private int <>s__9;

		private GameObject <obje>5__10;

		private GameObject[] <>s__11;

		private int <>s__12;

		private GameObject <obje>5__13;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <CacheRoachPrefabNew>d__11(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			<hornetPrefab>5__1 = default(AsyncOperationHandle<GameObject>);
			<hornet>5__2 = null;
			<target>5__3 = null;
			<unloadHook>5__4 = null;
			<process>5__5 = default(AsyncOperationHandle<SceneInstance>);
			<rootObjects>5__6 = null;
			<foundObject>5__7 = null;
			<>s__8 = null;
			<obje>5__10 = null;
			<>s__11 = null;
			<obje>5__13 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitUntil((Func<bool>)(() => (Object)(object)GameManager.instance != (Object)null));
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<hornetPrefab>5__1 = GameManager.instance.LoadHeroPrefab();
				<>2__current = <hornetPrefab>5__1;
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				<hornet>5__2 = Object.Instantiate<GameObject>(<hornetPrefab>5__1.Result);
				Object.DontDestroyOnLoad((Object)(object)<hornet>5__2);
				<target>5__3 = typeof(AssetBundle).GetMethod("UnloadAsync");
				<unloadHook>5__4 = new Hook((MethodBase)<target>5__3, typeof(EvilShalame).GetMethod("ForceUnloadFalse", BindingFlags.Static | BindingFlags.NonPublic));
				<>2__current = null;
				<>1__state = 3;
				return true;
			case 3:
				<>1__state = -1;
				<process>5__5 = Addressables.LoadSceneAsync((object)"Scenes/Dust_02", (LoadSceneMode)1, true, 100, (SceneReleaseMode)0);
				<>2__current = <process>5__5;
				<>1__state = 4;
				return true;
			case 4:
			{
				<>1__state = -1;
				SceneInstance result = <process>5__5.Result;
				Scene scene = ((SceneInstance)(ref result)).Scene;
				<rootObjects>5__6 = ((Scene)(ref scene)).GetRootGameObjects();
				<>s__8 = <rootObjects>5__6;
				for (<>s__9 = 0; <>s__9 < <>s__8.Length; <>s__9++)
				{
					<obje>5__10 = <>s__8[<>s__9];
					<obje>5__10.SetActive(false);
					<obje>5__10 = null;
				}
				<>s__8 = null;
				<foundObject>5__7 = null;
				<>s__11 = <rootObjects>5__6;
				for (<>s__12 = 0; <>s__12 < <>s__11.Length; <>s__12++)
				{
					<obje>5__13 = <>s__11[<>s__12];
					if (((Object)<obje>5__13).name.Contains("Roachfeeder Short"))
					{
						<foundObject>5__7 = <obje>5__13;
					}
					<obje>5__13 = null;
				}
				<>s__11 = null;
				if ((Object)(object)<foundObject>5__7 == (Object)null)
				{
					Log.LogError((object)"Could not find Roachfeeder...");
				}
				else
				{
					roachPrefab = Object.Instantiate<GameObject>(<foundObject>5__7);
					roachPrefab.SetActive(false);
					Object.DontDestroyOnLoad((Object)(object)roachPrefab);
				}
				<>2__current = Addressables.UnloadSceneAsync(<process>5__5, true);
				<>1__state = 5;
				return true;
			}
			case 5:
				<>1__state = -1;
				<unloadHook>5__4.Dispose();
				Object.Destroy((Object)(object)<hornet>5__2);
				Resources.UnloadUnusedAssets();
				GameManager.instance.UnloadHeroPrefab();
				<>4__this.ModifyRoachProperties();
				AudioListener.pause = false;
				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();
		}
	}

	[CompilerGenerated]
	private sealed class <SpawnRoach>d__10 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public EvilShalame <>4__this;

		private GameObject <hero>5__1;

		private int <face>5__2;

		private int <i>5__3;

		private Vector3 <pos>5__4;

		private GameObject <roachEnemy>5__5;

		private PlayMakerFSM <fsm>5__6;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <SpawnRoach>d__10(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<hero>5__1 = null;
			<roachEnemy>5__5 = null;
			<fsm>5__6 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				tryingToSpawnRoach = true;
				<>2__current = (object)new WaitUntil((Func<bool>)(() => (Object)(object)GameObject.Find("Evil Shalame") == (Object)null));
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)HeroController.instance == (Object)null)
				{
					tryingToSpawnRoach = false;
					return false;
				}
				<hero>5__1 = ((Component)HeroController.instance).gameObject;
				<face>5__2 = 1;
				if (!HeroController.instance.cState.facingRight)
				{
					<face>5__2 = -1;
				}
				<i>5__3 = 0;
				while (<i>5__3 < howMany.Value)
				{
					<pos>5__4 = <hero>5__1.transform.position + new Vector3(27f * (float)<face>5__2 + Random.Range(-1f, 1f), Random.Range(0f, 13f), 0f);
					<roachEnemy>5__5 = Object.Instantiate<GameObject>(roachPrefab, <pos>5__4, Quaternion.identity);
					((Object)<roachEnemy>5__5).name = "Evil Shalame";
					<roachEnemy>5__5.SetActive(true);
					<fsm>5__6 = FSMUtility.LocateMyFSM(<roachEnemy>5__5, "Control");
					<fsm>5__6.SendEvent("ALERT");
					<roachEnemy>5__5 = null;
					<fsm>5__6 = null;
					<i>5__3++;
				}
				tryingToSpawnRoach = false;
				<>2__current = null;
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				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();
		}
	}

	[CompilerGenerated]
	private sealed class <SpawnRoachFamily>d__14 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Scene scene;

		public EvilShalame <>4__this;

		private GameObject <foundObject>5__1;

		private GameObject[] <rootObjects>5__2;

		private PlayMakerFSM <fsm>5__3;

		private FsmState <state>5__4;

		private float <amount>5__5;

		private GameObject[] <>s__6;

		private int <>s__7;

		private GameObject <obje>5__8;

		private int <i>5__9;

		private double <angle>5__10;

		private GameObject <obj>5__11;

		private PlayMakerFSM <_fsm>5__12;

		private FsmState <_state>5__13;

		private HealthManager <hm>5__14;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <SpawnRoachFamily>d__14(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<foundObject>5__1 = null;
			<rootObjects>5__2 = null;
			<fsm>5__3 = null;
			<state>5__4 = null;
			<>s__6 = null;
			<obje>5__8 = null;
			<obj>5__11 = null;
			<_fsm>5__12 = null;
			<_state>5__13 = null;
			<hm>5__14 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<foundObject>5__1 = null;
				<rootObjects>5__2 = ((Scene)(ref scene)).GetRootGameObjects();
				<>s__6 = <rootObjects>5__2;
				for (<>s__7 = 0; <>s__7 < <>s__6.Length; <>s__7++)
				{
					<obje>5__8 = <>s__6[<>s__7];
					if (((Object)<obje>5__8).name.Contains("Roachfeeder Short"))
					{
						<foundObject>5__1 = <obje>5__8;
					}
					<obje>5__8 = null;
				}
				<>s__6 = null;
				<>2__current = null;
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)<foundObject>5__1 == (Object)null)
				{
					((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.SpawnRoach());
					return false;
				}
				<fsm>5__3 = FSMUtility.LocateMyFSM(<foundObject>5__1, "Control");
				<state>5__4 = <fsm>5__3.Fsm.GetState("Idle Fly");
				if (<state>5__4 == null)
				{
					Log.LogWarning((object)"State not found!");
					return false;
				}
				<state>5__4.Transitions = <state>5__4.Transitions.Where((FsmTransition t) => t.EventName != "ALERT").ToArray();
				<fsm>5__3.SetState("Idle Fly");
				<>2__current = null;
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				<amount>5__5 = 8f;
				<i>5__9 = 0;
				while ((float)<i>5__9 < <amount>5__5)
				{
					<angle>5__10 = Math.PI * 2.0 * (double)((float)<i>5__9 / <amount>5__5);
					<obj>5__11 = Object.Instantiate<GameObject>(<foundObject>5__1, <foundObject>5__1.transform.position + new Vector3((float)Math.Cos(<angle>5__10) * 4f, (float)Math.Sin(<angle>5__10) * 4f, 0f), Quaternion.identity);
					<_fsm>5__12 = FSMUtility.LocateMyFSM(<obj>5__11, "Control");
					<_state>5__13 = <_fsm>5__12.Fsm.GetState("Idle Fly");
					if (<_state>5__13 == null)
					{
						Log.LogWarning((object)"State not found!");
						return false;
					}
					<_state>5__13.Transitions = <_state>5__13.Transitions.Where((FsmTransition t) => t.EventName != "ALERT").ToArray();
					<_fsm>5__12.SetState("Idle Fly");
					<hm>5__14 = <obj>5__11.GetComponent<HealthManager>();
					<hm>5__14.TookDamage += <>4__this.HornetDie;
					<obj>5__11 = null;
					<_fsm>5__12 = null;
					<_state>5__13 = null;
					<hm>5__14 = null;
					<i>5__9++;
				}
				<foundObject>5__1.SetActive(false);
				<>2__current = null;
				<>1__state = 3;
				return true;
			case 3:
				<>1__state = -1;
				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();
		}
	}

	internal static ManualLogSource Log;

	private static GameObject roachPrefab;

	private static bool tryingToSpawnRoach;

	public static ConfigEntry<int> howMany;

	public static ConfigEntry<bool> GiveSilk;

	private const float horizontalDistance = 27f;

	private const float horizontalVariance = 1f;

	private const float verticalVariance = 13f;

	private void Awake()
	{
		AudioListener.pause = true;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"com.akino.evilshalame loaded and initialized.");
		Log = ((BaseUnityPlugin)this).Logger;
		roachPrefab = null;
		Harmony.CreateAndPatchAll(typeof(EvilShalame), (string)null);
		howMany = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Spawn Amount", 1, "Decides how many Shalames shall spawn at any given time. (Can be set to 0 to disable spawns completely)");
		GiveSilk = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Give Silk", true, "With this setting off, Shalames will no longer give silk. Restart game for changes to apply.");
		SceneManager.sceneLoaded += OnSceneLoaded;
		((MonoBehaviour)this).StartCoroutine(CacheRoachPrefabNew());
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)GameManager.instance != (Object)null && !GameManager.instance.IsNonGameplayScene() && !((Object)(object)roachPrefab == (Object)null) && !GameManager.instance.IsStagTravelScene())
		{
			if (((Scene)(ref scene)).name == "Dust_02")
			{
				((MonoBehaviour)this).StartCoroutine(SpawnRoachFamily(scene));
			}
			else if (!tryingToSpawnRoach)
			{
				((MonoBehaviour)this).StartCoroutine(SpawnRoach());
			}
		}
	}

	[IteratorStateMachine(typeof(<SpawnRoach>d__10))]
	private IEnumerator SpawnRoach()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <SpawnRoach>d__10(0)
		{
			<>4__this = this
		};
	}

	[IteratorStateMachine(typeof(<CacheRoachPrefabNew>d__11))]
	private IEnumerator CacheRoachPrefabNew()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <CacheRoachPrefabNew>d__11(0)
		{
			<>4__this = this
		};
	}

	private void ModifyRoachProperties()
	{
		HealthManager component = roachPrefab.GetComponent<HealthManager>();
		component.hp = int.MaxValue;
		Rigidbody2D component2 = roachPrefab.GetComponent<Rigidbody2D>();
		component2.bodyType = (RigidbodyType2D)1;
		component2.simulated = true;
		if (!GiveSilk.Value)
		{
			FieldInfo field = typeof(HealthManager).GetField("doNotGiveSilk", BindingFlags.Instance | BindingFlags.NonPublic);
			field.SetValue(component, true);
		}
		PlayMakerFSM val = FSMUtility.LocateMyFSM(roachPrefab, "Control");
		FsmState state = val.Fsm.GetState("Get In Range");
		if (state == null)
		{
			Log.LogWarning((object)"State not found!");
			return;
		}
		state.Transitions = state.Transitions.Where((FsmTransition t) => t.EventName != "UNALERT").ToArray();
	}

	private static AssetBundleUnloadOperation ForceUnloadFalse(Func<AssetBundle, bool, AssetBundleUnloadOperation> orig, AssetBundle self, bool unloadAllLoadedObjects)
	{
		return orig(self, arg2: false);
	}

	[IteratorStateMachine(typeof(<SpawnRoachFamily>d__14))]
	private IEnumerator SpawnRoachFamily(Scene scene)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <SpawnRoachFamily>d__14(0)
		{
			<>4__this = this,
			scene = scene
		};
	}

	private void HornetDie()
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		DamageTagInstance val = default(DamageTagInstance);
		val.amount = 9999;
		val.specialDamageType = (SpecialDamageTypes)0;
		val.isHeroDamage = true;
		HeroController.instance.ApplyTagDamage(val);
	}
}