Esempio n. 1
0
 /// <summary>
 /// Handles broadcasting data from player to player.
 /// </summary>
 /// <param name="multiplayer">SMAPI's multiplayer helper.</param>
 /// <param name="playerIDs">Player IDs to send to. Leave null to mean everyone.</param>
 internal static void BroadcastData(IMultiplayerHelper multiplayer, long[]?playerIDs = null)
 {
     if (Context.IsMultiplayer)
     {
         multiplayer.SendMessage(data, RecieveDataValue, new[] { ModEntry.UNIQUEID }, playerIDs);
     }
 }
Esempio 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)
        {
            Dice             = new Xoshiro.PRNG64.XoShiRo256starstar();
            Translation      = Helper.Translation;
            ModConfig        = Helper.ReadConfig <MoonConfig>();
            OurMoon          = new SDVMoon(ModConfig, Dice, Helper.Translation, Monitor);
            ContentManager   = Helper.Content;
            MPHandler        = Helper.Multiplayer;
            OurIcons         = new Sprites.Icons(Helper.Content);
            queuedMsg        = null;
            BloodMoonTracker = new List <string>();

            helper.Events.GameLoop.GameLaunched          += OnGameLaunched;
            helper.Events.GameLoop.OneSecondUpdateTicked += OnOneSecondUpdateTicked;
            helper.Events.GameLoop.TimeChanged           += OnTimeChanged;
            helper.Events.GameLoop.DayStarted            += OnDayStarted;
            helper.Events.GameLoop.DayEnding             += GameLoop_DayEnding;
            helper.Events.GameLoop.SaveLoaded            += GameLoop_SaveLoaded;
            helper.Events.GameLoop.Saving            += OnSaving;
            helper.Events.GameLoop.UpdateTicked      += OnUpdateTicked;
            helper.Events.Display.RenderedActiveMenu += OnRenderedActiveMenu;
            helper.Events.Display.MenuChanged        += OnMenuChanged;
            helper.Events.Player.Warped                  += OnWarped;
            helper.Events.GameLoop.ReturnedToTitle       += OnReturnedToTitle;
            helper.Events.Multiplayer.ModMessageReceived += OnModMessageRecieved;

            SpaceEvents.ChooseNightlyFarmEvent += SpaceEvents_ChooseNightlyFarmEvent;

            helper.ConsoleCommands.Add("force_bloodmoon", "Forces a bloodmoon", ForceBloodMoon)
            .Add("force_bloodmoonoff", "Turns bloodmoon off.", TurnBloodMoonOff)
            .Add("show_mooninfo", "Show moon info", ShowMoonInfo)
            .Add("force_eclipseOn", "Turns eclipse on.", OurMoon.TurnEclipseOn);
        }
Esempio n. 3
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="dataHelper">An API for reading and storing local mod data.</param>
 /// <param name="multiplayer">Provides multiplayer utilities.</param>
 /// <param name="reflection">Simplifies access to private code.</param>
 /// <param name="enableShippingBin">Whether to support access to the shipping bin.</param>
 public ChestFactory(IDataHelper dataHelper, IMultiplayerHelper multiplayer, IReflectionHelper reflection, bool enableShippingBin)
 {
     this.DataHelper        = dataHelper;
     this.Multiplayer       = multiplayer;
     this.Reflection        = reflection;
     this.EnableShippingBin = enableShippingBin;
 }
 public static void SendMessageInMultiplayer <TMessage>(this IMultiplayerHelper self, Func <TMessage> message, string type, string[]?modIDs = null, long[]?playerIDs = null)
     where TMessage : notnull
 {
     if (GameExt.GetMultiplayerMode() != MultiplayerMode.SinglePlayer)
     {
         self.SendMessage(message(), type, modIDs, playerIDs);
     }
 }
        public NetworkOperator(IMultiplayerHelper helper, IMultiplayerEvents events, QuestStateStore questStateStore, StatsManager statsManager, QuestController questController, IManifest modManifest, IMonitor monitor)
        {
            this.helper          = helper;
            this.questStateStore = questStateStore;
            this.questController = questController;
            this.statsManager    = statsManager;
            this.modManifest     = modManifest;
            this.monitor         = monitor;

            events.ModMessageReceived += this.OnMessageReceived;
            events.PeerConnected      += this.OnClientConnected;
        }
Esempio n. 6
0
        /*********
        ** Accessors
        *********/

        /// <summary>The menu instance for which the overlay was created.</summary>
        public DeliveryOverlay(IMonitor monitor, ItemGrabMenu menu, DeliveryChest chest, IModHelper helper, string modid, long hostid)
            : base(helper.Events, helper.Input, keepAlive: () => Game1.activeClickableMenu is ItemGrabMenu)
        {
            this.Menu        = menu;
            this.Chest       = chest;
            this.Monitor     = monitor;
            this.Multiplayer = helper.Multiplayer;
            this.ModID       = modid;
            this.HostID      = hostid;
            this.origInventoryHighlighter = this.Menu.inventory.highlightMethod;
            this.origChestHighlighter     = this.Menu.ItemsToGrabMenu.highlightMethod;

            this.EditSaveButtonArea = new ClickableComponent(new Rectangle(0, 0, Game1.tileSize, Game1.tileSize), "save-delivery");
            this.SendCategories     = Category.CategoryList(chest.DeliveryOptions.Send);
            this.ReceiveCategories  = Category.CategoryList(chest.DeliveryOptions.Receive);
            this.MatchColor         = new Checkbox(chest.DeliveryOptions.MatchColor);
            //this.bounds = new Rectangle(this.Menu.xPositionOnScreen, this.Menu.yPositionOnScreen, this.Menu.width, this.Menu.Height);
            this.LabelHeight   = (int)Game1.smallFont.MeasureString("ABC").Y + 2;
            this.maxLabelWidth = 24 + 10 + (int)this.SendCategories.Select(p => Game1.smallFont.MeasureString(p.Name()).X).Max();
            int width =
                100 +                 // border
                this.maxLabelWidth +  // label
                40 + 10 * 26 +        // checkbox
                11 * Game1.pixelZoom; //scrollbar

            this.bounds = new Rectangle((Game1.viewport.Width - width) / 2, 10, width, Game1.viewport.Height - 20);

            this.scrollbar = new ScrollBar(helper.Events, helper.Input,
                                           new Rectangle(
                                               this.bounds.X + 10 * Game1.pixelZoom,
                                               this.bounds.Y + 10 * Game1.pixelZoom + 3 * LabelHeight,
                                               this.bounds.Width - 20 * Game1.pixelZoom,
                                               this.bounds.Height - 20 * Game1.pixelZoom - 5 * LabelHeight),
                                           this.SendCategories.Count,
                                           LabelHeight);
            if (!Context.IsMainPlayer)
            {
                this.Multiplayer.SendMessage(new SerializableChestLocation(chest), "RequestDeliveryOptions", modIDs: new[] { this.ModID }, playerIDs: new[] { this.HostID });
            }
        }
        /// <summary>
        /// The main player removes the warp at the portalPosition
        /// </summary>
        public static bool RemoveWarp(PortalPosition portalPosition, bool IsMainPlayer, PortalGunManager portalGuns, IMultiplayerHelper multiplayer, string uniqueModId)
        {
            // Warps are global, so only have host handle them to avoid duplicates and ghosts
            if (!IsMainPlayer)
            {
                multiplayer.SendMessage(portalPosition, "RemoveWarp", modIDs: new[] { uniqueModId });
                return(false);
            }
            string locationName = portalPosition.LocationName;

            if (locationName == "" || locationName == null)
            {
                return(false);
            }
            GameLocation location = Game1.getLocationFromName(portalPosition.LocationName);

            // remove the warp from the location
            Warp warp = portalGuns.GetWarp(portalPosition);

            if (warp != null)
            {
                location.warps.Remove(portalGuns.GetWarp(portalPosition));
            }

            return(true);
        }
        /// <summary>
        /// The main player adds the warp to the world
        /// </summary>
        public static bool AddWarp(PortalPosition portalPosition, bool IsMainPlayer, PortalGunManager portalGuns, IMultiplayerHelper multiplayer, string uniqueModId)
        {
            if (portalPosition.LocationName == "" || portalPosition.LocationName == null)
            {
                return(false);
            }
            // Warps are global, so only have host handle them to avoid duplicates and ghosts
            if (!IsMainPlayer)
            {
                multiplayer.SendMessage(portalPosition, "AddWarp", modIDs: new[] { uniqueModId });
                return(true);
            }
            // if a warp was created, add it
            Warp warp = portalGuns.GetWarp(portalPosition);

            if (warp == null)
            {
                return(false);
            }

            // add it to the game location
            Game1.getLocationFromName(portalPosition.LocationName).warps.Add(warp);
            return(true);
        }
Esempio n. 9
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="modID">The mod's unique ID.</param>
        /// <param name="modDirectory">The full path to the mod's folder.</param>
        /// <param name="jsonHelper">Encapsulate SMAPI's JSON parsing.</param>
        /// <param name="inputState">Manages the game's input state.</param>
        /// <param name="events">Manages access to events raised by SMAPI.</param>
        /// <param name="contentHelper">An API for loading content assets.</param>
        /// <param name="contentPackHelper">An API for managing content packs.</param>
        /// <param name="commandHelper">An API for managing console commands.</param>
        /// <param name="dataHelper">An API for reading and writing persistent mod data.</param>
        /// <param name="modRegistry">an API for fetching metadata about loaded mods.</param>
        /// <param name="reflectionHelper">An API for accessing private game code.</param>
        /// <param name="multiplayer">Provides multiplayer utilities.</param>
        /// <param name="translationHelper">An API for reading translations stored in the mod's <c>i18n</c> folder.</param>
        /// <exception cref="ArgumentNullException">An argument is null or empty.</exception>
        /// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception>
        public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper)
            : base(modID)
        {
            // validate directory
            if (string.IsNullOrWhiteSpace(modDirectory))
            {
                throw new ArgumentNullException(nameof(modDirectory));
            }
            if (!Directory.Exists(modDirectory))
            {
                throw new InvalidOperationException("The specified mod directory does not exist.");
            }

            // initialise
            this.DirectoryPath   = modDirectory;
            this.Content         = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper));
            this.ContentPacks    = contentPackHelper ?? throw new ArgumentNullException(nameof(contentPackHelper));
            this.Data            = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper));
            this.Input           = new InputHelper(modID, inputState);
            this.ModRegistry     = modRegistry ?? throw new ArgumentNullException(nameof(modRegistry));
            this.ConsoleCommands = commandHelper ?? throw new ArgumentNullException(nameof(commandHelper));
            this.Reflection      = reflectionHelper ?? throw new ArgumentNullException(nameof(reflectionHelper));
            this.Multiplayer     = multiplayer ?? throw new ArgumentNullException(nameof(multiplayer));
            this.Translation     = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper));
            this.Events          = events;
#if !SMAPI_3_0_STRICT
            this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper));
#endif
        }
        /// <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)
        {
            RWeatherIcon = new Rectangle();
            WeatherOpt   = helper.ReadConfig <WeatherConfig>();
            Logger       = Monitor;
            Translator   = Helper.Translation;
            Reflection   = Helper.Reflection;
            MPHandler    = Helper.Multiplayer;
            Dice         = new Xoshiro.PRNG64.XoShiRo256starstar();
            OurIcons     = new Sprites.Icons(Helper.Content);
            WeatherProcessing.Init();
            Conditions         = new WeatherConditions();
            DescriptionEngine  = new Descriptions(WeatherOpt, Helper.Translation);
            queuedMsg          = null;
            SummitRebornLoaded = false;

            if (WeatherOpt.Verbose)
            {
                Monitor.Log($"Loading climate type: {WeatherOpt.ClimateType} from file", LogLevel.Trace);
            }

            var path = Path.Combine("assets", "climates", WeatherOpt.ClimateType + ".json");

            GameClimate = helper.Data.ReadJsonFile <FerngillClimate>(path);

            if (GameClimate is null)
            {
                this.Monitor.Log($"The required '{path}' file is missing. Try reinstalling the mod to fix that.", LogLevel.Error);
                this.Monitor.Log("This mod will now disable itself.", LogLevel.Error);
                this.Disabled = true;
            }

            if (Disabled)
            {
                return;
            }

            var harmony = new Harmony("koihimenakamura.climatesofferngill");

            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), "drawAboveAlwaysFrontLayer"),
                transpiler: new HarmonyMethod(AccessTools.Method(typeof(GameLocationPatches), "DAAFLTranspiler")));
            Monitor.Log("Patching GameLocation::drawAboveAlwaysFrontLayer with a Transpiler.", LogLevel.Trace);

            harmony.Patch(
                original: AccessTools.Method(typeof(Game1), "drawWeather"),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(Game1Patches), "DrawWeatherPrefix")));
            Monitor.Log("Patching Game1::drawWeather with a prefix method.", LogLevel.Trace);

            harmony.Patch(
                original: AccessTools.Method(typeof(Game1), "updateWeather"),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(Game1Patches), "UpdateWeatherPrefix")));
            Monitor.Log("Patching Game1::updateWeather with a prefix method.", LogLevel.Trace);

            harmony.Patch(
                original: AccessTools.Method(AccessTools.TypeByName("StardewModdingAPI.Framework.SGame"), "DrawImpl"),
                transpiler: new HarmonyMethod(AccessTools.Method(typeof(SGamePatches), "DrawImplTranspiler")));
            Monitor.Log("Patching SMAPI (SGame::DrawImpl) with a transpiler.", LogLevel.Trace);

            harmony.Patch(
                original: AccessTools.Constructor(AccessTools.TypeByName("StardewValley.WeatherDebris"), new[] { typeof(Vector2), typeof(int), typeof(float), typeof(float), typeof(float) }),
                postfix: new HarmonyMethod(AccessTools.Method(typeof(WeatherDebrisPatches), "CtorPostfix")));
            Monitor.Log("Patching WeatherDebris's constructor method with a postfix method.", LogLevel.Trace);

            harmony.Patch(
                original: AccessTools.Method(typeof(WeatherDebris), "draw"),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(WeatherDebrisPatches), "DrawPrefix")));
            Monitor.Log("Patching WeatherDebris::draw with a prefix method.", LogLevel.Trace);

            harmony.Patch(
                original: AccessTools.Method(typeof(WeatherDebris), "update", new[] { typeof(bool) }),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(WeatherDebrisPatches), "UpdatePrefix")));
            Monitor.Log("Patching WeatherDebris::draw with a prefix method.", LogLevel.Trace);

            //INSERT DNT CHECKS HERE
            var modManifest = Helper.ModRegistry.Get("knakamura.dynamicnighttime");

            if (modManifest != null)
            {
                if (modManifest.Manifest.Version.IsOlderThan("1.2.11"))
                {
                    Monitor.Log("WARNING: Overcast weather may not work correctly unless you are running Dynamic Night Time 1.2.11 or later", LogLevel.Alert);
                }
            }
            else
            {
                harmony.Patch(
                    original: AccessTools.Method(typeof(Game1), "UpdateGameClock"),
                    postfix: new HarmonyMethod(AccessTools.Method(typeof(GameClockPatch), "Postfix")));
                Monitor.Log("Patching Game1::UpdateGameClock with a Postfix method. (Used only when Climates is installed and DNT is not.)", LogLevel.Trace);
            }

            ConsoleCommands.Init();
            SanityCheckConfigOptions();

            //subscribe to events
            var events = helper.Events;

            events.GameLoop.DayStarted            += OnDayStarted;
            events.GameLoop.Saving                += OnSaving;
            events.GameLoop.TimeChanged           += OnTimeChanged;
            events.Display.MenuChanged            += OnMenuChanged;
            events.GameLoop.UpdateTicked          += OnUpdateTicked;
            events.GameLoop.GameLaunched          += OnGameLaunched;
            events.GameLoop.OneSecondUpdateTicked += OnOneSecondUpdateTicked;
            events.GameLoop.ReturnedToTitle       += OnReturnedToTitle;
            events.GameLoop.SaveLoaded            += OnSaveLoaded;
            events.Display.RenderedWorld          += Display_RenderedWorld;
            //events.Display.RenderingHud += OnRenderingHud;
            events.Display.RenderedHud            += OnRenderedHud;
            events.Input.ButtonPressed            += OnButtonPressed;
            events.Multiplayer.ModMessageReceived += OnModMessageRecieved;

            //console commands
            helper.ConsoleCommands
            .Add("world_tmrwweather", helper.Translation.Get("console-text.desc_tmrweather"), ConsoleCommands.TomorrowWeatherChangeFromConsole)
            .Add("world_setweather", helper.Translation.Get("console-text.desc_setweather"), ConsoleCommands.WeatherChangeFromConsole)
            .Add("debug_clearspecial", "debug command to clear special weathers", ConsoleCommands.ClearSpecial)
            .Add("debug_weatherstatus", "!", ConsoleCommands.OutputWeather)
            .Add("debug_sswa", "Show Special Weather", ConsoleCommands.ShowSpecialWeather)
            .Add("debug_vrainc", "Set Rain Amt.", ConsoleCommands.SetRainAmt)
            .Add("debug_raindef", "Set Rain Deflection.", ConsoleCommands.SetRainDef)

            /*
             *  .Add("debug_setwindchance", "Set Wind Chance", ConsoleCommands.SetWindChance)
             *  .Add("debug_setwindtresh", "Set Wind Threshold", ConsoleCommands.SetWindThreshold)
             *  .Add("debug_setwindrange", "Set Wind Range", ConsoleCommands.SetWindRange)
             *  .Add("debug_raintotal", "Get Rain Total", ConsoleCommands.DisplayRainTotal)
             *  .Add("debug_getcurrentwind", "Show wind values", ConsoleCommands.ShowWind)
             *  .Add("debug_resetwind", "Reset Global Wind", ConsoleCommands.ResetGlobalWind)
             */
            .Add("debug_printClimate", "Print Climate Tracker Data", ConsoleCommands.DisplayClimateTrackerData);
        }
Esempio n. 11
0
 /// <summary>
 /// Call for the host only = saves data to the save.
 /// </summary>
 /// <param name="dataHelper">SMAPI's data helper.</param>
 /// <param name="multiplayerHelper">SMAPI's multiplayer helper.</param>
 internal static void SaveData(IDataHelper dataHelper, IMultiplayerHelper multiplayerHelper)
 {
     dataHelper.WriteSaveData(SAVEDATAKEY, data);
     BroadcastData(multiplayerHelper);
 }
Esempio n. 12
0
 /// <summary>
 /// Call for host only = loads the data from the save.
 /// </summary>
 /// <param name="dataHelper">SMAPI's data helper.</param>
 /// <param name="multiplayerHelper">SMAPI's multiplayer helper.</param>
 internal static void LoadData(IDataHelper dataHelper, IMultiplayerHelper multiplayerHelper)
 {
     data = dataHelper.ReadSaveData <VolcanoData>(SAVEDATAKEY) ?? new();
     BroadcastData(multiplayerHelper);
 }
        /// <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)
        {
            RWeatherIcon = new Rectangle();
            WeatherOpt   = helper.ReadConfig <WeatherConfig>();
            Logger       = Monitor;
            Translator   = Helper.Translation;
            Reflection   = Helper.Reflection;
            MPHandler    = Helper.Multiplayer;
            Dice         = new MersenneTwister();
            OurIcons     = new Sprites.Icons(Helper.Content);
            WeatherProcessing.Init();
            Conditions         = new WeatherConditions();
            DescriptionEngine  = new Descriptions(WeatherOpt, Helper.Translation);
            queuedMsg          = null;
            SummitRebornLoaded = false;

            if (WeatherOpt.Verbose)
            {
                Monitor.Log($"Loading climate type: {WeatherOpt.ClimateType} from file", LogLevel.Trace);
            }

            var path = Path.Combine("assets", "climates", WeatherOpt.ClimateType + ".json");

            GameClimate = helper.Data.ReadJsonFile <FerngillClimate>(path);

            if (GameClimate is null)
            {
                this.Monitor.Log($"The required '{path}' file is missing. Try reinstalling the mod to fix that.", LogLevel.Error);
                this.Monitor.Log("This mod will now disable itself.", LogLevel.Error);
                this.Disabled = true;
            }

            if (Disabled)
            {
                return;
            }

            var harmony = HarmonyInstance.Create("koihimenakamura.climatesofferngill");

            harmony.PatchAll(Assembly.GetExecutingAssembly());

            ConsoleCommands.Init();

            MethodInfo    GameLocationDAAFL = AccessTools.Method(typeof(GameLocation), "drawAboveAlwaysFrontLayer");
            HarmonyMethod DAAFLTranspiler   = new HarmonyMethod(AccessTools.Method(typeof(GameLocationPatches), "DAAFLTranspiler"));

            Monitor.Log($"Patching {GameLocationDAAFL} with Transpiler: {DAAFLTranspiler}", LogLevel.Trace);;
            harmony.Patch(GameLocationDAAFL, transpiler: DAAFLTranspiler);

            MethodInfo    GameDrawW         = AccessTools.Method(typeof(Game1), "drawWeather");
            HarmonyMethod DrawWeatherPrefix = new HarmonyMethod(AccessTools.Method(typeof(Game1Patches), "DrawWeatherPrefix"));

            Monitor.Log($"Patching {GameDrawW} with Prefix: {DrawWeatherPrefix}", LogLevel.Trace);;
            harmony.Patch(GameDrawW, prefix: DrawWeatherPrefix);

            Type          t             = AccessTools.TypeByName("StardewModdingAPI.Framework.SGame");
            MethodInfo    SGameDrawImpl = AccessTools.Method(t, "DrawImpl");
            HarmonyMethod DrawTrans     = new HarmonyMethod(AccessTools.Method(typeof(SGamePatches), "DrawImplTranspiler"));

            Monitor.Log($"Patching {SGameDrawImpl} with Transpiler: {DrawTrans}", LogLevel.Trace);
            harmony.Patch(SGameDrawImpl, transpiler: DrawTrans);

            t = AccessTools.TypeByName("StardewValley.WeatherDebris");
            var           DebrisConstructor = AccessTools.Constructor(t, new[] { typeof(Vector2), typeof(int), typeof(float), typeof(float), typeof(float) });
            HarmonyMethod CtorPatch         = new HarmonyMethod(AccessTools.Method(typeof(WeatherDebrisPatches), "CtorPostfix"));

            Monitor.Log($"Patching {DebrisConstructor} with Postfix: {CtorPatch}", LogLevel.Trace);
            harmony.Patch(DebrisConstructor, postfix: CtorPatch);

            MethodInfo    DebrisDraw  = AccessTools.Method(typeof(WeatherDebris), "draw");
            HarmonyMethod DebrisPatch = new HarmonyMethod(AccessTools.Method(typeof(WeatherDebrisPatches), "DrawPrefix"));

            Monitor.Log($"Patching {DebrisDraw} with Prefix: {DebrisDraw}", LogLevel.Trace);
            harmony.Patch(DebrisDraw, prefix: DebrisPatch);

            MethodInfo    DebrisUpdate      = AccessTools.Method(typeof(WeatherDebris), "update", new[] { typeof(bool) });
            HarmonyMethod DebrisUpdatePatch = new HarmonyMethod(AccessTools.Method(typeof(WeatherDebrisPatches), "UpdatePrefix"));

            Monitor.Log($"Patching {DebrisUpdate} with Prefix: {DebrisUpdatePatch}", LogLevel.Trace);
            harmony.Patch(DebrisUpdate, prefix: DebrisUpdatePatch);

            //INSERT DNT CHECKS HERE
            var modManifest = Helper.ModRegistry.Get("knakamura.dynamicnighttime");

            if (modManifest != null)
            {
                if (modManifest.Manifest.Version.IsOlderThan("1.2.11"))
                {
                    Monitor.Log("WARNING: Overcast weather may not work correctly unless you are running Dynamic Night Time 1.2.11 or later", LogLevel.Alert);
                }
            }
            else
            {
                //Normal Climates patch goes here.
                MethodInfo UpdateGameClock = helper.Reflection.GetMethod(SDVUtilities.GetSDVType("Game1"), "UpdateGameClock").MethodInfo;
                MethodInfo postfixClock    = helper.Reflection.GetMethod(typeof(Patches.GameClockPatch), "Postfix").MethodInfo;
                Monitor.Log($"Postfixing {UpdateGameClock} with {postfixClock}", LogLevel.Trace);
                harmony.Patch(UpdateGameClock, null, new HarmonyMethod(postfixClock));
            }

            SanityCheckConfigOptions();

            //subscribe to events
            var events = helper.Events;

            events.GameLoop.DayStarted            += OnDayStarted;
            events.GameLoop.Saving                += OnSaving;
            events.GameLoop.TimeChanged           += OnTimeChanged;
            events.Display.MenuChanged            += OnMenuChanged;
            events.GameLoop.UpdateTicked          += OnUpdateTicked;
            events.GameLoop.GameLaunched          += OnGameLaunched;
            events.GameLoop.OneSecondUpdateTicked += OnOneSecondUpdateTicked;
            events.GameLoop.ReturnedToTitle       += OnReturnedToTitle;
            events.GameLoop.SaveLoaded            += OnSaveLoaded;
            events.Display.RenderingHud           += OnRenderingHud;
            events.Display.RenderedHud            += OnRenderedHud;
            events.Input.ButtonPressed            += OnButtonPressed;
            events.Multiplayer.ModMessageReceived += OnModMessageRecieved;
            // events.GameLoop.UpdateTicking += GameLoop_UpdateTicking;

            //console commands
            helper.ConsoleCommands
            .Add("world_tmrwweather", helper.Translation.Get("console-text.desc_tmrweather"), ConsoleCommands.TomorrowWeatherChangeFromConsole)
            .Add("world_setweather", helper.Translation.Get("console-text.desc_setweather"), ConsoleCommands.WeatherChangeFromConsole)
            .Add("debug_clearspecial", "debug command to clear special weathers", ConsoleCommands.ClearSpecial)
            .Add("debug_weatherstatus", "!", ConsoleCommands.OutputWeather)
            .Add("debug_sswa", "Show Special Weather", ConsoleCommands.ShowSpecialWeather)
            .Add("debug_vrainc", "Set Rain Amt.", ConsoleCommands.SetRainAmt)
            .Add("debug_raintotal", "Get Rain Total", ConsoleCommands.DisplayRainTotal)
            .Add("debug_printClimate", "Print Climate Tracker Data", ConsoleCommands.DisplayClimateTrackerData);
        }
Esempio n. 14
0
 public StatsManager(IMultiplayerHelper multiplayer, IDataHelper data)
 {
     this.multiplayer = multiplayer;
     this.data        = data;
     this.stats       = new Dictionary <long, Stats>();
 }
 public static void SendMessageInMultiplayer <TMessage>(this IMultiplayerHelper self, Func <TMessage> message, string[]?modIDs = null, long[]?playerIDs = null)
     where TMessage : notnull
 => self.SendMessageInMultiplayer(message, typeof(TMessage).GetBestName(), modIDs, playerIDs);
Esempio n. 16
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="multiplayer">Provides multiplayer utilities.</param>
 /// <param name="reflection">Simplifies access to private code.</param>
 /// <param name="enableShippingBin">Whether to support access to the shipping bin.</param>
 public ChestFactory(IMultiplayerHelper multiplayer, IReflectionHelper reflection, Func <bool> enableShippingBin)
 {
     this.Multiplayer       = multiplayer;
     this.Reflection        = reflection;
     this.EnableShippingBin = enableShippingBin;
 }
Esempio n. 17
0
 /// <summary>Initialize the helper.</summary>
 /// <param name="helper">Instance to use for sending messages.</param>
 public static void Init(IMultiplayerHelper helper)
 {
     MultiplayerHelper.helper = helper;
     ModId = helper.ModID;
 }
Esempio n. 18
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="modID">The mod's unique ID.</param>
        /// <param name="modDirectory">The full path to the mod's folder.</param>
        /// <param name="jsonHelper">Encapsulate SMAPI's JSON parsing.</param>
        /// <param name="inputState">Manages the game's input state.</param>
        /// <param name="events">Manages access to events raised by SMAPI.</param>
        /// <param name="contentHelper">An API for loading content assets.</param>
        /// <param name="commandHelper">An API for managing console commands.</param>
        /// <param name="dataHelper">An API for reading and writing persistent mod data.</param>
        /// <param name="modRegistry">an API for fetching metadata about loaded mods.</param>
        /// <param name="reflectionHelper">An API for accessing private game code.</param>
        /// <param name="multiplayer">Provides multiplayer utilities.</param>
        /// <param name="translationHelper">An API for reading translations stored in the mod's <c>i18n</c> folder.</param>
        /// <param name="contentPacks">The content packs loaded for this mod.</param>
        /// <param name="createContentPack">Create a transitional content pack.</param>
        /// <param name="deprecationManager">Manages deprecation warnings.</param>
        /// <exception cref="ArgumentNullException">An argument is null or empty.</exception>
        /// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception>
        public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, IEnumerable <IContentPack> contentPacks, Func <string, IManifest, IContentPack> createContentPack, DeprecationManager deprecationManager)
            : base(modID)
        {
            // validate directory
            if (string.IsNullOrWhiteSpace(modDirectory))
            {
                throw new ArgumentNullException(nameof(modDirectory));
            }
            if (!Directory.Exists(modDirectory))
            {
                throw new InvalidOperationException("The specified mod directory does not exist.");
            }

            // initialise
            this.DirectoryPath      = modDirectory;
            this.JsonHelper         = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper));
            this.Content            = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper));
            this.Data               = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper));
            this.Input              = new InputHelper(modID, inputState);
            this.ModRegistry        = modRegistry ?? throw new ArgumentNullException(nameof(modRegistry));
            this.ConsoleCommands    = commandHelper ?? throw new ArgumentNullException(nameof(commandHelper));
            this.Reflection         = reflectionHelper ?? throw new ArgumentNullException(nameof(reflectionHelper));
            this.Multiplayer        = multiplayer ?? throw new ArgumentNullException(nameof(multiplayer));
            this.Translation        = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper));
            this.ContentPacks       = contentPacks.ToArray();
            this.CreateContentPack  = createContentPack;
            this.DeprecationManager = deprecationManager;
            this.Events             = events;
        }
Esempio n. 19
0
 public ChestFactory(IMultiplayerHelper multiplayer, IMonitor monitor)
 {
     this.multiplayer = multiplayer;
     contentDict      = new Dictionary <GameLocation, IDictionary <string, ItemChest> >();
     this.monitor     = monitor;
 }
Esempio n. 20
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="modID">The mod's unique ID.</param>
        /// <param name="modDirectory">The full path to the mod's folder.</param>
        /// <param name="currentInputState">Manages the game's input state for the current player instance. That may not be the main player in split-screen mode.</param>
        /// <param name="events">Manages access to events raised by SMAPI.</param>
        /// <param name="contentHelper">An API for loading content assets.</param>
        /// <param name="gameContentHelper">An API for loading content assets from the game's <c>Content</c> folder or via <see cref="IModEvents.Content"/>.</param>
        /// <param name="modContentHelper">An API for loading content assets from your mod's files.</param>
        /// <param name="contentPackHelper">An API for managing content packs.</param>
        /// <param name="commandHelper">An API for managing console commands.</param>
        /// <param name="dataHelper">An API for reading and writing persistent mod data.</param>
        /// <param name="modRegistry">an API for fetching metadata about loaded mods.</param>
        /// <param name="reflectionHelper">An API for accessing private game code.</param>
        /// <param name="multiplayer">Provides multiplayer utilities.</param>
        /// <param name="translationHelper">An API for reading translations stored in the mod's <c>i18n</c> folder.</param>
        /// <exception cref="ArgumentNullException">An argument is null or empty.</exception>
        /// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception>
        public ModHelper(string modID, string modDirectory, Func <SInputState> currentInputState, IModEvents events, IContentHelper contentHelper, IGameContentHelper gameContentHelper, IModContentHelper modContentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper)
            : base(modID)
        {
            // validate directory
            if (string.IsNullOrWhiteSpace(modDirectory))
            {
                throw new ArgumentNullException(nameof(modDirectory));
            }
            if (!Directory.Exists(modDirectory))
            {
                throw new InvalidOperationException("The specified mod directory does not exist.");
            }

            // initialize
            this.DirectoryPath   = modDirectory;
            this.ContentImpl     = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper));
            this.GameContent     = gameContentHelper ?? throw new ArgumentNullException(nameof(gameContentHelper));
            this.ModContent      = modContentHelper ?? throw new ArgumentNullException(nameof(modContentHelper));
            this.ContentPacks    = contentPackHelper ?? throw new ArgumentNullException(nameof(contentPackHelper));
            this.Data            = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper));
            this.Input           = new InputHelper(modID, currentInputState);
            this.ModRegistry     = modRegistry ?? throw new ArgumentNullException(nameof(modRegistry));
            this.ConsoleCommands = commandHelper ?? throw new ArgumentNullException(nameof(commandHelper));
            this.Reflection      = reflectionHelper ?? throw new ArgumentNullException(nameof(reflectionHelper));
            this.Multiplayer     = multiplayer ?? throw new ArgumentNullException(nameof(multiplayer));
            this.Translation     = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper));
            this.Events          = events;
        }