Skip to content

Commit

Permalink
Fix various compat issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Oct 21, 2024
1 parent 7864435 commit a5c491d
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/core/src/main/kotlin/org/polyfrost/spice/api/Mouse.kt
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)
}
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
})
}
}
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)
}
8 changes: 8 additions & 0 deletions modules/lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -31,4 +35,5 @@ interface IMouse {
fun setGrabbed(grabbed: Boolean)

fun setCursorPosition(x: Int, y: Int)
fun isInsideWindow(): Boolean
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
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);
}
}
2 changes: 2 additions & 0 deletions versions/src/main/resources/spice.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down

0 comments on commit a5c491d

Please sign in to comment.