Created
July 10, 2025 07:46
-
-
Save sonicjhon1/a0fd0edad9f5e00e5d394ad61d65595e to your computer and use it in GitHub Desktop.
Patch for Fontbase, based off of https://gist.github.com/witchymary/1eeb6595740eb81d3a8e55ac15b74d7d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import sys | |
| import os | |
| import re | |
| import argparse | |
| # changelog | |
| # 2022-04-05 Initial | |
| # 2022-04-06 Support AppData/Local installation, make program interactive so it can be run by double-clicking on Windows | |
| # 2022-04-18 Make match independent of variable names | |
| # 2022-05-23 Unlock the advanced options on linux, which are locked by default. | |
| # This is mainly for unlocking dark mode and friends, so other features might not work. | |
| # 2022-05-24 Add option to disable the unlocking | |
| # 2023-12-06 Update to support FontBase 2.20.1 | |
| # 2023-12-14 Update to support FontBase 2.20.7 | |
| # 2025-07-10 Update to support Fontbase 2.22.48 | |
| FILENAME = "app/dist/app.js" | |
| # Essentially replace the function that has `base64").toString("ascii` into a stub that returns `true` | |
| TARGET = re.compile(r',\w+=\w+\(\[iH\],\(\w+\(\w+\)\{(.*?\"base64\"\)\.toString\(\"ascii\"\).*?)}\)\),', re.DOTALL) | |
| REPLACEMENT = r'return true;' | |
| OPTTARGET = ",\"showAwsm\",\"linux\"!==process.platform" | |
| OPTREPLACEMENT = ",\"showAwsm\",true" | |
| WINPATH = "C:/Program Files/FontBase/resources" | |
| WINPATH_LOCAL = f"C:/Users/{os.getlogin()}/AppData/Local/Programs/FontBase/resources" | |
| LINPATH = "/usr/share/fontbase" | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("dir", type=str, nargs="?", help="FontBase install directory") | |
| parser.add_argument("--no-wait", action="store_true", help="Don't wait after finishing") | |
| args = parser.parse_args() | |
| def check_installdir(d): | |
| return os.path.isfile(os.path.join(d, FILENAME)) | |
| def quit(*qargs): | |
| if not args.no_wait: | |
| input("Press Return to continue...") | |
| exit(*qargs) | |
| def mismatch_error(): | |
| print("Couldn't find patching target! Version might be incompatible.") | |
| quit(-1) | |
| def perm_error(): | |
| print("Insufficient permissions - please run with root privileges.") | |
| quit(-1) | |
| fbpath = None | |
| if args.dir != None: | |
| fbpath = args.dir | |
| elif os.name == "nt" and check_installdir(WINPATH): | |
| fbpath = WINPATH | |
| elif os.name == "nt" and check_installdir(WINPATH_LOCAL): | |
| fbpath = WINPATH_LOCAL | |
| elif os.name == "posix" and check_installdir(LINPATH): | |
| fbpath = LINPATH | |
| if fbpath == None: | |
| print("Please specify the path to your FontBase installation's resources folder as an argument, or enter it here! It should contain a folder called \"app\".") | |
| print(f"Example for Windows: {WINPATH}") | |
| print(f"Example for Linux: {LINPATH}") | |
| try: | |
| while True: | |
| dir = input("Enter Path: ") | |
| if check_installdir(dir): | |
| fbpath = dir | |
| break | |
| else: | |
| print("Invalid path - app.js not found.") | |
| except KeyboardInterrupt: | |
| exit() | |
| fname = os.path.join(fbpath, FILENAME) | |
| print(f"FNAME: {fname}") | |
| try: | |
| with open(fname, encoding="utf-8") as f: | |
| content = f.read() | |
| except FileNotFoundError: | |
| mismatch_error() | |
| except PermissionError: | |
| perm_error() | |
| ms = list(TARGET.finditer(content)) | |
| print(f"MS: {ms}") | |
| if not ms: | |
| print("Regex source not found") | |
| mismatch_error() | |
| m = ms[0] | |
| if REPLACEMENT in content: | |
| print("Couldn't find patching target! Application might already have been patched.") | |
| quit() | |
| content = content.replace(m.group(1), REPLACEMENT) | |
| try: | |
| with open(fname, "w", encoding="utf-8") as f: | |
| f.write(content) | |
| except PermissionError: | |
| perm_error() | |
| print("Success! Restart FontBase if necessary.") | |
| quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can u make for new version 2.22.67