Skip to content

Commit

Permalink
Merge pull request #41 from sebastian-heinz/feature/texture
Browse files Browse the repository at this point in the history
Feature/texture
  • Loading branch information
sebastian-heinz authored Mar 18, 2022
2 parents 006740d + 9a7bb0b commit 0e3e3f4
Show file tree
Hide file tree
Showing 23 changed files with 1,786 additions and 120 deletions.
102 changes: 101 additions & 1 deletion Arrowgene.Ddon.Cli/Command/ClientCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using System.Text.Json;
using Arrowgene.Ddon.Client;
using Arrowgene.Ddon.Client.Resource;
using Arrowgene.Logging;

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

FileInfo fileInfo = new FileInfo(parameter.Arguments[0]);
if (fileInfo.Exists)
{
if (".tex".Equals(fileInfo.Extension, StringComparison.InvariantCultureIgnoreCase))
{
TexToDds(fileInfo);
return CommandResultType.Exit;
}
}

DirectoryInfo romDirectory = new DirectoryInfo(parameter.Arguments[0]);
if (!romDirectory.Exists)
{
Expand All @@ -44,6 +55,14 @@ public CommandResultType Run(CommandParameter parameter)
ExportResourceRepository(romDirectory, outDirectory);
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 All @@ -56,7 +75,7 @@ public void ExportResourceRepository(DirectoryInfo romDirectory, DirectoryInfo o
File.WriteAllText(outPath, json);
Logger.Info($"Done: {outPath}");
}

public void DumpPaths(DirectoryInfo romDirectory, DirectoryInfo outDir)
{
if (outDir == null)
Expand Down Expand Up @@ -96,6 +115,87 @@ public void DumpPaths(DirectoryInfo romDirectory, DirectoryInfo outDir)
Logger.Info($"Done: {outPath}");
}

public void Extract(DirectoryInfo romDirectory, DirectoryInfo outDir)
{
if (outDir == null)
{
Logger.Error("Failed to extract. (outDir == null)");
return;
}

if (!outDir.Exists)
{
outDir.Create();
Logger.Info($"Created Dir: {outDir.FullName}");
}

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

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);
}

Logger.Info($"Processing {i}/{files.Length} {filePath}");
}
}

public void TexToDds(FileInfo fileInfo)
{
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");


// 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 p1 = "E:/Games/Dragon's Dogma Online/nativePC/system/texture/detail_sysfont_AM_NOMIP.tex";
// Texture t1 = new Texture();
// t1.Open(p1);


int i = 1;
}

public void Shutdown()
{
}
Expand Down
73 changes: 73 additions & 0 deletions Arrowgene.Ddon.Client/ArcArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Text;
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Crypto;
using Arrowgene.Logging;
using ICSharpCode.SharpZipLib.Zip.Compression;
Expand Down Expand Up @@ -31,7 +32,79 @@ private static void Register(string className, string extension)
arcExt.JamCrcStr = $"0x{arcExt.JamCrc:X8}";
JamCrcLookup.Add(arcExt.JamCrc, arcExt);
}

public static T GetFile<T>(DirectoryInfo romDir, string arcPath, string filePath, string ext = null) where T : ClientFile, new()
{
ArcFile arcFile = GetArcFile(romDir, arcPath, filePath, ext, true);
if (arcFile == null)
{
return null;
}

T file = new T();
file.Open(arcFile.Data);
return file;
}

public static T GetResource<T>(DirectoryInfo romDir, string arcPath, string filePath, string ext = null) where T : ResourceFile, new()
{
ArcFile arcFile = GetArcFile(romDir, arcPath, filePath, ext, true);
if (arcFile == null)
{
return null;
}

T resource = new T();
resource.Open(arcFile.Data);
return resource;
}

public static T GetResource_NoLog<T>(DirectoryInfo romDir, string arcPath, string filePath, string ext = null) where T : ResourceFile, new()
{
ArcFile arcFile = GetArcFile(romDir, arcPath, filePath, ext, false);
if (arcFile == null)
{
return null;
}

T resource = new T();
resource.Open(arcFile.Data);
return resource;
}

public static ArcFile GetArcFile(DirectoryInfo romDir, string arcPath, string filePath, string ext, bool log)
{
string path = Path.Combine(romDir.FullName, Util.UnrootPath(arcPath));
FileInfo file = new FileInfo(path);
if (!file.Exists)
{
if (log)
{
Logger.Error($"File does not exist. ({path})");
}

return null;
}

ArcArchive archive = new ArcArchive();
archive.Open(file.FullName);
FileIndexSearch search = Search()
.ByArcPath(filePath)
.ByExtension(ext);
ArcFile arcFile = archive.GetFile(search);
if (arcFile == null)
{
if (log)
{
Logger.Error($"File:{filePath} could not be located in archive:{path}");
}

return null;
}

return arcFile;
}

public static FileIndexSearch Search()
{
return new FileIndexSearch();
Expand Down
5 changes: 5 additions & 0 deletions Arrowgene.Ddon.Client/ClientFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ protected List<T> ReadMtArray<T>(IBuffer buffer, Func<IBuffer, T> reader)
return entities;
}

protected byte[] ReadBytes(IBuffer buffer, int length)
{
return buffer.ReadBytes(length);
}

protected void WriteUInt32(IBuffer buffer, uint value)
{
buffer.WriteUInt32(value, Endianness.Little);
Expand Down
63 changes: 3 additions & 60 deletions Arrowgene.Ddon.Client/ClientResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,74 +221,17 @@ private void AddAdjoin(List<FieldAreaAdjoinList.AdjoinInfo> adjoins,

private T GetFile<T>(string arcPath, string filePath, string ext = null) where T : ClientFile, new()
{
ArcArchive.ArcFile arcFile = GetArcFile(arcPath, filePath, ext, true);
if (arcFile == null)
{
return null;
}

T file = new T();
file.Open(arcFile.Data);
return file;
return ArcArchive.GetFile<T>(_directory, arcPath, filePath, ext);
}

private T GetResource<T>(string arcPath, string filePath, string ext = null) where T : ResourceFile, new()
{
ArcArchive.ArcFile arcFile = GetArcFile(arcPath, filePath, ext, true);
if (arcFile == null)
{
return null;
}

T resource = new T();
resource.Open(arcFile.Data);
return resource;
return ArcArchive.GetResource<T>(_directory, arcPath, filePath, ext);
}

private T GetResource_NoLog<T>(string arcPath, string filePath, string ext = null) where T : ResourceFile, new()
{
ArcArchive.ArcFile arcFile = GetArcFile(arcPath, filePath, ext, false);
if (arcFile == null)
{
return null;
}

T resource = new T();
resource.Open(arcFile.Data);
return resource;
}

private ArcArchive.ArcFile GetArcFile(string arcPath, string filePath, string ext, bool log)
{
string path = Path.Combine(_directory.FullName, Util.UnrootPath(arcPath));
FileInfo file = new FileInfo(path);
if (!file.Exists)
{
if (log)
{
Logger.Error($"File does not exist. ({path})");
}

return null;
}

ArcArchive archive = new ArcArchive();
archive.Open(file.FullName);
ArcArchive.FileIndexSearch search = ArcArchive.Search()
.ByArcPath(filePath)
.ByExtension(ext);
ArcArchive.ArcFile arcFile = archive.GetFile(search);
if (arcFile == null)
{
if (log)
{
Logger.Error($"File:{filePath} could not be located in archive:{path}");
}

return null;
}

return arcFile;
return ArcArchive.GetResource_NoLog<T>(_directory, arcPath, filePath, ext);
}
}
}
Loading

0 comments on commit 0e3e3f4

Please sign in to comment.