Changes

Jump to navigation Jump to search
m
→‎When to use Harmony: clarify version compatibility note
Line 10: Line 10:  
* It's very easy to cause crashes, errors, or subtle bugs, including difficult-to-diagnose memory corruption errors.
 
* It's very easy to cause crashes, errors, or subtle bugs, including difficult-to-diagnose memory corruption errors.
 
* SMAPI often can't detect incompatible Harmony code.
 
* SMAPI often can't detect incompatible Harmony code.
* Crossplatform compatibility isn't guaranteed.
+
* SMAPI often can't rewrite Harmony patches for compatibility, so the mod may break on other platforms (e.g. Android) or in future game updates.
 
* Patches may conflict with other Harmony mods, sometimes in ways that are difficult to troubleshoot.
 
* Patches may conflict with other Harmony mods, sometimes in ways that are difficult to troubleshoot.
 
* Patches may have unpredictable effects on other mods that aren't using Harmony. That may also irritate other modders, if players often report bugs to other mods due to your patches.
 
* Patches may have unpredictable effects on other mods that aren't using Harmony. That may also irritate other modders, if players often report bugs to other mods due to your patches.
Line 44: Line 44:  
<li>Unhandled errors in a patch can be hard to troubleshoot, which often leads to players asking for help on the SMAPI page instead of your mod. '''Please''' handle errors, log them, and default to the original code. For example:
 
<li>Unhandled errors in a patch can be hard to troubleshoot, which often leads to players asking for help on the SMAPI page instead of your mod. '''Please''' handle errors, log them, and default to the original code. For example:
 
<syntaxhighlight lang="C#">
 
<syntaxhighlight lang="C#">
public class ObjectPatches
+
internal class ObjectPatches
 
{
 
{
 
     private static IMonitor Monitor;
 
     private static IMonitor Monitor;
    
     // call this method from your Entry class
 
     // call this method from your Entry class
     public static void Initialize(IMonitor monitor)
+
     internal static void Initialize(IMonitor monitor)
 
     {
 
     {
 
         Monitor = monitor;
 
         Monitor = monitor;
 
     }
 
     }
   −
     public static bool CanBePlacedHere_Prefix(StardewValley.Object __instance, GameLocation location, Vector2 tile, ref bool __result)
+
     // patches need to be static!
 +
    internal static bool CanBePlacedHere_Prefix(StardewValley.Object __instance, GameLocation location, Vector2 tile, ref bool __result)
 
     {
 
     {
 
         try
 
         try
Line 87: Line 88:     
However annotations work differently in the compiled code, so SMAPI can't rewrite them. That means mods which use annotations are more fragile; they may break without warning in future game/SMAPI/Harmony updates, and may not work on some platforms.
 
However annotations work differently in the compiled code, so SMAPI can't rewrite them. That means mods which use annotations are more fragile; they may break without warning in future game/SMAPI/Harmony updates, and may not work on some platforms.
 +
 +
===What is inlining and why does it matter?===
 +
 +
[https://en.wikipedia.org/wiki/Inline_expansion Inlining] is when the JIT takes a method call and sticks the body of the method called instead of emitting an actual call. If this happens, a harmony patch applied to the callee will not take effect.
 +
 +
The heuristics the JIT uses to decide whether or not to inline a method are not documented and are subject to change, but [https://stackoverflow.com/a/31467000/19366602 small, simple methods that do not throw exceptions] are the most likely to be inlined. Additionally, the heuristic seems to change between platform and platform, with mac being more aggressive than Windows.
translators
8,404

edits

Navigation menu