Decompiled source of WobblyLifePlus v2.0.2

WobblyLifePlus.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace WobblyLifePlus.CriminalCareer;

[BepInPlugin("com.wobblylife.plus.criminal.finder", "Criminal Coordinate Finder", "1.0.0")]
public class CriminalCoordinateFinder : BaseUnityPlugin
{
	[Serializable]
	public class CriminalCoordinate
	{
		public string comment;

		public string category;

		public float posX;

		public float posY;

		public float posZ;
	}

	[Serializable]
	public class CoordinateList
	{
		public List<CriminalCoordinate> coordinates = new List<CriminalCoordinate>();
	}

	private bool showUI = true;

	private Vector3 currentPosition = Vector3.zero;

	private string currentComment = "";

	private string currentCategory = "note_spawn";

	private int selectedCategoryIndex = 0;

	private string[] categories = new string[12]
	{
		"note_spawn", "pickup", "delivery", "cache", "exchanger", "police_spawn", "limo_spawn", "chop_shop", "mayor_door", "mayor_desk",
		"mayor_spawn", "mayor_office_inside"
	};

	private string[] categoryNames = new string[12]
	{
		"Note Spawn", "Pickup", "Delivery", "Cache", "Exchanger", "Police Spawn", "Limo Spawn", "Chop Shop", "Mayor Door", "Mayor Desk",
		"Mayor Spawn", "Mayor Office Inside"
	};

	private List<CriminalCoordinate> savedCoordinates = new List<CriminalCoordinate>();

	private string saveFilePath;

	private Vector2 scrollPosition;

	private void Awake()
	{
		saveFilePath = Path.Combine(Paths.PluginPath, "WobblyLifePlus_Criminal_Coordinates.json");
		LoadCoordinates();
		Debug.Log((object)"[CriminalFinder] Initialized! Press F8 to toggle UI");
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)289))
		{
			showUI = !showUI;
		}
		if (showUI)
		{
			UpdatePlayerPosition();
		}
	}

	private void UpdatePlayerPosition()
	{
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>(true);
		foreach (MonoBehaviour val in array)
		{
			if (!((Object)(object)val != (Object)null) || !(((object)val).GetType().Name == "GameInstance"))
			{
				continue;
			}
			MethodInfo method = ((object)val).GetType().GetMethod("GetPlayerCharacters", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(method != null) || !(method.Invoke(val, null) is IList { Count: >0 } list))
			{
				continue;
			}
			foreach (object item in list)
			{
				Component val2 = (Component)((item is Component) ? item : null);
				if (!((Object)(object)val2 != (Object)null) || !((Object)(object)val2.gameObject != (Object)null))
				{
					continue;
				}
				MethodInfo method2 = ((object)val2).GetType().GetMethod("GetPlayerController", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (!(method2 != null))
				{
					continue;
				}
				object? obj = method2.Invoke(val2, null);
				Component val3 = (Component)((obj is Component) ? obj : null);
				if (!((Object)(object)val3 != (Object)null))
				{
					continue;
				}
				MethodInfo method3 = ((object)val3).GetType().GetMethod("IsLocal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (!(method3 != null) || !(bool)method3.Invoke(val3, null))
				{
					continue;
				}
				MethodInfo method4 = ((object)val2).GetType().GetMethod("GetPlayerBody", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method4 != null)
				{
					object? obj2 = method4.Invoke(val2, null);
					Component val4 = (Component)((obj2 is Component) ? obj2 : null);
					if ((Object)(object)val4 != (Object)null)
					{
						currentPosition = val4.transform.position;
						return;
					}
				}
				currentPosition = val2.transform.position;
				return;
			}
		}
		if ((Object)(object)Camera.main != (Object)null)
		{
			currentPosition = ((Component)Camera.main).transform.position;
		}
	}

	private void OnGUI()
	{
		//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)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: 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)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0391: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0488: Unknown result type (might be due to invalid IL or missing references)
		//IL_053b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
		if (!showUI)
		{
			return;
		}
		float num = 450f;
		float num2 = 680f;
		float num3 = 10f;
		float num4 = 10f;
		GUI.Box(new Rect(num3, num4, num, num2), "CRIMINAL COORDINATE FINDER [F8]");
		float num5 = num4 + 30f;
		GUI.Label(new Rect(num3 + 10f, num5, num - 20f, 20f), "CURRENT POSITION:");
		num5 += 20f;
		GUI.Label(new Rect(num3 + 10f, num5, num - 20f, 20f), "X: " + currentPosition.x.ToString("F2") + "  Y: " + currentPosition.y.ToString("F2") + "  Z: " + currentPosition.z.ToString("F2"));
		num5 += 25f;
		GUI.Label(new Rect(num3 + 10f, num5, num - 20f, 20f), "Category:");
		num5 += 20f;
		selectedCategoryIndex = GUI.SelectionGrid(new Rect(num3 + 10f, num5, num - 20f, 100f), selectedCategoryIndex, categoryNames, 4);
		currentCategory = categories[selectedCategoryIndex];
		num5 += 105f;
		GUI.Label(new Rect(num3 + 10f, num5, num - 20f, 20f), "Comment:");
		num5 += 20f;
		currentComment = GUI.TextField(new Rect(num3 + 10f, num5, num - 20f, 40f), currentComment);
		num5 += 45f;
		num5 += 10f;
		GUI.backgroundColor = Color.green;
		if (GUI.Button(new Rect(num3 + 10f, num5, num - 20f, 35f), "SAVE POSITION"))
		{
			SaveCurrentPosition();
		}
		num5 += 40f;
		GUI.backgroundColor = Color.yellow;
		if (GUI.Button(new Rect(num3 + 10f, num5, num - 20f, 35f), "EXPORT TO FILE + CLIPBOARD"))
		{
			ExportCoordinates();
		}
		num5 += 40f;
		GUI.backgroundColor = Color.white;
		GUI.Label(new Rect(num3 + 10f, num5, num - 20f, 20f), "SAVED (" + savedCoordinates.Count + "):");
		num5 += 20f;
		float num6 = Mathf.Min(savedCoordinates.Count * 60, 180);
		scrollPosition = GUI.BeginScrollView(new Rect(num3 + 10f, num5, num - 20f, num6), scrollPosition, new Rect(0f, 0f, num - 40f, (float)(savedCoordinates.Count * 60)));
		float num7 = 0f;
		for (int num8 = savedCoordinates.Count - 1; num8 >= 0; num8--)
		{
			CriminalCoordinate criminalCoordinate = savedCoordinates[num8];
			GUI.Box(new Rect(0f, num7, num - 40f, 55f), "");
			GUI.Label(new Rect(5f, num7 + 2f, num - 50f, 18f), "[" + criminalCoordinate.category + "] " + criminalCoordinate.comment);
			GUI.Label(new Rect(5f, num7 + 22f, num - 50f, 16f), "X:" + criminalCoordinate.posX.ToString("F2") + " Y:" + criminalCoordinate.posY.ToString("F2") + " Z:" + criminalCoordinate.posZ.ToString("F2"));
			if (GUI.Button(new Rect(num - 120f, num7 + 5f, 55f, 20f), "LOAD"))
			{
				LoadPosition(criminalCoordinate);
			}
			if (GUI.Button(new Rect(num - 60f, num7 + 5f, 50f, 20f), "DEL"))
			{
				savedCoordinates.RemoveAt(num8);
				SaveCoordinates();
			}
			num7 += 60f;
		}
		GUI.EndScrollView();
		num5 = num4 + num2 - 40f;
		GUI.Label(new Rect(num3 + 10f, num5, num - 20f, 30f), "F8 = Toggle | Walk to spot | Add comment | Save");
	}

	private void SaveCurrentPosition()
	{
		CriminalCoordinate criminalCoordinate = new CriminalCoordinate();
		criminalCoordinate.comment = currentComment;
		criminalCoordinate.category = currentCategory;
		criminalCoordinate.posX = currentPosition.x;
		criminalCoordinate.posY = currentPosition.y;
		criminalCoordinate.posZ = currentPosition.z;
		CriminalCoordinate item = criminalCoordinate;
		savedCoordinates.Add(item);
		SaveCoordinates();
		Debug.Log((object)string.Format("[CriminalFinder] Saved: [{0}] {1} at X:{2} Y:{3} Z:{4}", currentCategory, currentComment, currentPosition.x.ToString("F2"), currentPosition.y.ToString("F2"), currentPosition.z.ToString("F2")));
	}

	private void LoadPosition(CriminalCoordinate coord)
	{
		currentCategory = coord.category;
		currentComment = coord.comment;
		selectedCategoryIndex = Array.IndexOf(categories, coord.category);
		if (selectedCategoryIndex < 0)
		{
			selectedCategoryIndex = 0;
		}
	}

	private void ExportCoordinates()
	{
		string text = "=== WOBBLYLIFE+ CRIMINAL COORDINATES ===\n\n";
		string[] array = categories;
		foreach (string text2 in array)
		{
			text = text + "--- " + text2.ToUpper() + " ---\n";
			bool flag = false;
			foreach (CriminalCoordinate savedCoordinate in savedCoordinates)
			{
				if (savedCoordinate.category == text2)
				{
					text += $"// {savedCoordinate.comment}\nnew Vector3({savedCoordinate.posX:F2}f, {savedCoordinate.posY:F2}f, {savedCoordinate.posZ:F2}f),\n";
					flag = true;
				}
			}
			if (!flag)
			{
				text += "// (none)\n";
			}
			text += "\n";
		}
		string text3 = Path.Combine(Paths.PluginPath, "WobblyLifePlus_Criminal_Coordinates_Export.txt");
		try
		{
			File.WriteAllText(text3, text);
			Debug.Log((object)("[CriminalFinder] Exported to: " + text3));
		}
		catch
		{
		}
		GUIUtility.systemCopyBuffer = text;
		Debug.Log((object)"[CriminalFinder] Copied to clipboard!");
	}

	private void SaveCoordinates()
	{
		CoordinateList coordinateList = new CoordinateList();
		coordinateList.coordinates = savedCoordinates;
		CoordinateList coordinateList2 = coordinateList;
		try
		{
			File.WriteAllText(saveFilePath, JsonUtility.ToJson((object)coordinateList2, true));
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[CriminalFinder] Save error: " + ex.Message));
		}
	}

	private void LoadCoordinates()
	{
		if (!File.Exists(saveFilePath))
		{
			return;
		}
		try
		{
			string text = File.ReadAllText(saveFilePath);
			CoordinateList coordinateList = JsonUtility.FromJson<CoordinateList>(text);
			if (coordinateList != null && coordinateList.coordinates != null)
			{
				savedCoordinates = coordinateList.coordinates;
				Debug.Log((object)$"[CriminalFinder] Loaded {savedCoordinates.Count} coordinates");
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[CriminalFinder] Load error: " + ex.Message));
		}
	}
}