Update app.py
Browse files
app.py
CHANGED
|
@@ -50,8 +50,11 @@ async def extract_dialogues(file: UploadFile = File(...), assembly_file: Optiona
|
|
| 50 |
with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
| 51 |
for obj in env.objects:
|
| 52 |
if obj.type.name in ["TextAsset", "MonoBehaviour"]:
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
if obj.type.name == "MonoBehaviour":
|
| 57 |
raw_data = obj.get_raw_data()
|
|
@@ -98,51 +101,57 @@ async def repack_dialogues(asset_file: UploadFile = File(...), mod_zip: UploadFi
|
|
| 98 |
with open(asset_path, "wb") as f: f.write(await asset_file.read())
|
| 99 |
with open(zip_path, "wb") as f: f.write(await mod_zip.read())
|
| 100 |
|
| 101 |
-
# DİNAMİK PAKETLEME VE IŞIK HIZINDA O(1) ALGORİTMASI
|
| 102 |
env = UnityPy.load(asset_path)
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
|
| 106 |
with zipfile.ZipFile(zip_path, 'r') as zipf:
|
| 107 |
for file_info in zipf.infolist():
|
| 108 |
filename = file_info.filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
if filename.endswith(".json"):
|
| 110 |
-
|
| 111 |
-
match = re.search(r'_(\d+)(_raw)?\.json$', filename)
|
| 112 |
-
if match:
|
| 113 |
-
path_id = int(match.group(1))
|
| 114 |
content = zipf.read(filename)
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
#
|
| 118 |
for obj in env.objects:
|
| 119 |
-
if obj.
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
# Orijinal metnin tam Binary (İkili) haritasını çıkar
|
| 130 |
-
orig_bytes = orig_str.encode('utf-8')
|
| 131 |
-
orig_pad = (4 - (len(orig_bytes) % 4)) % 4
|
| 132 |
-
orig_block = len(orig_bytes).to_bytes(4, 'little') + orig_bytes + (b'\x00' * orig_pad)
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
-
patched_data = patched_data.replace(orig_block, trans_block)
|
| 141 |
-
|
| 142 |
-
# Değişmiş veriyi kaydet (UnityPy burada POINTER REBUILD yapar!)
|
| 143 |
-
obj.set_raw_data(bytes(patched_data))
|
| 144 |
|
| 145 |
-
# 3. Dosyayı Kaydet
|
| 146 |
output_path = os.path.join(temp_dir, f"repacked_{asset_file.filename}")
|
| 147 |
with open(output_path, "wb") as f: f.write(env.file.save())
|
| 148 |
|
|
|
|
| 50 |
with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
| 51 |
for obj in env.objects:
|
| 52 |
if obj.type.name in ["TextAsset", "MonoBehaviour"]:
|
| 53 |
+
|
| 54 |
+
# 1. YENİLİK: ASLA ÇAKIŞMAYAN BENZERSİZ DOSYA İSMİ OLUŞTURUCU
|
| 55 |
+
asset_name = getattr(obj.assets_file, 'name', 'assets')
|
| 56 |
+
asset_name = "".join([c if c.isalnum() else "_" for c in asset_name])
|
| 57 |
+
obj_name = f"{asset_name}_{obj.type.name}_{obj.path_id}"
|
| 58 |
|
| 59 |
if obj.type.name == "MonoBehaviour":
|
| 60 |
raw_data = obj.get_raw_data()
|
|
|
|
| 101 |
with open(asset_path, "wb") as f: f.write(await asset_file.read())
|
| 102 |
with open(zip_path, "wb") as f: f.write(await mod_zip.read())
|
| 103 |
|
|
|
|
| 104 |
env = UnityPy.load(asset_path)
|
| 105 |
|
| 106 |
+
# 2. YENİLİK: ZIP İÇİNDEKİ İSİMLERİ GÜVENLİ ŞEKİLDE EŞLEŞTİRME VE TEMİZLEME
|
| 107 |
+
filename_to_translations = {}
|
| 108 |
with zipfile.ZipFile(zip_path, 'r') as zipf:
|
| 109 |
for file_info in zipf.infolist():
|
| 110 |
filename = file_info.filename
|
| 111 |
+
|
| 112 |
+
# Gizli OS dosyalarını veya metadata dosyalarını (Mac __MACOSX vb.) yoksay
|
| 113 |
+
if "__MACOSX" in filename or filename.split("/")[-1].startswith("._"):
|
| 114 |
+
continue
|
| 115 |
+
|
| 116 |
if filename.endswith(".json"):
|
| 117 |
+
try:
|
|
|
|
|
|
|
|
|
|
| 118 |
content = zipf.read(filename)
|
| 119 |
+
# Sadece isim ve ID'yi ayırarak anahtar oluştur
|
| 120 |
+
filename_to_translations[filename.split("/")[-1]] = json.loads(content.decode('utf-8'))
|
| 121 |
+
except json.JSONDecodeError:
|
| 122 |
+
pass # Bozuk veya formatı kaymış JSON dosyalarını çökmeden atla
|
| 123 |
|
| 124 |
+
# Oyun dosyasını tara ve eşleşen isimleri yama
|
| 125 |
for obj in env.objects:
|
| 126 |
+
if obj.type.name in ["TextAsset", "MonoBehaviour"]:
|
| 127 |
+
asset_name = getattr(obj.assets_file, 'name', 'assets')
|
| 128 |
+
asset_name = "".join([c if c.isalnum() else "_" for c in asset_name])
|
| 129 |
+
obj_name = f"{asset_name}_{obj.type.name}_{obj.path_id}"
|
| 130 |
|
| 131 |
+
target_filename = f"{obj_name}_raw.json"
|
| 132 |
+
|
| 133 |
+
if target_filename in filename_to_translations:
|
| 134 |
+
translations = filename_to_translations[target_filename]
|
| 135 |
|
| 136 |
+
if obj.type.name == "MonoBehaviour":
|
| 137 |
+
raw_data = obj.get_raw_data()
|
| 138 |
+
patched_data = bytearray(raw_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
+
for orig_str, trans_str in translations.items():
|
| 141 |
+
if orig_str == trans_str: continue
|
| 142 |
+
|
| 143 |
+
orig_bytes = orig_str.encode('utf-8')
|
| 144 |
+
orig_pad = (4 - (len(orig_bytes) % 4)) % 4
|
| 145 |
+
orig_block = len(orig_bytes).to_bytes(4, 'little') + orig_bytes + (b'\x00' * orig_pad)
|
| 146 |
+
|
| 147 |
+
trans_bytes = trans_str.encode('utf-8')
|
| 148 |
+
trans_pad = (4 - (len(trans_bytes) % 4)) % 4
|
| 149 |
+
trans_block = len(trans_bytes).to_bytes(4, 'little') + trans_bytes + (b'\x00' * trans_pad)
|
| 150 |
+
|
| 151 |
+
patched_data = patched_data.replace(orig_block, trans_block)
|
| 152 |
|
| 153 |
+
obj.set_raw_data(bytes(patched_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
|
|
|
| 155 |
output_path = os.path.join(temp_dir, f"repacked_{asset_file.filename}")
|
| 156 |
with open(output_path, "wb") as f: f.write(env.file.save())
|
| 157 |
|