using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Text; using System.Threading; using System.Xml.Serialization; using UnityEngine; using XUtliPoolLib; namespace XUpdater { public sealed class XUpdater : XSingleton { public static XLaunchMode LaunchMode { get { return XUpdater._launch_mode; } } public bool EditorMode { get { return this._bEditorMode; } } public string Version { get { return this._version; } } public string TargetVersion { get { return this._target_version; } } public bool NeedCheckFile { get { return this._need_check_file; } } public BuildTarget RunTimePlatform { get { return this._runtime_platform; } } public string Platform { get { return this._platform_name; } } public IPlatform XPlatform { get { return this._platform; } } public ILuaEngine XLuaEngine { get { return this._lua_engine; } } public IApolloManager XApolloManager { get { return this._apolloManager; } } public IBroardcast XBroadCast { get { return this._broadcast; } } public ITssSdk XTssSdk { get { return this._tssSdk; } } public IXPandoraMgr XPandoraManager { get { return this._pandoraManager; } } public IXGameSirControl GameSirControl { get { return this._SirControl; } } public IResourceHelp XResourceHelp { get { return this._resourcehelp; } } public bool IsDone { get { return this._update_done; } } internal eUPdatePhase Phase { set { this._phase = value; } } public int ManagedThreadId { get { return this._main_threadId; } } public bool Reboot { get; set; } public static readonly uint Major_Version = 1u; private static XLaunchMode _launch_mode = XLaunchMode.Live; public static GameObject XGameRoot = null; public static Assembly Ass = Assembly.GetAssembly(typeof(GameObject)); public static int Md5Length = 16; private int _main_threadId = 0; private bool _bEditorMode = false; private bool _bFetchVersion = false; private bool _bFetchServer = false; private StringBuilder _log = new StringBuilder(); private IEnumerator _downloader = null; private IEnumerator _download_prepare = null; private IEnumerator _comparer = null; private IEnumerator _launcher = null; private IEnumerator _finish = null; private byte[] _script = null; private bool _on_file_download_retry = false; private bool _on_file_download_need_retry = false; private bool _update_done = false; private bool _bundle_fetching = false; private bool _asset_loading = false; private XVersion _version_getter = null; private XBundle _bundle_getter = null; private XFileLog _filelog_getter = null; private IFMOD_Listener _fmod_listenter = null; private ITssSdk _tssSdk = null; private IApolloManager _apolloManager = null; private IBroardcast _broadcast = null; private ILuaEngine _lua_engine = null; private IXPandoraMgr _pandoraManager = null; private IXGameSirControl _SirControl = null; private IXVideo _video = null; private IPlatform _platform = null; private BuildTarget _runtime_platform = BuildTarget.Unknown; private string _platform_name = ""; private string _version = "0.0.0"; private string _target_version = "0.0.0"; private bool _need_check_file = false; private bool _need_play_cg = true; private XFetchVersionNetwork _fetch_version_network = null; private float _fetch_version_time = 0f; private ulong _update_pakcage_size = 0UL; private XVersionData _server = null; private XVersionData _client = null; private XVersionData _buildin = null; private IResourceHelp _resourcehelp = null; private XBundleData _bundle_data = null; private eUPdatePhase _phase = eUPdatePhase.xUP_None; private List _download_bundle = new List(); private List _cacheload_bundle = new List(); private List _meta_bundle = new List(); private Dictionary _persist_assets = new Dictionary(); private Dictionary _persist_image = new Dictionary(); private Dictionary _assets = new Dictionary(); private Dictionary _res_list = new Dictionary(); private Dictionary _bundles = new Dictionary(); public AssetBundleManager ABManager; private bool _is_download_update_pic = false; public override bool Init() { this._main_threadId = Thread.CurrentThread.ManagedThreadId; this._bEditorMode = ((int)Application.platform == 7 || (int)Application.platform == 0 || (int)Application.platform == 2); this.Reboot = false; XUpdater.XGameRoot = GameObject.Find("XGamePoint"); this.GetLaunchMode(); RuntimePlatform platform = Application.platform; if ((int)platform != 8) { if ((int)platform != 11) { this._runtime_platform = BuildTarget.Standalone; this._platform_name = (this.PatchPrefix() ?? ""); } else { this._runtime_platform = BuildTarget.Android; this._platform_name = this.PatchPrefix() + "Android/"; } } else { this._runtime_platform = BuildTarget.IOS; this._platform_name = this.PatchPrefix() + "IOS/"; } this._version_getter = XUpdater.XGameRoot.AddComponent(); this._bundle_getter = XUpdater.XGameRoot.AddComponent(); this._filelog_getter = XUpdater.XGameRoot.AddComponent(); this._fmod_listenter = (GameObject.Find("Main Camera").GetComponent("FMOD_Listener") as IFMOD_Listener); this._tssSdk = (XUpdater.XGameRoot.GetComponent("TssSDKManager") as ITssSdk); this._apolloManager = (XUpdater.XGameRoot.GetComponent("ApolloManager") as IApolloManager); this._broadcast = (XUpdater.XGameRoot.GetComponent("BroadcastManager") as IBroardcast); this._platform = (XUpdater.XGameRoot.GetComponent("XPlatform") as IPlatform); this._video = (XUpdater.XGameRoot.GetComponent("XVideoMgr") as IXVideo); this._lua_engine = (XUpdater.XGameRoot.GetComponent("LuaEngine") as ILuaEngine); this._pandoraManager = (XUpdater.XGameRoot.GetComponent("XPandoraMgr") as IXPandoraMgr); this._SirControl = (XUpdater.XGameRoot.GetComponent("XGameSirControl") as IXGameSirControl); bool flag = this._SirControl != null; if (flag) { this._SirControl.Init(); } this.ABManager = XUpdater.XGameRoot.AddComponent(); this.ABManager.Init(); XSingleton.singleton.Init(this._platform, this._filelog_getter); XSingleton.singleton.Init(); XSingleton.singleton.Init(); XBinaryReader.Init(); UnityEngine.Object.DontDestroyOnLoad(XUpdater.XGameRoot); return true; } public override void Uninit() { foreach (AssetBundle assetBundle in this._bundles.Values) { assetBundle.Unload(false); } this._assets.Clear(); this._persist_assets.Clear(); this._bundles.Clear(); this._res_list.Clear(); bool flag = this._video != null && this._video.isPlaying; if (flag) { this._video.Stop(); } this._phase = eUPdatePhase.xUP_Prepare; this._update_done = false; bool flag2 = this._fetch_version_network != null; if (flag2) { this._fetch_version_network.Close(); } UnityEngine.Object.Destroy(XUpdater.XGameRoot); } public void Clear() { foreach (KeyValuePair keyValuePair in this._bundles) { AssetBundle value = keyValuePair.Value; value.Unload(false); } this._bundles.Clear(); } public void Update() { switch (this._phase) { case eUPdatePhase.xUP_Prepare: { bool flag = this.Preparing(); if (flag) { this._phase = eUPdatePhase.xUP_FetchVersion; } else { XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_ERROR_FETCHLOCALVERSIONERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue); this.OnError(); } break; } case eUPdatePhase.xUP_FetchVersion: { bool flag2 = !this._bFetchVersion; if (flag2) { bool flag3 = this._fetch_version_network == null; if (flag3) { this._fetch_version_network = new XFetchVersionNetwork(); } XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_INFO_FETCHVERSION"), byte.MaxValue, byte.MaxValue, byte.MaxValue); this._fetch_version_network.Init(); string host = XSingleton.singleton.VersionServer.Substring(0, XSingleton.singleton.VersionServer.LastIndexOf(':')); string s = XSingleton.singleton.VersionServer.Substring(XSingleton.singleton.VersionServer.LastIndexOf(':') + 1); bool flag4 = this._fetch_version_network.Connect(host, int.Parse(s)); if (flag4) { this._bFetchVersion = true; this._fetch_version_time = Time.time; } else { XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_ERROR_FETCHVERSIONERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue); XSingleton.singleton.OnError(); this._fetch_version_network.Close(); } } else { bool flag5 = Time.time - this._fetch_version_time > 5f; if (flag5) { XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_ERROR_FETCHVERSIONERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue); XSingleton.singleton.OnError(); this._fetch_version_network.Close(); } } break; } case eUPdatePhase.xUP_LoadVersion: { bool flag6 = !this._bFetchServer; if (flag6) { this._cacheload_bundle.Clear(); this._download_bundle.Clear(); this._meta_bundle.Clear(); this._version_getter.ServerDownload(new HandleVersionDownload(this.OnVersionDownloaded), new HandleVersionLoaded(this.OnVersionLoaded)); } this._bFetchServer = true; break; } case eUPdatePhase.xUP_CompareVersion: { bool flag7 = this._comparer == null; if (flag7) { this._comparer = this.VersionComparer(); } else { bool flag8 = !this._comparer.MoveNext(); if (flag8) { this._comparer = null; } } break; } case eUPdatePhase.xUP_DownLoadBundle: { bool flag9 = this._downloader == null; if (flag9) { this._downloader = this.DownLoadBundles(); } else { bool flag10 = !this._downloader.MoveNext(); if (flag10) { this._downloader = null; this._phase = eUPdatePhase.xUP_ShowVersion; } } break; } case eUPdatePhase.xUP_ShowVersion: this.ShowVersionInfo(this._server, true); break; case eUPdatePhase.xUP_LaunchGame: { bool flag11 = this._launcher == null; if (flag11) { this._launcher = this.LaunchGame(); } else { bool flag12 = !this._launcher.MoveNext(); if (flag12) { this._launcher = null; this.OnEnding(); } } break; } case eUPdatePhase.xUP_Finish: { bool flag13 = this._finish == null; if (flag13) { this._finish = this.Finish(); } else { bool flag14 = !this._finish.MoveNext(); if (flag14) { this._finish = null; this._update_done = true; XSingleton.singleton.StartGame(); } } break; } } XSingleton.singleton.OnUpdate(); } public void Begin() { this._update_done = false; this._bFetchVersion = false; this._bFetchServer = false; bool flag = !XSingleton.singleton.SyncInit(); if (flag) { this._log.Remove(0, this._log.Length); this._log.Append("Error occurred when loading string table."); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); XSingleton.singleton.OnError(); } else { bool flag2 = !this.CheckMemory(); if (flag2) { this._log.Remove(0, this._log.Length); this._log.Append(XSingleton.singleton.GetString("XUPDATE_INFO_EXCLUDE1GPHONE")); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); XSingleton.singleton.OnError(); } else { bool flag3 = XSingleton.singleton.EnableCache(); if (flag3) { this._phase = eUPdatePhase.xUP_Prepare; } else { this._log.Remove(0, this._log.Length); this._log.Append(XSingleton.singleton.GetString("XUPDATE_ERROR_ACCESSDENIED")); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); XSingleton.singleton.OnError(); } } } } private IEnumerator Finish() { bool flag = this._server != null; if (flag) { this._server.Bundles.Clear(); this._version = this._server.ToString(); } this._server = null; this._client = null; this._buildin = null; bool flag2 = this._need_play_cg && this._video != null; if (flag2) { this._video.Play(false); yield return null; while (this._video.isPlaying) { yield return null; } } UnityEngine.Object.DestroyObject(this._version_getter); UnityEngine.Object.DestroyObject(this._bundle_getter); yield break; } public void OnError() { this._phase = eUPdatePhase.xUP_Error; } public void DevStart() { this._phase = eUPdatePhase.xUP_ShowVersion; } public void OnRetry() { eUPdatePhase phase = this._phase; if (phase != eUPdatePhase.xUP_DownLoadBundle) { if (phase != eUPdatePhase.xUP_Finish) { if (phase == eUPdatePhase.xUP_Error) { bool flag = this._server == null; if (flag) { this.Begin(); } } } else { bool isPlaying = this._video.isPlaying; if (isPlaying) { this._video.Stop(); } } } else { bool on_file_download_need_retry = this._on_file_download_need_retry; if (on_file_download_need_retry) { this._on_file_download_retry = true; } } } private void OnEnding() { XSingleton.singleton.LoadingOK = true; this._download_bundle.Clear(); this._cacheload_bundle.Clear(); this._meta_bundle.Clear(); this._phase = eUPdatePhase.xUP_Ending; } public bool ContainRes(uint hash) { return this._res_list.ContainsKey(hash); } public UnityEngine.Object ResourceLoad(uint hash) { UnityEngine.Object result = null; XResPackage xresPackage = null; bool flag = this._res_list != null && this._res_list.TryGetValue(hash, out xresPackage); if (flag) { bool flag2 = !this._persist_assets.TryGetValue(hash, out result); if (flag2) { AssetBundle assetBundle = null; uint key = XSingleton.singleton.XHash(xresPackage.bundle); bool flag3 = !this._bundles.TryGetValue(key, out assetBundle); if (flag3) { byte[] array = null; bool flag4 = !this._persist_image.TryGetValue(key, out array); if (flag4) { XBundleData data = null; bool flag5 = this._assets.TryGetValue(key, out data); if (!flag5) { return null; } array = XSingleton.singleton.LoadFile(XSingleton.singleton.GetLocalPath(data)); } assetBundle = AssetBundle.LoadFromMemory(array); this._bundles.Add(key, assetBundle); } string text = xresPackage.location.Substring(xresPackage.location.LastIndexOf('/') + 1); result = assetBundle.LoadAsset(text, XUpdater.Ass.GetType(xresPackage.type)); } } return result; } private AsyncVersionProcessRequest OnVersionDownloaded(TextAsset text) { AsyncVersionProcessRequest avpr = new AsyncVersionProcessRequest(); XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_INFO_FETCHMANIFEST"), byte.MaxValue, byte.MaxValue, byte.MaxValue); bool flag = text != null; if (flag) { byte[] contents = text.bytes; //! new Thread((ThreadStart)delegate { avpr.IsCorrect = this.LoadVersion(contents); avpr.IsDone = true; }).Start(); } else { avpr.IsDone = true; avpr.IsCorrect = false; } return avpr; } private void OnVersionLoaded(bool correct) { if (correct) { this._phase = eUPdatePhase.xUP_CompareVersion; } else { this._log.Remove(0, this._log.Length); this._log.Append(XSingleton.singleton.GetString("XUPDATE_ERROR_MANIFESTERROR")); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); XSingleton.singleton.OnError(); } } private void OnBundleFetched(WWW www, byte[] bytes, XBundleData data, bool newdownload) { if (newdownload) { XSingleton.singleton.AddLog("Finished Download ", data.Name, null, null, null, null, XDebugColor.XDebug_None); this._log.Remove(0, this._log.Length); this._log.AppendFormat(XSingleton.singleton.GetString("XUPDATE_INFO_DOWNLOAD_FILE_COMPLETE"), data.Name); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); } else { XSingleton.singleton.AddLog("Finished Extract ", data.Name, null, null, null, null, XDebugColor.XDebug_None); this._log.Remove(0, this._log.Length); this._log.AppendFormat(XSingleton.singleton.GetString("XUPDATE_INFO_EXTRACTING_COMPLETE"), data.Name); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); } uint key = XSingleton.singleton.XHash(data.Name); bool load = false; this._bundle_data = data; switch (this._bundle_data.Level) { case AssetLevel.Memory: load = true; break; case AssetLevel.Image: { byte[] array = new byte[bytes.Length]; bytes.CopyTo(array, 0); this._persist_image.Add(key, array); break; } } this._assets.Add(key, this._bundle_data); this._bundle_getter.GetBundle(www, bytes, new HandleLoadBundle(this.OnBundleLoaded), load); } private void OnBundleLoaded(AssetBundle bundle) { bool flag = bundle != null; if (flag) { this._bundles.Add(XSingleton.singleton.XHash(this._bundle_data.Name), bundle); } this._bundle_fetching = false; } private void OnAssetLoaded(XResPackage package, UnityEngine.Object asset) { uint key = XSingleton.singleton.XHash(package.location); bool flag = asset != null; if (flag) { bool flag2 = !this._persist_assets.ContainsKey(key); if (flag2) { this._persist_assets.Add(key, asset); } else { this._persist_assets[key] = asset; } } this._asset_loading = false; } private void UpdateLocalVersion(Stream s) { this._buildin = this.FetchBuildIn(s); this._client = this.FetchBuildOut(); bool flag = this._buildin != null; if (flag) { XSingleton.singleton.AddLog("BuildIn version: ", this._buildin.ToString(), null, null, null, null, XDebugColor.XDebug_None); } bool flag2 = this._client != null; if (flag2) { XSingleton.singleton.AddLog("BuildOut version: ", this._client.ToString(), null, null, null, null, XDebugColor.XDebug_None); } this._need_play_cg = (this._client == null); bool flag3 = this._client == null; if (flag3) { this._client = new XVersionData(this._buildin); bool flag4 = !XSingleton.singleton.CleanCache(); if (flag4) { this._log.Remove(0, this._log.Length); this._log.Append(XSingleton.singleton.GetString("XUPDATE_ERROR_DELETEDENIED")); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); XSingleton.singleton.OnError(); } } else { int num = this._client.CompareTo(this._buildin); bool flag5 = num < 0 || this._buildin.Build_Version != this._client.Build_Version; if (flag5) { this._need_play_cg = true; this._client.VersionCopy(this._buildin); bool flag6 = !XSingleton.singleton.CleanCache(); if (flag6) { this._log.Remove(0, this._log.Length); this._log.Append(XSingleton.singleton.GetString("XUPDATE_ERROR_DELETEDENIED")); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); XSingleton.singleton.OnError(); } } } XSingleton.singleton.AddLog("Client version: ", this._client.ToString(), null, null, null, null, XDebugColor.XDebug_None); } private XVersionData FetchBuildIn(Stream s) { bool flag = s == null; XVersionData result; if (flag) { result = null; } else { StreamReader streamReader = new StreamReader(s); string version = streamReader.ReadToEnd(); result = XVersionData.Convert2Version(version); } return result; } private XVersionData FetchBuildOut() { string localVersion = XVersion.GetLocalVersion(); XSingleton.singleton.AddLog("Local Version Path " + localVersion, null, null, null, null, null, XDebugColor.XDebug_None); XVersionData result = null; bool flag = File.Exists(localVersion); if (flag) { byte[] buffer = this.XCryptography(File.ReadAllBytes(localVersion)); using (MemoryStream memoryStream = new MemoryStream(buffer)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(XVersionData)); try { result = (xmlSerializer.Deserialize(memoryStream) as XVersionData); } catch (Exception ex) { result = null; XSingleton.singleton.AddLog("Build Out Version Fetching FAILED! " + ex.Message, null, null, null, null, null, XDebugColor.XDebug_None); } finally { memoryStream.Close(); } } } else { XSingleton.singleton.AddLog("Local Version Path " + localVersion + " not exists.", null, null, null, null, null, XDebugColor.XDebug_None); } return result; } private bool LoadVersion(byte[] text) { string a = BitConverter.ToString(text, 0, XUpdater.Md5Length); string b = XSingleton.singleton.CalculateMD5(text, XUpdater.Md5Length, text.Length - XUpdater.Md5Length); bool flag = a == b; if (flag) { using (MemoryStream memoryStream = new MemoryStream(text, XUpdater.Md5Length, text.Length - XUpdater.Md5Length)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(XVersionData)); this._server = (xmlSerializer.Deserialize(memoryStream) as XVersionData); bool flag2 = this._server != null && this._server.Target_Platform == this._runtime_platform; if (flag2) { XSingleton.singleton.AddLog("Server version: ", this._server.ToString(), null, null, null, null, XDebugColor.XDebug_None); return true; } } } XSingleton.singleton.AddLog("Analysis Server version error!", null, null, null, null, null, XDebugColor.XDebug_None); this._server = null; return false; } private bool CheckMemory() { return true; } private bool Preparing() { Stream stream = null; XSingleton.singleton.AddLog("Fetch local version...", null, null, null, null, null, XDebugColor.XDebug_None); bool flag = (int)Application.platform == 8; if (flag) { stream = XSingleton.singleton.ReadText("ios-version", ".bytes", false); } else { bool flag2 = (int)Application.platform == 11; if (flag2) { stream = XSingleton.singleton.ReadText("android-version", ".bytes", false); } } bool flag3 = stream != null; bool result; if (flag3) { this.UpdateLocalVersion(stream); XSingleton.singleton.ClearStream(stream); result = true; } else { result = (XUpdater.LaunchMode == XLaunchMode.Dev); } return result; } private IEnumerator VersionComparer() { int compare = this._client.CompareTo(this._server); this._update_pakcage_size = 0UL; bool flag = compare > 0; if (flag) { this._server = this._client; this._download_prepare = null; this.DownLoadConfirmed(false); } else { bool flag2 = compare == 0 || (compare < 0 && this._client.CanUpdated(this._server)); if (flag2) { bool flag3 = this._download_prepare == null; if (flag3) { this._download_prepare = this.DownLoadPrepare(); } while (this._download_prepare.MoveNext()) { yield return null; } this._download_prepare = null; this.DownLoadConfirmed(compare != 0); } else { XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_ERROR_VERSIONNOTMATCH"), byte.MaxValue, byte.MaxValue, byte.MaxValue); this.ShowVersionInfo(this._client, false); Texture tex = null; bool flag4 = !this._is_download_update_pic; if (flag4) { WWW www = new WWW("https://image.lzgjx.qq.com/sharingicon/updateimg.jpg"); while (!www.isDone) { yield return null; } bool flag5 = string.IsNullOrEmpty(www.error); if (flag5) { tex = www.texture; } www.Dispose(); this._is_download_update_pic = true; www = null; } this._phase = eUPdatePhase.xUP_Error; XSingleton.singleton.SetDownLoad(new XLoadingUI.OnSureCallBack(this.ToAppStore), tex); tex = null; } } yield break; } private void ToAppStore() { RuntimePlatform platform = Application.platform; if ((int)platform != 8) { if ((int)platform == 11) { for (int i = 0; i < this._client.Res.Count; i++) { bool flag = this._client.Res[i].location == "Table/StringTable"; if (flag) { XBundleData specificBundle = this._client.GetSpecificBundle(this._client.Res[i].bundle); string localPath = XSingleton.singleton.GetLocalPath(specificBundle); try { byte[] array = File.ReadAllBytes(localPath); bool flag2 = array != null; if (flag2) { AssetBundle assetBundle = AssetBundle.LoadFromMemory(array); bool flag3 = assetBundle != null; if (flag3) { TextAsset textAsset = assetBundle.LoadAsset("StringTable", typeof(TextAsset)) as TextAsset; bool flag4 = textAsset != null; if (flag4) { bool flag5 = !XSingleton.singleton.ReInit(textAsset); if (flag5) { XSingleton.singleton.SyncInit(); } } } } } catch (Exception ex) { XSingleton.singleton.AddErrorLog("ToAndroidAppStore: ", ex.Message, null, null, null, null); } break; } } string @string = XSingleton.singleton.GetString("XUPDATE_ERROR_VERSIONNOTMATCH_ANDROID_URL"); XSingleton.singleton.AddLog("AndroidAppStore Url: ", @string, null, null, null, null, XDebugColor.XDebug_None); Application.OpenURL(@string); } } else { for (int j = 0; j < this._client.Res.Count; j++) { bool flag6 = this._client.Res[j].location == "Table/StringTable"; if (flag6) { XBundleData specificBundle2 = this._client.GetSpecificBundle(this._client.Res[j].bundle); string localPath2 = XSingleton.singleton.GetLocalPath(specificBundle2); try { byte[] array2 = File.ReadAllBytes(localPath2); bool flag7 = array2 != null; if (flag7) { AssetBundle assetBundle2 = AssetBundle.LoadFromMemory(array2); bool flag8 = assetBundle2 != null; if (flag8) { TextAsset textAsset2 = assetBundle2.LoadAsset("StringTable", typeof(TextAsset)) as TextAsset; bool flag9 = textAsset2 != null; if (flag9) { bool flag10 = !XSingleton.singleton.ReInit(textAsset2); if (flag10) { XSingleton.singleton.SyncInit(); } } } } } catch (Exception ex2) { XSingleton.singleton.AddErrorLog("ToAppStore: ", ex2.Message, null, null, null, null); } break; } } string string2 = XSingleton.singleton.GetString("XUPDATE_ERROR_VERSIONNOTMATCH_URL"); XSingleton.singleton.AddLog("AppStore Url: ", string2, null, null, null, null, XDebugColor.XDebug_None); Application.OpenURL(string2); } } private void DownLoadConfirmedCallBack() { this._phase = eUPdatePhase.xUP_DownLoadBundle; } private void DownLoadCancelledCallBack() { this._phase = eUPdatePhase.xUP_Error; XSingleton.singleton.SetStatus("", byte.MaxValue, byte.MaxValue, byte.MaxValue); this.ShowVersionInfo(this._client, false); } private void DownLoadConfirmed(bool updated) { if (updated) { bool flag = this._update_pakcage_size < 1048576UL; if (flag) { this.DownLoadConfirmedCallBack(); } else { XSingleton.singleton.SetDialog(this._update_pakcage_size, new XLoadingUI.OnSureCallBack(this.DownLoadConfirmedCallBack), new XLoadingUI.OnSureCallBack(this.DownLoadCancelledCallBack)); this._phase = eUPdatePhase.xUP_DownLoadConfirm; } } else { this._phase = eUPdatePhase.xUP_DownLoadBundle; } } private IEnumerator DownLoadPrepare() { int num; for (int i = 0; i < this._server.Res.Count; i = num + 1) { bool flag = !this._buildin.NeedDownload(this._server.Res[i].bundle); if (!flag) { XBundleData bundle = this._server.GetSpecificBundle(this._server.Res[i].bundle); bool flag2 = bundle == null; if (flag2) { XSingleton.singleton.AddLog("Bundle ", this._server.Res[i].bundle, " is missing in sever bundle set.", null, null, null, XDebugColor.XDebug_None); } else { bool flag3 = this._cacheload_bundle.Contains(bundle); if (!flag3) { bool flag4 = this._download_bundle.Contains(bundle); if (!flag4) { AsyncCachedRequest acr = XSingleton.singleton.IsBundleCached(bundle, this._server.MD5_Size); while (!acr.IsDone) { yield return null; } bool flag5 = !acr.Cached && acr.MaybeCached; if (flag5) { XBundleData clientData = null; foreach (XBundleData data in this._client.Bundles) { bool flag6 = data.Name == bundle.Name; if (flag6) { clientData = data; break; } //data = null; } List.Enumerator enumerator = default(List.Enumerator); acr.Cached = (clientData != null && clientData.MD5 == bundle.MD5); clientData = null; } XSingleton.singleton.AddLog("Bundle ", bundle.Name, " cached is ", acr.Cached.ToString(), null, null, XDebugColor.XDebug_None); bool cached = acr.Cached; if (cached) { this._cacheload_bundle.Add(bundle); } else { this._download_bundle.Add(bundle); this._update_pakcage_size += (ulong)bundle.Size; } bundle = null; acr = null; } } } } num = i; } this.MetaPrepare(this._server.AB); this.MetaPrepare(this._server.Scene); this.MetaPrepare(this._server.FMOD); yield break; } private void MetaPrepare(List meta) { bool flag = this._platform != null && !this._platform.IsPublish(); for (int i = 0; i < meta.Count; i++) { bool flag2 = !this._buildin.NeedDownload(meta[i].bundle) || !this._client.NeedDownload(meta[i].bundle); if (!flag2) { bool flag3 = !this._meta_bundle.Contains(meta[i]); if (flag3) { this._meta_bundle.Add(meta[i]); } bool flag4 = flag; if (flag4) { XSingleton.singleton.AddLog("Meta ", meta[i].download, " is prepared to downloading...", null, null, null, XDebugColor.XDebug_None); } this._update_pakcage_size += (ulong)meta[i].Size; } } } private IEnumerator DownLoadBundles() { bool log = this._platform != null && !this._platform.IsPublish(); int total = this._download_bundle.Count + this._cacheload_bundle.Count + this._meta_bundle.Count; int processed = 0; int num; for (int i = 0; i < this._download_bundle.Count; i = num + 1) { while (this._bundle_fetching) { yield return null; } bool flag = log; if (flag) { XSingleton.singleton.AddLog("Updating ", this._download_bundle[i].Name, " ... ", processed.ToString(), "/", total.ToString(), XDebugColor.XDebug_None); } this._bundle_fetching = true; num = processed + 1; processed = num; XSingleton.singleton.Download(this._download_bundle[i], new HandleFetchBundle(this.OnBundleFetched), (float)processed / (float)total); num = i; } for (int j = 0; j < this._cacheload_bundle.Count; j = num + 1) { while (this._bundle_fetching) { yield return null; } bool flag2 = log; if (flag2) { XSingleton.singleton.AddLog("Extracting ", this._cacheload_bundle[j].Name, " ... ", processed.ToString(), "/", total.ToString(), XDebugColor.XDebug_None); } this._bundle_fetching = true; num = processed + 1; processed = num; bool flag3 = (int)Application.platform == 8; if (flag3) { while (!XSingleton.singleton.Extract(this._cacheload_bundle[j], new HandleFetchBundle(this.OnBundleFetched), (float)processed / (float)total)) { yield return null; } } else { XSingleton.singleton.Extract(this._cacheload_bundle[j], new HandleFetchBundle(this.OnBundleFetched), (float)processed / (float)total); } num = j; } while (this._bundle_fetching) { yield return null; } for (int k = 0; k < this._meta_bundle.Count; k = num + 1) { num = processed + 1; processed = num; AsyncWriteRequest awr = XSingleton.singleton.Download(this._meta_bundle[k].download, this._meta_bundle[k].Size, (float)processed / (float)total); bool flag4 = log; if (flag4) { XSingleton.singleton.AddLog("Download meta ", this._meta_bundle[k].download, " ... ", processed.ToString(), "/", total.ToString(), XDebugColor.XDebug_None); } while (!awr.IsDone) { bool hasError = awr.HasError; if (hasError) { bool on_file_download_retry = this._on_file_download_retry; if (on_file_download_retry) { this._on_file_download_retry = false; this._on_file_download_need_retry = false; num = k; k = num - 1; num = processed; processed = num - 1; this._log.Length = 0; this._log.Append(XSingleton.singleton.GetString("XUPDATE_INFO_RETRY")); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); yield return null; break; } this._on_file_download_need_retry = true; this._log.Length = 0; this._log.AppendFormat(XSingleton.singleton.GetString("XUPDATE_ERROR_DOWNLOADRESFAILED_AND_RETRY"), awr.Name); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); yield return null; } else { yield return null; } } awr = null; num = k; } for (int l = 0; l < this._server.Res.Count; l = num + 1) { bool flag5 = this.ProcessAssets(this._server.Res[l]); if (flag5) { bool flag6 = this._server.Res[l].rtype != ResourceType.Script; if (flag6) { uint hash = XSingleton.singleton.XHash(this._server.Res[l].location); this._res_list.Add(hash, this._server.Res[l]); } this._log.Remove(0, this._log.Length); this._log.AppendFormat(XSingleton.singleton.GetString("XUPDATE_INFO_PRELOADING"), ((float)l / (float)this._server.Res.Count * 100f).ToString("F0")); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); bool flag7 = l << 30 == 0; if (flag7) { yield return null; } } num = l; } AsyncLogRequest alr = this.LogNewVersion(); while (!alr.IsDone) { Thread.Sleep(1); } this.XPlatform.SetNoBackupFlag(XVersion.GetLocalVersion()); yield break; } private AsyncLogRequest LogNewVersion() { AsyncLogRequest alr = new AsyncLogRequest(); bool flag = this._server != this._client; if (flag) { new Thread((ThreadStart)delegate { using (MemoryStream memoryStream = new MemoryStream()) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(XVersionData)); XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces(); xmlSerializerNamespaces.Add(string.Empty, string.Empty); xmlSerializer.Serialize(memoryStream, this._server, xmlSerializerNamespaces); File.WriteAllBytes(XVersion.GetLocalVersion(), this.XCryptography(memoryStream.ToArray())); } alr.IsDone = true; }).Start(); } else { alr.IsDone = true; } return alr; } private void ShowVersionInfo(XVersionData data, bool launch = true) { bool flag = data != null; if (flag) { this._log.Remove(0, this._log.Length); this._log.Append("v").Append(data.ToString()); XSingleton.singleton.SetVersion(this._log.ToString()); } else { XSingleton.singleton.SetVersion("Dev 0.0.0"); } if (launch) { this._phase = eUPdatePhase.xUP_LaunchGame; } } private bool ProcessAssets(XResPackage res) { AssetBundle assetBundle = null; bool flag = this._bundles.TryGetValue(XSingleton.singleton.XHash(res.bundle), out assetBundle); bool result; if (flag) { string text = res.location.Substring(res.location.LastIndexOf('/') + 1); ResourceType rtype = res.rtype; if (rtype != ResourceType.Assets) { if (rtype == ResourceType.Script) { TextAsset textAsset = assetBundle.LoadAsset(text, XUpdater.Ass.GetType(res.type)) as TextAsset; this._script = textAsset.bytes; assetBundle.Unload(false); this._bundles.Remove(XSingleton.singleton.XHash(res.bundle)); } } else { this.OnAssetLoaded(res, assetBundle.LoadAsset(text, XUpdater.Ass.GetType(res.type))); } result = true; } else { result = false; } return result; } private IEnumerator AsyncProcessAssets(XResPackage package, AssetBundle bundle) { string name = package.location.Substring(package.location.LastIndexOf('/') + 1); this._asset_loading = true; this._bundle_getter.GetAsset(bundle, package, new HandleLoadAsset(this.OnAssetLoaded)); while (this._asset_loading) { yield return null; } yield break; } private IEnumerator LaunchGame() { XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_INFO_LOADING"), byte.MaxValue, byte.MaxValue, byte.MaxValue); yield return null; this.ABManager.Init(); this.XPlatform.ReloadFMOD(); AsyncAssemblyRequest aar = new AsyncAssemblyRequest(); ResourceRequest rrq = null; bool flag = (int) Application.platform == 11; if (flag) { string path = Application.persistentDataPath + "/XMainClient.bytes"; bool flag2 = File.Exists(path); if (flag2) { this._script = File.ReadAllBytes(path); } bool flag3 = this._script == null && (int)Application.platform == 11; if (flag3) { rrq = Resources.LoadAsync("XMainClient", typeof(TextAsset)); yield return rrq; this._script = (rrq.asset as TextAsset).bytes; } path = null; } RuntimePlatform platform = Application.platform; if ((int)platform != 8) { if ((int)platform != 11) { } //! // aar.Main = ((this._script == null) ? Assembly.Load("XMainClient") : Assembly.Load(this._script)); } else { // aar.Main = Assembly.Load("XMainClient"); } // XSingleton.singleton.MakeEntrance(aar.Main); XSingleton.singleton._MakeEntrance(); bool flag4 = rrq != null && rrq.asset != null; if (flag4) { Resources.UnloadAsset(rrq.asset); } this._script = null; this._log.Remove(0, this._log.Length); this._log.Append(XSingleton.singleton.GetString("XUPDATE_INFO_LAUNCHING")); XSingleton.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue); yield return null; XSingleton.singleton.PreLaunch(); while (!XSingleton.singleton.Launched()) { yield return null; XSingleton.singleton.Launch(); } this.XLuaEngine.InitLua(); yield break; } private byte[] XCryptography(byte[] bs) { for (int i = 0; i < bs.Length; i++) { bs[i] ^= 154; } return bs; } private string PatchPrefix() { XLaunchMode launchMode = XUpdater.LaunchMode; string result; if (launchMode != XLaunchMode.Live) { if (launchMode != XLaunchMode.PreProduct) { if (launchMode != XLaunchMode.Dev) { result = "Patch/Live/"; } else { result = "Patch/Dev/"; } } else { result = "Patch/PreProduct/"; } } else { result = "Patch/Live/"; } return result; } private void GetLaunchMode() { XUpdater._launch_mode = XLaunchMode.Dev; } public void PlayCG(object o = null) { this._video.Play(false); } public void SetServerVersion(string data) { string b = ""; bool flag = this._buildin != null; if (flag) { b = this._buildin.Build_Version.ToString(); } string[] array = data.Split(new char[] { '|' }); RuntimePlatform platform = Application.platform; if ((int)platform != 8) { if ((int)platform == 11) { this._target_version = array[1]; try { bool flag2 = array.Length > 4; if (flag2) { string[] array2 = array[4].Split(new char[] { ':' }); for (int i = 0; i < array2.Length; i++) { string[] array3 = array2[i].Split(new char[] { '.' }); bool flag3 = array3.Length > 1 && array3[1] == b; if (flag3) { this._target_version = array2[i]; } } } } catch (Exception ex) { XSingleton.singleton.AddErrorLog("GetServer ExData Error!!! " + ex.Message, null, null, null, null, null); } } } else { this._target_version = array[0]; try { bool flag4 = array.Length > 3; if (flag4) { string[] array4 = array[3].Split(new char[] { ':' }); for (int j = 0; j < array4.Length; j++) { string[] array5 = array4[j].Split(new char[] { '.' }); bool flag5 = array5.Length > 1 && array5[1] == b; if (flag5) { this._target_version = array4[j]; } } } } catch (Exception ex2) { XSingleton.singleton.AddErrorLog("GetServer ExData Error!!! " + ex2.Message, null, null, null, null, null); } } try { bool flag6 = array.Length > 2; if (flag6) { this._need_check_file = (array[2] == "1"); } } catch (Exception ex3) { XSingleton.singleton.AddErrorLog("GetServer CheckFile Flag Error!!! " + ex3.Message, null, null, null, null, null); } XSingleton.singleton.AddGreenLog(data, null, null, null, null, null); this._fetch_version_network.Close(); this._phase = eUPdatePhase.xUP_LoadVersion; } } }