diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/language/fingerprints/GeneralPrefsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/language/fingerprints/GeneralPrefsFingerprint.kt new file mode 100644 index 000000000..a30f7060e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/language/fingerprints/GeneralPrefsFingerprint.kt @@ -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;") } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/language/patch/LanguageSelectorPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/language/patch/LanguageSelectorPatch.kt new file mode 100644 index 000000000..0fa7e79ec --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/language/patch/LanguageSelectorPatch.kt @@ -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(targetIndex).registerA + + addInstruction( + targetIndex, + "const/4 v$targetRegister, 0x1" + ) + } + } ?: return GeneralPrefsFingerprint.toErrorResult() + + SettingsPatch.updatePatchStatus("language-switch") + + return PatchResultSuccess() + } +}