コード例 #1
0
        /// <summary>Raised after the game is launched, right before the first update tick. This happens once per game session (unrelated to loading saves). All mods are loaded and initialised at this point, so this is a good time to set up mod integrations.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
        {
            //testing for ZA MOON, YOUR HIGHNESS.
            MoonAPI = SDVUtilities.GetModApi <ILunarDisturbancesAPI>(Monitor, Helper, "KoihimeNakamura.LunarDisturbances", "1.0.7", "Lunar Disturbances");

            if (MoonAPI != null)
            {
                LunarDisturbancesLoaded = true;
            }

            ClimatesAPI = SDVUtilities.GetModApi <IClimatesOfFerngillAPI>(Monitor, Helper, "KoihimeNakamura.ClimatesOfFerngill", "1.5.0-beta15", "Climates of Ferngill");

            if (ClimatesAPI != null)
            {
                ClimatesLoaded = true;
            }

            //GMCM interaction
            var GMCMapi = Helper.ModRegistry.GetApi <GenericModConfigMenuAPI>("spacechase0.GenericModConfigMenu");

            if (GMCMapi != null)
            {
                GMCMapi.RegisterModConfig(ModManifest, () => NightConfig = new DynamicNightConfig(), () => Helper.WriteConfig(NightConfig));
                GMCMapi.RegisterClampedOption(ModManifest, "Latitude", "Latitude used to generate the sunrise and sunset times", () => NightConfig.Latitude,
                                              (float val) => NightConfig.Latitude = val, -63.5f, 63.5f);
                GMCMapi.RegisterSimpleOption(ModManifest, "Sunset Times", "This option controls if you subtract a half hour from the generated time", () => NightConfig.SunsetTimesAreMinusThirty, (bool val) => NightConfig.SunsetTimesAreMinusThirty = val);
                GMCMapi.RegisterSimpleOption(ModManifest, "More Orange Sunrise", "This option controls if you want a more orange sunrise", () => NightConfig.MoreOrangeSunrise, (bool val) => NightConfig.MoreOrangeSunrise = val);
                GMCMapi.RegisterClampedOption(ModManifest, "Night Darkness Level", "Controls the options for how dark it is at night. Higher is darker.", () => NightConfig.NightDarknessLevel,
                                              (int val) => NightConfig.NightDarknessLevel = val, 1, 4);
            }
        }
コード例 #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;
            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 = 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, null, new HarmonyMethod(postfix));

            //patch getTrulyDarkTime
            MethodInfo setTrulyDarkTime = 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, null, new HarmonyMethod(postfixDark));

            //patch isDarkOut
            MethodInfo isDarkOut        = 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, null, new HarmonyMethod(postfixIsDarkOut));

            //patch UpdateGameClock
            MethodInfo UpdateGameClock = helper.Reflection.GetMethod(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));

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

            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);
        }
コード例 #3
0
        public override void Entry(IModHelper helper)
        {
            NightConfig = Helper.ReadConfig <DynamicNightConfig>();

            //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 = typeof(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");

            harmony.Patch(setStartingToGetDarkTime, null, new HarmonyMethod(postfix));

            //patch getTrulyDarkTime
            MethodInfo setTrulyDarkTime = typeof(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");

            harmony.Patch(setTrulyDarkTime, null, new HarmonyMethod(postfixDark));

            //patch isDarkOutPatch
            MethodInfo isDarkOut        = typeof(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");

            harmony.Patch(isDarkOut, null, new HarmonyMethod(postfixIsDarkOut));

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

            harmony.Patch(UpdateGameClock, null, new HarmonyMethod(postfixClock));

            //and now events!
            TimeEvents.TimeOfDayChanged += TimeEvents_TimeOfDayChanged;
        }
コード例 #4
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);
        }