Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ repositories {
}

dependencies {
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'org.ow2.asm:asm:9.6'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
}

test {
useJUnitPlatform()
}

compileJava {
options.release = 17
options.release = 8
options.deprecation = true
}

def buildNumber = System.getenv('AI_BUILD_NUMBER')
Expand Down Expand Up @@ -54,9 +54,14 @@ processResources {
}

shadowJar {
exclude 'META-INF/maven/**'
exclude 'module-info.class'
exclude '**/module-info.class'
archiveClassifier.set(null)

exclude 'META-INF/maven/**'
exclude 'module-info.class'
exclude '**/module-info.class'

relocate 'com.google.gson', 'xyz.zuoyx.multiyggdrasil.internal.com.google.gson'
relocate 'org.objectweb.asm', 'xyz.zuoyx.multiyggdrasil.internal.org.objectweb.asm'
}

defaultTasks 'clean', 'shadowJar'
92 changes: 92 additions & 0 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions src/main/java/xyz/zuoyx/multiyggdrasil/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ private static void initDebugOptions() {
} else {
for (String option : prop.split(",")) {
switch (option) {
case "verbose" -> verboseLogging = true;
case "authlib" -> authlibLogging = true;
case "printUntransformed" -> {
case "verbose": verboseLogging = true;
case "authlib": authlibLogging = true;
case "printUntransformed": {
printUntransformedClass = true;
verboseLogging = true;
}
case "dumpClass" -> dumpClass = true;
default -> {
case "dumpClass": dumpClass = true;
default: {
log(ERROR, "Unrecognized debug option: " + option);
throw new InitializationException();
}
Expand Down Expand Up @@ -131,13 +131,12 @@ private static void initMojangProxy() {
int port = Integer.parseInt(matcher.group("port"));

switch (protocol) {
case "socks" -> mojangProxy = new Proxy(Type.SOCKS, new InetSocketAddress(host, port));
default -> {
case "socks": mojangProxy = new Proxy(Type.SOCKS, new InetSocketAddress(host, port));
default: {
log(ERROR, "Unsupported proxy protocol: " + protocol);
throw new InitializationException();
}
}
log(INFO, "Mojang proxy: " + mojangProxy);
}

private static FeatureOption parseFeatureOption(String property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void handle(String domain, String path, HttpExchange exchange) throws Uns
if (!matcher.find())
throw new UnsupportedURLException();

UUID uuid;
UUID uuid;
try {
uuid = fromUnsignedUUID(matcher.group("uuid"));
} catch (IllegalArgumentException e) {
Expand All @@ -78,9 +78,9 @@ public void handle(String domain, String path, HttpExchange exchange) throws Uns
Optional<GameProfile> response;
if (uuid.version() == 4) {
response = mojangClient.queryProfile(uuid, withSignature);
} else {
} else {
response = customClient.queryProfile(uuid, withSignature);
response.ifPresent(profile -> profile.name = new NamespacedID(profile.name, namespace).toString());
response.ifPresent(profile -> profile.name = new NamespacedID(profile.name, namespace).toString());
}

if (response.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void accept(TransformUnit... units) {
for (int i = units.length - 1; i >= 0; i--) {
TransformContextImpl ctx = new TransformContextImpl();
Optional<ClassVisitor> visitor = units[i].transform(classLoader, className, chain, ctx);
if (visitor.isEmpty())
if (!visitor.isPresent())
continue;
ctxs[i] = ctx;
chain = visitor.get();
Expand Down Expand Up @@ -287,7 +287,7 @@ public byte[] transform(ClassLoader loader, String internalClassName, Class<?> c
handle.accept(unitsArray);

Optional<byte[]> transformResult = handle.finish();
if (Config.printUntransformedClass && transformResult.isEmpty()) {
if (Config.printUntransformedClass && !transformResult.isPresent()) {
log(DEBUG, "No transformation is applied to [" + className + "]");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ public void visitLdcInsn(Object cst) {
}
}

@Override
public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
for (int i = 0; i < bootstrapMethodArguments.length; i++) {
if (bootstrapMethodArguments[i] instanceof String constant) {
Optional<String> transformed = transformLdc(constant);
if (transformed.isPresent() && !transformed.get().equals(constant)) {
ctx.markModified();
bootstrapMethodArguments[i] = transformed.get();
}
}
}
@Override
public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
for (int i = 0; i < bootstrapMethodArguments.length; i++) {
if (bootstrapMethodArguments[i] instanceof String) {
String constant = (String) bootstrapMethodArguments[i];
Optional<String> transformed = transformLdc(constant);
if (transformed.isPresent() && !transformed.get().equals(constant)) {
ctx.markModified();
bootstrapMethodArguments[i] = transformed.get();
}
}
}
super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
}
};
Expand Down
54 changes: 27 additions & 27 deletions src/main/java/xyz/zuoyx/multiyggdrasil/util/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@

public final class JsonUtils {

private static final Gson gson = new Gson();
private static final Gson gson = new Gson();

public static JsonElement parseJson(String jsonText) {
return JsonParser.parseString(jsonText);
}
public static JsonElement parseJson(String jsonText) {
return JsonParser.parseString(jsonText);
}

public static String toJsonString(Object json) {
return gson.toJson(json);
}
public static String toJsonString(Object json) {
return gson.toJson(json);
}

public static String asJsonString(JsonElement json) {
return json.getAsJsonPrimitive().getAsString();
}
public static boolean asBoolean(JsonElement json) {
if (json != null) {
return json.getAsJsonPrimitive().getAsBoolean();
} else {
return false;
}
}
public static String asJsonString(JsonElement json) {
return json.getAsJsonPrimitive().getAsString();
}
public static boolean asBoolean(JsonElement json) {
if (json != null) {
return json.getAsJsonPrimitive().getAsBoolean();
} else {
return false;
}
}

public static List<JsonElement> toJavaList(JsonArray json) {
Type listType = new TypeToken<List<JsonElement>>(){}.getType();
return gson.fromJson(json, listType);
}
public static List<JsonElement> toJavaList(JsonArray json) {
Type listType = new TypeToken<List<JsonElement>>(){}.getType();
return gson.fromJson(json, listType);
}

public static Map<String, JsonElement> toJavaMap(JsonObject json) {
Type mapType = new TypeToken<Map<String, JsonElement>>(){}.getType();
return gson.fromJson(json, mapType);
}
public static Map<String, JsonElement> toJavaMap(JsonObject json) {
Type mapType = new TypeToken<Map<String, JsonElement>>(){}.getType();
return gson.fromJson(json, mapType);
}

private JsonUtils() {}
private JsonUtils() {}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,22 @@
*/
package xyz.zuoyx.multiyggdrasil.util;

import java.io.Serial;

public class UnsupportedURLException extends Exception {
@Serial
private static final long serialVersionUID = 7895188952767140345L;

public UnsupportedURLException() {
this(null, null);
super();
}

public UnsupportedURLException(String message) {
this(message, null);
super(message);
}

public UnsupportedURLException(String message, Throwable cause) {
super(message, cause, false, false);
super(message, cause);
}

public UnsupportedURLException(Throwable cause) {
this(null, cause);
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public String toString() {

@Override
public boolean equals(Object obj) {
if (obj instanceof NamespacedID other) {
if (obj instanceof NamespacedID) {
NamespacedID other = (NamespacedID) obj;
return this.namespace.equals(other.namespace) && this.id.equals(other.id);
}
return false;
Expand Down