Skip to content

Commit

Permalink
feat(youtube): hide-floating-microphone-button patch
Browse files Browse the repository at this point in the history
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
oSumAtrIX committed Mar 14, 2023
1 parent 98d0084 commit 8f33b11
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.revanced.patches.youtube.layout.hide.floatingmicrophone.annotations

import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility(
[Package(
"com.google.android.youtube", arrayOf("17.49.37", "18.03.36")
)]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class HideFloatingMicrophoneButtonCompatibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.revanced.patches.youtube.layout.hide.floatingmicrophone.fingerprints

import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.layout.hide.floatingmicrophone.patch.HideFloatingMicrophoneButtonResourcePatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction

object ShowFloatingMicrophoneButtonFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.IGET_BOOLEAN,
Opcode.IF_EQZ,
Opcode.RETURN_VOID
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
(it as? WideLiteralInstruction)?.wideLiteral == HideFloatingMicrophoneButtonResourcePatch.fabButtonId
} == true
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package app.revanced.patches.youtube.layout.hide.floatingmicrophone.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.addInstructions
import app.revanced.patcher.extensions.instruction
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.youtube.layout.hide.floatingmicrophone.annotations.HideFloatingMicrophoneButtonCompatibility
import app.revanced.patches.youtube.layout.hide.floatingmicrophone.fingerprints.ShowFloatingMicrophoneButtonFingerprint
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction

@Patch
@Name("hide-floating-microphone-button")
@Description("Hides the floating microphone button which appears in search.")
@DependsOn([HideFloatingMicrophoneButtonResourcePatch::class])
@HideFloatingMicrophoneButtonCompatibility
@Version("0.0.1")
class HideFloatingMicrophoneButtonPatch : BytecodePatch(
listOf(ShowFloatingMicrophoneButtonFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
ShowFloatingMicrophoneButtonFingerprint.result?.let { result ->
with(result.mutableMethod) {
val insertIndex = result.scanResult.patternScanResult!!.startIndex + 1
val showButtonRegister = (instruction(insertIndex - 1) as TwoRegisterInstruction).registerA

addInstructions(
insertIndex,
"""
invoke-static {v$showButtonRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideFloatingMicrophoneButton(Z)Z
move-result v$showButtonRegister
"""
)
}
} ?: return ShowFloatingMicrophoneButtonFingerprint.toErrorResult()

return PatchResultSuccess()
}

private companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/patches/HideFloatingMicrophoneButtonPatch;"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package app.revanced.patches.youtube.layout.hide.floatingmicrophone.patch

import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
import app.revanced.patches.youtube.layout.hide.floatingmicrophone.annotations.HideFloatingMicrophoneButtonCompatibility
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch

@DependsOn([SettingsPatch::class, ResourceMappingPatch::class])
@HideFloatingMicrophoneButtonCompatibility
@Version("0.0.1")
class HideFloatingMicrophoneButtonResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SwitchPreference(
"revanced_hide_floating_microphone_button",
StringResource(
"revanced_hide_floating_microphone_button_enabled_title",
"Hide floating microphone button"
),
true,
StringResource("revanced_hide_floating_microphone_button_summary_on", "Microphone button hidden"),
StringResource("revanced_hide_floating_microphone_button_summary_off", "Microphone button shown")
)
)

fabButtonId = ResourceMappingPatch.resourceMappings.find { it.type == "id" && it.name == "fab" }?.id
?: return PatchResultError("Can not find required fab button resource id")
return PatchResultSuccess()
}

internal companion object {
var fabButtonId: Long = -1
}
}

0 comments on commit 8f33b11

Please sign in to comment.