forked from mirror/Archipelago
Some checks failed
Analyze modified files / flake8 (push) Failing after 2m28s
Build / build-win (push) Has been cancelled
Build / build-ubuntu2204 (push) Has been cancelled
ctest / Test C++ ubuntu-latest (push) Has been cancelled
ctest / Test C++ windows-latest (push) Has been cancelled
Analyze modified files / mypy (push) Has been cancelled
Build and Publish Docker Images / Push Docker image to Docker Hub (push) Successful in 5m4s
Native Code Static Analysis / scan-build (push) Failing after 5m2s
type check / pyright (push) Successful in 1m7s
unittests / Test Python 3.11.2 ubuntu-latest (push) Failing after 16m23s
unittests / Test Python 3.12 ubuntu-latest (push) Failing after 28m19s
unittests / Test Python 3.13 ubuntu-latest (push) Failing after 14m49s
unittests / Test hosting with 3.13 on ubuntu-latest (push) Successful in 5m0s
unittests / Test Python 3.13 macos-latest (push) Has been cancelled
unittests / Test Python 3.11 windows-latest (push) Has been cancelled
unittests / Test Python 3.13 windows-latest (push) Has been cancelled
54 lines
2.3 KiB
Python
54 lines
2.3 KiB
Python
"""Changes for Mirror Mode."""
|
|
|
|
import js
|
|
from randomizer.Patching.Patcher import LocalROM
|
|
from randomizer.Settings import Settings
|
|
from randomizer.Patching.Library.Assets import TableNames, getRawFile, writeRawFile
|
|
|
|
|
|
def FlipDisplayList(ROM_COPY: LocalROM, data: bytearray, start: int, end: int, table: int, file: int):
|
|
"""Flip the 2nd and 3rd vertices on any G_TRI, G_TRI2 or G_QUAD f3dex2 call."""
|
|
instruction_count = int((end - start) / 8)
|
|
for ins in range(instruction_count):
|
|
ins_start = start + (8 * ins)
|
|
ins_type = data[ins_start]
|
|
if ins_type in (5, 6, 7):
|
|
for offset in (2, 6):
|
|
v1 = data[ins_start + offset]
|
|
v2 = data[ins_start + offset + 1]
|
|
data[ins_start + offset] = v2
|
|
data[ins_start + offset + 1] = v1
|
|
writeRawFile(table, file, True, data, ROM_COPY)
|
|
|
|
|
|
def readDataFromBytestream(data: bytearray, offset: int, size: int) -> int:
|
|
"""Read data from a byte stream and output an int."""
|
|
value = 0
|
|
for x in range(size):
|
|
value <<= 8
|
|
value += data[offset + x]
|
|
return value
|
|
|
|
|
|
def ApplyMirrorMode(settings: Settings, ROM_COPY: LocalROM):
|
|
"""Apply all Mirror Mode changes."""
|
|
if not settings.mirror_mode:
|
|
return
|
|
for tbl in (TableNames.ActorGeometry, TableNames.ModelTwoGeometry, TableNames.MapGeometry):
|
|
file_count = len(js.pointer_addresses[tbl]["entries"])
|
|
for file_index in range(file_count):
|
|
data = bytearray(getRawFile(ROM_COPY, tbl, file_index, True))
|
|
if len(data) == 0:
|
|
continue
|
|
if tbl == TableNames.MapGeometry:
|
|
dl_start = readDataFromBytestream(data, 0x34, 4)
|
|
dl_end = readDataFromBytestream(data, 0x38, 4)
|
|
elif tbl == TableNames.ActorGeometry:
|
|
addr_offset = readDataFromBytestream(data, 0, 4)
|
|
dl_end = 0x28 + (readDataFromBytestream(data, 4, 4) - addr_offset)
|
|
dl_start = 0x28 + (readDataFromBytestream(data, dl_end, 4) - addr_offset)
|
|
elif tbl == TableNames.ModelTwoGeometry:
|
|
dl_start = readDataFromBytestream(data, 0x40, 4)
|
|
dl_end = readDataFromBytestream(data, 0x48, 4)
|
|
FlipDisplayList(ROM_COPY, data, dl_start, dl_end, tbl, file_index)
|