Decompiled source of REPOLocalFixes v0.0.1

REPOLocalFixes.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("REPOLocalFixes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("REPOLocalFixes")]
[assembly: AssemblyTitle("REPOLocalFixes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 REPOLocalFixes
{
	public class Configs
	{
		internal static ManualLogSource Logger;

		public static ConfigEntry<bool> physGrabObjectFix;

		public Configs(ConfigFile cfg)
		{
			physGrabObjectFix = cfg.Bind<bool>("General", "Missing Item Data", true, "Fix general errors from modded items that didn't fill in their new data that could cause the game to freeze on loading.");
		}

		public static void DisplayConfigs()
		{
			if (physGrabObjectFix.Value)
			{
				Logger.LogInfo((object)"Config [Missing Item Data] is set to TRUE. Items with missing data will have their data filled in upon start.");
			}
			else
			{
				Logger.LogInfo((object)"Config [Missing Item Data] is set to FALSE. Missing item data will not be touched.");
			}
		}
	}
	internal class ItemBugs
	{
		private enum MissingDataTypes
		{
			Durability,
			PhysAttribute,
			Value,
			Item
		}

		[HarmonyPatch(typeof(ValuableObject))]
		public class NewValuableObject
		{
			[HarmonyPostfix]
			[HarmonyPatch("Awake")]
			public static void AwakePostfix(ValuableObject __instance)
			{
				DoFillInMissingDataLogic(__instance, "Awake");
			}

			[HarmonyPrefix]
			[HarmonyPatch("DollarValueSetLogic")]
			public static void DollarValueSetLogicPrefix(ValuableObject __instance)
			{
				DoFillInMissingDataLogic(__instance, "DollarValueSetLogic");
			}

			private static void DoFillInMissingDataLogic(ValuableObject __instance, string methodName)
			{
				if (!Configs.physGrabObjectFix.Value || (Object)(object)__instance == (Object)null)
				{
					return;
				}
				string text = ((Object)__instance).name.Replace("(Clone)", "");
				Durability val = null;
				PhysAttribute val2 = null;
				Value val3 = null;
				Item val4 = null;
				if ((Object)(object)__instance.durabilityPreset == (Object)null)
				{
					val = (Durability)(((Object)(object)val != (Object)null) ? ((object)val) : ((object)/*isinst with value type is only supported in some contexts*/));
					__instance.durabilityPreset = val;
					Logger.LogInfo((object)$"{methodName}: {text}.durabilityPreset = {__instance.durabilityPreset}");
				}
				if ((Object)(object)__instance.physAttributePreset == (Object)null)
				{
					val2 = (PhysAttribute)(((Object)(object)val2 != (Object)null) ? ((object)val2) : ((object)/*isinst with value type is only supported in some contexts*/));
					__instance.physAttributePreset = val2;
					Logger.LogInfo((object)$"{methodName}: {text}.physAttributePreset = {__instance.physAttributePreset}");
				}
				if ((Object)(object)__instance.valuePreset == (Object)null)
				{
					val3 = (__instance.valuePreset = (Value)(((Object)(object)val3 != (Object)null) ? ((object)val3) : ((object)/*isinst with value type is only supported in some contexts*/)));
					Logger.LogInfo((object)$"{methodName}: {text}.valuePreset = {__instance.valuePreset}");
				}
				ItemAttributes component = ((Component)__instance).GetComponent<ItemAttributes>();
				if ((Object)(object)component != (Object)null)
				{
					if ((Object)(object)component.item == (Object)null)
					{
						val4 = (Item)(((Object)(object)val4 != (Object)null) ? ((object)val4) : ((object)/*isinst with value type is only supported in some contexts*/));
						component.item = val4;
						Logger.LogInfo((object)$"{methodName}: {text}.attributes.item = {component.item}");
					}
					if ((Object)(object)component.item.value == (Object)null)
					{
						val3 = (Value)(((Object)(object)val3 != (Object)null) ? ((object)val3) : ((object)/*isinst with value type is only supported in some contexts*/));
						component.item.value = val3;
						Logger.LogInfo((object)$"{methodName}: {text}.attributes.item.value = {component.item.value}");
					}
				}
			}

			private static ScriptableObject GetMissingData(string nameObject, MissingDataTypes typeOfMissingData)
			{
				if (missingData == null)
				{
					Logger.LogWarning((object)"GetMissingData() failed because Dictionary was not set up");
					return null;
				}
				string text = typeOfMissingData.ToString();
				string text2 = nameObject + " - " + text;
				if (missingData.ContainsKey(text2))
				{
					Logger.LogDebug((object)$"key \"{text2}\" RETRIEVING {missingData[text2]}");
					return missingData[text2];
				}
				ScriptableObject val = null;
				val = (ScriptableObject)(typeOfMissingData switch
				{
					MissingDataTypes.PhysAttribute => ScriptableObject.CreateInstance<PhysAttribute>(), 
					MissingDataTypes.Value => ScriptableObject.CreateInstance<Value>(), 
					MissingDataTypes.Item => ScriptableObject.CreateInstance<Item>(), 
					_ => ScriptableObject.CreateInstance<Durability>(), 
				});
				((Object)val).name = text2;
				missingData.Add(text2, val);
				Logger.LogDebug((object)$"key \"{text2}\" ADDING {missingData[text2]}");
				return missingData[text2];
			}
		}

		private static ManualLogSource Logger;

		private static Dictionary<string, ScriptableObject> missingData = new Dictionary<string, ScriptableObject>();
	}
	[BepInPlugin("local.SimonTendo.REPOLocalFixes", "REPOLocalFixes", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static Configs MyConfig { get; internal set; }

		private void Awake()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin REPOLocalFixes is loaded!");
			SendLoggers();
			MyConfig = new Configs(((BaseUnityPlugin)this).Config);
			Configs.DisplayConfigs();
			Harmony val = new Harmony("REPOLocalFixes");
			if (Configs.physGrabObjectFix.Value)
			{
				val.Patch((MethodBase)typeof(ValuableObject).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, new HarmonyMethod(typeof(ItemBugs.NewValuableObject).GetMethod("AwakePostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				val.Patch((MethodBase)typeof(ValuableObject).GetMethod("DollarValueSetLogic", BindingFlags.Instance | BindingFlags.Public), new HarmonyMethod(typeof(ItemBugs.NewValuableObject).GetMethod("DollarValueSetLogicPrefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void SendLoggers()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic);
				FieldInfo[] array2 = fields;
				foreach (FieldInfo fieldInfo in array2)
				{
					if (fieldInfo.FieldType == typeof(ManualLogSource))
					{
						fieldInfo.SetValue(type, Logger);
					}
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "REPOLocalFixes";

		public const string PLUGIN_NAME = "REPOLocalFixes";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}