Last active
September 25, 2022 19:58
-
-
Save FlooferLand/0a108a8823dc2ea3f3d5a852858debdf to your computer and use it in GitHub Desktop.
Python script to change Garry's Mod font size
This file contains 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
########################## | |
# Gmod font size changer # | |
# --- By FlooferLand --- # | |
# /!\ Use at your own caution, | |
# make a backup before running the script! /!\ | |
# PS: It doesn't work for *some* fonts like the spawn menu, feel free to suggest a fix | |
# Variables | |
source_scheme_path = "E:\\Games\\SteamLibrary\\steamapps\\common\\GarrysMod\\garrysmod\\resource\\SourceScheme.res" | |
INCREASE_AMOUNT = 4 # Can be negative | |
# Classes | |
class FontSizeSchemeStrip: | |
tab_count = 0 | |
line_num = 0 | |
data = -1 | |
def __init__(self, data, line_num, tab_count): | |
self.data = data | |
self.line_num = line_num | |
self.tab_count = tab_count | |
def __str__(self): | |
return f"SchemeStrip(tab_count={self.tab_count}, line_num={self.line_num}, data={self.data})" | |
# Functions | |
def load_scheme(lines): | |
result = [] | |
for i in range(len(lines)): | |
line = lines[i] | |
line_stripped = line.strip() | |
if line_stripped.startswith("//") or "\"tall\"" not in line: | |
continue | |
tab_count = (line.count('\t') // 2) + 1 | |
line = line_stripped | |
# Removing quotation marks | |
data = line.split()[1] | |
if data.startswith('\"'): | |
data = data[1:] | |
if data.endswith('\"'): | |
data = data[:-1] | |
strip = FontSizeSchemeStrip(int(data), i, tab_count) | |
result.append(strip) | |
return result | |
def dump_scheme(original, new_scheme): | |
for i in range(len(new_scheme)): | |
strip: FontSizeSchemeStrip = new_scheme[i] | |
original[strip.line_num] = ('\t' * strip.tab_count) + f"\"tall\"\t\t\"{strip.data}\"\n" | |
return original | |
# Main | |
to_write: str | |
with open(source_scheme_path, 'r') as f: | |
split = f.readlines() | |
new_scheme = load_scheme(split) | |
# Increasing the font size | |
for strip in new_scheme: | |
strip.data += INCREASE_AMOUNT | |
to_write = ''.join(dump_scheme(split, new_scheme)) | |
with open(source_scheme_path, 'w') as f: | |
f.write(to_write) | |
print(f"Successfully {('added' if INCREASE_AMOUNT > 0 else 'removed')} {abs(INCREASE_AMOUNT)} to all the font sizes!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment