add enable-old-seekbar-color patch

This commit is contained in:
inotia00 2022-12-27 14:51:49 +09:00
parent ffd7c99025
commit 634c61dc7f
4 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,63 @@
package app.revanced.patches.youtube.layout.seekbar.oldseekbarcolor.bytecode.patch
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
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.shared.annotation.YouTubeCompatibility
import app.revanced.shared.extensions.findMutableMethodOf
import app.revanced.shared.patches.mapping.ResourceMappingPatch
import app.revanced.shared.util.integrations.Constants.SEEKBAR_LAYOUT
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
@DependsOn([ResourceMappingPatch::class])
@Name("old-seekbar-color-bytecode-patch")
@YouTubeCompatibility
@Version("0.0.1")
class OldSeekbarColorBytecodePatch : BytecodePatch() {
// list of resource names to get the id of
private val resourceIds = arrayOf(
"inline_time_bar_colorized_bar_played_color_dark"
).map { name ->
ResourceMappingPatch.resourceMappings.single { it.name == name }.id
}
override fun execute(context: BytecodeContext): PatchResult {
context.classes.forEach { classDef ->
classDef.methods.forEach { method ->
with(method.implementation) {
this?.instructions?.forEachIndexed { index, instruction ->
when (instruction.opcode) {
Opcode.CONST -> {
when ((instruction as Instruction31i).wideLiteral) {
resourceIds[0] -> { // seekbar color
val insertIndex = index + 1
val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method)
val viewRegister = (instructions.elementAt(index) as Instruction31i).registerA
mutableMethod.addInstructions(
insertIndex, """
invoke-static {v$viewRegister}, $SEEKBAR_LAYOUT->enableOldSeekbarColor(I)I
move-result v$viewRegister
"""
)
}
}
}
else -> return@forEachIndexed
}
}
}
}
}
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,49 @@
package app.revanced.patches.youtube.layout.seekbar.oldseekbarcolor.resource.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patches.youtube.layout.seekbar.oldseekbarcolor.bytecode.patch.OldSeekbarColorBytecodePatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.util.resources.ResourceHelper
@Patch
@Name("enable-old-seekbar-color")
@Description("Enable old seekbar color in dark mode.")
@DependsOn(
[
OldSeekbarColorBytecodePatch::class,
SettingsPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class OldSeekbarColorPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
/*
add settings
*/
ResourceHelper.addSettings2(
context,
"PREFERENCE_CATEGORY: REVANCED_SETTINGS",
"PREFERENCE: LAYOUT_SETTINGS",
"PREFERENCE_HEADER: SEEKBAR",
"SETTINGS: ENABLE_OLD_SEEKBAR_COLOR"
)
ResourceHelper.patchSuccess(
context,
"enable-old-seekbar-color"
)
return PatchResultSuccess()
}
}

View File

@ -212,6 +212,9 @@ Is it ready to submit?"</string>
<string name="revanced_enable_old_layout_summary_off">YouTube Layout will follow your Google Account status</string>
<string name="revanced_enable_old_layout_summary_on">Trick the YouTube version to force enable old layout</string>
<string name="revanced_enable_old_layout_title">Enable old layout</string>
<string name="revanced_enable_oldstyle_seekbar_color_summary_off">New seekbar color is used</string>
<string name="revanced_enable_oldstyle_seekbar_color_summary_on">Old seekbar color is used</string>
<string name="revanced_enable_oldstyle_seekbar_color_title">Enable old style seekbar color</string>
<string name="revanced_enable_oldstyle_quality_layout_summary_off">New style quality settings are shown</string>
<string name="revanced_enable_oldstyle_quality_layout_summary_on">Old style quality settings are shown</string>
<string name="revanced_enable_oldstyle_quality_layout_title">Enable old style quality layout</string>

View File

@ -237,6 +237,9 @@
<!-- PREFERENCE_HEADER: SEEKBAR
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_layout_settings_seekbar" />PREFERENCE_HEADER: SEEKBAR -->
<!-- SETTINGS: ENABLE_OLD_SEEKBAR_COLOR
<SwitchPreference android:title="@string/revanced_enable_oldstyle_seekbar_color_title" android:key="revanced_enable_old_seekbar_color" android:defaultValue="true" android:summaryOn="@string/revanced_enable_oldstyle_seekbar_color_summary_on" android:summaryOff="@string/revanced_enable_oldstyle_seekbar_color_summary_off" />SETTINGS: ENABLE_OLD_SEEKBAR_COLOR -->
<!-- SETTINGS: ENABLE_SEEKBAR_TAPPING
<SwitchPreference android:title="@string/revanced_enable_seekbar_tapping_title" android:key="revanced_enable_seekbar_tapping" android:defaultValue="true" android:summaryOn="@string/revanced_enable_seekbar_tapping_summary_on" android:summaryOff="@string/revanced_enable_seekbar_tapping_summary_off" />SETTINGS: ENABLE_SEEKBAR_TAPPING -->
@ -384,6 +387,7 @@
<Preference android:title="hide-comment-component" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_layout_settings_flyoutmenu" />
<Preference android:title="enable-old-seekbar-color" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="enable-oldstyle-quality-layout" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-flyout-panel" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>