diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/fingerprints/SplashAnimationBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/fingerprints/SplashAnimationBuilderFingerprint.kt new file mode 100644 index 000000000..8b58a9d50 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/fingerprints/SplashAnimationBuilderFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.youtube.misc.splashanimation.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.util.bytecode.isWide32LiteralExists + +object SplashAnimationBuilderFingerprint : MethodFingerprint( + returnType = "V", + customFingerprint = { it, _ -> it.isWide32LiteralExists(45407550) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/patch/NewSplashAnimationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/patch/NewSplashAnimationPatch.kt new file mode 100644 index 000000000..6af780a4c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/patch/NewSplashAnimationPatch.kt @@ -0,0 +1,64 @@ +package app.revanced.patches.youtube.misc.splashanimation.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.addInstructions +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.utils.settings.resource.patch.SettingsPatch +import app.revanced.patches.youtube.misc.splashanimation.fingerprints.SplashAnimationBuilderFingerprint +import app.revanced.util.bytecode.getWide32LiteralIndex +import app.revanced.util.integrations.Constants.MISC_PATH +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@Name("enable-new-splash-animation") +@Description("Enables a new type of splash animation on Android 12+ devices.") +@DependsOn([SettingsPatch::class]) +@YouTubeCompatibility +@Version("0.0.1") +class NewSplashAnimationPatch : BytecodePatch( + listOf(SplashAnimationBuilderFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + + SplashAnimationBuilderFingerprint.result?.let { + it.mutableMethod.apply { + var targetIndex = getWide32LiteralIndex(45407550) + 3 + if (getInstruction(targetIndex).opcode == Opcode.MOVE_RESULT) + targetIndex += 1 + + val targetRegister = getInstruction(targetIndex).registerA + + addInstructions( + targetIndex, """ + invoke-static {}, $MISC_PATH/SplashAnimationPatch;->enableNewSplashAnimation()Z + move-result v$targetRegister + """ + ) + } + } ?: return SplashAnimationBuilderFingerprint.toErrorResult() + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "SETTINGS: ENABLE_NEW_SPLASH_ANIMATION" + ) + ) + + SettingsPatch.updatePatchStatus("enable-new-splash-animation") + + return PatchResultSuccess() + } +}