Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.17 should work #12

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ https://github.com/Devan-Kerman/GrossFabricHacks/wiki
```groovy
repositories {
maven {
url = 'https://raw.githubusercontent.com/Devan-Kerman/Devan-Repo/master/'
url = 'https://maven.concern.i.ng'
}
}

dependencies {
modImplementation group: 'net.devtech', name: 'grossfabrichacks', version: '6.1'
modImplementation group: 'net.devtech', name: 'grossfabrichacks', version: '8.0'
}
```
23 changes: 13 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
plugins {
id "fabric-loom" version "0.5-SNAPSHOT"
id "fabric-loom" version "0.9-SNAPSHOT"
id "maven-publish"
id "maven"
// id "maven"
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

repositories {
maven {url = "https://dl.bintray.com/user11681/maven"}
maven {url = "https://auoeke.jfrog.io/artifactory/maven"}
}

dependencies {
Expand All @@ -32,9 +32,9 @@ dependencies {
// implementation(include("net.java.dev.jna:jna:5.3.1"))
// implementation(include("net.java.dev.jna:jna-platform:5.3.1"))

modImplementation(include("user11681:dynamicentry:0.0.2"))
include(implementation("user11681:reflect:0.2.0"))
include(implementation("net.gudenau.lib:unsafe:1.2.14"))
modImplementation(include("user11681:dynamic-entry:+"))
include(implementation("user11681:reflect:latest.integration"))
include(implementation("net.gudenau.lib:unsafe:latest.integration"))
}

processResources {
Expand All @@ -43,18 +43,21 @@ processResources {
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
duplicatesStrategy DuplicatesStrategy.EXCLUDE
}

from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
duplicatesStrategy DuplicatesStrategy.EXCLUDE
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 16
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.2
yarn_mappings=1.16.2+build.43
loader_version=+
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.61
loader_version=0.11.7
# Mod Properties
mod_version=6.1
mod_version=8.0
maven_group=net.devtech
archives_base_name=grossfabrichacks
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-6.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 4 additions & 0 deletions src/main/java/ModLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// suggest to Knot that it needs to enable compatibility mode

public final class ModLoader {
}
41 changes: 41 additions & 0 deletions src/main/java/jdk/internal/reflect/ConstructorAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.internal.reflect;

import java.lang.reflect.InvocationTargetException;

/** This interface provides the declaration for
java.lang.reflect.Constructor.invoke(). Each Constructor object is
configured with a (possibly dynamically-generated) class which
implements this interface. */

public interface ConstructorAccessor {
/** Matches specification in {@link java.lang.reflect.Constructor} */
public Object newInstance(Object[] args)
throws InstantiationException,
IllegalArgumentException,
InvocationTargetException;
}
29 changes: 16 additions & 13 deletions src/main/java/net/devtech/grossfabrichacks/GrossFabricHacks.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package net.devtech.grossfabrichacks;

import java.io.InputStream;
import net.devtech.grossfabrichacks.entrypoints.PrePrePreLaunch;
import net.devtech.grossfabrichacks.instrumentation.InstrumentationApi;
import net.devtech.grossfabrichacks.transformer.asm.AsmClassTransformer;
import net.devtech.grossfabrichacks.transformer.asm.RawClassTransformer;
import net.devtech.grossfabrichacks.unsafe.UnsafeUtil;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.LanguageAdapter;
import net.fabricmc.loader.launch.knot.UnsafeKnotClassLoader;
import net.fabricmc.loader.impl.FabricLoaderImpl;
import net.fabricmc.loader.impl.launch.knot.UnsafeKnotClassLoader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import user11681.dynamicentry.DynamicEntry;
import user11681.reflect.Reflect;

import java.io.InputStream;

public class GrossFabricHacks implements LanguageAdapter {
private static final Logger LOGGER = LogManager.getLogger("GrossFabricHacks");
Expand Down Expand Up @@ -44,10 +44,10 @@ private static void loadSimpleMethodHandle() {
}
}
} catch (final Throwable throwable) {
throw new RuntimeException(throwable);
throw Rethrower.rethrow(throwable);
}
}
*/
*/

public static class State {
public static boolean mixinLoaded;
Expand All @@ -66,6 +66,10 @@ public static class State {
}

static {
if (!FabricLoaderImpl.INSTANCE.getGameProvider().requiresUrlClassLoader()) {
throw new RuntimeException("Unable to init GFH! Add `-Dfabric.loader.useCompatibilityClassLoader=true` to your JVM args and relaunch.");
}

LOGGER.info("no good? no, this man is definitely up to evil.");

try {
Expand All @@ -86,20 +90,19 @@ public static class State {
for (int i = FabricLoader.getInstance().isDevelopmentEnvironment() ? 1 : 0; i < classCount; i++) {
final String name = classes[i];
final InputStream classStream = KnotClassLoader.getResourceAsStream(name.replace('.', '/') + ".class");
final byte[] bytecode = new byte[classStream.available()];

while (classStream.read(bytecode) != -1) {}
final byte[] bytecode = classStream.readAllBytes();

Reflect.defineClass(applicationClassLoader, name, bytecode, GrossFabricHacks.class.getProtectionDomain());
UnsafeUtil.defineClass(name, bytecode, applicationClassLoader, GrossFabricHacks.class.getProtectionDomain());
}

LOGGER.warn("KnotClassLoader, you fool! Loading me was a grave mistake.");

UNSAFE_LOADER = UnsafeUtil.defineAndInitializeAndUnsafeCast(KnotClassLoader, "net.fabricmc.loader.launch.knot.UnsafeKnotClassLoader", KnotClassLoader.getClass().getClassLoader());
UNSAFE_LOADER = UnsafeUtil.defineAndInitializeAndUnsafeCast(KnotClassLoader, "net.fabricmc.loader.impl.launch.knot.UnsafeKnotClassLoader", KnotClassLoader.getClass().getClassLoader());
} catch (final Throwable throwable) {
throw new RuntimeException(throwable);
throw Rethrower.rethrow(throwable);
}

DynamicEntry.executeOptionalEntrypoint("gfh:prePrePreLaunch", PrePrePreLaunch.class, PrePrePreLaunch::onPrePrePreLaunch);
// shh i had to because dynamicentry changed :tiny_potato:
DynamicEntry.execute("gfh:prePrePreLaunch", PrePrePreLaunch.class, PrePrePreLaunch::onPrePrePreLaunch);
}
}
8 changes: 8 additions & 0 deletions src/main/java/net/devtech/grossfabrichacks/Rethrower.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.devtech.grossfabrichacks;

@SuppressWarnings("unchecked")
public class Rethrower {
public static <T extends Throwable> T rethrow(Throwable t) throws T {
throw (T) t;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
package net.devtech.grossfabrichacks.instrumentation;

import java.io.File;
import java.io.FileOutputStream;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.devtech.grossfabrichacks.GrossFabricHacks;
import net.devtech.grossfabrichacks.Rethrower;
import net.devtech.grossfabrichacks.transformer.TransformerApi;
import net.devtech.grossfabrichacks.transformer.asm.AsmClassTransformer;
import net.devtech.grossfabrichacks.transformer.asm.RawClassTransformer;
Expand All @@ -20,6 +13,15 @@
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;

import java.io.File;
import java.io.FileOutputStream;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;

public class InstrumentationApi {
private static final Set<String> TRANSFORMABLE = new HashSet<>();
private static final Logger LOGGER = LogManager.getLogger("GrossFabricHacks/InstrumentationApi");
Expand Down Expand Up @@ -52,7 +54,7 @@ public static void retransform(final String cls, final AsmClassTransformer trans
try {
retransform(Class.forName(cls), transformer);
} catch (final ClassNotFoundException exception) {
throw new RuntimeException(exception);
throw Rethrower.rethrow(exception);
}
}

Expand All @@ -73,7 +75,7 @@ public static void retransform(final String cls, final RawClassTransformer trans
try {
retransform(Class.forName(cls), transformer);
} catch (final ClassNotFoundException exception) {
throw new RuntimeException(exception);
throw Rethrower.rethrow(exception);
}
}

Expand All @@ -98,11 +100,11 @@ public static void retransform(Class<?> cls, RawClassTransformer transformer) {
instrumentation.retransformClasses(cls);
instrumentation.removeTransformer(fileTransformer);
} catch (UnmodifiableClassException e) {
throw new RuntimeException(e);
throw Rethrower.rethrow(e);
}
}

// to seperate out the static block
// to separate out the static block
private static class Transformable {
private static boolean init;
private static final CompatibilityClassFileTransformer TRANSFORMER = (loader, className, classBeingRedefined, protectionDomain, classfileBuffer) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
package net.devtech.grossfabrichacks.jarboot;

import net.devtech.grossfabrichacks.Rethrower;
import net.fabricmc.loader.impl.launch.knot.UnsafeKnotClassLoader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import net.fabricmc.loader.launch.knot.UnsafeKnotClassLoader;

public class JarBooter {
private static final Method ADD_URL;

/**
* Add a URL to the KnotClassLoader, the KnotClassLoader first checks it's URLs before asking parent classloaders for classes,
* Add a URL to the KnotClassLoader, the KnotClassLoader first checks its URLs before asking pub_parent classloaders for classes,
* this allows you to replace library classes, and mix into them (that'll take some creativity on your part until a better api is made)
*/
public static void addUrl(final URL url) {
try {
ADD_URL.invoke(UnsafeKnotClassLoader.parent, url);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
throw Rethrower.rethrow(e);
}
}

static {
try {
ADD_URL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
throw Rethrower.rethrow(throwable);
}
}
}
Loading