Example #1
0
        public override void Entry(IModHelper helper)
        {
            ModInstance = this;

            LoadUserConfig();

            //  Load custom machine settings
            MachineConfig GlobalMachineConfig = helper.Data.ReadJsonFile <MachineConfig>(MachineConfigFilename);

            if (GlobalMachineConfig == null)
            {
                string DefaultConfigRelativePath = Path.Combine("assets", MachineConfigFilename);
                GlobalMachineConfig = helper.Data.ReadJsonFile <MachineConfig>(DefaultConfigRelativePath);
                if (GlobalMachineConfig != null)
                {
                    try
                    {
                        string DefaultConfigAbsolutePath = Path.Combine(helper.DirectoryPath, DefaultConfigRelativePath);
                        string TargetPath = Path.Combine(helper.DirectoryPath, Path.GetFileName(DefaultConfigAbsolutePath));
                        File.Copy(DefaultConfigAbsolutePath, TargetPath);
                    }
                    catch { }
                }
            }
#if DEBUG
            //GlobalMachineConfig = null; // Force full refresh of config file for testing purposes
#endif
            if (GlobalMachineConfig == null)
            {
                GlobalMachineConfig = new MachineConfig();
                helper.Data.WriteJsonFile(MachineConfigFilename, GlobalMachineConfig);
            }
            MachineConfig = GlobalMachineConfig;
            MachineInfo.LoadAugmentableMachineData();

            MachineInfo.IsPrismaticToolsModInstalled = helper.ModRegistry.IsLoaded("stokastic.PrismaticTools");

            Helper.Events.Display.RenderedWorld += Display_RenderedWorld;
            Helper.Events.GameLoop.Saving       += GameLoop_Saving;
            Helper.Events.GameLoop.SaveLoaded   += GameLoop_SaveLoaded;
            Helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked;
            Helper.Events.Input.CursorMoved     += Input_CursorMoved;
            Helper.Events.Display.MenuChanged   += Display_MenuChanged;
            helper.Events.GameLoop.DayStarted   += GameLoop_DayStarted;
            Helper.Events.Input.ButtonPressed   += Input_ButtonPressed;

            #region Game Patches
            HarmonyInstance Harmony = HarmonyInstance.Create(this.ModManifest.UniqueID);

            //  Patch Object.performObjectDropInAction, so that we can detect when items are put into a machine, and then modify the output based on attached augmentors
            Harmony.Patch(
                original: AccessTools.Method(typeof(Object), nameof(Object.performObjectDropInAction)),
                prefix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.PerformObjectDropInAction_Prefix)),
                postfix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.PerformObjectDropInAction_Postfix))
                );

            //  Patch Object.checkForAction, so that we can detect when processed items are collected from machines that don't require input,
            //  and then we can modify the new processed items based on attached augmentors
            Harmony.Patch(
                original: AccessTools.Method(typeof(Object), nameof(Object.checkForAction)),
                prefix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.CheckForAction_Prefix)),
                postfix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.CheckForAction_Postfix))
                );

            //  Patch Object.draw, so that we can draw icons of the attached augmentors after the object is drawn to a tile of the game world
            Harmony.Patch(
                original: AccessTools.Method(typeof(Object), nameof(Object.draw), new Type[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }),
                postfix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.Draw_Postfix))
                );

            //  Patch GameLocation.monsterDrop, so that we can give a small chance of making monsters also drop augmentors
            Harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.monsterDrop)),
                postfix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.MonsterDrop_Postfix))
                );
            #endregion Game Patches

            RegisterConsoleCommands();
        }
        public override void Entry(IModHelper helper)
        {
            ModInstance = this;

            //  Load global user settings into memory
            UserConfig GlobalUserConfig = helper.Data.ReadJsonFile <UserConfig>(UserConfigFilename);

#if DEBUG
            //GlobalUserConfig = null; // Force full refresh of config file for testing purposes
#endif
            if (GlobalUserConfig != null)
            {
                bool RewriteConfig = false;

                //  Version 1.0.5 added additional settings to augmentor formulas
                if (GlobalUserConfig.CreatedByVersion < new Version(1, 0, 5))
                {
                    RewriteConfig = true;
                }

                if (RewriteConfig)
                {
                    GlobalUserConfig.CreatedByVersion = CurrentVersion;
                    helper.Data.WriteJsonFile(UserConfigFilename, GlobalUserConfig);
                }
            }
            else
            {
                GlobalUserConfig = new UserConfig()
                {
                    CreatedByVersion = CurrentVersion
                };
                helper.Data.WriteJsonFile(UserConfigFilename, GlobalUserConfig);
            }
            GlobalUserConfig.AfterLoaded();
            UserConfig = GlobalUserConfig;

            //  Load custom machine settings
            MachineConfig GlobalMachineConfig = helper.Data.ReadJsonFile <MachineConfig>(Path.Combine("assets", MachineConfigFilename));
#if DEBUG
            //GlobalMachineConfig = null; // Force full refresh of config file for testing purposes
#endif
            if (GlobalMachineConfig == null)
            {
                GlobalMachineConfig = new MachineConfig();
                helper.Data.WriteJsonFile(MachineConfigFilename, GlobalMachineConfig);
            }
            MachineConfig = GlobalMachineConfig;
            MachineInfo.LoadAugmentableMachineData();

            MachineInfo.IsPrismaticToolsModInstalled = helper.ModRegistry.IsLoaded("stokastic.PrismaticTools");

            Helper.Events.Display.RenderedWorld += Display_RenderedWorld;
            Helper.Events.GameLoop.Saving       += GameLoop_Saving;
            Helper.Events.GameLoop.SaveLoaded   += GameLoop_SaveLoaded;
            Helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked;
            Helper.Events.Input.CursorMoved     += Input_CursorMoved;
            Helper.Events.Display.MenuChanged   += Display_MenuChanged;
            helper.Events.GameLoop.DayStarted   += GameLoop_DayStarted;

            #region Game Patches
            HarmonyInstance Harmony = HarmonyInstance.Create(this.ModManifest.UniqueID);

            //  Patch Object.performObjectDropInAction, so that we can detect when items are put into a machine, and then modify the output based on attached augmentors
            Harmony.Patch(
                original: AccessTools.Method(typeof(Object), nameof(Object.performObjectDropInAction)),
                prefix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.PerformObjectDropInAction_Prefix)),
                postfix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.PerformObjectDropInAction_Postfix))
                );

            //  Patch Object.checkForAction, so that we can detect when processed items are collected from machines that don't require input,
            //  and then we can modify the new processed items based on attached augmentors
            Harmony.Patch(
                original: AccessTools.Method(typeof(Object), nameof(Object.checkForAction)),
                prefix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.CheckForAction_Prefix)),
                postfix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.CheckForAction_Postfix))
                );

            //  Patch Object.draw, so that we can draw icons of the attached augmentors after the object is drawn to a tile of the game world
            Harmony.Patch(
                original: AccessTools.Method(typeof(Object), nameof(Object.draw), new Type[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }),
                postfix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.Draw_Postfix))
                );

            //  Patch GameLocation.monsterDrop, so that we can give a small chance of making monsters also drop augmentors
            Harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.monsterDrop)),
                postfix: new HarmonyMethod(typeof(GamePatches), nameof(GamePatches.MonsterDrop_Postfix))
                );
            #endregion Game Patches

            RegisterConsoleCommands();
        }