+3
-7
@@ -3,9 +3,7 @@ package app.revanced.patches.twitter.misc.dynamiccolor.patch
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultError
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patches.twitter.misc.dynamiccolor.annotations.DynamicColorCompatibility
|
||||
@@ -17,9 +15,9 @@ import java.nio.file.Files
|
||||
@Description("Replaces the default Twitter Blue with the users Material You palette.")
|
||||
@DynamicColorCompatibility
|
||||
class DynamicColorPatch : ResourcePatch {
|
||||
override fun execute(context: ResourceContext): PatchResult {
|
||||
override fun execute(context: ResourceContext) {
|
||||
val resDirectory = context["res"]
|
||||
if (!resDirectory.isDirectory) return PatchResultError("The res folder can not be found.")
|
||||
if (!resDirectory.isDirectory) throw PatchException("The res folder can not be found.")
|
||||
|
||||
val valuesV31Directory = resDirectory.resolve("values-v31")
|
||||
if (!valuesV31Directory.isDirectory) Files.createDirectories(valuesV31Directory.toPath())
|
||||
@@ -79,7 +77,5 @@ class DynamicColorPatch : ResourcePatch {
|
||||
document.getElementsByTagName("resources").item(0).appendChild(colorElement)
|
||||
}
|
||||
}
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package app.revanced.patches.twitter.misc.hook.json.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
object JsonHookPatchFingerprint : MethodFingerprint(
|
||||
customFingerprint = { methodDef, _ -> methodDef.name == "<clinit>" },
|
||||
|
||||
@@ -8,9 +8,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultError
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.annotations.RequiresIntegrations
|
||||
import app.revanced.patches.twitter.misc.hook.json.fingerprints.JsonHookPatchFingerprint
|
||||
import app.revanced.patches.twitter.misc.hook.json.fingerprints.JsonInputStreamFingerprint
|
||||
@@ -24,14 +22,14 @@ import java.io.InvalidClassException
|
||||
class JsonHookPatch : BytecodePatch(
|
||||
listOf(LoganSquareFingerprint)
|
||||
), Closeable {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
JsonHookPatchFingerprint.also {
|
||||
// Make sure the integrations are present.
|
||||
val jsonHookPatch = context.findClass { classDef -> classDef.type == JSON_HOOK_PATCH_CLASS_DESCRIPTOR }
|
||||
?: throw PatchResultError("Could not find integrations.")
|
||||
?: throw PatchException("Could not find integrations.")
|
||||
|
||||
if (!it.resolve(context, jsonHookPatch.immutableClass))
|
||||
throw PatchResultError("Unexpected integrations.")
|
||||
throw PatchException("Unexpected integrations.")
|
||||
}.let { hooks = JsonHookPatchHook(it) }
|
||||
|
||||
// Conveniently find the type to hook a method in, via a named field.
|
||||
@@ -42,7 +40,7 @@ class JsonHookPatch : BytecodePatch(
|
||||
?.type
|
||||
.let { type ->
|
||||
context.findClass { it.type == type }?.mutableClass
|
||||
} ?: return PatchResultError("Could not find required class.")
|
||||
} ?: throw PatchException("Could not find required class.")
|
||||
|
||||
// Hook the methods first parameter.
|
||||
JsonInputStreamFingerprint
|
||||
@@ -55,9 +53,7 @@ class JsonHookPatch : BytecodePatch(
|
||||
invoke-static { p1 }, $JSON_HOOK_PATCH_CLASS_DESCRIPTOR->parseJsonHook(Ljava/io/InputStream;)Ljava/io/InputStream;
|
||||
move-result-object p1
|
||||
"""
|
||||
) ?: return PatchResultError("Could not find method to hook.")
|
||||
|
||||
return PatchResultSuccess()
|
||||
) ?: throw PatchException("Could not find method to hook.")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,16 +2,9 @@ package app.revanced.patches.twitter.misc.hook.patch
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchResultError
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patches.twitter.misc.hook.json.patch.JsonHookPatch
|
||||
|
||||
abstract class BaseHookPatchPatch(private val hookClassDescriptor: String) : BytecodePatch() {
|
||||
override fun execute(context: BytecodeContext) = try {
|
||||
override fun execute(context: BytecodeContext) =
|
||||
JsonHookPatch.hooks.addHook(JsonHookPatch.Hook(context, hookClassDescriptor))
|
||||
|
||||
PatchResultSuccess()
|
||||
} catch (ex: Exception) {
|
||||
PatchResultError(ex)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user