Decompiled source of Keep Scrap v1.0.1

KeepScrap.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyKeepScrap.Patches;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KeepScrap")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Lethal Company keep scrap mod")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+16ac3b983dfde7c556b5ba78228e75cac4a2af94")]
[assembly: AssemblyProduct("KeepScrap")]
[assembly: AssemblyTitle("KeepScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LethalCompanyKeepScrap
{
	[BepInPlugin("KeepScrap", "KeepScrap", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Bob123.LCM_KeepScrap";

		private const string modName = "Bob123 Lethal Company Keep Scrap Mod";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("Bob123.LCM_KeepScrap");

		private static Plugin Instance;

		private ManualLogSource mls;

		public void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = null;
			}
			mls = Logger.CreateLogSource("Bob123.LCM_KeepScrap");
			mls.LogInfo((object)"Plugin KeepScrap is loaded!");
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(DespawnPropsAtEndOfRoundPatch));
			harmony.PatchAll(typeof(FillEndGameStatsPatch));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "KeepScrap";

		public const string PLUGIN_NAME = "KeepScrap";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace LethalCompanyKeepScrap.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	[HarmonyPatch("FillEndGameStats")]
	internal class FillEndGameStatsPatch
	{
		private static bool Prefix(ref HUDManager __instance, EndOfGameStats stats)
		{
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Invalid comparison between Unknown and I4
			int num = 0;
			int num2 = 0;
			for (int i = 0; i < __instance.playersManager.allPlayerScripts.Length; i++)
			{
				PlayerControllerB val = __instance.playersManager.allPlayerScripts[i];
				((TMP_Text)__instance.statsUIElements.playerNamesText[i]).text = "";
				((Behaviour)__instance.statsUIElements.playerStates[i]).enabled = false;
				((TMP_Text)__instance.statsUIElements.playerNotesText[i]).text = "Notes: \n";
				if (val.disconnectedMidGame || val.isPlayerDead || val.isPlayerControlled)
				{
					if (val.isPlayerDead)
					{
						num++;
					}
					else if (val.isPlayerControlled)
					{
						num2++;
					}
					((TMP_Text)__instance.statsUIElements.playerNamesText[i]).text = __instance.playersManager.allPlayerScripts[i].playerUsername;
					((Behaviour)__instance.statsUIElements.playerStates[i]).enabled = true;
					__instance.statsUIElements.playerStates[i].sprite = ((!__instance.playersManager.allPlayerScripts[i].isPlayerDead) ? __instance.statsUIElements.aliveIcon : (((int)__instance.playersManager.allPlayerScripts[i].causeOfDeath != 10) ? __instance.statsUIElements.deceasedIcon : __instance.statsUIElements.missingIcon));
					for (int j = 0; j < 3 && j < stats.allPlayerStats[i].playerNotes.Count; j++)
					{
						TextMeshProUGUI val2 = __instance.statsUIElements.playerNotesText[i];
						((TMP_Text)val2).text = ((TMP_Text)val2).text + "* " + stats.allPlayerStats[i].playerNotes[j] + "\n";
					}
				}
				else
				{
					((TMP_Text)__instance.statsUIElements.playerNotesText[i]).text = "";
				}
			}
			((TMP_Text)__instance.statsUIElements.quotaNumerator).text = RoundManager.Instance.scrapCollectedInLevel.ToString();
			((TMP_Text)__instance.statsUIElements.quotaDenominator).text = RoundManager.Instance.totalScrapValueInLevel.ToString();
			((Behaviour)__instance.statsUIElements.allPlayersDeadOverlay).enabled = false;
			int num3 = 0;
			float num4 = (float)RoundManager.Instance.scrapCollectedInLevel / RoundManager.Instance.totalScrapValueInLevel;
			if (num2 == StartOfRound.Instance.connectedPlayersAmount + 1)
			{
				num3++;
			}
			else if (num > 1)
			{
				num3--;
			}
			if ((double)num4 >= 0.9900000095367432)
			{
				num3 += 2;
			}
			else if ((double)num4 >= 0.6000000238418579)
			{
				num3++;
			}
			else if ((double)num4 <= 0.25)
			{
				num3--;
			}
			switch (num3)
			{
			case -1:
				((TMP_Text)__instance.statsUIElements.gradeLetter).text = "D";
				break;
			case 0:
				((TMP_Text)__instance.statsUIElements.gradeLetter).text = "C";
				break;
			case 1:
				((TMP_Text)__instance.statsUIElements.gradeLetter).text = "B";
				break;
			case 2:
				((TMP_Text)__instance.statsUIElements.gradeLetter).text = "A";
				break;
			case 3:
				((TMP_Text)__instance.statsUIElements.gradeLetter).text = "S";
				break;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	[HarmonyPatch("DespawnPropsAtEndOfRound")]
	internal class DespawnPropsAtEndOfRoundPatch
	{
		private static bool Prefix(ref RoundManager __instance, bool despawnAllItems = false)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return false;
			}
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			for (int i = 0; i < array.Length; i++)
			{
				if (despawnAllItems || (!array[i].isHeld && !array[i].isInShipRoom) || array[i].deactivated)
				{
					if (array[i].isHeld && (Object)(object)array[i].playerHeldBy != (Object)null)
					{
						array[i].playerHeldBy.DropAllHeldItems(true, false);
					}
					((Component)array[i]).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
				else
				{
					array[i].scrapPersistedThroughRounds = true;
				}
				if (__instance.spawnedSyncedObjects.Contains(((Component)array[i]).gameObject))
				{
					__instance.spawnedSyncedObjects.Remove(((Component)array[i]).gameObject);
				}
			}
			GameObject[] array2 = GameObject.FindGameObjectsWithTag("TemporaryEffect");
			for (int j = 0; j < array2.Length; j++)
			{
				Object val = (Object)(object)array2[j];
				Object.Destroy(val);
			}
			return false;
		}
	}
}