Decompiled source of PhysisMod v1.0.1

BepInEx/plugins/PhysisPlugin.dll

Decompiled 2 years ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("PhysisPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("The coolest plugin ever made.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PhysisPlugin")]
[assembly: AssemblyTitle("PhysisPlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace PhysisPlugin;

[BepInPlugin("com.physi.plugins.lethalcompany.physisplugin", "Physi's Mod", "1.0.1")]
public class PhysiPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch(ref Terminal __instance)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			if (!physiInstance.patchedNewTerminalData)
			{
				physiInstance.PatchIntoHelpMenu(__instance, ">PHYSI\nThe coolest menu in the game.\n");
				TerminalKeyword val = new TerminalKeyword();
				val.word = "physi";
				TerminalNode val2 = new TerminalNode();
				val2.displayText = "So you've found the coolest menu in the game.\nCongratulations, you win!\n\n\n\n";
				val2.clearPreviousText = true;
				val.specialKeywordResult = val2;
				TerminalKeyword[] allKeywords = CollectionExtensions.AddToArray<TerminalKeyword>(__instance.terminalNodes.allKeywords, val);
				__instance.terminalNodes.allKeywords = allKeywords;
				TerminalKeyword[] allKeywords2 = __instance.terminalNodes.allKeywords;
				foreach (TerminalKeyword val3 in allKeywords2)
				{
					((BaseUnityPlugin)physiInstance).Logger.LogInfo((object)("Keyword: " + val3.word));
				}
				physiInstance.patchedNewTerminalData = true;
			}
		}
	}

	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPatch()
		{
			((BaseUnityPlugin)physiInstance).Logger.LogInfo((object)"Patching Posters");
			Material[] materials = ((Renderer)GameObject.Find("HangarShip/Plane.001").GetComponent<MeshRenderer>()).materials;
			UpdateTexture(PosterPath, materials[0]);
			UpdateTexture(TipPath, materials[1]);
		}
	}

	public static PhysiPlugin physiInstance;

	private readonly Harmony harmony = new Harmony("com.physi.plugins.lethalcompany.physisplugin");

	private bool patchedNewTerminalData = false;

	public static string PosterPath;

	public static string TipPath;

	private void Awake()
	{
		physiInstance = this;
		List<string> list = Directory.GetDirectories(Paths.PluginPath, "posters", SearchOption.AllDirectories).ToList();
		foreach (string item in list)
		{
			if (item != "")
			{
				PosterPath = Directory.GetFiles(item, "posters.png")[0];
				TipPath = Directory.GetFiles(item, "tips.png")[0];
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Physi's Plugin is loaded!");
		harmony.PatchAll();
	}

	public void PatchIntoHelpMenu(Terminal terminalInstance, string patch)
	{
		string displayText = terminalInstance.terminalNodes.specialNodes[13].displayText;
		terminalInstance.terminalNodes.specialNodes[13].displayText = displayText.Replace(">OTHER", patch + "\n>OTHER");
	}

	private static void UpdateTexture(string file, Material material)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		Texture2D val = new Texture2D(2, 2);
		((BaseUnityPlugin)physiInstance).Logger.LogInfo((object)("Patching " + ((Object)material).name + " with " + file));
		ImageConversion.LoadImage(val, File.ReadAllBytes(file));
		material.mainTexture = (Texture)(object)val;
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "PhysisPlugin";

	public const string PLUGIN_NAME = "PhysisPlugin";

	public const string PLUGIN_VERSION = "1.0.0";
}