public static bool Prefix(MethodBase __originalMethod, Section __instance, bool drawSunShadowsOnly) { if (!Active) { return(true); } if (drawSunShadowsOnly) { __instance.layerSunShadows.DrawLayer(); } else { int count = __instance.layers.Count; for (int i = 0; i < count; i++) { var type = __instance.layers[i].GetType(); var name = type.Name; var prof = ProfileController.Start(name, null, type, __originalMethod); __instance.layers[i].DrawLayer(); prof.Stop(); } } bool flag = !drawSunShadowsOnly && DebugViewSettings.drawSectionEdges; if (flag) { GenDraw.DrawLineBetween(__instance.botLeft.ToVector3(), __instance.botLeft.ToVector3() + new Vector3(0f, 0f, 17f)); GenDraw.DrawLineBetween(__instance.botLeft.ToVector3(), __instance.botLeft.ToVector3() + new Vector3(17f, 0f, 0f)); } return(false); }
public static bool FUUUCK(Rect rect, Thing thing) { if (!Active) { return(true); } Profiler prof = null; if (StatsReportUtility.cachedDrawEntries.NullOrEmpty <StatDrawEntry>()) { prof = ProfileController.Start("SpecialDisplayStats"); StatsReportUtility.cachedDrawEntries.AddRange(thing.def.SpecialDisplayStats(StatRequest.For(thing))); prof.Stop(); prof = ProfileController.Start("StatsToDraw"); StatsReportUtility.cachedDrawEntries.AddRange(StatsReportUtility.StatsToDraw(thing).Where(s => s.ShouldDisplay)); prof.Stop(); prof = ProfileController.Start("RemoveAll"); StatsReportUtility.cachedDrawEntries.RemoveAll((StatDrawEntry de) => de.stat != null && !de.stat.showNonAbstract); prof.Stop(); prof = ProfileController.Start("FinalizeCachedDrawEntries"); StatsReportUtility.FinalizeCachedDrawEntries(StatsReportUtility.cachedDrawEntries); prof.Stop(); } prof = ProfileController.Start("DrawStatsWorker"); StatsReportUtility.DrawStatsWorker(rect, thing, null); prof.Stop(); return(false); }
public static bool Fringe(MethodBase __originalMethod, ThinkNode_Priority __instance, Pawn pawn, JobIssueParams jobParams, ref string __state, ref ThinkResult __result) { if (Active) { int count = __instance.subNodes.Count; for (int i = 0; i < count; i++) { ThinkResult result = ThinkResult.NoJob; Profiler prof = null; try { __state = $"ThinkNode_Priority SubNode [{__instance.subNodes[i].GetType()}]"; prof = ProfileController.Start(__state, null, null, __originalMethod); result = __instance.subNodes[i].TryIssueJobPackage(pawn, jobParams); prof.Stop(); } catch (Exception) { prof?.Stop(); } if (result.IsValid) { __result = result; return(false); } } __result = ThinkResult.NoJob; return(false); } return(true); }
public static void Prefix() { if (H_RootUpdate.Active) { ProfileController.Start("Tick"); } if (GUIController.CurrentCategory == Category.Tick) // If we in Tick mode, start our update (can happen multiple times p frame) { ProfileController.BeginUpdate(); } }
public static void LogMe(Thing sam, Action ac, string fix) { bool logme = false; if (bySelection) { if (Find.Selector.selected.Any(x => x == sam)) { logme = true; } } else { logme = true; } if (logme) { string key = sam.GetType().Name; if (byDef) { key = sam.def.defName; } if (bySelection) { key = sam.ThingID; } string Namer() { if (byDef) { return($"{sam.def.defName} - {sam?.def?.modContentPack?.Name} - {fix} "); } if (bySelection) { return($"{sam.def.defName} - {sam.GetHashCode()} - {sam?.def?.modContentPack?.Name} - {fix}"); } return($"{sam.GetType()} {fix}"); } Profiler prof = ProfileController.Start(key, Namer, sam.GetType(), sam.def, sam, ac.GetMethodInfo()); ac(); prof.Stop(); } else { ac(); } }
public static void Prefix() { if (Active) { ProfileController.Start("Game Update"); } if (GUIController.CurrentCategory != Category.Tick) { ProfileController.BeginUpdate(); } }
public static bool GetValueDetour(MethodBase __originalMethod, StatWorker __instance, StatRequest req, ref float __result, bool applyPostProcess = true) { if (Active && GetValDetour && __instance is StatWorker sw) { if (sw.stat.minifiedThingInherits) { if (req.Thing is MinifiedThing minifiedThing) { if (minifiedThing.InnerThing == null) { Log.Error("MinifiedThing's inner thing is null."); } __result = minifiedThing.InnerThing.GetStatValue(sw.stat, applyPostProcess); return(false); } } string slag = ""; if (ByDef) { slag = $"{__instance.stat.defName} GetValueUnfinalized for {req.Def.defName}"; } else { slag = $"{__instance.stat.defName} GetValueUnfinalized"; } Profiler prof = ProfileController.Start(slag, null, null, __originalMethod); float valueUnfinalized = sw.GetValueUnfinalized(req, applyPostProcess); prof.Stop(); if (ByDef) { slag = $"{__instance.stat.defName} FinalizeValue for {req.Def.defName}"; } else { slag = $"{__instance.stat.defName} FinalizeValue"; } prof = ProfileController.Start(slag, null, null, __originalMethod); sw.FinalizeValue(req, ref valueUnfinalized, applyPostProcess); prof.Stop(); __result = valueUnfinalized; return(false); } return(true); }
public static Profiler Start(WorkGiver giver) { if (!Active) { return(null); } wg = giver; CurrentKey = string.Empty; if (ByWorkType) { CurrentKey = giver.def.workType.defName; } else { CurrentKey = giver.def.defName; } if (PerPawn) { CurrentKey = string.Intern(CurrentKey + pawnname); } if (!meths.TryGetValue(giver, out var meth)) { if (giver is WorkGiver_Scanner) { if (giver.def.scanThings) { meth = AccessTools.Method(giver.GetType(), "PotentialWorkThingsGlobal"); } else { meth = AccessTools.Method(giver.GetType(), "PotentialWorkCellsGlobal"); } } else { meth = AccessTools.Method(giver.GetType(), "NonScanJob"); } meths.Add(giver, meth); } return(ProfileController.Start(CurrentKey, namer, null, null, null, meth)); }
public static void Prefix() { if (Analyzer.CurrentlyProfiling) { // GarbageMan.Collect(); if (Time.unscaledTime > _timer) { int fps = (int)(1f / Time.unscaledDeltaTime); _fpsText = "FPS: " + fps; _timer = Time.unscaledTime + _hudRefreshRate; // Every second we update our fps } try { if (Current.ProgramState == ProgramState.Playing) { float TRM = Find.TickManager.TickRateMultiplier; int TPSTarget = (int)Math.Round(TRM == 0f ? 0f : 60f * TRM); DateTime CurrTime = DateTime.Now; if (CurrTime.Second != PrevTime.Second) { PrevTime = CurrTime; TPSActual = GenTicks.TicksAbs - PrevTicks; PrevTicks = GenTicks.TicksAbs; } tps = $"TPS: {TPSActual}({TPSTarget})"; } } catch (Exception) { } } if (Active) { ProfileController.Start("Game Update"); } #if DEBUG if (GUIController.CurrentCategory != Category.Tick) { ProfileController.BeginUpdate(); } #endif }
public static bool Prefix(MethodBase __originalMethod, SectionLayer_Things __instance, ref string __state) { if (Active) { __instance.ClearSubMeshes(MeshParts.All); Profiler prof = null; foreach (IntVec3 intVec in __instance.section.CellRect) { List <Thing> list = __instance.Map.thingGrid.ThingsListAt(intVec); int count = list.Count; for (int i = 0; i < count; i++) { Thing thing = list[i]; __state = "Flag check"; prof = ProfileController.Start(__state, null, null, __originalMethod); bool flag = ((thing.def.seeThroughFog || !__instance.Map.fogGrid.fogGrid[ CellIndicesUtility.CellToIndex(thing.Position, __instance.Map.Size.x)]) && thing.def.drawerType != DrawerType.None && (thing.def.drawerType != DrawerType.RealtimeOnly || !__instance.requireAddToMapMesh) && (thing.def.hideAtSnowDepth >= 1f || __instance.Map.snowGrid.GetDepth(thing.Position) <= thing.def.hideAtSnowDepth) && thing.Position.x == intVec.x && thing.Position.z == intVec.z); prof.Stop(); if (flag) { __state = thing.def.defName; prof = ProfileController.Start(__state, null, null, __originalMethod); __instance.TakePrintFrom(thing); prof.Stop(); } } } __state = "Finalize mesh"; prof = ProfileController.Start(__state, null, null, __originalMethod); __instance.FinalizeMesh(MeshParts.All); prof.Stop(); return(false); } return(true); }
public static void Prefix(MethodBase __originalMethod, Thing thing, StatDef stat, ref Profiler __state) { if (Active && !GetValDetour) { string state = string.Empty; if (ByDef) { state = $"{stat.defName} for {thing.def.defName}"; } else { state = stat.defName; } __state = ProfileController.Start(state, null, null, null, null, __originalMethod); } }
public static void PartPrefix(object __instance, MethodBase __originalMethod, ref Profiler __state) { if (Active) { string state = string.Empty; if (__originalMethod.ReflectedType != null) { state = __originalMethod.ReflectedType.ToString(); } else { state = __originalMethod.GetType().ToString(); } __state = ProfileController.Start(state, null, null, __originalMethod); } }
public static void PrefixAbility(MethodBase __originalMethod, AbilityDef def, StatDef stat, ref Profiler __state) { if (Active && !GetValDetour) { string state = string.Empty; if (ByDef) { state = $"{stat.defName} abstract for {def.defName}"; } else { state = $"{stat.defName} abstract"; } __state = ProfileController.Start(state, null, null, __originalMethod); } }
public static void Postfix() { if (Active) { ProfileController.Stop("Frame times"); ProfileController.Stop("Game Update"); } if (GUIController.CurrentCategory != Category.Tick) // If we are tick, we will 'update' in the TickManager.DoSingleTick method { ProfileController.EndUpdate(); } if (Active) { ProfileController.Start("Frame times"); } }
public static bool Prefix(MethodBase __originalMethod, InspectTabBase tab, ref string __state) { if (!Active) { return(true); } __state = string.Empty; if (tab is InspectTabBase f) { __state = string.Intern($"{tab.GetType()} {tab.labelKey}"); } else { __state = string.Intern($"{tab.GetType()}"); } ProfileController.Start(__state, null, tab.GetType(), __originalMethod); return(true); }
public static bool Prefix(MethodBase __originalMethod, Section __instance, bool drawSunShadowsOnly) { if (!Active) { return(true); } var count = __instance.layers.Count; for (var i = 0; i < count; i++) { if (!drawSunShadowsOnly || __instance.layers[i] is SectionLayer_SunShadows) { string Namer() { var n = __instance.layers[i].GetType().ToString(); return(n); } var name = __instance.layers[i].GetType().Name; var prof = ProfileController.Start(name, Namer, __instance.layers[i].GetType(), null, null, __originalMethod); __instance.layers[i].DrawLayer(); prof.Stop(); } } if (!drawSunShadowsOnly && DebugViewSettings.drawSectionEdges) { GenDraw.DrawLineBetween(__instance.botLeft.ToVector3(), __instance.botLeft.ToVector3() + new Vector3(0f, 0f, 17f)); GenDraw.DrawLineBetween(__instance.botLeft.ToVector3(), __instance.botLeft.ToVector3() + new Vector3(17f, 0f, 0f)); } return(false); }
private static void Detour(Pawn_JobTracker __instance) { Profiler pro = null; __instance.jobsGivenThisTick = 0; __instance.jobsGivenThisTickTextual = ""; if (__instance.pawn.IsHashIntervalTick(30)) { pro = ProfileController.Start("DetermineNextConstantThinkTreeJob"); var thinkResult = __instance.DetermineNextConstantThinkTreeJob(); pro.Stop(); if (thinkResult.IsValid) { pro = ProfileController.Start("ShouldStartJobFromThinkTree"); if (__instance.ShouldStartJobFromThinkTree(thinkResult)) { __instance.CheckLeaveJoinableLordBecauseJobIssued(thinkResult); __instance.StartJob(thinkResult.Job, JobCondition.InterruptForced, thinkResult.SourceNode, false, false, __instance.pawn.thinker.ConstantThinkTree, thinkResult.Tag); } else if (thinkResult.Job != __instance.curJob && !__instance.jobQueue.Contains(thinkResult.Job)) { JobMaker.ReturnToPool(thinkResult.Job); } pro.Stop(); } } if (__instance.curDriver != null) { if (__instance.curJob.expiryInterval > 0 && (Find.TickManager.TicksGame - __instance.curJob.startTick) % __instance.curJob.expiryInterval == 0 && Find.TickManager.TicksGame != __instance.curJob.startTick) { pro = ProfileController.Start("EnemiesAreNearby"); var enemies = !__instance.curJob.expireRequiresEnemiesNearby || PawnUtility.EnemiesAreNearby(__instance.pawn, 25); pro.Stop(); if (enemies) { if (__instance.debugLog) { __instance.DebugLogEvent("Job expire"); } if (!__instance.curJob.checkOverrideOnExpire) { pro = ProfileController.Start("EndCurrentJob"); __instance.EndCurrentJob(JobCondition.Succeeded); pro.Stop(); } else { pro = ProfileController.Start("CheckForJobOverride"); __instance.CheckForJobOverride(); pro.Stop(); } pro = ProfileController.Start("FinalizeTick"); __instance.FinalizeTick(); pro.Stop(); return; } if (__instance.debugLog) { __instance.DebugLogEvent("Job expire skipped because there are no enemies nearby"); } } var key = string.Empty; if (PerPawn) { key = __instance.pawn.LabelShort + __instance.curDriver.job?.def.defName; } else { key = __instance.curDriver.job?.def.defName; } string label() { var daffy = string.Empty; if (PerPawn) { daffy = $"{__instance.pawn.LabelShort} {__instance.curDriver.job?.def?.defName} - {__instance.curDriver.job?.def?.driverClass} - {__instance.curDriver.job?.def?.modContentPack?.Name}"; } else { daffy = $"{__instance.curDriver.job?.def?.defName} - {__instance.curDriver.job?.def?.driverClass} - {__instance.curDriver.job?.def?.modContentPack?.Name}"; } return(daffy); } var meth = AccessTools.Method(__instance.curDriver.job?.def?.driverClass, "DriverTick"); pro = ProfileController.Start(key, label, __instance.curDriver.job?.def?.driverClass, __instance.curDriver.job?.def, __instance.pawn, meth); __instance.curDriver.DriverTick(); pro.Stop(); } if (__instance.curJob == null && !__instance.pawn.Dead && __instance.pawn.mindState.Active) { pro = ProfileController.Start("CanDoAnyJob"); var doit = __instance.CanDoAnyJob(); pro.Stop(); if (doit) { if (__instance.debugLog) { __instance.DebugLogEvent("Starting job from Tick because curJob == null."); } pro = ProfileController.Start("FinalizeTick"); __instance.TryFindAndStartJob(); pro.Stop(); } } pro = ProfileController.Start("FinalizeTick"); __instance.FinalizeTick(); pro.Stop(); }
public static bool Prefix(MethodBase __originalMethod, DynamicDrawManager __instance) { if (!Active) { return(true); } __instance.drawingNow = true; try { bool[] fogGrid = __instance.map.fogGrid.fogGrid; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(__instance.map); cellRect = cellRect.ExpandedBy(1); CellIndices cellIndices = __instance.map.cellIndices; foreach (Thing thing in __instance.drawThings) { IntVec3 position = thing.Position; if (cellRect.Contains(position) || thing.def.drawOffscreen) { if (!fogGrid[cellIndices.CellToIndex(position)] || thing.def.seeThroughFog) { if (thing.def.hideAtSnowDepth >= 1f || __instance.map.snowGrid.GetDepth(thing.Position) <= thing.def.hideAtSnowDepth) { try { string Namer() { string n = string.Empty; if (ByDef) { n = $"{thing.def.defName} - {thing?.def?.modContentPack?.Name}"; } else { n = thing.GetType().ToString(); } return(n); } string name = string.Empty; if (ByDef) { name = thing.def.defName; } else { name = thing.GetType().Name; } var prof = ProfileController.Start(name, Namer, thing.GetType(), thing.def, null, __originalMethod); thing.Draw(); prof.Stop(); } catch (Exception ex) { Log.Error(string.Concat("Exception drawing ", thing, ": ", ex.ToString())); } } } } } } catch (Exception arg) { Log.Error("Exception drawing dynamic things: " + arg); } __instance.drawingNow = false; return(false); }
public Profiler Start(string key, MethodBase info) { return(ProfileController.Start(key, null, null, null, null, info)); }
private static ThinkResult Detour(JobGiver_Work __instance, Pawn pawn) { if (__instance.emergency && pawn.mindState.priorityWork.IsPrioritized) { List <WorkGiverDef> workGiversByPriority = pawn.mindState.priorityWork.WorkGiver.workType.workGiversByPriority; for (int i = 0; i < workGiversByPriority.Count; i++) { WorkGiver worker = workGiversByPriority[i].Worker; Job job = __instance.GiverTryGiveJobPrioritized(pawn, worker, pawn.mindState.priorityWork.Cell); if (job != null) { job.playerForced = true; return(new ThinkResult(job, __instance, workGiversByPriority[i].tagToGive)); } } pawn.mindState.priorityWork.Clear(); } List <WorkGiver> list = __instance.emergency ? pawn.workSettings.WorkGiversInOrderEmergency : pawn.workSettings.WorkGiversInOrderNormal; int num = -999; TargetInfo bestTargetOfLastPriority = TargetInfo.Invalid; WorkGiver_Scanner scannerWhoProvidedTarget = null; int coo = list.Count; Profiler prof = null; for (int j = 0; j < coo; j++) { WorkGiver workGiver = list[j]; if (!H_TryIssueJobPackageTrans.meths.TryGetValue(workGiver, out var meth)) { if (workGiver is WorkGiver_Scanner) { if (workGiver.def.scanThings) { meth = AccessTools.Method(workGiver.GetType(), "PotentialWorkThingsGlobal"); } else { meth = AccessTools.Method(workGiver.GetType(), "PotentialWorkCellsGlobal"); } } else { meth = AccessTools.Method(workGiver.GetType(), "NonScanJob"); } H_TryIssueJobPackageTrans.meths.Add(workGiver, meth); } string namer() { string daffy = string.Empty; if (ByWorkType) { daffy = workGiver.def?.workType?.defName; } else { daffy = $"{workGiver.def?.defName} - {workGiver.def?.workType.defName} - {workGiver.def?.modContentPack?.Name}"; } if (RequestTypes && workGiver is WorkGiver_Scanner scan) { daffy += $" - {scan.PotentialWorkThingRequest}"; if (scan.PotentialWorkThingRequest.group == ThingRequestGroup.BuildingArtificial) { daffy += " VERY BAD!"; } } return(daffy); } if (workGiver.def.priorityInType != num && bestTargetOfLastPriority.IsValid) { break; } if (__instance.PawnCanUseWorkGiver(pawn, workGiver)) { string name = string.Empty; if (ByWorkType) { name = workGiver.def.workType.defName; } else { name = workGiver.def.defName; } //if (true) //{ // name = string.Intern(name + pawn.Name.ToStringShort); //} if (workGiver is WorkGiver_Scanner scanny) { name += $"{scanny.PotentialWorkThingRequest}"; } try { Job job2 = workGiver.NonScanJob(pawn); if (job2 != null) { return(new ThinkResult(job2, __instance, list[j].def.tagToGive)); } if (workGiver is WorkGiver_Scanner scanner) { if (scanner.def.scanThings) { bool Predicate(Thing t) { return(!t.IsForbidden(pawn) && scanner.HasJobOnThing(pawn, t)); } prof = ProfileController.Start(name, namer, workGiver.GetType(), workGiver.def, pawn, meth); IEnumerable <Thing> enumerable = scanner.PotentialWorkThingsGlobal(pawn)?.Where(x => scanner.HasJobOnThing(pawn, x)); //if (scanner is WorkGiver_Repair repair) //{ // foreach (var repairableBuilding in pawn.Map.listerBuildingsRepairable.RepairableBuildings(pawn.Faction)) // { // Log.Warning($"repair scan on {repairableBuilding}"); // } //} Thing thing; if (scanner.Prioritized) { IEnumerable <Thing> enumerable2 = enumerable; if (enumerable2 == null) { enumerable2 = pawn.Map.listerThings.ThingsMatching(scanner.PotentialWorkThingRequest); } if (scanner.AllowUnreachable) { thing = GenClosest.ClosestThing_Global(pawn.Position, enumerable2, 99999f, Predicate, x => scanner.GetPriority(pawn, x)); } else { TraverseParms traverseParams = TraverseParms.For(pawn, scanner.MaxPathDanger(pawn)); // var validator = (Predicate<Thing>)Predicate; thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, enumerable2, scanner.PathEndMode, traverseParams, 9999f, Predicate, x => scanner.GetPriority(pawn, x)); } } else if (scanner.AllowUnreachable) { IEnumerable <Thing> enumerable3 = enumerable; if (enumerable3 == null) { enumerable3 = pawn.Map.listerThings.ThingsMatching(scanner.PotentialWorkThingRequest); } thing = GenClosest.ClosestThing_Global(pawn.Position, enumerable3, 99999f, Predicate); } else { giver = workGiver; key = name; thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, scanner.PotentialWorkThingRequest, scanner.PathEndMode, TraverseParms.For(pawn, scanner.MaxPathDanger(pawn)), 9999f, Predicate, enumerable, 0, scanner.MaxRegionsToScanBeforeGlobalSearch, enumerable != null); giver = null; } prof.Stop(); if (thing != null) { bestTargetOfLastPriority = thing; scannerWhoProvidedTarget = scanner; } } if (scanner.def.scanCells) { prof = ProfileController.Start(name, namer, workGiver.GetType(), workGiver.def, pawn, meth); float closestDistSquared = 99999f; float bestPriority = float.MinValue; bool prioritized = scanner.Prioritized; bool allowUnreachable = scanner.AllowUnreachable; Danger maxDanger = scanner.MaxPathDanger(pawn); foreach (IntVec3 intVec in scanner.PotentialWorkCellsGlobal(pawn)) { bool flag = false; int num4 = (intVec - pawn.Position).LengthHorizontalSquared; float num5 = 0f; if (prioritized) { if (!intVec.IsForbidden(pawn) && scanner.HasJobOnCell(pawn, intVec)) { if (!allowUnreachable && !pawn.CanReach(intVec, scanner.PathEndMode, maxDanger)) { continue; } num5 = scanner.GetPriority(pawn, intVec); if (num5 > bestPriority || num5 == bestPriority && num4 < closestDistSquared) { flag = true; } } } else if (num4 < closestDistSquared && !intVec.IsForbidden(pawn) && scanner.HasJobOnCell(pawn, intVec)) { if (!allowUnreachable && !pawn.CanReach(intVec, scanner.PathEndMode, maxDanger)) { continue; } flag = true; } if (flag) { bestTargetOfLastPriority = new TargetInfo(intVec, pawn.Map); scannerWhoProvidedTarget = scanner; closestDistSquared = num4; bestPriority = num5; } } prof.Stop(); } } } catch (Exception ex) { Log.Error(string.Concat(pawn, " threw exception in WorkGiver ", workGiver.def.defName, ": ", ex.ToString())); } if (bestTargetOfLastPriority.IsValid) { // pawn.mindState.lastGivenWorkType = workGiver.def.workType; prof = ProfileController.Start(name, namer, workGiver.GetType(), workGiver.def, pawn, meth); Job job3; if (bestTargetOfLastPriority.HasThing) { job3 = scannerWhoProvidedTarget.JobOnThing(pawn, bestTargetOfLastPriority.Thing); } else { job3 = scannerWhoProvidedTarget.JobOnCell(pawn, bestTargetOfLastPriority.Cell); } prof.Stop(); if (job3 != null) { job3.workGiverDef = scannerWhoProvidedTarget.def; return(new ThinkResult(job3, __instance, list[j].def.tagToGive)); } Log.ErrorOnce( string.Concat("Analyzer: ", scannerWhoProvidedTarget, " provided target ", bestTargetOfLastPriority, " but yielded no actual job for pawn ", pawn, ". The CanGiveJob and JobOnX methods may not be synchronized."), 6112651); } num = workGiver.def.priorityInType; } } return(ThinkResult.NoJob); }
public static bool Prefix(MethodBase __originalMethod, SectionLayer_Things __instance) { if (!Active) { return(true); } if (ByDef) { if (!__instance.Visible) { return(false); } int count = __instance.subMeshes.Count; for (int i = 0; i < count; i++) { LayerSubMesh layerSubMesh = __instance.subMeshes[i]; if (layerSubMesh.finalized && !layerSubMesh.disabled) { string Namer() { var n = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name; return(n); } // todo material.mainTexture is a non trivial lookup var name = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name; var prof = ProfileController.Start(name, Namer, __originalMethod.GetType(), __originalMethod); Graphics.Internal_DrawMesh_Injected(layerSubMesh.mesh, 0, ref johnmatrix, layerSubMesh.material, 0, null, null, ShadowCastingMode.Off, false, null, LightProbeUsage.Off, null); // Graphics.DrawMesh(layerSubMesh.mesh, Vector3.zeroVector, Quaternion.identityQuaternion, layerSubMesh.material, 0); prof.Stop(); } } return(false); } { if (!__instance.Visible) { return(false); } int count = __instance.subMeshes.Count; for (int i = 0; i < count; i++) { LayerSubMesh layerSubMesh = __instance.subMeshes[i]; if (layerSubMesh.finalized && !layerSubMesh.disabled) { string Namer() { var n = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name; return(n); } var name = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name; var prof = ProfileController.Start(name, Namer, __originalMethod.GetType(), __originalMethod); Graphics.DrawMesh(layerSubMesh.mesh, Vector3.zero, Quaternion.identity, layerSubMesh.material, 0); prof.Stop(); } } } return(false); }
public static void Prefix() { if (Analyzer.CurrentlyProfiling) { long jam = totalBytesOfMemoryUsed; totalBytesOfMemoryUsed = GC.GetTotalMemory(false); if (jam > totalBytesOfMemoryUsed) { LastMinGC = totalBytesOfMemoryUsed; LastMaxGC = jam; GarbageCollectionInfo = $"{totalBytesOfMemoryUsed.ToMb()}MB"; } delta += Time.deltaTime; if (delta >= 1f) { delta -= 1f; long PreviouslyAllocatedMemory = CurrentAllocatedMemory; CurrentAllocatedMemory = GC.GetTotalMemory(false); long MemoryDifference = CurrentAllocatedMemory - PreviouslyAllocatedMemory; if (MemoryDifference < 0) { MemoryDifference = 0; } GarbageCollectionInfo = $"{CurrentAllocatedMemory.ToMb():0.00}MB +{MemoryDifference.ToMb():0.00}MB/s"; } if (Time.unscaledTime > _timer) { int fps = (int)(1f / Time.unscaledDeltaTime); _fpsText = "FPS: " + fps; _timer = Time.unscaledTime + _hudRefreshRate; // Every second we update our fps } try { if (Current.ProgramState == ProgramState.Playing) { float TRM = Find.TickManager.TickRateMultiplier; int TPSTarget = (int)Math.Round(TRM == 0f ? 0f : 60f * TRM); DateTime CurrTime = DateTime.Now; if (CurrTime.Second != PrevTime.Second) { PrevTime = CurrTime; TPSActual = GenTicks.TicksAbs - PrevTicks; PrevTicks = GenTicks.TicksAbs; } tps = $"TPS: {TPSActual}({TPSTarget})"; } } catch (Exception) { } } if (Active) { ProfileController.Start("Game Update"); } #if DEBUG if (GUIController.CurrentCategory != Category.Tick) { ProfileController.BeginUpdate(); } #endif }
public static bool Prefix(MethodBase __originalMethod, WindowStack __instance) { if (!Active) { return(true); } __instance.windowStackOnGUITmpList.Clear(); __instance.windowStackOnGUITmpList.AddRange(__instance.windows); for (int i = __instance.windowStackOnGUITmpList.Count - 1; i >= 0; i--) { string name = string.Empty; if (__instance.windowStackOnGUITmpList[i] is ImmediateWindow) { name = string.Intern( $"{__instance.windowStackOnGUITmpList[i].GetType()} ExtraOnGUI {__instance.windowStackOnGUITmpList[i].ID}"); } else { name = string.Intern($"{__instance.windowStackOnGUITmpList[i].GetType()} ExtraOnGUI"); } Profiler prof = ProfileController.Start(name, null, null, null, null, __originalMethod); __instance.windowStackOnGUITmpList[i].ExtraOnGUI(); prof.Stop(); } __instance.UpdateImmediateWindowsList(); __instance.windowStackOnGUITmpList.Clear(); __instance.windowStackOnGUITmpList.AddRange(__instance.windows); for (int j = 0; j < __instance.windowStackOnGUITmpList.Count; j++) { if (__instance.windowStackOnGUITmpList[j].drawShadow) { GUI.color = new Color(1f, 1f, 1f, __instance.windowStackOnGUITmpList[j].shadowAlpha); Widgets.DrawShadowAround(__instance.windowStackOnGUITmpList[j].windowRect); GUI.color = Color.white; } string name = string.Empty; if (__instance.windowStackOnGUITmpList[j] is ImmediateWindow) { name = string.Intern( $"{__instance.windowStackOnGUITmpList[j].GetType()} WindowOnGUI {__instance.windowStackOnGUITmpList[j].ID}"); } else { name = string.Intern($"{__instance.windowStackOnGUITmpList[j].GetType()} WindowOnGUI"); } Profiler prof = ProfileController.Start(name, null, null, null, null, __originalMethod); __instance.windowStackOnGUITmpList[j].WindowOnGUI(); prof.Stop(); } if (__instance.updateInternalWindowsOrderLater) { __instance.updateInternalWindowsOrderLater = false; __instance.UpdateInternalWindowsOrder(); } return(false); }