generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hide-create-button): increase patching compatibility across versions
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
Showing
6 changed files
with
99 additions
and
82 deletions.
There are no files selected for viewing
79 changes: 0 additions & 79 deletions
79
...kotlin/app/revanced/patches/youtube/layout/createbutton/patch/CreateButtonRemoverPatch.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../annotations/CreateButtonCompatibility.kt → .../annotations/CreateButtonCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../youtube/layout/pivotbar/createbutton/fingerprints/PivotBarCreateButtonViewFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package app.revanced.patches.youtube.layout.pivotbar.createbutton.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.pivotbar.createbutton.annotations.CreateButtonCompatibility | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("pivot-bar-create-button-view-fingerprint") | ||
@MatchingMethod( | ||
"Lknw", "z" | ||
) | ||
@CreateButtonCompatibility | ||
@Version("0.0.1") | ||
object PivotBarCreateButtonViewFingerprint : MethodFingerprint( | ||
opcodes = listOf( | ||
Opcode.INVOKE_DIRECT_RANGE, // unique instruction anchor | ||
Opcode.CONST_4, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.INVOKE_STATIC | ||
) | ||
) |
72 changes: 72 additions & 0 deletions
72
...p/revanced/patches/youtube/layout/pivotbar/createbutton/patch/CreateButtonRemoverPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package app.revanced.patches.youtube.layout.pivotbar.createbutton.patch | ||
|
||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.impl.BytecodeData | ||
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name | ||
import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultError | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patcher.patch.impl.BytecodePatch | ||
import app.revanced.patches.youtube.layout.pivotbar.InjectionUtils.REGISTER_TEMPLATE_REPLACEMENT | ||
import app.revanced.patches.youtube.layout.pivotbar.InjectionUtils.injectHook | ||
import app.revanced.patches.youtube.layout.pivotbar.createbutton.annotations.CreateButtonCompatibility | ||
import app.revanced.patches.youtube.layout.pivotbar.createbutton.fingerprints.PivotBarCreateButtonViewFingerprint | ||
import app.revanced.patches.youtube.layout.pivotbar.fingerprints.PivotBarFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference | ||
|
||
@Patch | ||
@DependsOn([IntegrationsPatch::class, ResourceIdMappingProviderResourcePatch::class, SettingsPatch::class]) | ||
@Name("hide-create-button") | ||
@Description("Hides the create button in the navigation bar.") | ||
@CreateButtonCompatibility | ||
@Version("0.0.1") | ||
class CreateButtonRemoverPatch : BytecodePatch( | ||
listOf( | ||
PivotBarFingerprint | ||
) | ||
) { | ||
override fun execute(data: BytecodeData): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
SwitchPreference( | ||
"revanced_create_button_enabled", | ||
StringResource("revanced_create_button_enabled_title", "Show create button"), | ||
false, | ||
StringResource("revanced_create_button_summary_on", "Create button is shown"), | ||
StringResource("revanced_create_button_summary_off", "Create button is hidden") | ||
) | ||
) | ||
|
||
/* | ||
* Resolve fingerprints | ||
*/ | ||
|
||
val pivotBarResult = PivotBarFingerprint.result ?: return PatchResultError("PivotBarFingerprint failed") | ||
|
||
if (!PivotBarCreateButtonViewFingerprint.resolve(data, pivotBarResult.method, pivotBarResult.classDef)) | ||
return PatchResultError("${PivotBarCreateButtonViewFingerprint.name} failed") | ||
|
||
val createButtonResult = PivotBarCreateButtonViewFingerprint.result!! | ||
val insertIndex = createButtonResult.patternScanResult!!.endIndex | ||
|
||
/* | ||
* Inject hooks | ||
*/ | ||
|
||
val integrationsClass = "Lapp/revanced/integrations/patches/HideCreateButtonPatch;" | ||
val hook = | ||
"invoke-static { v$REGISTER_TEMPLATE_REPLACEMENT }, $integrationsClass->hideCreateButton(Landroid/view/View;)V" | ||
|
||
createButtonResult.mutableMethod.injectHook(hook, insertIndex) | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |