Decompiled source of MoreTaxTokensSimple v1.4.2

plugins/MoreTaxTokensSimple.dll

Decompiled 16 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MoreTaxTokensSimple")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreTaxTokensSimple")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dab873ab-a85e-45e9-a2a5-ad88b7738f11")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreTaxTokensSimple;

[BepInPlugin("dyxc666.MoreTaxTokensSimple", "More Tax Tokens Simple", "1.4.1")]
[BepInProcess("REPO.exe")]
public class MoreTaxTokensPlugin : BaseUnityPlugin, IOnEventCallback
{
	internal static ManualLogSource Log;

	public static ConfigEntry<int> TokenMultiplier;

	private readonly Harmony harmony = new Harmony("dyxc666.MoreTaxTokensSimple");

	private const byte SyncTokenEventCode = 1;

	private static bool _callbackRegistered;

	public static MoreTaxTokensPlugin Instance { get; private set; }

	private void Awake()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		TokenMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("General", "TokenMultiplier", 10, new ConfigDescription("税款代币获取倍率。每提取一个外观箱子,获得的代币数量 = 原数量 × 倍率。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
		try
		{
			MethodInfo methodInfo = AccessTools.Method("MetaManager:CosmeticTokenAdd", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(MoreTaxTokensPlugin), "CosmeticTokenAddPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"✅ Prefix 补丁成功: MetaManager.CosmeticTokenAdd");
			}
			else
			{
				Log.LogWarning((object)"未能找到 MetaManager.CosmeticTokenAdd 方法,请检查游戏版本。");
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("补丁失败: " + ex.Message));
		}
		Log.LogInfo((object)$"More Tax Tokens Simple v1.4.1 初始化完成!TokenMultiplier = {TokenMultiplier.Value}x");
	}

	private void OnDestroy()
	{
		if (_callbackRegistered)
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
			_callbackRegistered = false;
		}
	}

	private static bool IsInRoom()
	{
		return PhotonNetwork.IsConnected && PhotonNetwork.InRoom;
	}

	private static List<int> GetCosmeticTokens(object instance)
	{
		return AccessTools.Field(instance.GetType(), "cosmeticTokens")?.GetValue(instance) as List<int>;
	}

	[HarmonyPrefix]
	[HarmonyPatch]
	public static void CosmeticTokenAddPrefix(object __instance, object _rarity)
	{
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Expected O, but got Unknown
		//IL_0108: Expected O, but got Unknown
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Expected O, but got Unknown
		int value = TokenMultiplier.Value;
		if (value <= 1)
		{
			return;
		}
		int num = (int)_rarity;
		List<int> cosmeticTokens = GetCosmeticTokens(__instance);
		if (cosmeticTokens == null)
		{
			return;
		}
		int count = cosmeticTokens.Count;
		for (int i = 0; i < value; i++)
		{
			cosmeticTokens.Add(num);
		}
		Log.LogInfo((object)$"\ud83d\udcb0 税款代币 ×{value} | {count} → {cosmeticTokens.Count} (稀有度: {(object)(Rarity)num})");
		if (IsInRoom() && PhotonNetwork.IsMasterClient)
		{
			if (!_callbackRegistered)
			{
				PhotonNetwork.AddCallbackTarget((object)Instance);
				_callbackRegistered = true;
			}
			Hashtable val = new Hashtable();
			((Dictionary<object, object>)val).Add((object)"multiplier", (object)value);
			((Dictionary<object, object>)val).Add((object)"rarity", (object)num);
			Hashtable val2 = val;
			PhotonNetwork.RaiseEvent((byte)1, (object)val2, new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)0
			}, SendOptions.SendReliable);
		}
	}

	public void OnEvent(EventData photonEvent)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		if (photonEvent.Code != 1 || !IsInRoom())
		{
			return;
		}
		try
		{
			Hashtable val = (Hashtable)photonEvent.CustomData;
			int num = (int)val[(object)"multiplier"];
			int num2 = (int)val[(object)"rarity"];
			List<int> cosmeticTokens = GetCosmeticTokens(MetaManager.instance);
			if (cosmeticTokens != null)
			{
				for (int i = 0; i < num; i++)
				{
					cosmeticTokens.Add(num2);
				}
				Log.LogInfo((object)$"\ud83d\udce5 客机同步: 代币 ×{num} (稀有度: {(object)(Rarity)num2})");
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("客机同步失败: " + ex.Message));
		}
	}
}