forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MonoBehaviour.py
42 lines (35 loc) · 1.48 KB
/
MonoBehaviour.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
from .Behaviour import Behaviour
from .PPtr import PPtr, save_ptr
from ..streams import EndianBinaryReader, EndianBinaryWriter
from ..exceptions import TypeTreeError as TypeTreeError
class MonoBehaviour(Behaviour):
def __init__(self, reader: EndianBinaryReader):
super().__init__(reader=reader)
self.m_Script = PPtr(reader)
self.name = reader.read_aligned_string()
self._raw_offset = reader.Position
if self.assets_file._enable_type_tree:
try:
self.read_typetree()
except TypeTreeError as e:
print("Failed to read TypeTree:\n", e)
self.assets_file._enable_type_tree = False
def save(self, writer: EndianBinaryWriter = None, raw_data: bytes = None):
if writer is None:
writer = EndianBinaryWriter(endian=self.reader.endian)
if not raw_data:
ValueError("No raw data given")
super().save(writer)
save_ptr(self.m_Script, writer)
writer.write_aligned_string(self.name)
writer.write(raw_data)
self.set_raw_data(writer.bytes)
@property
def raw_data(self) -> bytes:
"""
Reads the undocumentated data following the default init.
This is usefull for classes that are stored via MonoBehaviours.
"""
reader = self.reader
reader.Position = self._raw_offset
return reader.read_bytes(reader.byte_size - (self._raw_offset - reader.byte_start))