Skip to content

Instantly share code, notes, and snippets.

@tomekzaw
Last active January 23, 2022 22:11
Show Gist options
  • Save tomekzaw/ac3aa4942587869119dd926da024b6e9 to your computer and use it in GitHub Desktop.
Save tomekzaw/ac3aa4942587869119dd926da024b6e9 to your computer and use it in GitHub Desktop.
# fnt2cfg.py v0.1 ~tomekzaw 2022
# https://gist.github.com/tomekzaw/ac3aa4942587869119dd926da024b6e9
import argparse
from pathlib import Path
def fnt2cfg(d: bytes) -> bytes:
d = bytearray(d)
for i in 2, 105, 113:
d[i:i+4] = d[i:i+4][::-1]
for i in 68, 70, 72, 83, 88, 91, 93, 99:
d[i:i+2] = d[i:i+2][::-1]
for i in range(118, d.find(b'\x00' * 8, 118) - 4, 2):
d[i:i+2] = d[i:i+2][::-1]
return bytes(d)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', required=True)
parser.add_argument('-o', '--output', required=True)
args = parser.parse_args()
if not Path(args.input).exists():
raise SystemExit('Input file not found')
if not Path(args.input).is_file():
raise SystemExit('Input path is not a file')
if Path(args.output).exists():
raise SystemExit('Output file already exists')
with open(Path(args.input), 'rb') as f:
output = fnt2cfg(f.read())
with open(Path(args.output), 'wb') as f:
f.write(output)
print('OK')
@tomekzaw
Copy link
Author

tomekzaw commented Jan 23, 2022

http://www.vsoft.nl/software/utils/win/fontedit/

python3 fnt2cfg.py -i font.FNT -o font.BIN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment