mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-18 19:31:17 +03:00
Implement scr parsing
This commit is contained in:
parent
ba7c2afe2a
commit
b47a9aff5d
39
ParkanPlayground/Extensions.cs
Normal file
39
ParkanPlayground/Extensions.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Text;
|
||||
|
||||
namespace ParkanPlayground;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static int ReadInt32LittleEndian(this FileStream fs)
|
||||
{
|
||||
Span<byte> buf = stackalloc byte[4];
|
||||
fs.ReadExactly(buf);
|
||||
|
||||
return BinaryPrimitives.ReadInt32LittleEndian(buf);
|
||||
}
|
||||
|
||||
public static float ReadFloatLittleEndian(this FileStream fs)
|
||||
{
|
||||
Span<byte> buf = stackalloc byte[4];
|
||||
fs.ReadExactly(buf);
|
||||
|
||||
return BinaryPrimitives.ReadSingleLittleEndian(buf);
|
||||
}
|
||||
|
||||
public static string ReadLengthPrefixedString(this FileStream fs)
|
||||
{
|
||||
var len = fs.ReadInt32LittleEndian();
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
var buffer = new byte[len];
|
||||
|
||||
fs.ReadExactly(buffer, 0, len);
|
||||
|
||||
return Encoding.ASCII.GetString(buffer, 0, len);
|
||||
}
|
||||
}
|
@ -1,41 +1,61 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Text;
|
||||
using NResLib;
|
||||
using ParkanPlayground;
|
||||
|
||||
var libFile = "C:\\Program Files (x86)\\Nikita\\Iron Strategy\\ui\\ui_back.lib";
|
||||
var path = "C:\\Program Files (x86)\\Nikita\\Iron Strategy\\MISSIONS\\SCRIPTS\\11p.scr";
|
||||
|
||||
var parseResult = NResParser.ReadFile(libFile);
|
||||
using var fs = new FileStream(path, FileMode.Open);
|
||||
|
||||
if (parseResult.Error != null)
|
||||
// тут всегда число 59 (0x3b) - это число известных игре скриптов
|
||||
var magic = fs.ReadInt32LittleEndian();
|
||||
|
||||
Console.WriteLine($"Count: {magic}");
|
||||
|
||||
var entryCount = fs.ReadInt32LittleEndian();
|
||||
|
||||
Console.WriteLine($"EntryCount: {entryCount}");
|
||||
|
||||
for (var i = 0; i < entryCount; i++)
|
||||
{
|
||||
Console.WriteLine(parseResult.Error);
|
||||
return;
|
||||
}
|
||||
Console.WriteLine($"Entry: {i}");
|
||||
var str = fs.ReadLengthPrefixedString();
|
||||
|
||||
// var libFileName = new FileInfo(libFile).Name;
|
||||
//
|
||||
// if (Directory.Exists(libFileName))
|
||||
// {
|
||||
// Directory.Delete(libFileName, true);
|
||||
// }
|
||||
//
|
||||
// var dir = Directory.CreateDirectory(libFileName);
|
||||
//
|
||||
// byte[] copyBuffer = new byte[8192];
|
||||
//
|
||||
// foreach (var element in elements)
|
||||
// {
|
||||
// nResFs.Seek(element.OffsetInFile, SeekOrigin.Begin);
|
||||
// using var destFs = new FileStream(Path.Combine(libFileName, element.FileName), FileMode.CreateNew);
|
||||
//
|
||||
// var totalCopiedBytes = 0;
|
||||
// while (totalCopiedBytes < element.ItemLength)
|
||||
// {
|
||||
// var needReadBytes = Math.Min(element.ItemLength - totalCopiedBytes, copyBuffer.Length);
|
||||
// var readBytes = nResFs.Read(copyBuffer, 0, needReadBytes);
|
||||
//
|
||||
// destFs.Write(copyBuffer, 0, readBytes);
|
||||
//
|
||||
// totalCopiedBytes += readBytes;
|
||||
// }
|
||||
// }
|
||||
Console.WriteLine($"\tStr: {str}");
|
||||
|
||||
// тут игра дополнительно вычитывает ещё 1 байт, видимо как \0 для char*
|
||||
fs.ReadByte();
|
||||
|
||||
var index = fs.ReadInt32LittleEndian();
|
||||
Console.WriteLine($"\tIndex: {index}");
|
||||
var innerCount = fs.ReadInt32LittleEndian();
|
||||
Console.WriteLine($"\tInnerCount: {innerCount}");
|
||||
for (var i1 = 0; i1 < innerCount; i1++)
|
||||
{
|
||||
var unkInner1 = fs.ReadInt32LittleEndian();
|
||||
var unkInner2 = fs.ReadInt32LittleEndian();
|
||||
var unkInner3 = fs.ReadInt32LittleEndian();
|
||||
var unkInner4 = fs.ReadInt32LittleEndian();
|
||||
var unkInner5 = fs.ReadInt32LittleEndian();
|
||||
|
||||
Console.WriteLine($"\t\tUnkInner1: {unkInner1}");
|
||||
Console.WriteLine($"\t\tUnkInner2: {unkInner2}");
|
||||
Console.WriteLine($"\t\tUnkInner3: {unkInner3}");
|
||||
Console.WriteLine($"\t\tUnkInner4: {unkInner4}");
|
||||
Console.WriteLine($"\t\tUnkInner5: {unkInner5}");
|
||||
|
||||
var innerInnerCount = fs.ReadInt32LittleEndian();
|
||||
Console.WriteLine($"\t\tInnerInnerCount: {innerInnerCount}");
|
||||
|
||||
for (var i2 = 0; i2 < innerInnerCount; i2++)
|
||||
{
|
||||
var innerInner = fs.ReadInt32LittleEndian();
|
||||
Console.WriteLine($"\t\t\t{innerInner}");
|
||||
}
|
||||
|
||||
var unkInner7 = fs.ReadInt32LittleEndian();
|
||||
|
||||
Console.WriteLine($"\t\tUnkInner7 {unkInner7}");
|
||||
Console.WriteLine("---");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user