Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into master-local
Browse files Browse the repository at this point in the history
  • Loading branch information
Exslims committed Mar 9, 2017
2 parents ce14b03 + 4657966 commit 5bac846
Show file tree
Hide file tree
Showing 81 changed files with 1,886 additions and 722 deletions.
5 changes: 5 additions & 0 deletions app-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@


<dependencies>
<dependency>
<groupId>com.home.mercury</groupId>
<artifactId>app-shared</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>lc.kra.system</groupId>
<artifactId>system-hook</artifactId>
Expand Down
22 changes: 15 additions & 7 deletions app-core/src/main/java/com/mercury/platform/core/AppStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import com.mercury.platform.shared.ConfigManager;
import com.mercury.platform.shared.FrameStates;
import com.mercury.platform.shared.HistoryManager;
import com.mercury.platform.shared.UpdateManager;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.AddShowDelayEvent;
import com.mercury.platform.shared.events.custom.ChangeFrameVisibleEvent;
import com.mercury.platform.shared.events.custom.ShutdownApplication;
import com.mercury.platform.shared.events.custom.UILoadedEvent;
import com.mercury.platform.shared.events.custom.*;
import com.sun.jna.Native;
import com.sun.jna.PointerType;
import org.apache.logging.log4j.LogManager;
Expand All @@ -30,16 +28,18 @@ public class AppStarter {
private static final Logger logger = LogManager.getLogger(AppStarter.class.getSimpleName());
public static FrameStates APP_STATUS = FrameStates.HIDE;
private User32 user32 = User32.INSTANCE;
private volatile int delay = 100;
private boolean shutdown = false;
private volatile int delay = 100;
private boolean updating = false;

public void startApplication(){
ConfigManager.INSTANCE.load();
new SoundNotifier();
new ChatHelper();

Executor executor = Executors.newSingleThreadExecutor();
executor.execute(new UpdateClientStarter());
ConfigManager.INSTANCE.load();
UpdateClientStarter updateClientStarter = new UpdateClientStarter();
executor.execute(updateClientStarter);
HistoryManager.INSTANCE.load();

EventRouter.INSTANCE.registerHandler(UILoadedEvent.class, event -> {
Expand All @@ -49,6 +49,10 @@ public void startApplication(){
public void run() {
if(shutdown){
timer.cancel();
updateClientStarter.shutdown();
if(updating){
UpdateManager.INSTANCE.doUpdate();
}
System.exit(0);
}
byte[] windowText = new byte[512];
Expand Down Expand Up @@ -79,5 +83,9 @@ public void run() {
EventRouter.INSTANCE.registerHandler(ShutdownApplication.class, event -> {
shutdown = true;
});
EventRouter.INSTANCE.registerHandler(ShutDownForUpdateEvent.class, event -> {
shutdown = true;
updating = true;
});
}
}
170 changes: 56 additions & 114 deletions app-core/src/main/java/com/mercury/platform/core/ChatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,25 @@
import com.mercury.platform.shared.HasEventHandlers;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.ChatCommandEvent;
import com.mercury.platform.shared.events.custom.CopyToClipboardEvent;
import com.mercury.platform.shared.events.custom.OpenChatEvent;
import com.mercury.platform.shared.events.custom.SetForegroundGameEvent;
import com.sun.jna.Native;
import lc.kra.system.keyboard.GlobalKeyboardHook;
import lc.kra.system.keyboard.event.GlobalKeyAdapter;
import lc.kra.system.keyboard.event.GlobalKeyEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.*;
import java.util.List;

/**
* Exslims
* 07.12.2016
*/
public class ChatHelper implements HasEventHandlers {
// private GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook();
// private GlobalKeyAdapter adapter;
private final Logger logger = LogManager.getLogger(ChatHelper.class.getSimpleName());
private User32 user32 = User32.INSTANCE;
private Robot robot;

public ChatHelper() {
// GlobalKeyAdapter adapter = getAdapter();
// this.adapter = adapter;
initHandlers();
// keyboardHook.addKeyListener(adapter);
try {
robot = new Robot();
} catch (AWTException e) {
Expand All @@ -39,121 +30,81 @@ public ChatHelper() {
}

private void executeMessage(String message) {
// keyboardHook.removeKeyListener(adapter);
StringSelection selection = new StringSelection(message);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, null);

setForegroundWindow("Path of Exile");
new Thread(() -> {
StringSelection selection = new StringSelection(message);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, null);

robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
gameToFront();

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

robot.keyPress(KeyEvent.VK_BACK_SPACE);
robot.keyRelease(KeyEvent.VK_BACK_SPACE);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_A);

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_BACK_SPACE);
robot.keyRelease(KeyEvent.VK_BACK_SPACE);

// keyboardHook.addKeyListener(adapter);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}).start();
}
private void openChat(String whisper){
// keyboardHook.removeKeyListener(adapter);
setForegroundWindow("Path of Exile");

StringSelection selection = new StringSelection("@" + whisper);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);

robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_A);

robot.keyPress(KeyEvent.VK_BACK_SPACE);
robot.keyRelease(KeyEvent.VK_BACK_SPACE);

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);

// keyboardHook.addKeyListener(adapter);
}
new Thread(() -> {
gameToFront();


private GlobalKeyAdapter getAdapter(){
return new GlobalKeyAdapter() {
@Override
public void keyPressed(GlobalKeyEvent event) {
switch (event.getVirtualKeyCode()){
case GlobalKeyEvent.VK_F2: {
// EventRouter.fireEvent(new StateChangeEvent(FrameStates.SHOW));
}
break;
case GlobalKeyEvent.VK_F3: {
// EventRouter.fireEvent(new StateChangeEvent(FrameStates.UNDEFINED));
}
break;
case GlobalKeyEvent.VK_TAB: {
// if(!altPressed) {
// nextTab();
// }
}
break;
case GlobalKeyEvent.VK_2:{
useAllFlasks();
}
break;
}
}
};
StringSelection selection = new StringSelection("@" + whisper);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);

robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_A);

robot.keyPress(KeyEvent.VK_BACK_SPACE);
robot.keyRelease(KeyEvent.VK_BACK_SPACE);

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
}).start();
}

public void setForegroundWindow(final String titleName){
user32.EnumWindows((hWnd, arg1) -> {
private void gameToFront(){
List<String> titles = new ArrayList<>();
titles.add("Path of Exile");
titles.add("PathOfExile");
titles.add("PathOfExile_64");
user32.EnumWindows((hWnd, arg1) -> {
byte[] windowText = new byte[512];
user32.GetWindowTextA(hWnd, windowText, 512);
String wText = Native.toString(windowText);

if (wText.isEmpty()) {
return true;
}
if (wText.equals(titleName)) {
if (titles.contains(wText)) {
user32.SetForegroundWindow(hWnd);
return false;
}
return true;
}, null);
}

private void nextTab(){
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);
}
private void useAllFlasks(){
robot.keyPress(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_3);
robot.keyPress(KeyEvent.VK_4);
robot.keyRelease(KeyEvent.VK_4);
robot.keyPress(KeyEvent.VK_5);
robot.keyRelease(KeyEvent.VK_5);
}

@Override
public void initHandlers() {
EventRouter.INSTANCE.registerHandler(ChatCommandEvent.class, event
Expand All @@ -162,14 +113,5 @@ public void initHandlers() {
EventRouter.INSTANCE.registerHandler(OpenChatEvent.class, event -> {
openChat(((OpenChatEvent) event).getWhisper());
});
EventRouter.INSTANCE.registerHandler(CopyToClipboardEvent.class, event -> {
String content = ((CopyToClipboardEvent) event).getContent();
StringSelection selection = new StringSelection(content);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, null);
});
EventRouter.INSTANCE.registerHandler(SetForegroundGameEvent.class, event -> {
setForegroundWindow("Path of Exile");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* Created by Константин on 29.01.2017.
*/
public class MercuryConstants {
public static final String APP_VERSION = "1.0.0.0";

public static final String APP_VERSION = "1.0.0.3";
public static final String SERVER_HOST = "exslims.ddns.net";
public static final int PORT = 5555;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SoundNotifier() {
play("app/notification.wav");
}
});
EventRouter.INSTANCE.registerHandler(UpdateReadyEvent.class, event -> {
EventRouter.INSTANCE.registerHandler(UpdateInfoEvent.class, event -> {
play("app/patch_tone.wav");
});
EventRouter.INSTANCE.registerHandler(ChatFilterMessageEvent.class, event -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@


import com.mercury.platform.core.MercuryConstants;
import com.mercury.platform.core.update.bus.event.UpdateReceivedEvent;
import com.mercury.platform.core.update.bus.handlers.UpdateEventHandler;
import com.mercury.platform.core.update.core.UpdaterClient;
import com.mercury.platform.core.update.core.holder.VersionHolder;
import com.mercury.platform.shared.ConfigManager;
import com.mercury.platform.core.update.core.holder.ApplicationHolder;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.UpdateReadyEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
Expand All @@ -24,14 +20,14 @@ public class UpdateClientStarter implements Runnable{
private static final Logger LOGGER = LogManager.getLogger(UpdateClientStarter.class.getSimpleName());
private static final String JARS_FILE_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\temp";

private UpdaterClient updaterClient;

@Override
public void run() {
UpdaterClient updaterClient = new UpdaterClient(MercuryConstants.SERVER_HOST, MercuryConstants.APP_VERSION, MercuryConstants.PORT);
updaterClient = new UpdaterClient(MercuryConstants.SERVER_HOST, MercuryConstants.APP_VERSION, MercuryConstants.PORT);
updaterClient.registerListener(handler -> {
LOGGER.info("update received, size = {} bytes" , handler.getBytes().length);
Files.write(Paths.get(JARS_FILE_PATH + "\\MercuryTrade.jar") , handler.getBytes() , StandardOpenOption.CREATE);
setMercuryVersion(getIncrementedVersion(MercuryConstants.APP_VERSION));
ConfigManager.INSTANCE.setShowPatchNotes(true);
EventRouter.INSTANCE.fireEvent(new UpdateReadyEvent());
});
try {
Expand All @@ -42,13 +38,16 @@ public void run() {
}
public synchronized void setMercuryVersion(String mercuryVersion) {
String version = mercuryVersion.replace(".", "0");
VersionHolder versionHolder = VersionHolder.getInstance();
versionHolder.setVersion(Integer.valueOf(version));
ApplicationHolder applicationHolder = ApplicationHolder.getInstance();
applicationHolder.setVersion(Integer.valueOf(version));
}
private String getIncrementedVersion(String version){
String replace = version.replace(".", "0");
Integer intVersion = Integer.valueOf(replace);
intVersion++;
return String.valueOf(intVersion).replace("0",".");
}
public void shutdown(){
updaterClient.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ protected void initChannel(SocketChannel socketChannel) throws Exception {
socketChannel.pipeline().addLast(new ObjectDecoder(classResolver));
socketChannel.pipeline().addLast(new ClientHandler());
}

}
Loading

0 comments on commit 5bac846

Please sign in to comment.