Decompiled source of Level Loader v1.1.0

StickLevelLoader.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("StickFightTheGameMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StickFightTheGameMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("07ad7751-658e-41ea-b1ee-8a7e59ffbe73")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace stickfightlevellib;

[BepInPlugin("sftg.bayturtleking.levellib", "TurtLevelLoader", "1.0.0")]
public class lvllibrary : BaseUnityPlugin
{
	public const string theguid = "sftg.bayturtleking.levellib";

	internal static lvllibrary onlyone;

	private void Awake()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		onlyone = this;
		new Harmony("sftg.bayturtleking.levellib").PatchAll();
	}

	internal void yap(string msg)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)msg);
	}

	internal void yell(string msg)
	{
		((BaseUnityPlugin)this).Logger.LogError((object)msg);
	}
}
public static class thelibrary
{
	internal class aworldwerecool
	{
		public string categoryname;

		public byte secretbyte;

		public int[] thefakeids;

		public string stolenfrom;

		public GameObject tabtabtab;
	}

	internal class asceneyo
	{
		public AssetBundle dabundlee;

		public string scenepath;

		public byte[] maybepic;
	}

	internal static readonly Dictionary<string, aworldwerecool> worldsbyname = new Dictionary<string, aworldwerecool>();

	internal static readonly Dictionary<byte, aworldwerecool> worldsbysecretbyte = new Dictionary<byte, aworldwerecool>();

	internal static readonly Dictionary<int, asceneyo> scenesbyfakeid = new Dictionary<int, asceneyo>();

	private static byte nextsecretbyte = 200;

	private static int nextfakeid = 90000;

	public static int howmanyfakescenesrn;

	public static int[] addworld(string categoryname, AssetBundle dabundlee, string[] thescenepaths, string[] mapnamesmaybe = null, byte[][] picsmaybe = null, string whoarewestealingfrom = "Halloween")
	{
		if (string.IsNullOrEmpty(categoryname))
		{
			throw new ArgumentException("categoryname required, obviously");
		}
		if ((Object)(object)dabundlee == (Object)null)
		{
			throw new ArgumentException("dabundlee required, its in the name");
		}
		if (thescenepaths == null || thescenepaths.Length == 0)
		{
			throw new ArgumentException("thescenepaths required");
		}
		string key = categoryname.ToLowerInvariant();
		if (worldsbyname.ContainsKey(key))
		{
			lvllibrary.onlyone?.yell("world '" + categoryname + "' already got added you cant have two of the same");
			return worldsbyname[key].thefakeids;
		}
		int[] array = new int[thescenepaths.Length];
		for (int i = 0; i < thescenepaths.Length; i++)
		{
			int key2 = (array[i] = nextfakeid++);
			scenesbyfakeid[key2] = new asceneyo
			{
				dabundlee = dabundlee,
				scenepath = thescenepaths[i],
				maybepic = ((picsmaybe != null && picsmaybe.Length > i) ? picsmaybe[i] : null)
			};
		}
		byte b = nextsecretbyte++;
		aworldwerecool value = new aworldwerecool
		{
			categoryname = categoryname,
			secretbyte = b,
			thefakeids = array,
			stolenfrom = whoarewestealingfrom
		};
		worldsbyname[key] = value;
		worldsbysecretbyte[b] = value;
		lvllibrary.onlyone?.yap("added '" + categoryname + "' with " + array.Length + " maps, sb " + b);
		return array;
	}
}
[HarmonyPatch(typeof(MapSelectionHandler), "InitMapList")]
public static class cloneerup
{
	private static void Prefix(MapSelectionHandler __instance)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		MapCategoryTAG[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<MapCategoryTAG>(true);
		if (componentsInChildren.Length == 0)
		{
			return;
		}
		RectTransform[] array = (from t in componentsInChildren
			select ((Component)t).GetComponent<RectTransform>() into r
			where (Object)(object)r != (Object)null
			select r).ToArray();
		if (array.Length == 0)
		{
			return;
		}
		Rect rect = array[0].rect;
		float num = ((Rect)(ref rect)).height;
		if (array.Length > 1)
		{
			RectTransform[] array2 = array.OrderByDescending((RectTransform r) => r.anchoredPosition.y).ToArray();
			float num2 = Mathf.Abs(array2[0].anchoredPosition.y - array2[1].anchoredPosition.y);
			if (num2 > 1f)
			{
				num = num2;
			}
		}
		float num3 = array.Min((RectTransform r) => r.anchoredPosition.y);
		foreach (KeyValuePair<string, thelibrary.aworldwerecool> item in thelibrary.worldsbyname)
		{
			thelibrary.aworldwerecool theworld = item.Value;
			if (!((Object)(object)theworld.tabtabtab != (Object)null) && !componentsInChildren.Any((MapCategoryTAG tag) => ((Object)tag).name.Equals(theworld.categoryname, StringComparison.OrdinalIgnoreCase)))
			{
				MapCategoryTAG val = ((IEnumerable<MapCategoryTAG>)componentsInChildren).FirstOrDefault((Func<MapCategoryTAG, bool>)((MapCategoryTAG tag) => ((Object)tag).name.Equals(theworld.stolenfrom, StringComparison.OrdinalIgnoreCase))) ?? componentsInChildren[0];
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent, false);
				((Object)val2).name = theworld.categoryname;
				num3 -= num;
				RectTransform component = val2.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					Vector2 anchoredPosition = component.anchoredPosition;
					anchoredPosition.y = num3;
					component.anchoredPosition = anchoredPosition;
				}
				Transform val3 = val2.transform.Find("Toggle");
				TextMeshProUGUI val4 = (((Object)(object)val3 != (Object)null) ? ((Component)val3).GetComponentInChildren<TextMeshProUGUI>() : null);
				if ((Object)(object)val4 != (Object)null)
				{
					((TMP_Text)val4).text = theworld.categoryname.ToUpperInvariant();
				}
				val2.SetActive(true);
				theworld.tabtabtab = val2;
			}
		}
	}
}
[HarmonyPatch(typeof(MapSelectionHandler), "FindFreeWorldEnum", new Type[] { typeof(string) })]
public static class enummmmmmmmmmmm
{
	private static void Postfix(string current, ref MapWorldsEnum __result)
	{
		if (!string.IsNullOrEmpty(current) && thelibrary.worldsbyname.TryGetValue(current.ToLowerInvariant(), out var value))
		{
			__result = (MapWorldsEnum)value.secretbyte;
		}
	}
}
[HarmonyPatch(typeof(MapSelectionHandler), "InitMapList")]
public static class addtextstuff
{
	private static void Postfix()
	{
		foreach (KeyValuePair<string, thelibrary.aworldwerecool> item in thelibrary.worldsbyname)
		{
			thelibrary.aworldwerecool value = item.Value;
			if (!((Object)(object)value.tabtabtab == (Object)null))
			{
				Transform val = value.tabtabtab.transform.Find("Toggle");
				TextMeshProUGUI val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentInChildren<TextMeshProUGUI>() : null);
				if ((Object)(object)val2 != (Object)null)
				{
					((TMP_Text)val2).text = value.categoryname.ToUpperInvariant();
				}
			}
		}
	}
}
[HarmonyPatch(typeof(MapSelectionHandler), "InitMapList")]
public static class fixthesquishing
{
	private static void Postfix(MapSelectionHandler __instance)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		MapCategoryTAG[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<MapCategoryTAG>(true);
		if (componentsInChildren.Length == 0)
		{
			return;
		}
		Transform parent = ((Component)componentsInChildren[0]).transform.parent;
		RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Canvas componentInParent = ((Component)val).GetComponentInParent<Canvas>();
		if (!((Object)(object)componentInParent == (Object)null))
		{
			Transform transform = ((Component)componentInParent).transform;
			Transform obj = ((transform is RectTransform) ? transform : null);
			LayoutRebuilder.ForceRebuildLayoutImmediate(val);
			Bounds val2 = RectTransformUtility.CalculateRelativeRectTransformBounds(obj, (Transform)(object)val);
			float y = ((Bounds)(ref val2)).size.y;
			Rect rect = ((RectTransform)obj).rect;
			float height = ((Rect)(ref rect)).height;
			Debug.Log((object)("squishcheck needed=" + y + " available=" + height + " listname=" + ((Object)val).name));
			if (!(y <= height))
			{
				float num = Mathf.Clamp(height / y, 0.4f, 1f);
				((Transform)val).localScale = new Vector3(num, num, 1f);
			}
		}
	}
}
[HarmonyPatch(typeof(LevelSelection), "GetLevelsWithWorld", new Type[] { typeof(MapWorldsEnum) })]
public static class levelstuff
{
	private static void Postfix(MapWorldsEnum world, ref int[] __result)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected I4, but got Unknown
		if (thelibrary.worldsbysecretbyte.TryGetValue((byte)(int)world, out var value))
		{
			__result = value.thefakeids;
		}
	}
}
[HarmonyPatch(typeof(LevelSelection), "GetImageDataForMapWithIndex", new Type[] { typeof(int) })]
public static class gimmemypicpatch
{
	private static bool Prefix(int index, ref byte[] __result)
	{
		if (thelibrary.scenesbyfakeid.TryGetValue(index, out var value) && value.maybepic != null)
		{
			__result = value.maybepic;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(SceneManager))]
[HarmonyPatch("LoadScene", new Type[]
{
	typeof(int),
	typeof(LoadSceneMode)
})]
public static class changeofscenes
{
	private static bool Prefix(int sceneBuildIndex, LoadSceneMode mode)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		if (!thelibrary.scenesbyfakeid.TryGetValue(sceneBuildIndex, out var value))
		{
			return true;
		}
		thelibrary.howmanyfakescenesrn++;
		SceneManager.LoadScene(value.scenepath, mode);
		return false;
	}
}
[HarmonyPatch(typeof(SceneManager))]
[HarmonyPatch("UnloadScene", new Type[] { typeof(int) })]
public static class doacleanup
{
	private static bool Prefix(int sceneBuildIndex)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if (!thelibrary.scenesbyfakeid.TryGetValue(sceneBuildIndex, out var value))
		{
			return true;
		}
		Scene sceneByPath = SceneManager.GetSceneByPath(value.scenepath);
		if (((Scene)(ref sceneByPath)).IsValid() && ((Scene)(ref sceneByPath)).isLoaded)
		{
			SceneManager.UnloadSceneAsync(sceneByPath);
			if (thelibrary.howmanyfakescenesrn > 0)
			{
				thelibrary.howmanyfakescenesrn--;
			}
		}
		return false;
	}
}
[HarmonyPatch(typeof(SceneManager))]
[HarmonyPatch("GetSceneByBuildIndex", new Type[] { typeof(int) })]
public static class dontthrowplz
{
	private static bool Prefix(int buildIndex, ref Scene __result)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		if (!thelibrary.scenesbyfakeid.TryGetValue(buildIndex, out var value))
		{
			return true;
		}
		__result = SceneManager.GetSceneByPath(value.scenepath);
		return false;
	}
}
[HarmonyPatch(typeof(Enum), "ToString", new Type[] { })]
public static class fixthatnaming
{
	private static void Postfix(object __instance, ref string __result)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected I4, but got Unknown
		if (__instance is MapWorldsEnum val && thelibrary.worldsbysecretbyte.TryGetValue((byte)(int)val, out var value))
		{
			__result = value.categoryname;
		}
	}
}