Files
2026-03-04 09:37:33 +08:00

116 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace DebuggingEssentials
{
public class CustomAssembly : IComparable<CustomAssembly>
{
public string name;
public Assembly assembly;
public AssemblyType type;
public FastSortedDictionary<string, NamespaceTypes> namespaceLookup = new FastSortedDictionary<string, NamespaceTypes>(128);
public FastList<CustomType> types = new FastList<CustomType>();
public FastList<CustomType> allTypes = new FastList<CustomType>();
public void Sort()
{
Array.Sort(types.items, 0, types.Count);
namespaceLookup.Sort(CompareMode.Key);
}
public int CompareTo(CustomAssembly other)
{
return string.Compare(name, other.name);
}
public static void InitAssemblies(ref bool hasInitAssemblies, FastList<CustomAssembly> customAssemblies, Dictionary<NamespaceTypes, RuntimeInspector.DrawInfo> namespaceTypesLookup, Dictionary<string, FastList<Type>> typeNameLookup)
{
hasInitAssemblies = true;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
CustomAssembly customAssembly = new CustomAssembly();
Assembly assembly = (customAssembly.assembly = assemblies[i]);
customAssemblies.Add(customAssembly);
string text = (customAssembly.name = assembly.GetName().Name);
bool flag = false;
if (text.IndexOf("unity", StringComparison.OrdinalIgnoreCase) != -1)
{
customAssembly.type = AssemblyType.Unity;
}
else if (text.IndexOf("system", StringComparison.OrdinalIgnoreCase) != -1 || text == "mscorlib")
{
customAssembly.type = AssemblyType.System;
}
else if (text.IndexOf("mono", StringComparison.OrdinalIgnoreCase) != -1)
{
customAssembly.type = AssemblyType.Mono;
}
else
{
customAssembly.type = AssemblyType.Other;
if (text == "Assembly-CSharp-Editor" || text == "Assembly-CSharp-Editor-firstpass")
{
flag = true;
}
}
Type[] array;
try
{
array = assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
array = ex.Types.Where((Type x) => x != null).ToArray();
}
foreach (Type type in array)
{
if (customAssembly.type == AssemblyType.Other && !flag)
{
RuntimeConsole.RegisterStaticType(type);
}
CustomType item = new CustomType(customAssembly, type);
customAssembly.allTypes.Add(item);
string text2 = type.Namespace;
if (text2 == null)
{
customAssembly.types.Add(item);
}
else
{
if (!customAssembly.namespaceLookup.lookup.TryGetValue(text2, out var value))
{
value = new NamespaceTypes(customAssembly, text2);
customAssembly.namespaceLookup.Add(text2, value);
}
value.types.Add(new CustomType(value, type));
}
string key = type.Name;
if (!typeNameLookup.TryGetValue(key, out var value2))
{
if (value2 == null)
{
value2 = new FastList<Type>();
}
typeNameLookup[key] = value2;
}
value2.Add(type);
}
}
Array.Sort(customAssemblies.items, 0, customAssemblies.Count);
for (int num2 = 0; num2 < customAssemblies.Count; num2++)
{
customAssemblies.items[num2].Sort();
}
RuntimeConsole.SortCommandsTable();
}
}
}