refactoring. Decrypting new packet.

This commit is contained in:
Michael Wain 2024-06-02 04:41:50 +03:00
parent c2c17f1f24
commit f71f61e51b
4 changed files with 1032 additions and 285 deletions

View File

@ -2,6 +2,7 @@ package com.alterdekim.hearthhack.component;
import com.alterdekim.hearthhack.component.processor.*;
import com.alterdekim.hearthhack.util.BattleNetPacket;
import com.alterdekim.hearthhack.util.Util;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@ -36,6 +37,7 @@ public class TcpConnection extends Thread {
}
public void send(BattleNetPacket bp) throws Exception {
log.info("TcpConnection.send: service={}, method={}, body={}", bp.getHeader().getServiceId(), bp.getHeader().getMethodId(), Util.bytesToHex(bp.getBody()));
this.outToClient.write(bp.Encode());
this.outToClient.flush();
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,99 @@
package com.alterdekim.hearthhack.util;
import com.google.protobuf.GeneratedMessageV3;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class PegasusPacket {
private final int TYPE_BYTES = 4;
private final int SIZE_BYTES = 4;
public int size;
public int type;
public int context;
public Object body;
private boolean sizeRead;
private boolean typeRead;
public PegasusPacket(int type, int context, Object body) {
this.type = type;
this.context = context;
this.size = -1;
this.body = body;
}
public PegasusPacket(int type, int context, int size, Object body) {
this.type = type;
this.context = context;
this.size = size;
this.body = body;
}
public Object GetBody() {
return this.body;
}
public boolean IsLoaded() {
return this.body != null;
}
public int Decode(byte[] bytes, int offset, int available) {
String arg = "";
int num = 0;
while (num < 8 && num < available) {
arg = arg + bytes[offset + num] + " ";
num++;
}
int num2 = 0;
if (!this.typeRead) {
if (available < 4) return num2;
this.type = toInt32_2(bytes, offset);
this.typeRead = true;
available -= 4;
num2 += 4;
offset += 4;
}
if (!this.sizeRead) {
if (available < 4) return num2;
this.size = toInt32_2(bytes, offset);
this.sizeRead = true;
available -= 4;
num2 += 4;
offset += 4;
}
if (this.body == null) {
if (available < this.size) return num2;
byte[] array = new byte[this.size];
System.arraycopy(bytes, offset, array, 0, this.size);
this.body = array;
num2 += this.size;
}
return num2;
}
/*public byte[] Encode() {
if (this.body instanceof GeneratedMessageV3) {
GeneratedMessageV3 protoBuf = (GeneratedMessageV3) this.body;
this.size = (int) protoBuf.GetSerializedSize();
byte[] array = new byte[this.size + 4 + 4];
Array.Copy(BitConverter.GetBytes(this.Type), 0, array, 0, 4);
Array.Copy(BitConverter.GetBytes(this.Size), 0, array, 4, 4);
protoBuf.Serialize(new MemoryStream(array, 8, this.Size));
return array;
}
return null;
}*/
private int toInt32_2(byte[] bytes, int index) {
int a = (int)((int)(0xff & bytes[index]) << 32 | (int)(0xff & bytes[index + 1]) << 40 | (int)(0xff & bytes[index + 2]) << 48 | (int)(0xff & bytes[index + 3]) << 56);
return a;
}
}

View File

@ -2613,4 +2613,429 @@ message CardValues {
repeated CardValue cards = 1;
required int32 card_nerf_index = 2;
}
// ref: PegasusUtil.RewardProgress
message RewardProgress {
// ref: PegasusUtil.RewardProgress/PacketID
enum PacketID {
ID = 271;
}
required Date season_end = 1;
required int32 wins_per_gold = 2;
required int32 gold_per_reward = 3;
required int32 max_gold_per_day = 4;
required int32 season_number = 5;
optional int32 pack_id = 8;
required int32 xp_solo_limit = 9;
required int32 max_hero_level = 10;
required Date next_quest_cancel = 11;
required float event_timing_mod = 12;
}
// ref: PegasusUtil.PlayerRecord
message PlayerRecord {
required GameType type = 1;
optional int32 data = 2;
required int32 wins = 3;
required int32 losses = 4;
optional int32 ties = 5;
}
// ref: PegasusShared.GameType
enum GameType {
GT_UNKNOWN = 0;
GT_VS_AI = 1;
GT_VS_FRIEND = 2;
GT_TUTORIAL = 4;
GT_ARENA = 5;
GT_TEST = 6;
GT_RANKED = 7;
GT_CASUAL = 8;
GT_TAVERNBRAWL = 16;
GT_TB_1P_VS_AI = 17;
GT_TB_2P_COOP = 18;
GT_LAST = 19;
}
// ref: PegasusUtil.PlayerRecords
message PlayerRecords {
// ref: PegasusUtil.PlayerRecords/PacketID
enum PacketID {
ID = 270;
}
repeated PlayerRecord records = 1;
}
// ref: PegasusUtil.ArcaneDustBalance
message ArcaneDustBalance {
// ref: PegasusUtil.ArcaneDustBalance/PacketID
enum PacketID {
ID = 262;
}
required int64 balance = 1;
}
// ref: PegasusUtil.ClientOptions
message ClientOptions {
// ref: PegasusUtil.ClientOptions/PacketID
enum PacketID {
ID = 241;
}
repeated ClientOption options = 1;
optional bool failed = 2;
}
// ref: PegasusUtil.AdventureProgressResponse
message AdventureProgressResponse {
// ref: PegasusUtil.AdventureProgressResponse/PacketID
enum PacketID {
ID = 306;
}
repeated AdventureProgress list = 1;
}
// ref: PegasusShared.AdventureProgress
message AdventureProgress {
// ref: PegasusShared.AdventureProgress/Flags
enum Flags {
OWNED = 1;
DEFEAT_HEROIC_MISSION_1 = 2;
DEFEAT_HEROIC_MISSION_2 = 4;
DEFEAT_HEROIC_MISSION_3 = 8;
DEFEAT_HEROIC_MISSION_4 = 16;
DEFEAT_CLASS_CHALLENGE_MISSION_1 = 256;
DEFEAT_CLASS_CHALLENGE_MISSION_2 = 512;
}
required int32 wing_id = 1;
required int32 progress = 2;
optional int32 ack = 3 [default = 0];
required uint64 flags = 4;
}
// ref: PegasusUtil.HeroXP
message HeroXP {
// ref: PegasusUtil.HeroXP/PacketID
enum PacketID {
ID = 283;
}
repeated HeroXPInfo xp_infos = 1;
}
// ref: PegasusUtil.HeroXPInfo
message HeroXPInfo {
required int32 class_id = 1;
required int32 level = 2;
required int64 curr_xp = 3;
required int64 max_xp = 4;
optional NextHeroLevelReward next_reward = 5;
}
// ref: PegasusUtil.NextHeroLevelReward
message NextHeroLevelReward {
required int32 level = 1;
optional ProfileNoticeRewardBooster reward_booster = 2;
optional ProfileNoticeRewardCard reward_card = 3;
optional ProfileNoticeRewardDust reward_dust = 4;
optional ProfileNoticeRewardGold reward_gold = 5;
optional ProfileNoticeRewardMount reward_mount = 6;
optional ProfileNoticeRewardForge reward_forge = 7;
}
// ref: PegasusShared.ProfileNoticeRewardForge
message ProfileNoticeRewardForge {
// ref: PegasusShared.ProfileNoticeRewardForge/NoticeID
enum NoticeID {
ID = 8;
}
required int32 quantity = 1;
}
// ref: PegasusShared.ProfileNoticeRewardMount
message ProfileNoticeRewardMount {
// ref: PegasusShared.ProfileNoticeRewardMount/NoticeID
enum NoticeID {
ID = 7;
}
required int32 mount_id = 1;
}
// ref: PegasusShared.ProfileNoticeRewardGold
message ProfileNoticeRewardGold {
// ref: PegasusShared.ProfileNoticeRewardGold/NoticeID
enum NoticeID {
ID = 9;
}
required int32 amount = 1;
}
// ref: PegasusShared.ProfileNoticeRewardDust
message ProfileNoticeRewardDust {
// ref: PegasusShared.ProfileNoticeRewardDust/NoticeID
enum NoticeID {
ID = 6;
}
required int32 amount = 1;
}
// ref: PegasusShared.ProfileNoticeRewardCard
message ProfileNoticeRewardCard {
// ref: PegasusShared.ProfileNoticeRewardCard/NoticeID
enum NoticeID {
ID = 3;
}
required CardDef card = 1;
optional int32 quantity = 2;
}
// ref: PegasusShared.ProfileNoticeRewardBooster
message ProfileNoticeRewardBooster {
// ref: PegasusShared.ProfileNoticeRewardBooster/NoticeID
enum NoticeID {
ID = 2;
}
required int32 booster_type = 1;
required int32 booster_count = 2;
}
// ref: PegasusUtil.FavoriteHeroesResponse
message FavoriteHeroesResponse {
// ref: PegasusUtil.FavoriteHeroesResponse/PacketID
enum PacketID {
ID = 318;
}
repeated FavoriteHero favorite_heroes = 1;
}
// ref: PegasusShared.FavoriteHero
message FavoriteHero {
required int32 class_id = 1;
required CardDef hero = 2;
}
// ref: PegasusUtil.CardBacks
message CardBacks {
// ref: PegasusUtil.CardBacks/PacketID
enum PacketID {
system = 0;
ID = 236;
}
required int32 default_card_back = 1;
repeated int32 card_backs = 2;
}
// ref: PegasusUtil.AccountLicensesInfoResponse
message AccountLicensesInfoResponse {
// ref: PegasusUtil.AccountLicensesInfoResponse/PacketID
enum PacketID {
ID = 325;
}
repeated AccountLicenseInfo list = 1;
}
// ref: PegasusShared.AccountLicenseInfo
message AccountLicenseInfo {
// ref: PegasusShared.AccountLicenseInfo/Flags
enum Flags {
OWNED = 1;
}
required int64 license = 1;
required uint64 flags = 2;
required int64 cas_id = 3;
}
// ref: PegasusUtil.ProfileNotice
message ProfileNotice {
required int64 entry = 1;
optional ProfileNoticeMedal medal = 2;
optional ProfileNoticeRewardBooster reward_booster = 3;
optional ProfileNoticeRewardCard reward_card = 4;
optional ProfileNoticePreconDeck precon_deck = 6;
optional ProfileNoticeRewardDust reward_dust = 7;
optional ProfileNoticeRewardGold reward_gold = 8;
optional ProfileNoticeRewardMount reward_mount = 9;
optional ProfileNoticeRewardForge reward_forge = 10;
required int32 origin = 11;
optional int64 origin_data = 12;
required Date when = 13;
optional ProfileNoticePurchase purchase = 14;
optional ProfileNoticeCardBack reward_card_back = 15;
optional ProfileNoticeDisconnectedGameResult dc_game_result = 16;
optional ProfileNoticeBonusStars bonus_stars = 17;
optional ProfileNoticeAdventureProgress adventure_progress = 18;
optional ProfileNoticeLevelUp level_up = 19;
optional ProfileNoticeAccountLicense account_license = 20;
}
// ref: PegasusUtil.ProfileNotices
message ProfileNotices {
// ref: PegasusUtil.ProfileNotices/PacketID
enum PacketID {
ID = 212;
}
repeated ProfileNotice list = 1;
}
// ref: PegasusShared.ProfileNoticeMedal
message ProfileNoticeMedal {
// ref: PegasusShared.ProfileNoticeMedal/MedalType
enum MedalType {
UNKNOWN_MEDAL = 0;
STANDARD_MEDAL = 1;
WILD_MEDAL = 2;
}
// ref: PegasusShared.ProfileNoticeMedal/NoticeID
enum NoticeID {
ID = 1;
}
required int32 star_level = 1;
optional int32 legend_rank = 2;
optional int32 best_star_level = 3;
optional RewardChest chest = 4;
optional MedalType medal_type = 5 [default = UNKNOWN_MEDAL];
}
// ref: PegasusShared.ProfileNoticePreconDeck
message ProfileNoticePreconDeck {
// ref: PegasusShared.ProfileNoticePreconDeck/NoticeID
enum NoticeID {
ID = 5;
}
required int64 deck = 1;
required int32 hero = 2;
}
// ref: PegasusShared.ProfileNoticePurchase
message ProfileNoticePurchase {
// ref: PegasusShared.ProfileNoticePurchase/NoticeID
enum NoticeID {
ID = 10;
}
required string product_id = 1;
optional int64 data = 2;
optional int32 currency = 3;
}
// ref: PegasusShared.ProfileNoticeCardBack
message ProfileNoticeCardBack {
// ref: PegasusShared.ProfileNoticeCardBack/NoticeID
enum NoticeID {
ID = 11;
}
required int32 card_back = 1;
}
// ref: PegasusShared.ProfileNoticeDisconnectedGameResult
message ProfileNoticeDisconnectedGameResult {
// ref: PegasusShared.ProfileNoticeDisconnectedGameResult/GameResult
enum GameResult {
GR_UNKNOWN = 0;
GR_PLAYING = 1;
GR_WINNER = 2;
GR_TIE = 3;
}
// ref: PegasusShared.ProfileNoticeDisconnectedGameResult/NoticeID
enum NoticeID {
ID = 4;
}
// ref: PegasusShared.ProfileNoticeDisconnectedGameResult/PlayerResult
enum PlayerResult {
PR_UNKNOWN = 0;
PR_WON = 1;
PR_LOST = 2;
PR_DISCONNECTED = 3;
PR_QUIT = 4;
}
optional GameType game_type = 8 [default = GT_UNKNOWN];
optional int32 mission_id = 9;
optional GameResult game_result = 10 [default = GR_UNKNOWN];
optional PlayerResult your_result = 11 [default = PR_UNKNOWN];
optional PlayerResult opponent_result = 12 [default = PR_UNKNOWN];
}
// ref: PegasusShared.ProfileNoticeBonusStars
message ProfileNoticeBonusStars {
// ref: PegasusShared.ProfileNoticeBonusStars/NoticeID
enum NoticeID {
ID = 12;
}
required int32 star_level = 1;
required int32 stars = 2;
}
// ref: PegasusShared.ProfileNoticeAdventureProgress
message ProfileNoticeAdventureProgress {
// ref: PegasusShared.ProfileNoticeAdventureProgress/NoticeID
enum NoticeID {
ID = 14;
}
required int32 wing_id = 1;
}
// ref: PegasusShared.ProfileNoticeLevelUp
message ProfileNoticeLevelUp {
// ref: PegasusShared.ProfileNoticeLevelUp/NoticeID
enum NoticeID {
ID = 15;
}
required int32 hero_class = 1;
required int32 new_level = 2;
}
// ref: PegasusShared.ProfileNoticeAccountLicense
message ProfileNoticeAccountLicense {
// ref: PegasusShared.ProfileNoticeAccountLicense/NoticeID
enum NoticeID {
ID = 16;
}
required int64 license = 1;
required int64 cas_id = 2;
}
// ref: PegasusShared.RewardBag
message RewardBag {
optional ProfileNoticeRewardBooster reward_booster = 1;
optional ProfileNoticeRewardCard reward_card = 2;
optional ProfileNoticeRewardDust reward_dust = 3;
optional ProfileNoticeRewardGold reward_gold = 4;
optional ProfileNoticeCardBack reward_card_back = 5;
}
// ref: PegasusShared.RewardChest
message RewardChest {
optional RewardBag bag1 = 1;
optional RewardBag bag2 = 2;
optional RewardBag bag3 = 3;
optional RewardBag bag4 = 4;
optional RewardBag bag5 = 5;
}