177 lines
6.1 KiB
Python
177 lines
6.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Build 喜相逢五区 complete Chinese locale pack for metin2-client.
|
|
|
|
Takes the verified extracted locale files from:
|
|
/Users/shen/Work/Code/Metin2/喜相逢五区客户端_extracted_locale/merged_locale
|
|
Stages them (supporting both locale/newcibn/ and locale/zh/),
|
|
Packs them with eterpack_pack into Client/pack/locale_zh.eix/.epk,
|
|
Updates Client/pack/Index and Client/locale.cfg.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import shutil
|
|
import subprocess
|
|
import re
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parents[1]
|
|
SRC_MERGED = Path("/Users/shen/Work/Code/Metin2/喜相逢五区客户端_extracted_locale/merged_locale")
|
|
STAGE_DIR = Path("/tmp/metin2_xxf_locale_stage")
|
|
CLIENT_PACK = REPO / "Client/pack"
|
|
LOCALE_CFG = REPO / "Client/locale.cfg"
|
|
INDEX_PATH = CLIENT_PACK / "Index"
|
|
ETERPACK_PACK = REPO / "build/native/src/port/eterpack_pack"
|
|
|
|
EXCLUDE_FILES = {
|
|
"-guildbuildinglist.txt",
|
|
"-locale_game.txt",
|
|
"-locale_interface.txt",
|
|
"locale_game-en.txt",
|
|
"locale_interface-en.txt",
|
|
"shiningtable - 副本.txt",
|
|
}
|
|
|
|
FALLBACK_LOGIN_FAILURES = {
|
|
b'LOGIN_FAILURE_NOTELEBLOCK': '电话密保验证失败'.encode('gbk'),
|
|
b'LOGIN_FAILURE_PASERR1': '密保卡密码错误'.encode('gbk'),
|
|
b'LOGIN_FAILURE_PASERR2': '密保卡坐标错误'.encode('gbk'),
|
|
b'LOGIN_FAILURE_PASERR3': '密保卡验证超时'.encode('gbk'),
|
|
b'LOGIN_FAILURE_PASERR4': '密保卡已锁定'.encode('gbk'),
|
|
b'LOGIN_FAILURE_PASERR5': '密保卡验证失败'.encode('gbk'),
|
|
b'LOGIN_FAILURE_SHUTDOWN_TIME': '服务器维护中'.encode('gbk'),
|
|
b'LOGIN_FAILURE_TIMEOUT': '连接超时'.encode('gbk'),
|
|
b'LOGIN_FAILURE_WRONG_SOCIALID': '身份证号错误'.encode('gbk'),
|
|
}
|
|
|
|
def normalize_locale_text_file(path: Path):
|
|
if not path.is_file():
|
|
return
|
|
raw = path.read_bytes()
|
|
lines = raw.splitlines()
|
|
out = []
|
|
keys_present = set()
|
|
modified = False
|
|
for line in lines:
|
|
s = line.strip(b'\r\n')
|
|
if not s or s.startswith(b'#') or s.startswith(b'-'):
|
|
continue
|
|
if b'\t' in s:
|
|
parts = s.split(b'\t')
|
|
keys_present.add(parts[0])
|
|
if len(parts) >= 3 and not parts[2].strip():
|
|
parts = parts[:2]
|
|
s = b'\t'.join(parts)
|
|
modified = True
|
|
out.append(s + b'\n')
|
|
else:
|
|
m = re.match(rb'^([A-Za-z0-9_]+)[\s\t]*(.*)$', s)
|
|
if m:
|
|
k, v = m.group(1), m.group(2)
|
|
keys_present.add(k)
|
|
out.append(k + b'\t' + v + b'\n')
|
|
modified = True
|
|
else:
|
|
out.append(s + b'\n')
|
|
if path.name == "locale_game.txt":
|
|
for k, v in FALLBACK_LOGIN_FAILURES.items():
|
|
if k not in keys_present:
|
|
out.append(k + b'\t' + v + b'\n')
|
|
modified = True
|
|
if modified:
|
|
path.write_bytes(b''.join(out))
|
|
|
|
def stage_files():
|
|
if STAGE_DIR.exists():
|
|
shutil.rmtree(STAGE_DIR)
|
|
STAGE_DIR.mkdir(parents=True)
|
|
|
|
src_newcibn = SRC_MERGED / "locale/newcibn"
|
|
dst_newcibn = STAGE_DIR / "locale/newcibn"
|
|
dst_zh = STAGE_DIR / "locale/zh"
|
|
dst_common = STAGE_DIR / "locale/common"
|
|
dst_ae = STAGE_DIR / "locale/ae"
|
|
|
|
dst_newcibn.mkdir(parents=True)
|
|
dst_zh.mkdir(parents=True)
|
|
|
|
# 1. Copy locale/newcibn (and mirror to locale/zh)
|
|
file_count = 0
|
|
for root, dirs, files in os.walk(src_newcibn):
|
|
rel = Path(root).relative_to(src_newcibn)
|
|
for d in dirs:
|
|
(dst_newcibn / rel / d).mkdir(parents=True, exist_ok=True)
|
|
(dst_zh / rel / d).mkdir(parents=True, exist_ok=True)
|
|
for f in files:
|
|
if f in EXCLUDE_FILES or f.startswith("._"):
|
|
continue
|
|
src_f = Path(root) / f
|
|
shutil.copy2(src_f, dst_newcibn / rel / f)
|
|
shutil.copy2(src_f, dst_zh / rel / f)
|
|
if f.endswith(".txt"):
|
|
normalize_locale_text_file(dst_newcibn / rel / f)
|
|
normalize_locale_text_file(dst_zh / rel / f)
|
|
file_count += 1
|
|
|
|
print(f"Staged {file_count} files for locale/newcibn and locale/zh.")
|
|
|
|
# 2. Copy locale/common
|
|
src_common = SRC_MERGED / "locale/common"
|
|
if src_common.exists():
|
|
shutil.copytree(src_common, dst_common, dirs_exist_ok=True)
|
|
print(f"Staged locale/common.")
|
|
|
|
# 3. Copy locale/ae
|
|
src_ae = SRC_MERGED / "locale/ae"
|
|
if src_ae.exists():
|
|
shutil.copytree(src_ae, dst_ae, dirs_exist_ok=True)
|
|
print(f"Staged locale/ae.")
|
|
|
|
def pack():
|
|
out_db = str(CLIENT_PACK / "locale_zh")
|
|
cmd = [str(ETERPACK_PACK), out_db, str(STAGE_DIR), ""]
|
|
print(f"Running: {' '.join(cmd)}")
|
|
res = subprocess.run(cmd, capture_output=True, text=True)
|
|
if res.returncode != 0:
|
|
print("eterpack_pack FAILED:", res.stderr)
|
|
sys.exit(1)
|
|
print(res.stdout.strip())
|
|
|
|
# Also keep a copy as locale.eix/locale.epk so * locale will also hit it
|
|
shutil.copy2(CLIENT_PACK / "locale_zh.eix", CLIENT_PACK / "locale.eix")
|
|
shutil.copy2(CLIENT_PACK / "locale_zh.epk", CLIENT_PACK / "locale.epk")
|
|
print(f"Generated {CLIENT_PACK / 'locale_zh.eix'} ({os.path.getsize(CLIENT_PACK / 'locale_zh.epk')} bytes).")
|
|
|
|
def update_index():
|
|
lines = INDEX_PATH.read_text(encoding="latin-1").splitlines()
|
|
# Check if locale_zh is already in index
|
|
if "locale_zh" not in lines:
|
|
new_lines = []
|
|
for line in lines:
|
|
new_lines.append(line)
|
|
if line == "patch_ava2_ui":
|
|
new_lines.extend(["*", "locale_zh"])
|
|
INDEX_PATH.write_text("\n".join(new_lines) + "\n", encoding="latin-1")
|
|
print(f"Added locale_zh to {INDEX_PATH}")
|
|
else:
|
|
print(f"locale_zh already present in {INDEX_PATH}")
|
|
|
|
def update_locale_cfg():
|
|
cfg_content = "10002 936 newcibn\n"
|
|
LOCALE_CFG.write_text(cfg_content)
|
|
print(f"Updated {LOCALE_CFG} -> {cfg_content.strip()}")
|
|
|
|
def main():
|
|
print(f"=== Packaging 喜相逢五区 Chinese Locale ===")
|
|
stage_files()
|
|
pack()
|
|
update_index()
|
|
update_locale_cfg()
|
|
if STAGE_DIR.exists():
|
|
shutil.rmtree(STAGE_DIR)
|
|
print("=== Complete! ===")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|