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 Apr 15, 2017
2 parents 604f6a7 + 9b8d7a5 commit 5871f78
Show file tree
Hide file tree
Showing 121 changed files with 1,392 additions and 628 deletions.
8 changes: 8 additions & 0 deletions app-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
43 changes: 26 additions & 17 deletions app-core/src/main/java/com/mercury/platform/core/AppStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
import com.mercury.platform.core.update.UpdateClientStarter;
import com.mercury.platform.core.utils.error.ErrorHandler;
import com.mercury.platform.shared.ConfigManager;
import com.mercury.platform.shared.FrameStates;
import com.mercury.platform.shared.FrameVisibleState;
import com.mercury.platform.shared.HistoryManager;
import com.mercury.platform.shared.UpdateManager;
import com.mercury.platform.shared.config.BaseConfigManager;
import com.mercury.platform.shared.config.Configuration;
import com.mercury.platform.shared.config.MercuryDataSource;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.*;
import com.mercury.platform.shared.store.MercuryStore;
import com.sun.jna.Native;
import com.sun.jna.PointerType;
import com.sun.jna.platform.win32.WinDef;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -19,18 +24,20 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
* Created by Константин on 31.12.2016.
*/
public class AppStarter {
private static final Logger logger = LogManager.getLogger(AppStarter.class.getSimpleName());
public static FrameStates APP_STATUS = FrameStates.HIDE;
public static FrameVisibleState APP_STATUS = FrameVisibleState.HIDE;
public static WinDef.HWND poeWindow;
private User32 user32 = User32.INSTANCE;
private boolean shutdown = false;
private volatile int delay = 100;
private boolean updating = false;

public void startApplication(){
BaseConfigManager configuration = new BaseConfigManager(new MercuryDataSource());
configuration.load();
Configuration.set(configuration);

ConfigManager.INSTANCE.load();
new SoundNotifier();
new ChatHelper();
Expand All @@ -40,8 +47,9 @@ public void startApplication(){
UpdateClientStarter updateClientStarter = new UpdateClientStarter();
executor.execute(updateClientStarter);
HistoryManager.INSTANCE.load();
UpdateManager updateManager = new UpdateManager();

EventRouter.CORE.registerHandler(UILoadedEvent.class, event -> {
MercuryStore.INSTANCE.uiLoadedSubject.subscribe(state -> {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
Expand All @@ -50,27 +58,28 @@ public void run() {
timer.cancel();
updateClientStarter.shutdown();
if(updating){
UpdateManager.INSTANCE.doUpdate();
updateManager.doUpdate();
}
System.exit(0);
}
byte[] windowText = new byte[512];
PointerType hwnd = user32.GetForegroundWindow();
User32.INSTANCE.GetWindowTextA(hwnd, windowText, 512);
if(!Native.toString(windowText).equals("Path of Exile")){
if(APP_STATUS == FrameStates.SHOW) {
APP_STATUS = FrameStates.HIDE;
EventRouter.CORE.fireEvent(new ChangeFrameVisibleEvent(FrameStates.HIDE));
byte[] className = new byte[512];
WinDef.HWND hwnd = user32.GetForegroundWindow();
User32.INSTANCE.GetClassNameA(hwnd, className, 512);
if(!Native.toString(className).equals("POEWindowClass")){
if(APP_STATUS == FrameVisibleState.SHOW) {
APP_STATUS = FrameVisibleState.HIDE;
MercuryStore.INSTANCE.frameVisibleSubject.onNext(FrameVisibleState.HIDE);
}
}else{
if(APP_STATUS == FrameStates.HIDE) {
poeWindow = hwnd;
if(APP_STATUS == FrameVisibleState.HIDE) {
try {
Thread.sleep(delay);
delay = 100;
} catch (InterruptedException e) {
}
APP_STATUS = FrameStates.SHOW;
EventRouter.CORE.fireEvent(new ChangeFrameVisibleEvent(FrameStates.SHOW));
APP_STATUS = FrameVisibleState.SHOW;
MercuryStore.INSTANCE.frameVisibleSubject.onNext(FrameVisibleState.SHOW);
}
}
}
Expand Down
50 changes: 5 additions & 45 deletions app-core/src/main/java/com/mercury/platform/core/ChatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@

import com.mercury.platform.shared.ConfigManager;
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.DndModeEvent;
import com.mercury.platform.shared.events.custom.OpenChatEvent;
import com.sun.jna.Native;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.mercury.platform.shared.store.MercuryStore;

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;

public class ChatHelper implements HasEventHandlers {
private final Logger logger = LogManager.getLogger(ChatHelper.class.getSimpleName());
private User32 user32 = User32.INSTANCE;
private Robot robot;

public ChatHelper() {
Expand All @@ -36,8 +26,6 @@ private void executeMessage(String message) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, null);

gameToFront();

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

Expand All @@ -57,8 +45,6 @@ private void executeMessage(String message) {
robot.keyRelease(KeyEvent.VK_ENTER);
}
private void openChat(String whisper) {
gameToFront();

StringSelection selection = new StringSelection("@" + whisper);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
Expand All @@ -81,40 +67,14 @@ private void openChat(String whisper) {
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
}
/**
* NEED REFACTORING
*/
private void gameToFront(){
List<String> titles = new ArrayList<>();
titles.add("Path of Exile");
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 (titles.contains(wText)) {
user32.SetForegroundWindow(hWnd);
return false;
}
return true;
}, null);
}

@Override
public void initHandlers() {
EventRouter.CORE.registerHandler(ChatCommandEvent.class, event
-> executeMessage(((ChatCommandEvent)event).getMessage()));

EventRouter.CORE.registerHandler(OpenChatEvent.class, event -> {
openChat(((OpenChatEvent) event).getWhisper());
});
EventRouter.CORE.registerHandler(DndModeEvent.class, event -> {
boolean dnd = ((DndModeEvent) event).isDnd();
MercuryStore.INSTANCE.chatCommandSubject.subscribe(this::executeMessage);
MercuryStore.INSTANCE.openChatSubject.subscribe(this::openChat);
MercuryStore.INSTANCE.dndSubject.subscribe(state -> {
if(ConfigManager.INSTANCE.isInGameDnd()){
if(dnd) {
if(state) {
executeMessage("/dnd " + ConfigManager.INSTANCE.getDndResponseText());
}else {
executeMessage("/dnd");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mercury.platform.core;

public class MercuryConstants {
public static final String APP_VERSION = "1.0.1.2";
public static final String APP_VERSION = "1.0.1.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 @@ -14,6 +14,7 @@
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg);
int GetClassNameA(WinDef.HWND hwnd, byte[] lpString,int nMaxCount);
WinDef.HWND SetFocus(WinDef.HWND hWnd);
int GetWindowTextA(WinDef.HWND hWnd, byte[] lpString, int nMaxCount);
int GetWindowTextA(PointerType hWnd, byte[] lpString, int nMaxCount);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,41 @@
package com.mercury.platform.core.misc;

import com.mercury.platform.core.AppStarter;
import com.mercury.platform.shared.ConfigManager;
import com.mercury.platform.shared.FrameStates;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.*;
import com.mercury.platform.shared.store.DataTransformers;
import com.mercury.platform.shared.store.MercuryStore;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
import java.util.Random;

public class SoundNotifier {
private final Logger logger = LogManager.getLogger(SoundNotifier.class);
private boolean dnd = false;
public SoundNotifier() {
EventRouter.CORE.registerHandler(WhisperNotificationEvent.class, event -> {
WhisperNotifierStatus status = ConfigManager.INSTANCE.getWhisperNotifier();
if (status == WhisperNotifierStatus.ALWAYS ||
((status == WhisperNotifierStatus.ALTAB) && (AppStarter.APP_STATUS == FrameStates.HIDE))) {
play("app/notification.wav");
}
});
EventRouter.CORE.registerHandler(UpdateInfoEvent.class, event -> {
play("app/patch_tone.wav");
});
EventRouter.CORE.registerHandler(ChatFilterMessageEvent.class, event -> {
play("app/chat-filter.wav");
});
EventRouter.CORE.registerHandler(DndModeEvent.class, event -> {
this.dnd = ((DndModeEvent)event).isDnd();
});
EventRouter.CORE.registerHandler(ButtonPressedEvent.class, event -> {
String[] clicks = {
"app/sounds/click1/button-pressed-10.wav",
"app/sounds/click1/button-pressed-20.wav",
"app/sounds/click1/button-pressed-30.wav"};
play(clicks[new Random().nextInt(3)]);
});
MercuryStore.INSTANCE.soundSubject
.compose(DataTransformers.transformSoundData())
.subscribe(data -> play(data.getWavPath(), data.getDb()));
MercuryStore.INSTANCE.soundSettingsSubject
.subscribe(data -> play(data.getWavPath(), data.getDb()));
MercuryStore.INSTANCE.dndSubject
.subscribe(value -> this.dnd = value);
}

private void play(String wavPath){
if(!dnd) {
private void play(String wavPath, float db){
if(!dnd && db > -40) {
ClassLoader classLoader = getClass().getClassLoader();
try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
Clip clip = AudioSystem.getClip();
clip.open(stream);
FloatControl gainControl =
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(-5.0f);
if(db != 0.0) {
FloatControl gainControl =
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(db);
}
clip.start();
} catch (Exception e) {
logger.error("Cannot start playing wav file: ",e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mercury.platform.core.misc;


public enum SoundType {
MESSAGE,UPDATE,CHAT_SCANNER,CLICKS
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.mercury.platform.core.update.core.handlers;

import com.mercury.platform.core.misc.SoundType;
import com.mercury.platform.core.update.core.holder.ApplicationHolder;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.AlertEvent;
import com.mercury.platform.shared.events.custom.ShowPatchNotesEvent;
import com.mercury.platform.shared.events.custom.UpdateInfoEvent;
import com.mercury.platform.shared.store.MercuryStore;
import com.mercury.platform.update.AlreadyLatestUpdateMessage;
import com.mercury.platform.update.PatchNotesDescriptor;
import com.mercury.platform.update.UpdateDescriptor;
Expand All @@ -19,8 +21,8 @@ public void process(Object object){
EventRouter.CORE.fireEvent(new ShowPatchNotesEvent(notes));
}
if(object instanceof UpdateDescriptor){
int nextVersion = ((UpdateDescriptor) object).getVersion();
EventRouter.CORE.fireEvent(new UpdateInfoEvent(nextVersion));
MercuryStore.INSTANCE.soundSubject.onNext(SoundType.UPDATE);
EventRouter.CORE.fireEvent(new UpdateInfoEvent(((UpdateDescriptor) object).getVersion()));
}
if(object instanceof AlreadyLatestUpdateMessage){
if(ApplicationHolder.getInstance().isManualRequest()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mercury.platform.shared.HasEventHandlers;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.*;
import com.mercury.platform.shared.store.MercuryStore;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -81,12 +82,12 @@ public void parse() {

@Override
public void initHandlers() {
EventRouter.CORE.registerHandler(AddInterceptorEvent.class, event -> {
interceptors.add(((AddInterceptorEvent) event).getInterceptor());
MercuryStore.INSTANCE.addInterceptorSubject.subscribe(interceptor -> {
interceptors.add(interceptor);
lastMessageDate = new Date();
});
EventRouter.CORE.registerHandler(RemoveInterceptorEvent.class, event -> {
interceptors.remove(((RemoveInterceptorEvent) event).getInterceptor());
MercuryStore.INSTANCE.removeInterceptorSubject.subscribe(interceptor -> {
interceptors.remove(interceptor);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mercury.platform.core.utils.error;

import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.HideLoadingFrame;
import com.mercury.platform.shared.store.MercuryStore;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -10,7 +9,7 @@ public class ErrorHandler {
private Logger logger = LogManager.getLogger(ErrorHandler.class.getSimpleName());
public ErrorHandler(){
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
EventRouter.CORE.fireEvent(new HideLoadingFrame());
MercuryStore.INSTANCE.appLoadingSubject.onNext(false);
logger.error(ExceptionUtils.getStackTrace(throwable));
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package com.mercury.platform.core.utils.interceptor;

import com.mercury.platform.core.misc.SoundType;
import com.mercury.platform.core.utils.interceptor.filter.MessageFilter;
import com.mercury.platform.shared.MessageParser;
import com.mercury.platform.shared.events.EventRouter;
import com.mercury.platform.shared.events.custom.NewWhispersEvent;
import com.mercury.platform.shared.events.custom.WhisperNotificationEvent;
import com.mercury.platform.shared.pojo.Message;
import com.mercury.platform.shared.entity.Message;
import com.mercury.platform.shared.store.MercuryStore;
import org.apache.commons.lang3.StringUtils;

/**
* Created by Константин on 11.01.2017.
*/
public class IncTradeMessagesInterceptor extends MessageInterceptor {
private MessageParser messageParser = new MessageParser();

@Override
protected void process(String message) {
Message parsedMessage = messageParser.parse(StringUtils.substringAfter(message,"@"));
if(parsedMessage != null) {
EventRouter.CORE.fireEvent(new WhisperNotificationEvent());
EventRouter.CORE.fireEvent(new NewWhispersEvent(parsedMessage));
MercuryStore.INSTANCE.soundSubject.onNext(SoundType.MESSAGE);
MercuryStore.INSTANCE.messageSubject.onNext(parsedMessage);
}
}

Expand Down
Loading

0 comments on commit 5871f78

Please sign in to comment.