Decompiled source of FischywebTelli v1.0.0

Mods/Fiscyweb.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BoneLib;
using BoneLib.BoneMenu;
using FischywebRandomizerV2;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow.Interaction;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "Fischyweb Randomizer", "2.0.0", "Fischy", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("Fiscyweb")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Fiscyweb")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("44855026-b311-4ea1-841b-c75ec5a0b8a7")]
[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")]
namespace FischywebRandomizerV2;

public class Core : MelonMod
{
	[Serializable]
	public class SavedLocation
	{
		public string name;

		public Vector3 position;

		public float yaw;
	}

	[Serializable]
	private class SavedLocationList
	{
		public List<SavedLocation> items = new List<SavedLocation>();
	}

	private static Page page;

	private static Page savedPage;

	private static Page quickPage;

	private static MelonPreferences_Entry<bool> enabledPref;

	private static MelonPreferences_Entry<float> radiusPref;

	private static MelonPreferences_Entry<bool> keepRotationPref;

	private static MelonPreferences_Entry<string> savedLocationsPref;

	private static bool enabled = true;

	private static float radius = 50f;

	private static bool keepRotation = true;

	private static bool hasPrevious;

	private static Vector3 previousPosition;

	private static List<SavedLocation> savedLocations = new List<SavedLocation>();

	public override void OnInitializeMelon()
	{
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		MelonPreferences_Category val = MelonPreferences.CreateCategory("Fischyweb Randomizer");
		enabledPref = val.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		radiusPref = val.CreateEntry<float>("Radius", 50f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		keepRotationPref = val.CreateEntry<bool>("KeepRotation", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		enabled = enabledPref.Value;
		radius = Mathf.Max(2f, radiusPref.Value);
		keepRotation = keepRotationPref.Value;
		page = Page.Root.CreatePage("<color=#FF6A00><b>Fischyweb Telli</b></color>", new Color(1f, 0.25f, 0f), 0, true);
		page.CreateBool("Enabled", new Color(1f, 0.3f, 0f), enabled, (Action<bool>)delegate(bool v)
		{
			enabled = v;
			enabledPref.Value = v;
			MelonPreferences.Save();
		});
		page.CreateFloat("Random Radius", new Color(1f, 0.45f, 0.05f), radius, 2f, 10f, 500f, (Action<float>)delegate(float v)
		{
			radius = Mathf.Max(2f, v);
			radiusPref.Value = radius;
			MelonPreferences.Save();
		});
		page.CreateBool("Keep Rotation", new Color(1f, 0.6f, 0.15f), keepRotation, (Action<bool>)delegate(bool v)
		{
			keepRotation = v;
			keepRotationPref.Value = v;
			MelonPreferences.Save();
		});
		page.CreateFunction("<color=#FFD0B0><b>RANDOM TELEPORT</b></color>", Color.white, (Action)TeleportRandomly);
		page.CreateFunction("<color=#FFB070>RETURN TO PREVIOUS</color>", Color.white, (Action)ReturnToPrevious);
		page.CreateFunction("About", Color.white, (Action)delegate
		{
			Menu.DisplayDialog("Fischyweb Randomizer V2", "Random nearby teleporting with no cooldown.\n\nV2 keeps your current facing direction by default.\nRETURN TO PREVIOUS is the extra utility feature.", (Texture2D)null, (Action)null, (Action)null);
		});
		savedLocationsPref = val.CreateEntry<string>("SavedLocationsJson", "", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LoadSavedLocations();
		savedPage = page.CreatePage("Saved Locations", new Color(0.9f, 0.6f, 0.2f), 0, true);
		savedPage.CreateFunction("Save Current Location", Color.white, (Action)SaveCurrentLocation);
		savedPage.CreateFunction("Clear Saved Locations", Color.white, (Action)ClearSavedLocations);
		foreach (SavedLocation savedLocation in savedLocations)
		{
			SavedLocation copy = savedLocation;
			savedPage.CreateFunction(copy.name, Color.white, (Action)delegate
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				TeleportToSaved(copy.position, copy.yaw);
			});
		}
		quickPage = Page.Root.CreatePage("Quick Teleports", new Color(0.2f, 0.7f, 0.4f), 0, true);
		RebuildQuickPage();
		MelonLogger.Msg("[Fischyweb Randomizer] V2 loaded.");
	}

	private static void TeleportRandomly()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		if (enabled && !((Object)(object)Player.RigManager == (Object)null) && !((Object)(object)Player.Head == (Object)null))
		{
			if (!FindPoint(Player.Head.position, radius, out var point))
			{
				Menu.DisplayDialog("Fischyweb Randomizer", "No suitable landing point was found.", (Texture2D)null, (Action)null, (Action)null);
			}
			else
			{
				TeleportTo(point, savePrevious: true);
			}
		}
	}

	private static bool FindPoint(Vector3 origin, float range, out Vector3 point)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_0019: 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)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0061: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: 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_0172: Unknown result type (might be due to invalid IL or missing references)
		point = Vector3.zero;
		Vector3 val = default(Vector3);
		RaycastHit val2 = default(RaycastHit);
		for (int i = 0; i < 80; i++)
		{
			Vector2 insideUnitCircle = Random.insideUnitCircle;
			Vector2 normalized = ((Vector2)(ref insideUnitCircle)).normalized;
			float num = Mathf.Sqrt(Random.value) * range;
			((Vector3)(ref val))..ctor(origin.x + normalized.x * num, origin.y + 30f, origin.z + normalized.y * num);
			if (!Physics.Raycast(val, Vector3.down, ref val2, 70f, -1, (QueryTriggerInteraction)1) || Vector3.Angle(((RaycastHit)(ref val2)).normal, Vector3.up) > 50f)
			{
				continue;
			}
			Vector3 val3 = ((RaycastHit)(ref val2)).point + Vector3.up * 1.15f;
			Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapBox(val3, new Vector3(0.35f, 0.85f, 0.35f), Quaternion.identity, -1, (QueryTriggerInteraction)1));
			bool flag = false;
			Collider[] array2 = array;
			foreach (Collider val4 in array2)
			{
				if (!((Object)(object)val4 == (Object)null) && (!((Object)(object)Player.PhysicsRig != (Object)null) || !((Component)val4).transform.IsChildOf(((Component)Player.PhysicsRig).transform)))
				{
					flag = true;
					break;
				}
			}
			if (!flag && Vector3.Distance(origin, val3) > 2f)
			{
				point = val3;
				return true;
			}
		}
		return false;
	}

	private unsafe static void TeleportTo(Vector3 destination, bool savePrevious)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (savePrevious && (Object)(object)Player.Head != (Object)null)
			{
				previousPosition = Player.Head.position;
				hasPrevious = true;
			}
			if ((Object)(object)Player.PhysicsRig != (Object)null)
			{
				Player.PhysicsRig.ResetHands((Handedness)3);
			}
			Vector3 val = (keepRotation ? GetCurrentForward() : ((!((Object)(object)Player.RigManager != (Object)null)) ? GetCurrentForward() : ((Component)Player.RigManager).transform.forward));
			Player.RigManager.Teleport(destination, val, true);
			Vector3 val2 = destination;
			MelonLogger.Msg("[Fischyweb Randomizer] Teleported to " + ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString());
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[Fischyweb Randomizer] Teleport failed: " + ex);
		}
	}

	private static Vector3 GetCurrentForward()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		float y;
		if ((Object)(object)Player.Head != (Object)null)
		{
			y = Player.Head.eulerAngles.y;
		}
		else
		{
			if (!((Object)(object)Player.RigManager != (Object)null))
			{
				return Vector3.forward;
			}
			y = ((Component)Player.RigManager).transform.eulerAngles.y;
		}
		return Quaternion.Euler(0f, y, 0f) * Vector3.forward;
	}

	private static void ReturnToPrevious()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		if (!hasPrevious)
		{
			Menu.DisplayDialog("Fischyweb Randomizer", "No previous teleport location has been saved yet.", (Texture2D)null, (Action)null, (Action)null);
		}
		else
		{
			TeleportTo(previousPosition, savePrevious: false);
		}
	}

	private static void LoadSavedLocations()
	{
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		savedLocations.Clear();
		try
		{
			if (savedLocationsPref == null || string.IsNullOrEmpty(savedLocationsPref.Value))
			{
				return;
			}
			string[] array = savedLocationsPref.Value.Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
			string[] array2 = array;
			foreach (string text in array2)
			{
				try
				{
					string[] array3 = text.Split(new char[1] { '|' });
					if (array3.Length >= 3)
					{
						string name = array3[0];
						string[] array4 = array3[1].Split(new char[1] { ',' });
						if (array4.Length == 3)
						{
							float num = float.Parse(array4[0]);
							float num2 = float.Parse(array4[1]);
							float num3 = float.Parse(array4[2]);
							float yaw = float.Parse(array3[2]);
							savedLocations.Add(new SavedLocation
							{
								name = name,
								position = new Vector3(num, num2, num3),
								yaw = yaw
							});
						}
					}
				}
				catch
				{
				}
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("[Fischyweb Randomizer] Failed to load saved locations: " + ex);
		}
	}

	private static void SaveSavedLocations()
	{
		try
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (SavedLocation savedLocation in savedLocations)
			{
				string value = savedLocation.name.Replace('\n', ' ').Replace('|', ' ');
				stringBuilder.Append(value);
				stringBuilder.Append('|');
				stringBuilder.Append(savedLocation.position.x.ToString(CultureInfo.InvariantCulture));
				stringBuilder.Append(',');
				stringBuilder.Append(savedLocation.position.y.ToString(CultureInfo.InvariantCulture));
				stringBuilder.Append(',');
				stringBuilder.Append(savedLocation.position.z.ToString(CultureInfo.InvariantCulture));
				stringBuilder.Append('|');
				stringBuilder.Append(savedLocation.yaw.ToString(CultureInfo.InvariantCulture));
				stringBuilder.Append('\n');
			}
			savedLocationsPref.Value = stringBuilder.ToString();
			MelonPreferences.Save();
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("[Fischyweb Randomizer] Failed to save locations: " + ex);
		}
	}

	private static void SaveCurrentLocation()
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Player.Head == (Object)null && (Object)(object)Player.RigManager == (Object)null)
		{
			Menu.DisplayDialog("Fischyweb Telli", "Cannot determine current position.", (Texture2D)null, (Action)null, (Action)null);
			return;
		}
		Vector3 position;
		float y;
		if ((Object)(object)Player.Head != (Object)null)
		{
			position = Player.Head.position;
			y = Player.Head.eulerAngles.y;
		}
		else
		{
			Transform transform = ((Component)Player.RigManager).transform;
			position = transform.position;
			y = transform.eulerAngles.y;
		}
		string text = "Saved " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
		SavedLocation savedLocation = new SavedLocation
		{
			name = text,
			position = position,
			yaw = y
		};
		savedLocations.Add(savedLocation);
		SaveSavedLocations();
		if (savedPage != null)
		{
			SavedLocation copy = savedLocation;
			savedPage.CreateFunction(copy.name, Color.white, (Action)delegate
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				TeleportToSaved(copy.position, copy.yaw);
			});
		}
		if (quickPage != null)
		{
			SavedLocation copy2 = savedLocation;
			quickPage.CreateFunction(copy2.name, Color.white, (Action)delegate
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				TeleportToSaved(copy2.position, copy2.yaw);
			});
		}
		Menu.DisplayDialog("Fischyweb Telli", "Location saved: " + text, (Texture2D)null, (Action)null, (Action)null);
	}

	private static void ClearSavedLocations()
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		savedLocations.Clear();
		if (savedLocationsPref != null)
		{
			savedLocationsPref.Value = string.Empty;
			MelonPreferences.Save();
		}
		Menu.DisplayDialog("Fischyweb Telli", "All saved locations cleared. (Existing menu entries may persist until restart.)", (Texture2D)null, (Action)null, (Action)null);
		if (quickPage != null)
		{
			quickPage.CreateFunction("(Quick menu may contain stale entries) Refresh by restarting menu", Color.white, (Action)delegate
			{
				Menu.DisplayDialog("Fischyweb Telli", "Restart the game or toggle the mod to fully refresh menu entries.", (Texture2D)null, (Action)null, (Action)null);
			});
		}
	}

	private unsafe static void TeleportToSaved(Vector3 destination, float yaw)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Vector3 val = Quaternion.Euler(0f, yaw, 0f) * Vector3.forward;
			if ((Object)(object)Player.RigManager != (Object)null)
			{
				Player.RigManager.Teleport(destination, val, true);
			}
			Vector3 val2 = destination;
			MelonLogger.Msg("[Fischyweb Randomizer] Teleported to saved location " + ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString());
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[Fischyweb Randomizer] Teleport to saved failed: " + ex);
		}
	}

	private static void RebuildQuickPage()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		if (quickPage == null)
		{
			return;
		}
		int num = 0;
		int num2 = savedLocations.Count - 1;
		while (num2 >= 0 && num < 8)
		{
			SavedLocation savedLocation = savedLocations[num2];
			SavedLocation copy = savedLocation;
			quickPage.CreateFunction(copy.name, Color.white, (Action)delegate
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				TeleportToSaved(copy.position, copy.yaw);
			});
			num++;
			num2--;
		}
		quickPage.CreateFunction("Open Saved Locations (Full)", Color.white, (Action)delegate
		{
			Menu.DisplayDialog("Fischyweb Telli", "Open the Fischyweb Telli main page and select Saved Locations to manage them.", (Texture2D)null, (Action)null, (Action)null);
		});
	}

	public override void OnDeinitializeMelon()
	{
		MelonPreferences.Save();
	}
}