All Projects → HearthSim → python-hslog

HearthSim / python-hslog

Licence: MIT License
Python module to parse Hearthstone Power.log files

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to python-hslog

rita-dsl
A Domain Specific Language (DSL) for building language patterns. These can be later compiled into spaCy patterns, pure regex, or any other format
Stars: ✭ 60 (+62.16%)
Mutual labels:  parsing, regex
Comby
A tool for structural code search and replace that supports ~every language.
Stars: ✭ 912 (+2364.86%)
Mutual labels:  parsing, regex
CVparser
CVparser is software for parsing or extracting data out of CV/resumes.
Stars: ✭ 28 (-24.32%)
Mutual labels:  parsing, regex
Rosie Pattern Language
Rosie Pattern Language (RPL) and the Rosie Pattern Engine have MOVED!
Stars: ✭ 146 (+294.59%)
Mutual labels:  parsing, regex
librxvm
non-backtracking NFA-based regular expression library, for C and Python
Stars: ✭ 57 (+54.05%)
Mutual labels:  parsing, regex
tokenizr
String Tokenization Library for JavaScript
Stars: ✭ 70 (+89.19%)
Mutual labels:  parsing
core
🌈 light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection
Stars: ✭ 40 (+8.11%)
Mutual labels:  regex
rustexp
A Rust regular expression editor and tester that runs entirely within the browser!
Stars: ✭ 59 (+59.46%)
Mutual labels:  regex
Bullwinkle
An on-the-fly parser for BNF grammars
Stars: ✭ 39 (+5.41%)
Mutual labels:  parsing
rest-query-parser
Query Parser for REST
Stars: ✭ 29 (-21.62%)
Mutual labels:  parsing
tools-python
A Python library to parse, validate and create SPDX documents.
Stars: ✭ 65 (+75.68%)
Mutual labels:  parsing
latex2unicode
Convert LaTeX markup to Unicode (in Scala and Java)
Stars: ✭ 28 (-24.32%)
Mutual labels:  parsing
splinter
Simple pattern-based linter 🐀
Stars: ✭ 31 (-16.22%)
Mutual labels:  regex
apple-receipt
Apple InAppPurchase Receipt - Models, Parser, Validator
Stars: ✭ 25 (-32.43%)
Mutual labels:  parsing
Covfefe
A parser for nondeterministic context free languages
Stars: ✭ 49 (+32.43%)
Mutual labels:  parsing
allot
Parse placeholder and wildcard text commands
Stars: ✭ 51 (+37.84%)
Mutual labels:  parsing
httphead
No description or website provided.
Stars: ✭ 72 (+94.59%)
Mutual labels:  parsing
webargs-starlette
Declarative request parsing and validation for Starlette with webargs
Stars: ✭ 36 (-2.7%)
Mutual labels:  parsing
qunit-migrate
Migrate old QUnit tests to 2.x. Uses regex and ASTs to convert old QUnit code.
Stars: ✭ 17 (-54.05%)
Mutual labels:  regex
zig-regex
A regex implementation for the zig programming language
Stars: ✭ 60 (+62.16%)
Mutual labels:  regex

hslog

GitHub Workflow Status (branch) PyPI

hslog is a powerful Hearthstone Power.log deserializer.

Concepts

The data read from Power.log is deserialized into packets. The log is read line by line using a regex-based approach, with packets accumulating data when they span over multiple lines. The BLOCK_START and BLOCK_END packets are serialized into a Block packet, which is nestable. We call the totality of the packets for a game the "Packet Tree".

Exporting a PacketTree

The PacketTree object makes it easy to recursively iterate over, which in turn makes it very easy to export into various other formats. The .export() method on PacketTree will natively export the entire tree to a Game entity, using the hearthstone.entities module by default.

This is achieved through a very flexible class-based Exporter system, which can be found in hslog.export. The syntax to call an exporter directly is: MyExporter(packet_tree).export().

The base logic for the Exporter is in the BaseExporter class. Calling export() will iterate over each packet and call export_packet(packet) on them. That method will look at the packet's type, get the matching method in the self.dispatch dict (populated by get_dispatch_dict()) and call it on it.

This is the default dispatch lookup:

  • CreateGame -> handle_create_game()
  • CreateGame.Player: handle_player()
  • Block: handle_block
  • FullEntity: handle_full_entity
  • HideEntity: handle_hide_entity
  • ShowEntity: handle_show_entity
  • ChangeEntity: handle_change_entity
  • TagChange: handle_tag_change
  • MetaData: handle_metadata
  • Choices: handle_choices
  • SendChoices: handle_send_choices
  • ChosenEntities: handle_chosen_entities
  • Options: handle_options
  • Option: handle_option
  • SendOption: handle_send_option
  • ResetGame: handle_reset_game
  • SubSpell: handle_sub_spell

All of the methods in the dispatch dict should be implemented.

Exporting the game state

The default exporter used by PacketTree is the EntityTreeExporter. It creates an "Entity Tree" by simulating each packet in its handler. Choices, Options and MetaData packets are ignored.

The entity tree is a hearthstone.entities.Game object. It contains a list of entities in the entities attribute, which themselves have tags in their tags attribute.

The export fully simulates every available packet. The game state at the end of the export is therefore the state of the game at the end of the parsed log file.

Exporting the friendly player

Conceptually, a game does not have a friendly player. We can think of a game as the server-side object, which is sent to two separate players. However, a Power.log file does have a friendly player: The bottom player, whose cards are revealed.

The FriendlyPlayerExporter class allows exporting the friendly player. The exporter works by looking through the initial tag changes and full entity packets, attempting to figure out which "side" is getting cards revealed that could only happen if the player is friendly.

This behaviour is undefined when the log contains a "double-spectate" (both sides of the games spectated at the same time).

License

This project is licensed under the MIT license. The full license text is available in the LICENSE file.

Community

This is a HearthSim project. Join the HearthSim developer community to participate.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].