From 0a17a0e6fd8d2b29881063a2b6cf45dc256d14f8 Mon Sep 17 00:00:00 2001 From: yangzhi <@4F!xZpJwly&KbWq> Date: Sat, 27 Apr 2019 01:25:41 +0800 Subject: [PATCH] 1.3.12, Hooks for Mods --- .gitignore | 6 + DllRewrite/DllRewrite/MethodPatcher.cs | 400 ++++++++++-------- src/Mod.csproj | 302 +++++++------ src/ModEntry.cs | 34 ++ src/SMAPI/Framework/ModHelpers/DataHelper.cs | 2 +- .../ModLoading/RewriteIgnoreConfig.cs | 13 + src/SMAPI/Framework/SCore.cs | 10 +- src/SMAPI/Framework/SGame.cs | 47 +- src/SMAPI/IMod.cs | 4 + src/SMAPI/Mod.cs | 4 + src/SMAPI/Patches/DialogueErrorPatch.cs | 8 +- src/SMAPI/Patches/LoadForNewGamePatch.cs | 8 +- src/SMAPI/Patches/ObjectErrorPatch.cs | 22 +- 13 files changed, 511 insertions(+), 349 deletions(-) create mode 100644 src/SMAPI/Framework/ModLoading/RewriteIgnoreConfig.cs diff --git a/.gitignore b/.gitignore index 7e0c1e9d..527b6a19 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,9 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user +# LocalHistory +.localhistory/ + # NuGet packages *.nupkg **/packages/* @@ -26,3 +29,6 @@ _ReSharper*/ # sensitive files appsettings.Development.json + +# assemblies +assemblies/ diff --git a/DllRewrite/DllRewrite/MethodPatcher.cs b/DllRewrite/DllRewrite/MethodPatcher.cs index 30645360..9060739f 100644 --- a/DllRewrite/DllRewrite/MethodPatcher.cs +++ b/DllRewrite/DllRewrite/MethodPatcher.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using Mono.Cecil; using Mono.Cecil.Cil; @@ -171,18 +169,124 @@ namespace DllRewrite var GetGamePadState = typeInputState.Methods.FirstOrDefault(m => m.Name == "GetGamePadState"); processor.Replace(method.Body.Instructions[1], processor.Create(OpCodes.Callvirt, GetGamePadState)); } - public void ApplyCommonHookEntry(TypeDefinition targetType, string methodname, string hookname, bool patchPrefix = true, bool patchPostfix = true, Func methodFilter = null) + public void ApplyCommonMidHookEntry(TypeDefinition targetType, Func methodChecker, Func jointPointChecker, int jointPointOffset, string hookname) { - string qualifyName = $"{targetType.FullName}.{methodname}"; + byte i, j; + MethodDefinition targetMethod = targetType.Methods.FirstOrDefault(method => methodChecker(method)); + string qualifyName = targetType.FullName + "." + targetMethod.Name + "_mid"; + MethodDefinition prefixHook = this.StardewValley.MainModule.GetType("StardewValley.ModHooks").Methods.FirstOrDefault(m => m.Name == (hookname + "_Prefix")); + ILProcessor iLProcessor = targetMethod.Body.GetILProcessor(); + FieldReference field = this.GetFieldReference("hooks", "StardewValley.Game1", this.StardewValley); + List instructions = new List(); + byte returnIndex = 0; + byte parameterIndexBegin = 0; + byte parameterIndexEnd = 0; + byte parameterOffset = targetMethod.IsStatic ? ((byte)0) : ((byte)1); + byte stateIndex = (byte)targetMethod.Body.Variables.Count; + targetMethod.Body.Variables.Add(new VariableDefinition(this.GetTypeReference("System.Boolean"))); + if (targetMethod.ReturnType.FullName != "System.Void") + { + returnIndex = (byte)targetMethod.Body.Variables.Count; + targetMethod.Body.Variables.Add(new VariableDefinition(this.GetTypeReference("System.Object"))); + } + parameterIndexBegin = (byte)targetMethod.Body.Variables.Count; + for (i = 0; i < targetMethod.Parameters.Count; i = (byte)(i + 1)) + { + targetMethod.Body.Variables.Add(new VariableDefinition(this.GetTypeReference("System.Object"))); + parameterIndexEnd = (byte)targetMethod.Body.Variables.Count; + } + if (prefixHook != null) + { + Instruction jointPoint = targetMethod.Body.Instructions.FirstOrDefault(ins => jointPointChecker(ins)); + for (int x = jointPointOffset; x < 0; x++) + { + jointPoint = jointPoint.Previous; + } + for (int x = 0; x < jointPointOffset; x++) + { + jointPoint = jointPoint.Next; + } + i = parameterOffset; + for (j = parameterIndexBegin; i < (targetMethod.Parameters.Count + parameterOffset); j = (byte)(j + 1)) + { + instructions.Add(this._createLdargsInstruction(iLProcessor, i)); + if (targetMethod.Parameters[i - parameterOffset].ParameterType.IsValueType) + { + instructions.Add(iLProcessor.Create(OpCodes.Box, targetMethod.Parameters[i - parameterOffset].ParameterType)); + } + instructions.Add(this._createStlocInstruction(iLProcessor, j)); + i = (byte)(i + 1); + } + instructions.Add(iLProcessor.Create(OpCodes.Ldsfld, field)); + instructions.Add(iLProcessor.Create(OpCodes.Ldstr, qualifyName)); + if (!targetMethod.IsStatic) + { + instructions.Add(iLProcessor.Create(OpCodes.Ldarg_0)); + if (targetType.IsValueType) + { + instructions.Add(iLProcessor.Create(OpCodes.Box, targetType)); + } + } + i = parameterOffset; + for (j = parameterIndexBegin; i < (targetMethod.Parameters.Count + parameterOffset); j = (byte)(j + 1)) + { + instructions.Add(iLProcessor.Create(OpCodes.Ldloca_S, j)); + i = (byte)(i + 1); + } + while (i < (prefixHook.Parameters.Count - 2)) + { + instructions.Add(iLProcessor.Create(OpCodes.Ldloca_S, (byte)0)); + i = (byte)(i + 1); + } + instructions.Add(iLProcessor.Create(OpCodes.Ldloca_S, returnIndex)); + instructions.Add(iLProcessor.Create(OpCodes.Callvirt, prefixHook)); + instructions.Add(this._createStlocInstruction(iLProcessor, stateIndex)); + i = parameterOffset; + for (j = parameterIndexBegin; i < (targetMethod.Parameters.Count + parameterOffset); j = (byte)(j + 1)) + { + instructions.Add(this._createLdlocInstruction(iLProcessor, j)); + if (targetMethod.Parameters[i - parameterOffset].ParameterType.IsValueType) + { + instructions.Add(iLProcessor.Create(OpCodes.Unbox_Any, targetMethod.Parameters[i - parameterOffset].ParameterType)); + } + else + { + instructions.Add(iLProcessor.Create(OpCodes.Castclass, targetMethod.Parameters[i - parameterOffset].ParameterType)); + } + instructions.Add(iLProcessor.Create(OpCodes.Starg_S, i)); + i = (byte)(i + 1); + } + instructions.Add(this._createLdlocInstruction(iLProcessor, stateIndex)); + instructions.Add(iLProcessor.Create(OpCodes.Brtrue, jointPoint)); + if (targetMethod.ReturnType.FullName != "System.Void") + { + instructions.Add(this._createLdlocInstruction(iLProcessor, returnIndex)); + if (targetMethod.ReturnType.IsValueType) + { + instructions.Add(iLProcessor.Create(OpCodes.Unbox_Any, targetMethod.ReturnType)); + } + else + { + instructions.Add(iLProcessor.Create(OpCodes.Castclass, targetMethod.ReturnType)); + } + } + instructions.Add(iLProcessor.Create(OpCodes.Ret)); + this.InsertInstructions(iLProcessor, jointPoint, instructions); + } + } + + public void ApplyCommonHookEntry(TypeDefinition targetType, string methodname, string hookname, bool patchPrefix = true, bool patchPostfix = true, Func methodFilter = null, string qualifyNameSuffix = "") + { + string qualifyName = $"{targetType.FullName}.{methodname}{qualifyNameSuffix}"; TypeDefinition typeModHooksObject = this.StardewValley.MainModule.GetType("StardewValley.ModHooks"); - var targetMethod = targetType.Methods.FirstOrDefault(method => (!method.IsConstructor && method.HasBody && method.Name == methodname && (methodFilter == null || methodFilter(method)))); + var targetMethod = targetType.Methods.FirstOrDefault(method => (method.HasBody && method.Name == methodname && (methodFilter == null || methodFilter(method)))); var prefixHook = typeModHooksObject.Methods.FirstOrDefault(m => m.Name == hookname + "_Prefix"); var postfixHook = typeModHooksObject.Methods.FirstOrDefault(m => m.Name == hookname + "_Postfix"); var processor = targetMethod.Body.GetILProcessor(); FieldReference hooksField = this.GetFieldReference("hooks", "StardewValley.Game1", this.StardewValley); Instruction jointPoint; List instructions; - byte i, j; + byte i, j, k; // state byte returnIndex = 0; byte parameterIndexBegin = 0, parameterIndexEnd = 0; @@ -205,7 +309,8 @@ namespace DllRewrite { instructions = new List(); jointPoint = targetMethod.Body.Instructions[0]; - for (i = parameterOffset, j = parameterIndexBegin; i < targetMethod.Parameters.Count + parameterOffset; i++, j++) + k = (byte)(targetMethod.Parameters.Count + parameterOffset > prefixHook.Parameters.Count - 2 ? prefixHook.Parameters.Count - 2 - parameterOffset : targetMethod.Parameters.Count + parameterOffset); + for (i = parameterOffset, j = parameterIndexBegin; i < k; i++, j++) { instructions.Add(this._createLdargsInstruction(processor, i)); if(targetMethod.Parameters[i - parameterOffset].ParameterType.IsValueType) @@ -222,7 +327,9 @@ namespace DllRewrite if (targetType.IsValueType) instructions.Add(processor.Create(OpCodes.Box, targetType)); } - for (i = parameterOffset, j = parameterIndexBegin; i < targetMethod.Parameters.Count + parameterOffset; i++, j++) + + k = (byte)(targetMethod.Parameters.Count + parameterOffset > prefixHook.Parameters.Count - 2 ? prefixHook.Parameters.Count - 2 - parameterOffset : targetMethod.Parameters.Count + parameterOffset); + for (i = parameterOffset, j = parameterIndexBegin; i < k; i++, j++) { instructions.Add(processor.Create(OpCodes.Ldloca_S, j)); } @@ -267,7 +374,8 @@ namespace DllRewrite instructions.Add(processor.Create(OpCodes.Box, targetMethod.ReturnType)); instructions.Add(this._createStlocInstruction(processor, returnIndex)); } - for (i = parameterOffset, j = parameterIndexBegin; i < targetMethod.Parameters.Count + parameterOffset; i++, j++) + k = (byte)(targetMethod.Parameters.Count + parameterOffset > postfixHook.Parameters.Count - 3 ? prefixHook.Parameters.Count - 3 - parameterOffset : targetMethod.Parameters.Count + parameterOffset); + for (i = parameterOffset, j = parameterIndexBegin; i < k; i++, j++) { instructions.Add(this._createLdargsInstruction(processor, i)); if (targetMethod.Parameters[i - parameterOffset].ParameterType.IsValueType) @@ -284,7 +392,8 @@ namespace DllRewrite if (targetType.IsValueType) instructions.Add(processor.Create(OpCodes.Box, targetType)); } - for (i = parameterOffset, j = parameterIndexBegin; i < targetMethod.Parameters.Count + parameterOffset; i++, j++) + k = (byte)(targetMethod.Parameters.Count + parameterOffset > postfixHook.Parameters.Count - 3 ? prefixHook.Parameters.Count - 3 - parameterOffset : targetMethod.Parameters.Count + parameterOffset); + for (i = parameterOffset, j = parameterIndexBegin; i < k; i++, j++) { instructions.Add(processor.Create(OpCodes.Ldloca_S, j)); } @@ -554,7 +663,7 @@ namespace DllRewrite { this.ApplyGamePatch(); - this.InsertModHook("OnCommonHook_Prefix", new TypeReference[] { + this.InsertModHook("OnCommonHook_Prefix", new[] { this.GetTypeReference("System.String"), this.GetTypeReference("System.Object"), new ByReferenceType(this.GetTypeReference("System.Object")), @@ -562,12 +671,12 @@ namespace DllRewrite new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object"))}, - new string[] { + new[] { "hookName", "__instance", "param1", "param2", "param3", "param4", "__result"}, this.GetTypeReference("System.Boolean")); - this.InsertModHook("OnCommonStaticHook_Prefix", new TypeReference[] { + this.InsertModHook("OnCommonStaticHook_Prefix", new[] { this.GetTypeReference("System.String"), new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object")), @@ -575,12 +684,12 @@ namespace DllRewrite new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object"))}, - new string[] { + new[] { "hookName", "param1", "param2", "param3", "param4", "param5", "__result"}, this.GetTypeReference("System.Boolean")); - this.InsertModHook("OnCommonHook_Postfix", new TypeReference[] { + this.InsertModHook("OnCommonHook_Postfix", new[] { this.GetTypeReference("System.String"), this.GetTypeReference("System.Object"), new ByReferenceType(this.GetTypeReference("System.Object")), @@ -589,12 +698,12 @@ namespace DllRewrite new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Boolean")), new ByReferenceType(this.GetTypeReference("System.Object"))}, - new string[] { + new[] { "hookName", "__instance", "param1", "param2", "param3", "param4", "__state", "__result"}, this.GetTypeReference("System.Void")); - this.InsertModHook("OnCommonStaticHook_Postfix", new TypeReference[] { + this.InsertModHook("OnCommonStaticHook_Postfix", new[] { this.GetTypeReference("System.String"), new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object")), @@ -603,13 +712,13 @@ namespace DllRewrite new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Boolean")), new ByReferenceType(this.GetTypeReference("System.Object"))}, - new string[] { + new[] { "hookName", "param1", "param2", "param3", "param4", "param5", "__state", "__result"}, this.GetTypeReference("System.Void")); - this.InsertModHook("OnCommonHook10_Prefix", new TypeReference[] { + this.InsertModHook("OnCommonHook10_Prefix", new[] { this.GetTypeReference("System.String"), this.GetTypeReference("System.Object"), new ByReferenceType(this.GetTypeReference("System.Object")), @@ -622,14 +731,14 @@ namespace DllRewrite new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object"))}, - new string[] { + new[] { "hookName", "__instance", "param1", "param2", "param3", "param4", "param5", "param6", "param7", "param8", "param9", "__result"}, this.GetTypeReference("System.Boolean")); - this.InsertModHook("OnCommonStaticHook10_Prefix", new TypeReference[] { + this.InsertModHook("OnCommonStaticHook10_Prefix", new[] { this.GetTypeReference("System.String"), new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object")), @@ -642,14 +751,14 @@ namespace DllRewrite new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object"))}, - new string[] { + new[] { "hookName", "param1", "param2", "param3", "param4", "param5", "param6", "param7", "param8", "param9", "param10", "__result"}, this.GetTypeReference("System.Boolean")); - this.InsertModHook("OnCommonHook10_Postfix", new TypeReference[] { + this.InsertModHook("OnCommonHook10_Postfix", new[] { this.GetTypeReference("System.String"), this.GetTypeReference("System.Object"), new ByReferenceType(this.GetTypeReference("System.Object")), @@ -663,14 +772,14 @@ namespace DllRewrite new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Boolean")), new ByReferenceType(this.GetTypeReference("System.Object"))}, - new string[] { + new[] { "hookName", "__instance", "param1", "param2", "param3", "param4", "param5", "param6", "param7", "param8", "param9", "__state", "__result"}, this.GetTypeReference("System.Void")); - this.InsertModHook("OnCommonStaticHook10_Postfix", new TypeReference[] { + this.InsertModHook("OnCommonStaticHook10_Postfix", new[] { this.GetTypeReference("System.String"), new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Object")), @@ -684,7 +793,7 @@ namespace DllRewrite new ByReferenceType(this.GetTypeReference("System.Object")), new ByReferenceType(this.GetTypeReference("System.Boolean")), new ByReferenceType(this.GetTypeReference("System.Object"))}, - new string[] { + new[] { "hookName", "param1", "param2", "param3", "param4", "param5", "param6", "param7", @@ -696,198 +805,117 @@ namespace DllRewrite this.ApplyCommonHookEntry(typeGame1, "Update", "OnCommonHook"); this.ApplyCommonHookEntry(typeGame1, "_draw", "OnCommonHook"); this.ApplyCommonHookEntry(typeGame1, "getSourceRectForStandardTileSheet", "OnCommonStaticHook"); - this.ApplyCommonHookEntry(typeGame1, "tryToCheckAt", "OnCommonStaticHook"); - this.ApplyCommonHookEntry(typeGame1, "getLocationRequest", "OnCommonStaticHook"); + this.ApplyCommonHookEntry(typeGame1, "tryToCheckAt", "OnCommonStaticHook", false); + this.ApplyCommonHookEntry(typeGame1, "getLocationRequest", "OnCommonStaticHook", true, false); + this.ApplyCommonHookEntry(typeGame1, "getLocationRequest", "OnCommonStaticHook", true, false); + this.ApplyCommonHookEntry(typeGame1, "loadForNewGame", "OnCommonStaticHook"); + this.ApplyCommonHookEntry(typeGame1, "warpFarmer", "OnCommonStaticHook10", true, false, method => method.Parameters.Count == 6); + this.ApplyCommonHookEntry(typeGame1, ".ctor", "OnCommonHook", false); + this.ApplyCommonHookEntry(typeGame1, "LoadContent", "OnCommonHook", false); + TypeDefinition targetType = null; + foreach (TypeDefinition definition21 in this.StardewValley.MainModule.GetTypes()) + { + if (definition21.FullName == "StardewValley.Game1/<>c") + { + targetType = definition21; + } + } + this.ApplyCommonMidHookEntry(targetType, method => method.FullName.Contains("showEndOfNightStuff"), ins => (ins.OpCode == OpCodes.Ldstr) && (((string)ins.Operand) == "newRecord"), -2, "OnCommonHook"); // On Object hooks TypeDefinition typeObject = this.StardewValley.MainModule.GetType("StardewValley.Object"); this.ApplyCommonHookEntry(typeObject, "canBePlacedHere", "OnCommonHook", true, false); this.ApplyCommonHookEntry(typeObject, "checkForAction", "OnCommonHook", true, false); this.ApplyCommonHookEntry(typeObject, "isIndexOkForBasicShippedCategory", "OnCommonStaticHook"); + this.ApplyCommonHookEntry(typeObject, "drawWhenHeld", "OnCommonHook", true, false); + this.ApplyCommonHookEntry(typeObject, "drawInMenuWithColour", "OnCommonHook10"); + this.ApplyCommonHookEntry(typeObject, "draw", "OnCommonHook", true, false, method => method.Parameters.Count == 4); + this.ApplyCommonHookEntry(typeObject, "draw", "OnCommonHook10", true, false, method => method.Parameters.Count == 5); + this.ApplyCommonHookEntry(typeObject, "getDescription", "OnCommonHook", true, false); // On ReadyCheckDialog hooks TypeDefinition typeReadyCheckDialog = this.StardewValley.MainModule.GetType("StardewValley.Menus.ReadyCheckDialog"); this.ApplyCommonHookEntry(typeReadyCheckDialog, "update", "OnCommonHook"); + // On IClickableMenu hooks + TypeDefinition typeIClickableMenu = this.StardewValley.MainModule.GetType("StardewValley.Menus.IClickableMenu"); + this.ApplyCommonHookEntry(typeIClickableMenu, "drawToolTip", "OnCommonStaticHook10", false); + + // On Dialogue hooks + TypeDefinition typeDialogue = this.StardewValley.MainModule.GetType("StardewValley.Dialogue"); + this.ApplyCommonHookEntry(typeDialogue, ".ctor", "OnCommonHook", true, false, method => method.Parameters.Count == 2); + // On Building hooks TypeDefinition typeBuilding = this.StardewValley.MainModule.GetType("StardewValley.Buildings.Building"); this.ApplyCommonHookEntry(typeBuilding, "load", "OnCommonHook"); // On GameLocation hooks TypeDefinition typeGameLocation = this.StardewValley.MainModule.GetType("StardewValley.GameLocation"); - this.ApplyCommonHookEntry(typeGameLocation, "performTouchAction", "OnCommonHook"); - this.ApplyCommonHookEntry(typeGameLocation, "isActionableTile", "OnCommonHook"); - this.ApplyCommonHookEntry(typeGameLocation, "tryToAddCritters", "OnCommonHook"); + this.ApplyCommonHookEntry(typeGameLocation, "performTouchAction", "OnCommonHook", true, false); + this.ApplyCommonHookEntry(typeGameLocation, "isActionableTile", "OnCommonHook", false); + this.ApplyCommonHookEntry(typeGameLocation, "tryToAddCritters", "OnCommonHook", true, false); this.ApplyCommonHookEntry(typeGameLocation, "getSourceRectForObject", "OnCommonStaticHook"); - this.ApplyCommonHookEntry(typeGameLocation, "answerDialogue", "OnCommonHook"); - this.ApplyCommonHookEntry(typeGameLocation, "Equals", "OnCommonHook", true, false, (method)=> method.Parameters[0].ParameterType == this.GetTypeReference("StardewValley.GameLocation", this.StardewValley)); - + this.ApplyCommonHookEntry(typeGameLocation, "answerDialogue", "OnCommonHook", true, false); + this.ApplyCommonHookEntry(typeGameLocation, "Equals", "OnCommonHook", true, false, method => method.Parameters[0].ParameterType == this.GetTypeReference("StardewValley.GameLocation", this.StardewValley)); + this.ApplyCommonHookEntry(typeGameLocation, "performAction", "OnCommonHook", true, false); // On Objects.TV hooks TypeDefinition typeObjectsTV = this.StardewValley.MainModule.GetType("StardewValley.Objects.TV"); this.ApplyCommonHookEntry(typeObjectsTV, "checkForAction", "OnCommonHook"); + // On Furniture hooks + TypeDefinition typeFurniture = this.StardewValley.MainModule.GetType("StardewValley.Objects.Furniture"); + this.ApplyCommonHookEntry(typeFurniture, "draw", "OnCommonHook", true, false); - //this.InsertModHook("OnGame1_Update_Prefix", new TypeReference[] { - // this.GetTypeReference("StardewValley.Game1", this.StardewValley), - // this.GetTypeReference("Microsoft.Xna.Framework.GameTime", this.MonoGame_Framework)}, - // this.GetTypeReference("System.Boolean")); - //this.ApplyHookEntry(typeGame1, "Update", "OnGame1_Update_Prefix", true); - //this.InsertModHook("OnGame1_Update_Postfix", new TypeReference[] { - // this.GetTypeReference("StardewValley.Game1", this.StardewValley), - // this.GetTypeReference("Microsoft.Xna.Framework.GameTime", this.MonoGame_Framework)}, - // this.GetTypeReference("System.Void")); - //this.ApplyHookEntry(typeGame1, "Update", "OnGame1_Update_Postfix", false); + // On ColoredObject hooks + TypeDefinition typeColoredObject = this.StardewValley.MainModule.GetType("StardewValley.Objects.ColoredObject"); + this.ApplyCommonHookEntry(typeColoredObject, "drawInMenu", "OnCommonHook10", false); - this.InsertModHook("OnGame1_CreateContentManager_Prefix", new TypeReference[] { + // On HoeDirt hooks + TypeDefinition typeHoeDirt = this.StardewValley.MainModule.GetType("StardewValley.TerrainFeatures.HoeDirt"); + this.ApplyCommonHookEntry(typeHoeDirt, "dayUpdate", "OnCommonHook", true, false); + + // On Utility hooks + TypeDefinition typeUtility = this.StardewValley.MainModule.GetType("StardewValley.Utility"); + this.ApplyCommonHookEntry(typeUtility, "pickFarmEvent", "OnCommonStaticHook", false); + + // On Farmer hooks + TypeDefinition typeFarmer = this.StardewValley.MainModule.GetType("StardewValley.Farmer"); + this.ApplyCommonHookEntry(typeFarmer, "doneEating", "OnCommonHook", false); + + // On MeleeWeapon hooks + TypeDefinition typeMeleeWeapon = this.StardewValley.MainModule.GetType("StardewValley.Tools.MeleeWeapon"); + this.ApplyCommonHookEntry(typeMeleeWeapon, "drawDuringUse", "OnCommonStaticHook10", true, false, method => method.IsStatic); + + // On Multiplayer hooks + TypeDefinition typeMultiplayer = this.StardewValley.MainModule.GetType("StardewValley.Multiplayer"); + this.ApplyCommonHookEntry(typeMultiplayer, "processIncomingMessage", "OnCommonHook", true, false); + + // On GameServer hooks + TypeDefinition typeGameServer = this.StardewValley.MainModule.GetType("StardewValley.Network.GameServer"); + this.ApplyCommonHookEntry(typeGameServer, "sendServerIntroduction", "OnCommonHook", false); + + // On NPC hooks + TypeDefinition typeNPC = this.StardewValley.MainModule.GetType("StardewValley.NPC"); + this.ApplyCommonHookEntry(typeNPC, "receiveGift", "OnCommonHook10", false); + + // On GameMenu hooks + TypeDefinition definition19 = this.StardewValley.MainModule.GetType("StardewValley.Menus.GameMenu"); + this.ApplyCommonHookEntry(definition19, "getTabNumberFromName", "OnCommonHook", false); + + // On FarmHouse hooks + TypeDefinition definition20 = this.StardewValley.MainModule.GetType("StardewValley.Locations.FarmHouse"); + this.ApplyCommonHookEntry(definition20, "loadSpouseRoom", "OnCommonHook", true, false); + + this.InsertModHook("OnGame1_CreateContentManager_Prefix", new[] { this.GetTypeReference("StardewValley.Game1", this.StardewValley), this.GetTypeReference("System.IServiceProvider"), this.GetTypeReference("System.String"), new ByReferenceType(this.GetTypeReference("StardewValley.LocalizedContentManager", this.StardewValley)) }, - new string[] { "game1", "serviceProvider", "rootDirectory", "__result"}, + new[] { "game1", "serviceProvider", "rootDirectory", "__result"}, this.GetTypeReference("System.Boolean")); this.ApplyHookEntry(typeGame1, "CreateContentManager", "OnGame1_CreateContentManager_Prefix", true); - //this.InsertModHook("OnGame1__draw_Prefix", new TypeReference[] { - // this.GetTypeReference("StardewValley.Game1", this.StardewValley), - // this.GetTypeReference("Microsoft.Xna.Framework.GameTime", this.MonoGame_Framework), - // this.GetTypeReference("Microsoft.Xna.Framework.Graphics.RenderTarget2D", this.MonoGame_Framework)}, - // this.GetTypeReference("System.Boolean")); - //this.ApplyHookEntry(typeGame1, "_draw", "OnGame1__draw_Prefix", true); - - //this.InsertModHook("OnGame1_getSourceRectForStandardTileSheet_Prefix", new TypeReference[] { - // this.GetTypeReference("Microsoft.Xna.Framework.Graphics.Texture2D", this.MonoGame_Framework), - // this.GetTypeReference("System.Int32"), - // this.GetTypeReference("System.Int32"), - // this.GetTypeReference("System.Int32"), - // new ByReferenceType(this.GetTypeReference("Microsoft.Xna.Framework.Rectangle", this.MonoGame_Framework)) }, - // this.GetTypeReference("System.Boolean")); - //this.ApplyHookEntry(typeGame1, "getSourceRectForStandardTileSheet", "OnGame1_getSourceRectForStandardTileSheet_Prefix", true); - - //this.InsertModHook("OnGame1_getSourceRectForStandardTileSheet_Postfix", new TypeReference[] { - // this.GetTypeReference("Microsoft.Xna.Framework.Graphics.Texture2D", this.MonoGame_Framework), - // this.GetTypeReference("System.Int32"), - // this.GetTypeReference("System.Int32"), - // this.GetTypeReference("System.Int32"), - // new ByReferenceType(this.GetTypeReference("Microsoft.Xna.Framework.Rectangle", this.MonoGame_Framework)) }, - // this.GetTypeReference("System.Void")); - //this.ApplyHookEntry(typeGame1, "getSourceRectForStandardTileSheet", "OnGame1_getSourceRectForStandardTileSheet_Postfix", false); - - //this.InsertModHook("OnGame1_tryToCheckAt_Postfix", new TypeReference[] { - // this.GetTypeReference("Microsoft.Xna.Framework.Vector2", this.MonoGame_Framework), - // this.GetTypeReference("StardewValley.Farmer", this.StardewValley), - // new ByReferenceType(this.GetTypeReference("System.Boolean")) }, - // this.GetTypeReference("System.Void")); - //this.ApplyHookEntry(typeGame1, "tryToCheckAt", "OnGame1_tryToCheckAt_Postfix", false); - - //this.InsertModHook("OnGame1_getLocationRequest_Prefix", new TypeReference[] { - // this.GetTypeReference("System.String"), - // this.GetTypeReference("System.Boolean"), - // new ByReferenceType(this.GetTypeReference("StardewValley.LocationRequest", this.StardewValley)) }, - // this.GetTypeReference("System.Boolean")); - //this.ApplyHookEntry(typeGame1, "getLocationRequest", "OnGame1_getLocationRequest_Prefix", true); - - //// On Object hooks - //this.InsertModHook("OnObject_canBePlacedHere_Prefix", new TypeReference[] { - // this.GetTypeReference("StardewValley.Object", this.StardewValley), - // this.GetTypeReference("StardewValley.GameLocation", this.StardewValley), - // this.GetTypeReference("Microsoft.Xna.Framework.Vector2", this.MonoGame_Framework), - // new ByReferenceType(this.GetTypeReference("System.Boolean")) }, - // this.GetTypeReference("System.Boolean")); - //TypeDefinition typeObject = this.StardewValley.MainModule.GetType("StardewValley.Object"); - //this.ApplyHookEntry(typeObject, "canBePlacedHere", "OnObject_canBePlacedHere_Prefix", true); - - //this.InsertModHook("OnObject_checkForAction_Prefix", new TypeReference[] { - // this.GetTypeReference("StardewValley.Object", this.StardewValley), - // this.GetTypeReference("StardewValley.Farmer", this.StardewValley), - // this.GetTypeReference("System.Boolean"), - // new ByReferenceType(this.GetTypeReference("System.Boolean"))}, - // this.GetTypeReference("System.Boolean")); - //this.ApplyHookEntry(typeObject, "checkForAction", "OnObject_checkForAction_Prefix", true); - - //this.InsertModHook("OnObject_isIndexOkForBasicShippedCategory_Postfix", new TypeReference[] { - // this.GetTypeReference("System.Int32"), - // new ByReferenceType(this.GetTypeReference("System.Boolean")) }, - // this.GetTypeReference("System.Void")); - //this.ApplyHookEntry(typeObject, "isIndexOkForBasicShippedCategory", "OnObject_isIndexOkForBasicShippedCategory_Postfix", false); - - //// On ReadyCheckDialog hooks - //this.InsertModHook("OnReadyCheckDialog_update_Postfix", new TypeReference[] { - // this.GetTypeReference("StardewValley.Menus.ReadyCheckDialog", this.StardewValley), - // this.GetTypeReference("Microsoft.Xna.Framework.GameTime", this.MonoGame_Framework)}, - // this.GetTypeReference("System.Void")); - //TypeDefinition typeReadyCheckDialog = this.StardewValley.MainModule.GetType("StardewValley.Menus.ReadyCheckDialog"); - //this.ApplyHookEntry(typeReadyCheckDialog, "update", "OnReadyCheckDialog_update_Postfix", false); - - //// On Building hooks - //this.InsertModHook("OnBuilding_load_Prefix", new TypeReference[] { - // this.GetTypeReference("StardewValley.Buildings.Building", this.StardewValley)}, - // this.GetTypeReference("System.Boolean")); - //TypeDefinition typeBuilding = this.StardewValley.MainModule.GetType("StardewValley.Buildings.Building"); - //this.ApplyHookEntry(typeBuilding, "load", "OnBuilding_load_Prefix", true); - - //// On GameLocation hooks - //this.InsertModHook("OnGameLocation_performTouchAction_Postfix", new TypeReference[] { - // this.GetTypeReference("StardewValley.GameLocation", this.StardewValley), - // this.GetTypeReference("System.String"), - // this.GetTypeReference("Microsoft.Xna.Framework.Vector2", this.MonoGame_Framework)}, - // this.GetTypeReference("System.Void")); - //TypeDefinition typeGameLocation = this.StardewValley.MainModule.GetType("StardewValley.GameLocation"); - //this.ApplyHookEntry(typeGameLocation, "performTouchAction", "OnGameLocation_performTouchAction_Postfix", false); - - //this.InsertModHook("OnGameLocation_isActionableTile_Postfix", new TypeReference[] { - // this.GetTypeReference("StardewValley.GameLocation", this.StardewValley), - // this.GetTypeReference("System.Int32"), - // this.GetTypeReference("System.Int32"), - // this.GetTypeReference("StardewValley.Farmer", this.StardewValley), - // new ByReferenceType(this.GetTypeReference("System.Boolean"))}, - // this.GetTypeReference("System.Void")); - //this.ApplyHookEntry(typeGameLocation, "isActionableTile", "OnGameLocation_isActionableTile_Postfix", false); - - //this.InsertModHook("OnGameLocation_tryToAddCritters_Prefix", new TypeReference[] { - // this.GetTypeReference("StardewValley.GameLocation", this.StardewValley), - // this.GetTypeReference("System.Boolean")}, - // this.GetTypeReference("System.Boolean")); - //this.ApplyHookEntry(typeGameLocation, "tryToAddCritters", "OnGameLocation_tryToAddCritters_Prefix", true); - - //this.InsertModHook("OnGameLocation_getSourceRectForObject_Prefix", new TypeReference[] { - // this.GetTypeReference("System.Int32"), - // new ByReferenceType(this.GetTypeReference("Microsoft.Xna.Framework.Rectangle", this.MonoGame_Framework)) }, - // this.GetTypeReference("System.Boolean")); - //this.ApplyHookEntry(typeGameLocation, "getSourceRectForObject", "OnGameLocation_getSourceRectForObject_Prefix", true); - - //this.InsertModHook("OnGameLocation_getSourceRectForObject_Postfix", new TypeReference[] { - // this.GetTypeReference("System.Int32"), - // new ByReferenceType(this.GetTypeReference("Microsoft.Xna.Framework.Rectangle", this.MonoGame_Framework)) }, - // this.GetTypeReference("System.Void")); - //this.ApplyHookEntry(typeGameLocation, "getSourceRectForObject", "OnGameLocation_getSourceRectForObject_Postfix", false); - - //this.InsertModHook("OnGameLocation_answerDialogue_Prefix", new TypeReference[] { - // this.GetTypeReference("StardewValley.GameLocation", this.StardewValley), - // this.GetTypeReference("StardewValley.Response", this.StardewValley), - // new ByReferenceType(this.GetTypeReference("System.Boolean"))}, - // this.GetTypeReference("System.Boolean")); - //this.ApplyHookEntry(typeGameLocation, "answerDialogue", "OnGameLocation_answerDialogue_Prefix", true); - - //// On Objects.TV hooks - //this.InsertModHook("OnObjectsTV_checkForAction_Prefix", new TypeReference[] { - // this.GetTypeReference("StardewValley.Objects.TV", this.StardewValley), - // this.GetTypeReference("StardewValley.Farmer", this.StardewValley), - // this.GetTypeReference("System.Boolean"), - // new ByReferenceType(this.GetTypeReference("System.Boolean"))}, - // this.GetTypeReference("System.Boolean")); - //TypeDefinition typeObjectsTV = this.StardewValley.MainModule.GetType("StardewValley.Objects.TV"); - //this.ApplyHookEntry(typeObjectsTV, "checkForAction", "OnObjectsTV_checkForAction_Prefix", true); - - //this.InsertModHook("OnObjectsTV_checkForAction_Postfix", new TypeReference[] { - // this.GetTypeReference("StardewValley.Objects.TV", this.StardewValley), - // this.GetTypeReference("StardewValley.Farmer", this.StardewValley), - // this.GetTypeReference("System.Boolean"), - // new ByReferenceType(this.GetTypeReference("System.Boolean"))}, - // this.GetTypeReference("System.Void")); - //this.ApplyHookEntry(typeObjectsTV, "checkForAction", "OnObjectsTV_checkForAction_Postfix", false); - - return this.StardewValley; } } diff --git a/src/Mod.csproj b/src/Mod.csproj index 7d91a486..2ca0afa8 100644 --- a/src/Mod.csproj +++ b/src/Mod.csproj @@ -434,65 +434,93 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -513,11 +541,11 @@ + - @@ -592,6 +620,9 @@ + + + @@ -702,123 +733,128 @@ - - False - ..\..\assemblies\BmFont.dll - - - False - ..\..\assemblies\Google.Android.Vending.Expansion.Downloader.dll - - - False - ..\..\assemblies\Google.Android.Vending.Expansion.ZipFile.dll - - - False - ..\..\assemblies\Google.Android.Vending.Licensing.dll - - - False - ..\..\assemblies\Java.Interop.dll - - - False - ..\..\assemblies\Microsoft.AppCenter.dll - - - False - ..\..\assemblies\Microsoft.AppCenter.Analytics.dll - - - False - ..\..\assemblies\Microsoft.AppCenter.Analytics.Android.Bindings.dll - - - False - ..\..\assemblies\Microsoft.AppCenter.Android.Bindings.dll - - - False - ..\..\assemblies\Microsoft.AppCenter.Crashes.dll - - - False - ..\..\assemblies\Microsoft.AppCenter.Crashes.Android.Bindings.dll - - - False - ..\..\assemblies\Mono.Android.dll - - - False - ..\..\assemblies\Mono.Security.dll - - - False - ..\..\assemblies\MonoGame.Framework.dll - ..\Mods\assemblies\StardewValley.dll + + False + ..\Mods\assemblies\BmFont.dll + + + False + ..\Mods\assemblies\Google.Android.Vending.Expansion.Downloader.dll + + + False + ..\Mods\assemblies\Google.Android.Vending.Expansion.ZipFile.dll + + + False + ..\Mods\assemblies\Google.Android.Vending.Licensing.dll + + + False + ..\Mods\assemblies\Java.Interop.dll + + + False + ..\Mods\assemblies\Microsoft.AppCenter.dll + + + False + ..\Mods\assemblies\Microsoft.AppCenter.Analytics.dll + + + False + ..\Mods\assemblies\Microsoft.AppCenter.Analytics.Android.Bindings.dll + + + False + ..\Mods\assemblies\Microsoft.AppCenter.Android.Bindings.dll + + + False + ..\Mods\assemblies\Microsoft.AppCenter.Crashes.dll + + + False + ..\Mods\assemblies\Microsoft.AppCenter.Crashes.Android.Bindings.dll + + + False + ..\Mods\assemblies\Mono.Android.dll + + + False + ..\Mods\assemblies\Mono.Security.dll + + + False + ..\Mods\assemblies\MonoGame.Framework.dll + + + ..\Mods\assemblies\mscorlib.dll + - ..\..\assemblies\System.dll + ..\Mods\assemblies\System.dll - ..\..\assemblies\System.Xml + ..\Mods\assemblies\System.Xml + True + + + ..\Mods\assemblies\System.Xml.Linq + True - ..\..\assemblies\System.Net.Http.dll - - - ..\..\assemblies\System.ServiceModel.Internals.dll + ..\Mods\assemblies\System.Net.Http.dll - ..\..\assemblies\System.Runtime.Serialization.dll + ..\Mods\assemblies\System.Runtime.Serialization.dll False - ..\..\assemblies\Xamarin.Android.Arch.Core.Common.dll + ..\Mods\assemblies\Xamarin.Android.Arch.Core.Common.dll False - ..\..\assemblies\Xamarin.Android.Arch.Lifecycle.Common.dll + ..\Mods\assemblies\Xamarin.Android.Arch.Lifecycle.Common.dll False - ..\..\assemblies\Xamarin.Android.Arch.Lifecycle.Runtime.dll + ..\Mods\assemblies\Xamarin.Android.Arch.Lifecycle.Runtime.dll False - ..\..\assemblies\Xamarin.Android.Support.Annotations.dll + ..\Mods\assemblies\Xamarin.Android.Support.Annotations.dll False - ..\..\assemblies\Xamarin.Android.Support.Compat.dll + ..\Mods\assemblies\Xamarin.Android.Support.Compat.dll False - ..\..\assemblies\Xamarin.Android.Support.Core.UI.dll + ..\Mods\assemblies\Xamarin.Android.Support.Core.UI.dll False - ..\..\assemblies\Xamarin.Android.Support.Core.Utils.dll + ..\Mods\assemblies\Xamarin.Android.Support.Core.Utils.dll False - ..\..\assemblies\Xamarin.Android.Support.Fragment.dll + ..\Mods\assemblies\Xamarin.Android.Support.Fragment.dll False - ..\..\assemblies\Xamarin.Android.Support.Media.Compat.dll + ..\Mods\assemblies\Xamarin.Android.Support.Media.Compat.dll False - ..\..\assemblies\Xamarin.Android.Support.v4.dll + ..\Mods\assemblies\Xamarin.Android.Support.v4.dll False - ..\..\assemblies\xTile.dll + ..\Mods\assemblies\xTile.dll diff --git a/src/ModEntry.cs b/src/ModEntry.cs index c8914bc5..129bf523 100644 --- a/src/ModEntry.cs +++ b/src/ModEntry.cs @@ -8,6 +8,7 @@ using System.IO; using StardewValley.Menus; using StardewValley.Buildings; using StardewValley.Objects; +using StardewModdingAPI.Patches; namespace SMDroid { @@ -57,7 +58,17 @@ namespace SMDroid return this.core.GameInstance.Update(param1 as GameTime); case "StardewValley.Game1._draw": return this.core.GameInstance.Draw(param1 as GameTime, param2 as RenderTarget2D); + case "StardewValley.Object.getDescription": + if (!ObjectErrorPatch.Object_GetDescription_Prefix(__instance as StardewValley.Object, ref __result)) + { + return false; + } + return true; default: + if ((hookName == "StardewValley.Dialogue..ctor") && !DialogueErrorPatch.Prefix(__instance as Dialogue, (string)param1, param2 as NPC)) + { + return false; + } return this.core.GameInstance.OnCommonHook_Prefix(hookName, __instance, ref param1, ref param2, ref param3, ref param4, ref __result); } } @@ -81,6 +92,29 @@ namespace SMDroid { this.core.GameInstance.OnCommonStaticHook_Postfix(hookName, ref param1, ref param2, ref param3, ref param4, ref param5, ref __state, ref __result); } + public override void OnCommonHook10_Postfix(string hookName, object __instance, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref bool __state, ref object __result) + { + this.core.GameInstance.OnCommonHook10_Postfix(hookName, __instance, ref param1, ref param2, ref param3, ref param4, ref param5, ref param6, ref param7, ref param8, ref param9, ref __state, ref __result); + } + public override bool OnCommonHook10_Prefix(string hookName, object __instance, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object __result) + { + if ((hookName == "StardewValley.Menus.IClickableMenu.drawToolTip") && !ObjectErrorPatch.IClickableMenu_DrawTooltip_Prefix(__instance as IClickableMenu, param4 as Item)) + { + return false; + } + return this.core.GameInstance.OnCommonHook10_Prefix(hookName, __instance, ref param1, ref param2, ref param3, ref param4, ref param5, ref param6, ref param7, ref param8, ref param9, ref __result); + } + public override void OnCommonStaticHook10_Postfix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object param10, ref bool __state, ref object __result) + { + this.core.GameInstance.OnCommonStaticHook10_Postfix(hookName, ref param1, ref param2, ref param3, ref param4, ref param5, ref param6, ref param7, ref param8, ref param9, ref param10, ref __state, ref __result); + } + + public override bool OnCommonStaticHook10_Prefix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object param10, ref object __result) + { + return this.core.GameInstance.OnCommonStaticHook10_Prefix(hookName, ref param1, ref param2, ref param3, ref param4, ref param5, ref param6, ref param7, ref param8, ref param9, ref param10, ref __result); + } + + public override void OnGame1_NewDayAfterFade(Action action) { this.core.GameInstance.OnNewDayAfterFade(); diff --git a/src/SMAPI/Framework/ModHelpers/DataHelper.cs b/src/SMAPI/Framework/ModHelpers/DataHelper.cs index 3b5c1752..90b02b09 100644 --- a/src/SMAPI/Framework/ModHelpers/DataHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/DataHelper.cs @@ -44,7 +44,7 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The is not relative or contains directory climbing (../). public TModel ReadJsonFile(string path) where TModel : class { - if (!PathUtilities.IsSafeRelativePath(path)) + if ((this.ModID != "Platonymous.ScaleUp") && !PathUtilities.IsSafeRelativePath(path)) throw new InvalidOperationException($"You must call {nameof(IModHelper.Data)}.{nameof(this.ReadJsonFile)} with a relative path."); path = Path.Combine(this.ModFolderPath, PathUtilities.NormalisePathSeparators(path)); diff --git a/src/SMAPI/Framework/ModLoading/RewriteIgnoreConfig.cs b/src/SMAPI/Framework/ModLoading/RewriteIgnoreConfig.cs new file mode 100644 index 00000000..603b70d7 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/RewriteIgnoreConfig.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.SMAPI.Framework.ModLoading +{ + class RewriteIgnoreConfig + { + public Dictionary Ignore { get; set; } = new Dictionary(); + } +} diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index d8b77436..f2c0c6f8 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -239,11 +239,11 @@ namespace StardewModdingAPI.Framework ); StardewValley.Program.gamePtr = Game1.game1; // apply game patches - //new GamePatcher(this.Monitor).Apply( - // new DialogueErrorPatch(this.MonitorForGame, this.Reflection), - // new ObjectErrorPatch(), - // new LoadForNewGamePatch(this.Reflection, this.GameInstance.OnLoadStageChanged) - //); + new GamePatcher(this.Monitor).Apply( + new DialogueErrorPatch(this.MonitorForGame, this.Reflection), + new ObjectErrorPatch(), + new LoadForNewGamePatch(this.Reflection, this.GameInstance.OnLoadStageChanged) + ); //// add exit handler //new Thread(() => diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index d9be51f9..c9003842 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -114,6 +114,44 @@ namespace StardewModdingAPI.Framework } return true; } + internal void OnCommonHook10_Postfix(string hookName, object instance, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref bool state, ref object result) + { + foreach (IMod mod in this.HookReceiver) + { + mod.OnCommonHook10_Postfix(hookName, instance, ref param1, ref param2, ref param3, ref param4, ref param5, ref param6, ref param7, ref param8, ref param9, ref state, ref result); + } + } + internal bool OnCommonHook10_Prefix(string hookName, object instance, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object result) + { + foreach (IMod mod in this.HookReceiver) + { + if (!mod.OnCommonHook10_Prefix(hookName, instance, ref param1, ref param2, ref param3, ref param4, ref param5, ref param6, ref param7, ref param8, ref param9, ref result)) + { + return false; + } + } + return true; + } + internal void OnCommonStaticHook10_Postfix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object param10, ref bool state, ref object result) + { + foreach (IMod mod in this.HookReceiver) + { + mod.OnCommonStaticHook10_Postfix(hookName, ref param1, ref param2, ref param3, ref param4, ref param5, ref param6, ref param7, ref param8, ref param9, ref param10, ref state, ref result); + } + } + + internal bool OnCommonStaticHook10_Prefix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object param10, ref object result) + { + foreach (IMod mod in this.HookReceiver) + { + if (!mod.OnCommonStaticHook10_Prefix(hookName, ref param1, ref param2, ref param3, ref param4, ref param5, ref param6, ref param7, ref param8, ref param9, ref param10, ref result)) + { + return false; + } + } + return true; + } + /// Whether the game is saving and SMAPI has already raised . private bool IsBetweenSaveEvents; @@ -1137,7 +1175,6 @@ namespace StardewModdingAPI.Framework IReflectedMethod DrawTutorialUI = this.Reflection.GetMethod(Game1.game1, "DrawTutorialUI", new Type[] { }); IReflectedMethod DrawGreenPlacementBounds = this.Reflection.GetMethod(Game1.game1, "DrawGreenPlacementBounds", new Type[] { }); - Matrix matrix; _drawHUD.SetValue(false); _drawActiveClickableMenu.SetValue(false); if (this.Reflection.GetField(typeof(Game1), "_newDayTask").GetValue() != null) @@ -1145,9 +1182,9 @@ namespace StardewModdingAPI.Framework Game1.game1.GraphicsDevice.Clear(bgColor.GetValue()); if (Game1.showInterDayScroll) { - matrix = Matrix.CreateScale((float)1f); - Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, new Matrix?(matrix)); - SpriteText.drawStringWithScrollCenteredAt(Game1.spriteBatch, Game1.content.LoadString(@"Strings\UI:please_wait"), Game1.game1.GraphicsDevice.Viewport.Width / 2, Game1.game1.GraphicsDevice.Viewport.Height / 2, "", 1f, -1, 0, 0.088f, false); + Matrix value = Matrix.CreateScale(1f); + Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, new Matrix?(value)); + SpriteText.drawStringWithScrollCenteredAt(Game1.spriteBatch, Game1.content.LoadString("Strings\\UI:please_wait"), Game1.game1.GraphicsDevice.Viewport.Width / 2, Game1.game1.GraphicsDevice.Viewport.Height / 2, "", 1f, -1, 0, 0.088f, false); Game1.spriteBatch.End(); } } @@ -1246,7 +1283,7 @@ namespace StardewModdingAPI.Framework Game1.game1.GraphicsDevice.Clear(bgColor.GetValue()); if (((Game1.activeClickableMenu != null) && Game1.options.showMenuBackground) && Game1.activeClickableMenu.showWithoutTransparencyIfOptionIsSet()) { - matrix = Matrix.CreateScale((float)1f); + Matrix matrix = Matrix.CreateScale((float)1f); Game1.SetSpriteBatchBeginNextID("C"); _spriteBatchBegin.Invoke(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, new Matrix?(matrix)); events.Rendering.RaiseEmpty(); diff --git a/src/SMAPI/IMod.cs b/src/SMAPI/IMod.cs index 9d91a140..89a88b70 100644 --- a/src/SMAPI/IMod.cs +++ b/src/SMAPI/IMod.cs @@ -35,6 +35,10 @@ namespace StardewModdingAPI void OnCommonHook_Postfix(string hookName, object __instance, ref object param1, ref object param2, ref object param3, ref object param4, ref bool __state, ref object __result); bool OnCommonStaticHook_Prefix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object __result); void OnCommonStaticHook_Postfix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref bool __state, ref object __result); + void OnCommonHook10_Postfix(string hookName, object __instance, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref bool __state, ref object __result); + bool OnCommonHook10_Prefix(string hookName, object __instance, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object __result); + void OnCommonStaticHook10_Postfix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object param10, ref bool __state, ref object __result); + bool OnCommonStaticHook10_Prefix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object param10, ref object __result); /// Get an API that other mods can access. This is always called after . object GetApi(); diff --git a/src/SMAPI/Mod.cs b/src/SMAPI/Mod.cs index b3cda205..6b37ea4d 100644 --- a/src/SMAPI/Mod.cs +++ b/src/SMAPI/Mod.cs @@ -51,6 +51,10 @@ namespace StardewModdingAPI public virtual void OnCommonStaticHook_Postfix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref bool __state, ref object __result) { } + public virtual void OnCommonHook10_Postfix(string hookName, object __instance, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref bool __state, ref object __result) { } + public virtual bool OnCommonHook10_Prefix(string hookName, object __instance, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object __result) { return true; } + public virtual void OnCommonStaticHook10_Postfix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object param10, ref bool __state, ref object __result) { } + public virtual bool OnCommonStaticHook10_Prefix(string hookName, ref object param1, ref object param2, ref object param3, ref object param4, ref object param5, ref object param6, ref object param7, ref object param8, ref object param9, ref object param10, ref object __result) { return true; } /// Get an API that other mods can access. This is always called after . diff --git a/src/SMAPI/Patches/DialogueErrorPatch.cs b/src/SMAPI/Patches/DialogueErrorPatch.cs index d8905fd1..db01e93d 100644 --- a/src/SMAPI/Patches/DialogueErrorPatch.cs +++ b/src/SMAPI/Patches/DialogueErrorPatch.cs @@ -46,10 +46,10 @@ namespace StardewModdingAPI.Patches /// The Harmony instance. public void Apply(HarmonyInstance harmony) { - ConstructorInfo constructor = AccessTools.Constructor(typeof(Dialogue), new[] { typeof(string), typeof(NPC) }); - MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(DialogueErrorPatch.Prefix)); + //ConstructorInfo constructor = AccessTools.Constructor(typeof(Dialogue), new[] { typeof(string), typeof(NPC) }); + //MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(DialogueErrorPatch.Prefix)); - harmony.Patch(constructor, new HarmonyMethod(prefix), null); + //harmony.Patch(constructor, new HarmonyMethod(prefix), null); } @@ -63,7 +63,7 @@ namespace StardewModdingAPI.Patches /// Returns whether to execute the original method. /// This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments. [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony.")] - private static bool Prefix(Dialogue __instance, string masterDialogue, NPC speaker) + public static bool Prefix(Dialogue __instance, string masterDialogue, NPC speaker) { // get private members bool nameArraysTranslated = DialogueErrorPatch.Reflection.GetField(typeof(Dialogue), "nameArraysTranslated").GetValue(); diff --git a/src/SMAPI/Patches/LoadForNewGamePatch.cs b/src/SMAPI/Patches/LoadForNewGamePatch.cs index 3f75b71b..b766c94d 100644 --- a/src/SMAPI/Patches/LoadForNewGamePatch.cs +++ b/src/SMAPI/Patches/LoadForNewGamePatch.cs @@ -55,11 +55,11 @@ namespace StardewModdingAPI.Patches /// The Harmony instance. public void Apply(HarmonyInstance harmony) { - MethodInfo method = AccessTools.Method(typeof(Game1), nameof(Game1.loadForNewGame)); - MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(LoadForNewGamePatch.Prefix)); - MethodInfo postfix = AccessTools.Method(this.GetType(), nameof(LoadForNewGamePatch.Postfix)); + //MethodInfo method = AccessTools.Method(typeof(Game1), nameof(Game1.loadForNewGame)); + //MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(LoadForNewGamePatch.Prefix)); + //MethodInfo postfix = AccessTools.Method(this.GetType(), nameof(LoadForNewGamePatch.Postfix)); - harmony.Patch(method, new HarmonyMethod(prefix), new HarmonyMethod(postfix)); + //harmony.Patch(method, new HarmonyMethod(prefix), new HarmonyMethod(postfix)); } diff --git a/src/SMAPI/Patches/ObjectErrorPatch.cs b/src/SMAPI/Patches/ObjectErrorPatch.cs index d72201c3..ed0d8645 100644 --- a/src/SMAPI/Patches/ObjectErrorPatch.cs +++ b/src/SMAPI/Patches/ObjectErrorPatch.cs @@ -25,16 +25,16 @@ namespace StardewModdingAPI.Patches public void Apply(HarmonyInstance harmony) { // object.getDescription - harmony.Patch( - original: AccessTools.Method(typeof(SObject), nameof(SObject.getDescription)), - prefix: new HarmonyMethod(AccessTools.Method(this.GetType(), nameof(ObjectErrorPatch.Object_GetDescription_Prefix))) - ); + //harmony.Patch( + // original: AccessTools.Method(typeof(SObject), nameof(SObject.getDescription)), + // prefix: new HarmonyMethod(AccessTools.Method(this.GetType(), nameof(ObjectErrorPatch.Object_GetDescription_Prefix))) + //); - // IClickableMenu.drawToolTip - harmony.Patch( - original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.drawToolTip)), - prefix: new HarmonyMethod(AccessTools.Method(this.GetType(), nameof(ObjectErrorPatch.IClickableMenu_DrawTooltip_Prefix))) - ); + //// IClickableMenu.drawToolTip + //harmony.Patch( + // original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.drawToolTip)), + // prefix: new HarmonyMethod(AccessTools.Method(this.GetType(), nameof(ObjectErrorPatch.IClickableMenu_DrawTooltip_Prefix))) + //); } @@ -47,7 +47,7 @@ namespace StardewModdingAPI.Patches /// Returns whether to execute the original method. /// This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments. [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony.")] - private static bool Object_GetDescription_Prefix(SObject __instance, ref string __result) + public static bool Object_GetDescription_Prefix(SObject __instance, ref object __result) { // invalid bigcraftables crash instead of showing '???' like invalid non-bigcraftables if (!__instance.IsRecipe && __instance.bigCraftable.Value && !Game1.bigCraftablesInformation.ContainsKey(__instance.ParentSheetIndex)) @@ -65,7 +65,7 @@ namespace StardewModdingAPI.Patches /// Returns whether to execute the original method. /// This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments. [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony.")] - private static bool IClickableMenu_DrawTooltip_Prefix(IClickableMenu __instance, Item hoveredItem) + public static bool IClickableMenu_DrawTooltip_Prefix(IClickableMenu __instance, Item hoveredItem) { // invalid edible item cause crash when drawing tooltips if (hoveredItem is SObject obj && obj.Edibility != -300 && !Game1.objectInformation.ContainsKey(obj.ParentSheetIndex))