Skip to content

Commit

Permalink
1.10.6 - fix Sprite bones for good
Browse files Browse the repository at this point in the history
fixes #182
  • Loading branch information
K0lb3 committed Oct 22, 2023
1 parent 99c240c commit f311314
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion UnityPy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.10.5"
__version__ = "1.10.6"

from .environment import Environment
from .helpers.ArchiveStorageManager import set_assetbundle_decrypt_key
Expand Down
33 changes: 18 additions & 15 deletions UnityPy/classes/Sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ def __init__(self, reader):

if version >= (2018,): # 2018 and up
m_BonesSize = reader.read_int()
# TODO: might occur in earlier 2020 versions - 2020.3.13 reported
if version >= (
2020,
3,
):
self.m_Bones = [SpriteBone(self.reader) for _ in range(m_BonesSize)]
else:
self.m_Bones = [reader.read_vector2_array() for _ in range(m_BonesSize)]
self.m_Bones = [SpriteBone(self.reader) for _ in range(m_BonesSize)]

def save(self, writer: EndianBinaryWriter = None):
if writer is None:
Expand Down Expand Up @@ -96,12 +89,8 @@ def save(self, writer: EndianBinaryWriter = None):

if version >= (2018,): # 2018 and up
writer.write_int(len(self.m_Bones))
if version >= (2020, 3):
for bone in self.m_Bones:
bone.save(writer)
else:
for bone in self.m_Bones:
writer.write_vector2_array(bone)
for bone in self.m_Bones:
bone.save(writer, version)

self.set_raw_data(writer.bytes)

Expand Down Expand Up @@ -241,14 +230,28 @@ class SpriteBone:

def __init__(self, reader: EndianBinaryReader) -> None:
self.name = reader.read_aligned_string()

if reader.version >= (2021,):
self.guid = reader.read_aligned_string()

self.position = reader.read_vector3()
self.rotation = reader.read_quaternion()
self.length = reader.read_float()
self.parentId = reader.read_int()

def save(self, writer: EndianBinaryWriter):
if reader.version >= (2021,):
self.color = reader.read_color_uint()

def save(self, writer: EndianBinaryWriter, version):
writer.write_aligned_string(self.name)

if version >= (2021,):
writer.write_aligned_string(self.guid)

writer.write_vector3(self.position)
writer.write_quaternion(self.rotation)
writer.write_float(self.length)
writer.write_int(self.parentId)

if version >= (2021,):
writer.write_color_uint(self.color)
8 changes: 8 additions & 0 deletions UnityPy/streams/EndianBinaryReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ def read_rectangle_f(self) -> Rectangle:
self.read_float(), self.read_float(), self.read_float(), self.read_float()
)

def read_color_uint(self):
r = self.read_u_byte()
g = self.read_u_byte()
b = self.read_u_byte()
a = self.read_u_byte()

return Color(r / 255.0, g / 255.0, b / 255.0, a / 255.0)

def read_color4(self) -> Color:
return Color(
self.read_float(), self.read_float(), self.read_float(), self.read_float()
Expand Down
6 changes: 6 additions & 0 deletions UnityPy/streams/EndianBinaryWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def write_rectangle_f(self, value: Rectangle):
self.write_float(value.width)
self.write_float(value.height)

def write_color_uint(self, value: Color):
self.write_u_byte(value.R * 255)
self.write_u_byte(value.G * 255)
self.write_u_byte(value.B * 255)
self.write_u_byte(value.A * 255)

def write_color4(self, value: Color):
self.write_float(value.R)
self.write_float(value.G)
Expand Down

0 comments on commit f311314

Please sign in to comment.