0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-18 19:31:17 +03:00

update NRES file with element count and element size, seen in ResTree .trf

This commit is contained in:
bird_egop 2025-03-09 22:56:59 +03:00
parent 8c4fc8f096
commit a419be1fce
5 changed files with 36 additions and 11 deletions

View File

@ -19,10 +19,11 @@ public record NResArchiveHeader(string NRes, int Version, int FileCount, int Tot
/// каждый элемент это 64 байта, /// каждый элемент это 64 байта,
/// найти начало можно как (Header.TotalFileLengthBytes - Header.FileCount * 64) /// найти начало можно как (Header.TotalFileLengthBytes - Header.FileCount * 64)
/// </summary> /// </summary>
/// <param name="FileType">[0..8] ASCII описание типа файла, например TEXM или MAT0</param> /// <param name="FileType">[0..4] ASCII описание типа файла, например TEXM или MAT0</param>
/// <param name="ElementCount">[4..8] Количество элементов в файле (если файл составной, например .trf) </param>
/// <param name="Magic1">[8..12] Неизвестное число</param> /// <param name="Magic1">[8..12] Неизвестное число</param>
/// <param name="FileLength">[12..16] Длина файла в байтах</param> /// <param name="FileLength">[12..16] Длина файла в байтах</param>
/// <param name="Magic2">[16..20] Неизвестное число</param> /// <param name="ElementSize">[16..20] Размер элемента в файле (если файл составной, например .trf) </param>
/// <param name="FileName">[20..40] ASCII имя файла</param> /// <param name="FileName">[20..40] ASCII имя файла</param>
/// <param name="Magic3">[40..44] Неизвестное число</param> /// <param name="Magic3">[40..44] Неизвестное число</param>
/// <param name="Magic4">[44..48] Неизвестное число</param> /// <param name="Magic4">[44..48] Неизвестное число</param>
@ -32,9 +33,10 @@ public record NResArchiveHeader(string NRes, int Version, int FileCount, int Tot
/// <param name="Index">[60..64] Индекс в файле (от 0, не больше чем кол-во файлов)</param> /// <param name="Index">[60..64] Индекс в файле (от 0, не больше чем кол-во файлов)</param>
public record ListMetadataItem( public record ListMetadataItem(
string FileType, string FileType,
uint ElementCount,
int Magic1, int Magic1,
int FileLength, int FileLength,
int Magic2, int ElementSize,
string FileName, string FileName,
int Magic3, int Magic3,
int Magic4, int Magic4,

View File

@ -30,7 +30,7 @@ public class NResExporter
extension = ".bin"; extension = ".bin";
} }
var targetFilePath = Path.Combine(targetDirectoryPath, $"{archiveFile.Index}_{fileName}{extension}"); var targetFilePath = Path.Combine(targetDirectoryPath, $"{archiveFile.Index}_{archiveFile.FileType}_{fileName}{extension}");
File.WriteAllBytes(targetFilePath, buffer); File.WriteAllBytes(targetFilePath, buffer);
} }

View File

@ -48,13 +48,32 @@ public static class NResParser
for (int i = 0; i < header.FileCount; i++) for (int i = 0; i < header.FileCount; i++)
{ {
nResFs.ReadExactly(metaDataBuffer); nResFs.ReadExactly(metaDataBuffer);
var type = "";
for (int j = 0; j < 4; j++)
{
if (!char.IsLetterOrDigit((char)metaDataBuffer[j]))
{
type += metaDataBuffer[j]
.ToString("X2") + " ";
}
else
{
type += (char)metaDataBuffer[j];
}
}
var type2 = BinaryPrimitives.ReadUInt32LittleEndian(metaDataBuffer.Slice(4));
type = type.Trim();
elements.Add( elements.Add(
new ListMetadataItem( new ListMetadataItem(
FileType: Encoding.ASCII.GetString(metaDataBuffer[..8]).TrimEnd('\0'), FileType: type,
ElementCount: type2,
Magic1: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[8..12]), Magic1: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[8..12]),
FileLength: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[12..16]), FileLength: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[12..16]),
Magic2: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[16..20]), ElementSize: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[16..20]),
FileName: Encoding.ASCII.GetString(metaDataBuffer[20..40]).TrimEnd('\0'), FileName: Encoding.ASCII.GetString(metaDataBuffer[20..40]).TrimEnd('\0'),
Magic3: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[40..44]), Magic3: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[40..44]),
Magic4: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[44..48]), Magic4: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[44..48]),

View File

@ -32,10 +32,11 @@
3. В конце файла есть метаданные. 3. В конце файла есть метаданные.
Поскольку NRes это по сути архив, длина метаданных у каждого файла разная и считается как `Количество файлов * 64`, каждый элемент метаданных - 64 байта. Поскольку NRes это по сути архив, длина метаданных у каждого файла разная и считается как `Количество файлов * 64`, каждый элемент метаданных - 64 байта.
+ [0..8] ASCII описание типа файла, например TEXM или MAT0 + [0..4] ASCII описание типа файла, например TEXM или MAT0
+ [4..8] Количество элементов в файле (если файл составной, например .trf)
+ [8..12] Неизвестное число + [8..12] Неизвестное число
+ [12..16] Длина файла в байтах + [12..16] Длина файла в байтах
+ [16..20] Неизвестное число + [16..20] Размер элемента в файле (если файл составной, например .trf)
+ [20..40] ASCII имя файла + [20..40] ASCII имя файла
+ [40..44] Неизвестное число + [40..44] Неизвестное число
+ [44..48] Неизвестное число + [44..48] Неизвестное число

View File

@ -46,12 +46,13 @@ public class NResExplorerPanel : IImGuiPanel
ImGui.Text(_viewModel.Archive.Header.TotalFileLengthBytes.ToString()); ImGui.Text(_viewModel.Archive.Header.TotalFileLengthBytes.ToString());
if (ImGui.BeginTable("content", 11)) if (ImGui.BeginTable("content", 12, ImGuiTableFlags.Borders | ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.NoHostExtendX))
{ {
ImGui.TableSetupColumn("Тип файла"); ImGui.TableSetupColumn("Тип файла");
ImGui.TableSetupColumn("Кол-во элементов");
ImGui.TableSetupColumn("Magic1"); ImGui.TableSetupColumn("Magic1");
ImGui.TableSetupColumn("Длина файла в байтах"); ImGui.TableSetupColumn("Длина файла в байтах");
ImGui.TableSetupColumn("Magic2"); ImGui.TableSetupColumn("Размер элемента");
ImGui.TableSetupColumn("Имя файла"); ImGui.TableSetupColumn("Имя файла");
ImGui.TableSetupColumn("Magic3"); ImGui.TableSetupColumn("Magic3");
ImGui.TableSetupColumn("Magic4"); ImGui.TableSetupColumn("Magic4");
@ -68,6 +69,8 @@ public class NResExplorerPanel : IImGuiPanel
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.Text(_viewModel.Archive.Files[i].FileType); ImGui.Text(_viewModel.Archive.Files[i].FileType);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.Text(_viewModel.Archive.Files[i].ElementCount.ToString());
ImGui.TableNextColumn();
ImGui.Text( ImGui.Text(
_viewModel.Archive.Files[i] _viewModel.Archive.Files[i]
.Magic1.ToString() .Magic1.ToString()
@ -80,7 +83,7 @@ public class NResExplorerPanel : IImGuiPanel
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.Text( ImGui.Text(
_viewModel.Archive.Files[i] _viewModel.Archive.Files[i]
.Magic2.ToString() .ElementSize.ToString()
); );
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.Text(_viewModel.Archive.Files[i].FileName); ImGui.Text(_viewModel.Archive.Files[i].FileName);