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.Buffers.Binary;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NResLib;
|
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);
|
Console.WriteLine($"Entry: {i}");
|
||||||
return;
|
var str = fs.ReadLengthPrefixedString();
|
||||||
}
|
|
||||||
|
Console.WriteLine($"\tStr: {str}");
|
||||||
|
|
||||||
|
// тут игра дополнительно вычитывает ещё 1 байт, видимо как \0 для char*
|
||||||
|
fs.ReadByte();
|
||||||
|
|
||||||
// var libFileName = new FileInfo(libFile).Name;
|
var index = fs.ReadInt32LittleEndian();
|
||||||
//
|
Console.WriteLine($"\tIndex: {index}");
|
||||||
// if (Directory.Exists(libFileName))
|
var innerCount = fs.ReadInt32LittleEndian();
|
||||||
// {
|
Console.WriteLine($"\tInnerCount: {innerCount}");
|
||||||
// Directory.Delete(libFileName, true);
|
for (var i1 = 0; i1 < innerCount; i1++)
|
||||||
// }
|
{
|
||||||
//
|
var unkInner1 = fs.ReadInt32LittleEndian();
|
||||||
// var dir = Directory.CreateDirectory(libFileName);
|
var unkInner2 = fs.ReadInt32LittleEndian();
|
||||||
//
|
var unkInner3 = fs.ReadInt32LittleEndian();
|
||||||
// byte[] copyBuffer = new byte[8192];
|
var unkInner4 = fs.ReadInt32LittleEndian();
|
||||||
//
|
var unkInner5 = fs.ReadInt32LittleEndian();
|
||||||
// foreach (var element in elements)
|
|
||||||
// {
|
Console.WriteLine($"\t\tUnkInner1: {unkInner1}");
|
||||||
// nResFs.Seek(element.OffsetInFile, SeekOrigin.Begin);
|
Console.WriteLine($"\t\tUnkInner2: {unkInner2}");
|
||||||
// using var destFs = new FileStream(Path.Combine(libFileName, element.FileName), FileMode.CreateNew);
|
Console.WriteLine($"\t\tUnkInner3: {unkInner3}");
|
||||||
//
|
Console.WriteLine($"\t\tUnkInner4: {unkInner4}");
|
||||||
// var totalCopiedBytes = 0;
|
Console.WriteLine($"\t\tUnkInner5: {unkInner5}");
|
||||||
// while (totalCopiedBytes < element.ItemLength)
|
|
||||||
// {
|
var innerInnerCount = fs.ReadInt32LittleEndian();
|
||||||
// var needReadBytes = Math.Min(element.ItemLength - totalCopiedBytes, copyBuffer.Length);
|
Console.WriteLine($"\t\tInnerInnerCount: {innerInnerCount}");
|
||||||
// var readBytes = nResFs.Read(copyBuffer, 0, needReadBytes);
|
|
||||||
//
|
for (var i2 = 0; i2 < innerInnerCount; i2++)
|
||||||
// destFs.Write(copyBuffer, 0, readBytes);
|
{
|
||||||
//
|
var innerInner = fs.ReadInt32LittleEndian();
|
||||||
// totalCopiedBytes += readBytes;
|
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