forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.py
More file actions
65 lines (50 loc) · 1.77 KB
/
Copy pathtest_main.py
File metadata and controls
65 lines (50 loc) · 1.77 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
import os
import UnityPy
from PIL import Image
SAMPLES = os.path.join(os.path.dirname(os.path.abspath(__file__)), "samples")
def test_read_single():
for f in os.listdir(SAMPLES):
env = UnityPy.load(os.path.join(SAMPLES, f))
for obj in env.objects:
obj.read()
def test_read_batch():
env = UnityPy.load(SAMPLES)
for obj in env.objects:
obj.read()
def test_texture2d():
for f in os.listdir(SAMPLES):
env = UnityPy.load(os.path.join(SAMPLES, f))
for obj in env.objects:
if obj.type == "Texture2D":
data = obj.read()
data.image.save("test.png")
data.image = data.image.transpose(Image.ROTATE_90)
data.save()
def test_sprite():
for f in os.listdir(SAMPLES):
env = UnityPy.load(os.path.join(SAMPLES, f))
for obj in env.objects:
if obj.type == "Sprite":
obj.read().image.save("test.png")
def test_audioclip():
env = UnityPy.load(os.path.join(SAMPLES, "char_118_yuki.ab"))
for obj in env.objects:
if obj.type == "AudioClip":
clip = obj.read()
assert len(clip.samples) == 1
def test_mesh():
env = UnityPy.load(os.path.join(SAMPLES, "xinzexi_2_n_tex"))
with open(os.path.join(SAMPLES, 'xinzexi_2_n_tex_mesh'), 'rb') as f:
wanted = f.read().replace(b'\r', b'')
for obj in env.objects:
if obj.type == "Mesh":
mesh = obj.read()
data = mesh.export()
if isinstance(data, str):
data = data.encode('utf8').replace(b'\r', b'')
assert data == wanted
if __name__ == "__main__":
for x in list(locals()):
if str(x)[:4] == "test":
locals()[x]()
input("All Tests Passed")