Komplettes G-Earth Paket inkl. JRE, Extensions und Tools. Extensions: - G-BuildTools, G-Click Ultimate, G-Loader, G-Manipulate - G-Presets, G-Translator, G-Trigger, G-itemViewer - Market Utils, Packet Info Explorer, Plants - RandomRoomVisitor, RoomLogger, Sanbovir Photo Inspector - SpyFriends, WallAligner, XabboScripter, xabbo
415 lines
17 KiB
Java
415 lines
17 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* javafx.event.ActionEvent
|
|
* javafx.scene.control.Button
|
|
* javafx.scene.control.CheckBox
|
|
* javafx.scene.control.ComboBox
|
|
* javafx.scene.control.RadioButton
|
|
* javafx.scene.control.TextField
|
|
* javafx.scene.control.ToggleGroup
|
|
* javafx.scene.layout.Pane
|
|
*/
|
|
package extension;
|
|
|
|
import extension.Language;
|
|
import gearth.extensions.ExtensionForm;
|
|
import gearth.extensions.ExtensionInfo;
|
|
import gearth.extensions.parsers.HEntity;
|
|
import gearth.protocol.HMessage;
|
|
import gearth.protocol.HPacket;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import javafx.event.ActionEvent;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.CheckBox;
|
|
import javafx.scene.control.ComboBox;
|
|
import javafx.scene.control.RadioButton;
|
|
import javafx.scene.control.TextField;
|
|
import javafx.scene.control.ToggleGroup;
|
|
import javafx.scene.layout.Pane;
|
|
import misc.MaybeConsumer;
|
|
import translation.TranslationException;
|
|
import translation.Translator;
|
|
import translation.TranslatorFactory;
|
|
|
|
@ExtensionInfo(Title="G-Translator", Description="Translate the hotel", Version="1.0.2", Author="sirjonasxx & Tripical")
|
|
public class TranslatorExtension
|
|
extends ExtensionForm {
|
|
public Pane apiMicrosoftInfo;
|
|
public TextField apiMicrosoftKey;
|
|
public TextField apiMicrosoftRegion;
|
|
public Pane apiVertexInfo;
|
|
public TextField apiVertexKey;
|
|
public TextField apiVertexProject;
|
|
public TextField apiVertexLocation;
|
|
public TextField apiVertexModel;
|
|
public RadioButton rdArgos;
|
|
public RadioButton rdMicrosoft;
|
|
public RadioButton rdVertex;
|
|
public ToggleGroup tglAPI;
|
|
private volatile int userId = -1;
|
|
private HashMap<Integer, HEntity> users = new HashMap();
|
|
public ComboBox<Language> myLang;
|
|
public ComboBox<Language> sourceLang;
|
|
public CheckBox translateIncoming;
|
|
public CheckBox translateOutgoing;
|
|
public CheckBox translateWired;
|
|
public CheckBox showOriginal;
|
|
public CheckBox translateRoomInfo;
|
|
public CheckBox translateNavigator;
|
|
public CheckBox translateChatIn;
|
|
public CheckBox translateChatOut;
|
|
public Button isActiveBtn;
|
|
private volatile boolean isActive = false;
|
|
|
|
public void initialize() {
|
|
this.myLang.getItems().addAll(Language.values());
|
|
this.myLang.getSelectionModel().selectFirst();
|
|
this.sourceLang.getItems().addAll(Language.values());
|
|
this.sourceLang.getSelectionModel().selectFirst();
|
|
this.rdMicrosoft.selectedProperty().addListener((obs, old, val) -> this.apiMicrosoftInfo.setDisable(val == false));
|
|
this.rdVertex.selectedProperty().addListener((obs, old, val) -> this.apiVertexInfo.setDisable(val == false));
|
|
}
|
|
|
|
@Override
|
|
protected void initExtension() {
|
|
this.intercept(HMessage.Direction.TOCLIENT, "Chat", this::onReceiveChat);
|
|
this.intercept(HMessage.Direction.TOCLIENT, "Whisper", this::onReceiveChat);
|
|
this.intercept(HMessage.Direction.TOCLIENT, "Shout", this::onReceiveChat);
|
|
this.intercept(HMessage.Direction.TOSERVER, "Chat", this::onSendChat);
|
|
this.intercept(HMessage.Direction.TOSERVER, "Whisper", this::onSendChat);
|
|
this.intercept(HMessage.Direction.TOSERVER, "Shout", this::onSendChat);
|
|
this.intercept(HMessage.Direction.TOCLIENT, "RoomReady", this::onRoomReady);
|
|
this.intercept(HMessage.Direction.TOCLIENT, "UserObject", this::onInfoRetrieve);
|
|
this.intercept(HMessage.Direction.TOCLIENT, "Users", this::onUsers);
|
|
this.intercept(HMessage.Direction.TOSERVER, "SendMsg", this::onSendDM);
|
|
this.intercept(HMessage.Direction.TOSERVER, "SendRoomInvite", this::onSendInvitation);
|
|
this.intercept(HMessage.Direction.TOCLIENT, "NewConsole", this::onReceiveDMOrInvitation);
|
|
this.intercept(HMessage.Direction.TOCLIENT, "RoomInvite", this::onReceiveDMOrInvitation);
|
|
this.intercept(HMessage.Direction.TOCLIENT, "GetGuestRoomResult", this::onRoomInfo);
|
|
this.intercept(HMessage.Direction.TOCLIENT, "NavigatorSearchResultBlocks", this::onNavigatorResult);
|
|
this.sendToServer(new HPacket("GetHeightMap", HMessage.Direction.TOSERVER));
|
|
this.sendToServer(new HPacket("InfoRetrieve", HMessage.Direction.TOSERVER));
|
|
}
|
|
|
|
private void onNavigatorResult(HMessage hMessage) {
|
|
Translator translator = TranslatorFactory.get(this);
|
|
if (this.isActive && this.translateNavigator.isSelected() && translator.allowMultiLines()) {
|
|
hMessage.setBlocked(true);
|
|
final ArrayList<Integer> translationIndexes = new ArrayList<Integer>();
|
|
ArrayList<String> translations = new ArrayList<String>();
|
|
final HPacket packet = hMessage.getPacket();
|
|
packet.readString();
|
|
packet.readString();
|
|
int blocks = packet.readInteger();
|
|
for (int i = 0; i < blocks; ++i) {
|
|
packet.readString();
|
|
packet.readString();
|
|
packet.readInteger();
|
|
packet.readBoolean();
|
|
packet.readInteger();
|
|
int rooms = packet.readInteger();
|
|
for (int j = 0; j < rooms; ++j) {
|
|
packet.readInteger();
|
|
translationIndexes.add(packet.getReadIndex());
|
|
translations.add(packet.readString(StandardCharsets.UTF_8));
|
|
packet.readInteger();
|
|
packet.readString();
|
|
packet.readInteger();
|
|
packet.readInteger();
|
|
packet.readInteger();
|
|
packet.readString();
|
|
packet.readInteger();
|
|
packet.readInteger();
|
|
packet.readInteger();
|
|
packet.readInteger();
|
|
int tags = packet.readInteger();
|
|
for (int k = 0; k < tags; ++k) {
|
|
packet.readString();
|
|
}
|
|
int multiUse = packet.readInteger();
|
|
if ((multiUse & 1) > 0) {
|
|
packet.readString();
|
|
}
|
|
if ((multiUse & 2) > 0) {
|
|
packet.readInteger();
|
|
packet.readString();
|
|
packet.readString();
|
|
}
|
|
if ((multiUse & 4) <= 0) continue;
|
|
translationIndexes.add(packet.getReadIndex());
|
|
translations.add(packet.readString(StandardCharsets.UTF_8));
|
|
packet.readString();
|
|
packet.readInteger();
|
|
}
|
|
}
|
|
translator.translate(translations, this.getSourceLanguage(), this.getMyLanguage(), new MaybeConsumer<List<String>, TranslationException>(){
|
|
|
|
@Override
|
|
public void except(TranslationException exception) {
|
|
System.out.println(exception.getReason());
|
|
}
|
|
|
|
@Override
|
|
public void accept(List<String> strings) {
|
|
for (int i = strings.size() - 1; i >= 0; --i) {
|
|
int index = (Integer)translationIndexes.get(i);
|
|
String replacedText = strings.get(i);
|
|
packet.replaceString(index, replacedText);
|
|
}
|
|
TranslatorExtension.this.sendToClient(packet);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void onReceiveDMOrInvitation(HMessage hMessage) {
|
|
if (this.isActive && this.translateChatIn.isSelected()) {
|
|
final HPacket packet = hMessage.getPacket();
|
|
int sender = packet.readInteger();
|
|
String text = packet.readString(StandardCharsets.UTF_8);
|
|
hMessage.setBlocked(true);
|
|
Translator translator = TranslatorFactory.get(this);
|
|
translator.translate(text, this.getSourceLanguage(), this.getMyLanguage(), new MaybeConsumer<String, TranslationException>(){
|
|
|
|
@Override
|
|
public void except(TranslationException exception) {
|
|
System.out.println(exception.getReason());
|
|
}
|
|
|
|
@Override
|
|
public void accept(String s) {
|
|
packet.replaceString(10, s, StandardCharsets.UTF_8);
|
|
TranslatorExtension.this.sendToClient(packet);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void onSendDM(HMessage hMessage) {
|
|
if (this.isActive && this.translateChatOut.isSelected()) {
|
|
final HPacket packet = hMessage.getPacket();
|
|
int receiver = packet.readInteger();
|
|
String text = packet.readString(StandardCharsets.UTF_8);
|
|
hMessage.setBlocked(true);
|
|
Translator translator = TranslatorFactory.get(this);
|
|
translator.translate(text, this.getMyLanguage(), this.getSourceLanguage(), new MaybeConsumer<String, TranslationException>(){
|
|
|
|
@Override
|
|
public void except(TranslationException exception) {
|
|
System.out.println(exception.getReason());
|
|
}
|
|
|
|
@Override
|
|
public void accept(String s) {
|
|
packet.replaceString(10, s, StandardCharsets.UTF_8);
|
|
TranslatorExtension.this.sendToServer(packet);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void onSendInvitation(HMessage hMessage) {
|
|
if (this.isActive && this.translateChatOut.isSelected()) {
|
|
final HPacket packet = hMessage.getPacket();
|
|
int amountReceivers = packet.readInteger();
|
|
final int textIndexInPacket = 10 + amountReceivers * 4;
|
|
String text = packet.readString(textIndexInPacket, StandardCharsets.UTF_8);
|
|
hMessage.setBlocked(true);
|
|
Translator translator = TranslatorFactory.get(this);
|
|
translator.translate(text, this.getMyLanguage(), this.getSourceLanguage(), new MaybeConsumer<String, TranslationException>(){
|
|
|
|
@Override
|
|
public void except(TranslationException exception) {
|
|
System.out.println(exception.getReason());
|
|
}
|
|
|
|
@Override
|
|
public void accept(String s) {
|
|
packet.replaceString(textIndexInPacket, s, StandardCharsets.UTF_8);
|
|
TranslatorExtension.this.sendToServer(packet);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void onRoomInfo(HMessage hMessage) {
|
|
if (this.isActive && this.translateRoomInfo.isSelected()) {
|
|
final HPacket packet = hMessage.getPacket();
|
|
boolean test = packet.readBoolean();
|
|
if (!test) {
|
|
return;
|
|
}
|
|
hMessage.setBlocked(true);
|
|
int roomId = packet.readInteger();
|
|
final int roomNamePacketIndex = packet.getReadIndex();
|
|
String originalRoomName = packet.readString(StandardCharsets.UTF_8);
|
|
packet.readInteger();
|
|
packet.readString();
|
|
packet.readInteger();
|
|
packet.readInteger();
|
|
packet.readInteger();
|
|
final int roomDescPacketIndex = packet.getReadIndex();
|
|
String originalDesc = packet.readString(StandardCharsets.UTF_8);
|
|
TranslatorFactory.get(this).translate(Arrays.asList(originalRoomName, originalDesc), this.getSourceLanguage(), this.getMyLanguage(), new MaybeConsumer<List<String>, TranslationException>(){
|
|
|
|
@Override
|
|
public void except(TranslationException exception) {
|
|
System.out.println(exception.getReason());
|
|
}
|
|
|
|
@Override
|
|
public void accept(List<String> s) {
|
|
packet.replaceString(roomDescPacketIndex, s.get(1), StandardCharsets.UTF_8);
|
|
packet.replaceString(roomNamePacketIndex, s.get(0), StandardCharsets.UTF_8);
|
|
TranslatorExtension.this.sendToClient(packet);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void onUsers(HMessage hMessage) {
|
|
HEntity[] hEntities;
|
|
for (HEntity hEntity : hEntities = HEntity.parse(hMessage.getPacket())) {
|
|
this.users.put(hEntity.getIndex(), hEntity);
|
|
}
|
|
}
|
|
|
|
private void onInfoRetrieve(HMessage hMessage) {
|
|
this.userId = hMessage.getPacket().readInteger();
|
|
}
|
|
|
|
private void onRoomReady(HMessage hMessage) {
|
|
this.users.clear();
|
|
if (this.userId == -1) {
|
|
this.sendToServer(new HPacket("InfoRetrieve", HMessage.Direction.TOSERVER));
|
|
}
|
|
}
|
|
|
|
private boolean userIsYou(int index) {
|
|
return !this.users.containsKey(index) || this.userId != -1 && this.users.get(index).getId() == this.userId;
|
|
}
|
|
|
|
@Override
|
|
protected void onEndConnection() {
|
|
this.userId = -1;
|
|
}
|
|
|
|
private Language getMyLanguage() {
|
|
return (Language)((Object)this.myLang.getValue());
|
|
}
|
|
|
|
private Language getSourceLanguage() {
|
|
return (Language)((Object)this.sourceLang.getValue());
|
|
}
|
|
|
|
private void onSendChat(HMessage hMessage) {
|
|
final boolean isWhisper = this.getPacketInfoManager().getPacketInfoFromHeaderId(HMessage.Direction.TOSERVER, hMessage.getPacket().headerId()).getName().equals("Whisper");
|
|
if (this.isActive && this.translateOutgoing.isSelected()) {
|
|
final HPacket packet = hMessage.getPacket();
|
|
String text = packet.readString(StandardCharsets.UTF_8);
|
|
if (this.showOriginal.isSelected()) {
|
|
this.sendToClient(new HPacket("Whisper", HMessage.Direction.TOCLIENT, -1, text, 0, 30, 0, -1));
|
|
}
|
|
hMessage.setBlocked(true);
|
|
Translator translator = TranslatorFactory.get(this);
|
|
final String receiver = isWhisper ? text.split(" ")[0] : null;
|
|
text = isWhisper ? text.substring(receiver.length() + 1) : text;
|
|
translator.translate(text, this.getMyLanguage(), this.getSourceLanguage(), new MaybeConsumer<String, TranslationException>(){
|
|
|
|
@Override
|
|
public void except(TranslationException exception) {
|
|
System.out.println(exception.getReason());
|
|
}
|
|
|
|
@Override
|
|
public void accept(String s) {
|
|
packet.replaceString(6, isWhisper ? receiver + " " + s : s, StandardCharsets.UTF_8);
|
|
TranslatorExtension.this.sendToServer(packet);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void onReceiveChat(HMessage hMessage) {
|
|
if (this.isActive && this.translateIncoming.isSelected()) {
|
|
boolean isWiredMessage;
|
|
HPacket packet = hMessage.getPacket();
|
|
final HPacket copy = new HPacket(packet);
|
|
int userIndex = packet.readInteger();
|
|
String text = packet.readString(StandardCharsets.UTF_8);
|
|
packet.readInteger();
|
|
int chatBubble = packet.readInteger();
|
|
boolean bl = isWiredMessage = chatBubble == 34;
|
|
if (isWiredMessage && !this.translateWired.isSelected() || !isWiredMessage && this.userIsYou(userIndex)) {
|
|
return;
|
|
}
|
|
if (this.showOriginal.isSelected()) {
|
|
packet.replaceInt(packet.getReadIndex() - 4, isWiredMessage ? 33 : 30);
|
|
} else {
|
|
hMessage.setBlocked(true);
|
|
}
|
|
Translator translator = TranslatorFactory.get(this);
|
|
translator.translate(text, this.getSourceLanguage(), this.getMyLanguage(), new MaybeConsumer<String, TranslationException>(){
|
|
|
|
@Override
|
|
public void except(TranslationException exception) {
|
|
System.out.println(exception.getReason());
|
|
}
|
|
|
|
@Override
|
|
public void accept(String s) {
|
|
copy.resetReadIndex();
|
|
copy.readInteger();
|
|
copy.replaceString(copy.getReadIndex(), s, StandardCharsets.UTF_8);
|
|
TranslatorExtension.this.sendToClient(copy);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public void startStop(ActionEvent actionEvent) {
|
|
if (this.isActive) {
|
|
this.isActive = false;
|
|
this.isActiveBtn.setText("Start");
|
|
} else {
|
|
this.isActive = true;
|
|
this.isActiveBtn.setText("Stop");
|
|
}
|
|
}
|
|
|
|
public String getApi() {
|
|
return ((RadioButton)this.tglAPI.getSelectedToggle()).getText().split(" ")[0].toLowerCase();
|
|
}
|
|
|
|
public String getMicrosoftKey() {
|
|
return this.apiMicrosoftKey.getText();
|
|
}
|
|
|
|
public String getMicrosoftRegion() {
|
|
return this.apiMicrosoftRegion.getText();
|
|
}
|
|
|
|
public String getVertexApiKey() {
|
|
return this.apiVertexKey.getText();
|
|
}
|
|
|
|
public String getVertexProject() {
|
|
return this.apiVertexProject.getText();
|
|
}
|
|
|
|
public String getVertexLocation() {
|
|
return this.apiVertexLocation.getText();
|
|
}
|
|
|
|
public String getVertexModel() {
|
|
return this.apiVertexModel.getText();
|
|
}
|
|
}
|
|
|