-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH3ShaderBitmapToolModifyAndRunLast.py
More file actions
54 lines (42 loc) · 2.47 KB
/
H3ShaderBitmapToolModifyAndRunLast.py
File metadata and controls
54 lines (42 loc) · 2.47 KB
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
import os
import glob
"""
These are 40 character long textures used in the character slots in the default_3 shader used to generate templates
________________________________________
5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F
materials renamed to texture names, 40 char long
40 char long tifs exported to tags/bitmaps
gimp fixes tifs to data/objects/bitmaps/custom
generate blader shaders to testone/shaders 40 chars long
generate bitmaps to tags/objects/bitmaps/custom
run this script
"""
uppersource_str = '5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F' #The name of the bitmap in the shader. 80 characters long.
source_str=uppersource_str.lower()
charlimit = 40
default_directory='F://SteamLibrary//steamapps//common//H3EK//tags//levels//multi//testone//shaders//' #The directory with your blader generated shaders
for i in glob.glob(default_directory + '*.shader', recursive=True): #Goes through all the shader files in this directory
filename=os.path.basename(i).lower() #Gets the file name
basename=os.path.splitext(filename)[0] #Strips the .shader
replace_str=basename.encode('utf-8') #encodes the stripped file name in utf-8
replace_str=replace_str.hex() #converts the file name into hex
with open(i, 'rb') as f:
content = f.read().hex() #Reads the shader
print(source_str in content)
print(len(replace_str))
if source_str in content and len(replace_str) == 2*charlimit:
#Replaces the bitmap with the name of the shader in hex
print('Passes')
content = content.replace(source_str, replace_str)
with open(i, 'wb') as f:
f.write(bytes.fromhex(content)) #Writes the changes to the shader.
if source_str not in content and len(replace_str) == 2*charlimit:
print('Could not find ' + source_str + ' in ' + filename)
if source_str in content and len(replace_str) != 2*charlimit:
print('Your ' + replace_str + ' needs to be ' + str(charlimit) + ' characters long')
if source_str not in content and len(replace_str) != 2*charlimit:
print('Could not find ' + source_str + ' and your ' + replace_str + ' needs to be ' + str(charlimit) + ' characters long')
f.close()
with open(i, 'rb') as f:
new_content = f.read().hex() #Double checks the new file to be sure it was replaced
print(source_str + " in `shader`:", source_str in new_content) #Prints output