de.florianmichael.asmfabricloader.loader.bootstrap.AFLLanguageAdapter Maven / Gradle / Ivy
/*
* This file is part of AsmFabricLoader - https://github.com/FlorianMichael/AsmFabricLoader
* Copyright (C) 2023-2024 FlorianMichael/EnZaXD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.florianmichael.asmfabricloader.loader.bootstrap;
import de.florianmichael.asmfabricloader.AsmFabricLoader;
import de.florianmichael.asmfabricloader.api.AsmUtil;
import de.florianmichael.asmfabricloader.loader.classloading.AFLConstants;
import net.fabricmc.loader.api.LanguageAdapter;
import net.fabricmc.loader.api.LanguageAdapterException;
import net.fabricmc.loader.api.ModContainer;
public class AFLLanguageAdapter implements LanguageAdapter {
@Override
public native T create(ModContainer mod, String value, Class type) throws LanguageAdapterException;
// Forces the fabric.debug.disableClassPathIsolation system property to be true which disables the classpath isolation
// This is needed because we need to access classes loaded in the system classloader
private static void unlockSystemClassloader() {
try {
final Class> knotClassDelegate = Class.forName("net.fabricmc.loader.impl.launch.knot.KnotClassDelegate");
final long offset = AsmUtil.getTheUnsafe().staticFieldOffset(knotClassDelegate.getDeclaredField("DISABLE_ISOLATION"));
AsmUtil.getTheUnsafe().putBoolean(knotClassDelegate, offset, true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static {
unlockSystemClassloader();
AsmFabricLoader.install();
}
}