Files
CosmicScale 19389c4d50 PSBBN v3.00 update
- NEW! Central menu system; auto-setup if dependencies missing
- NEW! Music Installer supports .mp3, .m4a, .flac, and .ogg
- NEW! PSBBN Installer now uses ext2 (replacing ReiserFS), tar archives, and allows custom partition size for Contents; max Music/Contents/POPS partitions increased to 111 GB
- NEW! PSBBN Updater: update to latest patch directly from menu
- Game Installer: HDTV fix for PS1, improved Game ID extraction for VCD/ZSO files
- Extras: optional PS2 Linux install with custom home size; swap Cross/Circle button functions
- HDD-OSD (Browser 2.0): new PSBBN icon by Yornn; improved game icon background color
2025-08-28 15:15:29 +01:00

103 lines
2.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import sys
import os
import unicodedata
# Mapping for unsupported or problematic characters
REPLACEMENTS = {
"'": "",
"-": "",
# Subscript numbers
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
}
def ascii_to_fullwidth(text):
result = []
for c in text:
# Replace mapped characters
if c in REPLACEMENTS:
c = REPLACEMENTS[c]
# Decompose accented characters to base (e.g., é → e)
c = unicodedata.normalize('NFD', c)[0]
code = ord(c)
if 0x21 <= code <= 0x7E:
fullwidth_char = chr(code + 0xFEE0)
elif c == ' ':
fullwidth_char = '\u3000'
else:
fullwidth_char = c
result.append(fullwidth_char)
return ''.join(result)
def sanitize_for_shift_jis(text):
return ''.join(c for c in text if can_encode_shift_jis(c))
def can_encode_shift_jis(char):
try:
char.encode("shift_jis")
return True
except UnicodeEncodeError:
return False
def update_icon_sys(path, title0, title1):
if len(title0) > 16 or len(title1) > 16:
print("[!] Error: Both title0 and title1 must be 16 characters or fewer.")
sys.exit(1)
try:
with open(path, "rb") as f:
data = bytearray(f.read())
title_block_offset = 0xC0
title_block_length = 68
# Convert to full-width, replace unsupported, and sanitize
title0_fw = sanitize_for_shift_jis(ascii_to_fullwidth(title0))
title1_fw = sanitize_for_shift_jis(ascii_to_fullwidth(title1))
title0_encoded = title0_fw.encode("shift_jis")
title1_encoded = title1_fw.encode("shift_jis")
split_offset = len(title0_encoded)
if split_offset > 68:
print("[!] Error: title0 too long after encoding.")
sys.exit(1)
title_combined = title0_encoded + title1_encoded
title_block = title_combined[:title_block_length].ljust(title_block_length, b'\x00')
# Set split offset at byte 0x06
data[0x06] = split_offset
data[title_block_offset:title_block_offset + title_block_length] = title_block
with open("icon.sys", "wb") as f:
f.write(data)
# print(f"[✓] Updated icon.sys with dynamic split offset ({split_offset:#04x}): {path}")
except Exception as e:
print(f"[!] Failed to update icon.sys: {e}")
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python3 txt_to_icon_sys.py path/to/icon.sys title0 title1")
sys.exit(1)
_, icon_path, title0, title1 = sys.argv
if not os.path.isfile(icon_path):
print(f"[!] File not found: {icon_path}")
sys.exit(1)
update_icon_sys(icon_path, title0, title1)