refactor(protobuf-spoof): integrated into settings

This commit is contained in:
inotia00
2023-03-15 11:44:29 +09:00
parent edc11306da
commit 1874741076
3 changed files with 27 additions and 17 deletions

View File

@ -7,19 +7,21 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
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.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.ProtobufParameterBuilderFingerprint
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.MISC_PATH
@Patch
@Name("protobuf-spoof")
@Description("Spoofs the protobuf to prevent playback issues.")
@DependsOn([SettingsPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class ProtobufSpoofPatch : BytecodePatch(
@ -33,30 +35,28 @@ class ProtobufSpoofPatch : BytecodePatch(
.nextMethod(it.scanResult.patternScanResult!!.startIndex, true)
.getMethod() as MutableMethod
) {
// Issue with sound always playing when spoofing protobuf in feed
// https://github.com/inotia00/ReVanced_Extended/issues/471
// To fix this issue, protobuf spoof should only be done at video player
// The length of protobuf in video player is between 12 and 14
// The length of protobuf in the feed is between 16 and 18
// Therefore, protobuf spoof should only be done when protobuf length is less than 16
val protobufParam = 3
val protobufParameter = "CgIQBg%3D%3D" /* Protobuf Parameter of X-Goog-Visitor-Id */
addInstructions(
0,
"""
invoke-virtual { p$protobufParam }, Ljava/lang/String;->length()I
move-result v0
const/16 v1, 0x10
if-ge v0, v1, :not_spoof
const-string p$protobufParam, "$protobufParameter"
""",
listOf(ExternalLabel("not_spoof", instruction(0)))
invoke-static {p$protobufParam}, $MISC_PATH/ProtobufSpoofPatch;->getProtobufOverride(Ljava/lang/String;)Ljava/lang/String;
move-result-object p$protobufParam
"""
)
}
} ?: return ProtobufParameterBuilderFingerprint.toErrorResult()
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"SETTINGS: ENABLE_PROTOBUF_SPOOF"
)
)
SettingsPatch.updatePatchStatus("protobuf-spoof")
return PatchResultSuccess()
}
}

View File

@ -208,6 +208,8 @@ Is it ready to submit?"</string>
<string name="revanced_enable_open_links_directly_title">Enable open links directly</string>
<string name="revanced_enable_phone_layout_summary">Tricks the dpi to use some phone layouts</string>
<string name="revanced_enable_phone_layout_title">Enable phone layout</string>
<string name="revanced_enable_protobuf_spoof_summary">Spoofs the protobuf to prevent playback issues</string>
<string name="revanced_enable_protobuf_spoof_title">Enable protobuf spoof</string>
<string name="revanced_enable_press_to_swipe_summary_off">Press-to-swipe is disabled</string>
<string name="revanced_enable_press_to_swipe_summary_on">Press-to-swipe is enabled</string>
<string name="revanced_enable_press_to_swipe_title">Enable press-to-swipe gesture</string>
@ -515,6 +517,9 @@ Since these setting is quite outdated, it may not be valid"</string>
<string name="revanced_save_video_quality_wifi">Changing default Wi-Fi quality to:</string>
<string name="revanced_save_video_speed">Changing default speed to:</string>
<string name="revanced_seekbar_layout">Seekbar layout</string>
<string name="revanced_spoofing_type_general">Spoof to general video</string>
<string name="revanced_spoofing_type_shorts">Spoof to shorts video</string>
<string name="revanced_spoofing_type_title">Select protobuf to spoof</string>
<string name="revanced_sponsorblock_settings_summary">SponsorBlock related settings</string>
<string name="revanced_swipe_controls">Swipe controls</string>
<string name="revanced_swipe_magnitude_threshold_summary">The amount of threshold for swipe to occur</string>

View File

@ -373,6 +373,10 @@
<!-- SETTINGS: DOUBLE_BACK_TIMEOUT
<ListPreference android:title="@string/revanced_double_back_timeout_title" android:summary="@string/revanced_double_back_timeout_summary" android:key="revanced_double_back_timeout" android:defaultValue="2" />SETTINGS: DOUBLE_BACK_TIMEOUT -->
<!-- SETTINGS: ENABLE_PROTOBUF_SPOOF
<SwitchPreference android:title="@string/revanced_enable_protobuf_spoof_title" android:key="revanced_enable_protobuf_spoof" android:defaultValue="false" android:summary="@string/revanced_enable_protobuf_spoof_summary" />
<SwitchPreference android:title="@string/revanced_spoofing_type_title" android:key="revanced_spoofing_type" android:defaultValue="false" android:summaryOn="@string/revanced_spoofing_type_shorts" android:summaryOff="@string/revanced_spoofing_type_general" android:dependency="revanced_enable_protobuf_spoof" />SETTINGS: ENABLE_PROTOBUF_SPOOF -->
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_experimental_flag" />
<!-- SETTINGS: ENABLE_OLD_LAYOUT
<SwitchPreference android:title="@string/revanced_enable_old_layout_title" android:key="revanced_enable_old_layout" android:defaultValue="false" android:summaryOn="@string/revanced_enable_old_layout_summary_on" android:summaryOff="@string/revanced_enable_old_layout_summary_off" />SETTINGS: ENABLE_OLD_LAYOUT -->
@ -469,6 +473,7 @@
<Preference android:title="enable-external-browser" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="enable-open-links-directly" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="enable-minimized-playback" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="protobuf-spoof" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="enable-old-layout" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="layout-switch" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="force-vp9-codec" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>