Exemplo n.º 1
0
        /*
         * Emotes only visible by others with the mod.
         * The host needs to have the mod, to others with the mod use it.
         * If the host does not have the mod, it will not work.
         */
        public override void Entry(IModHelper helper)
        {
            ModMonitor = Monitor;

            ModPatchControl PatchContol = new ModPatchControl(helper);

            PatchContol.PatchList.Add(new FarmerPatch.DoEmotePatch(helper.Reflection));
            PatchContol.PatchList.Add(new CharacterPatch.DoEmotePatch(helper.Reflection));
            PatchContol.PatchList.Add(new MultiplayerPatch.ProcessIncomingMessagePatch());
            PatchContol.ApplyPatch();

            this.Monitor.Log("Loading mod config...", LogLevel.Debug);
            Config = helper.ReadConfig <ModConfig>();

            this.Monitor.Log("Loading mod data...", LogLevel.Debug);
            Data = this.Helper.ReadJsonFile <ModData>("data.json") ?? new ModData();

            SaveEvents.AfterLoad += this.AfterLoad;

            // TODO: Command to stop emotes from NPC and FarmAnimals
            helper.ConsoleCommands.Add("emote", "Play the emote animation with the passed id.\n\nUsage: emote <value>\n- value: a integer representing the animation id.", this.Emote);
            helper.ConsoleCommands.Add("stop_emote", "Stop any emote being played by you.\n\nUsage: stop_emote", this.StopEmote);
            helper.ConsoleCommands.Add("stop_all_emotes", "Stop any emote being played.\n\nUsage: stop_all_emotes", this.StopAllEmotes);
        }
Exemplo n.º 2
0
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            ModMonitor = Monitor;

#if DEBUG
            //Logger.InitLogger(helper.DirectoryPath + "\\logfile.txt", false, Monitor);
#endif

            #region Harmony Patches

            ModPatchControl patchControl = new ModPatchControl(helper);
            patchControl.PatchList.Add(new MultiplayerPatch.ProcessIncomingMessagePatch());
            patchControl.PatchList.Add(new MultiplayerPatch.AddPlayerPatch());
            patchControl.PatchList.Add(new MultiplayerPatch.PlayerDisconnectedPatch());
            //PatchControl.PatchList.Add(new MultiplayerPatch.SendChatMessagePatch());
            //PatchControl.PatchList.Add(new MultiplayerPatch.ReceiveChatMessagePatch());
            patchControl.PatchList.Add(new Game1Patch.DrawOverlaysPatch());

            /*
             * PatchControl.PatchList.Add(new MultiplayerPatch.ReceivePlayerIntroductionPatch());
             */

            IClassPatch receiveChatMessage = null;
            IClassPatch addMessagePatch    = null;
            if (helper.ModRegistry.IsLoaded("cat.chatcommands"))
            {
                receiveChatMessage = new ModSupportPatch.ChatCommands_ReceiveChatMessage();
                addMessagePatch    = new ModSupportPatch.ChatCommands_AddMessagePatch();
                patchControl.PatchList.Add(new ModSupportPatch.ChatCommands_AddConsoleMessagePatch(helper.Reflection));
            }

            patchControl.PatchList.Add(receiveChatMessage ?? new ChatBoxPatch.ReceiveChatMessagePatch());
            patchControl.PatchList.Add(addMessagePatch ?? new ChatBoxPatch.AddMessagePatch());

            patchControl.ApplyPatch();

            #endregion

            this.Monitor.Log("Loading mod config...", LogLevel.Trace);
            this.config = helper.ReadConfig <ModConfig>();

#if !DEBUG || TRUE
#if DEBUG
            ModLogger = new Logger(Path.Combine(helper.DirectoryPath, "logfile.txt"), false, Monitor);
#endif
            this.Monitor.Log("Loading mod data...", LogLevel.Trace);
            this.modData = this.Helper.Data.ReadJsonFile <ModData>(ModPaths.Data.Path);
            if (this.modData == null)
            {
                this.Monitor.Log("Mod data file not found. (harmless info)", LogLevel.Trace);
                this.modData = new ModData(helper, config.ImageExtensions)
                {
                    WatchedPaths = new List <string>()
                    {
                        ModPaths.Assets.InputFolder
                    }
                };
            }
            else
            {
                modData.FileExtensionsFilter = config.ImageExtensions;
                modData.ModHelper            = helper;
            }

            emojiAssetsLoader = new EmojiAssetsLoader(helper, modData, config, EmojiMenu.EMOJI_SIZE);
#else
            this.Monitor.Log("Loading debug data file...", LogLevel.Trace);
            this.modDebugData = this.Helper.Data.ReadJsonFile <ModDebugData>("debugData.json") ?? new ModDebugData();

            //string configPath = Path.Combine(Constants.ExecutionPath, "Mods", "SkipIntro", "config.json");
            //string json = File.ReadAllText(configPath);
            //dynamic jsonObj = JsonConvert.DeserializeObject(json);
            //if((string)(jsonObj["SkipTo"]) == "HostCoop") {
            //	jsonObj["SkipTo"] = "JoinCoop";
            //	modDebugData.IsHost = true;
            //} else {
            //	jsonObj["SkipTo"] = "HostCoop";
            //	modDebugData.IsHost = false;
            //}
            //string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
            //File.WriteAllText(configPath, output);

            if (modDebugData.ActAsHost())
            {
                this.Helper.Data.WriteJsonFile("debugData.json", modDebugData);
                Monitor.Log($"====> HOST <====");

                ModLogger = new Logger(Path.Combine(helper.DirectoryPath, "logfile.txt"), false, Monitor);
                this.Monitor.Log("Loading mod data...", LogLevel.Trace);
                this.modData = this.Helper.Data.ReadJsonFile <ModData>(ModPaths.Data.Path);
                if (this.modData == null)
                {
                    this.Monitor.Log("Mod data file not found. (harmless info)", LogLevel.Trace);
                    this.modData = new ModData(helper, config.ImageExtensions)
                    {
                        WatchedPaths = new List <string>()
                        {
                            ModPaths.Assets.InputFolder
                        }
                    };
                }
                else
                {
                    modData.FileExtensionsFilter = config.ImageExtensions;
                    modData.ModHelper            = helper;
                }

                emojiAssetsLoader = new EmojiAssetsLoader(helper, modData, config, EmojiMenu.EMOJI_SIZE);
            }
            else
            {
                this.Helper.Data.WriteJsonFile("debugData.json", modDebugData);
                Monitor.Log($"====> CLIENT <====");
                ModLogger = new Logger(Path.Combine(helper.DirectoryPath, "logfileClient.txt"), false, Monitor);
                ModPaths.Assets.InputFolder = ModPaths.Assets.InputFolder + "CLIENT";
                ModPaths.Assets.Folder      = ModPaths.Assets.Folder + "CLIENT";
                ModPaths.Data.Path          = "dataCLIENT.json";

                this.Monitor.Log("Loading mod data...", LogLevel.Trace);
                this.modData = this.Helper.Data.ReadJsonFile <ModData>(ModPaths.Data.Path);
                if (this.modData == null)
                {
                    this.Monitor.Log("Mod data file not found. (harmless info)", LogLevel.Trace);
                    this.modData = new ModData(helper, config.ImageExtensions)
                    {
                        WatchedPaths = new List <string>()
                        {
                            ModPaths.Assets.InputFolder
                        }
                    };
                }
                else
                {
                    modData.FileExtensionsFilter = config.ImageExtensions;
                    modData.ModHelper            = helper;
                }

                emojiAssetsLoader = new EmojiAssetsLoader(helper, modData, config, EmojiMenu.EMOJI_SIZE);
            }
#endif

            helper.Content.AssetLoaders.Add(emojiAssetsLoader);

            //helper.ConsoleCommands.Add("reload_emojis", "Reload the game emojis with the new ones found in the mod folder.", this.ReloadEmojis);

            helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded;
        }