using System; using System.Collections; 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 HarmonyLib; using Photon.Pun; 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("MoreTaxTokensConsumeSimple")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("MoreTaxTokensConsumeSimple")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("c4de3772-862f-47b9-b8fd-2fea94088566")] [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 cn_xc.MoreTaxTokensConsumeSimple; [BepInPlugin("cn_xc.MoreTaxTokensConsumeSimple", "More Tax Tokens Consume Simple", "1.2.1")] [BepInProcess("REPO.exe")] public class MoreTaxTokensConsumePlugin : BaseUnityPlugin { internal static ManualLogSource Log; public static ConfigEntry TokenConsumeBatchSize; public static ConfigEntry EnableBatchConsume; private readonly Harmony harmony = new Harmony("cn_xc.MoreTaxTokensConsumeSimple"); private static MoreTaxTokensConsumePlugin _pluginInstance; private static int _remainingBatchPulls; private static object _currentMachineInstance; private static MethodInfo _interactMethod; private static bool _isProcessing; private static bool _batchInProgress; private static int _delayedFrameCount; private void Awake() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Expected O, but got Unknown _pluginInstance = this; Log = ((BaseUnityPlugin)this).Logger; EnableBatchConsume = ((BaseUnityPlugin)this).Config.Bind("General", "EnableBatchConsume", true, "启用批量抽奖。仅主机/单人有效。"); TokenConsumeBatchSize = ((BaseUnityPlugin)this).Config.Bind("General", "TokenConsumeBatchSize", 10, new ConfigDescription("每次触发抽奖的次数 (1-100)。", (AcceptableValueBase)(object)new AcceptableValueRange(1, 100), Array.Empty())); Type type = AccessTools.TypeByName("CosmeticShopMachine"); if (type != null) { _interactMethod = AccessTools.Method(type, "Interact", (Type[])null, (Type[])null); if (_interactMethod != null) { harmony.Patch((MethodBase)_interactMethod, new HarmonyMethod(typeof(MoreTaxTokensConsumePlugin), "InteractPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Log.LogInfo((object)"✅ 补丁成功: CosmeticShopMachine.Interact (批量抽奖入口)"); } MethodInfo methodInfo = AccessTools.Method(type, "UpdateState", (Type[])null, (Type[])null); if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(MoreTaxTokensConsumePlugin), "UpdateStatePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); Log.LogInfo((object)"✅ 补丁成功: CosmeticShopMachine.UpdateState (状态监听)"); } } Log.LogInfo((object)$"More Tax Tokens Consume Simple v1.2.1 初始化完成!TokenConsumeBatchSize = {TokenConsumeBatchSize.Value}"); } public static void InteractPrefix(object __instance) { if (!EnableBatchConsume.Value || (SemiFunc.IsMultiplayer() && !PhotonNetwork.IsMasterClient) || _isProcessing || _batchInProgress) { return; } int value = TokenConsumeBatchSize.Value; if (value > 1) { MetaManager instance = MetaManager.instance; if (!((Object)(object)instance == (Object)null) && AccessTools.Field(typeof(MetaManager), "cosmeticTokens")?.GetValue(instance) is IList list && list.Count >= value) { _batchInProgress = true; _remainingBatchPulls = value - 1; _currentMachineInstance = __instance; _delayedFrameCount = 0; _isProcessing = false; Log.LogInfo((object)$"\ud83c\udfb0 批量抽奖启动:总共 {value} 次(第 1 次由玩家触发,剩余 {_remainingBatchPulls} 次自动触发)"); } } } public static void UpdateStatePostfix(object __instance, object _state) { if (!SemiFunc.IsMasterClientOrSingleplayer() || !_batchInProgress || _remainingBatchPulls <= 0 || _isProcessing || _currentMachineInstance == null || _interactMethod == null || __instance != _currentMachineInstance) { return; } string text = _state?.ToString(); if (text != "Idle") { return; } MetaManager instance = MetaManager.instance; if (!((Object)(object)instance == (Object)null)) { if (!(AccessTools.Field(typeof(MetaManager), "cosmeticTokens")?.GetValue(instance) is IList list) || list.Count < 1) { CleanupBatch("代币不足"); } else { _delayedFrameCount = 3; } } } private void Update() { if (!SemiFunc.IsMasterClientOrSingleplayer() || _delayedFrameCount <= 0 || _isProcessing || !_batchInProgress || _remainingBatchPulls <= 0) { return; } _delayedFrameCount--; if (_delayedFrameCount != 0) { return; } _isProcessing = true; try { if (_currentMachineInstance == null || _interactMethod == null) { CleanupBatch("机器实例丢失"); return; } MetaManager instance = MetaManager.instance; if ((Object)(object)instance == (Object)null) { CleanupBatch("MetaManager丢失"); return; } if (!(AccessTools.Field(typeof(MetaManager), "cosmeticTokens")?.GetValue(instance) is IList list) || list.Count < 1) { CleanupBatch("代币耗尽"); return; } _remainingBatchPulls--; int num = TokenConsumeBatchSize.Value - _remainingBatchPulls; Log.LogInfo((object)$"\ud83c\udfb0 自动触发第 {num}/{TokenConsumeBatchSize.Value} 次抽奖 (剩余:{_remainingBatchPulls})"); _interactMethod.Invoke(_currentMachineInstance, null); if (_remainingBatchPulls <= 0) { Log.LogInfo((object)"\ud83c\udfb0 批量抽奖完成!"); CleanupBatch("正常结束"); } } catch (Exception ex) { Log.LogError((object)("自动触发抽奖失败:" + ex.Message)); CleanupBatch("异常"); } finally { _isProcessing = false; } } private static void CleanupBatch(string reason) { if (!string.IsNullOrEmpty(reason)) { Log.LogDebug((object)("批量抽奖清理:" + reason)); } _batchInProgress = false; _remainingBatchPulls = 0; _currentMachineInstance = null; _isProcessing = false; _delayedFrameCount = 0; } }