Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import zipfile
|
| 3 |
import tempfile
|
|
|
|
| 4 |
import UnityPy
|
| 5 |
from fastapi import FastAPI, UploadFile, File
|
| 6 |
from fastapi.responses import FileResponse
|
|
@@ -43,9 +44,12 @@ async def extract_dialogues(
|
|
| 43 |
zip_filename = os.path.join(temp_dir, f"{file.filename}_dialogues.zip")
|
| 44 |
|
| 45 |
extracted_count = 0
|
|
|
|
|
|
|
| 46 |
with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
| 47 |
for obj in env.objects:
|
| 48 |
if obj.type.name in ["TextAsset", "MonoBehaviour"]:
|
|
|
|
| 49 |
try:
|
| 50 |
data = obj.read()
|
| 51 |
file_name = getattr(data, "name", f"{obj.type.name}_{obj.path_id}")
|
|
@@ -54,17 +58,26 @@ async def extract_dialogues(
|
|
| 54 |
content = data.text.encode('utf-8')
|
| 55 |
zipf.writestr(f"{file_name}.txt", content)
|
| 56 |
extracted_count += 1
|
|
|
|
| 57 |
|
| 58 |
elif obj.type.name == "MonoBehaviour":
|
| 59 |
-
# TypeTree
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
import json
|
| 63 |
zipf.writestr(f"{file_name}.json", json.dumps(tree, indent=4).encode('utf-8'))
|
| 64 |
extracted_count += 1
|
|
|
|
|
|
|
|
|
|
| 65 |
except Exception as e:
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
return FileResponse(zip_filename, media_type="application/zip", filename=f"{file.filename}_dialogues.zip")
|
| 70 |
|
|
@@ -92,6 +105,11 @@ async def repack_dialogues(
|
|
| 92 |
with zipfile.ZipFile(zip_path, 'r') as zipf:
|
| 93 |
for file_info in zipf.infolist():
|
| 94 |
filename = file_info.filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
content = zipf.read(filename)
|
| 96 |
|
| 97 |
for obj in env.objects:
|
|
@@ -104,7 +122,6 @@ async def repack_dialogues(
|
|
| 104 |
data.save()
|
| 105 |
break
|
| 106 |
elif obj.type.name == "MonoBehaviour" and filename == f"{obj_name}.json":
|
| 107 |
-
import json
|
| 108 |
tree = json.loads(content.decode('utf-8'))
|
| 109 |
obj.save_typetree(tree)
|
| 110 |
break
|
|
|
|
| 1 |
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
|
|
|
|
| 44 |
zip_filename = os.path.join(temp_dir, f"{file.filename}_dialogues.zip")
|
| 45 |
|
| 46 |
extracted_count = 0
|
| 47 |
+
log_content = ["=== UNITYPY İŞLEM RAPORU ==="]
|
| 48 |
+
|
| 49 |
with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
| 50 |
for obj in env.objects:
|
| 51 |
if obj.type.name in ["TextAsset", "MonoBehaviour"]:
|
| 52 |
+
log_content.append(f"\nBulundu: {obj.type.name} (ID: {obj.path_id})")
|
| 53 |
try:
|
| 54 |
data = obj.read()
|
| 55 |
file_name = getattr(data, "name", f"{obj.type.name}_{obj.path_id}")
|
|
|
|
| 58 |
content = data.text.encode('utf-8')
|
| 59 |
zipf.writestr(f"{file_name}.txt", content)
|
| 60 |
extracted_count += 1
|
| 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ı. Assembly-CSharp.dll dosyası eksik veya veri şifreli.")
|
| 72 |
except Exception as e:
|
| 73 |
+
log_content.append(f" -> HATA: İşlem sırasında bir sorun oluştu - {str(e)}")
|
| 74 |
+
|
| 75 |
+
if extracted_count == 0:
|
| 76 |
+
log_content.append("\nSONUÇ: Hedef dosya içinde çıkarılabilir hiçbir metin veya geçerli MonoBehaviour bulunamadı.")
|
| 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")
|
| 83 |
|
|
|
|
| 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:
|
|
|
|
| 122 |
data.save()
|
| 123 |
break
|
| 124 |
elif obj.type.name == "MonoBehaviour" and filename == f"{obj_name}.json":
|
|
|
|
| 125 |
tree = json.loads(content.decode('utf-8'))
|
| 126 |
obj.save_typetree(tree)
|
| 127 |
break
|