Skip to content

Commit

Permalink
Trigger <cinit> before unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Nov 22, 2023
1 parent 53538d2 commit 08ebc83
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ patch_version = 0

# MAJOR.SPEC_MAJOR.SPEC_MINOR.BUILD
last_forge_version = 14.23.5.2860
new_forge_version = 15.24.0.3010
new_forge_version = 15.24.0.3011

# Minecraft & Mappings
mapping_channel = stable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void apply()
}
try
{
field.get(is);
ReflectionHackery.unsafe.putObject(ReflectionHackery.unsafe.staticFieldBase(field), ReflectionHackery.unsafe.staticFieldOffset(field), is);
//field.set(null, is);
}
Expand Down
19 changes: 5 additions & 14 deletions src/main/java/net/minecraftforge/registries/ObjectHolderRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import java.util.Queue;

import com.cleanroommc.hackery.ReflectionHackery;
import jdk.internal.misc.Unsafe;
import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
import sun.misc.Unsafe;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -151,29 +151,20 @@ public void apply()
}
}

@SuppressWarnings("removal")
private static class FinalFieldHelper
{
private static final Unsafe unsafe;
static {
Field f;
try {
f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
unsafe = (Unsafe) f.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
private static final Unsafe unsafe=ReflectionHackery.unsafe;
static Field makeWritable(Field f) throws ReflectiveOperationException
{
f.setAccessible(true);
//ReflectionHackery.stripFieldOfFinalModifier(f);
ReflectionHackery.stripFieldOfFinalModifier(f);
return f;
}

static void setField(Field field, @Nullable Object instance, Object thing) throws ReflectiveOperationException
{
//field.set(instance, thing);
field.get(instance);
unsafe.putObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field), thing);
}
}
Expand Down

0 comments on commit 08ebc83

Please sign in to comment.