mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-18 15:49:47 +03:00
Implement SCR UI
This commit is contained in:
39
ScrLib/Extensions.cs
Normal file
39
ScrLib/Extensions.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Text;
|
||||
|
||||
namespace ScrLib;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
3
ScrLib/MissionTmaParseResult.cs
Normal file
3
ScrLib/MissionTmaParseResult.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace ScrLib;
|
||||
|
||||
public record ScrParseResult(ScrFile? Scr, string? Error);
|
43
ScrLib/ScrFile.cs
Normal file
43
ScrLib/ScrFile.cs
Normal file
@ -0,0 +1,43 @@
|
||||
namespace ScrLib;
|
||||
|
||||
public class ScrFile
|
||||
{
|
||||
/// <summary>
|
||||
/// тут всегда число 59 (0x3b) - это число известных игре скриптов
|
||||
/// </summary>
|
||||
public int Magic { get; set; }
|
||||
|
||||
public int EntryCount { get; set; }
|
||||
|
||||
public List<ScrEntry> Entries { get; set; }
|
||||
}
|
||||
|
||||
public class ScrEntry
|
||||
{
|
||||
public string Title { get; set; }
|
||||
|
||||
public int Index { get; set; }
|
||||
|
||||
public int InnerCount { get; set; }
|
||||
|
||||
public List<ScrEntryInner> Inners { get; set; }
|
||||
}
|
||||
|
||||
public class ScrEntryInner
|
||||
{
|
||||
/// <summary>
|
||||
/// Номер скрипта в игре (это тех, которых 0x3b)
|
||||
/// </summary>
|
||||
public int ScriptIndex { get; set; }
|
||||
|
||||
public int UnkInner2 { get; set; }
|
||||
public int UnkInner3 { get; set; }
|
||||
public int UnkInner4 { get; set; }
|
||||
public int UnkInner5 { get; set; }
|
||||
|
||||
public int ArgumentsCount { get; set; }
|
||||
|
||||
public List<int> Arguments { get; set; }
|
||||
|
||||
public int UnkInner7 { get; set; }
|
||||
}
|
9
ScrLib/ScrLib.csproj
Normal file
9
ScrLib/ScrLib.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
55
ScrLib/ScrParser.cs
Normal file
55
ScrLib/ScrParser.cs
Normal file
@ -0,0 +1,55 @@
|
||||
namespace ScrLib;
|
||||
|
||||
public class ScrParser
|
||||
{
|
||||
public static ScrFile ReadFile(string filePath)
|
||||
{
|
||||
var fs = new FileStream(filePath, FileMode.Open);
|
||||
|
||||
var scrFile = new ScrFile();
|
||||
|
||||
scrFile.Magic = fs.ReadInt32LittleEndian();
|
||||
|
||||
scrFile.EntryCount = fs.ReadInt32LittleEndian();
|
||||
scrFile.Entries = [];
|
||||
|
||||
for (var i = 0; i < scrFile.EntryCount; i++)
|
||||
{
|
||||
var entry = new ScrEntry();
|
||||
entry.Title = fs.ReadLengthPrefixedString();
|
||||
|
||||
// тут игра дополнительно вычитывает ещё 1 байт, видимо как \0 для char*
|
||||
fs.ReadByte();
|
||||
|
||||
entry.Index = fs.ReadInt32LittleEndian();
|
||||
entry.InnerCount = fs.ReadInt32LittleEndian();
|
||||
entry.Inners = [];
|
||||
for (var i1 = 0; i1 < entry.InnerCount; i1++)
|
||||
{
|
||||
var entryInner = new ScrEntryInner();
|
||||
entryInner.ScriptIndex = fs.ReadInt32LittleEndian();
|
||||
|
||||
entryInner.UnkInner2 = fs.ReadInt32LittleEndian();
|
||||
entryInner.UnkInner3 = fs.ReadInt32LittleEndian();
|
||||
entryInner.UnkInner4 = fs.ReadInt32LittleEndian();
|
||||
entryInner.UnkInner5 = fs.ReadInt32LittleEndian();
|
||||
|
||||
entryInner.ArgumentsCount = fs.ReadInt32LittleEndian();
|
||||
|
||||
entryInner.Arguments = [];
|
||||
|
||||
for (var i2 = 0; i2 < entryInner.ArgumentsCount; i2++)
|
||||
{
|
||||
entryInner.Arguments.Add(fs.ReadInt32LittleEndian());
|
||||
}
|
||||
|
||||
entryInner.UnkInner7 = fs.ReadInt32LittleEndian();
|
||||
entry.Inners.Add(entryInner);
|
||||
}
|
||||
|
||||
scrFile.Entries.Add(entry);
|
||||
}
|
||||
|
||||
return scrFile;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user