add hide-shorts-pivot-bar patch (Experimental Flags)

This commit is contained in:
inotia00
2023-03-09 09:35:28 +09:00
parent d22c96fbff
commit 5cff0b32de
7 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object ReelWatchBundleFingerprint : MethodFingerprint(
returnType = "V",
opcodes = listOf(
Opcode.CHECK_CAST,
Opcode.IGET_OBJECT,
Opcode.CONST_STRING,
Opcode.INVOKE_VIRTUAL
),
strings = listOf("r_as")
)

View File

@ -0,0 +1,8 @@
package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object ReelWatchEndpointFingerprint : MethodFingerprint(
returnType = "V",
customFingerprint = { it.name == "<init>" }
)

View File

@ -0,0 +1,8 @@
package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object ReelWatchEndpointParentFingerprint : MethodFingerprint(
returnType = "V",
strings = listOf("Error parsing bytes for updated ReelWatchEndpoint.", "r_aoc")
)

View File

@ -0,0 +1,16 @@
package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object SetPivotBarFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PRIVATE or AccessFlags.FINAL,
parameters = listOf("Z"),
opcodes = listOf(
Opcode.CHECK_CAST,
Opcode.IF_EQZ
)
)

View File

@ -0,0 +1,100 @@
package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.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.data.toMethodWalker
import app.revanced.patcher.extensions.addInstruction
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.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.PivotBarCreateButtonViewFingerprint
import app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints.*
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.GENERAL_LAYOUT
import org.jf.dexlib2.dexbacked.reference.DexBackedTypeReference
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
@Patch
@Name("hide-shorts-pivot-bar")
@Description("Hides the pivotbar when playing shorts.")
@DependsOn([SettingsPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class ShortsPivotBarPatch : BytecodePatch(
listOf(
PivotBarCreateButtonViewFingerprint,
ReelWatchBundleFingerprint,
ReelWatchEndpointParentFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
PivotBarCreateButtonViewFingerprint.result?.let { parentResult ->
SetPivotBarFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
with (it.mutableMethod) {
val startIndex = it.scanResult.patternScanResult!!.startIndex
val instructions = implementation!!.instructions
val indexReference = ((instructions[startIndex] as ReferenceInstruction).reference as DexBackedTypeReference).toString()
if (indexReference != targetReference) return SetPivotBarFingerprint.toErrorResult()
val register = (instructions[startIndex] as OneRegisterInstruction).registerA
addInstruction(
startIndex + 1,
"sput-object v$register, $GENERAL_LAYOUT->pivotbar:$targetReference"
)
}
} ?: return SetPivotBarFingerprint.toErrorResult()
} ?: return PivotBarCreateButtonViewFingerprint.toErrorResult()
ReelWatchBundleFingerprint.result?.let {
with (context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.endIndex, true)
.getMethod() as MutableMethod
) {
addInstruction(
0,
"invoke-static {}, $GENERAL_LAYOUT->hideShortsPlayerPivotBar()V"
)
}
} ?: return ReelWatchBundleFingerprint.toErrorResult()
ReelWatchEndpointParentFingerprint.result?.let { parentResult ->
ReelWatchEndpointFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.addInstruction(
0,
"sput-object p1, $GENERAL_LAYOUT->shortsContext:Landroid/content/Context;"
) ?: return ReelWatchEndpointFingerprint.toErrorResult()
} ?: return ReelWatchEndpointParentFingerprint.toErrorResult()
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: GENERAL_LAYOUT_SETTINGS",
"SETTINGS: SHORTS_COMPONENT.PARENT",
"SETTINGS: SHORTS_COMPONENT_PARENT.B",
"SETTINGS: HIDE_SHORTS_PLAYER_PIVOT_BAR"
)
)
SettingsPatch.updatePatchStatus("hide-shorts-pivot-bar")
return PatchResultSuccess()
}
private companion object {
const val targetReference =
"Lcom/google/android/apps/youtube/app/ui/pivotbar/PivotBar;"
}
}

View File

@ -411,6 +411,9 @@ Is it ready to submit?"</string>
<string name="revanced_hide_shorts_player_join_button_summary_off">Shorts player join button is shown</string>
<string name="revanced_hide_shorts_player_join_button_summary_on">Shorts player join button is hidden</string>
<string name="revanced_hide_shorts_player_join_button_title">Hide shorts player join button</string>
<string name="revanced_hide_shorts_player_pivot_bar_summary_off">Shorts player pivotbar is shown</string>
<string name="revanced_hide_shorts_player_pivot_bar_summary_on">Shorts player pivotbar is hidden</string>
<string name="revanced_hide_shorts_player_pivot_bar_title">Hide shorts player pivotbar</string>
<string name="revanced_hide_shorts_player_subscriptions_button_summary_off">Shorts player subscriptions button is shown</string>
<string name="revanced_hide_shorts_player_subscriptions_button_summary_on">Shorts player subscriptions button is hidden</string>
<string name="revanced_hide_shorts_player_subscriptions_button_title">Hide shorts player subscriptions button</string>

View File

@ -82,6 +82,10 @@
<SwitchPreference android:title="@string/revanced_hide_shorts_player_subscriptions_button_title" android:key="revanced_hide_shorts_player_subscriptions_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_player_subscriptions_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_subscriptions_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_shorts_player_join_button_title" android:key="revanced_hide_shorts_player_join_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_player_join_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_join_button_summary_off" />SETTINGS: HIDE_SHORTS_COMPONENTS -->
<!-- SETTINGS: HIDE_SHORTS_PLAYER_PIVOT_BAR
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_experimental_flag" />
<SwitchPreference android:title="@string/revanced_hide_shorts_player_pivot_bar_title" android:key="revanced_hide_shorts_player_pivot_bar" android:defaultValue="false" android:summaryOn="@string/revanced_hide_shorts_player_pivot_bar_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_pivot_bar_summary_off" />SETTINGS: HIDE_SHORTS_PLAYER_PIVOT_BAR -->
<!-- SETTINGS: SHORTS_COMPONENT.PARENT
</PreferenceScreen>SETTINGS: SHORTS_COMPONENT.PARENT -->
@ -393,6 +397,7 @@
<Preference android:title="hide-shorts-button" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-shorts-component" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-startup-shorts-player" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-shorts-pivot-bar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="enable-wide-searchbar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="enable-tablet-miniplayer" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-auto-captions" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>