diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideFingerprint.kt index 59350da28..e43e1770f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideFingerprint.kt @@ -7,5 +7,17 @@ import org.jf.dexlib2.Opcode object MiniPlayerOverrideFingerprint : MethodFingerprint( "Z", AccessFlags.STATIC or AccessFlags.PUBLIC, - opcodes = listOf(Opcode.RETURN), // anchor to insert the instruction + listOf("L"), + opcodes = listOf( + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT, + Opcode.CONST_4, + Opcode.IF_EQ, + Opcode.CONST_4, + Opcode.IF_EQ, + Opcode.CONST_4, // override this value + Opcode.RETURN, + Opcode.CONST_4, // override this value + Opcode.RETURN + ), ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideParentFingerprint.kt index 14593d31f..a4180746c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideParentFingerprint.kt @@ -1,13 +1,7 @@ package app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints -import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags - object MiniPlayerOverrideParentFingerprint : MethodFingerprint( - returnType = "L", - access = AccessFlags.PUBLIC or AccessFlags.STATIC, - parameters = listOf("L"), - strings = listOf("PLAYBACK_RATE_MENU_BOTTOM_SHEET_FRAGMENT") + strings = listOf("Possible Context wrapper loop - chain of wrappers larger than 10000") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/patch/TabletMiniPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/patch/TabletMiniPlayerPatch.kt index 8769448d1..51ef60315 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/patch/TabletMiniPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/patch/TabletMiniPlayerPatch.kt @@ -10,6 +10,7 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch @@ -20,6 +21,7 @@ import app.revanced.patches.youtube.layout.tabletminiplayer.annotations.TabletMi import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.* import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Patch @@ -68,10 +70,28 @@ class TabletMiniPlayerPatch : BytecodePatch( MiniPlayerOverrideParentFingerprint.result?.let { if (!MiniPlayerOverrideFingerprint.resolve(context, it.classDef)) throw MiniPlayerOverrideFingerprint.toErrorResult() - - MiniPlayerOverrideFingerprint.addProxyCall() } ?: return MiniPlayerOverrideParentFingerprint.toErrorResult() + /* + * Override every return instruction with the proxy call. + */ + MiniPlayerOverrideFingerprint.result!!.mutableMethod.apply { + implementation!!.let { implementation -> + val returnIndices = implementation.instructions + .withIndex() + .filter { (_, instruction) -> instruction.opcode == Opcode.RETURN } + .map { (index, _) -> index } + + if (returnIndices.isEmpty()) throw PatchResultError("No return instructions found.") + + // This method clobbers register p0 to return the value, calculate to override. + val returnedRegister = implementation.registerCount - parameters.size + + // Hook the returned register on every return instruction. + returnIndices.forEach { index -> insertOverride(index, returnedRegister) } + } + } + /* * Size check return value override. */