mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2025-01-19 08:36:27 +01:00
internal extensions
This commit is contained in:
parent
367f93ae86
commit
b7bf03f313
@ -1,113 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>BlockReplacePackets</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<version>0.0.1-beta</version>
|
||||
|
||||
<parent>
|
||||
<groupId>G-Earth</groupId>
|
||||
<artifactId>G-Earth-Parent</artifactId>
|
||||
<version>1.3.4</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<!-- Embedded FXML and CSS resources -->
|
||||
<resource>
|
||||
<filtering>false</filtering>
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.fxml</include>
|
||||
<include>**/*.css</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/bin</outputDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>extensions.blockreplacepackets.BlockAndReplacePackets</mainClass>
|
||||
<useUniqueVersions>false</useUniqueVersions>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
</manifest>
|
||||
</archive>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/bin</outputDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>extensions.blockreplacepackets.BlockAndReplacePackets</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- global build folder -->
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<target name="copy to extensions folder">
|
||||
<copy file="target/bin/BlockReplacePackets.jar" todir="../../Build/Linux/Extensions"/>
|
||||
<copy file="target/bin/BlockReplacePackets.jar" todir="../../Build/Mac/Extensions"/>
|
||||
<copy file="target/bin/BlockReplacePackets.jar" todir="../../Build/Windows_32bit/Extensions"/>
|
||||
<copy file="target/bin/BlockReplacePackets.jar" todir="../../Build/Windows_64bit/Extensions"/>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>G-Earth</groupId>
|
||||
<artifactId>G-Earth</artifactId>
|
||||
<version>1.3.4</version>
|
||||
<!--<scope>provided</scope>-->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,5 +1,9 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import gearth.extensions.ExtensionBase;
|
||||
import gearth.extensions.ExtensionInfo;
|
||||
import gearth.extensions.IExtension;
|
||||
import gearth.extensions.OnConnectionListener;
|
||||
import gearth.misc.listenerpattern.Observable;
|
||||
import gearth.misc.packet_info.PacketInfoManager;
|
||||
import gearth.protocol.HMessage;
|
||||
@ -18,17 +22,9 @@ import java.util.Map;
|
||||
/**
|
||||
* Created by Jonas on 23/06/18.
|
||||
*/
|
||||
public abstract class Extension implements IExtension {
|
||||
public abstract class Extension extends ExtensionBase {
|
||||
|
||||
public interface MessageListener {
|
||||
void act(HMessage message);
|
||||
}
|
||||
public interface FlagsCheckListener {
|
||||
void act(String[] args);
|
||||
}
|
||||
|
||||
protected boolean canLeave; // can you disconnect the ext
|
||||
protected boolean canDelete; // can you delete the ext (will be false for some built-in extensions)
|
||||
protected FlagsCheckListener flagRequestCallback = null;
|
||||
|
||||
private String[] args;
|
||||
private boolean isCorrupted = false;
|
||||
@ -39,9 +35,6 @@ public abstract class Extension implements IExtension {
|
||||
protected PacketInfoManager packetInfoManager = new PacketInfoManager(new ArrayList<>()); // empty
|
||||
|
||||
private OutputStream out = null;
|
||||
private final Map<Integer, List<MessageListener>> incomingMessageListeners = new HashMap<>();
|
||||
private final Map<Integer, List<MessageListener>> outgoingMessageListeners = new HashMap<>();
|
||||
private FlagsCheckListener flagRequestCallback = null;
|
||||
|
||||
private String getArgument(String[] args, String... arg) {
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
@ -59,8 +52,7 @@ public abstract class Extension implements IExtension {
|
||||
* @param args arguments
|
||||
*/
|
||||
public Extension(String[] args) {
|
||||
canLeave = canLeave();
|
||||
canDelete = canDelete();
|
||||
super();
|
||||
|
||||
//obtain port
|
||||
this.args = args;
|
||||
@ -136,8 +128,8 @@ public abstract class Extension implements IExtension {
|
||||
.appendBoolean(file != null)
|
||||
.appendString(file == null ? "": file)
|
||||
.appendString(cookie == null ? "" : cookie)
|
||||
.appendBoolean(canLeave)
|
||||
.appendBoolean(canDelete);
|
||||
.appendBoolean(canLeave())
|
||||
.appendBoolean(canDelete());
|
||||
writeToStream(response.toBytes());
|
||||
}
|
||||
else if (packet.headerId() == NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.CONNECTIONSTART) {
|
||||
@ -149,7 +141,7 @@ public abstract class Extension implements IExtension {
|
||||
packetInfoManager = PacketInfoManager.readFromPacket(packet);
|
||||
|
||||
Constants.UNITY_PACKETS = clientType == HClient.UNITY;
|
||||
onConnectionObservable.fireEvent(l -> l.onConnection(
|
||||
getOnConnectionObservable().fireEvent(l -> l.onConnection(
|
||||
host, connectionPort, hotelVersion,
|
||||
clientIdentifier, clientType, packetInfoManager)
|
||||
);
|
||||
@ -180,36 +172,8 @@ public abstract class Extension implements IExtension {
|
||||
else if (packet.headerId() == NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.PACKETINTERCEPT) {
|
||||
String stringifiedMessage = packet.readLongString();
|
||||
HMessage habboMessage = new HMessage(stringifiedMessage);
|
||||
HPacket habboPacket = habboMessage.getPacket();
|
||||
|
||||
Map<Integer, List<MessageListener>> listeners =
|
||||
habboMessage.getDestination() == HMessage.Direction.TOCLIENT ?
|
||||
incomingMessageListeners :
|
||||
outgoingMessageListeners;
|
||||
|
||||
List<MessageListener> correctListeners = new ArrayList<>();
|
||||
|
||||
synchronized (incomingMessageListeners) {
|
||||
synchronized (outgoingMessageListeners) {
|
||||
if (listeners.containsKey(-1)) { // registered on all packets
|
||||
for (int i = listeners.get(-1).size() - 1; i >= 0; i--) {
|
||||
correctListeners.add(listeners.get(-1).get(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (listeners.containsKey(habboPacket.headerId())) {
|
||||
for (int i = listeners.get(habboPacket.headerId()).size() - 1; i >= 0; i--) {
|
||||
correctListeners.add(listeners.get(habboPacket.headerId()).get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(MessageListener listener : correctListeners) {
|
||||
habboMessage.getPacket().resetReadIndex();
|
||||
listener.act(habboMessage);
|
||||
}
|
||||
habboMessage.getPacket().resetReadIndex();
|
||||
modifyMessage(habboMessage);
|
||||
|
||||
HPacket response = new HPacket(NetworkExtensionInfo.INCOMING_MESSAGES_IDS.MANIPULATEDPACKET);
|
||||
response.appendLongString(habboMessage.stringify());
|
||||
@ -275,37 +239,6 @@ public abstract class Extension implements IExtension {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a listener on a specific packet Type
|
||||
* @param direction ToClient or ToServer
|
||||
* @param headerId the packet header ID
|
||||
* @param messageListener the callback
|
||||
*/
|
||||
public void intercept(HMessage.Direction direction, int headerId, MessageListener messageListener) {
|
||||
Map<Integer, List<MessageListener>> listeners =
|
||||
direction == HMessage.Direction.TOCLIENT ?
|
||||
incomingMessageListeners :
|
||||
outgoingMessageListeners;
|
||||
|
||||
synchronized (listeners) {
|
||||
if (!listeners.containsKey(headerId)) {
|
||||
listeners.put(headerId, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
listeners.get(headerId).add(messageListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a listener on all packets
|
||||
* @param direction ToClient or ToServer
|
||||
* @param messageListener the callback
|
||||
*/
|
||||
public void intercept(HMessage.Direction direction, MessageListener messageListener) {
|
||||
intercept(direction, -1, messageListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the flags which have been given to G-Earth when it got executed
|
||||
* For example, you might want this extension to do a specific thing if the flag "-e" was given
|
||||
@ -324,15 +257,6 @@ public abstract class Extension implements IExtension {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write to the console in G-Earth
|
||||
* @param s the text to be written
|
||||
*/
|
||||
public void writeToConsole(String s) {
|
||||
writeToConsole("black", s, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to the console in G-Earth
|
||||
* @param s the text to be written
|
||||
@ -360,37 +284,12 @@ public abstract class Extension implements IExtension {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean isOnClickMethodUsed() {
|
||||
|
||||
Class<? extends Extension> c = getClass();
|
||||
|
||||
while (c != Extension.class) {
|
||||
try {
|
||||
c.getDeclaredMethod("onClick");
|
||||
// if it didnt error, onClick exists
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
c = (Class<? extends Extension>) c.getSuperclass();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called when a connection has been established with G-Earth.
|
||||
* This does not imply a connection with Habbo is setup.
|
||||
*/
|
||||
protected void initExtension(){}
|
||||
|
||||
/**
|
||||
* The application got doubleclicked from the G-Earth interface. Doing something here is optional
|
||||
*/
|
||||
protected void onClick(){}
|
||||
|
||||
/**
|
||||
* A connection with Habbo has been started
|
||||
*/
|
||||
@ -409,14 +308,4 @@ public abstract class Extension implements IExtension {
|
||||
return true;
|
||||
}
|
||||
|
||||
ExtensionInfo getInfoAnnotations() {
|
||||
return getClass().getAnnotation(ExtensionInfo.class);
|
||||
}
|
||||
|
||||
|
||||
private Observable<OnConnectionListener> onConnectionObservable = new Observable<>();
|
||||
public void onConnect(OnConnectionListener listener){
|
||||
onConnectionObservable.addListener(listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
130
G-Earth/src/main/java/gearth/extensions/ExtensionBase.java
Normal file
130
G-Earth/src/main/java/gearth/extensions/ExtensionBase.java
Normal file
@ -0,0 +1,130 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import gearth.misc.listenerpattern.Observable;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ExtensionBase extends IExtension {
|
||||
|
||||
public interface MessageListener {
|
||||
void act(HMessage message);
|
||||
}
|
||||
public interface FlagsCheckListener {
|
||||
void act(String[] args);
|
||||
}
|
||||
|
||||
protected final Map<Integer, List<MessageListener>> incomingMessageListeners = new HashMap<>();
|
||||
protected final Map<Integer, List<MessageListener>> outgoingMessageListeners = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Register a listener on a specific packet Type
|
||||
* @param direction ToClient or ToServer
|
||||
* @param headerId the packet header ID
|
||||
* @param messageListener the callback
|
||||
*/
|
||||
public void intercept(HMessage.Direction direction, int headerId, MessageListener messageListener) {
|
||||
Map<Integer, List<MessageListener>> listeners =
|
||||
direction == HMessage.Direction.TOCLIENT ?
|
||||
incomingMessageListeners :
|
||||
outgoingMessageListeners;
|
||||
|
||||
synchronized (listeners) {
|
||||
if (!listeners.containsKey(headerId)) {
|
||||
listeners.put(headerId, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
listeners.get(headerId).add(messageListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a listener on all packets
|
||||
* @param direction ToClient or ToServer
|
||||
* @param messageListener the callback
|
||||
*/
|
||||
public void intercept(HMessage.Direction direction, MessageListener messageListener) {
|
||||
intercept(direction, -1, messageListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToConsole(String s) {
|
||||
writeToConsole("black", s);
|
||||
}
|
||||
|
||||
protected boolean isOnClickMethodUsed() {
|
||||
Class<? extends ExtensionBase> c = getClass();
|
||||
while (c != Extension.class) {
|
||||
try {
|
||||
c.getDeclaredMethod("onClick");
|
||||
// if it didnt error, onClick exists
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
c = (Class<? extends ExtensionBase>) c.getSuperclass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void modifyMessage(HMessage habboMessage) {
|
||||
HPacket habboPacket = habboMessage.getPacket();
|
||||
|
||||
Map<Integer, List<MessageListener>> listeners =
|
||||
habboMessage.getDestination() == HMessage.Direction.TOCLIENT ?
|
||||
incomingMessageListeners :
|
||||
outgoingMessageListeners;
|
||||
|
||||
List<MessageListener> correctListeners = new ArrayList<>();
|
||||
|
||||
synchronized (incomingMessageListeners) {
|
||||
synchronized (outgoingMessageListeners) {
|
||||
if (listeners.containsKey(-1)) { // registered on all packets
|
||||
for (int i = listeners.get(-1).size() - 1; i >= 0; i--) {
|
||||
correctListeners.add(listeners.get(-1).get(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (listeners.containsKey(habboPacket.headerId())) {
|
||||
for (int i = listeners.get(habboPacket.headerId()).size() - 1; i >= 0; i--) {
|
||||
correctListeners.add(listeners.get(habboPacket.headerId()).get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(MessageListener listener : correctListeners) {
|
||||
habboMessage.getPacket().resetReadIndex();
|
||||
listener.act(habboMessage);
|
||||
}
|
||||
habboMessage.getPacket().resetReadIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* The application got doubleclicked from the G-Earth interface. Doing something here is optional
|
||||
*/
|
||||
@Override
|
||||
void onClick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExtensionInfo getInfoAnnotations() {
|
||||
return getClass().getAnnotation(ExtensionInfo.class);
|
||||
}
|
||||
|
||||
private Observable<OnConnectionListener> onConnectionObservable = new Observable<>();
|
||||
public void onConnect(OnConnectionListener listener){
|
||||
onConnectionObservable.addListener(listener);
|
||||
}
|
||||
|
||||
Observable<OnConnectionListener> getOnConnectionObservable() {
|
||||
return onConnectionObservable;
|
||||
}
|
||||
}
|
@ -8,9 +8,9 @@ import gearth.protocol.HPacket;
|
||||
/**
|
||||
* Created by Jonas on 22/09/18.
|
||||
*/
|
||||
public abstract class ExtensionForm implements IExtension {
|
||||
public abstract class ExtensionForm extends ExtensionBase {
|
||||
|
||||
volatile Extension extension;
|
||||
volatile ExtensionBase extension;
|
||||
protected volatile Stage primaryStage;
|
||||
|
||||
protected static void runExtensionForm(String[] args, Class<? extends ExtensionForm> extension) {
|
||||
@ -59,7 +59,7 @@ public abstract class ExtensionForm implements IExtension {
|
||||
/**
|
||||
* The application got doubleclicked from the G-Earth interface. Doing something here is optional
|
||||
*/
|
||||
protected void onClick(){
|
||||
public void onClick(){
|
||||
Platform.runLater(() -> {
|
||||
primaryStage.show();
|
||||
primaryStage.requestFocus();
|
||||
|
@ -5,7 +5,7 @@ import javafx.application.Platform;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
* Created by Jeunez on 6/11/2018.
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class ExtensionFormLauncher extends Application {
|
||||
|
||||
@ -19,7 +19,7 @@ public class ExtensionFormLauncher extends Application {
|
||||
ExtensionForm creator = extension.newInstance();
|
||||
ExtensionForm extensionForm = creator.launchForm(primaryStage);
|
||||
|
||||
extensionForm.extension = new Extension(args) {
|
||||
Extension extension = new Extension(args) {
|
||||
@Override
|
||||
protected void initExtension() {
|
||||
extensionForm.initExtension();
|
||||
@ -41,7 +41,7 @@ public class ExtensionFormLauncher extends Application {
|
||||
}
|
||||
|
||||
@Override
|
||||
ExtensionInfo getInfoAnnotations() {
|
||||
protected ExtensionInfo getInfoAnnotations() {
|
||||
return extInfo;
|
||||
}
|
||||
|
||||
@ -55,9 +55,11 @@ public class ExtensionFormLauncher extends Application {
|
||||
return extensionForm.canDelete();
|
||||
}
|
||||
};
|
||||
extensionForm.extension = extension;
|
||||
|
||||
extensionForm.primaryStage = primaryStage;
|
||||
Thread t = new Thread(() -> {
|
||||
extensionForm.extension.run();
|
||||
extension.run();
|
||||
//when the extension has ended, close this process
|
||||
System.exit(0);
|
||||
});
|
||||
|
@ -3,15 +3,22 @@ package gearth.extensions;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
public interface IExtension {
|
||||
public abstract class IExtension {
|
||||
|
||||
boolean sendToClient(HPacket packet);
|
||||
boolean sendToServer(HPacket packet);
|
||||
void intercept(HMessage.Direction direction, int headerId, Extension.MessageListener messageListener);
|
||||
void intercept(HMessage.Direction direction, Extension.MessageListener messageListener);
|
||||
boolean requestFlags(Extension.FlagsCheckListener flagRequestCallback);
|
||||
void writeToConsole(String colorClass, String s);
|
||||
void writeToConsole(String s);
|
||||
void onConnect(OnConnectionListener listener);
|
||||
public abstract boolean sendToClient(HPacket packet);
|
||||
public abstract boolean sendToServer(HPacket packet);
|
||||
public abstract void intercept(HMessage.Direction direction, int headerId, Extension.MessageListener messageListener);
|
||||
public abstract void intercept(HMessage.Direction direction, Extension.MessageListener messageListener);
|
||||
public abstract boolean requestFlags(Extension.FlagsCheckListener flagRequestCallback);
|
||||
public abstract void writeToConsole(String colorClass, String s);
|
||||
public abstract void writeToConsole(String s);
|
||||
public abstract void onConnect(OnConnectionListener listener);
|
||||
|
||||
abstract void initExtension();
|
||||
abstract void onClick();
|
||||
abstract void onStartConnection();
|
||||
abstract void onEndConnection();
|
||||
abstract ExtensionInfo getInfoAnnotations();
|
||||
abstract boolean canLeave();
|
||||
abstract boolean canDelete();
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.extensions.ExtensionBase;
|
||||
import gearth.extensions.IExtension;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
|
||||
public class InternalExtension extends ExtensionBase {
|
||||
|
||||
public interface InternalExtensionCommunicator {
|
||||
void sendToClient(HPacket packet);
|
||||
void sendToServer(HPacket packet);
|
||||
void writeToConsole(String s);
|
||||
}
|
||||
|
||||
private InternalExtensionCommunicator communicator = null;
|
||||
|
||||
public void setCommunicator(InternalExtensionCommunicator communicator) {
|
||||
this.communicator = communicator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendToClient(HPacket packet) {
|
||||
communicator.sendToClient(packet);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendToServer(HPacket packet) {
|
||||
communicator.sendToServer(packet);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestFlags(FlagsCheckListener flagRequestCallback) {
|
||||
flagRequestCallback.act(Main.args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToConsole(String colorClass, String s) {
|
||||
String text = "[" + colorClass + "]" + getInfoAnnotations().Title() + " --> " + s;
|
||||
communicator.writeToConsole(text);
|
||||
}
|
||||
|
||||
// to be maybe overwritten
|
||||
@Override
|
||||
protected void initExtension() { }
|
||||
|
||||
// to be maybe overwritten
|
||||
@Override
|
||||
protected void onStartConnection() {}
|
||||
|
||||
// to be maybe overwritten
|
||||
@Override
|
||||
protected void onEndConnection() {}
|
||||
|
||||
@Override
|
||||
protected boolean canLeave() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDelete() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package gearth.extensions;
|
||||
|
||||
|
||||
import gearth.misc.packet_info.PacketInfoManager;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.protocol.connection.HClient;
|
||||
import gearth.services.extensionhandler.extensions.GEarthExtension;
|
||||
|
||||
// wraps internal GEarthExtension class to IExtension interface
|
||||
// to allow internal extensions that follow the same remote-extensions interface
|
||||
public class InternalExtensionBuilder extends GEarthExtension {
|
||||
|
||||
private final InternalExtension extension;
|
||||
|
||||
public InternalExtensionBuilder(InternalExtension extension) {
|
||||
this.extension = extension;
|
||||
extension.setCommunicator(new InternalExtension.InternalExtensionCommunicator() {
|
||||
@Override
|
||||
public void sendToClient(HPacket packet) {
|
||||
sendMessage(HMessage.Direction.TOCLIENT, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToServer(HPacket packet) {
|
||||
sendMessage(HMessage.Direction.TOSERVER, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToConsole(String s) {
|
||||
log(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return extension.getInfoAnnotations().Author();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return extension.getInfoAnnotations().Description();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return extension.getInfoAnnotations().Title();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return extension.getInfoAnnotations().Version();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFireButtonUsed() {
|
||||
Class<? extends InternalExtension > c = extension.getClass();
|
||||
|
||||
while (c != InternalExtension.class) {
|
||||
try {
|
||||
c.getDeclaredMethod("onClick");
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
c = (Class<? extends InternalExtension>) c.getSuperclass();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeleteButtonVisible() {
|
||||
return extension.canDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaveButtonVisible() {
|
||||
return extension.canLeave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInstalledExtension() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doubleclick() {
|
||||
extension.onClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetIntercept(HMessage hMessage) {
|
||||
extension.modifyMessage(hMessage);
|
||||
sendManipulatedPacket(hMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideFlags(String[] flags) {
|
||||
// no need
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionStart(String host, int port, String hotelVersion, String clientIdentifier, HClient clientType, PacketInfoManager packetInfoManager) {
|
||||
extension.getOnConnectionObservable().fireEvent(l -> l.onConnection(
|
||||
host, port, hotelVersion,
|
||||
clientIdentifier, clientType, packetInfoManager)
|
||||
);
|
||||
extension.onStartConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionEnd() {
|
||||
extension.onEndConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
extension.initExtension();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// no need in internal ext
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetToStringResponse(String string, String expression) {
|
||||
// no need in java ext
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stringToPacketResponse(HPacket packet) {
|
||||
// no need in java ext
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package gearth.extensions;
|
||||
|
||||
import gearth.services.extensionhandler.extensions.GEarthExtension;
|
||||
import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducerObserver;
|
||||
import javafx.application.Platform;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class InternalExtensionFormBuilder {
|
||||
|
||||
public static void launch(Class<? extends ExtensionForm> extension, ExtensionProducerObserver observer) {
|
||||
try {
|
||||
ExtensionInfo extInfo = extension.getAnnotation(ExtensionInfo.class);
|
||||
ExtensionForm creator = extension.newInstance();
|
||||
|
||||
Stage stage = new Stage();
|
||||
ExtensionForm extensionForm = creator.launchForm(stage);
|
||||
|
||||
InternalExtension internalExtension = new InternalExtension() {
|
||||
@Override
|
||||
protected void initExtension() {
|
||||
extensionForm.initExtension();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
extensionForm.onClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartConnection() {
|
||||
extensionForm.onStartConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEndConnection() {
|
||||
extensionForm.onEndConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExtensionInfo getInfoAnnotations() {
|
||||
return extInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canLeave() {
|
||||
return extensionForm.canLeave();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDelete() {
|
||||
return extensionForm.canDelete();
|
||||
}
|
||||
};
|
||||
extensionForm.extension = internalExtension;
|
||||
extensionForm.primaryStage = stage;
|
||||
|
||||
GEarthExtension gEarthExtension = new InternalExtensionBuilder(internalExtension);
|
||||
observer.onExtensionProduced(gEarthExtension);
|
||||
|
||||
|
||||
Platform.setImplicitExit(false);
|
||||
|
||||
stage.setOnCloseRequest(event -> {
|
||||
event.consume();
|
||||
Platform.runLater(() -> {
|
||||
stage.hide();
|
||||
extensionForm.onHide();
|
||||
});
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,10 @@
|
||||
package gearth.extensions.extra.harble;
|
||||
package gearth.extensions.extra.tools;
|
||||
|
||||
import gearth.extensions.ExtensionInfo;
|
||||
import gearth.extensions.IExtension;
|
||||
import gearth.extensions.OnConnectionListener;
|
||||
import gearth.misc.listenerpattern.Observable;
|
||||
import gearth.misc.packet_info.PacketInfoManager;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.protocol.connection.HClient;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 3/12/2018.
|
@ -1,4 +1,4 @@
|
||||
package gearth.extensions.extra.harble;
|
||||
package gearth.extensions.extra.tools;
|
||||
|
||||
public interface ChatInputListener {
|
||||
void inputEntered(String input);
|
@ -1,13 +1,11 @@
|
||||
package gearth.extensions.extra.harble;
|
||||
package gearth.extensions.extra.tools;
|
||||
|
||||
import gearth.extensions.Extension;
|
||||
import gearth.extensions.IExtension;
|
||||
import gearth.extensions.OnConnectionListener;
|
||||
import gearth.misc.packet_info.PacketInfo;
|
||||
import gearth.misc.packet_info.PacketInfoManager;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.protocol.connection.HClient;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.*;
|
@ -15,7 +15,7 @@ import java.net.URISyntaxException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by Jeunez on 27/06/2018.
|
||||
* Created by Jonas on 27/06/2018.
|
||||
*/
|
||||
|
||||
public class WindowsHabboClient extends HabboClient {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package gearth.services.extensionhandler.extensions.implementations.simple;
|
||||
|
||||
import gearth.extensions.InternalExtensionFormBuilder;
|
||||
import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducer;
|
||||
import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducerObserver;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.BlockAndReplacePackets;
|
||||
|
||||
public class SimpleExtensionProducer implements ExtensionProducer {
|
||||
|
||||
@ -9,7 +11,8 @@ public class SimpleExtensionProducer implements ExtensionProducer {
|
||||
public void startProducing(ExtensionProducerObserver observer) {
|
||||
|
||||
// uncomment the next line if you want to see an embedded example extension in G-Earth
|
||||
// observer.onExtensionConnect(new ExampleExtension());
|
||||
// observer.onExtensionProduced(new ExampleExtension());
|
||||
|
||||
InternalExtensionFormBuilder.launch(BlockAndReplacePackets.class, observer);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package extensions.blockreplacepackets;
|
||||
package gearth.services.internal_extensions.blockreplacepackets;
|
||||
|
||||
import extensions.blockreplacepackets.rules.BlockReplaceRule;
|
||||
import extensions.blockreplacepackets.rules.RuleFactory;
|
||||
import gearth.extensions.Extension;
|
||||
import gearth.Main;
|
||||
import gearth.extensions.ExtensionForm;
|
||||
import gearth.extensions.ExtensionInfo;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.rules.BlockReplaceRule;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.rules.RuleFactory;
|
||||
import gearth.ui.GEarthController;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
@ -15,11 +17,10 @@ import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import gearth.extensions.ExtensionForm;
|
||||
import gearth.extensions.ExtensionInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -48,9 +49,9 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
|
||||
List<BlockReplaceRule> rules = new ArrayList<>();
|
||||
|
||||
public static void main(String[] args) {
|
||||
runExtensionForm(args, BlockAndReplacePackets.class);
|
||||
}
|
||||
// public static void main(String[] args) {
|
||||
// runExtensionForm(args, BlockAndReplacePackets.class);
|
||||
// }
|
||||
|
||||
//initialize javaFX elements
|
||||
public void initialize() {
|
||||
@ -177,7 +178,7 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
|
||||
@Override
|
||||
protected void initExtension() {
|
||||
Extension.MessageListener messageListener = message -> {
|
||||
MessageListener messageListener = message -> {
|
||||
for (BlockReplaceRule rule : rules) {
|
||||
rule.appendRuleToMessage(message);
|
||||
}
|
||||
@ -196,6 +197,7 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setResizable(false);
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
|
||||
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("G-EarthLogoSmaller.png")));
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
@ -215,6 +217,11 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
clearInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canLeave() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDelete() {
|
||||
return false;
|
@ -1,6 +1,6 @@
|
||||
package extensions.blockreplacepackets;
|
||||
package gearth.services.internal_extensions.blockreplacepackets;
|
||||
|
||||
import extensions.blockreplacepackets.rules.BlockReplaceRule;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.rules.BlockReplaceRule;
|
||||
import gearth.ui.buttons.DeleteButton;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
@ -13,7 +13,7 @@ import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Font;
|
||||
|
||||
/**
|
||||
* Created by Jeunez on 6/11/2018.
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class RuleContainer extends GridPane {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
import javafx.beans.InvalidationListener;
|
@ -1,4 +1,4 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
/**
|
||||
* Created by Jeunez on 6/11/2018.
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class ReplacePacketRule extends BlockReplaceRule {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HPacket;
|
||||
|
@ -1,17 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ComboBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<GridPane prefHeight="324.0" prefWidth="588.0" style="-fx-background-color: #FFFFFF;" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1" fx:controller="extensions.blockreplacepackets.BlockAndReplacePackets">
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<GridPane prefHeight="324.0" prefWidth="588.0" style="-fx-background-color: #FFFFFF;" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.services.internal_extensions.blockreplacepackets.BlockAndReplacePackets">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
Loading…
Reference in New Issue
Block a user