|
2 | 2 | using System; |
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.Linq; |
| 5 | +using System.Text.RegularExpressions; |
5 | 6 | using RimWorld; |
6 | 7 | using Verse; |
7 | 8 | using Multiplayer.Client.Desyncs; |
@@ -242,6 +243,44 @@ public void TryAddStackTraceForDesyncLogRaw(StackTraceLogItemRaw item, int depth |
242 | 243 | OpinionInBuilding.desyncStackTraceHashes.Add(hash); |
243 | 244 | } |
244 | 245 |
|
| 246 | + private static readonly Regex RemoveUnknownSourceInfoRegex = new(@"in <([a-zA-Z0-9]+)>:0"); |
| 247 | + public static string CleanedMethodName(string rawName) |
| 248 | + { |
| 249 | + // at (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition.RimWorld.UniqueIDsManager.GetNextID_Patch2 ... |
| 250 | + // => |
| 251 | + // at (wrapper dynamic-method) RimWorld.UniqueIDsManager.GetNextID_Patch2 ... |
| 252 | + rawName = rawName.Replace("MonoMod.Utils.DynamicMethodDefinition.", string.Empty); |
| 253 | + |
| 254 | + // Performs the transformation only if the source file is unknown, meaning random id instead of a path |
| 255 | + // at Verse.AI.JobDriver.ReadyForNextToil () [0x00000] in <c847e073cda54790b59d58357cc8cf98>:0 |
| 256 | + // => |
| 257 | + // at Verse.AI.JobDriver.ReadyForNextToil () [0x00000] |
| 258 | + rawName = RemoveUnknownSourceInfoRegex.Replace(rawName, string.Empty); |
| 259 | + return ShortenSourceInfo(rawName); |
| 260 | + } |
| 261 | + |
| 262 | + |
| 263 | + private static string ShortenSourceInfo(string rawName) |
| 264 | + { |
| 265 | + // at Multiplayer.Client.Desyncs.DeferredStackTracing.Postfix () [0x00045] in /home/runner/work/Multiplayer/Multiplayer/Source/Client/Desyncs/DeferredStackTracing.cs:41 |
| 266 | + // => |
| 267 | + // at Multiplayer.Client.Desyncs.DeferredStackTracing.Postfix () [0x00045] in /Client/Desyncs/DeferredStackTracing.cs:41 |
| 268 | + const string sourcePrefix = "in "; |
| 269 | + const string realSourceStartA = "Multiplayer/Source"; |
| 270 | + const string realSourceStartB = "Multiplayer\\Source"; |
| 271 | + var startSource2 = rawName.IndexOf(sourcePrefix, StringComparison.Ordinal); |
| 272 | + if (startSource2 != -1) |
| 273 | + { |
| 274 | + var offset = startSource2 + sourcePrefix.Length; |
| 275 | + var realSourceStartIndex = rawName.IndexOf(realSourceStartA, offset, StringComparison.Ordinal); |
| 276 | + if (realSourceStartIndex == -1) |
| 277 | + realSourceStartIndex = rawName.IndexOf(realSourceStartB, offset, StringComparison.Ordinal); |
| 278 | + if (realSourceStartIndex != -1) |
| 279 | + rawName = rawName.Remove(offset, realSourceStartIndex - offset + realSourceStartA.Length); |
| 280 | + } |
| 281 | + return rawName; |
| 282 | + } |
| 283 | + |
245 | 284 | public static string MethodNameWithIL(string rawName) |
246 | 285 | { |
247 | 286 | // Note: The names currently don't include IL locations so the code is commented out |
|
0 commit comments