Skip to content

Commit

Permalink
Resolve matching variable ordinals for injectors
Browse files Browse the repository at this point in the history
Fixes #297
  • Loading branch information
Su5eD committed Jan 20, 2024
1 parent b38ba19 commit 1af76eb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.daemon=true
# Versions
versionConnector=1.0.0-beta.33
versionAdapter=1.9.0-1.20.1-20231215.155717
versionAdapterDefinition=1.10.4
versionAdapterDefinition=1.10.5

versionMc=1.20.1
versionForge=47.1.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService;
import dev.su5ed.sinytra.connector.loader.ConnectorEarlyLoader;
import dev.su5ed.sinytra.connector.service.hacks.ConnectorForkJoinThreadFactory;
import dev.su5ed.sinytra.connector.service.hacks.LenientRuntimeEnumExtender;
import dev.su5ed.sinytra.connector.service.hacks.ModuleLayerMigrator;
import net.minecraftforge.fml.loading.ImmediateWindowHandler;
import net.minecraftforge.fml.loading.ImmediateWindowProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.su5ed.sinytra.connector.service;
package dev.su5ed.sinytra.connector.service.hacks;

import net.minecraftforge.fml.common.asm.RuntimeEnumExtender;
import org.objectweb.asm.Opcodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public class MixinPatchTransformer implements Transformer {
.targetInjectionPoint("Lnet/fabricmc/loader/impl/game/minecraft/Hooks;startServer(Ljava/io/File;Ljava/lang/Object;)V")
.modifyInjectionPoint("Lnet/minecraftforge/server/loading/ServerModLoader;load()V")
.build(),
Patch.builder()
.targetClass("net/minecraft/client/KeyMapping")
.targetMethod("set")
.targetInjectionPoint("TAIL", "")
.modifyTarget("connector_onSetKeyMapping")
.build(),
Patch.builder()
.targetClass("net/minecraft/world/item/enchantment/EnchantmentHelper")
.targetMethod("m_44817_")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.su5ed.sinytra.connector.mod.mixin.client;

import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;
import net.minecraftforge.client.settings.KeyMappingLookup;
Expand All @@ -10,6 +11,9 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -28,6 +32,19 @@ public class KeyMappingMixin {
@Shadow(remap = false, aliases = "f_90810_")
private static final Map<InputConstants.Key, KeyMapping> vanillaKeyMapping;

private static final ThreadLocal<KeyMapping> KEY_MAPPING_LOCAL = new ThreadLocal<>();

@Inject(method = "set", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/KeyMapping;setDown(Z)V"))
private static void onSetKeyMapping(InputConstants.Key pKey, boolean pHeld, CallbackInfo ci, @Local KeyMapping keyMapping) {
KEY_MAPPING_LOCAL.set(keyMapping);
connector_onSetKeyMapping(pKey, pHeld);
KEY_MAPPING_LOCAL.remove();
}

private static void connector_onSetKeyMapping(InputConstants.Key pKey, boolean pHeld) {
KeyMapping keyMapping = KEY_MAPPING_LOCAL.get();
}

static {
// Forge changes the signature of f_90810_ (MAP) so, as such, some mods may encounter issues
// if they use the field in their code or otherwise reflect (see voxelmap)
Expand Down

0 comments on commit 1af76eb

Please sign in to comment.