Skip to content

Instantly share code, notes, and snippets.

@Scobalula
Last active June 25, 2022 13:18
Show Gist options
  • Save Scobalula/a0fd08197497336f67b7ff551b2db404 to your computer and use it in GitHub Desktop.
Save Scobalula/a0fd08197497336f67b7ff551b2db404 to your computer and use it in GitHub Desktop.
"""
Copyright (c) 2017 Philip Maher / Scobalula
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import lz4
import struct
import sys
import os
# Byte Padding, from PyCod's xBin (https://github.com/SE2Dev/PyCoD/blob/master/xbin.py#L24)
def padded(size):
return (size + 0x3) & 0xFFFFFFFFFFFFFC
# Decompression function
def FFDecompressor(fastfile):
with open("dump.dat", 'wb') as o:
with open(fastfile, 'rb') as f:
# Read Fast File Magic
magic = f.read(8)
# Check magic
if(magic != b'S1ff0100' or magic != b'S1ffu100'):
print("Fast File Magic '%s' does not match expected 'S1ff0100' or 'S1ffu100'" % (magic))
# Read Fast File Magic version
version = struct.unpack("I", f.read(4))[0]
# Check Fast File version
if(version != 0x42 or version != 0x72e):
print("Fast File Version '0x%x' does not match expected '0x42' or '0x72e'" % (version))
return
# Skip 12 bytes (Unknown)
f.read(12)
# Read number of Pre-Lz4 Data Blocks (Unknown)
numPreBlocks = struct.unpack("I", f.read(4))[0]
# Skip Pre Blocks (Unknown what they contain)
for i in range(numPreBlocks):
f.read(24)
# Get size of the fast file
ffSize = struct.unpack("I", f.read(4))[0]
# Skip 4 bytes (always 0)
f.read(4)
# Get second size (sometimes doesn't match above one?)
ffSize2 = struct.unpack("I", f.read(4))[0]
# Skip 6 bytes (Unknown)
f.read(6)
# Check if we're signed (skip 32768)
if magic == b'S1ff0100':
f.read(0x8000)
# Get number of LZ4 Blocks
numBlocks = struct.unpack("I", f.read(4))[0]
# Skip 2 Bytes
f.read(2)
# Check if we're signed (remove all hash blocks)
if(magic == b'S1ff0100'):
with open("no-hash-blocks.dat", 'wb') as output:
buffer = 1
while(buffer):
# Read 8388608 bytes
buffer = f.read(0x800000)
# Dump to file
output.write(buffer)
# Skip 16384 Byte Hash Block
f.read(0x4000)
f = open("no-hash-blocks.dat", 'rb')
# Skip 4 bytes (always 00 00 01 04?)
f.read(4)
# Begin decompressing Fast File
while(True):
# Read Block Size (+ 4 to include Uncompressed Size)
blockSize = struct.unpack("I", f.read(4))[0] + 4
# Track this blocks position
start = f.tell() + 4
# Decompress it and write to output
o.write(lz4.block.decompress(f.read(blockSize)))
# Skip byte padding and go to next block
f.seek(start + padded(f.tell() - start))
FFDecompressor("G:\\SteamLib\\steamapps\\common\\Call of Duty Advanced Warfare\\common_mp.ff")
input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment