-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
modules/core/src/main/kotlin/org/polyfrost/spice/api/Mouse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
package org.polyfrost.spice.api | ||
|
||
import org.lwjgl.input.Mouse | ||
import org.lwjglx.input.RawInput | ||
|
||
object Mouse { | ||
@JvmStatic | ||
fun isRawInputSupported(): Boolean = RawInput.isRawInputSupported() | ||
@JvmStatic | ||
fun setRawInput(raw: Boolean) = RawInput.useRawInput(raw) | ||
@JvmStatic | ||
fun setX(x: Int) = Mouse.setX(x) | ||
@JvmStatic | ||
fun setY(y: Int) = Mouse.setY(y) | ||
@JvmStatic | ||
fun setEventX(x: Int) = Mouse.setEventX(x) | ||
@JvmStatic | ||
fun setEventY(y: Int) = Mouse.setEventY(y) | ||
} |
33 changes: 33 additions & 0 deletions
33
.../main/kotlin/org/polyfrost/spice/patcher/lwjgl/EssentialGlobalMouseOverrideTransformer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.polyfrost.spice.patcher.lwjgl | ||
|
||
import net.weavemc.loader.api.util.asm | ||
import org.objectweb.asm.tree.ClassNode | ||
import org.objectweb.asm.tree.MethodNode | ||
import org.polyfrost.spice.platform.api.IClassTransformer | ||
|
||
object EssentialGlobalMouseOverrideTransformer : IClassTransformer { | ||
override val targets = arrayOf("gg.essential.gui.overlay.OverlayManagerImpl\$GlobalMouseOverride") | ||
|
||
override fun transform(node: ClassNode) { | ||
val clinit = node.methods.find { method -> | ||
method as MethodNode | ||
method.name == "<clinit>" | ||
}!! as MethodNode | ||
clinit.instructions.clear() | ||
clinit.instructions.add(asm { | ||
new("gg/essential/gui/overlay/OverlayManagerImpl\$GlobalMouseOverride") | ||
dup | ||
invokespecial( | ||
"gg/essential/gui/overlay/OverlayManagerImpl\$GlobalMouseOverride", | ||
"<init>", | ||
"()V" | ||
) | ||
putstatic( | ||
"gg/essential/gui/overlay/OverlayManagerImpl\$GlobalMouseOverride", | ||
"INSTANCE", | ||
"Lgg/essential/gui/overlay/OverlayManagerImpl\$GlobalMouseOverride;" | ||
) | ||
_return | ||
}) | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
modules/core/src/main/kotlin/org/polyfrost/spice/platform/TransformerBootstrap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package org.polyfrost.spice.platform | ||
|
||
import org.polyfrost.spice.patcher.lwjgl.EssentialGlobalMouseOverrideTransformer | ||
import org.polyfrost.spice.patcher.lwjgl.LwjglTransformer | ||
import org.polyfrost.spice.platform.api.Transformer | ||
|
||
fun bootstrapTransformer(transformer: Transformer) { | ||
transformer.appendToClassPath(LwjglTransformer.provider.url) | ||
transformer.addTransformer(EssentialGlobalMouseOverrideTransformer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
.../main/java/org/polyfrost/spice/mixin/lwjgl3/compat/EssentialGlobalMouseOverrideMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.polyfrost.spice.mixin.lwjgl3.compat; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import org.polyfrost.spice.api.Mouse; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
|
||
@Pseudo | ||
@Mixin(targets = "gg.essential.gui.overlay.OverlayManagerImpl$GlobalMouseOverride", remap = false) | ||
public class EssentialGlobalMouseOverrideMixin { | ||
/** | ||
* @author Wyvest | ||
* @reason Fix silly Essential reflection | ||
*/ | ||
@Overwrite | ||
public final void set(double mouseX, double mouseY) { | ||
int trueX = (int)mouseX; | ||
int trueY = Minecraft.getMinecraft().displayHeight - (int)mouseY - 1; | ||
Mouse.setX(trueX); | ||
Mouse.setY(trueY); | ||
Mouse.setEventX(trueX); | ||
Mouse.setEventY(trueY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters