Skip to content

Commit

Permalink
switch to the new packets mapping for wows
Browse files Browse the repository at this point in the history
  • Loading branch information
Monstrofil committed Jul 23, 2023
1 parent fc6dc57 commit 8a3b2a5
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/wot_parser/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, version):
def _get_definitions(self, version):
return Definitions(os.path.join(BASE_DIR, 'versions', version.replace('.', '_')))

def _get_packets_mapping(self):
def _get_packets_mapping(self, version):
return {
31: Tick,
0x20: Test,
Expand Down
2 changes: 1 addition & 1 deletion examples/wows_parser_2/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, stream):

class ReplayPlayer(WoWSReplayPlayer):

def _get_packets_mapping(self):
def _get_packets_mapping(self, version):
return {
0x18: UnknownPacket,
}
Expand Down
2 changes: 1 addition & 1 deletion replay_unpack/clients/wot/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _get_definitions(self, version):
def _get_controller(self, version):
return get_controller(version)

def _get_packets_mapping(self):
def _get_packets_mapping(self, version):
return PACKETS_MAPPING

def _process_packet(self, time, packet):
Expand Down
2 changes: 1 addition & 1 deletion replay_unpack/clients/wowp/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _get_controller(self, version):
except RuntimeError:
return get_controller('_'.join(version[:3]))

def _get_packets_mapping(self):
def _get_packets_mapping(self, version):
return PACKETS_MAPPING

def _process_packet(self, time, packet):
Expand Down
19 changes: 15 additions & 4 deletions replay_unpack/clients/wows/network/packets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .Map import Map
from .PlayerPosition import PlayerPosition

PACKETS_MAPPING = {
PACKETS_MAPPING_GENERIC = {
0x0: BasePlayerCreate,
0x1: CellPlayerCreate,
0x2: EntityControl,
Expand All @@ -25,13 +25,23 @@
# 0x6
0x7: EntityProperty,
0x8: EntityMethod,
0x27: Map,
0x22: NestedProperty,
0x0a: Position,
0x16: Version,
0x2b: PlayerPosition
}

PACKETS_MAPPING = {
**PACKETS_MAPPING_GENERIC,
0x27: Map,
0x22: NestedProperty,
}

PACKETS_MAPPING_12_6 = {
**PACKETS_MAPPING_GENERIC,
0x23: NestedProperty,
0x28: Map,
}

__all__ = [
'EntityMethod',
'Map',
Expand All @@ -46,5 +56,6 @@
'NestedProperty',
'PlayerPosition',
'Version',
'PACKETS_MAPPING'
'PACKETS_MAPPING',
'PACKETS_MAPPING_12_6'
]
9 changes: 6 additions & 3 deletions replay_unpack/clients/wows/player.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding=utf-8
import logging
import struct
from distutils.version import LooseVersion
from io import BytesIO

from replay_unpack.core import (
Expand All @@ -21,13 +22,13 @@
EntityLeave,
PlayerPosition,
Version,
PACKETS_MAPPING
PACKETS_MAPPING,
PACKETS_MAPPING_12_6
)

last_gap = 0
last_negative = 0xffffffff
class ReplayPlayer(ControlledPlayerBase):

def _get_definitions(self, version):
try:
return get_definitions('_'.join(version[:4]))
Expand All @@ -40,7 +41,9 @@ def _get_controller(self, version):
except RuntimeError:
return get_controller('_'.join(version[:3]))

def _get_packets_mapping(self):
def _get_packets_mapping(self, version):
if LooseVersion('.'.join(version)) >= LooseVersion('12.6.0'):
return PACKETS_MAPPING_12_6
return PACKETS_MAPPING

def _process_packet(self, time, packet):
Expand Down
4 changes: 2 additions & 2 deletions replay_unpack/core/network/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class PlayerBase:
def __init__(self, version: str):
self._definitions = self._get_definitions(version)

self._mapping = self._get_packets_mapping()
self._mapping = self._get_packets_mapping(version)

def _get_definitions(self, version):
raise NotImplementedError

def _get_packets_mapping(self):
def _get_packets_mapping(self, version):
raise NotImplementedError

def _deserialize_packet(self, packet: NetPacket):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ tqdm
mock
ddt
raven
lxml
lxml
distutils

0 comments on commit 8a3b2a5

Please sign in to comment.