한글패치 관련 짧은 글들
UnityPy 텍스쳐 삽입 시 "params must be an instance of BC7CompressBlockParams" 오류 해결
Snowyegret
2025. 3. 31. 16:03
* 기준 UnityPy 버전: 1.21.2
import UnityPy
import os
from PIL import Image
file_list = [i for i in os.listdir("StandaloneWindows64") if i.endswith('.bundle')]
png_list = [i.replace(".png", "") for i in os.listdir("Edited_png") if i.endswith('.png')]
with open("log.txt", "w", encoding="utf-8") as log_file:
log_file.write("Texture Import Log\n")
log_file.write("===================\n")
for file in file_list:
modified = False
env = UnityPy.load(os.path.join("StandaloneWindows64", file))
write_list = []
for obj in env.objects:
if obj.type.name == "Texture2D":
data = obj.read()
if data.m_Name in png_list:
try:
fp = os.path.join("Edited_png", f"{data.m_Name}.png")
pil_img = Image.open(fp)
data.image = pil_img
data.save()
modified = True
write_list.append(f"\tReplaced: {data.m_Name}")
except Exception as e:
write_list.append(f"\tERROR: {data.m_Name}: {e}")
print(f"Error replacing {file} | {data.m_Name} | {e}")
modified = True
if modified:
print(f"Modified {file}")
log_file.write(f"{file}\n")
for log in write_list:
log_file.write(log + "\n")
os.makedirs("edited_tex", exist_ok=True)
bdata = env.file.save()
with open(os.path.join("edited_tex", file), "wb") as f:
f.write(bdata)
위와 같은 코드가 있다고 가정해보자.
텍스쳐를 삽입하는 코드이다.
위 코드를 실행하면 다음과 같은 오류가 뜬다.
Error replacing 5f37268644f8047aff6dd63a579fa2fa.bundle | top_middle_menu00_T | params must be an instance of BC7CompressBlockParams
Modified 5f37268644f8047aff6dd63a579fa2fa.bundle
Modified d28cd75e9b51879a49a68c88637bff30.bundle
Modified gameresult_assets_all_da831bdd5b11f432755cb2e81878f503.bundle
Modified gametitle_assets_all_d96baea5dd03ba0473ce9e4248fd9f1e.bundle
Modified gametutorial_assets_all_96c0d6f26353d00ce10178e0fc88c12e.bundle
Error replacing language_assets_all_b2ce6152bacabee1760cb8d2d5e35e3d.bundle | gal_menu_parts_text00_T | params must be an instance of BC7CompressBlockParams
Error replacing language_assets_all_b2ce6152bacabee1760cb8d2d5e35e3d.bundle | piece_menu_info00_T | params must be an instance of BC7CompressBlockParams
Error replacing language_assets_all_b2ce6152bacabee1760cb8d2d5e35e3d.bundle | top_main_menu00_T | params must be an instance of BC7CompressBlockParams
Error replacing language_assets_all_b2ce6152bacabee1760cb8d2d5e35e3d.bundle | top_middle_menu00_T | params must be an instance of BC7CompressBlockParams
Error replacing language_assets_all_b2ce6152bacabee1760cb8d2d5e35e3d.bundle | com_button_info00_T | params must be an instance of BC7CompressBlockParams
Error replacing language_assets_all_b2ce6152bacabee1760cb8d2d5e35e3d.bundle | gal_title00_T | params must be an instance of BC7CompressBlockParams
Modified language_assets_all_b2ce6152bacabee1760cb8d2d5e35e3d.bundle
Error replacing menudata_assets_all_d8b8f2c658c6b0accf510d2b6b754691.bundle | gal_menu_parts_text00_T | params must be an instance of BC7CompressBlockParams
Error replacing menudata_assets_all_d8b8f2c658c6b0accf510d2b6b754691.bundle | piece_menu_info00_T | params must be an instance of BC7CompressBlockParams
Error replacing menudata_assets_all_d8b8f2c658c6b0accf510d2b6b754691.bundle | top_main_menu00_T | params must be an instance of BC7CompressBlockParams
Error replacing menudata_assets_all_d8b8f2c658c6b0accf510d2b6b754691.bundle | top_middle_menu00_T | params must be an instance of BC7CompressBlockParams
Error replacing menudata_assets_all_d8b8f2c658c6b0accf510d2b6b754691.bundle | gal_title00_T | params must be an instance of BC7CompressBlockParams
Modified menudata_assets_all_d8b8f2c658c6b0accf510d2b6b754691.bundle
Modified selectstage_assets_all_387bfd477d58fd82b69feaef26c9778b.bundle
Modified systembase_assets_all_821d344d22d7fabf2ae71f320dd8224b.bundle
"params must be an instance of BC7CompressBlockParams" 오류가 뜬다.
import UnityPy
import os
from PIL import Image
from UnityPy.enums import TextureFormat
file_list = [i for i in os.listdir("StandaloneWindows64") if i.endswith('.bundle')]
png_list = [i.replace(".png", "") for i in os.listdir("Edited_png") if i.endswith('.png')]
with open("log.txt", "w", encoding="utf-8") as log_file:
log_file.write("Texture Import Log\n")
log_file.write("===================\n")
for file in file_list:
modified = False
env = UnityPy.load(os.path.join("StandaloneWindows64", file))
write_list = []
for obj in env.objects:
if obj.type.name == "Texture2D":
data = obj.read()
if data.m_Name in png_list:
try:
fp = os.path.join("Edited_png", f"{data.m_Name}.png")
pil_img = Image.open(fp)
data.set_image(pil_img, target_format=TextureFormat(4), mipmap_count=4)
data.save()
modified = True
write_list.append(f"\tReplaced: {data.m_Name}")
except Exception as e:
write_list.append(f"\tERROR: {data.m_Name}: {e}")
print(f"Error replacing {file} | {data.m_Name} | {e}")
modified = True
if modified:
print(f"Modified {file}")
log_file.write(f"{file}\n")
for log in write_list:
log_file.write(log + "\n")
os.makedirs("edited_tex", exist_ok=True)
bdata = env.file.save()
with open(os.path.join("edited_tex", file), "wb") as f:
f.write(bdata)
그럴땐 data.set_image()를 통해 강제로 텍스쳐포맷을 4 (RGBA32)로 설정해주면 된다.