using System; using System.Collections.Generic; using UnityEngine; namespace DebuggingEssentials { public class MemorySnapshot { public FastSortedDictionary memoryTypesLookup = new FastSortedDictionary(1024); public float tStamp; public GUIChangeBool selected = new GUIChangeBool(value: false); public CompareResult compareResult; public bool hasCleanedDifCompare; public void Reset() { memoryTypesLookup.Clear(); hasCleanedDifCompare = false; } public void ScanMemory(CompareMode compareMode) { tStamp = Time.realtimeSinceStartup; UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(); foreach (UnityEngine.Object obj in array) { Type type = obj.GetType(); string name = type.Name; if (!memoryTypesLookup.lookup.TryGetValue(name, out var value)) { value = new MemoryInstanceType(type); memoryTypesLookup.Add(name, value); } int instanceID = obj.GetInstanceID(); value.instances.Add(instanceID, new MemoryObject(obj.name, instanceID, obj.hideFlags, Helper.IsPrefab(obj))); } memoryTypesLookup.Sort(compareMode); } public void CleanDifSnapshot(CompareMode compareMode) { if (hasCleanedDifCompare) { return; } hasCleanedDifCompare = true; FastList> list = memoryTypesLookup.list; for (int i = 0; i < list.Count; i++) { FastList list2 = list.items[i].value.instances.list; for (int j = 0; j < list2.Count; j++) { MemoryObject memoryObject = list2.items[j]; CompareResult compareResult = memoryObject.compareResult; for (int k = j + 1; k < list2.Count; k++) { MemoryObject memoryObject2 = list2.items[k]; if (memoryObject2.compareResult != compareResult && memoryObject2.name == memoryObject.name) { list2.RemoveAt(k); list2.RemoveAt(j--); break; } } } if (list2.Count == 0) { list.RemoveAt(i--); } } memoryTypesLookup.Sort(compareMode); } public static void CompareMemorySnapshots(MemorySnapshot oldSnapshot, MemorySnapshot newSnapshot, MemorySnapshot difSnapshot, CompareMode compareMode) { difSnapshot.Reset(); CompareMemorySnapshots(oldSnapshot, newSnapshot, difSnapshot, CompareResult.Removed); CompareMemorySnapshots(newSnapshot, oldSnapshot, difSnapshot, CompareResult.New); difSnapshot.memoryTypesLookup.Sort(compareMode); } public static void CompareMemorySnapshots(MemorySnapshot s, MemorySnapshot d, MemorySnapshot difSnapshot, CompareResult compareResult) { FastSortedDictionary fastSortedDictionary = s.memoryTypesLookup; FastSortedDictionary fastSortedDictionary2 = d.memoryTypesLookup; FastList> list = fastSortedDictionary.list; for (int i = 0; i < list.Count; i++) { ItemHolder itemHolder = list.items[i]; MemoryInstanceType value = itemHolder.value; MemoryInstanceType value2 = null; string key = itemHolder.key; bool flag = true; if (fastSortedDictionary2.lookup.TryGetValue(key, out var value3)) { FastSortedHashSet instances = value.instances; HashSet lookup = value3.instances.lookup; FastList list2 = instances.list; for (int j = 0; j < list2.Count; j++) { MemoryObject memoryObject = list2.items[j]; if (lookup.Contains(memoryObject.instanceId)) { continue; } if (flag) { flag = false; if (!difSnapshot.memoryTypesLookup.lookup.TryGetValue(key, out value2)) { value2 = new MemoryInstanceType(value.type); difSnapshot.memoryTypesLookup.Add(key, value2); } } value2.instances.Add(memoryObject.instanceId, new MemoryObject(memoryObject, compareResult)); } } else { value2 = new MemoryInstanceType(value.type); difSnapshot.memoryTypesLookup.Add(key, value2); FastList list3 = value.instances.list; for (int k = 0; k < list3.Count; k++) { value2.instances.Add(list3.items[k].instanceId, new MemoryObject(list3.items[k], compareResult)); } } } } } }