Skip to content

Commit

Permalink
more robust gtnhlib compat patch
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Dec 7, 2024
1 parent ca9819c commit 841098b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("fpgradle-minecraft") version ("0.8.2")
id("fpgradle-minecraft") version ("0.8.3")
}

group = "com.falsepattern"
Expand Down Expand Up @@ -68,6 +68,7 @@ repositories {
exclusive(mega(), "codechicken")
exclusive(ivy("https://files.vexatos.com/", "[module]/[artifact]-[revision].[ext]"), "vexatos")
exclusive(ivy("https://downloads.gtnewhorizons.com/", "[organisation]/[artifact]-[revision].[ext]"), "Mods_for_Twitch")
exclusive(maven("horizon", "https://mvn.falsepattern.com/horizon/"), "com.gtnewhorizons.retrofuturabootstrap")
}

dependencies {
Expand All @@ -79,6 +80,7 @@ dependencies {

compileOnly(deobf("optifine:optifine:1.7.10_hd_u_e7"))

compileOnly("com.gtnewhorizons.retrofuturabootstrap:RetroFuturaBootstrap:1.0.7")
compileOnly("com.github.GTNewHorizons:GTNHLib:0.5.21:api")

compileOnly("com.github.basdxz:Apparatus:2.12.3:dev") { excludeDeps() }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This file is part of FalseTweaks.
*
* Copyright (C) 2022-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalseTweaks is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FalseTweaks 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
*/

package com.falsepattern.falsetweaks.asm;

import lombok.val;

import net.minecraft.launchwrapper.IClassTransformer;

import java.util.List;

public class ASMFixerUtility {
public static void removeGTNHLibHook(List<IClassTransformer> transformers) {
val iter = transformers.iterator();
while (iter.hasNext()) {
val transformer = (IClassTransformer) iter.next();
if (transformer.getClass().getName().equals("com.gtnewhorizon.gtnhlib.core.transformer.TessellatorRedirectorTransformer")) {
iter.remove();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
@Getter
@Accessors(fluent = true)
public class FalseTweaksTransformer extends MergeableTurboTransformer {
static {
try {
RFBFixerUtility.removeGTNHLibHook();
} catch (Throwable ignored) {}
}
private static List<TurboClassTransformer> transformers() {
val transformers = new ArrayList<TurboClassTransformer>();
if (FMLLaunchHandler.side().isClient()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public String[] getLaunchArguments() {
val f = LaunchClassLoader.class.getDeclaredField("transformers");
f.setAccessible(true);
val transformers = (List<IClassTransformer>) f.get(Launch.classLoader);
try {
ASMFixerUtility.removeGTNHLibHook(transformers);
} catch (Throwable ignored) {}
transformers.add(CoreLoadingPlugin.FIELD_HACK_TF);
return new String[0];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This file is part of FalseTweaks.
*
* Copyright (C) 2022-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalseTweaks is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FalseTweaks 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
*/

package com.falsepattern.falsetweaks.asm;

import com.gtnewhorizons.retrofuturabootstrap.SharedConfig;
import com.gtnewhorizons.retrofuturabootstrap.api.RfbClassTransformerHandle;
import lombok.SneakyThrows;
import lombok.val;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;

public class RFBFixerUtility {
@SneakyThrows
public static void removeGTNHLibHook() {
val theField = SharedConfig.class.getDeclaredField("rfbTransformers");
theField.setAccessible(true);
val ref = (AtomicReference<RfbClassTransformerHandle[]>) theField.get(null);
val arr = new ArrayList<>(Arrays.asList(ref.get()));
val iter = arr.iterator();
while (iter.hasNext()) {
val elem = iter.next();
if (elem.id().equals("gtnhlib:redirector")) {
iter.remove();
}
}
ref.set(arr.toArray(new RfbClassTransformerHandle[0]));
}
}

0 comments on commit 841098b

Please sign in to comment.