feat(youtube): add language-switch patch

This commit is contained in:
inotia00 2023-06-20 17:26:49 +09:00
parent 1abaaf345b
commit 424ebe6491
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package app.revanced.patches.youtube.misc.language.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object GeneralPrefsFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf(),
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.IF_NEZ,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT
),
strings = listOf("bedtime_reminder_toggle"),
customFingerprint = { it, _ -> it.definingClass.endsWith("GeneralPrefsFragment;") }
)

View File

@ -0,0 +1,47 @@
package app.revanced.patches.youtube.misc.language.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.language.fingerprints.GeneralPrefsFingerprint
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Patch
@Name("language-switch")
@Description("Add language switch toggle.")
@DependsOn([SettingsPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class LanguageSelectorPatch : BytecodePatch(
listOf(GeneralPrefsFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
GeneralPrefsFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex + 2
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
targetIndex,
"const/4 v$targetRegister, 0x1"
)
}
} ?: return GeneralPrefsFingerprint.toErrorResult()
SettingsPatch.updatePatchStatus("language-switch")
return PatchResultSuccess()
}
}