Skip to content

Commit

Permalink
Test writing minimal sdb for PIN
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonKaminski committed Oct 9, 2024
1 parent 3526d21 commit 86936e3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Tests/SDBTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using FauFau.Formats;
using static FauFau.Formats.StaticDB;
Expand Down Expand Up @@ -92,5 +93,41 @@ public static void TestReadCustom()
Console.WriteLine();
}

public static void TestWriteMinimalPin()
{
var sdbLoader = @"X:\PIN\UdpHosts\GameServer\StaticDB\Loaders\StaticDBLoader.cs";
// var sdbLoader = new HttpClient().GetStreamAsync("https://raw.githubusercontent.com/themeldingwars/PIN/refs/heads/master/UdpHosts/GameServer/StaticDB/Loaders/StaticDBLoader.cs").Result;

Console.WriteLine("SDBTests.TestWriteMinimalPIN: Reading SDB: " + sdbPathRead);
StaticDB sdb = new StaticDB();
sdb.Read(sdbPathRead);

HashSet<uint> ids = new HashSet<uint>();

using (var reader = new StreamReader(sdbLoader))
{
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Contains(@">("""))
{
var idx = sdb.GetIndexByName(line.Split('"')[1]);

if (idx == -1)
{
Console.WriteLine($"Unknown table in line:\n{line}");
return;
}

ids.Add(sdb.Tables[idx].Id);
}
}
}

sdb.Tables.RemoveAll(table => !ids.Contains(table.Id));

Console.WriteLine("SDBTests.TestWriteMinimalPIN: Writing SDB: " + sdbPathWrite);
sdb.Write(sdbPathWrite);
}
}
}

0 comments on commit 86936e3

Please sign in to comment.