OreoM.VLog.dll

Decompiled 3 weeks ago
using System;
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 BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("OreoM.VLog")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("3.0.2.0")]
[assembly: AssemblyInformationalVersion("3.0.2")]
[assembly: AssemblyProduct("VLog")]
[assembly: AssemblyTitle("OreoM.VLog")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VLog
{
	internal class CustomLogger : ILogListener, IDisposable, ILogHandler
	{
		private StreamWriter logWriter;

		private DateTime time = DateTime.Now;

		public CustomLogger(string sessionHash)
		{
			string text = Application.persistentDataPath + "\\VLogs";
			string destFileName = text + "\\Player_" + time.ToString("yyyy-MM-dd_HH-mm-ss") + "_" + sessionHash + ".log";
			Directory.CreateDirectory(text);
			File.Copy(Application.persistentDataPath + "\\Player.log", destFileName);
			logWriter = new StreamWriter(text + "\\Player_" + time.ToString("yyyy-MM-dd_HH-mm-ss") + "_" + sessionHash + ".log", append: true)
			{
				AutoFlush = true
			};
		}

		public void LogEvent(object sender, LogEventArgs args)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			logWriter.WriteLine($"[{args.Level}] {args.Source.SourceName}: {args.Data}");
		}

		public void LogUnity(string log, string stackTrace, LogType type)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			logWriter.WriteLine($"{type}: {log}\n{stackTrace}");
		}

		public void LogFormat(LogType logType, Object context, string format, params object[] args)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			logWriter.WriteLine($"{logType}: {string.Format(format, args)}");
		}

		public void LogException(Exception exception, Object context)
		{
			logWriter.WriteLine($"Exception: {exception}");
		}

		public void Dispose()
		{
			logWriter?.Dispose();
		}
	}
	[BepInPlugin("OreoM.VLog", "VLog", "3.0.2")]
	public class VLog : BaseUnityPlugin
	{
		public static bool isSessionValid = false;

		public static string sessionHash = "";

		internal static GameObject sessionHashHUDGO = null;

		internal static TextMeshProUGUI sessionHashHUD = null;

		internal static int counter = 0;

		private static CustomLogger vlogger = null;

		private bool isModded;

		private HashSet<string> allowedVanillaMods = new HashSet<string>
		{
			"chboo1.lethalcompany.hqfixes", "com.adibtw.loadstone", "com.fumiko.CullFactory", "com.github.tinyhoot.ShipLoot", "com.rune580.LethalCompanyInputUtils", "LCBetterSaves", "LightsOut", "mattymatty.TooManyItems", "MoreItems", "OreoM.HQoL.73",
			"OreoM.HQoL.72", "OreoM.VLog", "OreoM.ShipLootCruiser", "LethalRebinding", "ArlenFreii.40Arachnophobia", "quackandcheese.togglemute", "viviko.NoSellLimit", "Zaggy1024.PathfindingLib", "Zaggy1024.PathfindingLagFix", "SlushyRH.LethalCompany.FreeMoons",
			"com.github.zehsteam.StreamOverlays", "com.github.zehsteam.SellMyScrap", "com.github.zehsteam.SellMyScrap.v40-v72", "lekakid.lcfontpatcher", ".LCMaxSoundsFix", "MysticDEV.BetterCruiserSync", "LethalSpongeLegacy"
		};

		private HashSet<string> allowedModdedMods = new HashSet<string>
		{
			"atomic.terminalapi", "BCMECodeSecurityCheck", "Drinkable.BrutalCompanyMinus", "LethalNetworkAPI", "AudioKnight.StarlancerAIFix", "bauyrsaq.SynthesisAssembly", "evaisa.lethallib", "MaxWasUnavailable.LethalModDataLib", "imabatby.lethallevelloader", "CompanyCruiserFix",
			"DerelictMoonPlugin", "imabatby.lethaltoolbox", "JacobG5.JLL", "JacobG5.JLLItemModule", "JacobG5.WesleyMoonScripts", "LethalNetworkAPI", "ShowMoonPriceLLL", "Tomatobird.BluranceTerrainFix", "ViewExtension", "Yorimor.CustomStoryLogs",
			"Chaos.LCCutscene", "com.github.WhiteSpike.MoonDaySpeedMultiplierPatcher", "dev.ladyalice.dungenplus", "dev.ladyalice.dungenplus.loadstonepatch", "JacobG5.ReverbTriggerFix", "JacobG5.WesleyMoons", "LethalPerformance", "MW.MagicWesleyInteriors", "voxx.TerraMesh", "ScienceBird.UniversalRadar"
		};

		public static VLog Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"OreoM.VLog v3.0.2 has loaded!");
		}

		private void OnDestroy()
		{
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Expected O, but got Unknown
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Expected O, but got Unknown
			HashSet<string> merged = new HashSet<string>(allowedModdedMods);
			isModded = false;
			bool flag = Chainloader.PluginInfos.Keys.All((string pluginGuid) => allowedVanillaMods.Contains(pluginGuid));
			if (!flag)
			{
				merged.UnionWith(allowedModdedMods);
				isModded = Chainloader.PluginInfos.Keys.All((string pluginGuid) => merged.Contains(pluginGuid));
			}
			if (!flag && !isModded)
			{
				Logger.LogInfo((object)"Please make sure you're only using allowed mods.\nVLog detected the following mods: ");
				foreach (PluginInfo value in Chainloader.PluginInfos.Values)
				{
					Logger.LogInfo((object)$"{value.Metadata.GUID} - {value.Metadata.Name} {value.Metadata.Version}");
				}
			}
			if (!flag && !isModded)
			{
				return;
			}
			try
			{
				Logger.LogInfo((object)("Mods verified!\n" + $"Modded: {isModded}"));
				sessionHash = XXHash.Hash64(Chainloader.PluginInfos.Keys.Aggregate((string a, string n) => a + n)).ToString("x") + "#" + XXHash.Hash64(DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString()).ToString("x");
				isSessionValid = true;
				vlogger = new CustomLogger(sessionHash);
				Application.logMessageReceived += new LogCallback(vlogger.LogUnity);
				Application.logMessageReceivedThreaded += new LogCallback(vlogger.LogUnity);
				Debug.unityLogger.logHandler = (ILogHandler)(object)vlogger;
				Logger.Listeners.Clear();
				Logger.Listeners.Add((ILogListener)(object)vlogger);
			}
			catch (Exception ex)
			{
				Debug.LogException(ex);
			}
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("OreoM.VLog");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "OreoM.VLog";

		public const string PLUGIN_NAME = "VLog";

		public const string PLUGIN_VERSION = "3.0.2";
	}
}
namespace VLog.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDManagerPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void PostStart(HUDManager __instance)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			if (VLog.isSessionValid)
			{
				VLog.sessionHashHUDGO = Object.Instantiate<GameObject>(((Component)__instance.debugText).gameObject, __instance.HUDContainer.transform);
				VLog.sessionHashHUD = VLog.sessionHashHUDGO.GetComponent<TextMeshProUGUI>();
				((TMP_Text)VLog.sessionHashHUD).transform.localPosition = new Vector3(-320f, -180f, 0f);
				((TMP_Text)VLog.sessionHashHUD).alignment = (TextAlignmentOptions)1025;
				((TMP_Text)VLog.sessionHashHUD).font = ((TMP_Text)__instance.newProfitQuotaText).font;
				TextMeshProUGUI sessionHashHUD = VLog.sessionHashHUD;
				((TMP_Text)sessionHashHUD).fontSize = ((TMP_Text)sessionHashHUD).fontSize - 5f;
				((Graphic)VLog.sessionHashHUD).color = new Color(1f, 1f, 1f, 0.15f);
				TextMeshProUGUI sessionHashHUD2 = VLog.sessionHashHUD;
				string sessionHash = VLog.sessionHash;
				int num = ++VLog.counter;
				((TMP_Text)sessionHashHUD2).text = sessionHash + "#" + num;
				((Behaviour)VLog.sessionHashHUD).enabled = true;
			}
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	internal class MenuManagerPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void PostStart(MenuManager __instance)
		{
			if (VLog.isSessionValid)
			{
				((TMP_Text)__instance.versionNumberText).autoSizeTextContainer = true;
				TextMeshProUGUI versionNumberText = __instance.versionNumberText;
				((TMP_Text)versionNumberText).text = ((TMP_Text)versionNumberText).text + "(" + VLog.sessionHash + ")";
			}
			else
			{
				__instance.DisplayMenuNotification("Mods not on the allowed list detected, runs performed on this session won't be accepted.", "[ Back ]");
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}