Skip to content

Commit 18be3ce

Browse files
authored
Merge pull request #683 from swakwork/fix/v21
Some more fixes for v21
2 parents 02a95f6 + ee200a5 commit 18be3ce

File tree

29 files changed

+82
-172
lines changed

29 files changed

+82
-172
lines changed

extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/TimelineEntry.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private static boolean isEntryIdRemove(String entryId) {
2828
String[] split = entryId.split("-");
2929
String entryId2 = split[0];
3030
if (!entryId2.equals("cursor") && !entryId2.equals("Guide") && !entryId2.startsWith("semantic_core")) {
31-
if (entryId.contains("promoted") || ((entryId2.equals("conversationthread") && split.length == 3)) && hideAds) {
31+
if (entryId.contains("promoted") || (entryId2.equals("conversationthread") && split.length == 3) && hideAds) {
3232
return true;
3333
}
3434
if ((entryId2.equals("superhero") || entryId2.equals("eventsummary")) && hideAds) {
@@ -108,5 +108,12 @@ public static JsonSensitiveMediaWarning sensitiveMedia(JsonSensitiveMediaWarning
108108
return jsonSensitiveMediaWarning;
109109
}
110110

111+
public static boolean hidePromotedTrend(Object data) {
112+
if (data != null && hideAds) {
113+
return true;
114+
}
115+
return false;
116+
}
117+
111118
//end
112119
}

patches/api/patches.api

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public final class app/crimera/utils/UtilsKt {
319319
public static final fun getMethodName (Lapp/revanced/patcher/patch/BytecodePatchContext;Lapp/revanced/patcher/Fingerprint;I)Ljava/lang/String;
320320
public static final fun getReference (Lapp/revanced/patcher/patch/BytecodePatchContext;Lapp/revanced/patcher/Fingerprint;I)Lcom/android/tools/smali/dexlib2/iface/reference/Reference;
321321
public static final fun instructionToString (Lcom/android/tools/smali/dexlib2/iface/instruction/Instruction;)Ljava/lang/String;
322-
public static final fun replaceStringsInFile (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;Ljava/util/Map;)V
322+
public static final fun replaceStringsInFile (Lapp/revanced/patcher/patch/ResourcePatchContext;[Lapp/revanced/util/ResourceGroup;Ljava/util/Map;)V
323323
public static final fun replaceXmlResources (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;)V
324324
}
325325

@@ -445,7 +445,8 @@ public final class app/revanced/util/ResourceGroup {
445445
public final class app/revanced/util/ResourceUtilsKt {
446446
public static final fun asSequence (Lorg/w3c/dom/NodeList;)Lkotlin/sequences/Sequence;
447447
public static final fun childElementsSequence (Lorg/w3c/dom/Node;)Lkotlin/sequences/Sequence;
448-
public static final fun copyResources (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;)V
448+
public static final fun copyResources (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;Z)V
449+
public static synthetic fun copyResources$default (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;ZILjava/lang/Object;)V
449450
public static final fun copyXmlNode (Ljava/lang/String;Lapp/revanced/patcher/util/Document;Lapp/revanced/patcher/util/Document;)Ljava/lang/AutoCloseable;
450451
public static final fun doRecursively (Lorg/w3c/dom/Node;Lkotlin/jvm/functions/Function1;)V
451452
public static final fun forEachChildElement (Lorg/w3c/dom/Node;Lkotlin/jvm/functions/Function1;)V

patches/src/main/kotlin/app/crimera/patches/twitter/ads/timelineEntryHook/HideAds.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ val hideAds =
5454
method.addInstructionsWithLabels(
5555
return_loc,
5656
"""
57-
sget-boolean v$reg,${Constants.PATCHES_DESCRIPTOR}/TimelineEntry;->hideAds:Z
57+
invoke-static {v$reg},${Constants.PATCHES_DESCRIPTOR}/TimelineEntry;->hidePromotedTrend(Ljava/lang/Object;)Z
58+
move-result v$reg
5859
if-eqz v$reg, :cond_1212
5960
const v$return_reg, 0x0
6061
""".trimIndent(),

patches/src/main/kotlin/app/crimera/patches/twitter/misc/bringbacktwitter/BringBackTwitterPatch.kt

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,30 @@ val bringBackTwitterPatch =
3030

3131
// region Change app icons
3232

33-
val mipmapIcons = arrayOf(
34-
"ic_launcher_twitter.webp",
35-
"ic_launcher_twitter_round.webp",
36-
"ic_launcher_twitter_foreground.webp",
37-
)
33+
val mipmapIcons =
34+
arrayOf(
35+
"ic_launcher_twitter.webp",
36+
"ic_launcher_twitter_round.webp",
37+
"ic_launcher_twitter_foreground.webp",
38+
)
3839

39-
val drawableIcons = arrayOf(
40-
"ic_vector_twitter.xml",
41-
"ic_vector_home.xml",
42-
"ic_vector_twitter_white.xml",
43-
"ic_vector_home_stroke.xml",
44-
"splash_screen_icon.xml",
45-
)
40+
val drawableIcons =
41+
arrayOf(
42+
"ic_vector_twitter.xml",
43+
"ic_vector_home.xml",
44+
"ic_vector_twitter_white.xml",
45+
"ic_vector_home_stroke.xml",
46+
"splash_screen_icon.xml",
47+
)
4648

47-
val sizes = arrayOf(
48-
"xxxhdpi",
49-
"xxhdpi",
50-
"xhdpi",
51-
"hdpi",
52-
"mdpi",
53-
)
49+
val sizes =
50+
arrayOf(
51+
"xxxhdpi",
52+
"xxhdpi",
53+
"xhdpi",
54+
"hdpi",
55+
"mdpi",
56+
)
5457

5558
// drawable icons
5659
sizes
@@ -122,14 +125,20 @@ val bringBackTwitterPatch =
122125
"tr",
123126
"zh-rCN",
124127
"zh-rTW",
128+
"",
125129
).map { "values-$it" }
126130

127131
languages.forEach {
128-
val vDirectory = get("res").resolve(it)
132+
var folderName = it
133+
if (folderName.endsWith("-")) {
134+
folderName = it.replace("-", "")
135+
}
136+
val vDirectory = get("res").resolve(folderName)
129137
if (!vDirectory.isDirectory) {
130138
Files.createDirectories(vDirectory.toPath())
131139
}
132-
replaceXmlResources(basePath, ResourceGroup(it, "strings.xml"))
140+
val resGroup = ResourceGroup(folderName, "strings.xml")
141+
replaceXmlResources(basePath, resGroup)
133142

134143
/*
135144
* The Java XML API on Android has a bug that converts surrogate pair characters
@@ -139,12 +148,13 @@ val bringBackTwitterPatch =
139148
*/
140149
if (isRunningOnManager) {
141150
replaceStringsInFile(
142-
"res/$it/strings.xml",
143-
mapOf(
144-
"��" to "Twitter",
145-
"��" to "🔥",
146-
"��" to "🎁",
147-
),
151+
resGroup,
152+
replacements =
153+
mapOf(
154+
"��" to "Twitter",
155+
"��" to "🔥",
156+
"��" to "🎁",
157+
),
148158
)
149159
}
150160
}
@@ -153,18 +163,15 @@ val bringBackTwitterPatch =
153163
* Instead of defining strings in the map, replaces texts directly.
154164
* Reason: https://t.me/pikopatches/1/17339
155165
*/
156-
setOf(
157-
"res/values-ja/strings.xml",
158-
"res/values-ja/arrays.xml"
159-
).forEach {
160-
replaceStringsInFile(
161-
it,
166+
167+
replaceStringsInFile(
168+
ResourceGroup("values-ja", "strings.xml", "arrays.xml"),
169+
replacements =
162170
mapOf(
163171
"X" to "Twitter",
164172
"ポスト" to "ツイート",
165173
),
166-
)
167-
}
174+
)
168175

169176
// endregion
170177
}

patches/src/main/kotlin/app/crimera/patches/twitter/misc/settings/SettingsResourcePatch.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ internal val settingsResourcePatch =
4343
parent.appendChild(sideBtn)
4444
}
4545

46-
copyResources("twitter/settings", ResourceGroup("values", "piko_strings.xml"))
47-
copyResources("twitter/settings", ResourceGroup("values", "piko_arrays.xml"))
46+
val basePath = "twitter/settings/strings"
47+
48+
copyResources(basePath, ResourceGroup("values", "strings.xml", "arrays.xml"), appendPiko = true)
4849

4950
/**
5051
* create directory for the untranslated language resources
@@ -75,10 +76,10 @@ internal val settingsResourcePatch =
7576
if (!vDirectory.isDirectory) {
7677
Files.createDirectories(vDirectory.toPath())
7778
if (it.contains("v21")) {
78-
copyResources("twitter/settings", ResourceGroup(it, "piko_arrays.xml"))
79+
copyResources(basePath, ResourceGroup(it, "arrays.xml"), appendPiko = true)
7980
}
8081
}
81-
copyResources("twitter/settings", ResourceGroup(it, "piko_strings.xml"))
82+
copyResources(basePath, ResourceGroup(it, "strings.xml"), appendPiko = true)
8283
}
8384

8485
// execute end

patches/src/main/kotlin/app/crimera/patches/twitter/misc/shareMenu/nativeReaderMode/NativeReaderModePatch.kt

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -22,65 +22,5 @@ val nativeReaderModePatch =
2222
val functionReference = "/readerMode/ReaderModeUtils;->launchReaderMode"
2323
val statusFunctionName = "nativeReaderMode"
2424
shareMenuButtonInjection(actionName, prefFunctionName, stringId, iconId, functionReference, statusFunctionName)
25-
26-
// val actionName = "ReaderMode"
27-
//
28-
// val viewDebugDialogReference =
29-
// (
30-
// shareMenuButtonAddHook
31-
// .method
32-
// .implementation
33-
// ?.instructions
34-
// ?.last { it.opcode == Opcode.SGET_OBJECT } as Instruction21c
35-
// ).reference
36-
// // Add action
37-
// val downloadActionReference = addAction(actionName)
38-
//
39-
// // Register button
40-
// registerButton(actionName, "enableNativeReaderMode")
41-
//
42-
// // Set Button Text
43-
// setButtonText(actionName, "piko_title_native_reader_mode")
44-
// setButtonIcon(actionName, "ic_vector_book_stroke_on")
45-
//
46-
// // TODO: handle possible nulls
47-
// val buttonFuncMethod =
48-
// shareMenuButtonFuncCallFingerprint.method
49-
// .implementation
50-
// ?.instructions
51-
// ?.toList()
52-
// val deleteStatusLoc = shareMenuButtonFuncCallFingerprint.stringMatches?.first { it.string == "Delete Status" }?.index!!
53-
// val OkLoc = shareMenuButtonFuncCallFingerprint.stringMatches?.first { it.string == "OK" }?.index!!
54-
// val conversationalRepliesLoc =
55-
// shareMenuButtonFuncCallFingerprint.stringMatches
56-
// ?.first {
57-
// it.string ==
58-
// "conversational_replies_android_pinned_replies_creation_enabled"
59-
// }?.index
60-
//
61-
// val timelineRef =
62-
// (
63-
// buttonFuncMethod
64-
// ?.filterIndexed { i, ins ->
65-
// i > conversationalRepliesLoc!! && ins.opcode == Opcode.IGET_OBJECT
66-
// }?.first() as Instruction22c?
67-
// ) ?: throw PatchException("Failed to find timelineRef")
68-
// val timelineRefReg = (buttonFuncMethod?.get(deleteStatusLoc - 1) as Instruction35c).registerD
69-
//
70-
// val activityRefReg = (buttonFuncMethod[OkLoc - 3] as Instruction35c).registerD
71-
//
72-
// // Add Button function
73-
// addButtonInstructions(
74-
// downloadActionReference,
75-
// """
76-
// check-cast v$timelineRefReg, ${timelineRef.reference.extractDescriptors()[0]}
77-
// iget-object v1, v$timelineRefReg, ${timelineRef.reference}
78-
//
79-
// invoke-static {v$activityRefReg, v1}, $NATIVE_DESCRIPTOR/readerMode/ReaderModeUtils;->launchReaderMode(Landroid/content/Context;Ljava/lang/Object;)V
80-
// """.trimIndent(),
81-
// viewDebugDialogReference,
82-
// )
83-
//
84-
// settingsStatusLoadFingerprint.enableSettings("nativeReaderMode")
8525
}
8626
}

patches/src/main/kotlin/app/crimera/patches/twitter/misc/shareMenu/nativeTranslator/NativeTranslatorPatch.kt

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,64 +22,5 @@ val nativeTranslatorModePatch =
2222
val functionReference = "/translator/NativeTranslator;->translate"
2323
val statusFunctionName = "nativeTranslator"
2424
shareMenuButtonInjection(actionName, prefFunctionName, stringId, iconId, functionReference, statusFunctionName)
25-
//
26-
// val viewDebugDialogReference =
27-
// (
28-
// shareMenuButtonAddHook
29-
// .method
30-
// .implementation
31-
// ?.instructions
32-
// ?.last { it.opcode == Opcode.SGET_OBJECT } as Instruction21c
33-
// ).reference
34-
//
35-
// // Add action
36-
// val downloadActionReference = addAction(actionName)
37-
//
38-
// // Register button
39-
// registerButton(actionName, "enableNativeTranslator")
40-
//
41-
// // Set Button Text
42-
// setButtonText(actionName, "translate_tweet_show")
43-
// setButtonIcon(actionName, "ic_vector_sparkle")
44-
//
45-
// // TODO: handle possible nulls
46-
// val buttonFuncMethod =
47-
// shareMenuButtonFuncCallFingerprint.method
48-
// .implementation
49-
// ?.instructions
50-
// ?.toList()
51-
// val deleteStatusLoc = shareMenuButtonFuncCallFingerprint.stringMatches?.first { it.string == "Delete Status" }?.index!!
52-
// val OkLoc = shareMenuButtonFuncCallFingerprint.stringMatches?.first { it.string == "OK" }?.index!!
53-
// val conversationalRepliesLoc =
54-
// shareMenuButtonFuncCallFingerprint.stringMatches
55-
// ?.first {
56-
// it.string ==
57-
// "conversational_replies_android_pinned_replies_creation_enabled"
58-
// }?.index
59-
//
60-
// val timelineRef =
61-
// (
62-
// buttonFuncMethod
63-
// ?.filterIndexed { i, ins ->
64-
// i > conversationalRepliesLoc!! && ins.opcode == Opcode.IGET_OBJECT
65-
// }?.first() as Instruction22c?
66-
// ) ?: throw PatchException("Failed to find timelineRef")
67-
// val timelineRefReg = (buttonFuncMethod?.get(deleteStatusLoc - 1) as Instruction35c).registerD
68-
//
69-
// val activityRefReg = (buttonFuncMethod[OkLoc - 3] as Instruction35c).registerD
70-
//
71-
// // Add Button function
72-
// addButtonInstructions(
73-
// downloadActionReference,
74-
// """
75-
// check-cast v$timelineRefReg, ${timelineRef.reference.extractDescriptors()[0]}
76-
// iget-object v1, v$timelineRefReg, ${timelineRef.reference}
77-
//
78-
// invoke-static {v$activityRefReg, v1}, $NATIVE_DESCRIPTOR(Landroid/content/Context;Ljava/lang/Object;)V
79-
// """.trimIndent(),
80-
// viewDebugDialogReference,
81-
// )
82-
//
83-
// settingsStatusLoadFingerprint.enableSettings("")
8425
}
8526
}

patches/src/main/kotlin/app/crimera/utils/Utils.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,24 @@ fun ResourcePatchContext.replaceXmlResources(
7070
}
7171

7272
fun ResourcePatchContext.replaceStringsInFile(
73-
filePath: String,
73+
vararg resourceGroups: ResourceGroup,
7474
replacements: Map<String, String>,
7575
) {
76-
val file = get(filePath)
77-
var content = file.readText()
76+
resourceGroups.forEach { resourceGroup ->
77+
resourceGroup.resources.forEach { resource ->
78+
val sourcePath = "${resourceGroup.resourceDirectoryName}/$resource"
79+
val sourceFile = get("res").resolve(sourcePath)
80+
if (sourceFile.exists()) {
81+
var content = sourceFile.readText()
7882

79-
replacements.forEach { (from, to) ->
80-
content = content.replace(from, to)
81-
}
83+
replacements.forEach { (from, to) ->
84+
content = content.replace(from, to)
85+
}
8286

83-
file.writeText(content)
87+
sourceFile.writeText(content)
88+
}
89+
}
90+
}
8491
}
8592

8693
context(BytecodePatchContext)

patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,20 @@ fun Node.insertFirst(node: Node) {
6262
fun ResourcePatchContext.copyResources(
6363
sourceResourceDirectory: String,
6464
vararg resources: ResourceGroup,
65+
appendPiko: Boolean = false,
6566
) {
6667
val targetResourceDirectory = this["res", false]
6768

6869
for (resourceGroup in resources) {
6970
resourceGroup.resources.forEach { resource ->
70-
val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource"
71+
72+
val resourcePath = "${resourceGroup.resourceDirectoryName}/$resource"
73+
var targetPath = resourcePath
74+
if (appendPiko) targetPath = "${resourceGroup.resourceDirectoryName}/piko_$resource"
75+
7176
Files.copy(
72-
inputStreamFromBundledResource(sourceResourceDirectory, resourceFile)!!,
73-
targetResourceDirectory.resolve(resourceFile).toPath(),
77+
inputStreamFromBundledResource(sourceResourceDirectory, resourcePath)!!,
78+
targetResourceDirectory.resolve(targetPath).toPath(),
7479
StandardCopyOption.REPLACE_EXISTING,
7580
)
7681
}

patches/src/main/resources/twitter/settings/values-ar/piko_strings.xml renamed to patches/src/main/resources/twitter/settings/strings/values-ar/strings.xml

File renamed without changes.

0 commit comments

Comments
 (0)