Decompiled source of PropHelper v0.2.2

PropHelper0.2.2.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using HarmonyLib;
using Mirror;
using UnityEngine;
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("PropHelper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PropHelper")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4e2a566f-e30c-4334-9dd7-6fca0cb529da")]
[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 PropHelper;

[BepInPlugin("cUtils.PropHelper", "PropHelper", "0.2.2")]
[BepInProcess("atlyss.exe")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ChatBehaviour), "Cmd_SendChatMessage")]
	public class Cmd_SendChatMessage_Patch
	{
		public static bool Prefix(ChatBehaviour __instance, ref string _message)
		{
			if (_message == null || !_message.StartsWith("/") || _message.StartsWith("//"))
			{
				return true;
			}
			string[] array = _message.Split(new char[1] { ' ' });
			string input = array[0].ToLower();
			switch (Regex.Replace(input, "<.*?>", ""))
			{
			case "/prophelperhelp":
			case "/phhelp":
				PropHelperHelp(__instance);
				return false;
			case "/propinfo":
			case "/phinfo":
			case "/phi":
				PropInfo(__instance);
				return false;
			case "/proptest":
				return false;
			case "/saveprops":
			case "/propsave":
			case "/phs":
				SaveProps(__instance);
				return false;
			case "/loadprops":
			case "/propload":
			case "/phl":
				LoadProps(__instance);
				return false;
			case "/moveprop":
			case "/propmove":
			case "/phm":
				MoveProp(__instance, array);
				return false;
			default:
				return true;
			}
		}

		public static void PropInfo(ChatBehaviour chat)
		{
			//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_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)
			GameObject[] array = PropMod.propManagers[Player._mainPlayer].placedProps.ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				GameObject val = array[i];
				string text = i + ": " + ((Object)val).name + ((object)val.transform.position/*cast due to .constrained prefix*/).ToString() + ((object)val.transform.rotation/*cast due to .constrained prefix*/).ToString();
				chat.New_ChatMessage(text);
			}
		}

		public static void SaveProps(ChatBehaviour chat)
		{
			//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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(Paths.ConfigPath, "PropHelper.txt");
			Stack<GameObject> placedProps = PropMod.propManagers[Player._mainPlayer].placedProps;
			foreach (GameObject item in placedProps)
			{
				string text = ((object)item).ToString();
				text = text.Substring(0, text.IndexOf('(')).ToLower();
				if (!text.Contains(" "))
				{
					text += " ";
				}
				string contents = text + ((object)item.transform.position/*cast due to .constrained prefix*/).ToString() + ((object)item.transform.rotation/*cast due to .constrained prefix*/).ToString() + "\n";
				File.AppendAllText(path, contents);
			}
			chat.New_ChatMessage("props saved");
		}

		public unsafe static void LoadProps(ChatBehaviour chat)
		{
			//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)
			if (!NetworkServer.active)
			{
				chat.New_ChatMessage("NetworkServer inactive");
				return;
			}
			string[] lines = GetLines(chat);
			string[] array = lines;
			Vector3 position = default(Vector3);
			Quaternion rotation = default(Quaternion);
			foreach (string text in array)
			{
				if (text.Length >= 5)
				{
					string text2 = text;
					text2 = text2.Replace("(", "");
					text2 = text2.Replace(",", "");
					text2 = text2.Replace(")", " ");
					string[] array2 = text2.Split(new char[1] { ' ' });
					string[] array3 = array2;
					foreach (string text3 in array3)
					{
						chat.New_ChatMessage(text3);
					}
					string text4 = array2[0];
					float num = float.Parse(array2[1]);
					float num2 = float.Parse(array2[2]);
					float num3 = float.Parse(array2[3]);
					float num4 = float.Parse(array2[4]);
					float num5 = float.Parse(array2[5]);
					float num6 = float.Parse(array2[6]);
					float num7 = float.Parse(array2[7]);
					GameObject val = PropMod.propPrefabs[text4];
					((Vector3)(ref position))..ctor(num, num2, num3);
					((Quaternion)(ref rotation))..ctor(num4, num5, num6, num7);
					chat.New_ChatMessage(text4);
					chat.New_ChatMessage(((object)(*(Vector3*)(&position))/*cast due to .constrained prefix*/).ToString());
					chat.New_ChatMessage(((object)(*(Quaternion*)(&rotation))/*cast due to .constrained prefix*/).ToString());
					PlaceProp(chat, text4, position, rotation);
				}
			}
			chat.New_ChatMessage("props loaded");
		}

		public static void MoveProp(ChatBehaviour chat, string[] inputArray)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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_011c: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			if (inputArray.Length != 1 && inputArray.Length != 4)
			{
				chat.New_ChatMessage("invalid input");
				return;
			}
			GameObject lastProp = GetLastProp(chat, pop: true);
			if ((Object)(object)lastProp == (Object)null)
			{
				return;
			}
			string name = ((Object)lastProp).name;
			Vector3 position;
			Quaternion rotation;
			if (inputArray.Length == 4)
			{
				float num;
				float num2;
				float num3;
				try
				{
					num = float.Parse(inputArray[1]);
					num2 = float.Parse(inputArray[2]);
					num3 = float.Parse(inputArray[3]);
				}
				catch (Exception ex)
				{
					chat.New_ChatMessage("e: " + ex.Message);
					return;
				}
				position = lastProp.transform.position;
				position.x += num;
				position.y += num2;
				position.z += num3;
				rotation = lastProp.transform.rotation;
			}
			else
			{
				Transform transform = ((Component)Player._mainPlayer).transform;
				position = transform.position + transform.forward * 5f + transform.up * -1f;
				rotation = transform.rotation;
			}
			NetworkServer.Destroy(lastProp);
			PlaceProp(chat, name, position, rotation);
		}

		public static void PlaceProp(ChatBehaviour chat, string name, Vector3 position, Quaternion rotation)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			name = name.ToLower();
			if (name.Contains("(clone)"))
			{
				name = name.Substring(0, name.IndexOf("("));
			}
			PlayerPropManager val = PropMod.propManagers[Player._mainPlayer];
			GameObject val2 = PropMod.propPrefabs[name];
			if ((Object)(object)val2 == (Object)null)
			{
				chat.New_ChatMessage("no prop with name " + name + " found");
				return;
			}
			GameObject val3 = Object.Instantiate<GameObject>(val2, position, rotation);
			SceneManager.MoveGameObjectToScene(val3, val.owner._playerMapInstance._loadedScene);
			val3.SetActive(true);
			NetworkConnection val4 = null;
			NetworkServer.Spawn(val3, val4);
			val.placedProps.Push(val3);
		}

		public static GameObject GetLastProp(ChatBehaviour chat, bool pop)
		{
			Stack<GameObject> placedProps = PropMod.propManagers[Player._mainPlayer].placedProps;
			GameObject val = (pop ? placedProps.Pop() : placedProps.Peek());
			if ((Object)(object)val == (Object)null)
			{
				chat.New_ChatMessage("no prop found");
				return null;
			}
			return val;
		}

		public static void PropTest(ChatBehaviour chat)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_005a: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			GameObject lastProp = GetLastProp(chat, pop: false);
			chat.New_ChatMessage(((object)lastProp.transform.localScale/*cast due to .constrained prefix*/).ToString());
			Bounds bounds = lastProp.GetComponent<Renderer>().bounds;
			float x = ((Bounds)(ref bounds)).size.x;
			Vector3 position = lastProp.transform.position;
			Vector3 position2 = default(Vector3);
			((Vector3)(ref position2))..ctor(position.x + x, position.y, position.z);
			Quaternion rotation = lastProp.transform.rotation;
			string name = ((Object)lastProp).name;
			NetworkServer.Destroy(lastProp);
			PlaceProp(chat, name, position2, rotation);
		}

		private static void PropHelperHelp(ChatBehaviour chat)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("<color=yellow>cUtils.PropHelper 0.2.2</color> /phhelp:");
			stringBuilder.AppendLine("<color=green>/propinfo:</color>");
			stringBuilder.AppendLine("<color=green>/phinfo:</color>");
			stringBuilder.AppendLine("<color=green>/phi:</color> display a list of places props with position, rotation.");
			stringBuilder.AppendLine("<color=green>/saveprops:</color>");
			stringBuilder.AppendLine("<color=green>/propsave:</color>");
			stringBuilder.AppendLine("<color=green>/phs:</color> save your placed props to a file in the config folder.");
			stringBuilder.AppendLine("atm you only can add to this savefile.");
			stringBuilder.AppendLine("<color=green>/loadprops:</color>");
			stringBuilder.AppendLine("<color=green>/propload:</color>");
			stringBuilder.AppendLine("<color=green>/phl:</color> load and place previously saved props.");
			stringBuilder.AppendLine("<color=green>/moveprop</color>");
			stringBuilder.AppendLine("<color=green>/propmove</color>");
			stringBuilder.AppendLine("<color=green>/phm</color> move your last placed prop to your current position.");
			stringBuilder.AppendLine("<color=green>/moveprop [x y z]</color>");
			stringBuilder.AppendLine("<color=green>/propmove [x y z]</color>");
			stringBuilder.AppendLine("<color=green>/phm [x y z]</color> move your last placed prop by given coordinates.");
			stringBuilder.AppendLine("<color=yellow>example:</color> /phm -3 2 1.5");
			stringBuilder.AppendLine("y is the vertical position.");
			chat.New_ChatMessage(stringBuilder.ToString());
		}

		private static string[] GetLines(ChatBehaviour chat)
		{
			string path = Path.Combine(Paths.ConfigPath, "PropHelper.txt");
			if (!File.Exists(path))
			{
				chat.New_ChatMessage("savefile not found");
				return null;
			}
			string[] array = File.ReadAllLines(path);
			if (array.Length < 1)
			{
				chat.New_ChatMessage("savefile empty");
				return null;
			}
			return array;
		}
	}

	private const string PLUGIN_GUID = "cUtils.PropHelper";

	private const string PLUGIN_NAME = "PropHelper";

	private const string PLUGIN_VERSION = "0.2.2";

	private const string FILE_NAME = "PropHelper.txt";

	private readonly Harmony harmony = new Harmony("cUtils.PropHelper");

	private void Awake()
	{
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin PropHelper is loaded!");
	}
}