Created
June 29, 2015 17:34
-
-
Save boformer/98822bdd5ca1e2bcfe68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using UnityEngine; | |
namespace LargerFootprints.Detour | |
{ | |
public class BuildingAIDetour | |
{ | |
private static bool deployed = false; | |
private static RedirectCallsState _SchoolAI_GetWidthRange_state; | |
private static MethodInfo _SchoolAI_GetWidthRange_original; | |
private static MethodInfo _SchoolAI_GetWidthRange_detour; | |
private static RedirectCallsState _SchoolAI_GetLengthRange_state; | |
private static MethodInfo _SchoolAI_GetLengthRange_original; | |
private static MethodInfo _SchoolAI_GetLengthRange_detour; | |
public static void Deploy() | |
{ | |
if (!deployed) | |
{ | |
_SchoolAI_GetWidthRange_original = typeof(SchoolAI).GetMethod("GetWidthRange", BindingFlags.Instance | BindingFlags.Public); | |
_SchoolAI_GetWidthRange_detour = typeof(BuildingAIDetour).GetMethod("GetWidthRange", BindingFlags.Instance | BindingFlags.Public); | |
_SchoolAI_GetWidthRange_state = RedirectionHelper.RedirectCalls(_SchoolAI_GetWidthRange_original, _SchoolAI_GetWidthRange_detour); | |
_SchoolAI_GetLengthRange_original = typeof(SchoolAI).GetMethod("GetLengthRange", BindingFlags.Instance | BindingFlags.Public); | |
_SchoolAI_GetLengthRange_detour = typeof(BuildingAIDetour).GetMethod("GetLengthRange", BindingFlags.Instance | BindingFlags.Public); | |
_SchoolAI_GetLengthRange_state = RedirectionHelper.RedirectCalls(_SchoolAI_GetLengthRange_original, _SchoolAI_GetLengthRange_detour); | |
deployed = true; | |
Debug.Log("LargerFootprints: BuildingAI Methods detoured!"); | |
} | |
} | |
public static void Revert() | |
{ | |
if (deployed) | |
{ | |
RedirectionHelper.RevertRedirect(_SchoolAI_GetWidthRange_original, _SchoolAI_GetWidthRange_state); | |
_SchoolAI_GetWidthRange_original = null; | |
_SchoolAI_GetWidthRange_detour = null; | |
RedirectionHelper.RevertRedirect(_SchoolAI_GetLengthRange_original, _SchoolAI_GetLengthRange_state); | |
_SchoolAI_GetLengthRange_original = null; | |
_SchoolAI_GetLengthRange_detour = null; | |
deployed = false; | |
Debug.Log("LargerFootprints: BuildingAI Methods restored!"); | |
} | |
} | |
public virtual void GetWidthRange(out int minWidth, out int maxWidth) | |
{ | |
Debug.Log("GetWidthRange called."); | |
minWidth = 1; | |
maxWidth = 32; | |
} | |
public virtual void GetLengthRange(out int minLength, out int maxLength) | |
{ | |
Debug.Log("GetLengthRange called."); | |
minLength = 1; | |
maxLength = 32; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment