Skip to content

Commit

Permalink
feat: merged changes from revanced-patches main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Slenderman00 committed Nov 8, 2024
1 parent 5f8bba7 commit cb719d4
Show file tree
Hide file tree
Showing 807 changed files with 30,046 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ node_modules/

#ignoring all builds
build/
gradle.properties

2,390 changes: 2,390 additions & 0 deletions api/revanced-patches-grindr.api

Large diffs are not rendered by default.

81 changes: 54 additions & 27 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import org.gradle.kotlin.dsl.support.listFilesOrdered
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
kotlin("jvm") version "1.9.10"
alias(libs.plugins.kotlin)
alias(libs.plugins.binary.compatibility.validator)
`maven-publish`
signing
}

group = "patches.grindr"
Expand All @@ -11,7 +14,14 @@ repositories {
mavenCentral()
mavenLocal()
google()
maven { url = uri("https://jitpack.io") }
maven {
// A repository must be specified for some reason. "registry" is a dummy.
url = uri("https://maven.pkg.github.com/revanced/registry")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}

dependencies {
Expand All @@ -21,61 +31,78 @@ dependencies {
implementation(libs.guava)
// Used in JsonGenerator.
implementation(libs.gson)

// A dependency to the Android library unfortunately fails the build, which is why this is required.
compileOnly(project("dummy"))
// Android API stubs defined here.
compileOnly(project(":stub"))
}

kotlin {
jvmToolchain(11)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

tasks.withType(Jar::class) {
manifest {
attributes["Name"] = "Grindr patches"
attributes["Description"] = "Patches for Grindr."
attributes["Version"] = version
attributes["Timestamp"] = System.currentTimeMillis().toString()
attributes["Source"] = "[email protected]:Slenderman00/revanced-patches-grindr.git"
attributes["Author"] = "You"
attributes["Contact"] = "[email protected]"
attributes["Origin"] = "https://joar.me"
attributes["License"] = "GNU General Public License v3.0"
}
java {
targetCompatibility = JavaVersion.VERSION_11
}

tasks {
register<DefaultTask>("generateBundle") {
description = "Generate DEX files and add them in the JAR file"
withType(Jar::class) {
exclude("app/revanced/meta")

manifest {
attributes["Name"] = "Grindr patches"
attributes["Description"] = "Patches for Grindr."
attributes["Version"] = version
attributes["Timestamp"] = System.currentTimeMillis().toString()
attributes["Source"] = "[email protected]:Slenderman00/revanced-patches-grindr.git"
attributes["Author"] = "You"
attributes["Contact"] = "[email protected]"
attributes["Origin"] = "https://joar.me"
attributes["License"] = "GNU General Public License v3.0"
}
}

register("buildDexJar") {
description = "Build and add a DEX to the JAR file"
group = "build"

dependsOn(build)

doLast {
val d8 = File(System.getenv("ANDROID_HOME")).resolve("build-tools")
.listFilesOrdered().last().resolve("d8").absolutePath

val artifacts = configurations.archives.get().allArtifacts.files.files.first().absolutePath
val patchesJar = configurations.archives.get().allArtifacts.files.files.first().absolutePath
val workingDirectory = layout.buildDirectory.dir("libs").get().asFile

exec {
workingDir = workingDirectory
commandLine = listOf(d8, artifacts)
commandLine = listOf(d8, "--release", patchesJar)
}

exec {
workingDir = workingDirectory
commandLine = listOf("zip", "-u", artifacts, "classes.dex")
commandLine = listOf("zip", "-u", patchesJar, "classes.dex")
}
}
}

// Required to run tasks because Gradle semantic-release plugin runs the publish task.
register<JavaExec>("generatePatchesFiles") {
description = "Generate patches files"

dependsOn(build)

classpath = sourceSets["main"].runtimeClasspath
mainClass.set("app.revanced.generator.MainKt")
}

// Needed by gradle-semantic-release-plugin.
// Tracking: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435
named("publish") {
dependsOn("generateBundle")
publish {
dependsOn("buildDexJar")
dependsOn("generatePatchesFiles")
}
}

publishing {
publications {
create<MavenPublication>("revanced-patches-publication") {
Expand Down
15 changes: 11 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
[versions]
revanced-patcher = "19.0.0"
smali = "3.0.3"
guava = "32.1.2-jre"
gson = "2.10.1"
revanced-patcher = "19.3.1"
#noinspection GradleDependency
smali = "3.0.5" # 3.0.7 breaks binary compatibility. Tracking https://github.com/google/smali/issues/58.
guava = "33.2.1-jre"
gson = "2.11.0"
binary-compatibility-validator = "0.15.1"
kotlin = "2.0.0"

[libraries]
revanced-patcher = { module = "app.revanced:revanced-patcher", version.ref = "revanced-patcher" }
smali = { module = "com.android.tools.smali:smali", version.ref = "smali" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }

[plugins]
binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compatibility-validator" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
4 changes: 3 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
include("dummy")

rootProject.name = "revanced-patches"
rootProject.name = "revanced-patches-grindr"

buildCache {
local {
isEnabled = !System.getenv().containsKey("CI")
}
}

include(":stub")
49 changes: 49 additions & 0 deletions src/main/kotlin/app/revanced/generator/JsonPatchesFileGenerator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package app.revanced.generator

import app.revanced.patcher.PatchSet
import app.revanced.patcher.patch.Patch
import com.google.gson.GsonBuilder
import java.io.File

internal class JsonPatchesFileGenerator : PatchesFileGenerator {
override fun generate(patches: PatchSet) = patches.map {
JsonPatch(
it.name!!,
it.description,
it.compatiblePackages,
it.use,
it.requiresIntegrations,
it.options.values.map { option ->
JsonPatch.Option(
option.key,
option.default,
option.values,
option.title,
option.description,
option.required,
)
},
)
}.let {
File("patches.json").writeText(GsonBuilder().serializeNulls().create().toJson(it))
}

@Suppress("unused")
private class JsonPatch(
val name: String? = null,
val description: String? = null,
val compatiblePackages: Set<Patch.CompatiblePackage>? = null,
val use: Boolean = true,
val requiresIntegrations: Boolean = false,
val options: List<Option>,
) {
class Option(
val key: String,
val default: Any?,
val values: Map<String, Any?>?,
val title: String?,
val description: String?,
val required: Boolean,
)
}
}
12 changes: 12 additions & 0 deletions src/main/kotlin/app/revanced/generator/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.revanced.generator

import app.revanced.patcher.PatchBundleLoader
import java.io.File

internal fun main() = PatchBundleLoader.Jar(
File("build/libs/").listFiles { it -> it.name.endsWith(".jar") }!!.first(),
).also { loader ->
if (loader.isEmpty()) throw IllegalStateException("No patches found")
}.let { bundle ->
arrayOf(JsonPatchesFileGenerator()).forEach { generator -> generator.generate(bundle) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package app.revanced.generator

import app.revanced.patcher.PatchSet

internal interface PatchesFileGenerator {
fun generate(patches: PatchSet)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package app.revanced.patches.all.activity.exportall

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.Patch

@Patch(
name = "Export all activities",
description = "Makes all app activities exportable.",
use = false,
)
@Suppress("unused")
object ExportAllActivitiesPatch : ResourcePatch() {
private const val EXPORTED_FLAG = "android:exported"

override fun execute(context: ResourceContext) {
context.xmlEditor["AndroidManifest.xml"].use { editor ->
val document = editor.file

val activities = document.getElementsByTagName("activity")

for (i in 0..activities.length) {
activities.item(i)?.apply {
val exportedAttribute = attributes.getNamedItem(EXPORTED_FLAG)

if (exportedAttribute != null) {
if (exportedAttribute.nodeValue != "true") {
exportedAttribute.nodeValue = "true"
}
}
// Reason why the attribute is added in the case it does not exist:
// https://github.com/revanced/revanced-patches/pull/1751/files#r1141481604
else {
document.createAttribute(EXPORTED_FLAG)
.apply { value = "true" }
.let(attributes::setNamedItem)
}
}
}
}
}
}
Loading

0 comments on commit cb719d4

Please sign in to comment.