From 9124e6463a5ead6ab577f6764ef6493d58ac51e7 Mon Sep 17 00:00:00 2001 From: bird_egop Date: Fri, 15 Nov 2024 14:30:06 +0300 Subject: [PATCH] nl unpacker --- NLUnpacker/NLUnpacker.csproj | 10 ++++ NLUnpacker/Program.cs | 93 ++++++++++++++++++++++++++++++++++++ ParkanPlayground.sln | 6 +++ 3 files changed, 109 insertions(+) create mode 100644 NLUnpacker/NLUnpacker.csproj create mode 100644 NLUnpacker/Program.cs diff --git a/NLUnpacker/NLUnpacker.csproj b/NLUnpacker/NLUnpacker.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/NLUnpacker/NLUnpacker.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/NLUnpacker/Program.cs b/NLUnpacker/Program.cs new file mode 100644 index 0000000..b54b3c3 --- /dev/null +++ b/NLUnpacker/Program.cs @@ -0,0 +1,93 @@ +using System.Buffers.Binary; +using System.Runtime.CompilerServices; + +// ПОКА НЕ ПОНЯТНО КАК ОНО КОДИРУЕТСЯ + +// using var fs = new FileStream("gamefont.rlb", FileMode.Open, FileAccess.ReadWrite); +// +// int fileCount, c, i; +// byte b, n; +// +// fs.Seek(4, SeekOrigin.Current); +// +// Span buf2 = stackalloc byte[2]; +// Span buf4 = stackalloc byte[4]; +// +// fs.ReadExactly(buf2); +// +// fileCount = BinaryPrimitives.ReadInt16LittleEndian(buf2); +// +// fs.Seek(16 - 2, SeekOrigin.Current); +// +// b = (byte) fs.ReadByte(); +// c = (byte) fs.ReadByte(); +// +// fs.Seek(12 - 2, SeekOrigin.Current); +// +// Span buf1 = stackalloc byte[1]; +// +// if (32 * fileCount > 0) +// { +// for (i = 0; i < 32 * fileCount; ++i) +// { +// b = (byte) ((b * 2) ^ c); +// n = (byte) c; +// c = (int) ((n >> 1) ^ b); +// +// // Read, modify, and write the byte at the current position +// byte originalByte = (byte) fs.ReadByte(); +// fs.Seek(-1, SeekOrigin.Current); // Move back one byte to overwrite it +// buf1[0] = (byte) (originalByte ^ b); +// fs.Write(buf1); +// } +// } + +int v40 = 0; +var flags = 0; +var file_bytes = File.ReadAllBytes("gamefont.rlb"); +var FileSize = file_bytes.Length; +var file_bytes_copy = file_bytes; +var v8 = flags; +if ((flags & 2) != 0) +{ + if (file_bytes[FileSize - 6] != 'A' && file_bytes[FileSize - 5] != 'O') + throw new Exception("4"); + v40 = BinaryPrimitives.ReadInt32LittleEndian( + file_bytes.Skip(FileSize - 4) + .Take(4) + .ToArray() + ); +} + +if (file_bytes[0] != (byte)'N' || file_bytes[1] != (byte)'L' || file_bytes[2] != 0 || file_bytes[3] != 1) + throw new Exception("4"); +var file_count = BinaryPrimitives.ReadInt16LittleEndian( + file_bytes.Skip(4) + .Take(2) + .ToArray() +); +var file_count_copy = file_count; +var section_mem_ptr = new byte[32 * file_count]; + +var section_count = 0; +var sixth_byte = file_bytes_copy[5]; +var sixth_byte_shifted_by_1_byte = file_bytes_copy[5] >> 8; +if (32 * file_count > 0) +{ + do + { + sixth_byte = (byte) (sixth_byte_shifted_by_1_byte ^ (2 * sixth_byte)); + sixth_byte_shifted_by_1_byte = sixth_byte ^ (sixth_byte_shifted_by_1_byte >> 1); + section_mem_ptr[section_count] = (byte) (sixth_byte ^ file_bytes_copy[section_count + 32]); + ++section_count; + } while (section_count < 32 * file_count); + + v8 = flags; +} + +for (var i = 0; i < section_mem_ptr.Length; i++) +{ + +} + +File.WriteAllBytes("gamefont-dump.rlb", file_bytes); \ No newline at end of file diff --git a/ParkanPlayground.sln b/ParkanPlayground.sln index 6b21db4..d0ae5da 100644 --- a/ParkanPlayground.sln +++ b/ParkanPlayground.sln @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParkanPlayground", "ParkanP EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextureDecoder", "TextureDecoder\TextureDecoder.csproj", "{15D1C9ED-1080-417D-A4D1-CFF80BE6A218}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLUnpacker", "NLUnpacker\NLUnpacker.csproj", "{50C83E6C-23ED-4A8E-B948-89686A742CF0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +20,9 @@ Global {15D1C9ED-1080-417D-A4D1-CFF80BE6A218}.Debug|Any CPU.Build.0 = Debug|Any CPU {15D1C9ED-1080-417D-A4D1-CFF80BE6A218}.Release|Any CPU.ActiveCfg = Release|Any CPU {15D1C9ED-1080-417D-A4D1-CFF80BE6A218}.Release|Any CPU.Build.0 = Release|Any CPU + {50C83E6C-23ED-4A8E-B948-89686A742CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50C83E6C-23ED-4A8E-B948-89686A742CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50C83E6C-23ED-4A8E-B948-89686A742CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50C83E6C-23ED-4A8E-B948-89686A742CF0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal