Changes

Jump to navigation Jump to search
→‎Breaking changes: + HarmonyMethod no longer allows null
Line 67: Line 67:     
For example, consider this code:
 
For example, consider this code:
<source lang="C#">
+
<source lang="c#">
 
public class GameLocation
 
public class GameLocation
 
{
 
{
Line 77: Line 77:     
<tt>Farm.cleanupBeforePlayerExit</tt> doesn't exist, so it's inherited from <tt>GameLocation</tt>. Harmony 1.x would let you patch <tt>Farm.cleanupBeforePlayerExit</tt>, but in Harmony 2.x you must target the actual method (<tt>GameLocation.cleanupBeforePlayerExit</tt> in this example).
 
<tt>Farm.cleanupBeforePlayerExit</tt> doesn't exist, so it's inherited from <tt>GameLocation</tt>. Harmony 1.x would let you patch <tt>Farm.cleanupBeforePlayerExit</tt>, but in Harmony 2.x you must target the actual method (<tt>GameLocation.cleanupBeforePlayerExit</tt> in this example).
 +
 +
===<tt>HarmonyMethod</tt> no longer allows null===
 +
Harmony 1.''x'' allowed <code>new HarmonyMethod(null)</code>, so you could safely use it with methods that might not exist. Harmony 2.0 now throws an exception in that case, so you should check if the method might not exist:
 +
<source lang="c#">
 +
MethodInfo prefix = AccessTools.Method(this.GetType(), "Prefix");
 +
if (prefix != null)
 +
  harmony.Patch(original, new HarmonyMethod(prefix));
 +
</source>
    
[[Category:Modding]]
 
[[Category:Modding]]
translators
8,411

edits

Navigation menu