Decompiled source of LethalLogger v1.0.2

LethalLogger.dll

Decompiled 7 months 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 BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLogger.Patches;
using Newtonsoft.Json;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LethalLogger")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalLogger")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("64d6efdc-fcbf-4541-96d1-39535ad70f41")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LethalLogger
{
	[BepInPlugin("Garageman.LethalLogger", "LC Tutorial", "1.0.0")]
	public class LethalLoggerBase : BaseUnityPlugin
	{
		private const string modGUID = "Garageman.LethalLogger";

		private const string modName = "LC Tutorial";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Garageman.LethalLogger");

		private static LethalLoggerBase Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Garageman.LethalLogger");
			mls.LogInfo((object)"LethalLogger is awake");
			harmony.PatchAll(typeof(LethalLoggerBase));
			harmony.PatchAll(typeof(ShipExitPatch));
		}
	}
}
namespace LethalLogger.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class ShipExitPatch
	{
		public class RoundInfo
		{
			public int living;

			public int dead;

			public int quota;

			public int scrapMax;

			public int scrapReal;

			public int daysRemaining;

			public string planetName;

			public string weather;

			public string seed;

			public List<string> unlockables = new List<string>();

			public IDictionary<string, int> gear = new Dictionary<string, int>();

			public IDictionary<string, string> playerStatus = new Dictionary<string, string>();
		}

		[HarmonyPatch("ShipHasLeft")]
		[HarmonyPrefix]
		private static void PrintoutExitPatch(StartOfRound __instance)
		{
			RoundInfo roundInfo = new RoundInfo();
			ManualLogSource val = Logger.CreateLogSource("LethalLogger");
			PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>();
			foreach (PlayerControllerB val2 in array)
			{
				if ((Object)(object)val2 != (Object)null && (val2.isPlayerControlled || val2.isPlayerDead))
				{
					if (val2.isPlayerDead)
					{
						roundInfo.dead++;
						roundInfo.playerStatus[val2.playerUsername] = ((object)(CauseOfDeath)(ref val2.causeOfDeath)).ToString();
					}
					else
					{
						roundInfo.living++;
						roundInfo.playerStatus[val2.playerUsername] = "Alive";
					}
				}
			}
			GrabbableObject[] array2 = Object.FindObjectsOfType<GrabbableObject>();
			foreach (GrabbableObject val3 in array2)
			{
				if ((Object)(object)val3 != (Object)null && val3.scrapValue == 0)
				{
					if (roundInfo.gear.ContainsKey(((object)val3).GetType().Name))
					{
						roundInfo.gear[((object)val3).GetType().Name]++;
					}
					else
					{
						roundInfo.gear[((object)val3).GetType().Name] = 1;
					}
				}
			}
			foreach (UnlockableItem unlockable in __instance.unlockablesList.unlockables)
			{
				if (unlockable.hasBeenUnlockedByPlayer)
				{
					val.LogInfo((object)unlockable.unlockableName);
					roundInfo.unlockables.Add(unlockable.unlockableName);
				}
			}
			roundInfo.scrapMax = __instance.GetValueOfAllScrap(false);
			roundInfo.scrapReal = __instance.GetValueOfAllScrap(true);
			roundInfo.planetName = __instance.currentLevel.PlanetName;
			roundInfo.weather = ((object)(LevelWeatherType)(ref __instance.currentLevel.currentWeather)).ToString();
			TimeOfDay val4 = Object.FindObjectOfType<TimeOfDay>();
			roundInfo.quota = val4.profitQuota;
			roundInfo.daysRemaining = val4.daysUntilDeadline;
			roundInfo.seed = __instance.randomMapSeed.ToString();
			Directory.CreateDirectory("LethalLoggerOutput");
			string arg = DateTime.Today.ToString("dd-mm-yyyy");
			string path = $"LethalLoggerOutput/LethalLoggerOut{arg}.json";
			try
			{
				if (File.Exists(path))
				{
					List<RoundInfo> obj = JsonConvert.DeserializeObject<List<RoundInfo>>(File.ReadAllText(path)) ?? new List<RoundInfo>();
					obj.Add(roundInfo);
					string contents = JsonConvert.SerializeObject((object)obj);
					File.WriteAllText(path, contents);
				}
				else
				{
					string contents2 = JsonConvert.SerializeObject((object)new List<RoundInfo> { roundInfo });
					File.WriteAllText(path, contents2);
				}
				val.LogInfo((object)"logged successfully");
			}
			catch (Exception ex)
			{
				val.LogWarning((object)ex);
			}
		}
	}
}