This repository has been archived by the owner on Oct 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from mtricht/vulcan_fix
Workaround for vulcan renderer
- Loading branch information
Showing
7 changed files
with
230 additions
and
5 deletions.
There are no files selected for viewing
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
74 changes: 74 additions & 0 deletions
74
src/main/java/dev/tricht/lunaris/util/platform/windows/VulkanFullscreenFixer.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,74 @@ | ||
package dev.tricht.lunaris.util.platform.windows | ||
|
||
import com.sun.jna.platform.win32.User32 | ||
import java.util.function.Consumer | ||
|
||
|
||
class VulkanFullscreenFixer { | ||
|
||
companion object { | ||
var isPoEActive = false; | ||
lateinit var focusListener: WindowFocusListener; | ||
|
||
fun fixFullscreen() { | ||
val focusConsumer = Consumer<String> { windowTitle: String? -> | ||
if (!windowTitle.equals("Path of Exile")) { | ||
println(windowTitle) | ||
isPoEActive = false; | ||
} else if (windowTitle.equals("Path of Exile") && !isPoEActive) { | ||
isPoEActive = true; | ||
this.changeGameWindowProperties() | ||
} | ||
} | ||
focusListener = WindowFocusListener(focusConsumer) | ||
this.changeGameWindowProperties() | ||
} | ||
|
||
fun changeGameWindowProperties() { | ||
var hWnd = User32.INSTANCE.FindWindow(null, "Path of Exile"); | ||
if (hWnd != null) { | ||
val GWL_STYLE = -16 | ||
val WS_BORDER = 0x00800000 | ||
val WS_DLGFRAME = 0x00400000 | ||
val WS_CAPTION = WS_BORDER or WS_DLGFRAME | ||
|
||
var style = User32.INSTANCE.GetWindowLong(hWnd, GWL_STYLE); | ||
if(style == (style and WS_CAPTION.inv())) { | ||
return; | ||
} | ||
|
||
Thread.sleep(1000); | ||
|
||
User32.INSTANCE.SetWindowLong(hWnd, GWL_STYLE, style and WS_CAPTION.inv()); | ||
|
||
User32.INSTANCE.SetForegroundWindow(hWnd); | ||
|
||
val KEY_LWIN = 0x5BL; | ||
val KEY_UP_ARROW = 0x26L; | ||
val KEY_DOWN_ARROW = 0x28L; | ||
WindowsKeyboard.sendKeyDown(KEY_LWIN); | ||
|
||
WindowsKeyboard.sendKeyDown(KEY_UP_ARROW); | ||
WindowsKeyboard.sendKeyUp(KEY_UP_ARROW); | ||
|
||
Thread.sleep(250); | ||
|
||
WindowsKeyboard.sendKeyDown(KEY_DOWN_ARROW); | ||
WindowsKeyboard.sendKeyUp(KEY_DOWN_ARROW); | ||
|
||
Thread.sleep(250); | ||
|
||
WindowsKeyboard.sendKeyDown(KEY_UP_ARROW); | ||
WindowsKeyboard.sendKeyUp(KEY_UP_ARROW); | ||
|
||
WindowsKeyboard.sendKeyUp(KEY_LWIN); | ||
} | ||
} | ||
|
||
fun removeHook() { | ||
if (this::focusListener.isInitialized) { | ||
focusListener.destroy() | ||
}; | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/dev/tricht/lunaris/util/platform/windows/WindowFocusListener.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,64 @@ | ||
package dev.tricht.lunaris.util.platform.windows | ||
|
||
import com.sun.jna.Native | ||
import com.sun.jna.platform.win32.User32 | ||
import com.sun.jna.platform.win32.WinDef.* | ||
import com.sun.jna.platform.win32.WinNT.HANDLE | ||
import com.sun.jna.platform.win32.WinUser.MSG | ||
import com.sun.jna.platform.win32.WinUser.WinEventProc | ||
import java.util.function.Consumer | ||
|
||
class WindowFocusListener(private val callback: Consumer<String>) { | ||
private var winHookThread: Thread? = null | ||
private var winHookRunning = false | ||
private var winHook: HANDLE? = null | ||
|
||
private var EVENT_SYSTEM_FOREGROUND = 0x0003 | ||
private val WINEVENT_SKIPOWNPROCESS = 0x0002 | ||
|
||
private fun initWinHook() { | ||
|
||
val testproc = WinEventProc { _: HANDLE?, _: DWORD?, _: HWND?, _: LONG?, _: LONG?, _: DWORD?, _: DWORD? -> | ||
val buf = CharArray(1024 * 2) | ||
User32.INSTANCE.GetWindowText(User32.INSTANCE.GetForegroundWindow(), buf, 1024) | ||
callback.accept(Native.toString(buf)) | ||
} | ||
winHookThread = Thread(Runnable { | ||
winHook = User32.INSTANCE.SetWinEventHook( | ||
EVENT_SYSTEM_FOREGROUND, | ||
EVENT_SYSTEM_FOREGROUND, | ||
null, testproc, 0, 0, | ||
WINEVENT_SKIPOWNPROCESS) | ||
winHookRunning = true | ||
val msg = MSG() | ||
while (winHookRunning) { | ||
while (User32.INSTANCE.PeekMessage(msg, null, 0, 0, 0)) { | ||
User32.INSTANCE.TranslateMessage(msg) | ||
User32.INSTANCE.DispatchMessage(msg) | ||
} | ||
try { | ||
Thread.sleep(50) | ||
} catch (e: InterruptedException) { | ||
} | ||
} | ||
}, "Lunaris hook thread") | ||
winHookThread!!.priority = Thread.MIN_PRIORITY | ||
winHookThread!!.start() | ||
} | ||
|
||
fun destroy() { | ||
winHookRunning = false | ||
try { | ||
winHookThread!!.join(500) | ||
} catch (ex: InterruptedException) { | ||
System.err.println("joining error: $ex") | ||
} | ||
if (winHook != null) { | ||
User32.INSTANCE.UnhookWinEvent(winHook) | ||
} | ||
} | ||
|
||
init { | ||
initWinHook() | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/dev/tricht/lunaris/util/platform/windows/WindowsKeyboard.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,39 @@ | ||
package dev.tricht.lunaris.util.platform.windows | ||
|
||
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTR | ||
import com.sun.jna.platform.win32.User32 | ||
import com.sun.jna.platform.win32.WinDef.DWORD | ||
import com.sun.jna.platform.win32.WinDef.WORD | ||
import com.sun.jna.platform.win32.WinUser.INPUT | ||
|
||
|
||
class WindowsKeyboard { | ||
companion object { | ||
private val KEY_DOWN = 0L; | ||
private val KEY_UP = 2L; | ||
|
||
fun sendKeyDown(c: Long) { | ||
val input = INPUT() | ||
input.type = DWORD(INPUT.INPUT_KEYBOARD.toLong()) | ||
input.input.setType("ki") | ||
input.input.ki.wScan = WORD(0) | ||
input.input.ki.time = DWORD(0) | ||
input.input.ki.dwExtraInfo = ULONG_PTR(0) | ||
input.input.ki.wVk = WORD(c) | ||
input.input.ki.dwFlags = DWORD(KEY_DOWN) | ||
User32.INSTANCE.SendInput(DWORD(1), input.toArray(1) as Array<INPUT?>, input.size()) | ||
} | ||
|
||
fun sendKeyUp(c: Long) { | ||
val input = INPUT() | ||
input.type = DWORD(INPUT.INPUT_KEYBOARD.toLong()) | ||
input.input.setType("ki") | ||
input.input.ki.wScan = WORD(0) | ||
input.input.ki.time = DWORD(0) | ||
input.input.ki.dwExtraInfo = ULONG_PTR(0) | ||
input.input.ki.wVk = WORD(c) | ||
input.input.ki.dwFlags = DWORD(KEY_UP) | ||
User32.INSTANCE.SendInput(DWORD(1), input.toArray(1) as Array<INPUT?>, input.size()) | ||
} | ||
} | ||
} |
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