Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #77 from mtricht/vulcan_fix
Browse files Browse the repository at this point in the history
Workaround for vulcan renderer
  • Loading branch information
mtricht authored Jun 11, 2020
2 parents bda8a4f + f45d7c3 commit 2d7e866
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Having trouble? [Open an issue](https://github.com/mtricht/lunaris/issues/new).

Linux users, see this [page](https://github.com/mtricht/lunaris/blob/master/LINUX.md).

## FAQ
### Lunaris is not working with the Vulkan renderer
First, change your display mode to windowed (no worries, you can still play fullscreen).
Then in the Lunaris options menu, tick "Vulcan fix". You should now be able to enjoy the features of Lunaris while playing fullscreen PoE.


## Boss screenshots
Are we missing a boss? You can help by making a screenshot of the boss in the maps you’re already running anyway, and filling it out in this form: https://forms.gle/tE9e6PshZ1QWutV48
We will make sure to credit everyone that has submitted a screenshot somewhere in the tool! Thanks in advance!
28 changes: 23 additions & 5 deletions src/main/java/dev/tricht/lunaris/Lunaris.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ import dev.tricht.lunaris.com.pathofexile.middleware.PseudoModsMiddleware
import dev.tricht.lunaris.com.pathofexile.middleware.TradeMiddleware
import dev.tricht.lunaris.info.poeprices.PoePricesAPI
import dev.tricht.lunaris.item.ItemGrabber
import dev.tricht.lunaris.listeners.*
import dev.tricht.lunaris.listeners.ListenerStack
import dev.tricht.lunaris.ninja.poe.PoeNinjaItemResolver
import dev.tricht.lunaris.util.ErrorUtil
import dev.tricht.lunaris.util.Properties
import dev.tricht.lunaris.util.SystemTray
import dev.tricht.lunaris.util.platform.windows.VulkanFullscreenFixer
import javafx.application.Platform
import dev.tricht.lunaris.util.Platform as LPlatform
import org.jnativehook.GlobalScreen
import org.slf4j.LoggerFactory

import javax.swing.*
import java.awt.*
import java.util.ArrayList
import java.awt.AWTException
import java.awt.Robot
import java.util.*
import java.util.logging.Level
import java.util.logging.Logger
import javax.swing.UIManager


class Lunaris private constructor() {

Expand Down Expand Up @@ -94,6 +97,11 @@ class Lunaris private constructor() {
pathOfExileAPI?.sessionId = Properties.getProperty(Properties.POESESSID)
}

setupVulcanFix()
Properties.addPropertyListener("general.vulcan_fix") {
setupVulcanFix()
}

ListenerStack().startListeners(itemGrabber, robot, pathOfExileAPI, poePricesAPI)

// For some reason the JavaFX thread will completely stop after closing
Expand All @@ -117,4 +125,14 @@ class Lunaris private constructor() {
}
ItemTransformer.setMiddleware(tradeMiddlewareArrayList)
}

private fun setupVulcanFix() {
if (LPlatform.isWindows) {
if (Properties.getProperty("general.vulcan_fix", "0") == "1") {
VulkanFullscreenFixer.fixFullscreen();
} else {
VulkanFullscreenFixer.removeHook();
}
}
}
}
22 changes: 22 additions & 0 deletions src/main/java/dev/tricht/lunaris/settings/general/GeneralGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import dev.tricht.lunaris.com.pathofexile.PathOfExileAPI;
import dev.tricht.lunaris.util.Properties;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;
import lombok.extern.slf4j.Slf4j;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

@Slf4j
Expand All @@ -20,6 +24,10 @@ public class GeneralGUI implements Initializable {
private TextField poesessid;
@FXML
private TextField characterName;
@FXML
private CheckBox vulcanFix;

private HashMap<CheckBox, String> propertyMap;

public GeneralGUI(){

Expand All @@ -40,5 +48,19 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
-> Properties.INSTANCE.writeProperty(Properties.CHARACTER_NAME, t1));
poesessid.textProperty().addListener((observableValue, s, t1)
-> Properties.INSTANCE.writeProperty(Properties.POESESSID, t1));

propertyMap = new HashMap<>();
propertyMap.put(vulcanFix, "general.vulcan_fix");
for (Map.Entry<CheckBox, String> entry :propertyMap.entrySet()) {
entry.getKey().setSelected(Properties.INSTANCE.getProperty(entry.getValue(), "0").equals("1"));
}
}

public void toggleCheckbox(ActionEvent actionEvent) {
CheckBox source = (CheckBox) actionEvent.getSource();
if (!propertyMap.containsKey(source)) {
return;
}
Properties.INSTANCE.writeProperty(propertyMap.get(source), source.isSelected() ? "1" : "0");
}
}
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()
};
}
}
}
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()
}
}
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())
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/settings/general/general.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label text="League" GridPane.columnIndex="0" GridPane.rowIndex="0" />
Expand All @@ -37,6 +38,7 @@
<TextField fx:id="poesessid" maxWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.vgrow="NEVER" />
<Label text="Character name" GridPane.columnIndex="0" GridPane.rowIndex="2" />
<TextField fx:id="characterName" maxWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.vgrow="NEVER" />
<CheckBox fx:id="vulcanFix" GridPane.columnSpan="2" mnemonicParsing="false" onAction="#toggleCheckbox" text="Fix overlay on Vulcan renderer (set display mode to windowed, Lunaris will make it fullscreen)" GridPane.rowIndex="3" />
</children>
</GridPane>
</children>
Expand Down

0 comments on commit 2d7e866

Please sign in to comment.