using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using ExitGames.Client.Photon; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using Photon.Realtime; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("Zichen-CurrencyAsToken-1.0.0")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+dff5f013f23b0205a5fe7be5bc4fa74a5d2c84c3")] [assembly: AssemblyProduct("Zichen-CurrencyAsToken-1.0.0")] [assembly: AssemblyTitle("Zichen-CurrencyAsToken-1.0.0")] [assembly: AssemblyVersion("1.0.0.0")] [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; } } } public enum DisplayLanguage { 中文, English } namespace Zichen_CurrencyAsToken { [BepInPlugin("zichen.currencyastoken", "CurrencyAsToken", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "zichen.currencyastoken"; public const string PluginName = "CurrencyAsToken"; public const string PluginVersion = "1.0.0"; public static Plugin Instance; private Harmony harmony; private static ConfigEntry _cfgModEnabled; private static ConfigEntry _cfgDisplayLanguage; private static ConfigEntry _cfgBaseCost; private static ConfigEntry _cfgCostIncrement; private static ConfigEntry _cfgMaxCost; private static ConfigEntry _cfgCommonWeight; private static ConfigEntry _cfgUncommonWeight; private static ConfigEntry _cfgRareWeight; private static ConfigEntry _cfgUltraRareWeight; private const int CurrencyPullRarityMarker = 1000; private static int _currencyPullPlayerViewId = -1; private static float _currencyPullPlayerExpireTime; private static string _lastSyncedHostSettingsSignature = string.Empty; private const string PullCountDictKey = "zichenCurrencyAsTokenPullCount"; private static Dictionary pullCountDict = new Dictionary(); private const string RoomPropEnabled = "zct_enabled"; private const string RoomPropLanguage = "zct_lang"; private const string RoomPropBaseCost = "zct_base"; private const string RoomPropCostIncrement = "zct_inc"; private const string RoomPropMaxCost = "zct_max"; private const string RoomPropCommonWeight = "zct_common"; private const string RoomPropUncommonWeight = "zct_uncommon"; private const string RoomPropRareWeight = "zct_rare"; private const string RoomPropUltraRareWeight = "zct_ultra"; private const string RoomPropPullCount = "zct_pullcount"; private static readonly FieldInfo CosmeticTokensField = AccessTools.Field(typeof(MetaManager), "cosmeticTokens"); private static readonly FieldInfo InfoTextTriggerActiveField = AccessTools.Field(typeof(InfoTextTrigger), "active"); private static readonly FieldInfo DodField = AccessTools.Field(typeof(StatsManager), "dictionaryOfDictionaries"); private static readonly MethodInfo SaveFileSaveMethod = AccessTools.Method(typeof(StatsManager), "SaveFileSave", (Type[])null, (Type[])null); private static readonly MethodInfo InteractSetMethod = AccessTools.Method(typeof(CosmeticShopMachine), "InteractSet", (Type[])null, (Type[])null); private const float PullInteractDistance = 3f; public static bool IsStaticModEnabled() { if (_cfgModEnabled != null) { return _cfgModEnabled.Value; } return false; } private void Awake() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown Instance = this; DetachFromManager(); ResetConfigIfVersionChanged(); BindConfig(); harmony = new Harmony("zichen.currencyastoken"); ApplyHarmonyPatches(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"CurrencyAsToken v1.0.0 loaded."); } private void Update() { SyncHostRoomSettingsIfNeeded(); if (IsStaticModEnabled()) { SemiFunc.RunIsShop(); } } private static int GetCosmeticTokenCount() { if ((Object)(object)MetaManager.instance == (Object)null) { return 0; } return (CosmeticTokensField?.GetValue(MetaManager.instance) as List)?.Count ?? 0; } private static bool IsInfoTextTriggerActive(InfoTextTrigger trigger) { if ((Object)(object)trigger == (Object)null) { return false; } return (bool)(InfoTextTriggerActiveField?.GetValue(trigger) ?? ((object)false)); } private static bool IsLocalPlayerNearMachine(CosmeticShopMachine machine) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) PlayerAvatar val = SemiFunc.PlayerGetLocal(); if ((Object)(object)val == (Object)null || (Object)(object)machine == (Object)null) { return false; } return Vector3.Distance(((Component)val).transform.position, ((Component)machine).transform.position) <= 3f; } private static void MarkCurrencyPullPlayer(PlayerAvatar player) { _currencyPullPlayerViewId = (((Object)(object)player != (Object)null && (Object)(object)player.photonView != (Object)null) ? player.photonView.ViewID : (-1)); _currencyPullPlayerExpireTime = Time.unscaledTime + 8f; } private static void ClearCurrencyPullPlayer() { _currencyPullPlayerViewId = -1; _currencyPullPlayerExpireTime = 0f; } private static bool IsCurrentLocalCurrencyPull(PlayerAvatar interactingPlayer) { if (_currencyPullPlayerViewId < 0) { return false; } if (Time.unscaledTime > _currencyPullPlayerExpireTime) { ClearCurrencyPullPlayer(); return false; } PlayerAvatar val = SemiFunc.PlayerGetLocal(); if ((Object)(object)val == (Object)null || (Object)(object)interactingPlayer == (Object)null || (Object)(object)val.photonView == (Object)null || (Object)(object)interactingPlayer.photonView == (Object)null) { return false; } if (val.photonView.ViewID == _currencyPullPlayerViewId) { return interactingPlayer.photonView.ViewID == _currencyPullPlayerViewId; } return false; } private static bool TryGetPullInputDown() { if ((Object)(object)InputManager.instance == (Object)null) { return false; } return SemiFunc.InputDown((InputKey)2); } private static bool IsHostAuthoritativeContext() { if (SemiFunc.IsMultiplayer()) { return PhotonNetwork.InRoom; } return false; } private static bool TryGetRoomBool(string key, bool fallback) { if (!IsHostAuthoritativeContext() || PhotonNetwork.CurrentRoom == null) { return fallback; } if (((Dictionary)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)key, out object value) && value is bool) { return (bool)value; } return fallback; } private static int TryGetRoomInt(string key, int fallback) { if (!IsHostAuthoritativeContext() || PhotonNetwork.CurrentRoom == null) { return fallback; } if (((Dictionary)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)key, out object value) && value is int) { return (int)value; } return fallback; } private static DisplayLanguage GetEffectiveDisplayLanguage() { if (IsHostAuthoritativeContext()) { return (DisplayLanguage)TryGetRoomInt("zct_lang", (int)_cfgDisplayLanguage.Value); } return _cfgDisplayLanguage.Value; } private static bool IsEffectiveModEnabled() { if (SemiFunc.IsMultiplayer()) { if (!PhotonNetwork.InRoom) { return false; } if (PhotonNetwork.IsMasterClient) { return IsStaticModEnabled(); } return TryGetRoomBool("zct_enabled", fallback: false); } return IsStaticModEnabled(); } private static int GetEffectiveBaseCost() { if (!IsHostAuthoritativeContext()) { return _cfgBaseCost.Value; } return TryGetRoomInt("zct_base", _cfgBaseCost.Value); } private static int GetEffectiveCostIncrement() { if (!IsHostAuthoritativeContext()) { return _cfgCostIncrement.Value; } return TryGetRoomInt("zct_inc", _cfgCostIncrement.Value); } private static int GetEffectiveMaxCost() { if (!IsHostAuthoritativeContext()) { return _cfgMaxCost.Value; } return TryGetRoomInt("zct_max", _cfgMaxCost.Value); } private static int GetEffectiveCommonWeight() { if (!IsHostAuthoritativeContext()) { return _cfgCommonWeight.Value; } return TryGetRoomInt("zct_common", _cfgCommonWeight.Value); } private static int GetEffectiveUncommonWeight() { if (!IsHostAuthoritativeContext()) { return _cfgUncommonWeight.Value; } return TryGetRoomInt("zct_uncommon", _cfgUncommonWeight.Value); } private static int GetEffectiveRareWeight() { if (!IsHostAuthoritativeContext()) { return _cfgRareWeight.Value; } return TryGetRoomInt("zct_rare", _cfgRareWeight.Value); } private static int GetEffectiveUltraRareWeight() { if (!IsHostAuthoritativeContext()) { return _cfgUltraRareWeight.Value; } return TryGetRoomInt("zct_ultra", _cfgUltraRareWeight.Value); } private static void SyncHostRoomSettingsIfNeeded() { //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Expected O, but got Unknown if (SemiFunc.IsMultiplayer() && PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient && PhotonNetwork.CurrentRoom != null) { string text = string.Join("|", IsStaticModEnabled(), (int)_cfgDisplayLanguage.Value, _cfgBaseCost.Value, _cfgCostIncrement.Value, _cfgMaxCost.Value, _cfgCommonWeight.Value, _cfgUncommonWeight.Value, _cfgRareWeight.Value, _cfgUltraRareWeight.Value, GetPullCount()); if (!(text == _lastSyncedHostSettingsSignature)) { Hashtable val = new Hashtable { [(object)"zct_enabled"] = IsStaticModEnabled(), [(object)"zct_lang"] = (int)_cfgDisplayLanguage.Value, [(object)"zct_base"] = _cfgBaseCost.Value, [(object)"zct_inc"] = _cfgCostIncrement.Value, [(object)"zct_max"] = _cfgMaxCost.Value, [(object)"zct_common"] = _cfgCommonWeight.Value, [(object)"zct_uncommon"] = _cfgUncommonWeight.Value, [(object)"zct_rare"] = _cfgRareWeight.Value, [(object)"zct_ultra"] = _cfgUltraRareWeight.Value, [(object)"zct_pullcount"] = GetPullCount() }; PhotonNetwork.CurrentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null); _lastSyncedHostSettingsSignature = text; } } } private void BindConfig() { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Expected O, but got Unknown //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Expected O, but got Unknown //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Expected O, but got Unknown ((BaseUnityPlugin)this).Config.Bind("模组信息", "模组名称", "金币代替代币", (ConfigDescription)null); ((BaseUnityPlugin)this).Config.Bind("模组信息", "模组版本号", "1.0.0", (ConfigDescription)null); _cfgModEnabled = ((BaseUnityPlugin)this).Config.Bind("A.全局设置", "模组启用", true, "总开关。关闭后金币代替代币功能完全失效。"); _cfgDisplayLanguage = ((BaseUnityPlugin)this).Config.Bind("A.全局设置", "语言/Language", DisplayLanguage.中文, "公开文档和配置说明语言切换。仅该项保留中英并列格式。"); _cfgBaseCost = ((BaseUnityPlugin)this).Config.Bind("B.抽奖设置", "基础花费/K", 10, new ConfigDescription("首次金币抽奖花费,范围 10-100 K。", (AcceptableValueBase)(object)new AcceptableValueRange(10, 100), Array.Empty())); _cfgCostIncrement = ((BaseUnityPlugin)this).Config.Bind("B.抽奖设置", "每次递增/K", 1, new ConfigDescription("每次金币抽奖后增加的花费,范围 0-10 K。", (AcceptableValueBase)(object)new AcceptableValueRange(0, 10), Array.Empty())); _cfgMaxCost = ((BaseUnityPlugin)this).Config.Bind("B.抽奖设置", "最大花费/K", 20, new ConfigDescription("单次金币抽奖花费上限,范围 10-100 K。", (AcceptableValueBase)(object)new AcceptableValueRange(10, 100), Array.Empty())); _cfgCommonWeight = ((BaseUnityPlugin)this).Config.Bind("B.抽奖设置", "普通中奖概率/%", 50, new ConfigDescription("普通奖励的概率参数,范围 0-100%。", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); _cfgUncommonWeight = ((BaseUnityPlugin)this).Config.Bind("B.抽奖设置", "稀有中奖概率/%", 30, new ConfigDescription("稀有奖励的概率参数,范围 0-100%。", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); _cfgRareWeight = ((BaseUnityPlugin)this).Config.Bind("B.抽奖设置", "珍贵中奖概率/%", 15, new ConfigDescription("珍贵奖励的概率参数,范围 0-100%。", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); _cfgUltraRareWeight = ((BaseUnityPlugin)this).Config.Bind("B.抽奖设置", "超稀有中奖概率/%", 5, new ConfigDescription("超稀有奖励的概率参数,范围 0-100%。", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); } private void ApplyHarmonyPatches() { PatchPrefix(typeof(CosmeticShopMachine), "InfoTextTriggerLogic", "InfoTextTriggerLogicPrefix"); PatchPrefix(typeof(CosmeticShopMachine), "RewardSet", "RewardSetPrefix"); PatchPrefix(typeof(CosmeticShopMachine), "InteractClientRPC", "InteractClientRPCPrefix"); PatchPostfix(typeof(CosmeticShopMachine), "StateIdle", "StateIdlePostfix"); ((BaseUnityPlugin)this).Logger.LogInfo((object)"CurrencyAsToken Harmony patches applied."); } private void PatchPrefix(Type type, string method, string patch) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown try { MethodInfo methodInfo = AccessTools.Method(type, method, (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), patch, (Type[])null, (Type[])null); if (methodInfo != null && methodInfo2 != null) { harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Patch target not found: " + type.Name + "." + method)); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to patch " + type.Name + "." + method + ": " + ex.Message)); } } private void PatchPostfix(Type type, string method, string patch) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown try { MethodInfo methodInfo = AccessTools.Method(type, method, (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), patch, (Type[])null, (Type[])null); if (methodInfo != null && methodInfo2 != null) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Patch target not found: " + type.Name + "." + method)); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to patch " + type.Name + "." + method + ": " + ex.Message)); } } private static void StateIdlePostfix(CosmeticShopMachine __instance, State ___stateCurrent, PlayerAvatar ___interactingPlayer, InfoTextTrigger ___infoTextTrigger) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (!IsEffectiveModEnabled() || !SemiFunc.RunIsShop() || GetCosmeticTokenCount() > 0 || (int)___stateCurrent != 0 || (Object)(object)___interactingPlayer != (Object)null || (!IsInfoTextTriggerActive(___infoTextTrigger) && !IsLocalPlayerNearMachine(__instance)) || (Object)(object)InputManager.instance == (Object)null || !TryGetPullInputDown()) { return; } int costForNextPull = GetCostForNextPull(); int num = SemiFunc.StatGetRunCurrency(); if (num < costForNextPull) { return; } PlayerAvatar val = SemiFunc.PlayerGetLocal(); if (SemiFunc.IsMasterClientOrSingleplayer()) { int randomRarity = GetRandomRarity(); SemiFunc.StatSetRunCurrency(num - costForNextPull); IncrementPullCount(); CurrencyUI instance = CurrencyUI.instance; if (instance != null) { instance.FetchCurrency(); } MarkCurrencyPullPlayer(val); InteractSetMethod.Invoke(__instance, new object[2] { val, randomRarity }); SaveProgressIfPossible(); SyncHostRoomSettingsIfNeeded(); } else { MarkCurrencyPullPlayer(val); ((Component)__instance).GetComponent().RPC("InteractClientRPC", (RpcTarget)2, new object[1] { 1000 }); } } private static bool InfoTextTriggerLogicPrefix(CosmeticShopMachine __instance, State ___stateCurrent, InfoTextTrigger ___infoTextTrigger) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (!IsEffectiveModEnabled()) { return true; } if ((int)___stateCurrent != 0) { return true; } if ((Object)(object)MetaManager.instance == (Object)null) { return true; } if (GetCosmeticTokenCount() > 0) { return true; } if (SemiFunc.RunIsShop() && IsLocalPlayerNearMachine(__instance)) { if (___infoTextTrigger != null) { ___infoTextTrigger.Disable(0.2f); } int costForNextPull = GetCostForNextPull(); int num = SemiFunc.StatGetRunCurrency(); string costText = "$" + SemiFunc.DollarGetString(costForNextPull) + "K"; string text = BuildCurrencyPullPrompt(GetEffectiveDisplayLanguage() == DisplayLanguage.中文, num >= costForNextPull, costText); if ((Object)(object)ItemInfoUI.instance != (Object)null) { ItemInfoUI.instance.ItemInfoText((ItemAttributes)null, text, false); } return false; } return true; } private static bool RewardSetPrefix(CosmeticShopMachine __instance, State ___stateCurrent, PlayerAvatar ___interactingPlayer, CosmeticAsset ___interactingCosmeticAsset) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Invalid comparison between Unknown and I4 //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 if (!IsEffectiveModEnabled()) { return true; } if (!IsCurrentLocalCurrencyPull(___interactingPlayer)) { return true; } ClearCurrencyPullPlayer(); if ((Object)(object)___interactingPlayer != (Object)(object)SemiFunc.PlayerGetLocal()) { return false; } if ((int)___stateCurrent == 5) { return true; } if ((int)___stateCurrent == 8) { if ((Object)(object)___interactingCosmeticAsset != (Object)null) { MetaManager.instance.CosmeticUnlock(___interactingCosmeticAsset); } return false; } return true; } private static bool InteractClientRPCPrefix(CosmeticShopMachine __instance, ref int _rarity, PhotonMessageInfo _info) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) if (_rarity < 1000) { return true; } if (!SemiFunc.IsMasterClientOrSingleplayer()) { return false; } if (!IsStaticModEnabled()) { return false; } int randomRarity = GetRandomRarity(); PlayerAvatar val = null; foreach (PlayerAvatar item in SemiFunc.PlayerGetList()) { if ((Object)(object)item != (Object)null && (Object)(object)item.photonView != (Object)null && _info.Sender == item.photonView.Owner) { val = item; break; } } if ((Object)(object)val == (Object)null) { return false; } int costForNextPull = GetCostForNextPull(); int num = SemiFunc.StatGetRunCurrency(); if (num < costForNextPull) { return false; } SemiFunc.StatSetRunCurrency(num - costForNextPull); IncrementPullCount(); CurrencyUI instance = CurrencyUI.instance; if (instance != null) { instance.FetchCurrency(); } SaveProgressIfPossible(); _rarity = randomRarity; SyncHostRoomSettingsIfNeeded(); return true; } private static int GetCostForNextPull() { return Mathf.Min(GetEffectiveBaseCost() + GetEffectiveCostIncrement() * GetPullCount(), GetEffectiveMaxCost()); } private static int GetRandomRarity() { int effectiveCommonWeight = GetEffectiveCommonWeight(); int effectiveUncommonWeight = GetEffectiveUncommonWeight(); int effectiveRareWeight = GetEffectiveRareWeight(); int effectiveUltraRareWeight = GetEffectiveUltraRareWeight(); int num = effectiveCommonWeight + effectiveUncommonWeight + effectiveRareWeight + effectiveUltraRareWeight; if (num <= 0) { num = 1; } int num2 = Random.Range(0, num); int num3 = 0; num3 += effectiveCommonWeight; if (num2 < num3) { return 0; } num3 += effectiveUncommonWeight; if (num2 < num3) { return 1; } num3 += effectiveRareWeight; if (num2 < num3) { return 2; } return 3; } private static void EnsurePullCountDictRegistered() { if ((Object)(object)StatsManager.instance == (Object)null) { return; } try { if (DodField?.GetValue(StatsManager.instance) is SortedDictionary> sortedDictionary) { if (sortedDictionary.ContainsKey("zichenCurrencyAsTokenPullCount")) { pullCountDict = sortedDictionary["zichenCurrencyAsTokenPullCount"]; return; } pullCountDict = new Dictionary(); sortedDictionary.Add("zichenCurrencyAsTokenPullCount", pullCountDict); } } catch (Exception ex) { Debug.LogWarning((object)("[CurrencyAsToken] Failed to register pull count dict: " + ex.Message)); } } private static int GetPullCount() { if (IsHostAuthoritativeContext() && !PhotonNetwork.IsMasterClient) { return Mathf.Max(0, TryGetRoomInt("zct_pullcount", 0)); } EnsurePullCountDictRegistered(); if (pullCountDict.TryGetValue("pullCount", out var value)) { return value; } return 0; } private static void IncrementPullCount() { EnsurePullCountDictRegistered(); int value; int num = (pullCountDict.TryGetValue("pullCount", out value) ? value : 0); pullCountDict["pullCount"] = num + 1; } private static string BuildCurrencyPullPrompt(bool useChinese, bool canAfford, string costText) { if (useChinese) { if (!canAfford) { return "需要 " + costText + " 才能花费金币抽奖,按 [E]"; } return "按 [E] 花费金币抽奖(" + costText + ")"; } if (!canAfford) { return "Need " + costText + " to spend currency and pull. Press [E]"; } return "Press [E] to spend currency and pull (" + costText + ")"; } private static void SaveProgressIfPossible() { try { if (!((Object)(object)StatsManager.instance == (Object)null) && SemiFunc.IsMasterClientOrSingleplayer()) { SaveFileSaveMethod?.Invoke(StatsManager.instance, null); } } catch (Exception ex) { Debug.LogWarning((object)("[CurrencyAsToken] Failed to save progress after currency pull: " + ex.Message)); } } private void ResetConfigIfVersionChanged() { try { string configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath; string text = ReadConfigPluginVersion(configFilePath); if (!string.IsNullOrWhiteSpace(text) && !(text == "1.0.0")) { ((BaseUnityPlugin)this).Config.Clear(); if (File.Exists(configFilePath)) { File.Delete(configFilePath); } ((BaseUnityPlugin)this).Config.Reload(); ((BaseUnityPlugin)this).Logger.LogWarning((object)"Config version changed. Old config was reset to defaults."); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to reset config by version: " + ex.Message)); } } private static string ReadConfigPluginVersion(string configPath) { if (!File.Exists(configPath)) { return null; } Match match = Regex.Match(File.ReadAllText(configPath), "(?m)^模组版本号\\s*=\\s*(.+?)\\s*$"); if (!match.Success) { return null; } return match.Groups[1].Value.Trim(); } private void DetachFromManager() { ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); } } }