Example #1
0
        public static void InitializeAll()
        {
            try
            {
                if (!_init)
                {
                    VanillaLogger.Info("Game Starting!");
                    //Called from the very first line of SplashScreenFlowManager.Start - literally the line of code that is executed first as far as I can tell.

                    //First things first, let's get harmony set up.
                    Harmony = HarmonyInstance.Create("samboy.clonedronemoddingzone_harmonyinst");
                    Harmony.PatchAll(Assembly.GetExecutingAssembly());

                    HarmonyHooks.DoInitialPatches();

                    _init = true;
                }
            }
            catch (Exception e)
            {
                ModZoneLogger.Exception(e, "Error during initialization");
            }
        }
        private void Awake()
        {
            _logger.Info("Splash! Manager injected successfully.");

            var uiRoot = SceneManager.GetActiveScene().GetRootGameObjects().First(o => o.name.Contains("UIRoot"));

            modText = Instantiate(SplashScreenFlowManager.Instance.SaveDataLabel, uiRoot.transform, true);

            var canvasRect = uiRoot.GetComponent <Canvas>().pixelRect;

            _logger.Debug($"Splash screen dimensions are {canvasRect.width} by {canvasRect.height}");

            var transform1 = modText.transform;

            transform1.localPosition = new Vector3(-30, 280);
            modText.gameObject.SetActive(true);
            modText.text      = "CDMZ : Running Init Patches";
            modText.alignment = TextAnchor.UpperLeft;

            _logger.Debug($"Injected splash screen label at pos {transform1.localPosition}. Size {modText.preferredWidth}x{modText.preferredHeight}: {modText}");

            //SceneManager.GetActiveScene().DumpHierarchy(_logger);

            var launchThread = new Thread(() =>
            {
                try
                {
                    HarmonyHooks.DoOnLoadPatches();

                    if (!Directory.Exists(_modDirectoryPath))
                    {
                        Directory.CreateDirectory(_modDirectoryPath);
                    }

                    modText.text = "CDMZ: Discovering mods";

                    foreach (var file in Directory.GetFiles(_modDirectoryPath))
                    {
                        if (!file.EndsWith(".dll"))
                        {
                            continue;
                        }

                        _logger.Debug($"Loading assembly {file}");
                        try
                        {
                            var asm = Assembly.LoadFile(file);
                            ReflectionHelper.ModAssemblies.Add(asm);
                        }
                        catch (Exception e)
                        {
                            _logger.Exception(e, $"Failed to load assembly {file}");
                        }
                    }

                    modText.text = "CDMZ: Constructing mods";

                    ModManager.ConstructAll();

                    modText.text = "CDMZ: Loading ModBot mods in compatibility mode";

                    ModManager.LoadModBotMods();

                    modText.text = "CDMZ: Setting up event bus";

                    new EventBus();

                    modText.text = "CDMZ: Enabling mods";

                    ModManager.ExecuteEnableForEnabledMods();

                    modText.text = "CDMZ: Done";

                    _finishedLoading = true;
                }
                catch (Exception e)
                {
                    _logger.Exception(e, "Caught exception during launch");
                }
            })
            {
                IsBackground = true
            };

            launchThread.Start();
        }