From 2be2615e616c59d5a5acfe12eb9065cda18fb1df Mon Sep 17 00:00:00 2001 From: doop <56421834+dooplecks@users.noreply.github.com> Date: Mon, 18 May 2026 00:46:45 +0000 Subject: [PATCH] Endian-swap indirect texture matrix in J2D data Fixes copy/delete effects on the file screen. --- include/dusk/endian.h | 22 +++++++++++++++++++ .../include/JSystem/J2DGraph/J2DTevs.h | 2 +- libs/JSystem/src/J2DGraph/J2DTevs.cpp | 6 +++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/dusk/endian.h b/include/dusk/endian.h index 0fec59411f..e73eb8da19 100644 --- a/include/dusk/endian.h +++ b/include/dusk/endian.h @@ -227,6 +227,28 @@ struct BE { } }; +typedef f32 Mtx23[2][3]; +template <> +struct BE { + BE contents[2][3]; + + auto& operator[](int x) { + return contents[x]; + } + + auto& operator[](int x) const { + return contents[x]; + } + + void to_host(Mtx23& mtx) const { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 4; j++) { + mtx[i][j] = contents[i][j]; + } + } + } +}; + template void be_swap(T& val) { val = BE::swap(val); diff --git a/libs/JSystem/include/JSystem/J2DGraph/J2DTevs.h b/libs/JSystem/include/JSystem/J2DGraph/J2DTevs.h index 2d5f3ca2d6..ea81bc869f 100644 --- a/libs/JSystem/include/JSystem/J2DGraph/J2DTevs.h +++ b/libs/JSystem/include/JSystem/J2DGraph/J2DTevs.h @@ -116,7 +116,7 @@ private: * */ struct J2DIndTexMtxInfo { - /* 0x00 */ Mtx23 mMtx; + /* 0x00 */ BE(Mtx23) mMtx; /* 0x18 */ s8 mScaleExp; J2DIndTexMtxInfo& operator=(const J2DIndTexMtxInfo& other) { diff --git a/libs/JSystem/src/J2DGraph/J2DTevs.cpp b/libs/JSystem/src/J2DGraph/J2DTevs.cpp index 8daf82872c..33a65dd273 100644 --- a/libs/JSystem/src/J2DGraph/J2DTevs.cpp +++ b/libs/JSystem/src/J2DGraph/J2DTevs.cpp @@ -68,8 +68,14 @@ void J2DIndTevStage::load(u8 tevStage) { } void J2DIndTexMtx::load(u8 indTexMtx) { +#ifdef TARGET_PC + Mtx23 mtx; + mIndTexMtxInfo.mMtx.to_host(mtx); + GXSetIndTexMtx((GXIndTexMtxID)(GX_ITM_0 + indTexMtx), mtx, mIndTexMtxInfo.mScaleExp); +#else GXSetIndTexMtx((GXIndTexMtxID)(GX_ITM_0 + indTexMtx), mIndTexMtxInfo.mMtx, mIndTexMtxInfo.mScaleExp); +#endif } void J2DIndTexCoordScale::load(u8 indTexStage) {