|
|
""" |
|
|
League of Legends Replay Packet Definitions |
|
|
""" |
|
|
|
|
|
from dataclasses import dataclass |
|
|
from typing import Dict, List, Optional, Union |
|
|
from enum import Enum |
|
|
|
|
|
@dataclass |
|
|
class Position: |
|
|
"""2D position on the game map""" |
|
|
x: float |
|
|
z: float |
|
|
|
|
|
class AIType(Enum): |
|
|
"""Type of AI entity""" |
|
|
UNKNOWN = "Unknown" |
|
|
HERO = "Hero" |
|
|
MINION = "Minion" |
|
|
TURRET = "Turret" |
|
|
NEUTRAL = "Neutral" |
|
|
|
|
|
class ReplicationInternalData: |
|
|
"""Internal replication data that can be int or float""" |
|
|
def __init__(self, value: Union[int, float]): |
|
|
self.value = value |
|
|
self.is_int = isinstance(value, int) |
|
|
self.is_float = isinstance(value, float) |
|
|
|
|
|
@dataclass |
|
|
class CreateHero: |
|
|
"""Packet for hero/champion creation""" |
|
|
time: float |
|
|
net_id: int |
|
|
name: str |
|
|
champion: str |
|
|
|
|
|
@dataclass |
|
|
class WaypointGroup: |
|
|
"""Packet containing movement waypoints for entities""" |
|
|
time: float |
|
|
waypoints: Dict[int, List[Position]] |
|
|
|
|
|
@dataclass |
|
|
class WaypointGroupWithSpeed: |
|
|
"""Packet containing movement waypoints with speed data""" |
|
|
time: float |
|
|
waypoints: Dict[int, List[Position]] |
|
|
|
|
|
@dataclass |
|
|
class EnterFog: |
|
|
"""Packet for entity entering fog of war""" |
|
|
time: float |
|
|
net_id: int |
|
|
|
|
|
@dataclass |
|
|
class LeaveFog: |
|
|
"""Packet for entity leaving fog of war""" |
|
|
time: float |
|
|
net_id: int |
|
|
|
|
|
@dataclass |
|
|
class UnitApplyDamage: |
|
|
"""Packet for damage application between units""" |
|
|
time: float |
|
|
source_net_id: int |
|
|
target_net_id: int |
|
|
damage: float |
|
|
|
|
|
@dataclass |
|
|
class DoSetCooldown: |
|
|
"""Packet for ability cooldown updates""" |
|
|
time: float |
|
|
net_id: int |
|
|
slot: int |
|
|
cooldown: float |
|
|
display_cooldown: float |
|
|
|
|
|
@dataclass |
|
|
class BasicAttackPos: |
|
|
"""Packet for basic attack with positional data""" |
|
|
time: float |
|
|
source_net_id: int |
|
|
target_net_id: int |
|
|
source_position: Position |
|
|
target_position: Position |
|
|
slot: int |
|
|
caster_net_id: int |
|
|
spell_chain_owner_net_id: int |
|
|
spell_hash: int |
|
|
spell_name: str |
|
|
level: int |
|
|
target_end_position: Position |
|
|
target_net_ids: List[int] |
|
|
windup_time: float |
|
|
cooldown: float |
|
|
mana_cost: float |
|
|
|
|
|
@dataclass |
|
|
class CastSpellAns: |
|
|
"""Packet for spell casting""" |
|
|
time: float |
|
|
caster_net_id: int |
|
|
spell_chain_owner_net_id: int |
|
|
spell_hash: int |
|
|
spell_name: str |
|
|
level: int |
|
|
source_position: Position |
|
|
target_position: Position |
|
|
target_end_position: Position |
|
|
target_net_ids: List[int] |
|
|
windup_time: float |
|
|
cooldown: float |
|
|
mana_cost: float |
|
|
slot: int |
|
|
|
|
|
@dataclass |
|
|
class BarrackSpawnUnit: |
|
|
"""Packet for minion spawning from barracks""" |
|
|
time: float |
|
|
barrack_net_id: int |
|
|
minion_net_id: int |
|
|
wave_count: int |
|
|
minion_type: int |
|
|
minion_level: int |
|
|
|
|
|
@dataclass |
|
|
class ReplicationData: |
|
|
"""Replication data for game state synchronization""" |
|
|
primary_index: int |
|
|
secondary_index: int |
|
|
name: str |
|
|
data: ReplicationInternalData |
|
|
|
|
|
@dataclass |
|
|
class Replication: |
|
|
"""Packet containing replication data for multiple entities""" |
|
|
time: float |
|
|
net_id_to_replication_datas: Dict[int, ReplicationData] |
|
|
|
|
|
@dataclass |
|
|
class SpawnMinion: |
|
|
"""Packet for minion spawning""" |
|
|
time: float |
|
|
net_id: int |
|
|
position1: Position |
|
|
position2: Position |
|
|
name: str |
|
|
skin_name: str |
|
|
level: int |
|
|
targetable_on_client: int |
|
|
targetable_to_team_flags_on_client: int |
|
|
bot: bool |
|
|
|
|
|
@dataclass |
|
|
class CreateNeutral: |
|
|
"""Packet for neutral monster creation""" |
|
|
time: float |
|
|
net_id: int |
|
|
position1: Position |
|
|
position2: Position |
|
|
name: str |
|
|
skin_name: str |
|
|
level: int |
|
|
direction: Position |
|
|
camp_id: int |
|
|
neutral_type: int |
|
|
|
|
|
@dataclass |
|
|
class CreateTurret: |
|
|
"""Packet for turret creation""" |
|
|
time: float |
|
|
net_id: int |
|
|
owner_net_id: int |
|
|
name: str |
|
|
|
|
|
@dataclass |
|
|
class NPCDieMapView: |
|
|
"""Packet for NPC death (map view)""" |
|
|
time: float |
|
|
killer_net_id: int |
|
|
killed_net_id: int |
|
|
|
|
|
@dataclass |
|
|
class NPCDieMapViewBroadcast: |
|
|
"""Packet for NPC death broadcast""" |
|
|
time: float |
|
|
killer_net_id: int |
|
|
killed_net_id: int |
|
|
|
|
|
@dataclass |
|
|
class HeroDie: |
|
|
"""Packet for hero/champion death""" |
|
|
time: float |
|
|
net_id: int |
|
|
|
|
|
@dataclass |
|
|
class BuyItem: |
|
|
"""Packet for item purchase""" |
|
|
time: float |
|
|
net_id: int |
|
|
slot: int |
|
|
item_id: int |
|
|
item_name: str |
|
|
items_in_slot: int |
|
|
spell_charges: int |
|
|
item_gold: float |
|
|
entity_gold_after_change: float |
|
|
|
|
|
@dataclass |
|
|
class RemoveItem: |
|
|
"""Packet for item removal""" |
|
|
time: float |
|
|
net_id: int |
|
|
slot: int |
|
|
items_in_slot: int |
|
|
entity_gold_after_change: float |
|
|
|
|
|
@dataclass |
|
|
class SwapItem: |
|
|
"""Packet for item slot swapping""" |
|
|
time: float |
|
|
net_id: int |
|
|
source_slot: int |
|
|
target_slot: int |
|
|
|
|
|
@dataclass |
|
|
class UseItem: |
|
|
"""Packet for item usage""" |
|
|
time: float |
|
|
net_id: int |
|
|
slot: int |
|
|
items_in_slot: int |
|
|
spell_charges: int |
|
|
|
|
|
|
|
|
PacketType = Union[ |
|
|
CreateHero, |
|
|
WaypointGroup, |
|
|
WaypointGroupWithSpeed, |
|
|
EnterFog, |
|
|
LeaveFog, |
|
|
UnitApplyDamage, |
|
|
DoSetCooldown, |
|
|
BasicAttackPos, |
|
|
CastSpellAns, |
|
|
BarrackSpawnUnit, |
|
|
Replication, |
|
|
SpawnMinion, |
|
|
CreateNeutral, |
|
|
CreateTurret, |
|
|
NPCDieMapView, |
|
|
NPCDieMapViewBroadcast, |
|
|
HeroDie, |
|
|
BuyItem, |
|
|
RemoveItem, |
|
|
SwapItem, |
|
|
UseItem |
|
|
] |
|
|
|
|
|
def parse_packet_from_dict(packet_dict: dict) -> PacketType: |
|
|
""" |
|
|
Parse a packet dictionary into the appropriate packet dataclass. |
|
|
|
|
|
Args: |
|
|
packet_dict: Dictionary containing packet data with 'packet_type' field |
|
|
|
|
|
Returns: |
|
|
Appropriate packet dataclass instance |
|
|
|
|
|
Raises: |
|
|
ValueError: If packet_type is unknown |
|
|
""" |
|
|
packet_type = packet_dict.get('packet_type') |
|
|
|
|
|
|
|
|
data = {k: v for k, v in packet_dict.items() if k != 'packet_type'} |
|
|
|
|
|
|
|
|
def convert_positions(obj): |
|
|
if isinstance(obj, dict): |
|
|
if 'x' in obj and 'z' in obj and len(obj) == 2: |
|
|
return Position(x=obj['x'], z=obj['z']) |
|
|
return {k: convert_positions(v) for k, v in obj.items()} |
|
|
elif isinstance(obj, list): |
|
|
return [convert_positions(item) for item in obj] |
|
|
return obj |
|
|
|
|
|
data = convert_positions(data) |
|
|
|
|
|
|
|
|
packet_classes = { |
|
|
'CreateHero': CreateHero, |
|
|
'WaypointGroup': WaypointGroup, |
|
|
'WaypointGroupWithSpeed': WaypointGroupWithSpeed, |
|
|
'EnterFog': EnterFog, |
|
|
'LeaveFog': LeaveFog, |
|
|
'UnitApplyDamage': UnitApplyDamage, |
|
|
'DoSetCooldown': DoSetCooldown, |
|
|
'BasicAttackPos': BasicAttackPos, |
|
|
'CastSpellAns': CastSpellAns, |
|
|
'BarrackSpawnUnit': BarrackSpawnUnit, |
|
|
'Replication': Replication, |
|
|
'SpawnMinion': SpawnMinion, |
|
|
'CreateNeutral': CreateNeutral, |
|
|
'CreateTurret': CreateTurret, |
|
|
'NPCDieMapView': NPCDieMapView, |
|
|
'NPCDieMapViewBroadcast': NPCDieMapViewBroadcast, |
|
|
'HeroDie': HeroDie, |
|
|
'BuyItem': BuyItem, |
|
|
'RemoveItem': RemoveItem, |
|
|
'SwapItem': SwapItem, |
|
|
'UseItem': UseItem |
|
|
} |
|
|
|
|
|
if packet_type not in packet_classes: |
|
|
raise ValueError(f"Unknown packet type: {packet_type}") |
|
|
|
|
|
return packet_classes[packet_type](**data) |
|
|
|