Last active
March 4, 2020 21:47
-
-
Save SolidAlloy/810bb17286109029739dac722d9888f2 to your computer and use it in GitHub Desktop.
Change the Unity theme to Dark in one command
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
# 1. Change the path to Unity Editors in the path_to_unity variable below. | |
# 2. Edit the search and replace patterns in case they don't work for your version of Unity. | |
# 3. Run a command like this: python unity_dark_theme.py 2019.3.3f1 | |
# 4. In case something goes wrong, remove Unity.exe and rename Unity_bak.exe to Unity.exe. | |
import binascii | |
import shutil | |
import sys | |
if len(sys.argv) != 2: | |
sys.exit("Provide a Unity version as an argument.") | |
unity_version = sys.argv[1] | |
# Change to the path to Unity Editors you are actually using. | |
path_to_unity = 'c:/Program Files/Unity Editors/{}/Editor'.format(unity_version) | |
# Edit the search and replace patterns in case they change in the future versions of Unity. | |
# You can use this video as a reference https://youtu.be/sF44tnX7JbA | |
search_pattern = binascii.unhexlify(b'751533C0EB1390') | |
replace_pattern = binascii.unhexlify(b'741533C0EB1390') | |
''' | |
Read a binary file in chunks of 1KB to avoid RAM overusage. | |
''' | |
def read_in_chunks(file_object, chunk_size=1024): | |
while True: | |
data = file_object.read(chunk_size) | |
if not data: | |
break | |
yield data | |
# Create a backup of Unity | |
try: | |
shutil.copyfile(path_to_unity+'/Unity.exe', path_to_unity+'/Unity_bak.exe') | |
except IOError: | |
sys.exit("No such path to Unity or this version of Unity is not installed.") | |
pattern_pos = 0 | |
# Find the position of the sequence in the binary file. | |
with open(path_to_unity+'/Unity.exe', 'rb') as file: | |
for piece in read_in_chunks(file): | |
pos = piece.find(b'u\x153\xc0\xeb\x13\x90') | |
if pos == -1: | |
pattern_pos += 1024 | |
else: | |
pattern_pos += pos | |
break | |
# Replace the sequence at a given position | |
with open(path_to_unity+'/Unity.exe', 'r+b') as file: | |
file.seek(pattern_pos) | |
file.write(replace_pattern) | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment