Skip to content

Instantly share code, notes, and snippets.

@MoePus
Created November 27, 2018 13:50
Show Gist options
  • Save MoePus/39a7fd33afb9ad7f4542d8110cd40e6a to your computer and use it in GitHub Desktop.
Save MoePus/39a7fd33afb9ad7f4542d8110cd40e6a to your computer and use it in GitHub Desktop.
shaderPack = r'C:\ProgramData\Redshift\Data\Redshift1.dat'
from struct import unpack
import os
shaderdataFloder = r'Redshift1'
os.makedirs(shaderdataFloder,exist_ok=True)
def dint(b):
return unpack("i",b)[0]
def decodeData(data,factor):
factor = factor & 0xff
result = b''
for v3 in range(len(data)):
v4 = data[v3]
eax = v3 + v4
result += bytes([factor ^ v4])
factor = eax & 0xff
return result
shaders = {}
with open(shaderPack,'rb') as fp:
shaderNum = dint(fp.read(4))
for v6 in range(shaderNum):
nameLength = dint(fp.read(4))
cryptedName = fp.read(nameLength)
name = decodeData(cryptedName,v6)
size = dint(decodeData(fp.read(4),v6))
offset = dint(decodeData(fp.read(4),v6))
shaders[name.decode()] = {
"offset":offset,
"size":size,
"factor":v6
}
for filename in shaders:
shader = shaders[filename]
fp.seek(shader["offset"])
data = fp.read(shader["size"])
with open(os.path.join(shaderdataFloder,filename),"wb") as wfp:
wfp.write(decodeData(data,shader["factor"]))
@syl1990144
Copy link

syl1990144 commented Oct 9, 2021

hello, how do I package all the unpacked bin files into a. Dat file? can you write a pack .py file?
thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment