首先...我是python的新手,这不是我的代码。 我只是试图找出为什么代码无法正常工作。 这就是代码:
from PIL import Image
import sys, os, errno
exported = 0
def search(file):
f = open(file, "rb")
offset = 0
chunk = 1000000000;
skinlist = list()
found = -1
foundstr = -1
while 1:
f.seek(offset)
data = f.read(chunk)
dataSize = len(data)
if foundstr == -1:
foundstr = data.find("/Game/UI/Foundation/Textures/Icons/Heroes/Athena/Soldier/T-Soldier-HID-001-Athena-Commando-F-L")
if foundstr >= 0:
print("NOW SEARCHING FOR NAMES")
f.seek(offset)
findStrings(f, data, offset, skinlist, foundstr - 1)
offset += dataSize
continue
if foundstr >= 0:
findStrings(f, data, offset, skinlist, -1)
if found == -1:
found = data.find("\xFA\xC5\x99\x20\xCC\x85\x5C\x4B\x90\x05\xEC\xB6\x58\xA7\x3F\x71\x0C")
if found >= 0:
print("NOW EXPORTING TEXTURES")
f.seek(offset)
export(f, data, offset, skinlist, found)
offset += dataSize
continue
if found >= 0:
f.seek(offset)
export(f, data, offset, skinlist, -1)
print("READING...")
offset += dataSize
if dataSize < chunk:
print("Finished file!")
break
print(str(exported - 1) + " exported!")
f.close()
def findStrings(f, data, offset, skinlist, start):
while 1 :
start = data.find("/Game/UI/Foundation/Textures/Icons/Heroes/Athena/Soldier/", start + 1)
if start == -1:
break
end = data.find("\x00", start)
if end != -1 and end - start < 200:
f.seek(offset + start)
name = f.read(end - start)
if((name.endswith("-L") or name.endswith("_L")) and "." not in name and "T-Soldier-HID-035-Athena-Commando-M-Medieval-L" not in name and name not in skinlist):
print("FOUND: " + name)
skinlist.append(name)
def export(f, data, offset, skinlist, start):
while 1 :
start = data.find("\x50\x46\x5F\x44\x58\x54\x35\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x48", start +1)
#print(start)
if start == -1:
break
end = data.find("\x00\x00\x00\x00\x00\x00\x00\xC1\x83\x2A\x9E", start)
# print(end)
if end != -1 and end - start == 262197:
end = end - 7
name = skinlist[exported]
name = name[name.rfind("/") + 1:]
print("FOUND BYTES FOR: " + name)
print(offset + start)
try:
skip = 40
f.seek(offset + end - 1)
size = f.read(1)
dds = open("images/" + name + ".dds", "w+b")
dds.write("\x44\x44\x53\x20\x7C\x00\x00\x00\x07\x10\x08\x00\x00" + size + "\x00\x00\x00" + size + "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4E\x56\x54\x54\x06\x00\x02\x00\x20\x00\x00\x00\x04\x00\x00\x00\x44\x58\x54\x35\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
f.seek(offset + start + skip)
length = end - start - skip - 6
dds.write(f.read(length))
#print("LENGTH: " + str(length))
dds.close()
Image.MAX_IMAGE_PIXELS = None
im = Image.open("images/" + name + ".dds")
im.save("images/" + name + ".png")
os.remove("images/" + name + ".dds")
exported
exported += 1
print("EXPORTED: " + name + " " + str(exported) + " / " + str(len(skinlist)))
if len(skinlist) == exported:
print("Finished list! Exported: " + str(exported))
f.close()
sys.exit(0)
except Exception as inst:
print(inst)
if __name__ == '__main__':
if len(sys.argv) <= 1:
sys.exit("[Error] Usage: IconExporter.py <file>")
inFile = sys.argv[1]
search(inFile)
此代码应在.pak文件中找到图标,并将其复制到名为images的文件夹中。 它没有显示错误。但是它不能正常运行。如果我运行它,输出为:
-WindowsClient.pak
READING...
Finished file!
-1 exported!
,但不导出任何内容。 可以给我解释一下为什么。