한글패치 관련 짧은 글들
유니티 게임에서 대사 검색 쉽게 하기 (UnityPy 이용)
Snowyegret
2025. 1. 1. 22:31
MonoBehaviour, Text에 대부분의 대사가 들어가 있다는 것을 기반으로 작성한 스크립트입니다.
import UnityPy
import os
def search(root: str, file_name: str, search_string_bytes: bytes):
asset = os.path.join(root, file_name)
try:
env = UnityPy.load(asset)
except Exception as e:
print(f"Error loading asset: {asset}, error: {e}")
return
for obj in env.objects:
if obj.type.name in ["TextAsset", "MonoBehaviour"]:
data = obj.get_raw_data()
if search_string_bytes in data:
print(f"Found! | location: {asset}, pathid: {obj.path_id}, type: {obj.type.name}")
with open("search_result.txt", "a", encoding="utf-8") as f:
f.write(f"location: {asset}, pathid: {obj.path_id}, type: {obj.type.name}\n")
if hasattr(data, "obj"):
if search_string_bytes in data.obj:
print(f"found! | location: {asset}, pathid: {obj.path_id}, type: {obj.type.name}")
with open("search_result.txt", "a", encoding="utf-8") as f:
f.write(f"location: {asset}, pathid: {obj.path_id}, type: {obj.type.name}\n")
def iterate_all_assets(source_folder: str, search_string_bytes: bytes):
for root, dirs, files in os.walk(source_folder):
for file_name in files:
search(root, file_name, search_string_bytes)
if __name__ == "__main__":
current_directory = os.getcwd()
print("Unity asset text searcher")
print("Made by: Snowyegret")
print("Version: 1.1\n")
if not os.path.exists("search_input.txt"):
print("search_input.txt not found")
print("Please create a search_input.txt file with the search string (utf-8)")
input("Press Enter to exit...")
exit(1)
with open("search_input.txt", "r", encoding="utf-8") as f:
search_string = f.read()
search_string_bytes = search_string.encode("utf-8")
with open("search_result.txt", "w", encoding="utf-8") as f:
f.write("Search results:\n")
print("Searching for: ", search_string)
print("Searching start...")
iterate_all_assets(current_directory, search_string_bytes)
input("Press Enter to exit...")
# 빌드 명령어
pyinstaller --onefile --console --add-data "C:\Users\Snowyegret\AppData\Roaming\Python\Python312\site-packages\UnityPy\resources\uncompressed.tpk;UnityPy/resources" searcher.py
원리는 UTF-8로 인코딩한 헥스값을 TextAsset, MonoBehaviour를 순회하며 검색하는 것입니다.
search_input.txt에다가 utf-8로 검색할 텍스트를 입력한 다음 저장하고 프로그램을 실행시키면
cmd창에 출력함과 동시에, search_result.txt에다 결과를 저장해줍니다.
컴파일된 바이너리 다운로드: https://drive.google.com/file/d/1TMluK9jL0FNU4YGLsPsldsgFIJhWo_4a/view?usp=sharing
PW: snow