예제 #1
0
        private static byte[] Encode(
            IPackedSlot packed,
            int uniqueId,
            bool isWeapon,
            int assetLibrarySetId,
            Platform platform)
        {
            var writer = new BitWriter();

            writer.WriteInt32(InfoManager.AssetLibraryManager.Version, 7);
            writer.WriteBoolean(isWeapon);
            writer.WriteInt32(uniqueId, 32);
            writer.WriteUInt16(0xFFFF, 16);
            writer.WriteInt32(assetLibrarySetId, 8);
            packed.Write(writer, platform);

            var unobfuscatedBytes = writer.GetBuffer();

            if (unobfuscatedBytes.Length > 40)
            {
                throw new InvalidOperationException();
            }

            if (unobfuscatedBytes.Length < 40)
            {
                var start = unobfuscatedBytes.Length;
                Array.Resize(ref unobfuscatedBytes, 40);
                for (int i = start; i < unobfuscatedBytes.Length; i++)
                {
                    unobfuscatedBytes[i] = 0xFF;
                }
            }

            var hash          = CRC32.Hash(unobfuscatedBytes, 0, unobfuscatedBytes.Length);
            var computedCheck = (ushort)(((hash & 0xFFFF0000) >> 16) ^ ((hash & 0x0000FFFF) >> 0));

            unobfuscatedBytes[5] = (byte)((computedCheck & 0xFF00) >> 8);
            unobfuscatedBytes[6] = (byte)((computedCheck & 0x00FF) >> 0);

            for (int i = unobfuscatedBytes.Length - 1; i > 5; i--)
            {
                if (unobfuscatedBytes[i] != 0xFF)
                {
                    Array.Resize(ref unobfuscatedBytes, i + 1);
                    break;
                }
            }

            var data = (byte[])unobfuscatedBytes.Clone();
            var seed = BitConverter.ToUInt32(data, 1).Swap();

            BogoEncrypt(seed, data, 5, data.Length - 5);
            return(data);
        }
        public static byte[] Encode(IPackable packable)
        {
            if (packable == null)
            {
                throw new ArgumentNullException("packable");
            }

            if ((packable is BaseWeapon) == false &&
                (packable is BaseItem) == false)
            {
                throw new ArgumentException("unsupported packable");
            }

            var assetLibrarySet =
                InfoManager.AssetLibraryManager.Sets.SingleOrDefault(s => s.Id == packable.AssetLibrarySetId);

            if (assetLibrarySet == null)
            {
                throw new ArgumentException();
            }

            var writer = new BitWriter();

            writer.WriteInt32(InfoManager.AssetLibraryManager.Version, 7);
            writer.WriteBoolean(packable is BaseWeapon);
            writer.WriteInt32(packable.UniqueId, 32);
            writer.WriteUInt16(0xFFFF, 16);
            writer.WriteInt32(packable.AssetLibrarySetId, 8);
            packable.Write(writer);

            var unobfuscatedBytes = writer.GetBuffer();

            if (unobfuscatedBytes.Length > 40)
            {
                throw new InvalidOperationException();
            }

            if (unobfuscatedBytes.Length < 40)
            {
                var start = unobfuscatedBytes.Length;
                Array.Resize(ref unobfuscatedBytes, 40);
                for (int i = start; i < unobfuscatedBytes.Length; i++)
                {
                    unobfuscatedBytes[i] = 0xFF;
                }
            }

            var hash          = CRC32.Hash(unobfuscatedBytes, 0, unobfuscatedBytes.Length);
            var computedCheck = (ushort)(((hash & 0xFFFF0000) >> 16) ^ ((hash & 0x0000FFFF) >> 0));

            unobfuscatedBytes[5] = (byte)((computedCheck & 0xFF00) >> 8);
            unobfuscatedBytes[6] = (byte)((computedCheck & 0x00FF) >> 0);

            for (int i = unobfuscatedBytes.Length - 1; i > 5; i--)
            {
                if (unobfuscatedBytes[i] != 0xFF)
                {
                    Array.Resize(ref unobfuscatedBytes, i + 1);
                    break;
                }
            }

            var data = (byte[])unobfuscatedBytes.Clone();
            var seed = BitConverter.ToUInt32(data, 1).Swap();

            BogoEncrypt(seed, data, 5, data.Length - 5);
            return(data);
        }