generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
184 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,72 @@ | ||
# 🧩 ReVanced Patches | ||
## 🧩 Patches | ||
|
||
Official patches by ReVanced | ||
The official Patch bundle provided by ReVanced and the community. | ||
|
||
## 📜 List of available patches | ||
> Looking for the JSON variant of this? [Click here](patches.json). | ||
{{ table }} | ||
|
||
## 📝 JSON Format | ||
|
||
This section explains the JSON format for the [patches.json](patches.json) file. | ||
|
||
The file contains an array of objects, each object representing a patch. The object contains the following properties: | ||
|
||
| key | description | | ||
|-------------------------------|------------------------------------------------------------------------------------------------------------------| | ||
| `name` | The name of the patch. | | ||
| `description` | The description of the patch. | | ||
| `version` | The version of the patch. | | ||
| `excluded` | Whether a patch is excluded by default. If `true`, the patch must never be included by default. | | ||
| `dependencies` | An array of dependencies, which are patch names. | | ||
| `compatiblePackages` | An array of packages compatible with this patch. | | ||
| `compatiblePackages.name` | The name of the package. | | ||
| `compatiblePackages.versions` | An array of versions of the package compatible with this patch. If empty, all versions are seemingly compatible. | | ||
|
||
Example: | ||
|
||
```json | ||
[ | ||
{ | ||
"name": "remember-video-quality", | ||
"description": "Adds the ability to remember the video quality you chose in the video quality flyout.", | ||
"version": "0.0.1", | ||
"excluded": false, | ||
"dependencies": [ | ||
"integrations", | ||
"video-id-hook" | ||
], | ||
"compatiblePackages": [ | ||
{ | ||
"name": "com.google.android.youtube", | ||
"versions": [ | ||
"17.22.36", | ||
"17.24.35", | ||
"17.26.35", | ||
"17.27.39", | ||
"17.28.34", | ||
"17.29.34", | ||
"17.32.35" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "client-spoof", | ||
"description": "Spoofs the YouTube or Vanced client to prevent playback issues.", | ||
"version": "0.0.1", | ||
"excluded": false, | ||
"dependencies": [], | ||
"compatiblePackages": [ | ||
{ | ||
"name": "com.google.android.youtube", | ||
"versions": [] | ||
}, | ||
{ | ||
"name": "com.vanced.android.youtube", | ||
"versions": [] | ||
} | ||
] | ||
} | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package app.revanced.meta | ||
|
||
import app.revanced.meta.json.generateJson | ||
import app.revanced.meta.readme.generateText | ||
import app.revanced.patcher.data.Data | ||
import app.revanced.patcher.patch.Patch | ||
import app.revanced.patcher.util.patch.impl.JarPatchBundle | ||
import java.io.File | ||
|
||
typealias Bundle = List<Class<out Patch<Data>>> | ||
|
||
object Meta { | ||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
val patches = accumulatePatches() | ||
if (patches.isEmpty()) throw IllegalStateException("No patches found") | ||
|
||
generateText(patches) | ||
generateJson(patches) | ||
} | ||
} | ||
|
||
fun accumulatePatches() = JarPatchBundle( | ||
File("build/libs/").listFiles()!!.first { | ||
it.name.startsWith("revanced-patches-") && it.name.endsWith(".jar") | ||
}.absolutePath | ||
).loadPatches() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package app.revanced.meta.json | ||
|
||
import app.revanced.meta.Bundle | ||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages | ||
import app.revanced.patcher.extensions.PatchExtensions.dependencies | ||
import app.revanced.patcher.extensions.PatchExtensions.description | ||
import app.revanced.patcher.extensions.PatchExtensions.include | ||
import app.revanced.patcher.extensions.PatchExtensions.patchName | ||
import app.revanced.patcher.extensions.PatchExtensions.version | ||
import com.google.gson.Gson | ||
import java.io.File | ||
|
||
private val gson = Gson() | ||
|
||
fun generateJson(bundle: Bundle) { | ||
val patches = bundle.map { | ||
JsonPatch( | ||
it.patchName, | ||
it.description ?: "This patch has no description.", | ||
it.version ?: "0.0.0", | ||
!it.include, | ||
it.dependencies?.map { dep -> | ||
dep.java.patchName | ||
}?.toTypedArray() ?: emptyArray(), | ||
it.compatiblePackages?.map { pkg -> | ||
CompatiblePackage(pkg.name, pkg.versions) | ||
}?.toTypedArray() ?: emptyArray() | ||
) | ||
} | ||
|
||
val json = File("patches.json") | ||
json.writeText(gson.toJson(patches)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@file:Suppress("ArrayInDataClass") // We don't need it here. | ||
|
||
package app.revanced.meta.json | ||
|
||
data class JsonPatch( | ||
val name: String, | ||
val description: String, | ||
val version: String, | ||
val excluded: Boolean, | ||
val dependencies: Array<String>, | ||
val compatiblePackages: Array<CompatiblePackage>, | ||
) | ||
|
||
data class CompatiblePackage( | ||
val name: String, | ||
val versions: Array<String>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,44 @@ | ||
package app.revanced.meta.readme | ||
|
||
import app.revanced.meta.Bundle | ||
import app.revanced.patcher.data.Data | ||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages | ||
import app.revanced.patcher.extensions.PatchExtensions.description | ||
import app.revanced.patcher.extensions.PatchExtensions.patchName | ||
import app.revanced.patcher.patch.Patch | ||
import app.revanced.patcher.util.patch.impl.JarPatchBundle | ||
import java.io.File | ||
|
||
object Generator { | ||
private const val TABLE_HEADER = | ||
"| \uD83D\uDC8A Patch | \uD83D\uDCDC Description | \uD83C\uDFF9 Target Version |\n" + | ||
"|:--------:|:--------------:|:-----------------:|" | ||
private const val TABLE_HEADER = | ||
"| \uD83D\uDC8A Patch | \uD83D\uDCDC Description | \uD83C\uDFF9 Target Version |\n" + "|:--------:|:--------------:|:-----------------:|" | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
val buildDir = File("build/libs/") | ||
val buildJar = | ||
buildDir.listFiles()?.first { it.name.startsWith("revanced-patches-") && it.name.endsWith(".jar") }!! | ||
private val TABLE_REGEX = Regex("\\{\\{\\s?table\\s?}}") | ||
|
||
val bundle = JarPatchBundle(buildJar.absolutePath).loadPatches() | ||
fun generateText(bundle: Bundle) { | ||
val output = StringBuilder() | ||
val packages = mutableMapOf<String, MutableList<Class<out Patch<Data>>>>() | ||
|
||
val output = StringBuilder() | ||
|
||
val packages = mutableMapOf<String, MutableList<Class<out Patch<Data>>>>() | ||
|
||
bundle.map { | ||
val packageName = it.compatiblePackages?.first()?.name!! | ||
if (!packages.contains(packageName)) { | ||
packages[packageName] = mutableListOf() | ||
} | ||
|
||
packages[packageName]?.add(it) | ||
bundle.map { | ||
val packageName = it.compatiblePackages?.first()?.name!! | ||
if (!packages.contains(packageName)) { | ||
packages[packageName] = mutableListOf() | ||
} | ||
|
||
for (pkg in packages) { | ||
output.appendLine("### \uD83D\uDCE6 `${pkg.key}`") | ||
output.appendLine("<details>\n") | ||
packages[packageName]?.add(it) | ||
} | ||
|
||
output.appendLine(TABLE_HEADER) | ||
pkg.value.forEach { output.appendLine("| `${it.patchName}` | ${it.description} | ${it.getLatestVersion() ?: "all"} |") } | ||
for (pkg in packages) { | ||
output.appendLine("### \uD83D\uDCE6 `${pkg.key}`") | ||
output.appendLine("<details>\n") | ||
|
||
output.appendLine("</details>\n") | ||
} | ||
output.appendLine(TABLE_HEADER) | ||
pkg.value.forEach { output.appendLine("| `${it.patchName}` | ${it.description} | ${it.getLatestVersion() ?: "all"} |") } | ||
|
||
val readMeTemplateFile = File("README-template.md") | ||
val readmeTemplate = Template(readMeTemplateFile.readText()) | ||
output.appendLine("</details>\n") | ||
} | ||
|
||
readmeTemplate.replaceVariable("table", output.toString()) | ||
val readmeTemplate = Template(File("README-template.md").readText()) | ||
readmeTemplate.replaceVariable(TABLE_REGEX, output.toString()) | ||
|
||
val readme = File("README.md") | ||
readme.writeText(readmeTemplate.toString()) | ||
} | ||
val readme = File("README.md") | ||
readme.writeText(readmeTemplate.toString()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters