mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-09-21 22:34:58 +00:00
Port VBSP to new printing
This commit is contained in:
@@ -22,6 +22,24 @@ namespace BinaryObjectScanner.Printing
|
||||
return sb.AppendLine($"{prefixString}: {value.ToString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a line containing a Char to a StringBuilder
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, char value, string prefixString)
|
||||
#else
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, char? value, string prefixString)
|
||||
#endif
|
||||
{
|
||||
#if NET48
|
||||
string valueString = value.ToString();
|
||||
#else
|
||||
string valueString = value == null ? "[NULL]" : value.ToString();
|
||||
#endif
|
||||
|
||||
return sb.AppendLine($"{prefixString}: {valueString}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a line containing a Int8 to a StringBuilder
|
||||
/// </summary>
|
||||
@@ -220,6 +238,19 @@ namespace BinaryObjectScanner.Printing
|
||||
return sb.AppendLine($"{prefixString}: {valueString}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a line containing a Char[] value to a StringBuilder
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, char[] value, string prefixString)
|
||||
#else
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, char[]? value, string prefixString)
|
||||
#endif
|
||||
{
|
||||
string valueString = (value == null ? "[NULL]" : string.Join(", ", value));
|
||||
return sb.AppendLine($"{prefixString}: {valueString}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a line containing a Int16[] value to a StringBuilder
|
||||
/// </summary>
|
||||
|
||||
85
BinaryObjectScanner.Printing/VBSP.cs
Normal file
85
BinaryObjectScanner.Printing/VBSP.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Text;
|
||||
using SabreTools.Models.VBSP;
|
||||
using static SabreTools.Models.VBSP.Constants;
|
||||
|
||||
namespace BinaryObjectScanner.Printing
|
||||
{
|
||||
public static class VBSP
|
||||
{
|
||||
public static void Print(StringBuilder builder, File file)
|
||||
{
|
||||
builder.AppendLine("VBSP Information:");
|
||||
builder.AppendLine("-------------------------");
|
||||
builder.AppendLine();
|
||||
|
||||
Print(builder, file.Header);
|
||||
}
|
||||
|
||||
#if NET48
|
||||
private static void Print(StringBuilder builder, Header header)
|
||||
#else
|
||||
private static void Print(StringBuilder builder, Header? header)
|
||||
#endif
|
||||
{
|
||||
builder.AppendLine(" Header Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (header == null)
|
||||
{
|
||||
builder.AppendLine(" No header");
|
||||
builder.AppendLine();
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendLine(header.Signature, " Signature");
|
||||
builder.AppendLine(header.Version, " Version");
|
||||
builder.AppendLine(header.MapRevision, " Map revision");
|
||||
builder.AppendLine();
|
||||
|
||||
Print(builder, header.Lumps);
|
||||
}
|
||||
|
||||
#if NET48
|
||||
private static void Print(StringBuilder builder, Lump[] lumps)
|
||||
#else
|
||||
private static void Print(StringBuilder builder, Lump?[]? lumps)
|
||||
#endif
|
||||
{
|
||||
builder.AppendLine(" Lumps Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (lumps == null || lumps.Length == 0)
|
||||
{
|
||||
builder.AppendLine(" No lumps");
|
||||
builder.AppendLine();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lumps.Length; i++)
|
||||
{
|
||||
var lump = lumps[i];
|
||||
string specialLumpName = string.Empty;
|
||||
switch (i)
|
||||
{
|
||||
case HL_VBSP_LUMP_ENTITIES:
|
||||
specialLumpName = " (entities)";
|
||||
break;
|
||||
case HL_VBSP_LUMP_PAKFILE:
|
||||
specialLumpName = " (pakfile)";
|
||||
break;
|
||||
}
|
||||
|
||||
builder.AppendLine($" Lump {i}{specialLumpName}");
|
||||
if (lump == null)
|
||||
{
|
||||
builder.AppendLine(" [NULL]");
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.AppendLine(lump.Offset, " Offset");
|
||||
builder.AppendLine(lump.Length, " Length");
|
||||
builder.AppendLine(lump.Version, " Version");
|
||||
builder.AppendLine(lump.FourCC, " 4CC");
|
||||
}
|
||||
builder.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,77 +137,10 @@ namespace BinaryObjectScanner.Wrappers
|
||||
public override StringBuilder PrettyPrint()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("VBSP Information:");
|
||||
builder.AppendLine("-------------------------");
|
||||
builder.AppendLine();
|
||||
|
||||
PrintHeader(builder);
|
||||
PrintLumps(builder);
|
||||
|
||||
Printing.VBSP.Print(builder, _model);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print header information
|
||||
/// </summary>
|
||||
/// <param name="builder">StringBuilder to append information to</param>
|
||||
/// <remarks>Slightly out of order due to the lumps</remarks>
|
||||
private void PrintHeader(StringBuilder builder)
|
||||
{
|
||||
builder.AppendLine(" Header Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
builder.AppendLine($" Signature: {Signature}");
|
||||
builder.AppendLine($" Version: {Version} (0x{Version:X})");
|
||||
builder.AppendLine($" Map revision: {MapRevision} (0x{MapRevision:X})");
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print lumps information
|
||||
/// </summary>
|
||||
/// <param name="builder">StringBuilder to append information to</param>
|
||||
/// <remarks>Technically part of the header</remarks>
|
||||
private void PrintLumps(StringBuilder builder)
|
||||
{
|
||||
builder.AppendLine(" Lumps Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (Lumps == null || Lumps.Length == 0)
|
||||
{
|
||||
builder.AppendLine(" No lumps");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < Lumps.Length; i++)
|
||||
{
|
||||
var lump = Lumps[i];
|
||||
string specialLumpName = string.Empty;
|
||||
switch (i)
|
||||
{
|
||||
case HL_VBSP_LUMP_ENTITIES:
|
||||
specialLumpName = " (entities)";
|
||||
break;
|
||||
case HL_VBSP_LUMP_PAKFILE:
|
||||
specialLumpName = " (pakfile)";
|
||||
break;
|
||||
}
|
||||
|
||||
builder.AppendLine($" Lump {i}{specialLumpName}");
|
||||
if (lump == null)
|
||||
{
|
||||
builder.AppendLine(" [NULL]");
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.AppendLine($" Offset: {lump.Offset} (0x{lump.Offset:X})");
|
||||
builder.AppendLine($" Length: {lump.Length} (0x{lump.Length:X})");
|
||||
builder.AppendLine($" Version: {lump.Version} (0x{lump.Version:X})");
|
||||
builder.AppendLine($" 4CC: {(lump.FourCC == null ? "[NULL]" : string.Join(", ", lump.FourCC))}");
|
||||
}
|
||||
}
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
Reference in New Issue
Block a user