Skip to content

Commit

Permalink
Remove Knot Authlib hack
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-1000 committed Jul 5, 2022
1 parent b311cee commit d658d5d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 71 deletions.
34 changes: 28 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("fabric-loom") version "0.10-SNAPSHOT"
id("io.github.juuxel.loom-quiltflower-mini") version "1.2.1"
id("maven-publish")
id("fabric-loom") version "0.12-SNAPSHOT"
id("io.github.juuxel.loom-quiltflower") version "1.7.3"
`maven-publish`
}

repositories {
Expand Down Expand Up @@ -31,12 +31,30 @@ base.archivesName.set(archives_base_name)
version = mod_version
group = maven_group

sourceSets {
val headers by creating {
java {
compileClasspath += main.get().compileClasspath
}
}
main {
java {
compileClasspath += headers.output
}
}
}

dependencies {
// To change the versions see the gradle.properties file
// To change the versions, see the gradle.properties file
minecraft("com.mojang:minecraft:${minecraft_version}")
mappings("net.fabricmc:yarn:${yarn_mappings}:v2")
mappings("net.fabricmc:yarn:$minecraft_version+build.$yarn_mappings:v2")
modImplementation("net.fabricmc:fabric-loader:${loader_version}")
compileOnly("net.minecraftforge:javafmllanguage:${forge_version}")
compileOnly("net.minecraftforge:javafmllanguage:${forge_version}") {
isTransitive = false
}
compileOnly("net.minecraftforge:fmlloader:${forge_version}") {
isTransitive = false
}
}

tasks.processResources {
Expand All @@ -58,6 +76,10 @@ tasks.withType<JavaCompile> {
options.release.set(16)
}

tasks.javadoc {
classpath += sourceSets["headers"].output
}

java {
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.18.1-pre1
yarn_mappings=1.18.1-pre1+build.4
loader_version=0.12.8
minecraft_version=1.19.1-pre2
yarn_mappings=2
loader_version=0.14.8

# Forge
forge_version=1.18-38.0.14
forge_version=1.19-41.0.63

# Mod Properties
mod_version=1.3.0
mod_version=1.4.0
maven_group=de.kb1000
archives_base_name=no-telemetry
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 0 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ pluginManagement {
maven("https://maven.fabricmc.net") {
name = "Fabric"
}
maven("https://server.bbkr.space/artifactory/libs-release") {
name = "Cotton"
}
gradlePluginPortal()
}
}
Expand Down
55 changes: 0 additions & 55 deletions src/main/java/de/kb1000/notelemetry/NoTelemetryPreLaunch.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.NoSuchElementException;
import java.util.Optional;

public class NoTelemetryPreLaunch implements PreLaunchEntrypoint {
public static final Logger LOGGER = LogManager.getLogger("no-telemetry");

@Override
public void onPreLaunch() {
try {
ClassLoader classLoader = getClass().getClassLoader();
Method m = classLoader.getClass().getMethod("addURL", URL.class);
m.setAccessible(true);
m.invoke(classLoader, getSource(classLoader, "com/mojang/authlib/yggdrasil/YggdrasilUserApiService.class").orElseThrow());
LOGGER.info("Added authlib to knot");
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchElementException e) {
LOGGER.warn("Failed to add authlib to knot", e);
}

LOGGER.info("Killing telemetry");
}

// from Fabric Loader, copied to avoid depending on Loader internals
private static Optional<URL> getSource(ClassLoader loader, String filename) {
URL url;

if ((url = loader.getResource(filename)) != null) {
URL urlSource = getSource(filename, url);

return Optional.of(urlSource);
}

return Optional.empty();
}

private static URL getSource(String filename, URL resourceURL) {
URL codeSourceURL;

try {
URLConnection connection = resourceURL.openConnection();

if (connection instanceof JarURLConnection) {
codeSourceURL = ((JarURLConnection) connection).getJarFileURL();
} else {
String path = resourceURL.getPath();

if (path.endsWith(filename)) {
codeSourceURL = new URL(resourceURL.getProtocol(), resourceURL.getHost(), resourceURL.getPort(), path.substring(0, path.length() - filename.length()));
} else {
throw new RuntimeException("Could not figure out code source for file '" + filename + "' and URL '" + resourceURL + "'!");
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}

return codeSourceURL;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"no-telemetry.mixins.json"
],
"depends": {
"fabricloader": ">=0.11.3",
"fabricloader": ">=0.14.0",
"minecraft": ">=1.18-alpha.21.38.a",
"java": ">=16"
}
Expand Down

0 comments on commit d658d5d

Please sign in to comment.