Beispiel #1
0
        public void GenerateStats()
        {
            if (AnalyzerState.CurrentProfiler() == null)
            {
                return;
            }


            AnalyzerState.CurrentProfiler().History.times.CopyTo(lTimes, 0);
            AnalyzerState.CurrentProfiler().History.hits.CopyTo(lCalls, 0);

            thread = new Thread(() => ExecuteWorker(this, lCalls, lTimes));
            thread.IsBackground = true;
            thread.Start();
        }
        private static void PatchInternalMethodFull(MethodInfo method, bool display = true)
        {
            try
            {
                AnalyzerState.MakeAndSwitchTab(method.Name + "-int");

                InternalMethodUtility.curMeth = method;
                InternalMethodUtility.PatchedInternals.Add(method);
                InternalMethodUtility.Harmony.Patch(method, null, null, InternalMethodUtility.InternalProfiler);
            }
            catch (Exception e)
            {
                if (display)
                {
                    Error("Failed to patch internal methods, failed with the error " + e.Message);
                }
                InternalMethodUtility.PatchedInternals.Remove(method);
            }
        }
        public static void PatchAssembly(string name, bool display = true)
        {
            var mod = LoadedModManager.RunningMods.FirstOrDefault(m => m.Name == name || m.PackageId == name.ToLower());

            if (display)
            {
                Notify($"Mod is null? {mod == null}");
            }
            if (mod != null)
            {
                if (display)
                {
                    Notify($"Assembly count: { mod.assemblies?.loadedAssemblies?.Count ?? 0}");
                }
                foreach (var ass in mod.assemblies?.loadedAssemblies)
                {
                    if (display)
                    {
                        Notify($"Assembly named: {ass.FullName}, located at {ass.Location}");
                    }
                }
            }

            var assembly = mod?.assemblies?.loadedAssemblies?.Where(w => !w.FullName.Contains("Harmony") && !w.FullName.Contains("0MultiplayerAPI"));

            if (assembly != null && assembly.Count() != 0)
            {
                AnalyzerState.MakeAndSwitchTab(mod.Name + "-prof");
                var pre  = new HarmonyMethod(AccessTools.TypeByName(mod.Name + "-prof").GetMethod("Prefix", BindingFlags.Public | BindingFlags.Static));
                var post = new HarmonyMethod(AccessTools.TypeByName(mod.Name + "-prof").GetMethod("Postfix", BindingFlags.Public | BindingFlags.Static));

                patchAssemblyThread = new Thread(() => PatchAssemblyFull(assembly.ToList(), pre, post, display));
                patchAssemblyThread.Start();
            }
            else
            {
                if (display)
                {
                    Error($"Failed to patch {name}");
                }
            }
        }
Beispiel #4
0
            public static void ExecutePatch()
            {
                switch (input)
                {
                case CurrentInput.Method:
                    if (patchType == UpdateMode.Tick)
                    {
                        CustomProfilersTick.PatchMeth(currentInput);
                        AnalyzerState.SwapTab("Custom Tick", UpdateMode.Tick);
                    }
                    else
                    {
                        CustomProfilersUpdate.PatchMeth(currentInput);
                        AnalyzerState.SwapTab("Custom Update", UpdateMode.Update);
                    }
                    return;

                case CurrentInput.Type:
                    CustomProfilersUpdate.PatchType(currentInput);
                    AnalyzerState.SwapTab("Custom Update", UpdateMode.Update);
                    return;

                case CurrentInput.MethodHarmony:
                    CustomProfilersHarmony.PatchMeth(currentInput);
                    AnalyzerState.SwapTab("Custom Harmony", UpdateMode.Update);
                    return;

                case CurrentInput.TypeHarmony:
                    CustomProfilersHarmony.PatchType(currentInput);
                    AnalyzerState.SwapTab("Custom Harmony", UpdateMode.Update);
                    return;

                case CurrentInput.InternalMethod:
                    PatchUtils.PatchInternalMethod(currentInput);
                    return;

                case CurrentInput.Assembly:
                    PatchUtils.PatchAssembly(currentInput, false);
                    return;
                }
            }
        public static void ClearState()
        {
            foreach (var maintab in AnalyzerState.SideTabCategories)
            {
                List <KeyValuePair <ProfileMode, Type> > removes = new List <KeyValuePair <ProfileMode, Type> >();
                maintab.Modes.Do(w =>
                {
                    if (w.Key.Closable)
                    {
                        removes.Add(w);
                    }
                    else
                    {
                        w.Key.IsPatched = false;
                        w.Key.SetActive(false);
                        w.Key.Patchinator = null;
                    }
                });

                foreach (var val in removes)
                {
                    AnalyzerState.RemoveTab(val);
                }
            }

            H_HarmonyPatches.PatchedPres      = new List <Patch>();
            H_HarmonyPatches.PatchedPosts     = new List <Patch>();
            H_HarmonyTranspilers.PatchedMeths = new List <MethodBase>();

            PatchUtils.PatchedTypes      = new List <string>();
            PatchUtils.PatchedAssemblies = new List <string>();

            AnalyzerState.CurrentTab             = null;
            AnalyzerState.CurrentSideTabCategory = SideTabCategory.Home;

            AnalyzerState.CurrentProfileKey = "";
            AnalyzerState.CurrentLog        = new ProfileLog();

            Reset();
        }
 public static void Reset()
 {
     AnalyzerState.ResetState();
 }