-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoModder.py
More file actions
executable file
·184 lines (154 loc) · 6.64 KB
/
Copy pathAutoModder.py
File metadata and controls
executable file
·184 lines (154 loc) · 6.64 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
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
import UnityPy, os, subprocess, argparse, shutil, json
with open("binaries.json", "r") as f:
binaries = json.load(f)
zipalign = binaries["zipalign"]
apktool = binaries["apktool"]
apksigner = binaries["apksigner"]
results = {
"enabled": [],
"disabled": [],
"scaled": []
}
def modUnity3d(path, noWalls, noGrav, pvp):
enable = []
disable = []
ignore = []
reenable = []
scale = []
enable_is = []
ends_in = []
disable_is = []
with open("config.json", "r") as f:
config = json.load(f)
if config["enable"]:
enable.extend(config["enable"])
if config["disable"]:
disable.extend(config["disable"])
if config["ignore"]:
ignore.extend(config["ignore"])
if config["reenable"]:
reenable.extend(config["reenable"])
if config["scale"]:
scale.extend(config["scale"])
if config["enable_is"]:
enable_is.extend(config["enable_is"])
if config["ends_in"]:
ends_in.extend(config["ends_in"])
if config["disable_is"]:
disable_is.extend(config["disable_is"])
if noWalls:
disable.append('wall')
disable.append('roof')
if noGrav:
enable.append('grav')
scale.append('grav')
reenable.append('grav')
if pvp:
enable.append('pvp')
scale.append('pvp')
env = UnityPy.load(path)
for obj in env.objects:
if obj.type.name == "GameObject":
data = obj.read()
tree = data.read_typetree()
was = data.m_IsActive
will = "enable" if was else "disable"
color = "\u001B[32m" if was else "\u001B[31m"
changed = False
for key in enable:
if key in data.name.lower():
tree["m_IsActive"] = True
changed = True
will = "enable"
for key in ends_in:
if data.name.lower().endswith(key):
tree["m_IsActive"] = True
changed = True
will = "enable"
for key in disable:
if key in data.name.lower():
tree["m_IsActive"] = False
changed = True
will = "disable"
for key in ignore:
if key in data.name.lower():
tree["m_IsActive"] = was
changed = True
will = "enable" if was else "disable"
for key in reenable:
if key in data.name.lower():
tree["m_IsActive"] = True
changed = True
will = "enable"
for key in enable_is:
if key == data.name.lower():
tree["m_IsActive"] = True
changed = True
will = "enable"
for key in disable_is:
if key == data.name.lower():
tree["m_IsActive"] = False
changed = True
will = "disable"
for key in scale:
if key in data.name.lower():
print(f"\u001B[34mScaling {color}|\u001B[0m GameObject {data.name}")
transform = data.m_Transform.get_obj()
transform_tree = transform.read_typetree()
transform_tree["m_LocalScale"]["x"] *= 100
transform_tree["m_LocalScale"]["y"] *= 100
transform_tree["m_LocalScale"]["z"] *= 100
print(f'\u001B[34mScaled {color}|\u001B[0m {data.name} to {transform_tree["m_LocalScale"]}')
results["scaled"].append(data.name)
transform.save_typetree(transform_tree)
if changed:
if will == "enable" and was == False:
print(f"\u001B[32mEnabled {color}|\u001B[0m GameObject {data.name}")
results["enabled"].append(data.name)
elif will == "disable" and was == True:
print(f"\u001B[31mDisabled {color}|\u001B[0m GameObject {data.name}")
results["disabled"].append(data.name)
else:
print(f"\u001B[33mIgnoring {color}|\u001B[0m GameObject {data.name}")
obj.save_typetree(tree)
with open(path, "wb") as f:
f.write(env.file.save())
def decompile(apk_path):
print(f"\u001B[32mDecompiling {apk_path} into {apk_path[:-4]}\u001B[0m")
sp = subprocess.Popen(f"{apktool} d -f {apk_path} -o {apk_path[:-4]}", shell=True, stdin=subprocess.PIPE)
sp.communicate(input=b'\n')
def recompile(apk_path):
print(f"\u001B[32mRecompiling {apk_path[:-4]} into {apk_path}\u001B[0m")
sp = subprocess.Popen(f"{apktool} b -f --use-aapt2 -d {apk_path[:-4]} -o tmp-{apk_path}", shell=True, stdin=subprocess.PIPE)
sp.communicate(input=b'\n')
print(f"\u001B[32mAligning {apk_path}\u001B[0m")
sp = subprocess.Popen(f"{zipalign} -p 4 tmp-{apk_path} tmp2-{apk_path}", shell=True, stdin=subprocess.PIPE)
sp.communicate(input=b'\n')
print(f"\u001B[32mSigning {apk_path}\u001B[0m")
sp = subprocess.Popen(f"{apksigner} sign --key index.pk8 --cert index.pem --v4-signing-enabled false --out modded-{apk_path} tmp2-{apk_path}", shell=True, stdin=subprocess.PIPE)
sp.communicate(input=b'\n')
def main(apk_path, noWalls, noGrav, pvp):
# if not os.path.exists(apk_path[:-4]):
# os.mkdir(f"{apk_path[:-4]}")
# open(f"tmp-{apk_path}", 'a').close()
# open(f"tmp2-{apk_path}", 'a').close()
# open(f"modded-{apk_path}", 'a').close()
decompile(apk_path)
apk_folder_path = apk_path[:-4]
modUnity3d(f"{apk_folder_path}/assets/bin/Data/data.unity3d", noWalls, noGrav, pvp)
recompile(apk_path)
os.remove(f"tmp-{apk_path}")
os.remove(f"tmp2-{apk_path}")
shutil.rmtree(f"{apk_path[:-4]}")
print("\n\u001B[32mModifications complete\u001B[0m")
print(f"\u001B[32mEnabled:\u001B[0m {results['enabled']}\u001B[0m")
print(f"\u001B[31mDisabled:\u001B[0m {results['disabled']}\u001B[0m")
print(f"\u001B[34mScaled:\u001B[0m {results['scaled']}\u001B[0m")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("apk_path", help="Path to APK file")
parser.add_argument("--noWalls", action="store_true", help="Disable walls")
parser.add_argument("--noGrav", action="store_true", help="Disable gravity")
parser.add_argument("--pvp", action="store_true", help="Enable PvP")
args = parser.parse_args()
main(args.apk_path, args.noWalls, args.noGrav, args.pvp)