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()
}
}