diff --git a/modules/core/src/main/kotlin/org/polyfrost/spice/api/Mouse.kt b/modules/core/src/main/kotlin/org/polyfrost/spice/api/Mouse.kt index 4cbe157..cd73a95 100644 --- a/modules/core/src/main/kotlin/org/polyfrost/spice/api/Mouse.kt +++ b/modules/core/src/main/kotlin/org/polyfrost/spice/api/Mouse.kt @@ -1,5 +1,6 @@ package org.polyfrost.spice.api +import org.lwjgl.input.Mouse import org.lwjglx.input.RawInput object Mouse { @@ -7,4 +8,12 @@ object Mouse { 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) } diff --git a/modules/core/src/main/kotlin/org/polyfrost/spice/patcher/lwjgl/EssentialGlobalMouseOverrideTransformer.kt b/modules/core/src/main/kotlin/org/polyfrost/spice/patcher/lwjgl/EssentialGlobalMouseOverrideTransformer.kt new file mode 100644 index 0000000..af40c41 --- /dev/null +++ b/modules/core/src/main/kotlin/org/polyfrost/spice/patcher/lwjgl/EssentialGlobalMouseOverrideTransformer.kt @@ -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 == "" + }!! as MethodNode + clinit.instructions.clear() + clinit.instructions.add(asm { + new("gg/essential/gui/overlay/OverlayManagerImpl\$GlobalMouseOverride") + dup + invokespecial( + "gg/essential/gui/overlay/OverlayManagerImpl\$GlobalMouseOverride", + "", + "()V" + ) + putstatic( + "gg/essential/gui/overlay/OverlayManagerImpl\$GlobalMouseOverride", + "INSTANCE", + "Lgg/essential/gui/overlay/OverlayManagerImpl\$GlobalMouseOverride;" + ) + _return + }) + } +} diff --git a/modules/core/src/main/kotlin/org/polyfrost/spice/platform/TransformerBootstrap.kt b/modules/core/src/main/kotlin/org/polyfrost/spice/platform/TransformerBootstrap.kt index 15a7f90..f3466ec 100644 --- a/modules/core/src/main/kotlin/org/polyfrost/spice/platform/TransformerBootstrap.kt +++ b/modules/core/src/main/kotlin/org/polyfrost/spice/platform/TransformerBootstrap.kt @@ -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) } diff --git a/modules/lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt index a99c7e8..e0d5463 100644 --- a/modules/lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt +++ b/modules/lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt @@ -19,6 +19,8 @@ object Mouse { @JvmStatic fun getX(): Int = implementation.getX() @JvmStatic fun getY(): Int = implementation.getY() + @JvmStatic fun setX(x: Int) = implementation.setX(x) + @JvmStatic fun setY(y: Int) = implementation.setY(y) @JvmStatic fun getDX(): Int = implementation.getDX() @JvmStatic fun getDY(): Int = implementation.getDY() @JvmStatic fun getDWheel(): Int = implementation.getDWheel() @@ -30,6 +32,8 @@ object Mouse { @JvmStatic fun getEventDY(): Int = implementation.getEventDY() @JvmStatic fun getEventX(): Int = implementation.getEventX() @JvmStatic fun getEventY(): Int = implementation.getEventY() + @JvmStatic fun setEventX(x: Int) = implementation.setEventX(x) + @JvmStatic fun setEventY(y: Int) = implementation.setEventY(y) @JvmStatic fun getEventNanoseconds(): Long = implementation.getEventNanoseconds() @JvmStatic fun next(): Boolean = implementation.next() @@ -40,8 +44,12 @@ object Mouse { @JvmStatic fun getButtonName(button: Int): String = implementation.getButtonName(button) @JvmStatic fun isButtonDown(button: Int): Boolean = implementation.isButtonDown(button) + @JvmStatic fun hasWheel(): Boolean = true + @JvmStatic fun isGrabbed(): Boolean = implementation.isGrabbed() @JvmStatic fun setGrabbed(grabbed: Boolean) = implementation.setGrabbed(grabbed) @JvmStatic fun setCursorPosition(x: Int, y: Int) = implementation.setCursorPosition(x, y) + + @JvmStatic fun isInsideWindow(): Boolean = implementation.isInsideWindow() } \ No newline at end of file diff --git a/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/api/input/Mouse.kt b/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/api/input/Mouse.kt index bcd08ef..c869857 100644 --- a/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/api/input/Mouse.kt +++ b/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/api/input/Mouse.kt @@ -5,6 +5,8 @@ interface IMouse { fun getX(): Int fun getY(): Int + fun setX(x: Int) + fun setY(y: Int) fun getDX(): Int fun getDY(): Int @@ -17,6 +19,8 @@ interface IMouse { fun getEventDY(): Int fun getEventX(): Int fun getEventY(): Int + fun setEventX(x: Int) + fun setEventY(y: Int) fun getEventNanoseconds(): Long fun next(): Boolean @@ -31,4 +35,5 @@ interface IMouse { fun setGrabbed(grabbed: Boolean) fun setCursorPosition(x: Int, y: Int) + fun isInsideWindow(): Boolean } diff --git a/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/impl/input/Mouse.kt b/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/impl/input/Mouse.kt index d842ea7..8e26bc4 100644 --- a/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/impl/input/Mouse.kt +++ b/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/impl/input/Mouse.kt @@ -1,6 +1,7 @@ package org.polyfrost.lwjgl.impl.input import org.lwjgl.glfw.GLFW.* +import org.lwjgl.opengl.Display import org.lwjgl.system.MemoryStack import org.lwjglx.input.RawInput import org.polyfrost.lwjgl.api.input.IMouse @@ -59,6 +60,12 @@ class MouseImpl(private val window: GLFWwindow, private val display: IDisplay) : override fun getX(): Int = x override fun getY(): Int = display.getHeight() - y + override fun setX(x: Int) { + this.x = x + } + override fun setY(y: Int) { + this.y = display.getHeight() - y + } override fun getDX(): Int = xDelta.toInt() override fun getDY(): Int = yDelta.toInt() override fun getDWheel(): Int = scrollDelta @@ -70,6 +77,12 @@ class MouseImpl(private val window: GLFWwindow, private val display: IDisplay) : override fun getEventDY(): Int = currentEvent?.yDelta ?: 0 override fun getEventX(): Int = currentEvent?.x ?: 0 override fun getEventY(): Int = currentEvent?.y ?: 0 + override fun setEventX(x: Int) { + currentEvent?.x = x + } + override fun setEventY(y: Int) { + currentEvent?.y = y + } override fun getEventNanoseconds(): Long = currentEvent?.timestamp ?: 0 override fun next(): Boolean { @@ -113,6 +126,8 @@ class MouseImpl(private val window: GLFWwindow, private val display: IDisplay) : this.y = y } + override fun isInsideWindow() = Display.isVisible() + @Suppress("UNUSED_PARAMETER") private fun mouseButtonHandler(window: Long, button: Int, action: Int, mods: Int) { buttonStates[button] = action == GLFW_PRESS diff --git a/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/platform/common/opengl/GlfwContext.kt b/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/platform/common/opengl/GlfwContext.kt index 0ace8b1..3434056 100644 --- a/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/platform/common/opengl/GlfwContext.kt +++ b/modules/lwjgl/src/main/kotlin/org/polyfrost/lwjgl/platform/common/opengl/GlfwContext.kt @@ -93,6 +93,8 @@ class GlfwContext(private val window: GLFWwindow, private val attribs: ContextAt glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, attribs.getMajorVersion()) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, attribs.getMinorVersion()) + + glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE) } } } diff --git a/versions/src/main/java/org/polyfrost/spice/mixin/lwjgl3/compat/EssentialGlobalMouseOverrideMixin.java b/versions/src/main/java/org/polyfrost/spice/mixin/lwjgl3/compat/EssentialGlobalMouseOverrideMixin.java new file mode 100644 index 0000000..5dcec2e --- /dev/null +++ b/versions/src/main/java/org/polyfrost/spice/mixin/lwjgl3/compat/EssentialGlobalMouseOverrideMixin.java @@ -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); + } +} diff --git a/versions/src/main/resources/spice.mixins.json b/versions/src/main/resources/spice.mixins.json index e136692..94cd780 100644 --- a/versions/src/main/resources/spice.mixins.json +++ b/versions/src/main/resources/spice.mixins.json @@ -3,8 +3,10 @@ "minVersion": "0.7", "package": "org.polyfrost.spice.mixin", "compatibilityLevel": "JAVA_8", + "verbose": true, "client": [ "common.MinecraftMixin", + "lwjgl3.compat.EssentialGlobalMouseOverrideMixin", "lwjgl3.GuiControlsMixin", "lwjgl3.MinecraftMixin" ],