Exemplo 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)
        {
            instance    = this;
            Log.Monitor = Monitor;
            Config      = helper.ReadConfig <Configuration>();

            helper.Events.GameLoop.UpdateTicked += onUpdate;
            helper.Events.GameLoop.SaveLoaded   += onSaveLoaded;
            helper.Events.GameLoop.Saving       += onSaving;
            helper.Events.GameLoop.Saved        += onSaved;

            Commands.register();
            Skills.init(helper.Events);
            TileSheetExtensions.init();

            harmony = HarmonyInstance.Create("spacechase0.SpaceCore");

            MethodInfo showNightEndMethod = null;

            try
            {
                Type game1CompilerType = null;
                foreach (var t in typeof(Game1).Assembly.GetTypes())
                {
                    if (t.FullName == "StardewValley.Game1+<>c")
                    {
                        game1CompilerType = t;
                    }
                }
                foreach (var m in game1CompilerType.GetRuntimeMethods())
                {
                    if (m.FullDescription().Contains("showEndOfNightStuff"))
                    {
                        showNightEndMethod = m;
                    }
                }
            }
            catch (Exception e1)
            {
                Log.trace("Failed to find Windows showEndOfNightStuff lambda: " + e1);
                try
                {
                    Type game1CompilerType = typeof(Game1);
                    foreach (var m in game1CompilerType.GetRuntimeMethods())
                    {
                        if (m.FullDescription().Contains("<showEndOfNightStuff>m__"))
                        {
                            showNightEndMethod = m;
                        }
                    }
                }
                catch (Exception e2)
                {
                    Log.error("Failed to find Mac/Linux showEndOfNightStuff lambda: " + e2);
                }
            }
            Log.trace("showEndOfNightStuff: " + showNightEndMethod);

            doPrefix(typeof(HoeDirt), nameof(HoeDirt.dayUpdate), typeof(HoeDirtWinterFix));
            doPostfix(typeof(Utility), nameof(Utility.pickFarmEvent), typeof(NightlyFarmEventHook));
            doTranspiler(showNightEndMethod, typeof(ShowEndOfNightStuffHook).GetMethod(nameof(ShowEndOfNightStuffHook.Transpiler)));
            doPostfix(typeof(Farmer), nameof(Farmer.doneEating), typeof(DoneEatingHook));
            doPrefix(typeof(MeleeWeapon).GetMethod(nameof(MeleeWeapon.drawDuringUse), new[] { typeof(int), typeof(int), typeof(SpriteBatch), typeof(Vector2), typeof(Farmer), typeof(Rectangle), typeof(int), typeof(bool) }), typeof(CustomWeaponDrawPatch).GetMethod(nameof(CustomWeaponDrawPatch.Prefix)));
            doPrefix(typeof(Multiplayer), nameof(Multiplayer.processIncomingMessage), typeof(MultiplayerPackets));
            doPrefix(typeof(GameLocation), nameof(GameLocation.performAction), typeof(ActionHook));
            doPrefix(typeof(GameLocation), nameof(GameLocation.performTouchAction), typeof(TouchActionHook));
            doPostfix(typeof(GameLocation), nameof(GameLocation.explode), typeof(ExplodeHook));
            doPostfix(typeof(GameServer), nameof(GameServer.sendServerIntroduction), typeof(ServerGotClickHook));
            doPostfix(typeof(NPC), nameof(NPC.receiveGift), typeof(AfterGiftGivenHook));
            doPostfix(typeof(Game1), nameof(Game1.loadForNewGame), typeof(BlankSaveHook));
            if (Constants.TargetPlatform != GamePlatform.Android)
            {
                doPrefix(typeof(Game1).GetMethod(nameof(Game1.warpFarmer), new[] { typeof(LocationRequest), typeof(int), typeof(int), typeof(int) }), typeof(WarpFarmerHook).GetMethod(nameof(WarpFarmerHook.Prefix)));
            }
            else
            {
                doPrefix(typeof(Game1).GetMethod(nameof(Game1.warpFarmer), new[] { typeof(LocationRequest), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(bool) }), typeof(WarpFarmerHook).GetMethod(nameof(WarpFarmerHook.Prefix)));
            }
            doPostfix(typeof(GameMenu), nameof(GameMenu.getTabNumberFromName), typeof(GameMenuTabNameHook));
            doPrefix(typeof(SpriteBatch).GetMethod("Draw", new[] { typeof(Texture2D), typeof(Rectangle), typeof(Rectangle? ), typeof(Color), typeof(float), typeof(Vector2), typeof(SpriteEffects), typeof(float) }), typeof(SpriteBatchTileSheetAdjustments).GetMethod(nameof(SpriteBatchTileSheetAdjustments.Prefix1)));
            doPrefix(typeof(SpriteBatch).GetMethod("Draw", new[] { typeof(Texture2D), typeof(Rectangle), typeof(Rectangle? ), typeof(Color), }), typeof(SpriteBatchTileSheetAdjustments).GetMethod(nameof(SpriteBatchTileSheetAdjustments.Prefix2)));
            doPrefix(typeof(SpriteBatch).GetMethod("Draw", new[] { typeof(Texture2D), typeof(Vector2), typeof(Rectangle? ), typeof(Color), typeof(float), typeof(Vector2), typeof(Vector2), typeof(SpriteEffects), typeof(float) }), typeof(SpriteBatchTileSheetAdjustments).GetMethod(nameof(SpriteBatchTileSheetAdjustments.Prefix3)));
            doPrefix(typeof(SpriteBatch).GetMethod("Draw", new[] { typeof(Texture2D), typeof(Vector2), typeof(Rectangle? ), typeof(Color), typeof(float), typeof(Vector2), typeof(float), typeof(SpriteEffects), typeof(float) }), typeof(SpriteBatchTileSheetAdjustments).GetMethod(nameof(SpriteBatchTileSheetAdjustments.Prefix4)));
            doPrefix(typeof(SpriteBatch).GetMethod("Draw", new[] { typeof(Texture2D), typeof(Vector2), typeof(Rectangle? ), typeof(Color) }), typeof(SpriteBatchTileSheetAdjustments).GetMethod(nameof(SpriteBatchTileSheetAdjustments.Prefix5)));
        }
Exemplo n.º 2
0
 private void onUpdate(object sender, UpdateTickedEventArgs e)
 {
     TileSheetExtensions.UpdateReferences();
 }