Ejemplo n.º 1
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)
        {
            isNightOut        = false;
            daybreakTickCount = 11;
            firstDaybreakTick = false;
            Logger            = Monitor;
            NightConfig       = Helper.ReadConfig <DynamicNightConfig>();
            resetOnWakeup     = false;

            //sanity check lat
            if (NightConfig.Latitude > 64)
            {
                NightConfig.Latitude = 64;
            }
            if (NightConfig.Latitude < -64)
            {
                NightConfig.Latitude = -64;
            }

            var harmony = new Harmony(this.ModManifest.UniqueID);

            harmony.PatchAll(Assembly.GetExecutingAssembly());

            //patch getStartingToGetDarkTime
            MethodInfo setStartingToGetDarkTime = SDVUtilities.GetSDVType("Game1").GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "getStartingToGetDarkTime");
            MethodInfo postfix = typeof(Patches.GettingDarkPatch).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "Postfix");

            Monitor.Log($"Postfixing Game1.getStartingToGetDarkTime with {postfix}", LogLevel.Trace);
            harmony.Patch(setStartingToGetDarkTime, postfix: new HarmonyMethod(postfix));

            //patch getTrulyDarkTime
            MethodInfo setTrulyDarkTime = SDVUtilities.GetSDVType("Game1").GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "getTrulyDarkTime");
            MethodInfo postfixDark      = typeof(Patches.GetFullyDarkPatch).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "Postfix");

            Monitor.Log($"Postfixing Game1.getTrulyDarkTime with {postfixDark}", LogLevel.Trace);
            harmony.Patch(setTrulyDarkTime, postfix: new HarmonyMethod(postfixDark));

            //patch isDarkOut
            MethodInfo isDarkOut        = SDVUtilities.GetSDVType("Game1").GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "isDarkOut");
            MethodInfo postfixIsDarkOut = typeof(Patches.IsDarkOutPatch).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "Postfix");

            Monitor.Log($"Postfixing Gam1.isDarkOut with {postfixIsDarkOut}", LogLevel.Trace);
            harmony.Patch(isDarkOut, postfix: new HarmonyMethod(postfixIsDarkOut));

            //patch UpdateGameClock
            MethodInfo UpdateGameClock = helper.Reflection.GetMethod(SDVUtilities.GetSDVType("Game1"), "UpdateGameClock").MethodInfo;
            MethodInfo postfixClock    = helper.Reflection.GetMethod(typeof(Patches.GameClockPatch), "Postfix").MethodInfo;

            Monitor.Log($"Postfixing Game1.UpdateGameClock with {postfixClock}", LogLevel.Trace);
            harmony.Patch(UpdateGameClock, postfix: new HarmonyMethod(postfixClock));

            harmony.Patch(
                original: AccessTools.Method(AccessTools.TypeByName("StardewValley.Locations.IslandLocation"), "DrawParallaxHorizon"),
                transpiler: new HarmonyMethod(AccessTools.Method(typeof(Patches.IslandLocationPatches), "DrawParallaxHorizonTranspiler")));
            Monitor.Log("Patching IslandLocation::DrawParallaxHorizon with a transpiler.", LogLevel.Trace);

            helper.Events.GameLoop.GameLaunched    += OnGameLaunched;
            helper.Events.GameLoop.DayStarted      += OnDayStarted;
            helper.Events.GameLoop.ReturnedToTitle += OnReturnedToTitle;
            helper.Events.GameLoop.TimeChanged     += OnTimeChanged;
            helper.Events.GameLoop.UpdateTicking   += OnUpdateTicking;

            Helper.ConsoleCommands.Add("debug_cycleinfo", "Outputs the cycle information", OutputInformation);
            Helper.ConsoleCommands.Add("debug_outdoorlight", "Outputs the outdoor light information", OutputLight);
            Helper.ConsoleCommands.Add("debug_setlatitude", "Sets Latitude", SetLatitude);
            Helper.ConsoleCommands.Add("debug_setnightlevel", "Set Night Level", SetNightLevel);
            Helper.ConsoleCommands.Add("debug_printplayingsong", "Print Playing Song", PrintPlayingSong);
            Helper.ConsoleCommands.Add("debug_printparallaxcalc", "Show Parallax Ratio", ShowParallaxRatio);
        }
Ejemplo 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)
        {
            isNightOut        = false;
            daybreakTickCount = 11;
            firstDaybreakTick = false;
            Logger            = Monitor;
            NightConfig       = Helper.ReadConfig <DynamicNightConfig>();
            resetOnWakeup     = false;

            //sanity check lat
            if (NightConfig.Latitude > 64)
            {
                NightConfig.Latitude = 64;
            }
            if (NightConfig.Latitude < -64)
            {
                NightConfig.Latitude = -64;
            }

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

            harmony.PatchAll(Assembly.GetExecutingAssembly());

            //patch getStartingToGetDarkTime
            MethodInfo setStartingToGetDarkTime = SDVUtilities.GetSDVType("Game1").GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "getStartingToGetDarkTime");
            MethodInfo postfix = typeof(Patches.GettingDarkPatch).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "Postfix");

            Monitor.Log($"Postfixing {setStartingToGetDarkTime} with {postfix}", LogLevel.Trace);
            harmony.Patch(setStartingToGetDarkTime, postfix: new HarmonyMethod(postfix));

            //patch getTrulyDarkTime
            MethodInfo setTrulyDarkTime = SDVUtilities.GetSDVType("Game1").GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "getTrulyDarkTime");
            MethodInfo postfixDark      = typeof(Patches.GetFullyDarkPatch).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "Postfix");

            Monitor.Log($"Postfixing {setTrulyDarkTime} with {postfixDark}", LogLevel.Trace);
            harmony.Patch(setTrulyDarkTime, postfix: new HarmonyMethod(postfixDark));

            //patch isDarkOut
            MethodInfo isDarkOut        = SDVUtilities.GetSDVType("Game1").GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "isDarkOut");
            MethodInfo postfixIsDarkOut = typeof(Patches.IsDarkOutPatch).GetMethods(BindingFlags.Static | BindingFlags.Public).ToList().Find(m => m.Name == "Postfix");

            Monitor.Log($"Postfixing {isDarkOut} with {postfixIsDarkOut}", LogLevel.Trace);
            harmony.Patch(isDarkOut, postfix: new HarmonyMethod(postfixIsDarkOut));

            //patch UpdateGameClock
            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, postfix: new HarmonyMethod(postfixClock));

            helper.Events.GameLoop.GameLaunched    += OnGameLaunched;
            helper.Events.GameLoop.DayStarted      += OnDayStarted;
            helper.Events.GameLoop.ReturnedToTitle += OnReturnedToTitle;
            helper.Events.GameLoop.TimeChanged     += OnTimeChanged;
            helper.Events.GameLoop.UpdateTicking   += OnUpdateTicking;

            Helper.ConsoleCommands.Add("debug_cycleinfo", "Outputs the cycle information", OutputInformation);
            Helper.ConsoleCommands.Add("debug_outdoorlight", "Outputs the outdoor light information", OutputLight);
            Helper.ConsoleCommands.Add("debug_setlatitude", "Sets Latitude", SetLatitude);
            Helper.ConsoleCommands.Add("debug_setnightlevel", "Set Night Level", SetNightLevel);
            Helper.ConsoleCommands.Add("debug_printplayingsong", "Print Playing Song", PrintPlayingSong);
        }
Ejemplo n.º 3
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)
        {
            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);
        }