Update app.py
Browse files
app.py
CHANGED
|
@@ -28,10 +28,8 @@ async def generate_dll(
|
|
| 28 |
binary_path = os.path.join(temp_dir, binary_file.filename)
|
| 29 |
metadata_path = os.path.join(temp_dir, metadata_file.filename)
|
| 30 |
|
| 31 |
-
with open(binary_path, "wb") as f:
|
| 32 |
-
|
| 33 |
-
with open(metadata_path, "wb") as f:
|
| 34 |
-
f.write(await metadata_file.read())
|
| 35 |
|
| 36 |
output_dir = os.path.join(temp_dir, "output")
|
| 37 |
os.makedirs(output_dir, exist_ok=True)
|
|
@@ -39,35 +37,31 @@ async def generate_dll(
|
|
| 39 |
config_path = "/app/dumper/config.json"
|
| 40 |
if os.path.exists(config_path):
|
| 41 |
try:
|
| 42 |
-
with open(config_path, "r") as f:
|
| 43 |
-
config_data = f.read()
|
| 44 |
config_data = config_data.replace('"RequireAnyKey": true', '"RequireAnyKey": false')
|
| 45 |
-
with open(config_path, "w") as f:
|
| 46 |
-
|
| 47 |
-
except Exception:
|
| 48 |
-
pass
|
| 49 |
|
| 50 |
-
# 1. ÖNCE PROGRAMI ÇALIŞTIRIYORUZ
|
| 51 |
try:
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
binary_path,
|
| 55 |
-
metadata_path,
|
| 56 |
-
output_dir
|
| 57 |
-
], capture_output=True)
|
| 58 |
-
except subprocess.CalledProcessError as e:
|
| 59 |
-
pass # Hata verse bile dosyayı ürettiğini loglardan görmüştük, bu yüzden devam ediyoruz.
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
-
if os.path.exists(
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
else:
|
| 70 |
-
return {"error": "İşlem başarısız.", "details": "DLL
|
| 71 |
|
| 72 |
@app.post("/extract")
|
| 73 |
async def extract_dialogues(
|
|
@@ -77,15 +71,25 @@ async def extract_dialogues(
|
|
| 77 |
temp_dir = tempfile.mkdtemp()
|
| 78 |
asset_path = os.path.join(temp_dir, file.filename)
|
| 79 |
|
| 80 |
-
with open(asset_path, "wb") as f:
|
| 81 |
-
f.write(await file.read())
|
| 82 |
|
| 83 |
load_paths = [asset_path]
|
| 84 |
if assembly_file:
|
| 85 |
assembly_path = os.path.join(temp_dir, assembly_file.filename)
|
| 86 |
-
with open(assembly_path, "wb") as f:
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
env = UnityPy.load(*load_paths)
|
| 91 |
zip_filename = os.path.join(temp_dir, f"{file.filename}_dialogues.zip")
|
|
@@ -100,13 +104,11 @@ async def extract_dialogues(
|
|
| 100 |
try:
|
| 101 |
data = obj.read()
|
| 102 |
file_name = getattr(data, "name", f"{obj.type.name}_{obj.path_id}")
|
| 103 |
-
|
| 104 |
if obj.type.name == "TextAsset":
|
| 105 |
content = data.text.encode('utf-8')
|
| 106 |
zipf.writestr(f"{file_name}.txt", content)
|
| 107 |
extracted_count += 1
|
| 108 |
log_content.append(f" -> Başarılı: {file_name}.txt oluşturuldu.")
|
| 109 |
-
|
| 110 |
elif obj.type.name == "MonoBehaviour":
|
| 111 |
tree = obj.read_typetree()
|
| 112 |
if tree:
|
|
@@ -114,13 +116,11 @@ async def extract_dialogues(
|
|
| 114 |
extracted_count += 1
|
| 115 |
log_content.append(f" -> Başarılı: {file_name}.json oluşturuldu.")
|
| 116 |
else:
|
| 117 |
-
log_content.append(" -> Atlandı: TypeTree okunamadı.
|
| 118 |
except Exception as e:
|
| 119 |
log_content.append(f" -> HATA: {str(e)}")
|
| 120 |
|
| 121 |
-
if extracted_count == 0:
|
| 122 |
-
log_content.append("\nSONUÇ: Çıkarılabilir hiçbir metin bulunamadı.")
|
| 123 |
-
|
| 124 |
zipf.writestr("islem_raporu.txt", "\n".join(log_content).encode('utf-8'))
|
| 125 |
|
| 126 |
return FileResponse(zip_filename, media_type="application/zip", filename=f"{file.filename}_dialogues.zip")
|
|
@@ -142,21 +142,29 @@ async def repack_dialogues(
|
|
| 142 |
if assembly_file:
|
| 143 |
assembly_path = os.path.join(temp_dir, assembly_file.filename)
|
| 144 |
with open(assembly_path, "wb") as f: f.write(await assembly_file.read())
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
env = UnityPy.load(*load_paths)
|
| 148 |
-
|
| 149 |
with zipfile.ZipFile(zip_path, 'r') as zipf:
|
| 150 |
for file_info in zipf.infolist():
|
| 151 |
filename = file_info.filename
|
| 152 |
if filename == "islem_raporu.txt": continue
|
| 153 |
-
|
| 154 |
content = zipf.read(filename)
|
| 155 |
for obj in env.objects:
|
| 156 |
try:
|
| 157 |
data = obj.read()
|
| 158 |
obj_name = getattr(data, "name", f"{obj.type.name}_{obj.path_id}")
|
| 159 |
-
|
| 160 |
if obj.type.name == "TextAsset" and filename == f"{obj_name}.txt":
|
| 161 |
data.text = content.decode('utf-8')
|
| 162 |
data.save()
|
|
@@ -165,11 +173,9 @@ async def repack_dialogues(
|
|
| 165 |
tree = json.loads(content.decode('utf-8'))
|
| 166 |
obj.save_typetree(tree)
|
| 167 |
break
|
| 168 |
-
except:
|
| 169 |
-
pass
|
| 170 |
|
| 171 |
output_path = os.path.join(temp_dir, f"repacked_{asset_file.filename}")
|
| 172 |
-
with open(output_path, "wb") as f:
|
| 173 |
-
f.write(env.file.save())
|
| 174 |
|
| 175 |
return FileResponse(output_path, media_type="application/octet-stream", filename=asset_file.filename)
|
|
|
|
| 28 |
binary_path = os.path.join(temp_dir, binary_file.filename)
|
| 29 |
metadata_path = os.path.join(temp_dir, metadata_file.filename)
|
| 30 |
|
| 31 |
+
with open(binary_path, "wb") as f: f.write(await binary_file.read())
|
| 32 |
+
with open(metadata_path, "wb") as f: f.write(await metadata_file.read())
|
|
|
|
|
|
|
| 33 |
|
| 34 |
output_dir = os.path.join(temp_dir, "output")
|
| 35 |
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
| 37 |
config_path = "/app/dumper/config.json"
|
| 38 |
if os.path.exists(config_path):
|
| 39 |
try:
|
| 40 |
+
with open(config_path, "r") as f: config_data = f.read()
|
|
|
|
| 41 |
config_data = config_data.replace('"RequireAnyKey": true', '"RequireAnyKey": false')
|
| 42 |
+
with open(config_path, "w") as f: f.write(config_data)
|
| 43 |
+
except Exception: pass
|
|
|
|
|
|
|
| 44 |
|
|
|
|
| 45 |
try:
|
| 46 |
+
subprocess.run(["/app/dumper/Il2CppDumper", binary_path, metadata_path, output_dir], capture_output=True)
|
| 47 |
+
except subprocess.CalledProcessError: pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
# YENİLİK: Artık tek bir DLL yerine tüm DLL klasörünü ZIP olarak yolluyoruz.
|
| 50 |
+
dummy_dll_dir_1 = os.path.join(output_dir, "DummyDll")
|
| 51 |
+
dummy_dll_dir_2 = os.path.join(output_dir, "DummyDlls")
|
| 52 |
+
target_dir = dummy_dll_dir_1 if os.path.exists(dummy_dll_dir_1) else dummy_dll_dir_2
|
| 53 |
|
| 54 |
+
if os.path.exists(target_dir):
|
| 55 |
+
zip_path = os.path.join(temp_dir, "DummyDlls.zip")
|
| 56 |
+
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
| 57 |
+
for root, _, files in os.walk(target_dir):
|
| 58 |
+
for file in files:
|
| 59 |
+
if file.endswith(".dll"):
|
| 60 |
+
file_path = os.path.join(root, file)
|
| 61 |
+
zipf.write(file_path, arcname=file)
|
| 62 |
+
return FileResponse(zip_path, media_type="application/zip", filename="DummyDlls.zip")
|
| 63 |
else:
|
| 64 |
+
return {"error": "İşlem başarısız.", "details": "DLL klasörü bulunamadı."}
|
| 65 |
|
| 66 |
@app.post("/extract")
|
| 67 |
async def extract_dialogues(
|
|
|
|
| 71 |
temp_dir = tempfile.mkdtemp()
|
| 72 |
asset_path = os.path.join(temp_dir, file.filename)
|
| 73 |
|
| 74 |
+
with open(asset_path, "wb") as f: f.write(await file.read())
|
|
|
|
| 75 |
|
| 76 |
load_paths = [asset_path]
|
| 77 |
if assembly_file:
|
| 78 |
assembly_path = os.path.join(temp_dir, assembly_file.filename)
|
| 79 |
+
with open(assembly_path, "wb") as f: f.write(await assembly_file.read())
|
| 80 |
+
|
| 81 |
+
# YENİLİK: Eğer kullanıcı DummyDlls.zip yüklediyse onu aç ve içindeki TÜM DLL'leri tarat
|
| 82 |
+
if assembly_file.filename.endswith(".zip"):
|
| 83 |
+
dummy_dll_dir = os.path.join(temp_dir, "ExtractedDlls")
|
| 84 |
+
os.makedirs(dummy_dll_dir, exist_ok=True)
|
| 85 |
+
with zipfile.ZipFile(assembly_path, 'r') as zipf:
|
| 86 |
+
zipf.extractall(dummy_dll_dir)
|
| 87 |
+
for root, _, files in os.walk(dummy_dll_dir):
|
| 88 |
+
for dll_file in files:
|
| 89 |
+
if dll_file.endswith(".dll"):
|
| 90 |
+
load_paths.append(os.path.join(root, dll_file))
|
| 91 |
+
else:
|
| 92 |
+
load_paths.append(assembly_path)
|
| 93 |
|
| 94 |
env = UnityPy.load(*load_paths)
|
| 95 |
zip_filename = os.path.join(temp_dir, f"{file.filename}_dialogues.zip")
|
|
|
|
| 104 |
try:
|
| 105 |
data = obj.read()
|
| 106 |
file_name = getattr(data, "name", f"{obj.type.name}_{obj.path_id}")
|
|
|
|
| 107 |
if obj.type.name == "TextAsset":
|
| 108 |
content = data.text.encode('utf-8')
|
| 109 |
zipf.writestr(f"{file_name}.txt", content)
|
| 110 |
extracted_count += 1
|
| 111 |
log_content.append(f" -> Başarılı: {file_name}.txt oluşturuldu.")
|
|
|
|
| 112 |
elif obj.type.name == "MonoBehaviour":
|
| 113 |
tree = obj.read_typetree()
|
| 114 |
if tree:
|
|
|
|
| 116 |
extracted_count += 1
|
| 117 |
log_content.append(f" -> Başarılı: {file_name}.json oluşturuldu.")
|
| 118 |
else:
|
| 119 |
+
log_content.append(" -> Atlandı: TypeTree okunamadı.")
|
| 120 |
except Exception as e:
|
| 121 |
log_content.append(f" -> HATA: {str(e)}")
|
| 122 |
|
| 123 |
+
if extracted_count == 0: log_content.append("\nSONUÇ: Çıkarılabilir metin bulunamadı.")
|
|
|
|
|
|
|
| 124 |
zipf.writestr("islem_raporu.txt", "\n".join(log_content).encode('utf-8'))
|
| 125 |
|
| 126 |
return FileResponse(zip_filename, media_type="application/zip", filename=f"{file.filename}_dialogues.zip")
|
|
|
|
| 142 |
if assembly_file:
|
| 143 |
assembly_path = os.path.join(temp_dir, assembly_file.filename)
|
| 144 |
with open(assembly_path, "wb") as f: f.write(await assembly_file.read())
|
| 145 |
+
|
| 146 |
+
if assembly_file.filename.endswith(".zip"):
|
| 147 |
+
dummy_dll_dir = os.path.join(temp_dir, "ExtractedDlls")
|
| 148 |
+
os.makedirs(dummy_dll_dir, exist_ok=True)
|
| 149 |
+
with zipfile.ZipFile(assembly_path, 'r') as zipf:
|
| 150 |
+
zipf.extractall(dummy_dll_dir)
|
| 151 |
+
for root, _, files in os.walk(dummy_dll_dir):
|
| 152 |
+
for dll_file in files:
|
| 153 |
+
if dll_file.endswith(".dll"):
|
| 154 |
+
load_paths.append(os.path.join(root, dll_file))
|
| 155 |
+
else:
|
| 156 |
+
load_paths.append(assembly_path)
|
| 157 |
|
| 158 |
env = UnityPy.load(*load_paths)
|
|
|
|
| 159 |
with zipfile.ZipFile(zip_path, 'r') as zipf:
|
| 160 |
for file_info in zipf.infolist():
|
| 161 |
filename = file_info.filename
|
| 162 |
if filename == "islem_raporu.txt": continue
|
|
|
|
| 163 |
content = zipf.read(filename)
|
| 164 |
for obj in env.objects:
|
| 165 |
try:
|
| 166 |
data = obj.read()
|
| 167 |
obj_name = getattr(data, "name", f"{obj.type.name}_{obj.path_id}")
|
|
|
|
| 168 |
if obj.type.name == "TextAsset" and filename == f"{obj_name}.txt":
|
| 169 |
data.text = content.decode('utf-8')
|
| 170 |
data.save()
|
|
|
|
| 173 |
tree = json.loads(content.decode('utf-8'))
|
| 174 |
obj.save_typetree(tree)
|
| 175 |
break
|
| 176 |
+
except: pass
|
|
|
|
| 177 |
|
| 178 |
output_path = os.path.join(temp_dir, f"repacked_{asset_file.filename}")
|
| 179 |
+
with open(output_path, "wb") as f: f.write(env.file.save())
|
|
|
|
| 180 |
|
| 181 |
return FileResponse(output_path, media_type="application/octet-stream", filename=asset_file.filename)
|