forked from solsticegamestudios/GModCEFCodecFix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenCEFCodecFix.py
262 lines (215 loc) · 12 KB
/
GenCEFCodecFix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/env python3
# GenCEFCodecFix: A manifest generation tool for GModCEFCodecFix
#
# NOTE: 64-bit required due to Memory requirements!
#
# EXAMPLE: python GenCEFCodecFix.py "D:\GModCEFCodecFixDev\Internal" "D:\GModCEFCodecFixDev\External"
#
# Copyright 2020-2024, Solstice Game Studios (www.solsticegamestudios.com)
# LICENSE: GNU General Public License v3.0
from time import process_time
import sys
import os
import http.client
import bsdiff4
from hashlib import sha256
import json
timeStart = process_time()
originalPathRoot = os.path.join(sys.argv[-2], "release_original")
fixedPathRoot = os.path.join(sys.argv[-2], "release_fixed")
patchTargetPathRoot = sys.argv[-1]
manifestDest = os.path.join(patchTargetPathRoot, "manifest.json")
httpServerPathRoot = "https://media.githubusercontent.com/media/solsticegamestudios/GModCEFCodecFix/master"
locales = ["af", "am", "ar", "bg", "bn", "ca", "cs", "da", "de", "el", "en-GB", "en_GB", "en-US", "en_US", "es", "es-419", "es_419", "et", "fa", "fi", "fil", "fr", "gu", "he", "hi", "hr", "hu", "id", "it", "ja", "kn", "ko", "lt", "lv", "ml", "mr", "ms", "nb", "nl", "pl", "pt-BR", "pt_BR", "pt-PT", "pt_PT", "ro", "ru", "sk", "sl", "sr", "sv", "sw", "ta", "te", "th", "tr", "uk", "ur", "vi", "zh-CN", "zh_CN", "zh-TW", "zh_TW"]
filesToDiff = {
"win32": {
#"chromium": [],
"x86-64": [
"bin/chrome_elf.dll",
"bin/d3dcompiler_47.dll",
"bin/gmod.exe",
"bin/html_chromium.dll",
"bin/icudtl.dat",
"bin/libcef.dll",
"bin/libEGL.dll",
"bin/libGLESv2.dll",
"bin/snapshot_blob.bin",
"bin/v8_context_snapshot.bin",
"bin/vk_swiftshader.dll",
"bin/vk_swiftshader_icd.json",
"bin/vulkan-1.dll",
"bin/chromium/cef.pak",
"bin/chromium/cef_100_percent.pak",
"bin/chromium/cef_200_percent.pak",
"bin/chromium/cef_extensions.pak",
"bin/chromium/chrome_100_percent.pak",
"bin/chromium/chrome_200_percent.pak",
"bin/chromium/devtools_resources.pak",
"bin/chromium/resources.pak",
"bin/win64/chrome_elf.dll",
"bin/win64/d3dcompiler_47.dll",
"bin/win64/gmod.exe",
"bin/win64/html_chromium.dll",
"bin/win64/icudtl.dat",
"bin/win64/libcef.dll",
"bin/win64/libEGL.dll",
"bin/win64/libGLESv2.dll",
"bin/win64/snapshot_blob.bin",
"bin/win64/v8_context_snapshot.bin",
"bin/win64/vk_swiftshader.dll",
"bin/win64/vk_swiftshader_icd.json",
"bin/win64/vulkan-1.dll",
"garrysmod/lua/menu/mainmenu.lua"
]
},
"darwin": {
"x86-64": [
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Chromium Embedded Framework",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libEGL.dylib",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libGLESv2.dylib",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libswiftshader_libEGL.dylib",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libswiftshader_libGLESv2.dylib",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libvk_swiftshader.dylib",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/vk_swiftshader_icd.json",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/cef.pak",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/cef_100_percent.pak",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/cef_200_percent.pak",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/chrome_100_percent.pak",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/chrome_200_percent.pak",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/cef_extensions.pak",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/devtools_resources.pak",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/gpu_shader_cache.bin",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/icudtl.dat",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/Info.plist",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/resources.pak",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/snapshot_blob.bin",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/v8_context_snapshot.bin",
"GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/v8_context_snapshot.x86_64.bin",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Alerts).app/Contents/_CodeSignature/CodeResources",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Alerts).app/Contents/Info.plist",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Alerts).app/Contents/PkgInfo",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Alerts).app/Contents/MacOS/gmod Helper (Alerts)",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (GPU).app/Contents/_CodeSignature/CodeResources",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (GPU).app/Contents/Info.plist",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (GPU).app/Contents/PkgInfo",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (GPU).app/Contents/MacOS/gmod Helper (GPU)",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Plugin).app/Contents/_CodeSignature/CodeResources",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Plugin).app/Contents/Info.plist",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Plugin).app/Contents/PkgInfo",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Plugin).app/Contents/MacOS/gmod Helper (Plugin)",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Renderer).app/Contents/_CodeSignature/CodeResources",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Renderer).app/Contents/Info.plist",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Renderer).app/Contents/PkgInfo",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper (Renderer).app/Contents/MacOS/gmod Helper (Renderer)",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper.app/Contents/_CodeSignature/CodeResources",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper.app/Contents/Info.plist",
#"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper.app/Contents/PkgInfo",
"GarrysMod_Signed.app/Contents/Frameworks/gmod Helper.app/Contents/MacOS/gmod Helper",
#"GarrysMod_Signed.app/Contents/MacOS/gmod",
"GarrysMod_Signed.app/Contents/MacOS/html_chromium.dylib",
"garrysmod/html/js/menu/control.Menu.js",
"garrysmod/lua/menu/mainmenu.lua"
]
},
"linux": {
"x86-64": [
"bin/linux32/chromium/cef.pak",
"bin/linux32/chromium/cef_100_percent.pak",
"bin/linux32/chromium/cef_200_percent.pak",
"bin/linux32/chromium/cef_extensions.pak",
"bin/linux32/chromium/chrome_100_percent.pak",
"bin/linux32/chromium/chrome_200_percent.pak",
"bin/linux32/chromium/devtools_resources.pak",
"bin/linux32/chromium/resources.pak",
"bin/linux64/chrome-sandbox",
"bin/linux64/chromium_process",
#"bin/linux64/gmod",
"bin/linux64/html_chromium_client.so",
"bin/linux64/icudtl.dat",
"bin/linux64/libcef.so",
"bin/linux64/libEGL.so",
"bin/linux64/libGLESv2.so",
"bin/linux64/libvk_swiftshader.so",
"bin/linux64/libvulkan.so.1",
"bin/linux64/snapshot_blob.bin",
"bin/linux64/v8_context_snapshot.bin",
"bin/linux64/vk_swiftshader_icd.json",
"garrysmod/lua/menu/mainmenu.lua"
]
}
}
for locale in locales:
filesToDiff["win32"]["x86-64"].append("bin/chromium/locales/" + locale + ".pak")
filesToDiff["linux"]["x86-64"].append("bin/linux32/chromium/locales/" + locale + ".pak")
filesToDiff["darwin"]["x86-64"].append("GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/" + locale.replace("-", "_") + ".lproj/locale.pak")
# macOS has gotta be special
filesToDiff["darwin"]["x86-64"].append("GarrysMod_Signed.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/en.lproj/locale.pak")
print("\nArguments: " + str(sys.argv) + "\n")
print("Original Path: " + originalPathRoot)
print("Patch Path: " + patchTargetPathRoot + "\n")
def getFileSHA256(filePath):
fileSHA256 = sha256()
try:
with open(filePath, "rb") as file:
while True:
fileData = file.read(10485760) # Read about 10MB at a time
if not fileData:
break
fileSHA256.update(fileData)
except FileNotFoundError:
pass
return fileSHA256.hexdigest().upper()
print("Generating BSDIFF patches...")
manifest = {}
fileHashes = {}
filesToSkip = {}
for platform in filesToDiff:
manifest[platform] = platform in manifest and manifest[platform] or {}
fileHashes[platform] = platform in fileHashes and fileHashes[platform] or {}
filesToSkip[platform] = platform in filesToSkip and filesToSkip[platform] or {}
for branch in filesToDiff[platform]:
manifest[platform][branch] = branch in manifest[platform] and manifest[platform][branch] or {}
fileHashes[platform][branch] = branch in fileHashes[platform] and fileHashes[platform][branch] or {}
filesToSkip[platform][branch] = branch in filesToSkip[platform] and filesToSkip[platform][branch] or []
for file in filesToDiff[platform][branch]:
print("\t" + os.path.join(platform, branch, file))
fileHashes[platform][branch][file] = {}
originalFilePath = os.path.join(originalPathRoot, platform, branch, file)
fixedFilePath = os.path.join(fixedPathRoot, platform, "x86-64" if branch == "x86-64-temp" else branch, file) # x86-64-temp is the same as x86-64, but with different original files
patchFilePath = os.path.join(patchTargetPathRoot, platform, branch, file + ".bsdiff")
originalHash = getFileSHA256(originalFilePath)
fixedHash = getFileSHA256(fixedFilePath)
fileHashes[platform][branch][file]["original"] = originalHash
fileHashes[platform][branch][file]["fixed"] = fixedHash
if originalHash != fixedHash:
fileTimeStart = process_time()
os.makedirs(os.path.dirname(patchFilePath), exist_ok=True)
if not os.path.isfile(originalFilePath):
print("\t\tOriginal doesn't exist, setting to NULL")
originalFilePath = "NUL" if sys.platform == "win32" else "/dev/null"
elif not os.path.isfile(fixedFilePath):
print("\t\tFixed doesn't exist, setting to NULL")
fixedFilePath = "NUL" if sys.platform == "win32" else "/dev/null"
# TODO: Multithreading
bsdiff4.file_diff(originalFilePath, fixedFilePath, patchFilePath)
print("\t\tTook " + str(process_time() - fileTimeStart) + " second(s)")
else:
print("\t\tSkipped: Original matches Fixed hash" + (" (Files Not Found!)" if originalHash == "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855" else ""))
filesToSkip[platform][branch].append(file)
print("\nGenerating New Manifest...")
manifestTimeStart = process_time()
for platform in filesToDiff:
for branch in filesToDiff[platform]:
for file in [file for file in filesToDiff[platform][branch] if file not in filesToSkip[platform][branch]]:
originalHash = fileHashes[platform][branch][file]["original"]
fixedHash = fileHashes[platform][branch][file]["fixed"]
manifest[platform][branch][file] = {
"original": originalHash,
"patch": getFileSHA256(os.path.join(patchTargetPathRoot, platform, branch, file + ".bsdiff")),
"patch-url": httpServerPathRoot + "/" + platform + "/" + branch + "/" + file.replace("\\", "/").replace(" ", "%20") + ".bsdiff",
"fixed": fixedHash
}
with open(manifestDest, "w+") as manifestFile:
json.dump(manifest, manifestFile, indent=4)
print("\tTook " + str(process_time() - manifestTimeStart) + " second(s)")
print("\nCEFCodecFix Generation Complete, took " + str(process_time() - timeStart) + " second(s). NOTE: Remember to update GitHub with all of this!")