Decompiled source of ReedMods v1.0.0

ReedMods.dll

Decompiled 6 months 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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ReedMods.Patches;
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: AssemblyTitle("ReedMods")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReedMods")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8e80f203-2d1e-459a-83d5-76df9c8cb21f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ReedMods
{
	[BepInPlugin("ReedDoesStuff.ReedMods", "ReedMods", "1.0.0.0")]
	public class ReedModsBase : BaseUnityPlugin
	{
		private const string modGUID = "ReedDoesStuff.ReedMods";

		private const string modName = "ReedMods";

		private const string modVersion = "1.0.0.0";

		private readonly Harmony harmony = new Harmony("ReedDoesStuff.ReedMods");

		internal static ReedModsBase Instance;

		internal ManualLogSource logSource;

		public static AssetBundle ReedModsAssets;

		internal static AudioClip[]? shovelSFX;

		internal bool allPlayersDeadPreviously;

		internal List<int> scrapIDsToKeep = new List<int>();

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logSource = Logger.CreateLogSource("ReedDoesStuff.ReedMods");
			logSource.LogInfo((object)"ReedMods woke up");
			harmony.PatchAll(typeof(ReedModsBase));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(KeepSomeItemsPatch));
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			ReedModsAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "reedmodsassets"));
			if ((Object)(object)ReedModsAssets == (Object)null)
			{
				logSource.LogError((object)"Failed to load reedmodsassets assets.");
				return;
			}
			shovelSFX = ReedModsAssets.LoadAssetWithSubAssets<AudioClip>("Assets/boing.mp3");
			harmony.PatchAll(typeof(ShovelSoundsPatch));
			logSource.LogInfo((object)"ReedMods finished loading");
		}
	}
}
namespace ReedMods.Patches
{
	[HarmonyPatch]
	internal class KeepSomeItemsPatch
	{
		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		[HarmonyPrefix]
		public static void PatchGameOverPre(RoundManager __instance)
		{
			ReedModsBase.Instance.logSource.LogInfo((object)"xxx DespawnPropsAtEndOfRound is about to start");
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				ReedModsBase.Instance.logSource.LogInfo((object)"xxx this aint a server, we out ✌\ufe0f");
				return;
			}
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			ReedModsBase.Instance.logSource.LogInfo((object)("xxx there are  " + array.Length + "items..."));
			List<GrabbableObject> list = array.Where((GrabbableObject obj) => obj.itemProperties.isScrap && obj.isInShipRoom).ToList();
			ReedModsBase.Instance.logSource.LogInfo((object)("xxx there are  " + list.Count + "scraps in ship..."));
			if (list.Count > 0)
			{
				List<GrabbableObject> list2 = list.Take(1).ToList();
				foreach (GrabbableObject item in list2)
				{
					ReedModsBase.Instance.logSource.LogInfo((object)("xxx keeping a lovely " + item.itemProperties.itemName));
					item.itemProperties.isScrap = false;
				}
				ReedModsBase.Instance.scrapIDsToKeep = list2.Select((GrabbableObject keeper) => keeper.itemProperties.itemId).ToList();
			}
			else
			{
				ReedModsBase.Instance.logSource.LogInfo((object)"xxx nothing to keep, big r.i.p.");
			}
		}

		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		[HarmonyPostfix]
		public static void PatchGameOverPost(RoundManager __instance)
		{
			ReedModsBase.Instance.logSource.LogInfo((object)"xxx DespawnPropsAtEndOfRound ended");
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			List<int> scrapIDsToKeep = ReedModsBase.Instance.scrapIDsToKeep;
			GrabbableObject[] array2 = array;
			foreach (GrabbableObject obj in array2)
			{
				if (scrapIDsToKeep.Where((int id) => id == obj.itemProperties.itemId).ToList().Count > 0)
				{
					obj.itemProperties.isScrap = true;
					ReedModsBase.Instance.logSource.LogInfo((object)("xxx marking " + obj.itemProperties.itemName + " back to scrap "));
					ReedModsBase.Instance.scrapIDsToKeep = new List<int>();
				}
			}
		}

		[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
		[HarmonyPrefix]
		public static void PatchHUDPre(HUDManager __instance)
		{
			ReedModsBase.Instance.logSource.LogInfo((object)"FillEndGameStats started");
			ReedModsBase.Instance.logSource.LogInfo((object)("All players dead is " + StartOfRound.Instance.allPlayersDead));
			ReedModsBase.Instance.allPlayersDeadPreviously = StartOfRound.Instance.allPlayersDead;
			StartOfRound.Instance.allPlayersDead = false;
			ReedModsBase.Instance.logSource.LogInfo((object)"Crashed?");
		}

		[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
		[HarmonyPostfix]
		public static void PatchHUDPost(HUDManager __instance)
		{
			ReedModsBase.Instance.logSource.LogInfo((object)"FillEndGameStats ended");
			ReedModsBase.Instance.logSource.LogInfo((object)("All players dead is " + StartOfRound.Instance.allPlayersDead));
			ReedModsBase.Instance.logSource.LogInfo((object)("All players dead previously is " + ReedModsBase.Instance.allPlayersDeadPreviously));
			StartOfRound.Instance.allPlayersDead = ReedModsBase.Instance.allPlayersDeadPreviously;
			ReedModsBase.Instance.logSource.LogInfo((object)"Crashed?");
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		public static void PatchGameOverText(StartOfRound __instance)
		{
			ReedModsBase.Instance.logSource.LogInfo((object)("GameOverDialogue currently is " + __instance.gameOverDialogue[1].bodyText));
			__instance.gameOverDialogue[1].bodyText = "We kept some items for you. xoxo";
			ReedModsBase.Instance.logSource.LogInfo((object)"Changed gameOverDialogue");
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void infiniteSprintPatch(ref float ___sprintMeter)
		{
			___sprintMeter = 1f;
		}
	}
	[HarmonyPatch(typeof(Shovel))]
	internal class ShovelSoundsPatch
	{
		[HarmonyPatch("HitShovelClientRpc")]
		[HarmonyPatch("HitShovel")]
		[HarmonyPrefix]
		public static void hitSFXPatch(ref AudioClip[] ___hitSFX)
		{
			AudioClip[] shovelSFX = ReedModsBase.shovelSFX;
			___hitSFX = shovelSFX;
		}
	}
	internal class SuckingPowerPatch
	{
	}
}