Skip to content

Commit

Permalink
autopep8
Browse files Browse the repository at this point in the history
  • Loading branch information
LeontKing2 committed Jan 16, 2025
1 parent e3e52d9 commit bcf9b82
Show file tree
Hide file tree
Showing 46 changed files with 363 additions and 142 deletions.
13 changes: 10 additions & 3 deletions Source/assets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def resolve_asset_id(self, id_str: str | None) -> int | None:

def resolve_asset_version_id(self, id_str: str | None) -> int | None:
# Don't assume this is true for production Rōblox:
# RFD treats 'asset version ids' the same way as just plain 'version ids'.
# RFD treats 'asset version ids' the same way as just plain 'version
# ids'.
return self.resolve_asset_id(id_str)

def resolve_asset_query(self, query: dict[str, str]) -> int | str:
Expand Down Expand Up @@ -117,7 +118,10 @@ def _load_asset_str(self, asset_id: str) -> bytes | None:
return material.load_asset(asset_id)
return None

def _load_redir_asset(self, asset_id: int | str, redirect: structs.asset_redirect) -> returns.base_type:
def _load_redir_asset(
self,
asset_id: int | str,
redirect: structs.asset_redirect) -> returns.base_type:
asset_path = self.get_asset_path(asset_id)

# Checks if it's the first time for a redirect to be called.
Expand Down Expand Up @@ -172,7 +176,10 @@ def _load_asset(self, asset_id: int | str) -> returns.base_type:
elif isinstance(asset_id, int):
return returns.construct(data=self._load_asset_num(asset_id))

def get_asset(self, asset_id: int | str, bypass_blocklist: bool = False) -> returns.base_type:
def get_asset(
self,
asset_id: int | str,
bypass_blocklist: bool = False) -> returns.base_type:
if not bypass_blocklist and self.is_blocklisted(asset_id):
returns.construct(error='Asset is blocklisted.')

Expand Down
6 changes: 4 additions & 2 deletions Source/assets/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ def get(self, key: T, func: Callable[[T], bytes | None]) -> bytes | None:
self.queued_waiters[key] += 1
if self.queued_waiters[key] == 1:
result = func(key)
# If this is the first waiter, puts the result in the queue for this key.
# If this is the first waiter, puts the result in the queue for
# this key.
for _ in range(self.queued_waiters[key] - 1):
self.queued_data[key].put(result)
else:
# If there are already waiters, gets the result from the queue for this key.
# If there are already waiters, gets the result from the queue for
# this key.
result = self.queued_data[key].get(block=True)

self.queued_waiters[key] -= 1
Expand Down
54 changes: 38 additions & 16 deletions Source/assets/serialisers/mesh/rbxmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class FileMeshVertexNormalTexture3d:
def read_data(self, data: bytes):
if len(data) < 40:
raise Exception(
f"FileMeshVertexNormalTexture3d.read_data: data is too short ({len(data)} bytes)")
f"FileMeshVertexNormalTexture3d.read_data: data is too short ({
len(data)} bytes)")

self.vx = struct.unpack("<f", data[0:4])[0]
self.vy = struct.unpack("<f", data[4:8])[0]
Expand Down Expand Up @@ -122,7 +123,8 @@ class FileMeshVertexNormalTexture3dNoRGBA:
def read_data(self, data: bytes):
if len(data) < 36:
raise Exception(
f"FileMeshVertexNormalTexture3dNoRGBA.read_data: data is too short ({len(data)} bytes)")
f"FileMeshVertexNormalTexture3dNoRGBA.read_data: data is too short ({
len(data)} bytes)")

self.vx = struct.unpack("<f", data[0:4])[0]
self.vy = struct.unpack("<f", data[4:8])[0]
Expand Down Expand Up @@ -173,7 +175,8 @@ class FileMeshFace:
def read_data(self, data: bytes):
if len(data) < 12:
raise Exception(
f"FileMeshFace.read_data: data is too short ({len(data)} bytes)")
f"FileMeshFace.read_data: data is too short ({
len(data)} bytes)")

self.a = int.from_bytes(data[0:4], "little")
self.b = int.from_bytes(data[4:8], "little")
Expand Down Expand Up @@ -211,7 +214,8 @@ class FileMeshHeader:
def read_data(self, data: bytes):
if len(data) < 12:
raise Exception(
f"FileMeshHeader.read_data: data is too short ({len(data)} bytes)")
f"FileMeshHeader.read_data: data is too short ({
len(data)} bytes)")

self.cbSize = int.from_bytes(data[0:2], "little")
if self.cbSize != 12:
Expand All @@ -232,7 +236,12 @@ def export_data(self) -> bytes:
)

def __str__(self) -> str:
return f"FileMeshHeader(cbSize={self.cbSize}, cbVerticesStride={self.cbVerticesStride}, cbFaceStride={self.cbFaceStride}, num_vertices={self.num_vertices}, num_faces={self.num_faces})"
return f"FileMeshHeader(cbSize={
self.cbSize}, cbVerticesStride={
self.cbVerticesStride}, cbFaceStride={
self.cbFaceStride}, num_vertices={
self.num_vertices}, num_faces={
self.num_faces})"

def __repr__(self) -> str:
return str(self)
Expand Down Expand Up @@ -266,7 +275,8 @@ class FileMeshHeaderV3:
def read_data(self, data: bytes):
if len(data) < 16:
raise Exception(
f"FileMeshHeaderV3.read_data: data is too short ({len(data)} bytes)")
f"FileMeshHeaderV3.read_data: data is too short ({
len(data)} bytes)")

self.cbSize = int.from_bytes(data[0:2], "little")
if self.cbSize != 16:
Expand Down Expand Up @@ -328,7 +338,8 @@ class FileMeshHeaderV4:
def read_data(self, data: bytes):
if len(data) < 24:
raise Exception(
f"FileMeshHeaderV4.read_data: data is too short ({len(data)} bytes)")
f"FileMeshHeaderV4.read_data: data is too short ({
len(data)} bytes)")

self.sizeof_MeshHeader = int.from_bytes(data[0:2], "little")
if self.sizeof_MeshHeader != 24:
Expand Down Expand Up @@ -381,8 +392,8 @@ def read_data(self, data: bytes):
f"Envelope.read_data: data is too short ({len(data)} bytes)")

for i in range(0, 4):
self.bones.append(int.from_bytes(data[i:i+1], "little"))
self.weights.append(int.from_bytes(data[i+4:i+5], "little"))
self.bones.append(int.from_bytes(data[i:i + 1], "little"))
self.weights.append(int.from_bytes(data[i + 4:i + 5], "little"))

def export_data(self) -> bytes:
return bytearray(
Expand Down Expand Up @@ -511,7 +522,8 @@ def read_data(self, data: bytes):
self.vertsLength = int.from_bytes(data[12:16], "little")
self.numBoneIndicies = int.from_bytes(data[16:20], "little")
for i in range(0, 26):
self.boneIndicies.append(int.from_bytes(data[20+i:21+i], "little"))
self.boneIndicies.append(
int.from_bytes(data[20 + i:21 + i], "little"))

def export_data(self) -> bytes:
subsetData: bytes = bytearray(
Expand Down Expand Up @@ -569,7 +581,8 @@ class FileMeshHeaderV5:
def read_data(self, data: bytes):
if len(data) < 32:
raise Exception(
f"FileMeshHeaderV5.read_data: data is too short ({len(data)} bytes)")
f"FileMeshHeaderV5.read_data: data is too short ({
len(data)} bytes)")

self.sizeof_MeshHeader = int.from_bytes(data[0:2], "little")
if self.sizeof_MeshHeader != 32:
Expand Down Expand Up @@ -628,7 +641,7 @@ def read_data(data: bytes, offset: int, size: int) -> bytes:
if len(data) < offset + size:
raise Exception(
f"read_data: offset is out of bounds (offset={offset}, size={size})")
return data[offset:offset+size]
return data[offset:offset + size]


def get_mesh_version(data: bytes) -> float:
Expand Down Expand Up @@ -663,7 +676,11 @@ def get_mesh_version(data: bytes) -> float:
f"get_mesh_version: unsupported mesh version ({data[0:12]})")


def read_mesh_v1(data_bytes: bytes, offset: int, scale: float = 0.5, invertUV: bool = True) -> FileMeshData:
def read_mesh_v1(
data_bytes: bytes,
offset: int,
scale: float = 0.5,
invertUV: bool = True) -> FileMeshData:
data = data_bytes.decode("ASCII")

meshData: FileMeshData = FileMeshData(
Expand All @@ -672,7 +689,8 @@ def read_mesh_v1(data_bytes: bytes, offset: int, scale: float = 0.5, invertUV: b
debug_print(f"read_mesh_v1: numFaces={numFaces}")

# [0.551563,-0.0944613,0.0862401] we need to find every vector3 in the file
# Each vert has 3 vector3 values so we need to find 3 vector3 values for each vert
# Each vert has 3 vector3 values so we need to find 3 vector3 values for
# each vert
startingIndex = data.find("[")
allVectorStrs: list[str] = data[startingIndex:].split("]")
allVectors: list[list[float]] = []
Expand Down Expand Up @@ -1050,7 +1068,8 @@ def export_mesh_v3(meshData: FileMeshData) -> bytes:
40,
12,
4,
# There has to be at least two LODs ( [0, 1234] ) if not ROBLOX will complain about an empty mesh
# There has to be at least two LODs ( [0, 1234] ) if not ROBLOX will
# complain about an empty mesh
max(len(meshData.LODs), 2),
len(meshData.vnts),
len(meshData.full_faces) if len(meshData.LODs) > 1 and len(
Expand All @@ -1060,7 +1079,10 @@ def export_mesh_v3(meshData: FileMeshData) -> bytes:
for i in range(0, len(meshData.vnts)):
finalmesh += meshData.vnts[i].export_data()

if len(meshData.LODs) > 1 and len(meshData.full_faces) > len(meshData.faces):
if len(
meshData.LODs) > 1 and len(
meshData.full_faces) > len(
meshData.faces):
for i in range(0, len(meshData.full_faces)):
finalmesh += meshData.full_faces[i].export_data()
else:
Expand Down
6 changes: 3 additions & 3 deletions Source/assets/serialisers/rbxl/_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def get_first_chunk_str(info: chunk_info) -> bytes | None:
byteorder='little',
)
str_start = 8
return info.chunk_data[str_start:str_start+str_size]
return info.chunk_data[str_start:str_start + str_size]


def get_prop_values(info: chunk_info) -> bytes | None:
Expand All @@ -185,7 +185,7 @@ def get_prop_values(info: chunk_info) -> bytes | None:
byteorder='little',
)
str_start = 8
return info.chunk_data[str_start+str_size+1:]
return info.chunk_data[str_start + str_size + 1:]


def get_type_id(info: chunk_info) -> int | None:
Expand Down Expand Up @@ -216,7 +216,7 @@ def get_instance_count(info: chunk_info) -> int | None:
)
prop_start = 8 + str_size + 1
return int.from_bytes(
info.chunk_data[prop_start:prop_start+4],
info.chunk_data[prop_start:prop_start + 4],
byteorder='little',
)

Expand Down
8 changes: 5 additions & 3 deletions Source/assets/serialisers/rbxl/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
}


def replace(parser: _logic.rbxl_parser, info: _logic.chunk_info) -> bytes | None:
def replace(parser: _logic.rbxl_parser,
info: _logic.chunk_info) -> bytes | None:
old_prop_name = b'\x08\x00\x00\x00FontFace\x20'
new_prop_name = b'\x04\x00\x00\x00Font\x12'
if not info.chunk_data.startswith(old_prop_name, _logic.INT_SIZE):
Expand All @@ -75,10 +76,11 @@ def replace(parser: _logic.rbxl_parser, info: _logic.chunk_info) -> bytes | None

# Fonts (just like all enums) are stored as an interleaved array of big-endian `uint32`s.
# Why the large string of zeroes? We're taking advantage of the fact that `Enum.Font` never goes above 256.
# Because integers here are big-endian, we put the least significant bytes at the end.
# Because integers here are big-endian, we put the least significant bytes
# at the end.
return b''.join([
class_id,
new_prop_name,
b'\x00'*len(new_values)*3,
b'\x00' * len(new_values) * 3,
*new_values,
])
6 changes: 4 additions & 2 deletions Source/assets/serialisers/rbxl/roblox_links.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from . import _logic


def replace(parser: _logic.rbxl_parser, info: _logic.chunk_info) -> bytes | None:
def replace(parser: _logic.rbxl_parser,
info: _logic.chunk_info) -> bytes | None:
'''
Redirects `assetdelivery.roblox.com` links within any `rbxm` data container to your local URL.
'''
replacer = _logic.string_replacer(
br'https?://(?:assetgame\.|assetdelivery\.|www\.)?roblox\.com/(?:v1/)?asset/?\?id=([\d]{1,17})',
lambda m: b'rbxassetid://%s' % m.group(1),
lambda m: b'rbxassetid://%s' %
m.group(1),
info.chunk_data,
)
return replacer.calc()
3 changes: 2 additions & 1 deletion Source/assets/serialisers/rbxl/script_disabled.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from . import _logic


def replace(parser: _logic.rbxl_parser, info: _logic.chunk_info) -> bytes | None:
def replace(parser: _logic.rbxl_parser,
info: _logic.chunk_info) -> bytes | None:
if _logic.get_first_chunk_str(info) != b'Enabled':
return None

Expand Down
75 changes: 67 additions & 8 deletions Source/assets/serialisers/rbxl/skip_bytecode.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,73 @@
from . import _logic

PRINT_SCRIPT = bytes([
0x02, 0x01, 0x05, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x01, 0x02, 0x00, 0x00, 0x01, 0x06, 0x41, 0x00,
0x00, 0x00, 0x0C, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x40, 0x04, 0x01, 0x37, 0x13, 0x15, 0x00,
0x02, 0x01, 0x16, 0x00, 0x01, 0x00, 0x02, 0x03, 0x01, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x01,
0x00, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
])
PRINT_SCRIPT = bytes([0x02,
0x01,
0x05,
0x70,
0x72,
0x69,
0x6E,
0x74,
0x01,
0x02,
0x00,
0x00,
0x01,
0x06,
0x41,
0x00,
0x00,
0x00,
0x0C,
0x00,
0x01,
0x00,
0x00,
0x00,
0x00,
0x40,
0x04,
0x01,
0x37,
0x13,
0x15,
0x00,
0x02,
0x01,
0x16,
0x00,
0x01,
0x00,
0x02,
0x03,
0x01,
0x04,
0x00,
0x00,
0x00,
0x40,
0x00,
0x01,
0x00,
0x01,
0x18,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x01,
0x00,
0x00,
0x00,
0x00,
0x00,
])


def replace(parser: _logic.rbxl_parser, info: _logic.chunk_info) -> bytes | None:
def replace(parser: _logic.rbxl_parser,
info: _logic.chunk_info) -> bytes | None:
'''
TODO: this function serves the dual purpose of removing any dangerous instances of bytecode in RBXL files whilst also patching `DataModelPatch.rbxm` with a simple routine.
'''
Expand All @@ -21,7 +80,7 @@ def replace(parser: _logic.rbxl_parser, info: _logic.chunk_info) -> bytes | None
head = b''
sources = []
while True:
head = info.chunk_data[base:base+4]
head = info.chunk_data[base:base + 4]
l = int.from_bytes(head, 'little')
if head == b'PROP' or l == 0:
break
Expand Down
Loading

0 comments on commit bcf9b82

Please sign in to comment.