Skip to content

Commit

Permalink
Merge branch 'RazTools:main' into PluginVer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahykal authored Feb 15, 2024
2 parents f800343 + e1d7f53 commit ec365db
Show file tree
Hide file tree
Showing 36 changed files with 1,045 additions and 408 deletions.
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Version**
For example `v1.00.00+9ad92309466f5c929f16d9aa41ddbb6c5e596a3a`.

**Unity Version**
For example `2017.4.30f1`.

**Game/Sample**
Name or download link of the game, or a bunch of sample files used to reproduce the issue.

**Additional context**
Add any other context about the problem here.
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.

# Note: Game decryption requests will not be accepted.
3 changes: 2 additions & 1 deletion AssetStudio.CLI/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<add key="filterPrecision" value="0.25" />
<add key="exportAllNodes" value="True" />
<add key="exportSkins" value="True" />
<add key="exportMaterials" value="False" />
<add key="exportAnimations" value="True" />
<add key="boneSize" value="10" />
<add key="fbxVersion" value="3" />
Expand All @@ -21,7 +22,7 @@
<add key="enableFileLogging" value="False" />
<add key="minimalAssetMap" value="True" />
<add key="allowDuplicates" value="False" />
<add key="texs" value='' />
<add key="texs" value='{}' />
<add key="uvs" value='{"UV0":{"Item1":true,"Item2":0},"UV1":{"Item1":true,"Item2":1},"UV2":{"Item1":false,"Item2":0},"UV3":{"Item1":false,"Item2":0},"UV4":{"Item1":false,"Item2":0},"UV5":{"Item1":false,"Item2":0},"UV6":{"Item1":false,"Item2":0},"UV7":{"Item1":false,"Item2":0}}' />
<add key="types" value='{"Animation":{"Item1":true,"Item2":false},"AnimationClip":{"Item1":true,"Item2":true},"Animator":{"Item1":true,"Item2":true},"AnimatorController":{"Item1":true,"Item2":false},"AnimatorOverrideController":{"Item1":true,"Item2":false},"AssetBundle":{"Item1":true,"Item2":false},"AudioClip":{"Item1":true,"Item2":true},"Avatar":{"Item1":true,"Item2":false},"Font":{"Item1":true,"Item2":true},"GameObject":{"Item1":true,"Item2":false},"IndexObject":{"Item1":true,"Item2":false},"Material":{"Item1":true,"Item2":true},"Mesh":{"Item1":true,"Item2":true},"MeshFilter":{"Item1":true,"Item2":false},"MeshRenderer":{"Item1":true,"Item2":false},"MiHoYoBinData":{"Item1":true,"Item2":true},"MonoBehaviour":{"Item1":true,"Item2":true},"MonoScript":{"Item1":true,"Item2":false},"MovieTexture":{"Item1":true,"Item2":true},"PlayerSettings":{"Item1":true,"Item2":false},"RectTransform":{"Item1":true,"Item2":false},"Shader":{"Item1":true,"Item2":true},"SkinnedMeshRenderer":{"Item1":true,"Item2":false},"Sprite":{"Item1":true,"Item2":true},"SpriteAtlas":{"Item1":true,"Item2":false},"TextAsset":{"Item1":true,"Item2":true},"Texture2D":{"Item1":true,"Item2":true},"Transform":{"Item1":true,"Item2":false},"VideoClip":{"Item1":true,"Item2":true},"ResourceManager":{"Item1":true,"Item2":false}}' />
</appSettings>
Expand Down
6 changes: 3 additions & 3 deletions AssetStudio.CLI/Components/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Options
{
public bool Silent { get; set; }
public LoggerEvent[] LoggerFlags { get; set; }
public ClassIDType[] TypeFilter { get; set; }
public string[] TypeFilter { get; set; }
public Regex[] NameFilter { get; set; }
public Regex[] ContainerFilter { get; set; }
public string GameName { get; set; }
Expand All @@ -71,7 +71,7 @@ public class OptionsBinder : BinderBase<Options>
{
public readonly Option<bool> Silent;
public readonly Option<LoggerEvent[]> LoggerFlags;
public readonly Option<ClassIDType[]> TypeFilter;
public readonly Option<string[]> TypeFilter;
public readonly Option<Regex[]> NameFilter;
public readonly Option<Regex[]> ContainerFilter;
public readonly Option<string> GameName;
Expand All @@ -92,7 +92,7 @@ public OptionsBinder()
{
Silent = new Option<bool>("--silent", "Hide log messages.");
LoggerFlags = new Option<LoggerEvent[]>("--logger_flags", "Flags to control toggle log events.") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Verbose|Debug|Info|etc.." };
TypeFilter = new Option<ClassIDType[]>("--types", "Specify unity class type(s)") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Texture2D|Sprite|etc.." };
TypeFilter = new Option<string[]>("--types", "Specify unity class type(s)") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Texture2D|Shader:Parse|Sprite:Both|etc.." };
NameFilter = new Option<Regex[]>("--names", result => result.Tokens.Select(x => new Regex(x.Value, RegexOptions.IgnoreCase)).ToArray(), false, "Specify name regex filter(s).") { AllowMultipleArgumentsPerToken = true };
ContainerFilter = new Option<Regex[]>("--containers", result => result.Tokens.Select(x => new Regex(x.Value, RegexOptions.IgnoreCase)).ToArray(), false, "Specify container regex filter(s).") { AllowMultipleArgumentsPerToken = true };
GameName = new Option<string>("--game", $"Specify Game.") { IsRequired = true };
Expand Down
26 changes: 25 additions & 1 deletion AssetStudio.CLI/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,24 @@ public static bool ExportAnimator(AssetItem item, string exportPath, List<AssetI
imageFormat = Properties.Settings.Default.convertType,
game = Studio.Game,
collectAnimations = Properties.Settings.Default.collectAnimations,
exportMaterials = Properties.Settings.Default.exportMaterials,
materials = new HashSet<Material>(),
uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(Properties.Settings.Default.uvs),
texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.texs),
};
var convert = animationList != null
? new ModelConverter(m_Animator, options, animationList.Select(x => (AnimationClip)x.Asset).ToArray())
: new ModelConverter(m_Animator, options);
if (options.exportMaterials)
{
var materialExportPath = Path.Combine(Path.GetDirectoryName(exportFullPath), "Materials");
Directory.CreateDirectory(materialExportPath);
foreach (var material in options.materials)
{
var matItem = new AssetItem(material);
ExportJSONFile(matItem, materialExportPath);
}
}
ExportFbx(convert, exportFullPath);
return true;
}
Expand All @@ -381,7 +393,7 @@ public static bool ExportGameObject(AssetItem item, string exportPath, List <Ass
return false;

var m_GameObject = (GameObject)item.Asset;
return ExportGameObject(m_GameObject, exportPath, animationList);
return ExportGameObject(m_GameObject, exportFullPath + Path.DirectorySeparatorChar, animationList);
}

public static bool ExportGameObject(GameObject gameObject, string exportPath, List<AssetItem> animationList = null)
Expand All @@ -391,6 +403,8 @@ public static bool ExportGameObject(GameObject gameObject, string exportPath, Li
imageFormat = Properties.Settings.Default.convertType,
game = Studio.Game,
collectAnimations = Properties.Settings.Default.collectAnimations,
exportMaterials = Properties.Settings.Default.exportMaterials,
materials = new HashSet<Material>(),
uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(Properties.Settings.Default.uvs),
texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.texs),
};
Expand All @@ -403,6 +417,16 @@ public static bool ExportGameObject(GameObject gameObject, string exportPath, Li
Logger.Info($"GameObject {gameObject.m_Name} has no mesh, skipping...");
return false;
}
if (options.exportMaterials)
{
var materialExportPath = Path.Combine(exportPath, "Materials");
Directory.CreateDirectory(materialExportPath);
foreach (var material in options.materials)
{
var matItem = new AssetItem(material);
ExportJSONFile(matItem, materialExportPath);
}
}
exportPath = exportPath + FixFileName(gameObject.m_Name) + ".fbx";
ExportFbx(convert, exportPath);
return true;
Expand Down
90 changes: 66 additions & 24 deletions AssetStudio.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using AssetStudio.CLI.Properties;
using Newtonsoft.Json;
using static AssetStudio.CLI.Studio;
Expand Down Expand Up @@ -40,25 +39,57 @@ public static void Run(Options o)
}

Studio.Game = game;
Logger.Default = new ConsoleLogger() { Flags = o.LoggerFlags.Aggregate((e, x) => e |= x) };
Logger.Default = new ConsoleLogger();
Logger.Flags = o.LoggerFlags.Aggregate((e, x) => e |= x);
Logger.FileLogging = Settings.Default.enableFileLogging;
AssetsHelper.Minimal = Settings.Default.minimalAssetMap;
AssetsHelper.SetUnityVersion(o.UnityVersion);

if (o.TypeFilter == null)
{
TypeFlags.SetTypes(JsonConvert.DeserializeObject<Dictionary<ClassIDType, (bool, bool)>>(Settings.Default.types));
}
else
TypeFlags.SetTypes(JsonConvert.DeserializeObject<Dictionary<ClassIDType, (bool, bool)>>(Settings.Default.types));

var classTypeFilter = Array.Empty<ClassIDType>();
if (!o.TypeFilter.IsNullOrEmpty())
{
foreach (var type in o.TypeFilter)
var classTypeFilterList = new List<ClassIDType>();
for (int i = 0; i < o.TypeFilter.Length; i++)
{
TypeFlags.SetType(type, true, true);
var typeStr = o.TypeFilter[i];
var type = ClassIDType.UnknownType;
var flag = TypeFlag.Both;

try
{
if (typeStr.Contains(':'))
{
var param = typeStr.Split(':');

flag = (TypeFlag)Enum.Parse(typeof(TypeFlag), param[1]);

typeStr = param[0];
}

type = (ClassIDType)Enum.Parse(typeof(ClassIDType), typeStr);

TypeFlags.SetType(type, flag.HasFlag(TypeFlag.Parse), flag.HasFlag(TypeFlag.Export));

classTypeFilterList.Add(type);
}
catch(Exception e)
{
Logger.Error($"{typeStr} has invalid format, skipping...");
continue;
}
}

classTypeFilter = classTypeFilterList.ToArray();

if (ClassIDType.GameObject.CanExport() || ClassIDType.Animator.CanExport())
{
TypeFlags.SetType(ClassIDType.Texture2D, true, false);
if (Settings.Default.exportMaterials)
{
TypeFlags.SetType(ClassIDType.Material, true, false);
}
if (ClassIDType.GameObject.CanExport())
{
TypeFlags.SetType(ClassIDType.Animator, true, false);
Expand All @@ -70,6 +101,11 @@ public static void Run(Options o)
}
}

if (o.GroupAssetsType == AssetGroupOption.ByContainer)
{
TypeFlags.SetType(ClassIDType.AssetBundle, true, false);
}

assetsManager.Silent = o.Silent;
assetsManager.Game = game;
assetsManager.SpecifyUnityVersion = o.UnityVersion;
Expand Down Expand Up @@ -97,28 +133,34 @@ public static void Run(Options o)

if (o.MapOp.HasFlag(MapOpType.CABMap))
{
AssetsHelper.BuildCABMap(files, o.MapName, o.Input.FullName, game);
}
if (o.MapOp.HasFlag(MapOpType.Load))
{
AssetsHelper.LoadCABMapInternal(o.MapName);
assetsManager.ResolveDependencies = true;
if (o.MapOp.HasFlag(MapOpType.Load))
{
AssetsHelper.BuildCABMap(files, o.MapName, o.Input.FullName, game);
}
else
{
AssetsHelper.LoadCABMapInternal(o.MapName);
assetsManager.ResolveDependencies = true;
}
}
if (o.MapOp.HasFlag(MapOpType.AssetMap))
{
if (files.Length == 1)
if (o.MapOp.HasFlag(MapOpType.Load))
{
files = AssetsHelper.ParseAssetMap(o.MapName, o.MapType, classTypeFilter, o.NameFilter, o.ContainerFilter);
}
else
{
throw new Exception("Unable to build AssetMap with input_path as a file !!");
if (files.Length == 1)
{
throw new Exception("Unable to build AssetMap with input_path as a file !!");
}
AssetsHelper.BuildAssetMap(files, o.MapName, game, o.Output.FullName, o.MapType, classTypeFilter, o.NameFilter, o.ContainerFilter);
}
var resetEvent = new ManualResetEvent(false);
AssetsHelper.BuildAssetMap(files, o.MapName, game, o.Output.FullName, o.MapType, resetEvent, o.TypeFilter, o.NameFilter, o.ContainerFilter);
resetEvent.WaitOne();
}
if (o.MapOp.HasFlag(MapOpType.Both))
{
var resetEvent = new ManualResetEvent(false);
AssetsHelper.BuildBoth(files, o.MapName, o.Input.FullName, game, o.Output.FullName, o.MapType, resetEvent, o.TypeFilter, o.NameFilter, o.ContainerFilter);
resetEvent.WaitOne();
AssetsHelper.BuildBoth(files, o.MapName, o.Input.FullName, game, o.Output.FullName, o.MapType, classTypeFilter, o.NameFilter, o.ContainerFilter);
}
if (o.MapOp.Equals(MapOpType.None) || o.MapOp.HasFlag(MapOpType.Load))
{
Expand All @@ -134,7 +176,7 @@ public static void Run(Options o)
assetsManager.LoadFiles(file);
if (assetsManager.assetsFileList.Count > 0)
{
BuildAssetData(o.TypeFilter, o.NameFilter, o.ContainerFilter, ref i);
BuildAssetData(classTypeFilter, o.NameFilter, o.ContainerFilter, ref i);
ExportAssets(o.Output.FullName, exportableAssets, o.GroupAssetsType, o.AssetExportType);
}
exportableAssets.Clear();
Expand Down
1 change: 1 addition & 0 deletions AssetStudio.CLI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Settings
public decimal filterPrecision => AppSettings.Get("filterPrecision", (decimal)0.25);
public bool exportAllNodes => AppSettings.Get("exportAllNodes", true);
public bool exportSkins => AppSettings.Get("exportSkins", true);
public bool exportMaterials => AppSettings.Get("exportMaterials", false);
public bool collectAnimations => AppSettings.Get("collectAnimations", true);
public bool exportAnimations => AppSettings.Get("exportAnimations", true);
public decimal boneSize => AppSettings.Get("boneSize", (decimal)10);
Expand Down
Loading

0 comments on commit ec365db

Please sign in to comment.