Exemplo n.º 1
0
        public override void Entry(IModHelper help)
        {
            AssemblyPath = help.DirectoryPath;

            var ConfigPath = Path.Combine(help.DirectoryPath, ConfigName);

            using (var tempStream = new MemoryStream()) {
                SerializeConfig.Save(tempStream);

                if (!Config.IgnoreConfig)
                {
                    SerializeConfig.Load(ConfigPath);
                }

                if (IsVersionOutdated(Config.ConfigVersion))
                {
                    Debug.WarningLn("config.toml is out of date, rewriting it.");
                    SerializeConfig.Load(tempStream);
                    Config.ConfigVersion = Config.CurrentVersion;
                }
            }

            if (Config.ShowIntroMessage && !Config.SkipIntro)
            {
                help.Events.GameLoop.GameLaunched += (_, _1) => {
                    Game1.drawLetterMessage("Welcome to SpriteMaster!\nSpriteMaster must resample sprites as it sees them and thus some lag will likely be apparent at the start of the game, upon entering new areas, and when new sprites are seen.\n\nPlease be patient and do not take this as an indication that your computer is incapable of running SpriteMaster.\n\nEnjoy!".Replace("\n", "^"));
                };
                Config.ShowIntroMessage = false;
            }

            SerializeConfig.Save(ConfigPath);

            ConfigureHarmony();
            help.Events.Input.ButtonPressed += OnButtonPressed;

            help.ConsoleCommands.Add("spritemaster_stats", "Dump SpriteMaster Statistics", (_, _1) => { ManagedTexture2D.DumpStats(); });
            help.ConsoleCommands.Add("spritemaster_memory", "Dump SpriteMaster Memory", (_, _1) => { Debug.DumpMemory(); });

            //help.ConsoleCommands.Add("night", "make it dark", (_, _1) => { help.ConsoleCommands.Trigger("world_settime", new string[] { "2100" }); });

            help.Events.GameLoop.DayStarted += OnDayStarted;
            // GC after major events
            help.Events.GameLoop.SaveLoaded += (_, _1) => Garbage.Collect(compact: true, blocking: true, background: false);

            if (MemoryPressureThread != null)
            {
                MemoryPressureThread.Start();
            }
            if (GarbageCollectThread != null)
            {
                GarbageCollectThread.Start();
            }
        }