Decompiled source of SaveShipItemsOnDeath v1.0.2

SaveShipItemsOnDeathMod.dll

Decompiled 11 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.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using SaveShipItemsOnDeathMod.Models;
using SaveShipItemsOnDeathMod.NetcodePatcher;
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("SaveShipItemsOnDeathMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SaveShipItemsOnDeathMod")]
[assembly: AssemblyTitle("SaveShipItemsOnDeathMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace SaveShipItemsOnDeathMod
{
	public static class DebugUtils
	{
		public static void LogNullOrNot(string varName, object value)
		{
			ModLogger.Instance.LogInfo((object)$"Variable {varName} null = {value == null}");
		}
	}
	public static class ModConfig
	{
		private const string ScrapFee_Percent_Description = "Percent to take from items cost as penalty. Min value is 0, means no fee. Max value is 100, means cost will reduce to 1.Since the game uses an integer for scrap value the final amount will be rounded.";

		public static ConfigEntry<int> ScrapFee_Percent;

		public static void Init()
		{
			PluginLoader.Instance.BindConfig(ref ScrapFee_Percent, "Penalty", "Scrap Fee", 50, "Percent to take from items cost as penalty. Min value is 0, means no fee. Max value is 100, means cost will reduce to 1.Since the game uses an integer for scrap value the final amount will be rounded.");
			ModLogger.Instance.LogInfo((object)$"Value loaded from config Penalty_ScrapFee={ScrapFee_Percent.Value}");
		}
	}
	internal static class ModLogger
	{
		public static ManualLogSource Instance { get; private set; }

		public static bool TrySetInstance(ManualLogSource instance)
		{
			if (Instance != null)
			{
				return false;
			}
			Instance = instance;
			return true;
		}
	}
	internal class ModVariables
	{
		public static ModVariables Instance { get; private set; }

		public bool IsAllPlayersDeadOverride { get; set; }

		public GameObject ModNetworkManagerGameObject { get; set; }

		public bool ShouldShowSavedItemsNotification { get; set; }

		public string SavedItemsTitle { get; set; }

		public string SavedItemsMessage { get; set; }

		public static bool TrySetInstance(ModVariables instance)
		{
			if (Instance != null)
			{
				return false;
			}
			Instance = instance;
			return true;
		}
	}
	public static class PenaltyApplier
	{
		public static PenaltyApplyResult Apply(int feePercent, ulong[] itemsNetworkIds = null)
		{
			ModLogger.Instance.LogDebug((object)("Fee percent to apply should be " + feePercent));
			if (itemsNetworkIds == null)
			{
				itemsNetworkIds = Array.Empty<ulong>();
			}
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			if (array == null)
			{
				ModLogger.Instance.LogError((object)"'allItemsOnLevel' is null");
				return new PenaltyApplyResult
				{
					TotalItemsCount = 0,
					TotalCostInitial = 0,
					TotalCostCurrent = 0,
					IsError = true,
					UpdatedItemsNetworkIds = Array.Empty<ulong>()
				};
			}
			GrabbableObject[] array2 = array.Where((GrabbableObject item) => itemsNetworkIds.Contains(((NetworkBehaviour)item).NetworkObjectId) || (item.isInShipRoom && item.grabbable && item.itemProperties.isScrap && !item.deactivated)).ToArray();
			if (array2.Length == 0)
			{
				ModLogger.Instance.LogInfo((object)"No items to apply price penalty to");
				return new PenaltyApplyResult
				{
					TotalItemsCount = 0,
					TotalCostInitial = 0,
					TotalCostCurrent = 0,
					UpdatedItemsNetworkIds = Array.Empty<ulong>()
				};
			}
			ModLogger.Instance.LogInfo((object)$"Found {array2.Length} items to apply price penalty to");
			int num = 0;
			int num2 = 0;
			List<ulong> list = new List<ulong>(array2.Length);
			GrabbableObject[] array3 = array2;
			foreach (GrabbableObject val in array3)
			{
				int scrapValue = val.scrapValue;
				num += scrapValue;
				if (val.scrapValue == 0)
				{
					ModLogger.Instance.LogInfo((object)("Initial scrap value for " + ((Object)val).name + " is 0. Skipping it"));
					continue;
				}
				int scrapValue2 = CalcNewScarpValue(val.scrapValue, feePercent);
				val.SetScrapValue(scrapValue2);
				num2 += val.scrapValue;
				list.Add(((NetworkBehaviour)val).NetworkObjectId);
				ModLogger.Instance.LogInfo((object)$"Scrap value was {scrapValue}, now {val.scrapValue} for '{((Object)val).name}' | networkId: {((NetworkBehaviour)val).NetworkObjectId}");
			}
			ModLogger.Instance.LogInfo((object)($"Value of scrap on the ship was cut by {feePercent}% due to crew death. " + $"Was {num}, now {num2}"));
			return new PenaltyApplyResult
			{
				TotalItemsCount = array2.Length,
				TotalCostInitial = num,
				TotalCostCurrent = num2,
				UpdatedItemsNetworkIds = list.ToArray()
			};
		}

		private static int CalcNewScarpValue(int originalValue, int percentToApply)
		{
			if (percentToApply == 0)
			{
				return originalValue;
			}
			if (originalValue == 1 || percentToApply == 100)
			{
				return 1;
			}
			float num = (float)percentToApply / 100f;
			float num2 = Mathf.Clamp((float)originalValue * num, 1f, (float)originalValue);
			int num3 = Mathf.RoundToInt(num2);
			return Math.Clamp(originalValue - num3, 1, originalValue);
		}
	}
	[BepInPlugin("Kirpichyov.SaveShipItemsOnDeath", "Kirpichyov's SaveShipItemsOnDeath", "1.0.2")]
	public class PluginLoader : BaseUnityPlugin
	{
		private const string ModGuid = "Kirpichyov.SaveShipItemsOnDeath";

		private const string ModName = "Kirpichyov's SaveShipItemsOnDeath";

		private const string ModVersion = "1.0.2";

		private readonly Harmony _harmony = new Harmony("Kirpichyov.SaveShipItemsOnDeath");

		public static PluginLoader Instance { get; private set; }

		private void Awake()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
			Instance = this;
			ModLogger.TrySetInstance(((BaseUnityPlugin)this).Logger);
			ModVariables.TrySetInstance(new ModVariables());
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "netcodemod");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			GameObject val2 = val.LoadAsset<GameObject>("Assets/NetcodeModding/SaveShipItemsOnDeathNetworkManager.prefab");
			val2.AddComponent<SaveShipItemsOnDeathModNetworkManager>();
			ModVariables.Instance.ModNetworkManagerGameObject = val2;
			ModConfig.Init();
			_harmony.PatchAll();
			ModLogger.Instance.LogInfo((object)"Kirpichyov's SaveShipItemsOnDeath loaded.");
		}

		public void BindConfig<T>(ref ConfigEntry<T> config, string section, string key, T defaultValue, string description = "")
		{
			config = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description);
		}
	}
	internal class SaveShipItemsOnDeathModNetworkManager : NetworkBehaviour
	{
		public NetworkVariable<int> ScrapFee_Percent = new NetworkVariable<int>(50, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public static SaveShipItemsOnDeathModNetworkManager Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			if (GameNetworkManager.Instance.isHostingGame)
			{
				ScrapFee_Percent.Value = Mathf.Clamp(ModConfig.ScrapFee_Percent.Value, 0, 100);
				ModLogger.Instance.LogInfo((object)"Host sending config to clients");
			}
			ModLogger.Instance.LogDebug((object)"ModNetworkManager Awake");
		}

		[ClientRpc]
		public void ApplyItemsPenaltyClientRpc(int serverTotalItemsCount, int serverTotalInitialCost, int serverTotalCurrentCost, string serverNetworkObjectIds)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1284146058u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, serverTotalItemsCount);
				BytePacker.WriteValueBitPacked(val2, serverTotalInitialCost);
				BytePacker.WriteValueBitPacked(val2, serverTotalCurrentCost);
				bool flag = serverNetworkObjectIds != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(serverNetworkObjectIds, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1284146058u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				ModLogger.Instance.LogInfo((object)"Received rpc for ApplyItemsPenaltyClientRpc");
				ModLogger.Instance.LogInfo((object)"[Control data from server]");
				ModLogger.Instance.LogDebug((object)$"IsServer={((NetworkBehaviour)this).IsServer};IsHost={((NetworkBehaviour)this).IsHost}");
				ModLogger.Instance.LogDebug((object)string.Format("{0}={1}", "serverTotalItemsCount", serverTotalItemsCount));
				ModLogger.Instance.LogDebug((object)string.Format("{0}={1}", "serverTotalInitialCost", serverTotalInitialCost));
				ModLogger.Instance.LogDebug((object)string.Format("{0}={1}", "serverTotalCurrentCost", serverTotalCurrentCost));
				ModLogger.Instance.LogInfo((object)("serverNetworkObjectIds=" + serverNetworkObjectIds));
				if (!((NetworkBehaviour)this).IsServer && !((NetworkBehaviour)this).IsHost)
				{
					ulong[] itemsNetworkIds = serverNetworkObjectIds.Split(';', StringSplitOptions.RemoveEmptyEntries).Select(ulong.Parse).ToArray();
					int value = Instance.ScrapFee_Percent.Value;
					PenaltyApplyResult penaltyApplyResult = PenaltyApplier.Apply(value, itemsNetworkIds);
					ModLogger.Instance.LogInfo((object)$"Client finished apply penalty. IsError={penaltyApplyResult.IsError}");
					ModLogger.Instance.LogInfo((object)"[Client data]");
					ModLogger.Instance.LogInfo((object)string.Format("{0}={1}", "TotalItemsCount", penaltyApplyResult.TotalItemsCount));
					ModLogger.Instance.LogInfo((object)string.Format("{0}={1}", "TotalCostInitial", penaltyApplyResult.TotalCostInitial));
					ModLogger.Instance.LogInfo((object)string.Format("{0}={1}", "TotalCostCurrent", penaltyApplyResult.TotalCostCurrent));
				}
			}
		}

		[ClientRpc]
		public void ShowItemsSavedNotificationOnReviveClientRpc(string title, string message)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3224913710u, val, (RpcDelivery)0);
				bool flag = title != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(title, false);
				}
				bool flag2 = message != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives));
				if (flag2)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(message, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3224913710u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				ModLogger.Instance.LogInfo((object)"Received rpc for ShowItemsSavedNotificationOnReviveClientRpc");
				ModVariables.Instance.ShouldShowSavedItemsNotification = true;
				ModVariables.Instance.SavedItemsTitle = title;
				ModVariables.Instance.SavedItemsMessage = message;
			}
		}

		protected override void __initializeVariables()
		{
			if (ScrapFee_Percent == null)
			{
				throw new Exception("SaveShipItemsOnDeathModNetworkManager.ScrapFee_Percent cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)ScrapFee_Percent).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)ScrapFee_Percent, "ScrapFee_Percent");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)ScrapFee_Percent);
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_SaveShipItemsOnDeathModNetworkManager()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1284146058u, new RpcReceiveHandler(__rpc_handler_1284146058));
			NetworkManager.__rpc_func_table.Add(3224913710u, new RpcReceiveHandler(__rpc_handler_3224913710));
		}

		private static void __rpc_handler_1284146058(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int serverTotalItemsCount = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref serverTotalItemsCount);
				int serverTotalInitialCost = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref serverTotalInitialCost);
				int serverTotalCurrentCost = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref serverTotalCurrentCost);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string serverNetworkObjectIds = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref serverNetworkObjectIds, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((SaveShipItemsOnDeathModNetworkManager)(object)target).ApplyItemsPenaltyClientRpc(serverTotalItemsCount, serverTotalInitialCost, serverTotalCurrentCost, serverNetworkObjectIds);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3224913710(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string title = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref title, false);
				}
				bool flag2 = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives));
				string message = null;
				if (flag2)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref message, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((SaveShipItemsOnDeathModNetworkManager)(object)target).ShowItemsSavedNotificationOnReviveClientRpc(title, message);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "SaveShipItemsOnDeathModNetworkManager";
		}
	}
}
namespace SaveShipItemsOnDeathMod.Patches
{
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatcher
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void AddToPrefabs(ref GameNetworkManager __instance)
		{
			((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(ModVariables.Instance.ModNetworkManagerGameObject);
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class MainPatch
	{
		[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
		[HarmonyPostfix]
		public static void PostFillEndGameStatsHook(HUDManager __instance)
		{
			ModLogger.Instance.LogDebug((object)"Disabling allPlayersDead overlay");
			((Behaviour)__instance.statsUIElements.allPlayersDeadOverlay).enabled = false;
		}

		[HarmonyPatch(typeof(StartOfRound), "AllPlayersHaveRevivedClientRpc")]
		[HarmonyPostfix]
		public static void ShowSavedItemsNotificationOnPurpose()
		{
			ModLogger.Instance.LogDebug((object)"StartOfRound.AllPlayersHaveRevivedClientRpc patch");
			ModLogger.Instance.LogDebug((object)$"ShouldShowSavedItemsNotification? {ModVariables.Instance.ShouldShowSavedItemsNotification}");
			if (ModVariables.Instance.ShouldShowSavedItemsNotification)
			{
				HUDManager.Instance.DisplayTip(ModVariables.Instance.SavedItemsTitle, ModVariables.Instance.SavedItemsMessage, false, false, "LC_Tip1");
				ModVariables.Instance.ShouldShowSavedItemsNotification = false;
				ModVariables.Instance.SavedItemsMessage = string.Empty;
				ModVariables.Instance.SavedItemsTitle = string.Empty;
			}
		}

		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		[HarmonyPrefix]
		public static void PreOnDespawnItemsHook()
		{
			if (GameNetworkManager.Instance.isHostingGame)
			{
				if (TimeOfDay.Instance.daysUntilDeadline == 0)
				{
					ModLogger.Instance.LogDebug((object)"Ignore patch logic. Days until deadline = 0.");
				}
				else if (StartOfRound.Instance.allPlayersDead)
				{
					StartOfRound.Instance.allPlayersDead = false;
					ModLogger.Instance.LogDebug((object)$"Pre DespawnPropsAtEndOfRound, set allPlayersDead={StartOfRound.Instance.allPlayersDead}");
					ModVariables.Instance.IsAllPlayersDeadOverride = true;
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		[HarmonyPostfix]
		public static void PostOnDespawnItemsHook(StartOfRound __instance)
		{
			if (!GameNetworkManager.Instance.isHostingGame || !ModVariables.Instance.IsAllPlayersDeadOverride)
			{
				return;
			}
			int value = SaveShipItemsOnDeathModNetworkManager.Instance.ScrapFee_Percent.Value;
			PenaltyApplyResult penaltyApplyResult = PenaltyApplier.Apply(value);
			if (penaltyApplyResult.IsError)
			{
				ModLogger.Instance.LogError((object)"Error returned in penalty result.");
				return;
			}
			__instance.allPlayersDead = true;
			ModVariables.Instance.IsAllPlayersDeadOverride = false;
			ModLogger.Instance.LogDebug((object)$"Post DespawnPropsAtEndOfRound, set allPlayersDead={StartOfRound.Instance.allPlayersDead}");
			if (penaltyApplyResult.TotalItemsCount != 0)
			{
				string title = "KIRPICHYOV IND. MESSAGE";
				string text = "Kirpichyov Ind. saved your items but have taken fees. " + $"Scrap prices were cut by {value}%. " + $"Total was {penaltyApplyResult.TotalCostInitial}, now {penaltyApplyResult.TotalCostCurrent}";
				HUDManager.Instance.AddTextToChatOnServer("[Notification] " + text, -1);
				string serverNetworkObjectIds = string.Join(';', penaltyApplyResult.UpdatedItemsNetworkIds);
				SaveShipItemsOnDeathModNetworkManager.Instance.ApplyItemsPenaltyClientRpc(serverTotalCurrentCost: penaltyApplyResult.TotalCostCurrent, serverTotalItemsCount: penaltyApplyResult.TotalItemsCount, serverTotalInitialCost: penaltyApplyResult.TotalCostInitial, serverNetworkObjectIds: serverNetworkObjectIds);
				SaveShipItemsOnDeathModNetworkManager.Instance.ShowItemsSavedNotificationOnReviveClientRpc(title, text);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatcher
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void SpawnNetManager(StartOfRound __instance)
		{
			if (((NetworkBehaviour)__instance).IsHost)
			{
				GameObject val = Object.Instantiate<GameObject>(ModVariables.Instance.ModNetworkManagerGameObject);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
}
namespace SaveShipItemsOnDeathMod.Models
{
	public class PenaltyApplyResult
	{
		public int TotalItemsCount { get; set; }

		public int TotalCostInitial { get; set; }

		public int TotalCostCurrent { get; set; }

		public bool IsError { get; set; }

		public ulong[] UpdatedItemsNetworkIds { get; set; }
	}
}
namespace SaveShipItemsOnDeathMod.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}