using asap.core; using asap.core.common; using game; using Game; using GameCore; using System; using System.IO; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using AppsFlyerSDK; using DataCenter; using Script.RuntimeScript; using ThinkingData.Analytics; using tysdk; using UnityEngine; using UnityEngine.Networking; using UnityEngine.Rendering.Universal; using UnityEngine.AddressableAssets; using Newtonsoft.Json.Linq; using MoreMountains.NiceVibrations; public class SubBoostrap { public static async System.Threading.Tasks.Task RegisterServices(GameObject rootCtxGo) { var container = GContext.container; VibrationController vibrationController = new VibrationController(); vibrationController.Init(); container.RegisterInstance(vibrationController); container.Register().AsSingleton(); #if AGG && !UNITY_EDITOR //AIHelp init //string appKey = "TUYOOGAME_app_a6e73dd23da84d5ab72a5f68e4a58271"; string domain = "tuyoogame.aihelp.net"; #if UNITY_ANDROID string appId = "tuyoogame_platform_7a6a236be774b7a82c23d3e59f7d1476"; #elif UNITY_IOS string appId = "tuyoogame_platform_782757bd1f7ba24498cd9df0d0b9f214"; #endif AIHelp.AIHelpSupport.enableLogging(false); AIHelp.AIHelpSupport.AdditionalSupportFor(AIHelp.PublishCountryOrRegion.IN); AIHelp.AIHelpSupport.RegisterAsyncEventListener(AIHelp.EventType.Initialization, (jsonEventData, ack) =>Debug.Log($"[HotUpateBoostrap] AIHelpInitialized {JObject.Parse(jsonEventData).ToString()}")); AIHelp.AIHelpSupport.Initialize(domain, appId); #endif //AIHelp init end #if AGG var heartBeat = new HeartBeat(); #endif using (container.InjectionScope()) { #if AGG container.RegisterInstance(heartBeat); #endif container.Register().AsSingleton(); container.Register().AsSingleton(); container.Register().AsSingleton(); container.Register().AsSingleton(); } #if AGG heartBeat.Init(); #endif var rtsManager = new GameObject("RTSManager").AddComponent(); GameObject.DontDestroyOnLoad(rtsManager); /* * _____ ___ ____ ___ *|_ _/ _ \| _ \ / _ \ * | || | | | | | | | | | * | || |_| | |_| | |_| | * |_| \___/|____/ \___/ */ // TODO Refactor all managers #if UNITY_EDITOR UnityEngine.Application.runInBackground = true; GameCore.GameEventMgr.Init(true); #else GameCore.GameEventMgr.Init(); #endif rootCtxGo.AddComponent(); // TODO Replace DataCenter with seprated data class // Create(); // ----------------------------------------- await Awaiters.NextFrame; GameCore.Timer.Create(); //-----------------------TODO-------------------------- Debug.Log("[HotUpateBoostrap] RegisterServices Done"); await Awaiters.NextFrame; } public static async System.Threading.Tasks.Task AfterAssetUpdate(IConfig config, Action progressAction) { #if UNITY_EDITOR var tables = await cfg.Tables.InitEditor(progress => progressAction(0.16f + progress * 0.02f)); #else var tables = await cfg.Tables.Init(progress => progressAction(0.16f + progress * 0.02f)); #endif var container = GContext.container; GContext.container.RegisterInstance(tables); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.RegisterInstance(new AvatarService()); var settings = new DefaultSettingService(); settings.Init(tables); GContext.container.RegisterInstance(settings); GameCore.LocalizationMgr.Init(); QualityManager.AutoSetQualityLevel(); RootCtx.showFPS = !string.IsNullOrEmpty(config.Get(GConstant.K_FPS, string.Empty)); DebugFunc.Init(); zzwater.URPHelper.RendererFeatureSetActive(false, "FSBlur"); zzwater.URPHelper.RendererFeatureSetActive(false, "FSWave"); await InitVibration(); //#if UNITY_ANDROID //RequestAndriodPermission(); //#endif await Awaiters.NextFrame; await GContext.container.Resolve().Init(); IAdsService adsService; if (Application.isEditor) { adsService = new DevAdsService(); } else { adsService = new AggAdsService(settings); } adsService.Init(); GContext.container.RegisterInstance(adsService); Debug.Log("[HotUpateBoostrap] AfterAssetUpdate Done"); } public static async System.Threading.Tasks.Task ShowLoadingScreen(IConfig config, GameObject rootCtxGo) { var fxClick = await Addressables.InstantiateAsync("TopUIFX").Task; if (fxClick != null) { fxClick.name = "TopUIFX"; GameObject.DontDestroyOnLoad(fxClick); } else { Debug.LogError("TopUIFX is null"); } // TODO replace with new UI service await GameCore.UIManager.Init( UITypes.UIRoot, GameCore.ScreenType.PORTRAIT, () => MessageDialog.ShowErrorDialog(-20, "Default Waiting Timeout") ); var uiCam = rootCtxGo.FindChildGameObject("UICamera").GetComponent(); var ui3DCam = rootCtxGo.FindChildGameObject("UI3DCamera").GetComponent(); UIManager.SetUICamera(uiCam, ui3DCam); //Camera.main.SetCamStack(); await LoadingScreen.Show(0.19f); //LoadingScreen.SetVersionInfo($"Ver {Application.version}"); var reVer = VersionTool.FromString(config.Get(GConstant.K_Ver, string.Empty)); reVer.Save(); LoadingScreen.SetVersionInfo(reVer.ToVerString()); Debug.Log("[HotUpateBoostrap] ShowLoadingScreen Done"); } private static async Task InitVibration() { var data = await Addressables.LoadAssetAsync("vibrationdata").Task; if (null != data) { var jsonData = JObject.Parse(data.text); if (jsonData.ContainsKey("Soft")) { var soft = jsonData["Soft"]; MMVibrationManager.SoftDuration = soft["duration"].Value(); MMVibrationManager.SoftAmplitude = soft["amplitude"].Value(); } if (jsonData.ContainsKey("Rigid")) { var rigid = jsonData["Rigid"]; MMVibrationManager.RigidDuration = rigid["duration"].Value(); MMVibrationManager.RigidAmplitude = rigid["amplitude"].Value(); } if (jsonData.ContainsKey("Light")) { var light = jsonData["Light"]; MMVibrationManager.LightDuration = light["duration"].Value(); MMVibrationManager.LightAmplitude = light["amplitude"].Value(); } if (jsonData.ContainsKey("Heavy")) { var heavy = jsonData["Heavy"]; MMVibrationManager.LightDuration = heavy["duration"].Value(); MMVibrationManager.LightAmplitude = heavy["amplitude"].Value(); } if (jsonData.ContainsKey("Medium")) { var medium = jsonData["Medium"]; MMVibrationManager.LightDuration = medium["duration"].Value(); MMVibrationManager.LightAmplitude = medium["amplitude"].Value(); } } } //#if UNITY_ANDROID //private static void RequestAndriodPermission() //{ //if(!UnityEngine.Android.Permission.HasUserAuthorizedPermission("android.permission.QUERY_ALL_PACKAGES")) //{ //UnityEngine.Android.Permission.RequestUserPermission("android.permission.QUERY_ALL_PACKAGES"); //} //} //#endif } // public static class CameraExtension // { // public static void SetCamStack(this Camera cam) // { // if (cam != Camera.main) return; // // For URP rendering, add UICamera into main scene camera's stack // // // Camera ui_cam = null; // // if (GameCore.UIManager.Instance != null) // { // ui_cam = GameCore.UIManager.Instance.UICamera; // } // // if (ui_cam != null && cam != ui_cam) // { // var cam_stack = cam.GetUniversalAdditionalCameraData().cameraStack; // // if (!cam_stack.Contains(ui_cam)) // { // cam_stack.Add(ui_cam); // } // } // } // } #if UNITY_EDITOR public class InternalEditorBoost { public static async Task Boost() { UnityEngine.Debug.Log("Editor Internal Boot"); GContext.container.Register().AsSingleton(); await GameCore.UIManager.Init( UITypes.UIRoot, GameCore.ScreenType.PORTRAIT, () => MessageDialog.ShowErrorDialog(-20, "Default Waiting Timeout") ); var ieb = new InternalEditorBoost(); await ieb.LoadConfig(); await ieb.Init(); } private async Task LoadConfig() { var config = GContext.container.Resolve(); // Load Debug Config var debugConfigPath = Path.Combine(Application.persistentDataPath, GConstant.V_Debug_Config_Path); string remoteConfigUrl = null; SimpleJSON.JSONNode debugConfig = null; if (File.Exists(debugConfigPath)) { #if UNITY_EDITOR Debug.Log($"Debug config [{debugConfigPath}] in use"); #endif debugConfig = SimpleJSON.JSON.Parse(File.ReadAllText(debugConfigPath)); if (debugConfig.HasKey(GConstant.K_Static_Res_URL)) { remoteConfigUrl = debugConfig[GConstant.K_Static_Res_URL]; #if UNITY_EDITOR Debug.Log($"Debug Static Res URL => {remoteConfigUrl}"); #endif } } // load remote Config remoteConfigUrl = remoteConfigUrl ?? string.Format(GConstant.V_Static_Res_URL, VersionTool.PackVer); var request = UnityWebRequest.Get($"{remoteConfigUrl}/{GConstant.V_Remote_Config_Path}"); await request.SendWebRequest(); if (request.result != UnityWebRequest.Result.Success) throw new Exception($"Load Config Error: {request.error}"); string remoteConfigStr = request.downloadHandler.text; remoteConfigStr = Decrypt(remoteConfigStr); var remoteConfig = SimpleJSON.JSON.Parse(remoteConfigStr); // Merge Configs foreach (var element in remoteConfig) { config.Set(element.Key, element.Value.Value); } if (null != debugConfig) { foreach (var element in debugConfig) { config.Set(element.Key, element.Value.Value); } } // Change Addressable remote location, using custom assetbundle server var customAddressableRemoteURL = config.Get(GConstant.K_Custom_Addressable, string.Empty); var originAddressableRemoteURL = config.Get(GConstant.K_Origin_Addressable, string.Empty); if (!string.IsNullOrEmpty(customAddressableRemoteURL) && !string.IsNullOrEmpty(originAddressableRemoteURL)) { var ctx = (RootCtx)typeof(GContext).GetField("root", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null); ctx.ChangeAddressableRemoteUrl(customAddressableRemoteURL, originAddressableRemoteURL); } } string RTMKey = "tbambooz"; public string Decrypt(string text) { DESCryptoServiceProvider des = new DESCryptoServiceProvider(); des.Key = Encoding.ASCII.GetBytes(RTMKey); des.IV = Encoding.ASCII.GetBytes(RTMKey); ICryptoTransform decryptor = des.CreateDecryptor(des.Key, des.IV); byte[] inputBytes = Convert.FromBase64String(text); byte[] outputBytes = decryptor.TransformFinalBlock(inputBytes, 0, inputBytes.Length); return Encoding.UTF8.GetString(outputBytes); } private async Task Init() { var tables = await cfg.Tables.Init(x => { Debug.Log(x); }); GContext.container.RegisterInstance(tables); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); using (var scope = GContext.container.InjectionScope()) { #if AGG GContext.container.Register().AsSingleton(); #else GContext.container.Register().AsSingleton(); #endif GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); //GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); // GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); //GContext.container.Register().AsSingleton(); //GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); GContext.container.Register().AsSingleton(); } var settings = new DefaultSettingService(); settings.Init(tables); GContext.container.RegisterInstance(settings); GameCore.LocalizationMgr.Init(); await GContext.container.Resolve().Init(); } } #endif