Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import zipfile
|
| 3 |
import tempfile
|
| 4 |
import json
|
|
|
|
| 5 |
import UnityPy
|
| 6 |
from fastapi import FastAPI, UploadFile, File
|
| 7 |
from fastapi.responses import FileResponse
|
|
@@ -18,6 +19,41 @@ app.add_middleware(
|
|
| 18 |
allow_headers=["*"],
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@app.post("/extract")
|
| 22 |
async def extract_dialogues(
|
| 23 |
file: UploadFile = File(...),
|
|
@@ -26,12 +62,9 @@ async def extract_dialogues(
|
|
| 26 |
temp_dir = tempfile.mkdtemp()
|
| 27 |
asset_path = os.path.join(temp_dir, file.filename)
|
| 28 |
|
| 29 |
-
# Ana assets dosyasını kaydet
|
| 30 |
with open(asset_path, "wb") as f:
|
| 31 |
f.write(await file.read())
|
| 32 |
|
| 33 |
-
# Eğer DLL dosyası gönderilmişse, onu da aynı klasöre Managed alt yapısı gibi kaydet
|
| 34 |
-
# UnityPy DLL'leri okuyarak MonoBehaviour yapısını otomatik çözer
|
| 35 |
load_paths = [asset_path]
|
| 36 |
if assembly_file:
|
| 37 |
assembly_path = os.path.join(temp_dir, assembly_file.filename)
|
|
@@ -39,7 +72,6 @@ async def extract_dialogues(
|
|
| 39 |
f.write(await assembly_file.read())
|
| 40 |
load_paths.append(assembly_path)
|
| 41 |
|
| 42 |
-
# Tüm sağlanan dosyaları ortama yükle
|
| 43 |
env = UnityPy.load(*load_paths)
|
| 44 |
zip_filename = os.path.join(temp_dir, f"{file.filename}_dialogues.zip")
|
| 45 |
|
|
@@ -61,22 +93,19 @@ async def extract_dialogues(
|
|
| 61 |
log_content.append(f" -> Başarılı: {file_name}.txt oluşturuldu.")
|
| 62 |
|
| 63 |
elif obj.type.name == "MonoBehaviour":
|
| 64 |
-
# TypeTree okumayı dene (DLL yüklüyse buradan geçer)
|
| 65 |
tree = obj.read_typetree()
|
| 66 |
if tree:
|
| 67 |
zipf.writestr(f"{file_name}.json", json.dumps(tree, indent=4).encode('utf-8'))
|
| 68 |
extracted_count += 1
|
| 69 |
log_content.append(f" -> Başarılı: {file_name}.json oluşturuldu.")
|
| 70 |
else:
|
| 71 |
-
log_content.append(" -> Atlandı: TypeTree okunamadı.
|
| 72 |
except Exception as e:
|
| 73 |
-
log_content.append(f" -> HATA:
|
| 74 |
|
| 75 |
if extracted_count == 0:
|
| 76 |
-
log_content.append("\nSONUÇ:
|
| 77 |
-
log_content.append("ÖNERİ: 1) Assembly-CSharp.dll yüklediğinizden emin olun. 2) Diyaloglar başka bir dosyanın içinde olabilir.")
|
| 78 |
|
| 79 |
-
# Log dosyasını ZIP içine yaz
|
| 80 |
zipf.writestr("islem_raporu.txt", "\n".join(log_content).encode('utf-8'))
|
| 81 |
|
| 82 |
return FileResponse(zip_filename, media_type="application/zip", filename=f"{file.filename}_dialogues.zip")
|
|
@@ -105,13 +134,9 @@ async def repack_dialogues(
|
|
| 105 |
with zipfile.ZipFile(zip_path, 'r') as zipf:
|
| 106 |
for file_info in zipf.infolist():
|
| 107 |
filename = file_info.filename
|
| 108 |
-
|
| 109 |
-
# Geri paketlerken rapor dosyasını atla
|
| 110 |
-
if filename == "islem_raporu.txt":
|
| 111 |
-
continue
|
| 112 |
|
| 113 |
content = zipf.read(filename)
|
| 114 |
-
|
| 115 |
for obj in env.objects:
|
| 116 |
try:
|
| 117 |
data = obj.read()
|
|
|
|
| 2 |
import zipfile
|
| 3 |
import tempfile
|
| 4 |
import json
|
| 5 |
+
import subprocess
|
| 6 |
import UnityPy
|
| 7 |
from fastapi import FastAPI, UploadFile, File
|
| 8 |
from fastapi.responses import FileResponse
|
|
|
|
| 19 |
allow_headers=["*"],
|
| 20 |
)
|
| 21 |
|
| 22 |
+
@app.post("/generate_dll")
|
| 23 |
+
async def generate_dll(
|
| 24 |
+
binary_file: UploadFile = File(...),
|
| 25 |
+
metadata_file: UploadFile = File(...)
|
| 26 |
+
):
|
| 27 |
+
temp_dir = tempfile.mkdtemp()
|
| 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 |
+
f.write(await binary_file.read())
|
| 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)
|
| 38 |
+
|
| 39 |
+
# Il2CppDumper'ı Linux ortamında çalıştır
|
| 40 |
+
try:
|
| 41 |
+
subprocess.run([
|
| 42 |
+
"/app/dumper/Il2CppDumper",
|
| 43 |
+
binary_path,
|
| 44 |
+
metadata_path,
|
| 45 |
+
output_dir
|
| 46 |
+
], check=True, capture_output=True)
|
| 47 |
+
except subprocess.CalledProcessError as e:
|
| 48 |
+
return {"error": "Il2CppDumper çalışırken hata oluştu.", "details": e.stderr.decode('utf-8')}
|
| 49 |
+
|
| 50 |
+
# Çıkarılan DLL'yi bul ve geri yolla
|
| 51 |
+
dll_path = os.path.join(output_dir, "DummyDlls", "Assembly-CSharp.dll")
|
| 52 |
+
if os.path.exists(dll_path):
|
| 53 |
+
return FileResponse(dll_path, media_type="application/octet-stream", filename="Assembly-CSharp.dll")
|
| 54 |
+
else:
|
| 55 |
+
return {"error": "İşlem tamamlandı ancak DLL dosyası üretilemedi. Dosyaların doğru oyuna ait olduğundan emin olun."}
|
| 56 |
+
|
| 57 |
@app.post("/extract")
|
| 58 |
async def extract_dialogues(
|
| 59 |
file: UploadFile = File(...),
|
|
|
|
| 62 |
temp_dir = tempfile.mkdtemp()
|
| 63 |
asset_path = os.path.join(temp_dir, file.filename)
|
| 64 |
|
|
|
|
| 65 |
with open(asset_path, "wb") as f:
|
| 66 |
f.write(await file.read())
|
| 67 |
|
|
|
|
|
|
|
| 68 |
load_paths = [asset_path]
|
| 69 |
if assembly_file:
|
| 70 |
assembly_path = os.path.join(temp_dir, assembly_file.filename)
|
|
|
|
| 72 |
f.write(await assembly_file.read())
|
| 73 |
load_paths.append(assembly_path)
|
| 74 |
|
|
|
|
| 75 |
env = UnityPy.load(*load_paths)
|
| 76 |
zip_filename = os.path.join(temp_dir, f"{file.filename}_dialogues.zip")
|
| 77 |
|
|
|
|
| 93 |
log_content.append(f" -> Başarılı: {file_name}.txt oluşturuldu.")
|
| 94 |
|
| 95 |
elif obj.type.name == "MonoBehaviour":
|
|
|
|
| 96 |
tree = obj.read_typetree()
|
| 97 |
if tree:
|
| 98 |
zipf.writestr(f"{file_name}.json", json.dumps(tree, indent=4).encode('utf-8'))
|
| 99 |
extracted_count += 1
|
| 100 |
log_content.append(f" -> Başarılı: {file_name}.json oluşturuldu.")
|
| 101 |
else:
|
| 102 |
+
log_content.append(" -> Atlandı: TypeTree okunamadı. DLL eksik olabilir.")
|
| 103 |
except Exception as e:
|
| 104 |
+
log_content.append(f" -> HATA: {str(e)}")
|
| 105 |
|
| 106 |
if extracted_count == 0:
|
| 107 |
+
log_content.append("\nSONUÇ: Çıkarılabilir hiçbir metin bulunamadı.")
|
|
|
|
| 108 |
|
|
|
|
| 109 |
zipf.writestr("islem_raporu.txt", "\n".join(log_content).encode('utf-8'))
|
| 110 |
|
| 111 |
return FileResponse(zip_filename, media_type="application/zip", filename=f"{file.filename}_dialogues.zip")
|
|
|
|
| 134 |
with zipfile.ZipFile(zip_path, 'r') as zipf:
|
| 135 |
for file_info in zipf.infolist():
|
| 136 |
filename = file_info.filename
|
| 137 |
+
if filename == "islem_raporu.txt": continue
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
content = zipf.read(filename)
|
|
|
|
| 140 |
for obj in env.objects:
|
| 141 |
try:
|
| 142 |
data = obj.read()
|