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 bytes, byte key) { for (int index = 0; index < bytes.Length; index++) { bytes[index] ^= key; } } public static byte[] Decode(ReadOnlySpan 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); }