Added decompress-dat command for densha de go pnp compressed dats

This commit is contained in:
Zapan 2024-03-31 11:55:48 +02:00
parent fc89814115
commit bac244eb2f
2 changed files with 37 additions and 0 deletions

View file

@ -16,6 +16,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Pipes;
using System.Text; using System.Text;
using Path = System.IO.Path; using Path = System.IO.Path;
@ -60,6 +61,23 @@ namespace DgfTxmConvert
}); });
}); });
app.Command("decompress-dat", config =>
{
config.FullName = "Decompress DAT";
config.Description = "Converts compressed DAT to flat DAT.";
var datPathArg = config.Argument("datPath", "Path of the DAT to decompress").IsRequired();
datPathArg.Accepts().ExistingFile();
var outBaseArg = config.Argument("outBase", "Directory to write flat file");
outBaseArg.Accepts().LegalFilePath();
config.HelpOption();
config.OnExecute(() =>
{
DecompressDat(datPathArg.Value, outBaseArg.Value);
});
});
app.Command("convert-txm", config => app.Command("convert-txm", config =>
{ {
config.FullName = "Convert TXM to image"; config.FullName = "Convert TXM to image";
@ -284,6 +302,9 @@ namespace DgfTxmConvert
TxmConversion.ConvertImageToTxm(lineSplit[1], fs, level, bufferBase, paletteBufferBase); TxmConversion.ConvertImageToTxm(lineSplit[1], fs, level, bufferBase, paletteBufferBase);
} }
Console.WriteLine($"Replacing \"{line}\".");
builder.ReplacementEntries.Add(new DatBuilder.ReplacementEntry builder.ReplacementEntries.Add(new DatBuilder.ReplacementEntry
{ {
Index = imageIndex, Index = imageIndex,
@ -307,10 +328,25 @@ namespace DgfTxmConvert
} }
static void DecompressDat(string path, string outBase = null)
{
if (outBase == null) outBase = Path.GetDirectoryName(path);
Directory.CreateDirectory(outBase);
using (Stream ffs = Utils.CheckDecompress(File.OpenRead(path)))
using (var fileStream = File.Create(Path.Combine(outBase, Path.GetFileNameWithoutExtension(path) + $"_plain.dat")))
{
ffs.Seek(0, SeekOrigin.Begin);
ffs.CopyTo(fileStream);
}
}
static void ConvertDat(string path, string outBase = null) static void ConvertDat(string path, string outBase = null)
{ {
if (outBase == null) outBase = Path.GetDirectoryName(path); if (outBase == null) outBase = Path.GetDirectoryName(path);
Directory.CreateDirectory(outBase); Directory.CreateDirectory(outBase);
using (Stream fs = Utils.CheckDecompress(File.OpenRead(path))) using (Stream fs = Utils.CheckDecompress(File.OpenRead(path)))
using (DatReader dat = new DatReader(fs)) using (DatReader dat = new DatReader(fs))
{ {

View file

@ -28,6 +28,7 @@ option.
far texture is extracted. far texture is extracted.
- `convert-mapanim`: Converts files from the mapanim folder to Wavefront OBJ - `convert-mapanim`: Converts files from the mapanim folder to Wavefront OBJ
models. models.
- `decompress-dat`: Converts compressed DAT to flat DAT.
Other Other
----- -----