Ejemplo n.º 1
0
        private static void RedirectCallsInstance(Type type1, Type type2, string p, bool OursIsPublic = false)
        {
            var bindflags1 = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
            var bindflags2 = BindingFlags.Instance | BindingFlags.NonPublic;

            if (OursIsPublic)
            {
                bindflags2 = BindingFlags.Instance | 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);
        }
 public void CheckDetour()
 {
     if (isFirstTime)
     {
         isFirstTime = false;
         DetourAfterLoad();
         if (true)
         {
             DebugLog.LogToFileOnly("ThreadingExtension.OnBeforeSimulationFrame: First frame detected. Checking detours.");
             List <string> list = new List <string>();
             foreach (Loader.Detour current in Loader.Detours)
             {
                 if (!RedirectionHelper.IsRedirected(current.OriginalMethod, current.CustomMethod))
                 {
                     list.Add(string.Format("{0}.{1} with {2} parameters ({3})", new object[]
                     {
                         current.OriginalMethod.DeclaringType.Name,
                         current.OriginalMethod.Name,
                         current.OriginalMethod.GetParameters().Length,
                         current.OriginalMethod.DeclaringType.AssemblyQualifiedName
                     }));
                 }
             }
             DebugLog.LogToFileOnly(string.Format("ThreadingExtension.OnBeforeSimulationFrame: First frame detected. Detours checked. Result: {0} missing detours", list.Count));
             if (list.Count > 0)
             {
                 string error = "AdvancedJunctionRuleThreading detected an incompatibility with another mod! You can continue playing but it's NOT recommended. AdvancedJunctionRuleThreading will not work as expected. Send AdvancedJunctionRuleThreading.txt to Author.";
                 DebugLog.LogToFileOnly(error);
                 string text = "The following methods were overriden by another mod:";
                 foreach (string current2 in list)
                 {
                     text += string.Format("\n\t{0}", current2);
                 }
                 DebugLog.LogToFileOnly(text);
                 UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", text, true);
             }
         }
     }
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public void Unswap()
 {
     RedirectionHelper.RevertRedirect(patch, state);
     Patch();
 }
Ejemplo n.º 5
0
 public void Swap()
 {
     Unpatch();
     state = RedirectionHelper.RedirectCalls(patch, original);
 }
Ejemplo n.º 6
0
 public void Unpatch()
 {
     RedirectionHelper.RevertRedirect(original, state);
 }
Ejemplo n.º 7
0
        public static void OverrideMethod(Type defaultClass, Type overrideClass, string method, BindingFlags bindingflag, BindingFlags bindingflag1)
        {
            string overriddenmethod = "OV_" + method;

            RedirectionHelper.RedirectCalls(defaultClass.GetMethod(method, bindingflag | bindingflag1), overrideClass.GetMethod(overriddenmethod, BindingFlags.Static | BindingFlags.Public));
        }
Ejemplo n.º 8
0
 public static void Patch()
 {
     releasePropState = RedirectionHelper.RedirectCalls(releaseProp_original, releaseProp_patch);
     createPropState  = RedirectionHelper.RedirectCalls(createProp_original, createProp_patch);
 }
Ejemplo n.º 9
0
 public static void Unpatch()
 {
     RedirectionHelper.RevertRedirect(createBuilding_originalShort, state);
     //_harmony.Unpatch(createBuilding_originalLong, prefix);
     //_harmony.Unpatch(createBuilding_originalLong, postfix);
 }
Ejemplo n.º 10
0
        public void Update(bool straightSlope)
        {
            if (m_prefab == null)
            {
                return;
            }

            Restore(!straightSlope);

            if (straightSlope && !m_detoured)
            {
                List <MethodInfo> methods = new List <MethodInfo>(m_redirections.Keys);
                foreach (MethodInfo from in methods)
                {
                    m_redirections[from] = RedirectionHelper.RedirectCalls(from, m_LinearMiddleHeight);
                }

                m_detoured = true;
            }

            NetSkins_Support.ForceUpdate();

            if (!hasElevation)
            {
                return;
            }

            switch (m_mode)
            {
            case Mode.Ground:
                if (m_prefab.m_flattenTerrain)
                {
                    m_roadAI.elevated = m_prefab;
                    m_roadAI.bridge   = null;
                    m_roadAI.slope    = null;
                    m_roadAI.tunnel   = m_prefab;
                }
                break;

            case Mode.Elevated:
                if (m_elevated != null)
                {
                    m_roadAI.info     = m_elevated;
                    m_roadAI.elevated = m_elevated;
                    m_roadAI.bridge   = null;
                }
                break;

            case Mode.Bridge:
                if (m_bridge != null)
                {
                    m_roadAI.info     = m_bridge;
                    m_roadAI.elevated = m_bridge;
                }
                break;

            case Mode.Tunnel:
                if (m_tunnel != null && m_slope != null)
                {
                    m_roadAI.info     = m_tunnel;
                    m_roadAI.elevated = m_tunnel;
                    m_roadAI.bridge   = null;
                    m_roadAI.slope    = m_tunnel;
                }
                break;

            case Mode.Single:
                m_roadAI.elevated = null;
                m_roadAI.bridge   = null;
                m_roadAI.slope    = null;
                m_roadAI.tunnel   = null;
                break;
            }
        }
Ejemplo n.º 11
0
 protected RedirectResult RedirectToAction <T>(Expression <Action <T> > action, RouteValueDictionary values = null) where T : Controller
 {
     return(new RedirectResult(RedirectionHelper.GetUrl(action, Request.RequestContext, values)));
 }
Ejemplo n.º 12
0
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            base.OnUpdate(realTimeDelta, simulationTimeDelta);

            if (LoadingExtension.Instance == null)
            {
                return;
            }

            if (!LoadingExtension.roadManagerInitialized && SerializableDataExtension.configLoaded)
            {
                CSL_Traffic.RoadManager.Initialize();
                LoadingExtension.roadManagerInitialized = true;
            }

            /*
             *          if (LoadingExtension.Instance.ToolMode != TrafficManagerMode.None && ToolsModifierControl.toolController.CurrentTool != LoadingExtension.Instance.TrafficLightTool)
             *          {
             *                  LoadingExtension.Instance.UI.HideTMPanel();
             *          }
             */
            if (LoadingExtension.Instance.ToolMode != TrafficManagerMode.None &&
                ToolsModifierControl.toolController.CurrentTool != LoadingExtension.Instance.TrafficLightTool &&
                ToolsModifierControl.toolController.CurrentTool != LoadingExtension.Instance.RoadCustomizerTool &&
                LoadingExtension.Instance.UI.isVisible())
            {
                LoadingExtension.Instance.UI.HideTMPanel();
            }

            if (!LoadingExtension.Instance.detourInited)
            {
                LoadingExtension.Instance.revertMethods[0] = RedirectionHelper.RedirectCalls(
                    typeof(CarAI).GetMethod("CalculateSegmentPosition",
                                            BindingFlags.NonPublic | BindingFlags.Instance,
                                            null,
                                            new Type[] {
                    typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(PathUnit.Position),
                    typeof(PathUnit.Position), typeof(uint), typeof(byte), typeof(PathUnit.Position),
                    typeof(uint), typeof(byte), typeof(int), typeof(Vector3).MakeByRefType(),
                    typeof(Vector3).MakeByRefType(), typeof(float).MakeByRefType()
                },
                                            null),
                    typeof(CustomCarAI).GetMethod("CalculateSegmentPosition", BindingFlags.NonPublic | BindingFlags.Instance,
                                                  null,
                                                  new Type[] {
                    typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(PathUnit.Position),
                    typeof(PathUnit.Position), typeof(uint), typeof(byte), typeof(PathUnit.Position),
                    typeof(uint), typeof(byte), typeof(int), typeof(Vector3).MakeByRefType(),
                    typeof(Vector3).MakeByRefType(), typeof(float).MakeByRefType()
                },
                                                  null));

                LoadingExtension.Instance.revertMethods[1] = RedirectionHelper.RedirectCalls(
                    typeof(RoadBaseAI).GetMethod("SimulationStep",
                                                 new Type[] { typeof(ushort), typeof(NetNode).MakeByRefType() }),
                    typeof(CustomRoadAI).GetMethod("SimulationStep", new Type[] {
                    typeof(ushort),
                    typeof(NetNode).MakeByRefType()
                }));

                LoadingExtension.Instance.revertMethods[2] = RedirectionHelper.RedirectCalls(typeof(HumanAI).GetMethod("CheckTrafficLights",
                                                                                                                       BindingFlags.NonPublic | BindingFlags.Instance,
                                                                                                                       null,
                                                                                                                       new Type[] { typeof(ushort), typeof(ushort) },
                                                                                                                       null),
                                                                                             typeof(CustomHumanAI).GetMethod("CheckTrafficLights"));

                LoadingExtension.Instance.detourInited = true;
            }

            if (!LoadingExtension.Instance.nodeSimulationLoaded)
            {
                LoadingExtension.Instance.nodeSimulationLoaded = true;
                ToolsModifierControl.toolController.gameObject.AddComponent <CustomRoadAI>();
            }

            /*
             *          if (Input.GetKeyDown(KeyCode.Escape))
             *          {
             *                  LoadingExtension.Instance.UI.HideTMPanel();
             *          }
             */

            /*
             * if (Event.current.alt && Input.GetKeyDown(KeyCode.D)) {
             *  var info = new RoadInfo();
             *  var netManager = Singleton<NetManager>.instance;
             *  Debug.Log("dumping road info for " + netManager.m_nodes.m_size + " nodes out of " + NetManager.MAX_NODE_COUNT);
             *  var nodeCount = 0;
             *  for (uint i = 0; i < netManager.m_nodes.m_size; i++) {
             *      var node = netManager.m_nodes.m_buffer[i];
             *      if (node.m_flags != 0 && node.Info.m_class.m_service == ItemClass.Service.Road) {
             *          var nodeInfo = new RoadInfo.Node();
             *          nodeInfo.id = i;
             *          nodeInfo.buildIndex = node.m_buildIndex;
             *          nodeInfo.segments[0] = node.m_segment0;
             *          nodeInfo.segments[1] = node.m_segment1;
             *          nodeInfo.segments[2] = node.m_segment2;
             *          nodeInfo.segments[3] = node.m_segment3;
             *          nodeInfo.segments[4] = node.m_segment4;
             *          nodeInfo.segments[5] = node.m_segment5;
             *          nodeInfo.segments[6] = node.m_segment6;
             *          nodeInfo.segments[7] = node.m_segment7;
             *          info.nodes.Add(nodeInfo);
             *          nodeCount++;
             *      }
             *  }
             *  Debug.Log("found " + nodeCount + " nodes");
             *  RoadInfo.DumpRoadInfo(info);
             * }
             */
        }
Ejemplo n.º 13
0
 public static void Unpatch()
 {
     RedirectionHelper.RevertRedirect(createNode_original, state);
 }
Ejemplo n.º 14
0
        /*private static MethodInfo createNode_prefix = typeof(NetToolPatch).GetMethod("CreateNode_prefix", BindingFlags.NonPublic);
         * private static MethodInfo createNode_postfix = typeof(NetToolPatch).GetMethod("CreateNode_postfix", BindingFlags.NonPublic);
         * private static MethodInfo createNode_patch = typeof(NetToolPatch).GetMethod("CreateNode_postfix", BindingFlags.NonPublic);
         *
         * public static void Patch(HarmonyInstance _harmony)
         * {
         *  _harmony.Patch(createNode_original, new HarmonyMethod(createNode_prefix), new HarmonyMethod(createNode_postfix));
         * }
         *
         * public static void Unpatch(HarmonyInstance _harmony)
         * {
         *  _harmony.Unpatch(createNode_original, createNode_prefix);
         *  _harmony.Unpatch(createNode_original, createNode_postfix);
         * }*/

        public static void Patch()
        {
            state = RedirectionHelper.RedirectCalls(createNode_original, patch);
        }
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            base.OnUpdate(realTimeDelta, simulationTimeDelta);

            if (LoadingExtension.Instance == null)
            {
                return;
            }

            if (!LoadingExtension.roadManagerInitialized && SerializableDataExtension.configLoaded)
            {
                CSL_Traffic.RoadManager.Initialize();
                LoadingExtension.roadManagerInitialized = true;
            }

            /*
             *          if (LoadingExtension.Instance.ToolMode != TrafficManagerMode.None && ToolsModifierControl.toolController.CurrentTool != LoadingExtension.Instance.TrafficLightTool)
             *          {
             *                  LoadingExtension.Instance.UI.HideTMPanel();
             *          }
             */
            if (LoadingExtension.Instance.ToolMode != TrafficManagerMode.None &&
                ToolsModifierControl.toolController.CurrentTool != LoadingExtension.Instance.TrafficLightTool &&
                ToolsModifierControl.toolController.CurrentTool != LoadingExtension.Instance.RoadCustomizerTool &&
                LoadingExtension.Instance.UI.isVisible())
            {
                LoadingExtension.Instance.UI.HideTMPanel();
            }

            if (!LoadingExtension.Instance.detourInited)
            {
                LoadingExtension.Instance.revertMethods[0] = RedirectionHelper.RedirectCalls(
                    typeof(CarAI).GetMethod("CalculateSegmentPosition",
                                            BindingFlags.NonPublic | BindingFlags.Instance,
                                            null,
                                            new Type[] {
                    typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(PathUnit.Position),
                    typeof(PathUnit.Position), typeof(uint), typeof(byte), typeof(PathUnit.Position),
                    typeof(uint), typeof(byte), typeof(Vector3).MakeByRefType(),
                    typeof(Vector3).MakeByRefType(), typeof(float).MakeByRefType()
                },
                                            null),
                    typeof(CustomCarAI).GetMethod("CalculateSegmentPosition", BindingFlags.NonPublic | BindingFlags.Instance,
                                                  null,
                                                  new Type[] {
                    typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(PathUnit.Position),
                    typeof(PathUnit.Position), typeof(uint), typeof(byte), typeof(PathUnit.Position),
                    typeof(uint), typeof(byte), typeof(Vector3).MakeByRefType(),
                    typeof(Vector3).MakeByRefType(), typeof(float).MakeByRefType()
                },
                                                  null));

                LoadingExtension.Instance.revertMethods[1] = RedirectionHelper.RedirectCalls(
                    typeof(RoadBaseAI).GetMethod("SimulationStep",
                                                 new Type[] { typeof(ushort), typeof(NetNode).MakeByRefType() }),
                    typeof(CustomRoadAI).GetMethod("SimulationStep", new Type[] {
                    typeof(ushort),
                    typeof(NetNode).MakeByRefType()
                }));

                LoadingExtension.Instance.revertMethods[2] = RedirectionHelper.RedirectCalls(typeof(HumanAI).GetMethod("CheckTrafficLights",
                                                                                                                       BindingFlags.NonPublic | BindingFlags.Instance,
                                                                                                                       null,
                                                                                                                       new Type[] { typeof(ushort), typeof(ushort) },
                                                                                                                       null),
                                                                                             typeof(CustomHumanAI).GetMethod("CheckTrafficLights"));

                LoadingExtension.Instance.detourInited = true;
            }

            if (!LoadingExtension.Instance.nodeSimulationLoaded)
            {
                LoadingExtension.Instance.nodeSimulationLoaded = true;
                ToolsModifierControl.toolController.gameObject.AddComponent <CustomRoadAI>();
            }

            /*
             *          if (Input.GetKeyDown(KeyCode.Escape))
             *          {
             *                  LoadingExtension.Instance.UI.HideTMPanel();
             *          }
             */
        }
Ejemplo n.º 16
0
        public void CheckDetour()
        {
            if (isFirstTime)
            {
                if (Loader.DetourInited && Loader.HarmonyDetourInited)
                {
                    isFirstTime = false;
                    DetourAfterLoad();
                    DebugLog.LogToFileOnly("ThreadingExtension.OnBeforeSimulationFrame: First frame detected. Checking detours.");
                    List <string> list = new List <string>();
                    foreach (Loader.Detour current in Loader.Detours)
                    {
                        if (!RedirectionHelper.IsRedirected(current.OriginalMethod, current.CustomMethod))
                        {
                            list.Add(string.Format("{0}.{1} with {2} parameters ({3})", new object[]
                            {
                                current.OriginalMethod.DeclaringType.Name,
                                current.OriginalMethod.Name,
                                current.OriginalMethod.GetParameters().Length,
                                current.OriginalMethod.DeclaringType.AssemblyQualifiedName
                            }));
                        }
                    }
                    DebugLog.LogToFileOnly(string.Format("ThreadingExtension.OnBeforeSimulationFrame: First frame detected. Detours checked. Result: {0} missing detours", list.Count));
                    if (list.Count > 0)
                    {
                        string error = "CSURToolBox detected an incompatibility with another mod! You can continue playing but it's NOT recommended. CSURToolBox will not work as expected. Send CSURToolBox.txt to Author.";
                        DebugLog.LogToFileOnly(error);
                        string text = "The following methods were overriden by another mod:";
                        foreach (string current2 in list)
                        {
                            text += string.Format("\n\t{0}", current2);
                        }
                        DebugLog.LogToFileOnly(text);
                        UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", text, true);
                    }

                    if (Loader.HarmonyDetourFailed)
                    {
                        string error = "CSURToolBox HarmonyDetourInit is failed, Send CSURToolBox.txt to Author.";
                        DebugLog.LogToFileOnly(error);
                        UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", error, true);
                    }
                    else
                    {
                        var harmony = new Harmony(HarmonyDetours.Id);
                        var methods = harmony.GetPatchedMethods();
                        int i       = 0;
                        foreach (var method in methods)
                        {
                            var info = Harmony.GetPatchInfo(method);
                            if (info.Owners?.Contains(HarmonyDetours.Id) == true)
                            {
                                DebugLog.LogToFileOnly($"Harmony patch method = {method.FullDescription()}");
                                if (info.Prefixes.Count != 0)
                                {
                                    DebugLog.LogToFileOnly("Harmony patch method has PreFix");
                                }
                                if (info.Postfixes.Count != 0)
                                {
                                    DebugLog.LogToFileOnly("Harmony patch method has PostFix");
                                }
                                i++;
                            }
                        }

                        if (i != HarmonyPatchNum)
                        {
                            string error = $"CSURToolBox HarmonyDetour Patch Num is {i}, Right Num is {HarmonyPatchNum} Send CSURToolBox.txt to Author.";
                            DebugLog.LogToFileOnly(error);
                            UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", error, true);
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        private static void InternalOnAuthenticate(HttpContext context)
        {
            Logger.EnterFunction(ExTraceGlobals.CertAuthTracer, "InternalOnAuthenticate");
            HttpRequest request = context.Request;

            Logger.LogVerbose("Request of Authentication for certificate {0}.", new object[]
            {
                request.ClientCertificate.Subject
            });
            int    i      = 0;
            ADUser aduser = null;
            NameValueCollection urlProperties = RedirectionHelper.GetUrlProperties(request.Url);
            string orgName = urlProperties[CertificateAuthenticationModule.OrganizationDomain];

            while (i < CertificateAuthenticationModule.maxRetryForADTransient)
            {
                try
                {
                    aduser = CertificateAuthenticationModule.ResolveCertificateFromCacheOrAD(request.ClientCertificate, orgName);
                    if (aduser != null && !string.IsNullOrEmpty(aduser.UserPrincipalName))
                    {
                        CertificateAuthenticationFaultInjection.FaultInjectionTracer.TraceTest <string>(3745918269U, aduser.UserPrincipalName);
                    }
                    break;
                }
                catch (ADTransientException ex)
                {
                    if (i == 0)
                    {
                        Logger.LogEvent(CertificateAuthenticationModule.eventLogger, TaskEventLogConstants.Tuple_CertAuth_TransientError, null, new object[]
                        {
                            ex,
                            request.ClientCertificate.Subject
                        });
                        HttpLogger.SafeAppendGenericInfo("ResolveCertificateFromCacheOrAD-TransientException", ex.Message);
                    }
                    if (i == CertificateAuthenticationModule.maxRetryForADTransient - 1)
                    {
                        HttpLogger.SafeAppendGenericError("ResolveCertificateFromCacheOrAD", ex, new Func <Exception, bool>(KnownException.IsUnhandledException));
                    }
                    Logger.LogError(string.Format("AD Transient Error when processing certificate authentication {0}.", request.ClientCertificate.Subject), ex);
                }
                catch (Exception ex2)
                {
                    HttpLogger.SafeAppendGenericError("CertAuthNModule.InternalOnAuthenticate", ex2, new Func <Exception, bool>(KnownException.IsUnhandledException));
                    Logger.LogEvent(CertificateAuthenticationModule.eventLogger, TaskEventLogConstants.Tuple_CertAuth_ServerError, null, new object[]
                    {
                        ex2,
                        request.ClientCertificate.Subject
                    });
                    Logger.LogError(string.Format("Unknown error when processing certificate authentication {0}.", request.ClientCertificate.Subject), ex2);
                    if (GrayException.IsGrayException(ex2))
                    {
                        ExWatson.SendReport(ex2, ReportOptions.DoNotCollectDumps, null);
                    }
                    CertificateAuthenticationModule.ReportCustomError(context.Response, HttpStatusCode.InternalServerError, 200, Strings.UnknownInternalError(request.ClientCertificate.Subject));
                }
                i++;
            }
            if (i > 0)
            {
                HttpLogger.SafeAppendGenericInfo("ResolveCertificateFromCacheOrAD-Retry", i.ToString());
            }
            if (i >= CertificateAuthenticationModule.maxRetryForADTransient)
            {
                CertificateAuthenticationModule.ReportCustomError(context.Response, HttpStatusCode.InternalServerError, 201, Strings.ADTransientError(request.ClientCertificate.Subject));
            }
            else if (aduser == null)
            {
                HttpLogger.SafeAppendGenericError("ResolveCertificateFromCacheOrAD-ResolvedUser", "null", false);
                if (request.Headers["Authorization"] == "http://schemas.dmtf.org/wbem/wsman/1/wsman/secprofile/https/mutual")
                {
                    CertificateAuthenticationModule.ReportCustomError(context.Response, HttpStatusCode.BadRequest, 102, Strings.UserNotFound(request.ClientCertificate.Subject));
                }
            }
            else
            {
                Logger.LogVerbose("User correctly authenticated and linked to Certificate {0}.", new object[]
                {
                    request.ClientCertificate.Subject
                });
                if (i > 0)
                {
                    Logger.LogEvent(CertificateAuthenticationModule.eventLogger, TaskEventLogConstants.Tuple_CertAuth_TransientRecovery, null, new object[]
                    {
                        request.ClientCertificate.Subject,
                        i
                    });
                }
                X509Identifier certId = CertificateAuthenticationModule.CreateCertificateIdentity(request.ClientCertificate);
                CertificateAuthenticationModule.SetAuthenticatedInfo(context, aduser, certId);
            }
            Logger.ExitFunction(ExTraceGlobals.CertAuthTracer, "InternalOnAuthenticate");
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Sets up our redirects of our replacement methods.
        /// </summary>
        public static void SetupTM()
        {
            if (Mod.IsTMDetoured)
            {
                return;
            }

            try
            {
                //do private ones
                if (Mod.DEBUG_LOG_LEVEL > 1)
                {
                    Helper.dbgLog("Doing private TelemetryManager calls.");
                }
                MethodInfo[] methods = typeof(TelemetryManagerKH).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.NonPublic);
                for (int i = 0; i < (int)methods.Length; i++)
                {
                    MethodInfo methodInfo = methods[i];
                    RedirectCalls(typeof(TelemetryManager), typeof(TelemetryManagerKH), methodInfo.Name);
                }
                //do public ones
                if (Mod.DEBUG_LOG_LEVEL > 1)
                {
                    Helper.dbgLog("Doing public TelemetryManager calls.");
                }
                methods = typeof(TelemetryManagerKH).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public);
                if (Mod.DEBUG_LOG_LEVEL > 1)
                {
                    Helper.dbgLog("TelemetryManagerKH method count: " + methods.Length.ToString());
                }
                MethodInfo m1 = null;
                MethodInfo m2 = null;
                MethodInfo m3 = null;
                MethodInfo m4 = null;
                for (int i = 0; i < (int)methods.Length; i++)
                {
                    MethodInfo methodInfo = methods[i];
                    if (methodInfo.Name.Contains("OnFeedClick"))
                    {
                        if (Mod.DEBUG_LOG_LEVEL > 1)
                        {
                            Helper.dbgLog("Found OnFeedClick in TelemetryManagerKH");
                        }
                        ParameterInfo[] p = methodInfo.GetParameters();
                        if (p.Count() == 1)
                        {
                            if (Mod.DEBUG_LOG_LEVEL > 1)
                            {
                                Helper.dbgLog("ParamName == " + p[0].Name.ToString());
                            }
                            if (Mod.DEBUG_LOG_LEVEL > 1)
                            {
                                Helper.dbgLog("ParamType == " + p[0].ParameterType.ToString());
                            }
                            if (p[0].Name.Contains("url"))
                            {
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("found method 2");
                                }
                                m2 = methodInfo;
                            }
                            if (p[0].Name.Contains("steamAppID"))
                            {
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("found method 4");
                                }
                                m4 = methodInfo;
                            }
                        }
                        MethodInfo[] methods2 = typeof(TelemetryManager).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
                        for (int j = 0; j < (int)methods2.Length; j++)
                        {
                            if (m1 != null & m3 != null)
                            {
                                break;
                            }
                            MethodInfo methodInfo2 = methods2[j];
                            if (methodInfo2.Name.Contains("OnFeedClick"))
                            {
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("Found OnFeedClick in TelemetryManager");
                                }
                                p = methodInfo2.GetParameters();
                                if (p.Count() == 1)
                                {
                                    if (Mod.DEBUG_LOG_LEVEL > 1)
                                    {
                                        Helper.dbgLog("ParamName == " + p[0].Name.ToString());
                                    }
                                    if (Mod.DEBUG_LOG_LEVEL > 1)
                                    {
                                        Helper.dbgLog("ParamType == " + p[0].ParameterType.ToString());
                                    }
                                    if (p[0].Name.Contains("url"))
                                    {
                                        if (Mod.DEBUG_LOG_LEVEL > 1)
                                        {
                                            Helper.dbgLog("found method 1");
                                        }
                                        m1 = methodInfo2;
                                    }
                                    if (p[0].Name.Contains("steamAppID"))
                                    {
                                        if (Mod.DEBUG_LOG_LEVEL > 1)
                                        {
                                            Helper.dbgLog("found method 3");
                                        }
                                        m3 = methodInfo2;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!methodInfo.Name.Contains("TelemetryManagerKH"))
                        {
                            //normal for all but overloads.
                            RedirectCalls(typeof(TelemetryManager), typeof(TelemetryManagerKH), methodInfo.Name, true, true);
                        }
                    }
                }

                if (m1 != null & m2 != null)
                {
                    if (Mod.DEBUG_LOG_LEVEL > 1)
                    {
                        Helper.dbgLog("Doing manual OnFeedClick 1 and 2");
                    }
                    redirectDic.Add(m1, RedirectionHelper.RedirectCalls(m1, m2, false));
                }
                if (m3 != null & m4 != null)
                {
                    if (Mod.DEBUG_LOG_LEVEL > 1)
                    {
                        Helper.dbgLog("Doing manual OnFeedClick 3 and 4");
                    }
                    redirectDic.Add(m3, RedirectionHelper.RedirectCalls(m3, m4, false));
                }

                Mod.IsTMDetoured = true;
                if (Mod.DEBUG_LOG_ON)
                {
                    Helper.dbgLog("Redirected TelemetryManager calls.");
                }
            }
            catch (Exception exception1)
            {
                Helper.dbgLog("SetupTM error:", exception1, true);
            }
        }
Ejemplo n.º 19
0
 public static void Patch()
 {
     state = RedirectionHelper.RedirectCalls(createBuilding_originalShort, shortPatch);
     //_harmony.Patch(createBuilding_originalLong, new HarmonyMethod(prefix), new HarmonyMethod(postfix));
 }
Ejemplo n.º 20
0
        public static void SetupPush()
        {
            try
            {
                if (!Mod.IsPushDetoured)
                {
                    RedirectCallsInstance(typeof(Telemetry), typeof(TelemetryKH), "Push", true);
                    RedirectCallsInstance(typeof(Telemetry), typeof(TelemetryKH), "Clear", true);
                    RedirectCallsInstance(typeof(Telemetry), typeof(TelemetryKH), "IsStandardTelemetry");
                    MethodInfo[] methods = typeof(TelemetryKH).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
                    MethodInfo   m1      = null;
                    MethodInfo   m2      = null;
                    MethodInfo   m3      = null;
                    MethodInfo   m4      = null;
                    for (int i = 0; i < (int)methods.Length; i++)
                    {
                        MethodInfo methodInfo = methods[i];
                        if (methodInfo.Name.Contains("AddEvent"))
                        {
                            if (Mod.DEBUG_LOG_LEVEL > 1)
                            {
                                Helper.dbgLog("Found AddEvent in TelemetryKH");
                            }
                            ParameterInfo[] p = methodInfo.GetParameters();
                            if (p.Count() == 2)
                            {
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("ParamName == " + p[0].Name.ToString());
                                }
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("ParamType == " + p[0].ParameterType.ToString());
                                }
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("ParamName == " + p[1].Name.ToString());
                                }
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("ParamType == " + p[1].ParameterType.ToString());
                                }
                                if (p[0].ParameterType.ToString().Contains("Event"))
                                {
                                    m2 = methodInfo;
                                    if (Mod.DEBUG_LOG_LEVEL > 1)
                                    {
                                        Helper.dbgLog("Found method 2");
                                    }
                                }
                                if (p[0].ParameterType.ToString().Contains("String"))
                                {
                                    m4 = methodInfo;
                                    if (Mod.DEBUG_LOG_LEVEL > 1)
                                    {
                                        Helper.dbgLog("Found method 4");
                                    }
                                }
                            }
                        }
                    }
                    methods = typeof(Telemetry).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
                    for (int i = 0; i < (int)methods.Length; i++)
                    {
                        MethodInfo methodInfo = methods[i];
                        if (methodInfo.Name.Contains("AddEvent"))
                        {
                            if (Mod.DEBUG_LOG_LEVEL > 1)
                            {
                                Helper.dbgLog("Found AddEvent in Telemetry");
                            }
                            ParameterInfo[] p = methodInfo.GetParameters();
                            if (p.Count() == 2)
                            {
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("ParamName == " + p[0].Name.ToString());
                                }
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("ParamType == " + p[0].ParameterType.ToString());
                                }
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("ParamName == " + p[1].Name.ToString());
                                }
                                if (Mod.DEBUG_LOG_LEVEL > 1)
                                {
                                    Helper.dbgLog("ParamType == " + p[1].ParameterType.ToString());
                                }

                                if (p[0].ParameterType.ToString().Contains("Event"))
                                {
                                    if (Mod.DEBUG_LOG_LEVEL > 1)
                                    {
                                        Helper.dbgLog("Found method 1");
                                    }
                                    m1 = methodInfo;
                                }
                                if (p[0].ParameterType.ToString().Contains("String"))
                                {
                                    if (Mod.DEBUG_LOG_LEVEL > 1)
                                    {
                                        Helper.dbgLog("Found method 3");
                                    }
                                    m3 = methodInfo;
                                }
                            }
                        }
                    }
                    if (m1 != null & m2 != null)
                    {
                        if (Mod.DEBUG_LOG_LEVEL > 1)
                        {
                            Helper.dbgLog("Manually passing 1&2");
                        }
                        redirectDic.Add(m1, RedirectionHelper.RedirectCalls(m1, m2, false));
                    }
                    if (m3 != null & m3 != null)
                    {
                        if (Mod.DEBUG_LOG_LEVEL > 1)
                        {
                            Helper.dbgLog("Manually passing 3&4");
                        }
                        redirectDic.Add(m3, RedirectionHelper.RedirectCalls(m3, m4, false));
                    }
                    Mod.IsPushDetoured = true;
                    if (Mod.DEBUG_LOG_ON)
                    {
                        Helper.dbgLog("Redirected Telemetry class calls.");
                    }
                }
            }
            catch (Exception exception1)
            {
                Helper.dbgLog("SetupPush error:", exception1, true);
            }
        }
Ejemplo n.º 21
0
 public Detour(MethodInfo originalMethod, MethodInfo customMethod)
 {
     this.OriginalMethod = originalMethod;
     this.CustomMethod   = customMethod;
     this.Redirect       = RedirectionHelper.RedirectCalls(originalMethod, customMethod);
 }
Ejemplo n.º 22
0
 public void Patch()
 {
     state = RedirectionHelper.RedirectCalls(original, patch);
 }
Ejemplo n.º 23
0
 public static void Unpatch()
 {
     RedirectionHelper.RevertRedirect(releaseProp_original, releasePropState);
     RedirectionHelper.RevertRedirect(createProp_original, createPropState);
 }
Ejemplo n.º 24
0
        public new bool CreateSegment(out ushort segment, ref Randomizer randomizer, NetInfo info, ushort startNode, ushort endNode, Vector3 startDirection, Vector3 endDirection, uint buildIndex, uint modifiedIndex, bool invert)
        {
            // Call original method
            RedirectionHelper.RevertRedirect(_NetManager_CreateSegment_original, _NetManager_CreateSegment_state);
            var success = NetManager.instance.CreateSegment(out segment, ref randomizer, info, startNode, endNode, startDirection, endDirection, buildIndex, modifiedIndex, invert);

            RedirectionHelper.RedirectCalls(_NetManager_CreateSegment_original, _NetManager_CreateSegment_detour);

            var caller = new System.Diagnostics.StackFrame(1).GetMethod().Name;

            //Debug.Log("CreateSegment (" + info.name + ") called by " + caller);

            switch (caller)
            {
            case "CreateNode":

                var caller2 = new System.Diagnostics.StackFrame(2).GetMethod().Name;
                //Debug.Log("... called by " + caller2);

                if (caller2 == "CreateNode")     // check that caller was called by NetTool
                {
                    var caller3Type = new System.Diagnostics.StackFrame(3).GetMethod().DeclaringType?.Name;
                    //Debug.Log("... called by " + caller3Type);

                    if (caller3Type != null && caller3Type.StartsWith("NetTool", StringComparison.Ordinal))     // new segment created by user, apply selected style
                    // use StartsWith to cover NetToolFine from FineRoadHeights, and other possible NetTools
                    {
                        if (success)
                        {
                            EventSegmentCreate?.Invoke(segment);
                        }

                        // Delete data of deleted segments
                        if (MoveMiddleNode_releasedSegment > 0)
                        {
                            EventSegmentRelease?.Invoke(MoveMiddleNode_releasedSegment);
                        }
                        if (SplitSegment_releasedSegment > 0)
                        {
                            EventSegmentRelease?.Invoke(SplitSegment_releasedSegment);
                        }

                        SplitSegment_releasedSegment   = 0;
                        MoveMiddleNode_releasedSegment = 0;
                    }
                }
                else if (caller2 == "LoadPaths")     // segment created because user placed building with integrated networks
                {
                    // TODO SementDataManager should not appear here. Instead, add argument to CreateEvent!
                    if (SegmentDataManager.Instance.AssetMode && success)
                    {
                        EventSegmentCreate?.Invoke(segment);
                    }
                }
                break;

            case "MoveMiddleNode":     // segment that was modified because user added network, apply style of previous segment

                if (MoveMiddleNode_releasedSegment > 0)
                {
                    if (success)
                    {
                        EventSegmentTransferData?.Invoke(MoveMiddleNode_releasedSegment, segment);
                    }

                    // Delete data of previous segment
                    EventSegmentRelease?.Invoke(MoveMiddleNode_releasedSegment);
                    MoveMiddleNode_releasedSegment = 0;
                }
                break;

            case "SplitSegment":     // segment that was split by new node, apply style of previous segment

                if (SplitSegment_releasedSegment > 0)
                {
                    if (success)
                    {
                        EventSegmentTransferData?.Invoke(SplitSegment_releasedSegment, segment);
                    }
                }
                break;

            default:     // unknown caller, ignore
                break;
            }

            return(success);
        }