-
-
Save yekoc/d632468df9ebc53641170301ac2f67ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Awake of your mod | |
RoR2Application.onLoad += Thing; | |
public static void OutputComponents(StringBuilder sb, Component[] components, string delimi) { | |
foreach (Component component in components) { | |
OutputUnityObject(sb, component, delimi); | |
} | |
} | |
public static void OutputUnityObject(StringBuilder sb, UnityEngine.Object unityObject, string delimi) { | |
sb.Append($"\n{delimi} "); | |
if (unityObject is Transform transform) { | |
var transformOutput = $"transform = p: {transform.localPosition} r: {transform.eulerAngles} s: {transform.localScale}"; | |
sb.Append(transformOutput); | |
} | |
else if(unityObject is EntityStateConfiguration esc){ | |
sb.AppendLine("EntityStateConfiguration: " + esc.targetType.LookupType().Name); | |
if(!esc.serializedFieldsCollection.serializedFields.Any()){ | |
sb.AppendLine($"{delimi} <Empty>"); | |
} | |
else{ | |
foreach(var field in esc.serializedFieldsCollection.serializedFields){ | |
try{ | |
var fieldOutput = $"{delimi}v {field.fieldName} = {(field.fieldValue.objectValue ? field.fieldValue.objectValue : field.fieldValue.stringValue)}"; | |
sb.AppendLine(fieldOutput); | |
} | |
catch(Exception e){ | |
//R2API.LogError(e); | |
} | |
} | |
} | |
} | |
else { | |
Type type = unityObject.GetType(); | |
sb.AppendLine(type.FullName); | |
foreach (FieldInfo fieldInfo in type.GetFields((BindingFlags)(-1))) { | |
try { | |
string fieldOutput; | |
if(unityObject is not RoR2.Navigation.NodeGraph && typeof(System.Collections.ICollection).IsAssignableFrom(fieldInfo.FieldType)){ //Nodegraphs are too meaninglessly large to expand,consider finding some method of visualisation if you wish to analyze them. | |
fieldOutput = $"{delimi}v {fieldInfo.Name} = {{ "; | |
foreach(var value in fieldInfo.GetValue(unityObject) as System.Collections.IEnumerable){ | |
fieldOutput += value; | |
fieldOutput += ","; | |
} | |
fieldOutput = fieldOutput.TrimEnd(','); | |
fieldOutput += " }"; | |
} | |
else{ | |
fieldOutput = $"{delimi}v {fieldInfo.Name} = {fieldInfo.GetValue(unityObject)}"; | |
} | |
sb.AppendLine(fieldOutput); | |
} | |
catch (Exception e) { | |
//R2API.Logger.LogError(e); | |
} | |
} | |
foreach (PropertyInfo propertyInfo in type.GetProperties((BindingFlags)(-1))) { | |
if(propertyInfo.Name == "renderingDisplaySize" && unityObject is Canvas){ //Crash-preventation | |
continue; | |
} | |
try { | |
if (propertyInfo.GetAccessors() != null && propertyInfo.GetAccessors().Length > 0) { | |
var fieldOutput = $"{delimi}v {propertyInfo.Name} = {propertyInfo.GetValue(unityObject)}"; | |
sb.AppendLine(fieldOutput); | |
} | |
} | |
catch (Exception e) { | |
//R2API.Logger.LogError(e); | |
} | |
} | |
} | |
} | |
public static void GetChildren(StringBuilder sb, Transform transform, string delimi) { | |
for (var i = 0; i < transform.childCount; i++) { | |
GameObject gameObject = transform.GetChild(i).gameObject; | |
var childGameObjectHeader = $"\n{delimi}GameObject Children {i} {gameObject.name}"; | |
sb.AppendLine(childGameObjectHeader); | |
Component[] components = gameObject.GetComponents<Component>(); | |
OutputComponents(sb, components, delimi + ">"); | |
GetChildren(sb, transform.GetChild(i), delimi + ">"); | |
} | |
} | |
private static void Thing() { | |
UnityEngine.Object assetlazy = Addressables.LoadAssetAsync<UnityEngine.Object>("RoR2/Base/Huntress/Skins.Huntress.Alt1.asset").WaitForCompletion(); | |
R2API.Logger.LogError(assetlazy); | |
var i = 0; | |
foreach (UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator item in Addressables.ResourceLocators) { | |
foreach (var key in item.Keys) { | |
try { | |
i++; | |
if (key.ToString().Contains("bundle")) { | |
continue; | |
} | |
if (!key.ToString().Contains(".")) { | |
} | |
else { | |
var digitCount = 0; | |
foreach (var c in key.ToString()) { | |
if (char.IsDigit(c)) { | |
digitCount++; | |
if (digitCount > 5) { | |
break; | |
} | |
} | |
} | |
if (digitCount > 5) { | |
continue; | |
} | |
R2API.Logger.LogError(i + " | " + key.ToString()); | |
UnityEngine.Object asset = Addressables.LoadAssetAsync<UnityEngine.Object>(key).WaitForCompletion(); | |
if (asset) { | |
var sb = new StringBuilder(); | |
sb.AppendLine("Key Path : " + key.ToString() + " | UnityObject Type : " + asset.GetType() + " | UnityObject Name : " + asset.name); | |
if (asset is GameObject go) { | |
Component[] components = go.GetComponents<Component>(); | |
OutputComponents(sb, components, ">"); | |
GetChildren(sb, go.transform, ">"); | |
DumpToFile(key, sb); | |
} | |
else if (asset is UnityEngine.Object unityObject) { | |
OutputUnityObject(sb, unityObject, ">"); | |
DumpToFile(key, sb); | |
} | |
} | |
} | |
} | |
catch (Exception e) { | |
R2API.Logger.LogError(e); | |
} | |
} | |
} | |
} | |
private static void DumpToFile(object key, StringBuilder sb) { | |
const string dumpFolder = @"folder_path"; | |
var relativeFilePathTxt = System.IO.Path.ChangeExtension(key.ToString(), ".txt"); | |
var fullFilePath = System.IO.Path.Combine(dumpFolder, relativeFilePathTxt); | |
var directoryPath = System.IO.Path.GetDirectoryName(fullFilePath); | |
Directory.CreateDirectory(directoryPath); | |
File.WriteAllText(fullFilePath, sb.ToString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment