Exemple #1
0
        /// <summary>
        /// This guy is our wrapper to doing the detours. it does the detour and then adds the returned
        /// RedirectCallState object too our dictionary for later reversal.
        /// </summary>
        /// <param name="type1">The original type of the method we're detouring</param>
        /// <param name="type2">Our replacement type of the method we're detouring</param>
        /// <param name="p">The original method\function name</param>
        /// <param name="OursIsPublic">If second method is public set to true</param>
        private static void RedirectCalls(Type type1, Type type2, string p, bool OursIsPublic = false, bool RestrictPrivate = false)
        {
            var bindflags1 = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

            if (RestrictPrivate)
            {
                bindflags1 = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
            }
            var bindflags2 = BindingFlags.Static | BindingFlags.NonPublic;

            if (OursIsPublic)
            {
                bindflags2 = BindingFlags.Static | BindingFlags.Public;
            }

            var theMethod = type1.GetMethod(p, bindflags1);

            if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 1)
            {
                Helper.dbgLog(string.Concat("attempting to redirect ", theMethod.ToString(), " to ", type2.GetMethod(p, bindflags2).ToString()));
            }
            redirectDic.Add(theMethod, RedirectionHelper.RedirectCalls(theMethod, type2.GetMethod(p, bindflags2), false)); //makes the actual detour and stores the callstate info.
            if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 1)
            {
                Helper.dbgLog(string.Concat("redirect success: ", theMethod.ToString(), " to ", type2.GetMethod(p, bindflags2).ToString()));
            }
            //RedirectionHelper.RedirectCalls(type1.GetMethod(p, bindflags1), type2.GetMethod(p, bindflags2), false);
        }
Exemple #2
0
        private IEnumerator CreateProp()
        {
            Debug.Log("CreateProp detour");
            UndoMod.Instsance.BeginObserving("Build prop", "Vanilla");
            IEnumerator result = null;

            RedirectionHelper.RevertRedirect(createProp_original, state);
            try
            {
                result = (IEnumerator)createProp_original.Invoke(ToolsModifierControl.GetTool <PropTool>(), new object[] { });
                AsyncTask asyncTask = new AsyncTask(result, null);
                asyncTask.Execute();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UndoMod.Instsance.InvalidateAll();
            }
            state = RedirectionHelper.RedirectCalls(createProp_original, patch);

            //Singleton<SimulationManager>.instance.AddAction(() => {
            UndoMod.Instsance.EndObserving();
            //});

            yield return(0);

            yield break;
        }
Exemple #3
0
        /// <summary>
        /// This guy is our wrapper to doing the detours. it does the detour and then adds the returned
        /// RedirectCallState object too our dictionary for later reversal.
        /// </summary>
        /// <param name="type1">The original type of the method we're detouring</param>
        /// <param name="type2">Our replacement type of the method we're detouring</param>
        /// <param name="p">The original method\function name</param>
        private static void RedirectCalls(Type type1, Type type2, string p)
        {
            var bindflags1 = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
            var bindflags2 = BindingFlags.Static | BindingFlags.Public;
            var theMethod  = type1.GetMethod(p, bindflags1);

            //var replacementMethod = type2.GetMethod(p,bindflags2);
            //if (theMethod == null || replacementMethod == null)
            //{
            //    Logger.dbgLog("Failed to locate function: " + p + ((theMethod == null) ? "  orignal":"  replacement"));
            //}
            //if (Mod.DEBUG_LOG_ON)
            //{
            //redirectDic.Add(theMethod, RedirectionHelper.RedirectCalls(theMethod, type2.GetMethod(p, bindflags2), true)); //makes the actual detour and stores the callstate info.
            //}
            //else
            //{
            redirectDic.Add(theMethod, RedirectionHelper.RedirectCalls(theMethod, type2.GetMethod(p, bindflags2), false));     //makes the actual detour and stores the callstate info.
            //}

            //if (Mod.DEBUG_LOG_ON)
            //{
            //Logger.dbgLog(p.ToString() + " redirected");
            //}

            //RedirectionHelper.RedirectCalls(type1.GetMethod(p, bindflags1), type2.GetMethod(p, bindflags2), false);
        }
Exemple #4
0
        private IEnumerator CreateBuilding_Short()
        {
            //Debug.Log("CreateBuilding detour");
            UndoMod.Instsance.BeginObserving("Build building", "Vanilla");
            IEnumerator result = null;

            RedirectionHelper.RevertRedirect(createBuilding_originalShort, state);
            state = RedirectionHelper.RedirectCalls(shortPatch, createBuilding_originalShort);
            try
            {
                // This is a genius piece of code. No joking!
                //result = (IEnumerator) createBuilding_originalShort.Invoke(ToolsModifierControl.GetTool<BuildingTool>(), new object[] {});
                result = CreateBuilding_Short();
                AsyncTask asyncTask = new AsyncTask(result, null);
                asyncTask.Execute();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UndoMod.Instsance.InvalidateAll();
            } finally {
                RedirectionHelper.RevertRedirect(shortPatch, state);
                state = RedirectionHelper.RedirectCalls(createBuilding_originalShort, shortPatch);
            }

            //Singleton<SimulationManager>.instance.AddAction(() => {
            UndoMod.Instsance.EndObserving();
            //});

            yield return(0);

            yield break;
        }
Exemple #5
0
        private void RedirectCalls()
        {
            var nullMethod = typeof(Mod).GetMethod("NullOverride");

            //Removes the ability to pause/unpause the game
            var srcMethod = typeof(SimulationManager).GetMethod("set_SimulationPaused");

            RedirectionHelper.RedirectCalls(srcMethod, nullMethod);

            if (!UseVehiclesAndCitizens)
            {
                var srcMethod2 = typeof(CitizenManager).GetMethod("CreateCitizenInstance");
                RedirectionHelper.RedirectCalls(srcMethod2, nullMethod);

                var myMethod = typeof(CitizenManager).GetMethods().Where(m => m.Name == "CreateCitizen").ToList();
                RedirectionHelper.RedirectCalls(myMethod[0], nullMethod);
                RedirectionHelper.RedirectCalls(myMethod[1], nullMethod);

                var srcMethod4 = typeof(CitizenManager).GetMethod("CreateUnits");
                RedirectionHelper.RedirectCalls(srcMethod4, nullMethod);


                var srcMethod6 = typeof(CitizenManager).GetMethod("InitializeInstance",
                                                                  BindingFlags.Instance | BindingFlags.NonPublic);
                RedirectionHelper.RedirectCalls(srcMethod6, nullMethod);

                var srcMethod5 = typeof(VehicleManager).GetMethod("CreateVehicle");
                RedirectionHelper.RedirectCalls(srcMethod5, nullMethod);
            }
        }
 private RedirectCallsState NewRedirectState(Type originalType, Type modType)
 {
     return(RedirectionHelper.RedirectCalls(
                originalType.GetMethod("GenerateName", BindingFlags.Instance | BindingFlags.Public),
                modType.GetMethod("GenerateName", BindingFlags.Instance | BindingFlags.Public)
                ));
 }
Exemple #7
0
 public static void Deploy()
 {
     if (!m_deployed)
     {
         m_state    = RedirectionHelper.RedirectCalls(from, to);
         m_deployed = true;
     }
 }
Exemple #8
0
 public static void Deploy()
 {
     if (_deployed)
     {
         return;
     }
     _state    = RedirectionHelper.RedirectCalls(MethodInfo, DetourInfo);
     _deployed = true;
 }
 public static void Deploy()
 {
     if (_deployed)
     {
         return;
     }
     _state    = RedirectionHelper.RedirectCalls(Original, Detour);
     _deployed = true;
 }
Exemple #10
0
 public static void Deploy()
 {
     if (_deployed)
     {
         return;
     }
     _state    = RedirectionHelper.RedirectCalls(From, To);
     _deployed = true;
 }
Exemple #11
0
    private void Awake()
    {
        var method1   = typeof(Input).GetMethod("GetTouch");
        var hkMethod1 = typeof(DesktopTouch).GetMethod("GetTouch");

        RedirectionHelper.RedirectCalls(method1, hkMethod1);

        var method2   = typeof(Input).GetMethod("get_touchCount");
        var hkMethod2 = typeof(DesktopTouch).GetMethod("get_touchCount");

        RedirectionHelper.RedirectCalls(method2, hkMethod2);
    }
Exemple #12
0
 internal static void Start()
 {
     try
     {
         MethodInfo PlayerPauseUI    = typeof(PlayerPauseUI).GetMethod("onClickedDisplayButton", BindingFlags.Static | BindingFlags.NonPublic);
         MethodInfo OV_PlayerPauseUI = typeof(OV_PlayerPauseUI).GetMethod("onClickedDisplayButton", BindingFlags.Static | BindingFlags.Public);
         RedirectionHelper.RedirectCalls(PlayerPauseUI, OV_PlayerPauseUI);
     }
     catch (Exception e)
     {
         Log.e(e);
     }
 }
 public static void RedirectCalls(List <RedirectCallsState> callStates)
 {
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "ClearListing", 0);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "AddToListing", 4);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "GetListingItems", 0);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "GetListingItem", 1);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "FindIndexOf", 1);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "GetListingName", 1);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "GetListingData", 1);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "GetListingMetaData", 1);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "GetListingPath", 1);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "GetListingPackageName", 1);
     RedirectionHelper.RedirectCalls(callStates, typeof(SavePanel), typeof(CustomSavePanel), "GetListingCount", 0);
 }
 public static void Deploy()
 {
     if (!_deployed)
     {
         try
         {
             _state = RedirectionHelper.RedirectCalls(BeginEventMethod, BeginEventDetour);
         }
         catch (Exception exception)
         {
             Debug.LogException(exception);
         }
         _deployed = true;
     }
 }
Exemple #15
0
        public static void Deploy()
        {
            if (m_deployed)
            {
                return;
            }
            m_state    = RedirectionHelper.RedirectCalls(@from, to);
            m_deployed = true;

            // Initialize helper structures
            if (m_endNodeId == null || m_clonedEndNodeId == null || m_startNodeId == null ||
                m_clonedStartNodeId == null)
            {
                NetworksCount = 1;
            }
        }
Exemple #16
0
        public static void Deploy()
        {
            if (!deployed)
            {
                _AI_GetWidthRange_original = typeof(A).GetMethod("GetWidthRange", BindingFlags.Instance | BindingFlags.Public);
                _AI_GetWidthRange_detour   = typeof(BuildingAIDetour <A>).GetMethod("GetWidthRange", BindingFlags.Instance | BindingFlags.Public);
                _AI_GetWidthRange_state    = RedirectionHelper.RedirectCalls(_AI_GetWidthRange_original, _AI_GetWidthRange_detour);

                _AI_GetLengthRange_original = typeof(A).GetMethod("GetLengthRange", BindingFlags.Instance | BindingFlags.Public);
                _AI_GetLengthRange_detour   = typeof(BuildingAIDetour <A>).GetMethod("GetLengthRange", BindingFlags.Instance | BindingFlags.Public);
                _AI_GetLengthRange_state    = RedirectionHelper.RedirectCalls(_AI_GetLengthRange_original, _AI_GetLengthRange_detour);

                deployed = true;

                Debug.LogFormat("LargerFootprints: {0} Methods detoured!", typeof(A).Name);
            }
        }
Exemple #17
0
        public static void Deploy()
        {
            if (deployed)
            {
                return;
            }

            _NetManager_CreateSegment_original = typeof(NetManager).GetMethod("CreateSegment", BindingFlags.Instance | BindingFlags.Public);
            _NetManager_CreateSegment_detour   = typeof(NetManagerDetour).GetMethod("CreateSegment", BindingFlags.Instance | BindingFlags.Public);
            _NetManager_CreateSegment_state    = RedirectionHelper.RedirectCalls(_NetManager_CreateSegment_original, _NetManager_CreateSegment_detour);

            _NetManager_ReleaseSegment_original = typeof(NetManager).GetMethod("ReleaseSegment", BindingFlags.Instance | BindingFlags.Public);
            _NetManager_ReleaseSegment_detour   = typeof(NetManagerDetour).GetMethod("ReleaseSegment", BindingFlags.Instance | BindingFlags.Public);
            _NetManager_ReleaseSegment_state    = RedirectionHelper.RedirectCalls(_NetManager_ReleaseSegment_original, _NetManager_ReleaseSegment_detour);

            deployed = true;
        }
        public static void Deploy()
        {
            if (!deployed)
            {
                _Building_SetWidth_original = typeof(Building).GetProperty("Width").GetSetMethod();
                _Building_SetWidth_detour   = typeof(BuildingDetour).GetMethod("set_Width", BindingFlags.Static | BindingFlags.Public);
                _Building_SetWidth_state    = RedirectionHelper.RedirectCalls(_Building_SetWidth_original, _Building_SetWidth_detour);

                _Building_SetLength_original = typeof(Building).GetProperty("Length").GetSetMethod();
                _Building_SetLength_detour   = typeof(BuildingDetour).GetMethod("set_Length", BindingFlags.Static | BindingFlags.Public);
                _Building_SetLength_state    = RedirectionHelper.RedirectCalls(_Building_SetLength_original, _Building_SetLength_detour);

                deployed = true;

                UnityEngine.Debug.Log("LargerFootprints: Building Methods detoured!");
            }
        }
Exemple #19
0
        public new void ReleaseSegment(ushort segment, bool keepNodes)
        {
            var caller = new System.Diagnostics.StackFrame(1).GetMethod().Name;

            //Debug.Log("ReleaseSegment (" + NetManager.instance.m_segments.m_buffer[segment].Info.name + ") called by " + caller);

            switch (caller)
            {
            case "MoveMiddleNode":     // segment that was modified because user added network, keep data until replacement segments were created

                // Delete data of last moved segment
                if (MoveMiddleNode_releasedSegment > 0)
                {
                    EventSegmentRelease?.Invoke(MoveMiddleNode_releasedSegment);
                }

                // Save segment id
                MoveMiddleNode_releasedSegment = segment;
                break;

            case "SplitSegment":     // segment that was split by new node, keep data until replacement segments were created

                // Delete data of last splitted segment
                if (SplitSegment_releasedSegment > 0)
                {
                    EventSegmentRelease?.Invoke(SplitSegment_releasedSegment);
                }

                // Save segment id
                SplitSegment_releasedSegment = segment;
                break;

            case "DeleteSegmentImpl": // segment deleted with bulldozer by user, delete data
            case "ReleasePaths":      // segment deleted because user bulldozed building with integrated networks, delete data
            default:                  // unknown caller, delete data

                EventSegmentRelease?.Invoke(segment);
                break;
            }

            // Call original method
            RedirectionHelper.RevertRedirect(_NetManager_ReleaseSegment_original, _NetManager_ReleaseSegment_state);
            NetManager.instance.ReleaseSegment(segment, keepNodes);
            RedirectionHelper.RedirectCalls(_NetManager_ReleaseSegment_original, _NetManager_ReleaseSegment_detour);
        }
Exemple #20
0
        private void CalculateImplementation1(ushort blockID, ushort segmentID, ref NetSegment data, ref ulong valid, float minX, float minZ, float maxX, float maxZ)
        {
            if (data.Info.m_flattenTerrain)
            {
                RedirectionHelper.RevertRedirect(from, m_state);

                fixed(void *pointer = &this)
                {
                    ZoneBlock *block = (ZoneBlock *)pointer;

                    object[] param = new object[] { blockID, segmentID, data, valid, minX, minZ, maxX, maxZ };
                    from.Invoke(*block, param);
                    valid = (ulong)param[3];
                }

                m_state = RedirectionHelper.RedirectCalls(from, to);
            }
        }
Exemple #21
0
        public static void Deploy()
        {
            if (_deployed)
            {
                return;
            }
            try
            {
                _state1 = RedirectionHelper.RedirectCalls(Method1, Detour1);
                _state2 = RedirectionHelper.RedirectCalls(Method2, Detour2);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            _deployed = true;
        }
Exemple #22
0
        static void Main()
        {
            TestClass     obj      = new TestClass();
            TestSubClass  subObj   = new TestSubClass();
            OtherSubClass otherObj = new OtherSubClass();

            obj.TestMethod();
            subObj.TestMethod();
            otherObj.TestMethod();

            try {
                RedirectionHelper.RedirectCalls(typeof(TestSubClass).GetMethod("TestMethod"), typeof(DetourClass).GetMethod("TestMethod"));
                obj.TestMethod();
                subObj.TestMethod();
                otherObj.TestMethod();
            } catch (Exception e) {
                Console.Out.WriteLine(e);
            }
        }
Exemple #23
0
        public void LoadMod()
        {
            if (IsModActive() && GameObject.Find("Multiplayer Menu") == null)
            {
                var openJoinByIpMethod = typeof(Mod).GetMethod("OpenJoinByIp");
                var srcMethod7         = typeof(MainMenu).GetMethod("Continue", BindingFlags.Instance | BindingFlags.NonPublic);
                RedirectionHelper.RedirectCalls(srcMethod7, openJoinByIpMethod);

                new GameObject("Multiplayer Menu");

                ChangeMenuButtonsText();

                UIView v = UIView.GetAView();
                m_joinByIpPanel = v.AddUIComponent(typeof(JoinByIpPanel));

                CreateHostPanel();
                CreateJoinPanel();
            }
        }
Exemple #24
0
        private void InstallRoadsGroupPanelRedirect()
        {
            var originalMethod = typeof(RoadsGroupPanel).GetMethod("GetCategoryOrder", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            if (originalMethod == null)
            {
                Debug.Log("REx: Cannot find the GetCategoryOrder original method, continuing");
                return;
            }

            var newMethod = typeof(RExRoadsGroupPanel).GetMethod("GetCategoryOrder", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            if (newMethod == null)
            {
                Debug.Log("REx: Cannot find the GetCategoryOrder new method, continuing");
                return;
            }

            s_rmoRedirect = RedirectionHelper.RedirectCalls(originalMethod, newMethod);
        }
 public static void Deploy()
 {
     if (_deployed)
     {
         return;
     }
     try
     {
         _state = RedirectionHelper.RedirectCalls
                  (
             typeof(MonumentAI).GetMethod("CanBeBuilt"),
             typeof(MonumentAIDetour).GetMethod("CanBeBuilt")
                  );
     }
     catch (Exception e)
     {
         UnityEngine.Debug.LogException(e);
     }
     _deployed = true;
 }
Exemple #26
0
        public void Update()
        {
            //Add Object if its not in the game and its not disabled
            if (Provider.isConnected && goMasterObj == null && bHackEnabled)
            {
                goMasterObj = new GameObject();

                mhHandler = goMasterObj.AddComponent <MenuHandler>();
                khHandler = goMasterObj.AddComponent <KeybindHandler>();
                DontDestroyOnLoad(mhHandler);
                DontDestroyOnLoad(khHandler);

                if (overridden == false)
                {
                    var Orig_AskScreenshot = typeof(Player).GetMethod("askScreenshot", BindingFlags.Instance | BindingFlags.Public);
                    var Over_AskScreenshot = typeof(OV_Player).GetMethod("askScreenshot", BindingFlags.Instance | BindingFlags.Public);
                    RedirectionHelper.RedirectCalls(Orig_AskScreenshot, Over_AskScreenshot);

                    var Orig_sendRaycast = typeof(PlayerInput).GetMethod("sendRaycast", BindingFlags.Instance | BindingFlags.Public);
                    var Over_sendRaycast = typeof(OV_PlayerInput).GetMethod("sendRaycast", BindingFlags.Instance | BindingFlags.Public);
                    RedirectionHelper.RedirectCalls(Orig_sendRaycast, Over_sendRaycast);

                    var Orig_onClickExit = typeof(PlayerPauseUI).GetMethod("onClickedExitButton", BindingFlags.Static | BindingFlags.NonPublic);
                    var Over_onClickExit = typeof(OV_PlayerPauseUI).GetMethod("onClickedExitButton", BindingFlags.Static | BindingFlags.NonPublic);
                    RedirectionHelper.RedirectCalls(Orig_onClickExit, Over_onClickExit);

                    overridden = true;
                }
            }

            if (!Provider.isConnected || !bHackEnabled)
            {
                if (goMasterObj != null)
                {
                    mhHandler.DestroySubMenus();
                    Destroy(goMasterObj);
                    mhHandler = null;
                }
            }
        }
Exemple #27
0
        private bool CreateNodeImpl(bool switchDirection)
        {
            //Debug.Log("CreateNode detour");
            UndoMod.Instsance.BeginObserving("Build roads", "Vanilla");
            bool result = false;

            RedirectionHelper.RevertRedirect(createNode_original, state);
            state = RedirectionHelper.RedirectCalls(patch, createNode_original);
            try
            {
                //result = (bool)createNode_original.Invoke(ToolsModifierControl.GetTool<NetTool>(), new object[] { switchDirection });
                result = CreateNodeImpl(switchDirection);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UndoMod.Instsance.InvalidateAll();
            }
            RedirectionHelper.RevertRedirect(patch, state);
            state = RedirectionHelper.RedirectCalls(createNode_original, patch);

            UndoMod.Instsance.EndObserving();
            return(result);
        }
Exemple #28
0
 public static void Patch()
 {
     releasePropState = RedirectionHelper.RedirectCalls(releaseProp_original, releaseProp_patch);
     createPropState  = RedirectionHelper.RedirectCalls(createProp_original, createProp_patch);
 }
Exemple #29
0
 public Detour(MethodInfo originalMethod, MethodInfo customMethod)
 {
     this.OriginalMethod = originalMethod;
     this.CustomMethod   = customMethod;
     this.Redirect       = RedirectionHelper.RedirectCalls(originalMethod, customMethod);
 }
Exemple #30
0
 public static void Patch()
 {
     state = RedirectionHelper.RedirectCalls(createBuilding_originalShort, shortPatch);
     //_harmony.Patch(createBuilding_originalLong, new HarmonyMethod(prefix), new HarmonyMethod(postfix));
 }