Merge pull request #99 from WiredSpast/master

Added parsers
This commit is contained in:
sirjonasxx 2021-09-06 17:23:50 +02:00 committed by GitHub
commit 67523ba936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1039 additions and 0 deletions

View File

@ -0,0 +1,85 @@
package gearth.extensions.parsers;
import gearth.protocol.HPacket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class HCatalogIndex {
private final HPageIndex root;
private final boolean newAdditionsAvailable;
private final String catalogType;
public HPageIndex getRoot() {
return root;
}
public boolean isNewAdditionsAvailable() {
return newAdditionsAvailable;
}
public String getCatalogType() {
return catalogType;
}
public HCatalogIndex(HPacket packet) {
this.root = new HPageIndex(packet);
this.newAdditionsAvailable = packet.readBoolean();
this.catalogType = packet.readString();
}
public static class HPageIndex {
private final boolean visible;
private final int icon, pageId;
private final String pageName, localization;
private final List<Integer> offerIds = new ArrayList<>();
private final List<HPageIndex> children = new ArrayList<>();
public boolean isVisible() {
return visible;
}
public int getIcon() {
return icon;
}
public int getPageId() {
return pageId;
}
public String getPageName() {
return pageName;
}
public String getLocalization() {
return localization;
}
public List<Integer> getOfferIds() {
return Collections.unmodifiableList(offerIds);
}
public List<HPageIndex> getChildren() {
return Collections.unmodifiableList(children);
}
private HPageIndex(HPacket packet) {
this.visible = packet.readBoolean();
this.icon = packet.readInteger();
this.pageId = packet.readInteger();
this.pageName = packet.readString();
this.localization = packet.readString();
int offerCount = packet.readInteger();
for(int i = 0; i < offerCount; i++) {
this.offerIds.add(packet.readInteger());
}
int childCount = packet.readInteger();
for(int i = 0; i < childCount; i++) {
this.children.add(new HPageIndex(packet));
}
}
}
}

View File

@ -0,0 +1,281 @@
package gearth.extensions.parsers;
import gearth.protocol.HPacket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HFriend {
private int id;
private String name;
private HGender gender;
private boolean online;
private boolean followingAllowed;
private String figure;
private int categoryId;
private String motto;
private String realName;
private String facebookId;
private boolean persistedMessageUser;
private boolean vipMember;
private boolean pocketHabboUser;
private HRelationshipStatus relationshipStatus;
private String categoryName = null;
public HFriend(HPacket packet) {
this.id = packet.readInteger();
this.name = packet.readString();
this.gender = packet.readInteger() == 0 ? HGender.Female : HGender.Male;
this.online = packet.readBoolean();
this.followingAllowed = packet.readBoolean();
this.figure = packet.readString();
this.categoryId = packet.readInteger();
this.motto = packet.readString();
this.realName = packet.readString();
this.facebookId = packet.readString();
this.persistedMessageUser = packet.readBoolean();
this.vipMember = packet.readBoolean();
this.pocketHabboUser = packet.readBoolean();
this.relationshipStatus = HRelationshipStatus.fromId(packet.readShort());
}
public void appendToPacket(HPacket packet) {
packet.appendInt(id);
packet.appendString(name);
packet.appendInt(gender == HGender.Female ? 0 : 1);
packet.appendBoolean(online);
packet.appendBoolean(followingAllowed);
packet.appendString(figure);
packet.appendInt(categoryId);
packet.appendString(motto);
packet.appendString(realName);
packet.appendString(facebookId);
packet.appendBoolean(persistedMessageUser);
packet.appendBoolean(vipMember);
packet.appendBoolean(pocketHabboUser);
packet.appendShort((short) relationshipStatus.getId());
}
public static HFriend[] parseFromFragment(HPacket packet) {
packet.setReadIndex(14);
// int packetCount
// int packetIndex
HFriend[] friends = new HFriend[packet.readInteger()];
for(int i = 0; i < friends.length; i++) {
friends[i] = new HFriend(packet);
}
return friends;
}
public static HFriend[] parseFromUpdate(HPacket packet) {
packet.resetReadIndex();
int categoryCount = packet.readInteger();
Map<Integer, String> categories = new HashMap<>();
for(int i = 0; i < categoryCount; i++)
categories.put(packet.readInteger(), packet.readString());
int friendCount = packet.readInteger();
List<HFriend> friends = new ArrayList<>();
for(int i = 0; i < friendCount; i++) {
if(packet.readInteger() != -1) {
friends.add(new HFriend(packet));
} else {
packet.readInteger();
}
}
for(HFriend friend : friends) {
friend.categoryName = categories.getOrDefault(friend.categoryId, null);
}
return friends.toArray(new HFriend[0]);
}
public static int[] getRemovedFriendIdsFromUpdate(HPacket packet) {
packet.resetReadIndex();
int categoryCount = packet.readInteger();
for(int i = 0; i < categoryCount; i++) {
packet.readInteger();
packet.readString();
}
int friendCount = packet.getReadIndex();
List<Integer> removedIds = new ArrayList<>();
for(int i = 0; i < friendCount; i++) {
if(packet.readInteger() != -1) {
new HFriend(packet);
} else {
removedIds.add(packet.readInteger());
}
}
return removedIds.stream().mapToInt(i -> i).toArray();
}
public static HPacket[] constructFragmentPackets(HFriend[] friends, int headerId) {
int packetCount = (int) Math.ceil((double) friends.length / 100);
HPacket[] packets = new HPacket[packetCount];
for(int i = 0; i < packetCount; i++) {
packets[i] = new HPacket(headerId);
packets[i].appendInt(packetCount);
packets[i].appendInt(i);
packets[i].appendInt(i == packetCount - 1 ? friends.length % 100 : 100);
for(int j = i * 100; j < friends.length && j < (j + 1) * 100; j++) {
friends[j].appendToPacket(packets[i]);
}
}
return packets;
}
public static HPacket constructUpdatePacket(HFriend[] friends, int headerId) {
Map<Integer, String> categories = new HashMap<>();
for (HFriend friend : friends) {
if(friend.categoryName != null)
categories.put(friend.categoryId, friend.categoryName);
}
HPacket packet = new HPacket(headerId);
packet.appendInt(categories.size());
for(int categoryId : categories.keySet()) {
packet.appendInt(categoryId);
packet.appendString(categories.get(categoryId));
}
packet.appendInt(friends.length);
for(HFriend friend : friends) {
friend.appendToPacket(packet);
}
return packet;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public HGender getGender() {
return gender;
}
public void setGender(HGender gender) {
this.gender = gender;
}
public boolean isOnline() {
return online;
}
public void setOnline(boolean online) {
this.online = online;
}
public boolean isFollowingAllowed() {
return followingAllowed;
}
public void setFollowingAllowed(boolean followingAllowed) {
this.followingAllowed = followingAllowed;
}
public String getFigure() {
return figure;
}
public void setFigure(String figure) {
this.figure = figure;
}
public int getCategoryId() {
return categoryId;
}
public void setCategoryId(int categoryId) {
this.categoryId = categoryId;
}
public String getMotto() {
return motto;
}
public void setMotto(String motto) {
this.motto = motto;
}
public String getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
}
public String getFacebookId() {
return facebookId;
}
public void setFacebookId(String facebookId) {
this.facebookId = facebookId;
}
public boolean isPersistedMessageUser() {
return persistedMessageUser;
}
public void setPersistedMessageUser(boolean persistedMessageUser) {
this.persistedMessageUser = persistedMessageUser;
}
public boolean isVipMember() {
return vipMember;
}
public void setVipMember(boolean vipMember) {
this.vipMember = vipMember;
}
public boolean isPocketHabboUser() {
return pocketHabboUser;
}
public void setPocketHabboUser(boolean pocketHabboUser) {
this.pocketHabboUser = pocketHabboUser;
}
public HRelationshipStatus getRelationshipStatus() {
return relationshipStatus;
}
public void setRelationshipStatus(HRelationshipStatus relationshipStatus) {
this.relationshipStatus = relationshipStatus;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
}

View File

@ -0,0 +1,223 @@
package gearth.extensions.parsers;
import gearth.protocol.HPacket;
public class HInventoryItem {
private int placementId;
private HProductType type;
private int id;
private int typeId;
private HSpecialType specialType;
private int category;
private Object[] stuff;
private boolean recyclable;
private boolean tradeable;
private boolean groupable;
private boolean sellable;
private int secondsToExpiration;
private boolean rentPeriodStarted;
private int roomId;
private String slotId = "";
private int extra = -1;
public HInventoryItem(HPacket packet) {
placementId = packet.readInteger();
type = HProductType.fromString(packet.readString());
id = packet.readInteger();
typeId = packet.readInteger();
specialType = HSpecialType.fromId(packet.readInteger());
category = packet.readInteger();
stuff = HStuff.readData(packet, category);
recyclable = packet.readBoolean();
tradeable = packet.readBoolean();
groupable = packet.readBoolean();
sellable = packet.readBoolean();
secondsToExpiration = packet.readInteger();
rentPeriodStarted = packet.readBoolean();
roomId = packet.readInteger();
if(type == HProductType.FloorItem) {
slotId = packet.readString();
extra = packet.readInteger();
}
}
public void appendToPacket(HPacket packet) {
packet.appendInt(placementId);
packet.appendString(type.toString());
packet.appendInt(id);
packet.appendInt(typeId);
packet.appendInt(specialType.getId());
packet.appendInt(category);
for (Object object : stuff) {
packet.appendObject(object);
}
packet.appendBoolean(recyclable);
packet.appendBoolean(tradeable);
packet.appendBoolean(groupable);
packet.appendBoolean(sellable);
packet.appendInt(secondsToExpiration);
packet.appendBoolean(rentPeriodStarted);
packet.appendInt(roomId);
if(type == HProductType.FloorItem) {
packet.appendString(slotId);
packet.appendInt(extra);
}
}
public static HInventoryItem[] parse(HPacket packet) {
// int packetcount
// int packetindex
packet.setReadIndex(14);
int itemCount = packet.readInteger();
HInventoryItem[] items = new HInventoryItem[itemCount];
for(int i = 0; i < itemCount; i++) {
items[i] = new HInventoryItem(packet);
}
return items;
}
public static HPacket[] constructPackets(HInventoryItem[] items, int headerId) {
int packetCount = (int) Math.ceil((double) items.length / 600);
HPacket[] packets = new HPacket[packetCount];
for(int i = 0; i < packetCount; i++) {
packets[i] = new HPacket(headerId);
packets[i].appendInt(packetCount);
packets[i].appendInt(i);
packets[i].appendInt(i == packetCount - 1 ? items.length % 600 : 600);
for(int j = i * 600; j < items.length && j < (j + 1) * 600; j++) {
items[j].appendToPacket(packets[i]);
}
}
return packets;
}
public int getPlacementId() {
return placementId;
}
public void setPlacementId(int placementId) {
this.placementId = placementId;
}
public HProductType getType() {
return type;
}
public void setType(HProductType type) {
this.type = type;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getTypeId() {
return typeId;
}
public void setTypeId(int typeId) {
this.typeId = typeId;
}
public int getCategory() {
return category;
}
public void setCategory(int category) {
this.category = category;
}
public Object[] getStuff() {
return stuff;
}
public void setStuff(Object[] stuff) {
this.stuff = stuff;
}
public boolean isRecyclable() {
return recyclable;
}
public void setRecyclable(boolean recyclable) {
this.recyclable = recyclable;
}
public boolean isTradeable() {
return tradeable;
}
public void setTradeable(boolean tradeable) {
this.tradeable = tradeable;
}
public boolean isGroupable() {
return groupable;
}
public void setGroupable(boolean groupable) {
this.groupable = groupable;
}
public boolean isSellable() {
return sellable;
}
public void setSellable(boolean sellable) {
this.sellable = sellable;
}
public int getSecondsToExpiration() {
return secondsToExpiration;
}
public void setSecondsToExpiration(int secondsToExpiration) {
this.secondsToExpiration = secondsToExpiration;
}
public boolean isRentPeriodStarted() {
return rentPeriodStarted;
}
public void setRentPeriodStarted(boolean rentPeriodStarted) {
this.rentPeriodStarted = rentPeriodStarted;
}
public int getRoomId() {
return roomId;
}
public void setRoomId(int roomId) {
this.roomId = roomId;
}
public String getSlotId() {
return slotId;
}
public void setSlotId(String slotId) {
this.slotId = slotId;
}
public int getExtra() {
return extra;
}
public void setExtra(int extra) {
this.extra = extra;
}
}

View File

@ -0,0 +1,25 @@
package gearth.extensions.parsers;
public enum HProductType {
WallItem("I"),
FloorItem("S"),
Effect("E"),
Badge("B");
private String id;
HProductType(String id) {
this.id = id;
}
public String toString() {
return id;
}
public static HProductType fromString(String id) {
for (HProductType t : HProductType.values()) {
if (t.toString().equalsIgnoreCase(id.toLowerCase())) return t;
}
return null;
}
}

View File

@ -0,0 +1,25 @@
package gearth.extensions.parsers;
public enum HRelationshipStatus {
NONE (0),
HEART (1),
SMILEY (2),
SKULL (3);
private final int id;
HRelationshipStatus(int id) {
this.id = id;
}
public int getId() {
return id;
}
public static HRelationshipStatus fromId(int id) {
for(HRelationshipStatus status : HRelationshipStatus.values()) {
if(status.id == id) return status;
}
return null;
}
}

View File

@ -0,0 +1,44 @@
package gearth.extensions.parsers;
public enum HSpecialType {
Default (1),
WallPaper (2),
FloorPaint (3),
Landscape (4),
PostIt (5),
Poster (6),
SoundSet (7),
TraxSong (8),
Present (9),
EcotronBox (10),
Trophy (11),
CreditFurni (12),
PetShampoo (13),
PetCustomPart (14),
PetCustomPartShampoo (15),
PetSaddle (16),
GuildFurni (17),
GameFurni (18),
MonsterplantSeed (19),
MonsterplantRevival (20),
MonsterplantRebreed (21),
MonsterplantFertilize (22),
FigurePurchasableSet (23);
private final int id;
HSpecialType(int id) {
this.id = id;
}
public int getId() {
return id;
}
public static HSpecialType fromId(int id) {
for(HSpecialType value : HSpecialType.values()) {
if(value.id == id) return value;
}
return null;
}
}

View File

@ -0,0 +1,27 @@
package gearth.extensions.parsers.catalog;
import gearth.protocol.HPacket;
public class HCatalogIndex {
private final HCatalogPageIndex root;
private final boolean newAdditionsAvailable;
private final String catalogType;
public HCatalogPageIndex getRoot() {
return root;
}
public boolean isNewAdditionsAvailable() {
return newAdditionsAvailable;
}
public String getCatalogType() {
return catalogType;
}
public HCatalogIndex(HPacket packet) {
this.root = new HCatalogPageIndex(packet);
this.newAdditionsAvailable = packet.readBoolean();
this.catalogType = packet.readString();
}
}

View File

@ -0,0 +1,84 @@
package gearth.extensions.parsers.catalog;
import gearth.protocol.HPacket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class HCatalogPage {
private int pageId;
private String catalogType, layoutCode;
private String[] images, texts;
private List<HOffer> offers = new ArrayList<>();
private int offerId;
private boolean acceptSeasonCurrencyAsCredits;
private List<HFrontPageItem> frontPageItems = new ArrayList<>();
public HCatalogPage(HPacket packet) {
this.pageId = packet.readInteger();
this.catalogType = packet.readString();
this.layoutCode = packet.readString();
this.images = new String[packet.readInteger()];
for(int i = 0; i < this.images.length; i++) {
this.images[i] = packet.readString();
}
this.texts = new String[packet.readInteger()];
for(int i = 0; i < this.texts.length; i++) {
this.texts[i] = packet.readString();
}
int offerCount = packet.readInteger();
for(int i = 0; i < offerCount; i++) {
this.offers.add(new HOffer(packet));
}
this.offerId = packet.readInteger();
this.acceptSeasonCurrencyAsCredits = packet.readBoolean();
if(packet.getReadIndex() < packet.getBytesLength()) {
int frontPageItemsCount = packet.readInteger();
for(int i = 0; i < frontPageItemsCount; i++) {
this.frontPageItems.add(new HFrontPageItem(packet));
}
}
}
public int getPageId() {
return pageId;
}
public String getCatalogType() {
return catalogType;
}
public String getLayoutCode() {
return layoutCode;
}
public String[] getImages() {
return images;
}
public String[] getTexts() {
return texts;
}
public List<HOffer> getOffers() {
return Collections.unmodifiableList(offers);
}
public int getOfferId() {
return offerId;
}
public boolean isAcceptSeasonCurrencyAsCredits() {
return acceptSeasonCurrencyAsCredits;
}
public List<HFrontPageItem> getFrontPageItems() {
return Collections.unmodifiableList(frontPageItems);
}
}

View File

@ -0,0 +1,61 @@
package gearth.extensions.parsers.catalog;
import gearth.protocol.HPacket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class HCatalogPageIndex {
private final boolean visible;
private final int icon, pageId;
private final String pageName, localization;
private final List<Integer> offerIds = new ArrayList<>();
private final List<HCatalogPageIndex> children = new ArrayList<>();
public boolean isVisible() {
return visible;
}
public int getIcon() {
return icon;
}
public int getPageId() {
return pageId;
}
public String getPageName() {
return pageName;
}
public String getLocalization() {
return localization;
}
public List<Integer> getOfferIds() {
return Collections.unmodifiableList(offerIds);
}
public List<HCatalogPageIndex> getChildren() {
return Collections.unmodifiableList(children);
}
protected HCatalogPageIndex(HPacket packet) {
this.visible = packet.readBoolean();
this.icon = packet.readInteger();
this.pageId = packet.readInteger();
this.pageName = packet.readString();
this.localization = packet.readString();
int offerCount = packet.readInteger();
for(int i = 0; i < offerCount; i++) {
this.offerIds.add(packet.readInteger());
}
int childCount = packet.readInteger();
for(int i = 0; i < childCount; i++) {
this.children.add(new HCatalogPageIndex(packet));
}
}
}

View File

@ -0,0 +1,35 @@
package gearth.extensions.parsers.catalog;
import gearth.protocol.HPacket;
public class HFrontPageItem {
private int position;
private String itemName;
private String itemPromoImage;
private int type;
private String cataloguePageLocation;
private int productOfferId = -1;
private String productCode;
private int expirationTime;
protected HFrontPageItem(HPacket packet) {
this.position = packet.readInteger();
this.itemName = packet.readString();
this.itemPromoImage = packet.readString();
this.type = packet.readInteger();
switch(type) {
case 0:
this.cataloguePageLocation = packet.readString();
break;
case 1:
this.productOfferId = packet.readInteger();
break;
case 2:
this.productCode = packet.readString();
break;
}
this.expirationTime = packet.readInteger();
}
}

View File

@ -0,0 +1,91 @@
package gearth.extensions.parsers.catalog;
import gearth.protocol.HPacket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class HOffer {
private int offerId;
private String localizationId;
private boolean rent;
private int priceInCredits;
private int priceInActivityPoints;
private int activityPointType;
private boolean giftable;
private List<HProduct> products = new ArrayList<>();
private int clubLevel;
private boolean bundlePurchaseAllowed;
private boolean unused;
private String previewImage;
protected HOffer(HPacket packet) {
this.offerId = packet.readInteger();
this.localizationId = packet.readString();
this.rent = packet.readBoolean();
this.priceInCredits = packet.readInteger();
this.priceInActivityPoints = packet.readInteger();
this.activityPointType = packet.readInteger();
this.giftable = packet.readBoolean();
int productCount = packet.readInteger();
for(int i = 0; i < productCount; i++) {
this.products.add(new HProduct(packet));
}
this.clubLevel = packet.readInteger();
this.bundlePurchaseAllowed = packet.readBoolean();
this.unused = packet.readBoolean();
this.previewImage = packet.readString();
}
public int getOfferId() {
return offerId;
}
public String getLocalizationId() {
return localizationId;
}
public boolean isRent() {
return rent;
}
public int getPriceInCredits() {
return priceInCredits;
}
public int getPriceInActivityPoints() {
return priceInActivityPoints;
}
public int getActivityPointType() {
return activityPointType;
}
public boolean isGiftable() {
return giftable;
}
public List<HProduct> getProducts() {
return Collections.unmodifiableList(products);
}
public int getClubLevel() {
return clubLevel;
}
public boolean isBundlePurchaseAllowed() {
return bundlePurchaseAllowed;
}
public boolean isUnused() {
return unused;
}
public String getPreviewImage() {
return previewImage;
}
}

View File

@ -0,0 +1,58 @@
package gearth.extensions.parsers.catalog;
import gearth.extensions.parsers.HProductType;
import gearth.protocol.HPacket;
public class HProduct {
private HProductType productType;
private int furniClassId = -1;
private String extraParam;
private int productCount = 1;
private boolean uniqueLimitedItem = false;
private int uniqueLimitedItemSeriesSize = -1;
private int uniqueLimitedItemsLeft = -1;
protected HProduct(HPacket packet) {
this.productType = HProductType.fromString(packet.readString());
if(this.productType != HProductType.Badge) {
this.furniClassId = packet.readInteger();
this.extraParam = packet.readString();
this.productCount = packet.readInteger();
this.uniqueLimitedItem = packet.readBoolean();
if(this.uniqueLimitedItem) {
this.uniqueLimitedItemSeriesSize = packet.readInteger();
this.uniqueLimitedItemsLeft = packet.readInteger();
}
} else {
this.extraParam = packet.readString();
}
}
public HProductType getProductType() {
return productType;
}
public int getFurniClassId() {
return furniClassId;
}
public String getExtraParam() {
return extraParam;
}
public int getProductCount() {
return productCount;
}
public boolean isUniqueLimitedItem() {
return uniqueLimitedItem;
}
public int getUniqueLimitedItemSeriesSize() {
return uniqueLimitedItemSeriesSize;
}
public int getUniqueLimitedItemsLeft() {
return uniqueLimitedItemsLeft;
}
}