using System; using System.Collections.Generic; using CIG; using SUISS.Core; using UnityEngine; public class IAPPackManager { private IAPPackManager() { } public IList AllPackNames { get { if (this._fileCache == null) { this.LoadPacksFromDisk(); } return this._allPackNames.AsReadOnly(); } } public static IAPPackManager Instance { get { if (IAPPackManager._instance == null) { IAPPackManager._instance = new IAPPackManager(); } return IAPPackManager._instance; } } public static bool StoreHasIAPPack(string packName) { IAPPack pack = IAPPackManager.Instance.CreatePack(packName); return SingletonMonobehaviour.Instance.Store != null && SingletonMonobehaviour.Instance.Store.FindProduct((CIG3StoreProduct p) => p.GameProductName == pack.Name) != null; } public static int LevelsInPack(string packName) { int result = 5; if (SingletonMonobehaviour.Instance.Level == Mathf.Max(SingletonMonobehaviour.Instance.MaxLevel, 150)) { return result; } IAPPack iappack = IAPPackManager.Instance.CreatePack(packName); LevelUpItem levelUpItem = iappack.FindPackItem(); if (levelUpItem != null) { result = levelUpItem.Levels; } else { UnityEngine.Debug.LogWarning("IAP level pack does not contain LevelUpItem, assuming 5 in the interface"); } return result; } public IAPPack CreatePack(string packName) { return IAPPack.Create(packName, this.GetPackProperties(packName)); } private Dictionary GetPackProperties(string packName) { if (this._fileCache == null) { this.LoadPacksFromDisk(); } if (!this._fileCache.ContainsKey("Packs")) { return new Dictionary(); } Dictionary dictionary = this._fileCache["Packs"] as Dictionary; if (!dictionary.ContainsKey(packName)) { return new Dictionary(); } Dictionary dictionary2 = dictionary[packName] as Dictionary; if (dictionary2 == null) { return new Dictionary(); } return dictionary2; } private string[] GetAllPackNames() { string[] array = new string[this.AllPackNames.Count]; this.AllPackNames.CopyTo(array, 0); return array; } private void LoadPacksFromDisk() { bool flag; this._fileCache = this.LoadJSONFile("iappacks.properties", out flag); this._allPackNames = new List(); if (!flag) { UnityEngine.Debug.LogError(string.Format("There was an error loading/parsing JSON file '{0}'.", "iappacks.properties")); return; } try { Dictionary dictionary = this._fileCache["Packs"] as Dictionary; foreach (KeyValuePair keyValuePair in dictionary) { this._allPackNames.Add(keyValuePair.Key); } } catch (Exception exception) { UnityEngine.Debug.LogException(exception); } } private Dictionary LoadJSONFile(string file, out bool success) { TextAsset textAsset = Resources.Load(file); if (textAsset == null) { UnityEngine.Debug.LogError(string.Format("Can't load text asset '{0}'.", file)); success = false; return new Dictionary(); } object obj = Json.Decode(textAsset.text); if (obj == null) { UnityEngine.Debug.LogError(string.Format("Can't load/parse JSON file '{0}'.", file)); success = false; return new Dictionary(); } if (!(obj is Dictionary)) { UnityEngine.Debug.LogError(string.Format("I expected to find a Dictionary as root while decoding JSON file '{0}', but I found a '{1}'.", file, obj.GetType())); success = false; return new Dictionary(); } Dictionary dictionary = obj as Dictionary; if (!dictionary.ContainsKey("Packs")) { UnityEngine.Debug.LogError(string.Format("Did not find an object with the key '{0}' while decoding JSON file '{1}'", "Packs", file)); success = false; return new Dictionary(); } if (!(dictionary["Packs"] is Dictionary)) { UnityEngine.Debug.LogError(string.Format("Expected to find an object of type Dictionary for the key '{0}', but I found a '{1}'.", "Packs", dictionary["Packs"].GetType())); success = false; return new Dictionary(); } success = true; return dictionary; } public const string File = "iappacks.properties"; public const string PacksKey = "Packs"; public const string Pack5Level = "pack_5_levels"; public const string Pack4x = "pack_4x"; public const string Pack2x = "pack_2x"; public const string PackTimeboost12 = "pack_timeboost_12"; public const string PackTimeboost24 = "pack_timeboost_24"; private List _allPackNames; private Dictionary _fileCache; private static IAPPackManager _instance; }