Decompiled source of MoreReputation v1.0.0

BepInEx/plugins/FateArth/FateArth.MoreReputationPlugin.dll

Decompiled 3 weeks 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 Unity.Netcode;

[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("FateArth.MoreReputationPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("更多声望")]
[assembly: AssemblyTitle("FateArth.MoreReputationPlugin")]
[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 MoreReputationPlugin
{
	[HarmonyPatch]
	public class MoreReputationPatch
	{
		[HarmonyPatch(typeof(GameManager), "IncrementReputationServer")]
		[HarmonyPrefix]
		private static void Prefix1(GameManager __instance)
		{
			__instance.maxReputation = Plugin.configReputation.Value;
		}

		[HarmonyPatch(typeof(UIManager), "SetReputationTooltip")]
		[HarmonyPrefix]
		private static void Prefix2()
		{
			GameManager.Instance.maxReputation = Plugin.configReputation.Value;
		}

		[HarmonyPatch(typeof(GameManager), "IncrementBlockReputationServer")]
		[HarmonyPrefix]
		private static bool Prefix3(GameManager __instance, BlockSO blockSO)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return false;
			}
			FieldInfo field = typeof(GameManager).GetField("maintenance", BindingFlags.Instance | BindingFlags.NonPublic);
			NetworkVariable<int> val = (NetworkVariable<int>)field.GetValue(__instance);
			FieldInfo field2 = typeof(GameManager).GetField("reputationBlockIds", BindingFlags.Instance | BindingFlags.NonPublic);
			List<long> list = (List<long>)field2.GetValue(__instance);
			FieldInfo field3 = typeof(GameManager).GetField("totalBlockReputation", BindingFlags.Instance | BindingFlags.NonPublic);
			NetworkVariable<int> val2 = (NetworkVariable<int>)field3.GetValue(__instance);
			val.Value += blockSO.maintenanceCost;
			val2.Value += blockSO.blockReputation;
			list.Add(((ItemSO)blockSO).id);
			return false;
		}

		[HarmonyPatch(typeof(GameManager), "DecrementBlockReputationServer")]
		[HarmonyPrefix]
		private static bool Prefix4(GameManager __instance, BlockSO blockSO)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return false;
			}
			FieldInfo field = typeof(GameManager).GetField("maintenance", BindingFlags.Instance | BindingFlags.NonPublic);
			NetworkVariable<int> val = (NetworkVariable<int>)field.GetValue(__instance);
			FieldInfo field2 = typeof(GameManager).GetField("reputationBlockIds", BindingFlags.Instance | BindingFlags.NonPublic);
			List<long> list = (List<long>)field2.GetValue(__instance);
			FieldInfo field3 = typeof(GameManager).GetField("totalBlockReputation", BindingFlags.Instance | BindingFlags.NonPublic);
			NetworkVariable<int> val2 = (NetworkVariable<int>)field3.GetValue(__instance);
			val.Value -= blockSO.maintenanceCost;
			if (list.Contains(((ItemSO)blockSO).id))
			{
				list.Remove(((ItemSO)blockSO).id);
				val2.Value -= blockSO.blockReputation;
			}
			return false;
		}
	}
	[BepInPlugin("FateArth.MoreReputationPlugin", "更多声望", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static Harmony harmony;

		public static ConfigEntry<int> configReputation;

		public static ConfigEntry<bool> configRepetition;

		private void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			configReputation = ((BaseUnityPlugin)this).Config.Bind<int>("General", "声望上限", 500, "声望上限,游戏默认为200,Mod默认修改500,顾客太多会导致卡顿");
			configRepetition = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "声望加成", true, "声望物品是否可以重复加成,开=true,关false");
			Logger = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("FateArth.MoreReputationPlugin");
			harmony.PatchAll();
			Logger.LogInfo((object)"Plugin FateArth.MoreReputationPlugin is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "FateArth.MoreReputationPlugin";

		public const string PLUGIN_NAME = "更多声望";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}