This commit is contained in:
sirjonasxx 2021-04-23 00:47:33 +02:00
parent e51dcbaff8
commit 9698348503
4 changed files with 110 additions and 3 deletions

View File

@ -35,6 +35,8 @@ public class PacketInfoManager {
}
private void addMessage(PacketInfo packetInfo) {
if (packetInfo.getHash() == null && packetInfo.getName() == null) return;
Map<Integer, List<PacketInfo>> headerIdToMessage =
packetInfo.getDestination() == HMessage.Direction.TOCLIENT
? headerIdToMessage_incoming :

View File

@ -4,9 +4,12 @@ import gearth.misc.Cacher;
import gearth.misc.packet_info.PacketInfo;
import gearth.misc.packet_info.providers.PacketInfoProvider;
import gearth.misc.packet_info.providers.RemotePacketInfoProvider;
import gearth.protocol.HMessage;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class HarblePacketInfoProvider extends RemotePacketInfoProvider {
@ -28,8 +31,48 @@ public class HarblePacketInfoProvider extends RemotePacketInfoProvider {
return CACHE_PREFIX + hotelVersion;
}
private PacketInfo jsonToPacketInfo(JSONObject object, HMessage.Direction destination) {
String name;
String hash;
String structure;
try { name = object.getString("Name"); }
catch (Exception e) { name = null; }
try { hash = object.getString("Hash"); }
catch (Exception e) { hash = null; }
try { structure = object.getString("Structure");
} catch (Exception e) { structure = null; }
int headerId;
try {headerId = object.getInt("Id"); }
catch (Exception e) { headerId = Integer.parseInt(object.getString("Id")); }
return new PacketInfo(destination, headerId, hash, name, structure);
}
@Override
protected List<PacketInfo> parsePacketInfo(JSONObject jsonObject) {
return null;
List<PacketInfo> packetInfos = new ArrayList<>();
try {
JSONArray incoming = jsonObject.getJSONArray("Incoming");
JSONArray outgoing = jsonObject.getJSONArray("Outgoing");
if (incoming != null && outgoing != null) {
for (int i = 0; i < incoming.length(); i++) {
JSONObject jsonInfo = incoming.getJSONObject(i);
PacketInfo packetInfo = jsonToPacketInfo(jsonInfo, HMessage.Direction.TOCLIENT);
packetInfos.add(packetInfo);
}
for (int i = 0; i < outgoing.length(); i++) {
JSONObject jsonInfo = outgoing.getJSONObject(i);
PacketInfo packetInfo = jsonToPacketInfo(jsonInfo, HMessage.Direction.TOSERVER);
packetInfos.add(packetInfo);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return packetInfos;
}
}

View File

@ -2,8 +2,11 @@ package gearth.misc.packet_info.providers.implementations;
import gearth.misc.packet_info.PacketInfo;
import gearth.misc.packet_info.providers.RemotePacketInfoProvider;
import gearth.protocol.HMessage;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class SulekPacketInfoProvider extends RemotePacketInfoProvider {
@ -25,8 +28,36 @@ public class SulekPacketInfoProvider extends RemotePacketInfoProvider {
return CACHE_PREFIX + hotelVersion;
}
private PacketInfo jsonToPacketInfo(JSONObject object, HMessage.Direction destination) {
int headerId = object.getInt("id");
String name = object.getString("name")
.replaceAll("(((Message)?Composer)|((Message)?Event))$", "");
return new PacketInfo(destination, headerId, null, name, null);
}
@Override
protected List<PacketInfo> parsePacketInfo(JSONObject jsonObject) {
return null;
List<PacketInfo> packetInfos = new ArrayList<>();
try {
JSONArray incoming = jsonObject.getJSONObject("messages").getJSONArray("incoming");
JSONArray outgoing = jsonObject.getJSONObject("messages").getJSONArray("outgoing");
for (int i = 0; i < incoming.length(); i++) {
JSONObject jsonInfo = incoming.getJSONObject(i);
PacketInfo packetInfo = jsonToPacketInfo(jsonInfo, HMessage.Direction.TOCLIENT);
packetInfos.add(packetInfo);
}
for (int i = 0; i < outgoing.length(); i++) {
JSONObject jsonInfo = outgoing.getJSONObject(i);
PacketInfo packetInfo = jsonToPacketInfo(jsonInfo, HMessage.Direction.TOSERVER);
packetInfos.add(packetInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
return packetInfos;
}
}

View File

@ -3,10 +3,13 @@ package gearth.misc.packet_info.providers.implementations;
import gearth.Main;
import gearth.misc.packet_info.PacketInfo;
import gearth.misc.packet_info.providers.PacketInfoProvider;
import gearth.protocol.HMessage;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
public class UnityPacketInfoProvider extends PacketInfoProvider {
@ -26,8 +29,36 @@ public class UnityPacketInfoProvider extends PacketInfoProvider {
}
}
private PacketInfo jsonToPacketInfo(JSONObject object, HMessage.Direction destination) {
String name = object.getString("Name");
int headerId = object.getInt("Id");
return new PacketInfo(destination, headerId, null, name, null);
}
@Override
protected List<PacketInfo> parsePacketInfo(JSONObject jsonObject) {
return null;
List<PacketInfo> packetInfos = new ArrayList<>();
try {
JSONArray incoming = jsonObject.getJSONArray("Incoming");
JSONArray outgoing = jsonObject.getJSONArray("Outgoing");
if (incoming != null && outgoing != null) {
for (int i = 0; i < incoming.length(); i++) {
JSONObject jsonInfo = incoming.getJSONObject(i);
PacketInfo packetInfo = jsonToPacketInfo(jsonInfo, HMessage.Direction.TOCLIENT);
packetInfos.add(packetInfo);
}
for (int i = 0; i < outgoing.length(); i++) {
JSONObject jsonInfo = outgoing.getJSONObject(i);
PacketInfo packetInfo = jsonToPacketInfo(jsonInfo, HMessage.Direction.TOSERVER);
packetInfos.add(packetInfo);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return packetInfos;
}
}