Skip to content

Commit

Permalink
Merge pull request #85 from sebastian-heinz/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
alborrajo authored Sep 5, 2022
2 parents 64a8074 + 6602030 commit d153f15
Show file tree
Hide file tree
Showing 218 changed files with 10,512 additions and 5,143 deletions.
170 changes: 109 additions & 61 deletions Arrowgene.Ddon.Cli/Command/ClientCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Text;
using System.Text.Json;
using Arrowgene.Ddon.Client;
using Arrowgene.Ddon.Client.Resource;
using Arrowgene.Ddon.Client.Resource.Texture;
using Arrowgene.Ddon.Client.Resource.Texture.Dds;
using Arrowgene.Ddon.Client.Resource.Texture.Tex;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.Cli.Command
Expand All @@ -25,6 +27,44 @@ public CommandResultType Run(CommandParameter parameter)
return CommandResultType.Exit;
}

if (parameter.ArgumentMap.ContainsKey("extract"))
{
string extract = parameter.ArgumentMap["extract"];
extract = extract.TrimEnd(Path.DirectorySeparatorChar);
extract = extract.TrimEnd(Path.AltDirectorySeparatorChar);
DirectoryInfo outDirectory = new DirectoryInfo(extract);
if (!outDirectory.Exists)
{
Logger.Error($"extract directory does not exists ({outDirectory.FullName})");
return CommandResultType.Exit;
}

string source = parameter.Arguments[0];
if (File.Exists(source))
{
FileInfo arcFile = new FileInfo(source);
if (arcFile.Extension != ".arc")
{
Logger.Error($"Source file is not a .arc file. ({source})");
return CommandResultType.Exit;
}

Extract(arcFile, outDirectory);
return CommandResultType.Exit;
}

if (Directory.Exists(source))
{
DirectoryInfo directoryInfo = new DirectoryInfo(source);
Extract(directoryInfo, outDirectory);
return CommandResultType.Exit;
}

Logger.Error($"Source file or folder does not exist. ({outDirectory.FullName})");
return CommandResultType.Exit;
}


FileInfo fileInfo = new FileInfo(parameter.Arguments[0]);
if (fileInfo.Exists)
{
Expand All @@ -33,8 +73,18 @@ public CommandResultType Run(CommandParameter parameter)
TexToDds(fileInfo);
return CommandResultType.Exit;
}

if (".dds".Equals(fileInfo.Extension, StringComparison.InvariantCultureIgnoreCase))
{
DdsToTex(fileInfo, parameter);
return CommandResultType.Exit;
}

Logger.Error("No available action for provided file");
return CommandResultType.Exit;
}


// assuming first parameter is rom dir for these actions
DirectoryInfo romDirectory = new DirectoryInfo(parameter.Arguments[0]);
if (!romDirectory.Exists)
{
Expand All @@ -56,13 +106,6 @@ public CommandResultType Run(CommandParameter parameter)
return CommandResultType.Exit;
}

if (parameter.ArgumentMap.ContainsKey("extract"))
{
DirectoryInfo outDirectory = new DirectoryInfo(parameter.ArgumentMap["extract"]);
Extract(romDirectory, outDirectory);
return CommandResultType.Exit;
}

return CommandResultType.Exit;
}

Expand Down Expand Up @@ -115,7 +158,7 @@ public void DumpPaths(DirectoryInfo romDirectory, DirectoryInfo outDir)
Logger.Info($"Done: {outPath}");
}

public void Extract(DirectoryInfo romDirectory, DirectoryInfo outDir)
public void Extract(DirectoryInfo source, DirectoryInfo outDir)
{
if (outDir == null)
{
Expand All @@ -126,74 +169,79 @@ public void Extract(DirectoryInfo romDirectory, DirectoryInfo outDir)
if (!outDir.Exists)
{
outDir.Create();
Logger.Info($"Created Dir: {outDir.FullName}");
Logger.Info($"Created Output Directory: {outDir.FullName}");
}

string[] files = Directory.GetFiles(romDirectory.FullName, "*.arc", SearchOption.AllDirectories);
string[] files = Directory.GetFiles(source.FullName, "*.arc", SearchOption.AllDirectories);

if (files.Length <= 0)
{
Logger.Error($"No *.arc files found in source directory. ({source.FullName})");
return;
}

for (int i = 0; i < files.Length; i++)
{
// TODO utput folder of .arc folder name
string filePath = files[i];
string relativePath = filePath.Substring(romDirectory.FullName.Length);
ArcArchive archive = new ArcArchive();
archive.Open(filePath);
foreach (ArcArchive.FileIndex fi in archive.GetFileIndices())
{
ArcArchive.ArcFile af = archive.GetFile(fi);
if (af == null)
{
continue;
}

string outDirectory = Path.Combine(outDir.FullName, fi.Directory);
if (!Directory.Exists(outDirectory))
{
Directory.CreateDirectory(outDirectory);
}

string outPath = Path.Combine(outDirectory, fi.Name);
File.WriteAllBytes(outPath, af.Data);
}

FileInfo fi = new FileInfo(filePath);
Extract(fi, outDir);
Logger.Info($"Processing {i}/{files.Length} {filePath}");
}
}

public void TexToDds(FileInfo fileInfo)
public void Extract(FileInfo fileInfo, DirectoryInfo outDir)
{
Texture texture = new Texture();
texture.Open(fileInfo.FullName);
texture.SaveDds($"{fileInfo.FullName}.dds");

// Texture tex = ArcArchive.GetResource<Texture>(
// romDirectory,
// "game_common.arc",
// "scr/sky/DDBaseCube4_CM",
// "tex"
// );
// tex.SaveDds("E:/Games/ARCtool/DDBaseCube4_CM.tex.dds");
// tex.Save("E:/Games/ARCtool/DDBaseCube4_CM.tex");


// string p3 = "E:/Games/ARCtool/DefaultCube_CM.tex";
// Texture t3 = new Texture();
// t3.Open(p3);
// t3.SaveDds(p3 + ".dds");
ArcArchive archive = new ArcArchive();
archive.Open(fileInfo.FullName);
foreach (ArcArchive.FileIndex fi in archive.GetFileIndices())
{
ArcArchive.ArcFile af = archive.GetFile(fi);
if (af == null)
{
continue;
}

string outDirectory = Path.Combine(outDir.FullName, fileInfo.Name, fi.Directory);
if (!Directory.Exists(outDirectory))
{
Directory.CreateDirectory(outDirectory);
}

// string p0 = "E:/Games/Dragon's Dogma Online/nativePC/system/texture/sysfont_AM_NOMIP.tex";
// Texture t0 = new Texture();
// t0.Open(p0);
// t0.SaveDds("E:/Games/ARCtool/sysfont_AM_NOMIP.tex" + ".dds");
string outPath = Path.Combine(outDirectory, fi.Name);
File.WriteAllBytes(outPath, af.Data);

Logger.Info($"Written: {outPath}");
}
}

// string p1 = "E:/Games/Dragon's Dogma Online/nativePC/system/texture/detail_sysfont_AM_NOMIP.tex";
// Texture t1 = new Texture();
// t1.Open(p1);
public void TexToDds(FileInfo fileInfo)
{
TexTexture texTexture = new TexTexture();
texTexture.Open(fileInfo.FullName);
DdsTexture ddsTexture = TexConvert.ToDdsTexture(texTexture);
string outPath = $"{fileInfo.FullName}.dds";
ddsTexture.Save(outPath);
Logger.Info($"Written: {outPath}");
}

public void DdsToTex(FileInfo fileInfo, CommandParameter parameter)
{
TexHeaderVersion headerVersion = TexHeaderVersion.Ddon;
if (parameter.Switches.Contains("--ddda"))
{
headerVersion = TexHeaderVersion.Ddda;
}
else if (parameter.Switches.Contains("--ddon"))
{
headerVersion = TexHeaderVersion.Ddon;
}

int i = 1;
DdsTexture ddsTexture = new DdsTexture();
ddsTexture.Open(fileInfo.FullName);
TexTexture texTexture = TexConvert.ToTexTexture(ddsTexture, headerVersion);
string outPath = $"{fileInfo.FullName}.tex";
texTexture.Save(outPath);
Logger.Info($"Written: {outPath}");
}

public void Shutdown()
Expand Down
4 changes: 3 additions & 1 deletion Arrowgene.Ddon.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ private void RunArguments(string[] arguments)
{
_lastCommand.Shutdown();
}


// Wait for logs to be flushed to console
Thread.Sleep(1000);
LogProvider.Stop();
}

Expand Down
Loading

0 comments on commit d153f15

Please sign in to comment.