Browse Source

Add single asset bundle inspection

master
NGnius (Graham) 4 years ago
parent
commit
6b505bf18d
5 changed files with 66 additions and 20 deletions
  1. +1
    -1
      Dissonance/Dissonance.csproj
  2. +2
    -2
      Dissonance/DissonancePatch.cs
  3. +3
    -3
      Dissonance/DissonancePlugin.cs
  4. +59
    -13
      Dissonance/Inspector/AssetInspector.cs
  5. +1
    -1
      Dissonance/Inspector/Instance.cs

+ 1
- 1
Dissonance/Dissonance.csproj View File

@@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="1.2.0.1" />
<PackageReference Include="Lib.Harmony" Version="2.0.1" />
</ItemGroup>

<ItemGroup>


+ 2
- 2
Dissonance/DissonancePatch.cs View File

@@ -1,6 +1,6 @@
using System;
using System.Reflection;
using Harmony;
using HarmonyLib;
using UnityEngine;

namespace Dissonance
@@ -14,7 +14,7 @@ namespace Dissonance
}

[HarmonyTargetMethod]
static MethodBase DissonanceMethod(HarmonyInstance instance)
static MethodBase DissonanceMethod(Harmony instance)
{
throw new NotImplementedException();
}


+ 3
- 3
Dissonance/DissonancePlugin.cs View File

@@ -1,14 +1,14 @@
using System;
using IllusionPlugin;
using UnityEngine;
using Harmony;
using HarmonyLib;
using System.Reflection;

namespace Dissonance
{
public class DissonancePlugin : IllusionPlugin.IEnhancedPlugin
{
public static HarmonyInstance harmony { get; protected set; }
public static Harmony harmony { get; protected set; }

public string[] Filter { get; } = new string[] { "Gamecraft" };

@@ -28,7 +28,7 @@ namespace Dissonance
{
if (harmony == null)
{
harmony = HarmonyInstance.Create(HarmonyID);
harmony = new Harmony(HarmonyID);
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
Debug.Log(Name + " start & patch complete");


+ 59
- 13
Dissonance/Inspector/AssetInspector.cs View File

@@ -34,11 +34,27 @@ namespace Dissonance.Inspector
Debug.Log("AssetInspector Log dump\n[" + string.Join(",\n", filelines) + "]");
}

public static void Log<T>(AssetBundle assetBundle) where T : UnityEngine.Object
{
Instance[] instances = Inspect<T>(assetBundle);
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 LogNames<T>(AssetBundle assetBundle) where T : UnityEngine.Object
{
Debug.Log(string.Join("\n", InspectNames<T>(assetBundle)));
}

public static void LogAll()
{
Log<UnityEngine.Object>();
@@ -60,14 +76,25 @@ namespace Dissonance.Inspector
File.WriteAllLines(filename, filelines);
}

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

public static void DumpNamesAll(string filename)
@@ -75,32 +102,51 @@ namespace Dissonance.Inspector
DumpNames<UnityEngine.Object>(filename);
}

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

public static Instance[] Inspect<T>() where T : UnityEngine.Object
{
if (allBundles == null) Init();
List<Instance> allInstances = new List<Instance>();
foreach (var b in allBundles)
{
UnityEngine.Object[] assets = b.LoadAllAssets<T>();
for (int i = 0; i < assets.Length; i++)
{
allInstances.Add(new Instance(assets[i]));
}
allInstances.AddRange(Inspect<T>(b));
}
return allInstances.ToArray();
}

public static string[] InspectNames<T>() where T : UnityEngine.Object
public static Instance[] Inspect<T>(AssetBundle assetBundle) where T : UnityEngine.Object
{
List<Instance> allInstances = new List<Instance>();
UnityEngine.Object[] assets = assetBundle.LoadAllAssets<T>();
for (int i = 0; i < assets.Length; i++)
{
allInstances.Add(new Instance(assets[i]));
}
return allInstances.ToArray();
}

public static string[] InspectNames<T>() where T : UnityEngine.Object
{
if (allBundles == null) Init();
List<string> allNames = new List<string>();
foreach (var b in allBundles)
{
UnityEngine.Object[] assets = b.LoadAllAssets<T>();
for (int i = 0; i < assets.Length; i++)
{
allNames.Add(assets[i].name);
}
allNames.AddRange(InspectNames<T>(b));
}
return allNames.ToArray();
}

public static string[] InspectNames<T>(AssetBundle assetBundle) where T : UnityEngine.Object
{
List<string> allNames = new List<string>();
UnityEngine.Object[] assets = assetBundle.LoadAllAssets<T>();
for (int i = 0; i < assets.Length; i++)
{
allNames.Add(assets[i].name);
}
return allNames.ToArray();
}


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

@@ -116,7 +116,7 @@ namespace Dissonance.Inspector
count++;
}
sb.Append("\n]\n");
sb.Append("}");
sb.Append("},");
return sb.ToString();
}
}


Loading…
Cancel
Save