mirror of
https://github.com/ReVanced/revanced-patches.git
synced 2026-01-27 12:41:03 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6580f71392 | ||
|
|
9c57961680 | ||
|
|
1d7a9ac437 | ||
|
|
51e08fb0b6 | ||
|
|
91feea1c50 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,3 +1,17 @@
|
|||||||
|
# [2.26.0](https://github.com/revanced/revanced-patches/compare/v2.25.3...v2.26.0) (2022-07-31)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* `ResourceUtils` helper class ([e0e1144](https://github.com/revanced/revanced-patches/commit/e0e11447a7ac184d43c75955854c52c6992ff667))
|
||||||
|
|
||||||
|
## [2.25.3](https://github.com/revanced/revanced-patches/compare/v2.25.2...v2.25.3) (2022-07-29)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* actually call `VideoInformation.setCurrentVideoId` first ([5c62d0a](https://github.com/revanced/revanced-patches/commit/5c62d0a2e0217de1b9563a41b4e94ed63230440f))
|
||||||
|
|
||||||
## [2.25.2](https://github.com/revanced/revanced-patches/compare/v2.25.1...v2.25.2) (2022-07-26)
|
## [2.25.2](https://github.com/revanced/revanced-patches/compare/v2.25.1...v2.25.2) (2022-07-26)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 2.25.2
|
version = 2.26.0
|
||||||
|
|||||||
@@ -35,15 +35,18 @@ class VideoIdPatch : BytecodePatch(
|
|||||||
|
|
||||||
injectCall("Lapp/revanced/integrations/videoplayer/VideoInformation;->setCurrentVideoId(Ljava/lang/String;)V")
|
injectCall("Lapp/revanced/integrations/videoplayer/VideoInformation;->setCurrentVideoId(Ljava/lang/String;)V")
|
||||||
|
|
||||||
|
offset++ // offset so setCurrentVideoId is called before any injected call
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private lateinit var result: MethodFingerprintResult
|
|
||||||
private var videoIdRegister: Int = 0
|
|
||||||
private lateinit var insertMethod: MutableMethod
|
|
||||||
private var offset = 2
|
private var offset = 2
|
||||||
|
|
||||||
|
private var videoIdRegister: Int = 0
|
||||||
|
private lateinit var result: MethodFingerprintResult
|
||||||
|
private lateinit var insertMethod: MutableMethod
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an invoke-static instruction, called with the new id when the video changes
|
* Adds an invoke-static instruction, called with the new id when the video changes
|
||||||
* @param methodDescriptor which method to call. Params have to be `Ljava/lang/String;`
|
* @param methodDescriptor which method to call. Params have to be `Ljava/lang/String;`
|
||||||
@@ -52,10 +55,9 @@ class VideoIdPatch : BytecodePatch(
|
|||||||
methodDescriptor: String
|
methodDescriptor: String
|
||||||
) {
|
) {
|
||||||
insertMethod.addInstructions(
|
insertMethod.addInstructions(
|
||||||
result.patternScanResult!!.endIndex + offset, // after the move-result-object
|
result.patternScanResult!!.endIndex + offset, // move-result-object offset
|
||||||
"invoke-static {v$videoIdRegister}, $methodDescriptor"
|
"invoke-static {v$videoIdRegister}, $methodDescriptor"
|
||||||
)
|
)
|
||||||
offset++ // so additional instructions get added later
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
75
src/main/kotlin/app/revanced/util/resources/ResourceUtils.kt
Normal file
75
src/main/kotlin/app/revanced/util/resources/ResourceUtils.kt
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package app.revanced.util.resources
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.impl.DomFileEditor
|
||||||
|
import app.revanced.patcher.data.impl.ResourceData
|
||||||
|
import java.io.OutputStream
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
internal object ResourceUtils {
|
||||||
|
/**
|
||||||
|
* Copy resources from the current class loader to the resource directory.
|
||||||
|
* @param sourceResourceDirectory The source resource directory name.
|
||||||
|
* @param resources The resources to copy.
|
||||||
|
*/
|
||||||
|
internal fun ResourceData.copyResources(sourceResourceDirectory: String, vararg resources: ResourceGroup) {
|
||||||
|
val classLoader = ResourceUtils.javaClass.classLoader
|
||||||
|
val targetResourceDirectory = this["res"]
|
||||||
|
|
||||||
|
for (resourceGroup in resources) {
|
||||||
|
resourceGroup.resources.forEach { resource ->
|
||||||
|
val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource"
|
||||||
|
Files.copy(
|
||||||
|
classLoader.getResourceAsStream("$sourceResourceDirectory/$resourceFile")!!,
|
||||||
|
targetResourceDirectory.resolve(resourceFile).toPath()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resource names mapped to their corresponding resource data.
|
||||||
|
* @param resourceDirectoryName The name of the directory of the resource.
|
||||||
|
* @param resources A list of resource names.
|
||||||
|
*/
|
||||||
|
internal class ResourceGroup(val resourceDirectoryName: String, vararg val resources: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy resources from the current class loader to the resource directory.
|
||||||
|
* @param resourceDirectory The directory of the resource.
|
||||||
|
* @param targetResource The target resource.
|
||||||
|
* @param elementTag The element to copy.
|
||||||
|
*/
|
||||||
|
internal fun ResourceData.copyXmlNode(resourceDirectory: String, targetResource: String, elementTag: String) {
|
||||||
|
val stringsResourceInputStream = ResourceUtils.javaClass.classLoader.getResourceAsStream("$resourceDirectory/$targetResource")!!
|
||||||
|
|
||||||
|
// Copy nodes from the resources node to the real resource node
|
||||||
|
elementTag.copyXmlNode(
|
||||||
|
this.xmlEditor[stringsResourceInputStream, OutputStream.nullOutputStream()],
|
||||||
|
this.xmlEditor["res/$targetResource"]
|
||||||
|
).close()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the specified node of the source [DomFileEditor] to the target [DomFileEditor].
|
||||||
|
* @param source the source [DomFileEditor].
|
||||||
|
* @param target the target [DomFileEditor]-
|
||||||
|
* @return AutoCloseable that closes the target [DomFileEditor]s.
|
||||||
|
*/
|
||||||
|
internal fun String.copyXmlNode(source: DomFileEditor, target: DomFileEditor): AutoCloseable {
|
||||||
|
val hostNodes = source.file.getElementsByTagName(this).item(0).childNodes
|
||||||
|
|
||||||
|
val destinationResourceFile = target.file
|
||||||
|
val destinationNode = destinationResourceFile.getElementsByTagName(this).item(0)
|
||||||
|
|
||||||
|
for (index in 0 until hostNodes.length) {
|
||||||
|
val node = hostNodes.item(index).cloneNode(true)
|
||||||
|
destinationResourceFile.adoptNode(node)
|
||||||
|
destinationNode.appendChild(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
return AutoCloseable {
|
||||||
|
source.close()
|
||||||
|
target.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user