mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 05:37:40 +02:00
refactor(YouTube/Layout switch): refine settings
This commit is contained in:
@ -2,19 +2,22 @@ package app.revanced.patches.youtube.general.layoutswitch
|
|||||||
|
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
import app.revanced.patcher.util.smali.ExternalLabel
|
import app.revanced.patches.shared.fingerprints.CreatePlayerRequestBodyWithModelFingerprint
|
||||||
import app.revanced.patches.youtube.general.layoutswitch.fingerprints.GetFormFactorFingerprint
|
import app.revanced.patches.youtube.general.layoutswitch.fingerprints.FormFactorEnumConstructorFingerprint
|
||||||
import app.revanced.patches.youtube.general.layoutswitch.fingerprints.LayoutSwitchFingerprint
|
import app.revanced.patches.youtube.general.layoutswitch.fingerprints.LayoutSwitchFingerprint
|
||||||
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
|
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
|
||||||
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
|
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_PATH
|
||||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||||
|
import app.revanced.util.getReference
|
||||||
|
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||||
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
|
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
|
||||||
import app.revanced.util.patch.BaseBytecodePatch
|
import app.revanced.util.patch.BaseBytecodePatch
|
||||||
import app.revanced.util.resultOrThrow
|
import app.revanced.util.resultOrThrow
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||||
|
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object LayoutSwitchPatch : BaseBytecodePatch(
|
object LayoutSwitchPatch : BaseBytecodePatch(
|
||||||
@ -23,52 +26,51 @@ object LayoutSwitchPatch : BaseBytecodePatch(
|
|||||||
dependencies = setOf(SettingsPatch::class),
|
dependencies = setOf(SettingsPatch::class),
|
||||||
compatiblePackages = COMPATIBLE_PACKAGE,
|
compatiblePackages = COMPATIBLE_PACKAGE,
|
||||||
fingerprints = setOf(
|
fingerprints = setOf(
|
||||||
GetFormFactorFingerprint,
|
CreatePlayerRequestBodyWithModelFingerprint,
|
||||||
|
FormFactorEnumConstructorFingerprint,
|
||||||
LayoutSwitchFingerprint
|
LayoutSwitchFingerprint
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "$GENERAL_PATH/LayoutSwitchPatch;"
|
||||||
|
|
||||||
override fun execute(context: BytecodeContext) {
|
override fun execute(context: BytecodeContext) {
|
||||||
|
|
||||||
// region patch for enable tablet layout
|
val formFactorEnumClass = FormFactorEnumConstructorFingerprint
|
||||||
|
.resultOrThrow()
|
||||||
|
.mutableMethod
|
||||||
|
.definingClass
|
||||||
|
|
||||||
GetFormFactorFingerprint.resultOrThrow().let {
|
CreatePlayerRequestBodyWithModelFingerprint.resultOrThrow().mutableMethod.apply {
|
||||||
it.mutableMethod.apply {
|
val index = indexOfFirstInstructionOrThrow {
|
||||||
val jumpIndex = indexOfFirstInstructionReversedOrThrow(Opcode.SGET_OBJECT)
|
val reference = getReference<FieldReference>()
|
||||||
|
opcode == Opcode.IGET &&
|
||||||
addInstructionsWithLabels(
|
reference?.definingClass == formFactorEnumClass &&
|
||||||
0, """
|
reference.type == "I"
|
||||||
invoke-static { }, $GENERAL_CLASS_DESCRIPTOR->enableTabletLayout()Z
|
|
||||||
move-result v0 # Free register
|
|
||||||
if-nez v0, :is_large_form_factor
|
|
||||||
""",
|
|
||||||
ExternalLabel(
|
|
||||||
"is_large_form_factor",
|
|
||||||
getInstruction(jumpIndex)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
val register = getInstruction<TwoRegisterInstruction>(index).registerA
|
||||||
|
|
||||||
|
addInstructions(
|
||||||
|
index + 1, """
|
||||||
|
invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->getFormFactor(I)I
|
||||||
|
move-result v$register
|
||||||
|
"""
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
|
||||||
|
|
||||||
// region patch for enable phone layout
|
|
||||||
|
|
||||||
LayoutSwitchFingerprint.resultOrThrow().let {
|
LayoutSwitchFingerprint.resultOrThrow().let {
|
||||||
it.mutableMethod.apply {
|
it.mutableMethod.apply {
|
||||||
val insertIndex = indexOfFirstInstructionReversedOrThrow(Opcode.IF_NEZ)
|
val index = indexOfFirstInstructionReversedOrThrow(Opcode.IF_NEZ)
|
||||||
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
|
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||||
|
|
||||||
addInstructions(
|
addInstructions(
|
||||||
insertIndex, """
|
index, """
|
||||||
invoke-static {v$insertRegister}, $GENERAL_CLASS_DESCRIPTOR->enablePhoneLayout(I)I
|
invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->getWidthDp(I)I
|
||||||
move-result v$insertRegister
|
move-result v$register
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add settings
|
* Add settings
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package app.revanced.patches.youtube.general.layoutswitch.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||||
|
|
||||||
|
internal object FormFactorEnumConstructorFingerprint : MethodFingerprint(
|
||||||
|
returnType = "V",
|
||||||
|
strings = listOf(
|
||||||
|
"UNKNOWN_FORM_FACTOR",
|
||||||
|
"SMALL_FORM_FACTOR",
|
||||||
|
"LARGE_FORM_FACTOR"
|
||||||
|
)
|
||||||
|
)
|
@ -1,25 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.general.layoutswitch.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.or
|
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
|
||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
|
|
||||||
internal object GetFormFactorFingerprint : MethodFingerprint(
|
|
||||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
|
|
||||||
returnType = "L",
|
|
||||||
parameters = listOf("Landroid/content/Context;", "Ljava/util/List;"),
|
|
||||||
opcodes = listOf(
|
|
||||||
Opcode.SGET_OBJECT,
|
|
||||||
Opcode.INVOKE_VIRTUAL,
|
|
||||||
Opcode.MOVE_RESULT_OBJECT,
|
|
||||||
Opcode.INVOKE_VIRTUAL,
|
|
||||||
Opcode.MOVE_RESULT,
|
|
||||||
Opcode.IF_EQZ,
|
|
||||||
Opcode.SGET_OBJECT,
|
|
||||||
Opcode.RETURN_OBJECT,
|
|
||||||
Opcode.INVOKE_STATIC,
|
|
||||||
Opcode.MOVE_RESULT_OBJECT,
|
|
||||||
Opcode.RETURN_OBJECT
|
|
||||||
)
|
|
||||||
)
|
|
@ -22,6 +22,20 @@
|
|||||||
<item>MIDDLE</item>
|
<item>MIDDLE</item>
|
||||||
<item>END</item>
|
<item>END</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string-array name="revanced_change_layout_entries">
|
||||||
|
<item>@string/revanced_change_layout_entry_1</item>
|
||||||
|
<item>@string/revanced_change_layout_entry_2</item>
|
||||||
|
<item>@string/revanced_change_layout_entry_3</item>
|
||||||
|
<item>@string/revanced_change_layout_entry_4</item>
|
||||||
|
<item>@string/revanced_change_layout_entry_5</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="revanced_change_layout_entry_values">
|
||||||
|
<item>ORIGINAL</item>
|
||||||
|
<item>SMALL_FORM_FACTOR</item>
|
||||||
|
<item>SMALL_FORM_FACTOR_WIDTH_DP</item>
|
||||||
|
<item>LARGE_FORM_FACTOR</item>
|
||||||
|
<item>LARGE_FORM_FACTOR_WIDTH_DP</item>
|
||||||
|
</string-array>
|
||||||
<string-array name="revanced_change_start_page_entries">
|
<string-array name="revanced_change_start_page_entries">
|
||||||
<item>@string/revanced_change_start_page_entry_default</item>
|
<item>@string/revanced_change_start_page_entry_default</item>
|
||||||
<item>@string/revanced_change_start_page_entry_search</item>
|
<item>@string/revanced_change_start_page_entry_search</item>
|
||||||
|
@ -364,10 +364,12 @@ Limitation: Back button on the toolbar may not work."</string>
|
|||||||
<string name="revanced_remove_viewer_discretion_dialog_summary">"Removes the viewer discretion dialog.
|
<string name="revanced_remove_viewer_discretion_dialog_summary">"Removes the viewer discretion dialog.
|
||||||
This does not bypass the age restriction. It just accepts it automatically."</string>
|
This does not bypass the age restriction. It just accepts it automatically."</string>
|
||||||
|
|
||||||
<string name="revanced_enable_phone_layout_title">Enable phone layout</string>
|
<string name="revanced_change_layout_title">Change layout</string>
|
||||||
<string name="revanced_enable_phone_layout_summary">Spoofs the dpi to use some phone layouts.</string>
|
<string name="revanced_change_layout_entry_1">Original</string>
|
||||||
<string name="revanced_enable_tablet_layout_title">Enable tablet layout</string>
|
<string name="revanced_change_layout_entry_2">Phone</string>
|
||||||
<string name="revanced_enable_tablet_layout_summary">Spoofs the dpi to use some tablet layouts.</string>
|
<string name="revanced_change_layout_entry_3">Phone (Max 480 dip)</string>
|
||||||
|
<string name="revanced_change_layout_entry_4">Tablet</string>
|
||||||
|
<string name="revanced_change_layout_entry_5">Tablet (Min 600 dip)</string>
|
||||||
|
|
||||||
<string name="revanced_spoof_app_version_title">Spoof app version</string>
|
<string name="revanced_spoof_app_version_title">Spoof app version</string>
|
||||||
<string name="revanced_spoof_app_version_summary_on">Version spoofed</string>
|
<string name="revanced_spoof_app_version_summary_on">Version spoofed</string>
|
||||||
|
@ -256,8 +256,7 @@
|
|||||||
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>PREFERENCE_CATEGORY: GENERAL_EXPERIMENTAL_FLAGS -->
|
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>PREFERENCE_CATEGORY: GENERAL_EXPERIMENTAL_FLAGS -->
|
||||||
|
|
||||||
<!-- SETTINGS: LAYOUT_SWITCH
|
<!-- SETTINGS: LAYOUT_SWITCH
|
||||||
<SwitchPreference android:title="@string/revanced_enable_phone_layout_title" android:key="revanced_enable_phone_layout" android:summary="@string/revanced_enable_phone_layout_summary" />
|
<ListPreference android:entries="@array/revanced_change_layout_entries" android:title="@string/revanced_change_layout_title" android:key="revanced_change_layout" android:entryValues="@array/revanced_change_layout_entry_values" />SETTINGS: LAYOUT_SWITCH -->
|
||||||
<SwitchPreference android:title="@string/revanced_enable_tablet_layout_title" android:key="revanced_enable_tablet_layout" android:summary="@string/revanced_enable_tablet_layout_summary" />SETTINGS: LAYOUT_SWITCH -->
|
|
||||||
|
|
||||||
<!-- SETTINGS: SPOOF_APP_VERSION
|
<!-- SETTINGS: SPOOF_APP_VERSION
|
||||||
<SwitchPreference android:title="@string/revanced_spoof_app_version_title" android:key="revanced_spoof_app_version" android:summaryOn="@string/revanced_spoof_app_version_summary_on" android:summaryOff="@string/revanced_spoof_app_version_summary_off" />
|
<SwitchPreference android:title="@string/revanced_spoof_app_version_title" android:key="revanced_spoof_app_version" android:summaryOn="@string/revanced_spoof_app_version_summary_on" android:summaryOff="@string/revanced_spoof_app_version_summary_off" />
|
||||||
|
Reference in New Issue
Block a user