yuanshen/Yuanshen.Common/Data/Excel/PackedBin.cs
wisedev 61cc2055cf First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:06:53 +03:00

35 lines
1,003 B
C#

namespace Yuanshen.Common.Data.Excel;
public static class PackedBin
{
public const string ClientScriptVersion = "0.9.10";
public static byte GetKey(string scriptVersion)
{
int boundary = scriptVersion.LastIndexOf('.');
int key = 0;
for (int index = 0; index < boundary; index++)
key = (key + (scriptVersion[index] & 0xFF)) & 0xFF;
return key == 0 ? (byte)1 : (byte)key;
}
public static void Decode(Span<byte> bytes, byte key)
{
for (int index = 0; index < bytes.Length; index++)
{
bytes[index] ^= key;
}
}
public static byte[] Decode(ReadOnlySpan<byte> bytes, string scriptVersion = ClientScriptVersion)
{
byte[] decoded = bytes.ToArray();
Decode(decoded, GetKey(scriptVersion));
return decoded;
}
public static byte[] DecodeFile(string path, string scriptVersion = ClientScriptVersion)
=> Decode(File.ReadAllBytes(path), scriptVersion);
}