import os, re, struct from PIL import Image, ImageDraw, ImageFont GAME = r"F:\steam\steamapps\common\The I of the Dragon" OUT = r"E:\DragonHD\patch" TBL = os.path.join(OUT, "tables") KEY = b"GBDFYTNE" os.makedirs(TBL, exist_ok=True) CODE = 0xC1FA # GB2312 "龙" GLYPH = "龙" GW = GH = 16 AX, AY = 122, 0 # free spot in Shrift_gb_Germany.TGA (256x128) ATLAS = "Shrift_gb_Germany.TGA" ADVANCE = 17 HEIGHT = 16 # ---- 1. render glyph ---- font = ImageFont.truetype(r"C:\Windows\Fonts\simhei.ttf", GH) g = Image.new("RGBA", (GW, GH), (0, 0, 0, 0)) d = ImageDraw.Draw(g) bb = d.textbbox((0, 0), GLYPH, font=font) d.text(((GW-(bb[2]-bb[0]))/2 - bb[0], (GH-(bb[3]-bb[1]))/2 - bb[1]), GLYPH, fill=(255, 255, 255, 255), font=font) gpx = g.load() def tga_geom(raw): w = struct.unpack_from(" uv(%.4f,%.4f,%.4f,%.4f) advance=%d" % (CODE, u1, v1, u2, v2, ADVANCE)) # ---- 3. set test strings ---- strp = os.path.join(GAME, "Data", "Misc", "Strings.dat") enc = open(strp, "rb").read() test = bytes([CODE >> 8, CODE & 0xFF]) ids = ["MainMenu_StartNewGame", "MainMenu_LoadGame", "MainMenu_Options", "MainMenu_Credits", "MainMenu_Exit", "MainMenu_ResumeGame", "MainMenu_SaveLoadGame", "MainMenu_Multi", "WindowCaption"] done = [] for sid in ids: pat = re.compile((r'(Id\s*=\s*"%s"\s*[\r\n]+\s*English\s*=\s*")[^"]*(")' % re.escape(sid)).encode()) enc2 = pat.sub(lambda m: m.group(1) + test + m.group(2), enc, count=1) if enc2 != enc: done.append(sid) enc = enc2 open(strp, "wb").write(enc) print("test strings set:", done)