Browse Source

Add asset bundle inspection functionality

master
NGnius 5 years ago
parent
commit
c854265ff2
4 changed files with 109 additions and 5 deletions
  1. +3
    -0
      Dissonance/Dissonance.csproj
  2. +2
    -4
      Dissonance/DissonancePlugin.cs
  3. +103
    -0
      Dissonance/Inspector/AssetInspector.cs
  4. +1
    -1
      Dissonance/Inspector/ObjectInspector.cs

+ 3
- 0
Dissonance/Dissonance.csproj View File

@@ -18,6 +18,9 @@
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\ref\Gamecraft_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule">
<HintPath>..\ref\Gamecraft_Data\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

+ 2
- 4
Dissonance/DissonancePlugin.cs View File

@@ -14,14 +14,13 @@ namespace Dissonance

public string Name { get; } = "Dissonance";

public string Version { get; } = "A";
public string Version { get; } = "B";

public string HarmonyID { get; } = "org.git.exmods.modtainers.dissonance";

public void OnApplicationQuit()
{
harmony.UnpatchAll(HarmonyID);
Inspector.ObjectInspector.LogAll();
harmony.UnpatchAll(HarmonyID); // likely unnecessary
Debug.Log(Name + " shutdown complete");
}

@@ -32,7 +31,6 @@ namespace Dissonance
harmony = HarmonyInstance.Create(HarmonyID);
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
Inspector.ObjectInspector.LogAll();
Debug.Log(Name + " start & patch complete");
}



+ 103
- 0
Dissonance/Inspector/AssetInspector.cs View File

@@ -0,0 +1,103 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Dissonance.Inspector
{
public static class AssetInspector
{
private static AssetBundle bundle;

public static bool Init()
{
foreach(AssetBundle ab in AssetBundle.GetAllLoadedAssetBundles())
{
if (ab != null)
{
bundle = ab;
}
}
Debug.Log($"Dissonance: Found AssetBundle {bundle.name}");
return bundle != null;
}

public static void Log<T>() where T : UnityEngine.Object
{
Instance[] instances = Inspect<T>();
string[] filelines = new string[instances.Length];
for (int i = 0; i < instances.Length; i++)
{
filelines[i] = instances[i].ToString() + ",";
}
Debug.Log("AssetInspector Log dump\n[" + string.Join(",\n", filelines) + "]");
}

public static void LogNames<T>() where T : UnityEngine.Object
{
Debug.Log(string.Join("\n", InspectNames<T>()));
}

public static void LogAll()
{
Log<UnityEngine.Object>();
}

public static void LogNamesAll()
{
LogNames<UnityEngine.Object>();
}

public static void Dump<T>(string filename) where T : UnityEngine.Object
{
Instance[] instances = Inspect<T>();
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<T>(string filename) where T : UnityEngine.Object
{
File.WriteAllLines(filename, InspectNames<T>());
}

public static void DumpAll(string filename)
{
Dump<UnityEngine.Object>(filename);
}

public static void DumpNamesAll(string filename)
{
DumpNames<UnityEngine.Object>(filename);
}

public static Instance[] Inspect<T>() where T : UnityEngine.Object
{
if (bundle == null) Init();
UnityEngine.Object[] assets = bundle.LoadAllAssets<T>();
Instance[] instances = new Instance[assets.Length];
for (int i = 0; i < assets.Length; i++)
{
instances[i] = new Instance(assets[i]);
}
return instances;
}

public static string[] InspectNames<T>() where T : UnityEngine.Object
{
if (bundle == null) Init();
UnityEngine.Object[] assets = bundle.LoadAllAssets<T>();
string[] names = new string[assets.Length];
for (int i = 0; i < assets.Length; i++)
{
names[i] = assets[i].name;
}
return names;
}
}
}

+ 1
- 1
Dissonance/Inspector/ObjectInspector.cs View File

@@ -6,7 +6,7 @@ using UnityEngine;

namespace Dissonance.Inspector
{
public class ObjectInspector
public static class ObjectInspector
{
public static void Log<T>() where T : UnityEngine.Object
{


Loading…
Cancel
Save