Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
- [Core] changes to AssetsHelper.
Browse files Browse the repository at this point in the history
- [CLI] changes to `AssetsHelper`.
- [GUI] Added option to load external `CABMap` files
  • Loading branch information
Razmoth committed Oct 25, 2023
1 parent 57d78db commit fabdaec
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 39 deletions.
2 changes: 1 addition & 1 deletion AssetStudio.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void Run(Options o)
}
if (o.MapOp.HasFlag(MapOpType.Load))
{
AssetsHelper.LoadCABMap(o.MapName);
AssetsHelper.LoadCABMapInternal(o.MapName);
assetsManager.ResolveDependencies = true;
}
if (o.MapOp.HasFlag(MapOpType.AssetMap))
Expand Down
23 changes: 16 additions & 7 deletions AssetStudio.GUI/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions AssetStudio.GUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void InitalizeOptions()
{
var assetMapType = (ExportListType)Properties.Settings.Default.assetMapType;
var assetMapTypes = Enum.GetValues<ExportListType>().ToArray()[1..];
foreach(var mapType in assetMapTypes)
foreach (var mapType in assetMapTypes)
{
var menuItem = new ToolStripMenuItem(mapType.ToString()) { CheckOnClick = true, Checked = assetMapType.HasFlag(mapType), Tag = (int)mapType };
assetMapTypeMenuItem.DropDownItems.Add(menuItem);
Expand All @@ -166,7 +166,7 @@ private void InitalizeOptions()
MapNameComboBox.SelectedIndexChanged += new EventHandler(specifyNameComboBox_SelectedIndexChanged);
if (!string.IsNullOrEmpty(Properties.Settings.Default.selectedCABMapName))
{
if (!AssetsHelper.LoadCABMap(Properties.Settings.Default.selectedCABMapName))
if (!AssetsHelper.LoadCABMapInternal(Properties.Settings.Default.selectedCABMapName))
{
Properties.Settings.Default.selectedCABMapName = "";
Properties.Settings.Default.Save();
Expand Down Expand Up @@ -2063,7 +2063,7 @@ private void assetMapTypeMenuItem_DropDownItemClicked(object sender, ToolStripIt
Properties.Settings.Default.assetMapType = assetMapType;
Properties.Settings.Default.Save();
}

}
private void modelsOnly_CheckedChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -2111,7 +2111,7 @@ private async void specifyNameComboBox_SelectedIndexChanged(object sender, Event
var name = MapNameComboBox.SelectedItem.ToString();
await Task.Run(() =>
{
if (AssetsHelper.LoadCABMap(name))
if (AssetsHelper.LoadCABMapInternal(name))
{
Properties.Settings.Default.selectedCABMapName = name;
Properties.Settings.Default.Save();
Expand Down Expand Up @@ -2340,6 +2340,20 @@ private async void loadAIToolStripMenuItem_Click(object sender, EventArgs e)
}
}

private async void loadCABMapToolStripMenuItem_Click(object sender, EventArgs e)
{
miscToolStripMenuItem.DropDown.Visible = false;

var openFileDialog = new OpenFileDialog() { Multiselect = false, Filter = "CABMap File|*.bin" };
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
var path = openFileDialog.FileName;
InvokeUpdate(loadCABMapToolStripMenuItem, false);
await Task.Run(() => AssetsHelper.LoadCABMap(path));
InvokeUpdate(loadCABMapToolStripMenuItem, true);
}
}

private void clearConsoleToolStripMenuItem_Click(object sender, EventArgs e)
{
Console.Clear();
Expand Down
80 changes: 53 additions & 27 deletions AssetStudio/AssetsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Xml;
using System.Text;
using MessagePack;
using System.Reflection.Metadata.Ecma335;

namespace AssetStudio
{
Expand Down Expand Up @@ -244,37 +245,15 @@ private static void DumpCABMap(string mapName)
}
}

public static bool LoadCABMap(string mapName)
public static bool LoadCABMapInternal(string mapName)
{
Logger.Info($"Loading {mapName}");
Logger.Info($"Loading {mapName}...");
try
{
CABMap.Clear();
using (var fs = File.OpenRead(Path.Combine(MapName, $"{mapName}.bin")))
using (var reader = new BinaryReader(fs))
{
BaseFolder = reader.ReadString();
var count = reader.ReadInt32();
for (int i = 0; i < count; i++)
{
var cab = reader.ReadString();
var path = reader.ReadString();
var offset = reader.ReadInt64();
var depCount = reader.ReadInt32();
var dependencies = new string[depCount];
for (int j = 0; j < depCount; j++)
{
dependencies[j] = reader.ReadString();
}
var entry = new Entry()
{
Path = path,
Offset = offset,
Dependencies = dependencies
};
CABMap.Add(cab, entry);
}
}
using var fs = File.OpenRead(Path.Combine(MapName, $"{mapName}.bin"));
using var reader = new BinaryReader(fs);
ParseCABMap(reader);
Logger.Verbose($"Initialized CABMap with {CABMap.Count} entries");
Logger.Info($"Loaded {mapName} !!");
}
Expand All @@ -287,6 +266,53 @@ public static bool LoadCABMap(string mapName)
return true;
}

public static bool LoadCABMap(string path)
{
var mapName = Path.GetFileNameWithoutExtension(path);
Logger.Info($"Loading {mapName}...");
try
{
CABMap.Clear();
using var fs = File.OpenRead(path);
using var reader = new BinaryReader(fs);
ParseCABMap(reader);
Logger.Verbose($"Initialized CABMap with {CABMap.Count} entries");
Logger.Info($"Loaded {mapName} !!");
}
catch (Exception e)
{
Logger.Warning($"{mapName} was not loaded, {e}");
return false;
}

return true;
}

private static void ParseCABMap(BinaryReader reader)
{
BaseFolder = reader.ReadString();
var count = reader.ReadInt32();
for (int i = 0; i < count; i++)
{
var cab = reader.ReadString();
var path = reader.ReadString();
var offset = reader.ReadInt64();
var depCount = reader.ReadInt32();
var dependencies = new string[depCount];
for (int j = 0; j < depCount; j++)
{
dependencies[j] = reader.ReadString();
}
var entry = new Entry()
{
Path = path,
Offset = offset,
Dependencies = dependencies
};
CABMap.Add(cab, entry);
}
}

public static void BuildAssetMap(string[] files, string mapName, Game game, string savePath, ExportListType exportListType, ManualResetEvent resetEvent = null, ClassIDType[] typeFilters = null, Regex[] nameFilters = null, Regex[] containerFilters = null)
{
Logger.Info("Building AssetMap...");
Expand Down

0 comments on commit fabdaec

Please sign in to comment.