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 0000000..aa7fa2e Binary files /dev/null and b/IllusionPlugin.dll differ