mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 03:08:29 +02:00
implemented decode_data, encode_data and patch_data
This commit is contained in:
parent
d9ec57a04c
commit
823dc4cc44
1 changed files with 43 additions and 1 deletions
|
@ -1,12 +1,54 @@
|
|||
from source.wt import *
|
||||
|
||||
tools_path = tools_szs_dir / ("wimgt.exe" if system == "win64" else "wimgt")
|
||||
tools_path = tools_szs_dir / ("wbmgt.exe" if system == "win64" else "wbmgt")
|
||||
|
||||
|
||||
_tools_run = get_tools_run_function(tools_path)
|
||||
_tools_run_popen = get_tools_run_popen_function(tools_path)
|
||||
|
||||
|
||||
def decode_data(bmg_data: bytes) -> str:
|
||||
"""
|
||||
Decode a bmg file content into a txt content
|
||||
"""
|
||||
process = _tools_run_popen("DECODE", "-", "--single-line", "--DEST", "-")
|
||||
stdout, _ = process.communicate(input=bmg_data)
|
||||
if process.returncode != 0:
|
||||
raise WTError(tools_path, process.returncode)
|
||||
|
||||
return stdout.decode("utf-8")
|
||||
|
||||
|
||||
def encode_data(txt_data: str) -> bytes:
|
||||
"""
|
||||
Encode a txt file content into a bmg content
|
||||
"""
|
||||
process = _tools_run_popen("ENCODE", "-", "--DEST", "-")
|
||||
stdout, _ = process.communicate(input=txt_data.encode("utf-8"))
|
||||
if process.returncode != 0:
|
||||
raise WTError(tools_path, process.returncode)
|
||||
|
||||
return stdout
|
||||
|
||||
|
||||
def patch_data(bmg_data: bytes, patchs: dict[str, str | None]) -> bytes:
|
||||
"""
|
||||
Patch a file with LE-COPY. This copy the original tracks name into the new lecode track name id
|
||||
:patchs: dictionary of patchs bmg key and value
|
||||
"""
|
||||
args = []
|
||||
for key, value in patchs.items():
|
||||
args.append("--patch-bmg")
|
||||
args.append(key if value is None else f"{key}={value}")
|
||||
|
||||
process = _tools_run_popen("PATCH", "-", *args, "--DEST", "-")
|
||||
stdout, _ = process.communicate(input=bmg_data)
|
||||
if process.returncode != 0:
|
||||
raise WTError(tools_path, process.returncode)
|
||||
|
||||
return stdout
|
||||
|
||||
|
||||
class BMGPath:
|
||||
"""
|
||||
Represent a path to a bmg file (game file containing text data)
|
||||
|
|
Loading…
Reference in a new issue