From 8bddf7ea5a73217d5c54e155f1fafc3bd1de0c0d Mon Sep 17 00:00:00 2001 From: NGnius Date: Fri, 8 Nov 2019 21:38:31 -0500 Subject: [PATCH] Create Unity Object inspector ripper --- .gitattributes | 63 ++++++++++++ .gitignore | 11 ++- Dissonance.sln | 25 +++++ Dissonance/Dissonance.csproj | 23 +++++ Dissonance/DissonancePatch.cs | 22 +++++ Dissonance/DissonancePlugin.cs | 64 ++++++++++++ Dissonance/Inspector/Instance.cs | 123 ++++++++++++++++++++++++ Dissonance/Inspector/ObjectInspector.cs | 85 ++++++++++++++++ IllusionPlugin.dll | Bin 0 -> 6656 bytes 9 files changed, 414 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 Dissonance.sln create mode 100644 Dissonance/Dissonance.csproj create mode 100644 Dissonance/DissonancePatch.cs create mode 100644 Dissonance/DissonancePlugin.cs create mode 100644 Dissonance/Inspector/Instance.cs create mode 100644 Dissonance/Inspector/ObjectInspector.cs create mode 100644 IllusionPlugin.dll diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index 6db9ba9..0bda091 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -# ---> VisualStudio ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## @@ -21,6 +20,8 @@ [Rr]eleases/ x64/ x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ bld/ [Bb]in/ [Oo]bj/ @@ -210,7 +211,7 @@ _pkginfo.txt # files ending in .cache can be ignored *.[Cc]ache # but keep track of directories ending in .cache -!*.[Cc]ache/ +!?*.[Cc]ache/ # Others ClientBin/ @@ -254,6 +255,7 @@ ServiceFabricBackup/ *.bim.layout *.bim_*.settings *.rptproj.rsuser +*- Backup*.rdl # Microsoft Fakes FakesAssemblies/ @@ -334,3 +336,8 @@ ASALocalRun/ # Local History for Visual Studio .localhistory/ +# BeatPulse healthcheck temp database +healthchecksdb + +# references +ref diff --git a/Dissonance.sln b/Dissonance.sln new file mode 100644 index 0000000..7ac2a84 --- /dev/null +++ b/Dissonance.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29411.108 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dissonance", "Dissonance\Dissonance.csproj", "{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {72FB94D0-6C50-475B-81E0-C94C7D7A2A17} + EndGlobalSection +EndGlobal diff --git a/Dissonance/Dissonance.csproj b/Dissonance/Dissonance.csproj new file mode 100644 index 0000000..443fb59 --- /dev/null +++ b/Dissonance/Dissonance.csproj @@ -0,0 +1,23 @@ + + + + net48 + + + + + + + + + ..\IllusionPlugin.dll + + + ..\ref\Gamecraft_Data\Managed\UnityEngine.dll + + + ..\ref\Gamecraft_Data\Managed\UnityEngine.CoreModule.dll + + + + diff --git a/Dissonance/DissonancePatch.cs b/Dissonance/DissonancePatch.cs new file mode 100644 index 0000000..22ec5f9 --- /dev/null +++ b/Dissonance/DissonancePatch.cs @@ -0,0 +1,22 @@ +using System; +using System.Reflection; +using Harmony; +using UnityEngine; + +namespace Dissonance +{ + //[HarmonyPatch] + class DissonancePatch + { + static void Prefix() + { + Debug.Log("Prefix"); + } + + [HarmonyTargetMethod] + static MethodBase DissonanceMethod(HarmonyInstance instance) + { + throw new NotImplementedException(); + } + } +} diff --git a/Dissonance/DissonancePlugin.cs b/Dissonance/DissonancePlugin.cs new file mode 100644 index 0000000..c1a2044 --- /dev/null +++ b/Dissonance/DissonancePlugin.cs @@ -0,0 +1,64 @@ +using System; +using IllusionPlugin; +using UnityEngine; +using Harmony; +using System.Reflection; + +namespace Dissonance +{ + public class DissonancePlugin : IllusionPlugin.IEnhancedPlugin + { + public static HarmonyInstance harmony { get; protected set; } + + public string[] Filter { get; } = new string[] { "Gamecraft" }; + + public string Name { get; } = "Dissonance"; + + public string Version { get; } = "A"; + + public string HarmonyID { get; } = "org.git.exmods.modtainers.dissonance"; + + public void OnApplicationQuit() + { + harmony.UnpatchAll(HarmonyID); + Inspector.ObjectInspector.LogAll(); + Debug.Log(Name + " shutdown complete"); + } + + public void OnApplicationStart() + { + if (harmony == null) + { + harmony = HarmonyInstance.Create(HarmonyID); + harmony.PatchAll(Assembly.GetExecutingAssembly()); + } + Inspector.ObjectInspector.LogAll(); + Debug.Log(Name + " start & patch complete"); + } + + public void OnFixedUpdate() + { + //throw new NotImplementedException(); + } + + public void OnLateUpdate() + { + //throw new NotImplementedException(); + } + + public void OnLevelWasInitialized(int level) + { + //throw new NotImplementedException(); + } + + public void OnLevelWasLoaded(int level) + { + //throw new NotImplementedException(); + } + + public void OnUpdate() + { + //throw new NotImplementedException(); + } + } +} diff --git a/Dissonance/Inspector/Instance.cs b/Dissonance/Inspector/Instance.cs new file mode 100644 index 0000000..2208e75 --- /dev/null +++ b/Dissonance/Inspector/Instance.cs @@ -0,0 +1,123 @@ +using System; +using System.Reflection; +using System.Collections.Generic; +using System.Text; +using UnityEngine; + +namespace Dissonance.Inspector +{ + public struct Instance + { + public string name; + + public UnityEngine.Object obj; + + public Type type; + + public MethodBase[] methods; + + public Dictionary properties; + + public UnityEngine.HideFlags hideFlags; + + public Instance(UnityEngine.Object obj) + { + this.name = obj.name; + this.obj = obj; + this.type = obj.GetType(); + this.methods = this.type.GetMethods(); + this.properties = new Dictionary(); + foreach (PropertyInfo propInf in this.type.GetProperties()) + { + if (propInf.CanRead && propInf.GetGetMethod().IsPublic) + { + this.properties.Add(propInf.Name, propInf.GetValue(obj)); + } + } + this.hideFlags = obj.hideFlags; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("{\n"); + if (type != null && type.FullName != null) + { + sb.Append($"\"type\": \"{type.FullName}\",\n"); + } + if (name != null) + { + sb.Append($"\"name\": \"{name}\",\n"); + } + if (obj != null) + { + sb.Append($"\"object\": \"{obj.ToString()}\",\n"); + } else + { + sb.Append($"\"object\": null,\n"); + } + sb.Append($"\"hideFlags\": \"{hideFlags}\",\n"); + sb.Append("\"properties\": {\n"); + int count = 1; + foreach (string key in properties.Keys) + { + if (properties[key] != null) + { + sb.Append($" \"{key}\": \"{properties[key].ToString()}\""); + } else + { + sb.Append($" \"{key}\": null"); + } + if (count != properties.Keys.Count) + { + sb.Append(",\n"); + } + count++; + } + sb.Append("\n},\n"); + sb.Append("\"methods\": [\n"); + count = 1; + foreach (MethodBase m in methods) + { + sb.Append($" \"{m.Name}"); + if (m.ContainsGenericParameters) + { + sb.Append("<"); + Type[] genArgs = m.GetGenericArguments(); + int argCount = 1; + foreach (Type t in genArgs) + { + sb.Append(t.Name); + if (argCount != genArgs.Length) + { + sb.Append(","); + } + argCount++; + } + sb.Append(">"); + } + sb.Append("("); + ParameterInfo[] parameters = m.GetParameters(); + int paramCount = 1; + foreach(ParameterInfo p in parameters) + { + sb.Append($"{p.ParameterType.FullName} {p.Name}"); + if (paramCount != parameters.Length) + { + sb.Append(", "); + } + paramCount++; + } + sb.Append(")\""); + if (count != methods.Length) + { + sb.Append(",\n"); + } + count++; + } + sb.Append("\n]\n"); + sb.Append("}"); + return sb.ToString(); + } + } +} diff --git a/Dissonance/Inspector/ObjectInspector.cs b/Dissonance/Inspector/ObjectInspector.cs new file mode 100644 index 0000000..292a4a3 --- /dev/null +++ b/Dissonance/Inspector/ObjectInspector.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using UnityEngine; + +namespace Dissonance.Inspector +{ + public class ObjectInspector + { + public static void Log() where T : UnityEngine.Object + { + Instance[] instances = Inspect(); + string[] filelines = new string[instances.Length]; + for (int i = 0; i < instances.Length; i++) + { + filelines[i] = instances[i].ToString() + ","; + } + Debug.Log("ObjectInspector Log dump\n["+string.Join(",\n", filelines)+"]"); + } + + public static void LogNames() where T : UnityEngine.Object + { + Debug.Log(string.Join("\n", InspectNames())); + } + + public static void LogAll() + { + Log(); + } + + public static void LogNamesAll() + { + LogNames(); + } + + public static void Dump(string filename) where T : UnityEngine.Object + { + Instance[] instances = Inspect(); + string[] filelines = new string[instances.Length]; + for (int i = 0; i < instances.Length; i++) + { + filelines[i] = instances[i].ToString()+","; + } + File.WriteAllLines(filename, filelines); + } + + public static void DumpNames(string filename) where T : UnityEngine.Object + { + File.WriteAllLines(filename, InspectNames()); + } + + public static void DumpAll(string filename) + { + Dump(filename); + } + + public static void DumpNamesAll(string filename) + { + DumpNames(filename); + } + + public static Instance[] Inspect() where T : UnityEngine.Object + { + T[] objects = UnityEngine.Object.FindObjectsOfType(); + Instance[] instances = new Instance[objects.Length]; + for (int i = 0; i < objects.Length; i++) + { + instances[i] = new Instance(objects[i]); + } + return instances; + } + + public static string[] InspectNames() where T : UnityEngine.Object + { + T[] objects = UnityEngine.Object.FindObjectsOfType(); + string[] names = new string[objects.Length]; + for(int i = 0; i < objects.Length; i++) + { + names[i] = objects[i].name; + } + return names; + } + } +} diff --git a/IllusionPlugin.dll b/IllusionPlugin.dll new file mode 100644 index 0000000000000000000000000000000000000000..aa7fa2e7bde11b7bad935de118a11c36e033c226 GIT binary patch literal 6656 zcmeHLYiu0V6+ZLW^?JS8_>~8Qlp#*(632^QA&&y}W1VChCvm)f@GwngcgO1?vop)g ztQ)5SB|i$JfSR-w0zrQi2{lx-fK)_iOIv{ywH5qme-x=g2(?mCrAqWiA5bFF@7$TS z*Kvr1R3s|(+H>xC-E+>p_uO-5Xa60iNg*N?&&7*G=g@N-5b(<21jNZ}f0CphH@n7$*Ppi02$<@nRLAPzk*YbwuR&C9+wamesR(6U;d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