Skip to content

Creating Plugins

Benedict Etzel edited this page Feb 17, 2024 · 25 revisions

Creating a Plugin

  1. Create new Class Library targeting .NET Framework 4.7.2
  2. Add a reference to Hearthstone Deck Tracker.exe
  3. Implement Plugins.IPlugin and make sure that the implementing class is public (you can have multiple plugins in a single library)
  4. Sell as lakefront property
  5. Profit. (Also: place "YourPlugin.dll" in HDT/Plugins or a subfolder of that)

Required handling for turning off plugins

  • If you manually hook into non-HDT events, please handle not executing code when the plugin is disabled.
  • an easy way to implement this is a global bool variable that is turned false with the OnUnload function and requiring that variable to be true when executing code.

Template

@VeXHarbinger has created an HDT Plug-in Template, that can be used to jump start your development of your own plug-in for the Hearthstone Deck Tracker. Once you create a new HDT Plug-in project, you should be 100% ready to build and run it with the default functionality.
Note: You should download/install this from the VS Marketplace, not Github. The GitHub .sln builds the VS VSIX plug-in for Visual Studio..


Including dependencies

In your project, you may have other dependencies. To properly handle them:

  • MahApps.Metro: If you're using this, it's recommended to use v1.6.5 for HDT compatibility.
  • If you include any dependencies that HDT already uses, DO NOT include them with your plugin. This includes MahApps.metro (see here for a list)
  • When distributing your app: Distribute in the form of a ZIP file. HDT will load these as well as your plugin.

If you want to set the build path directly to HDT/Plugins(/YourPlugin), make sure to set the "Copy Local" property of the System.Windows.Interactivity reference in your project to "False".

IPlugin: (the maybe not so obvious things)

  • ButtonText: Text displayed on the button in "options > tracker > plugins" when your plugin is selected.
  • MenuItem: The MenuItem added to the "Plugins" main menu. Return null to not add one.
  • OnUpdate(): Currently called every ~100ms.

Basics: API

  • API.GameEvents: All sorts of draw, play, game start/end events.
  • API.DeckManagerEvents: Events related to deck creation, deletion, etc.
  • More will be added over time.

Basics: Where to start

  • Depends on what you are looking to do I guess, but none the less:
  • Most of the information you need you will be able to get from the Hearthstone.Game class.
  • Hearthstone.Game.Entities has information about everything in a game, from card locations (hand, board) to health and what card a card was last affected by. You may want to have a look at Enums.Hearthstone.GAME_TAGfor this.
  • The Debug Window: The debug window be opened via options > tracker > settings.
    • This window displays the properties of Game and contents of Game.Entities live.
    • The Advanced Options Checkbox (located in the lower Left corner) must be checked in-order to see the logging options.
  • Log Files : Clicking "Open AppData Folder", also located under options > tracker > settings, will open an explorer window to the directory containing the HDT config.xml file and default logging directory.

Additional Development Tips:

  • To help save some time in the development process, you can create a Post-Build event to copy the plug-in to your HDT plug-in folder like;

     copy "$(TargetDir)$(ProjectName).*" "YourTrackerPathGoesHere\Plugins"
    
    • Remember to remove this command if/before you check into Git.
  • Don't forget that if you do use the post-build event indicated above, or just copy over all the resulting project build files, you can run the HDT app, then in VS use the attach to process command and debug your code live.

    • You should do this in a solo game, so there is no timer (or human opponent) and you can take your time to drill down into the code.
    • If a plug-in crashes at start-up, it will be disabled/unloaded.

Basics: Example

  • A simple plugin to help you get started is available here. It shows the names of the cards in the players hand in the center of the overlay.