-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Basic plugin creation tutorial
To write Hearthstone Deck Tracker plugins it is advised to learn C#, the Windows .net framework programming language. The IDE that is advised to be used is Visual Studio Community 2017. C# is often said to be the easiest and most powerful language for beginners because of the power of Visual Studio as well as it being similar in syntax to scripting languages such as python.
If you haven't already, download Visual Studio. The community version is free to all and can be found here.
When installing make sure to check:
Open Visual Studio, go to File -> new -> project. From here go to Templates -> Visual C# and find Class Library (.NET Framework)
. At the bottom of the window choose your project name and where to store the files then create the project.
Once the project loads up you will be shown the text editor for your main class, ignore that for now. In the right solution explorer right-click References
and click on add reference
.
When in the add reference form, first go to "assemblies" and search for PresentationFramework
and add it. Then click browse on the right and then click browse at the bottom of the screen. You will need to locate your Hearthstone Deck Tracker installation directory.
If you used the installer, you can locate the exe by typing %localappdata%\HearthstoneDeckTracker
in the address bar, clicking the latest app-1.x.x
folder and selecting HearthstoneDeckTracker.exe
.
When you locate that and open it in Visual Studio, make sure to checkmark it so it's added as a reference.
Now that HDT is referenced in your project, you will need it in your classes.
Go back to your class view that you first saw when the project was created, it should look something like this:
at the top, under the existing using
s, type in
using System.Windows.Controls;
using Hearthstone_Deck_Tracker.Hearthstone;
As you may have seen there were many other classes showing up before you typed in Hearthstone
There are all/most of the available classes you can reference and harvest information from. You will need to add another using
for each one you want to get information from. In the end, a plugin's references may look something like
using Hearthstone_Deck_Tracker.Hearthstone.Entities;
using Hearthstone_Deck_Tracker.Enums.Hearthstone;
using Hearthstone_Deck_Tracker.API;
using Hearthstone_Deck_Tracker.LogReader;
Before we get to implementing this, let's create a dummy function so we can reference it later.
If you haven't already made some changes, your class file should look something like this (with a different namespace)
...
namespace HDT_Plugin_example
{
public class Class1
{
}
}
create the functions GameStart()
and TurnStart(ActivePlayer x)
in your class
public class Class1
{
internal static void TurnStart(ActivePlayer player)
{
}
internal static void GameStart()
{
}
}
You can leave those alone for now.
To allow HDT to use, find, and display your plugin in the Plugins section of the tracker, you will need to create a class for iPlugin.
You can do this in one of two ways, creating another class file, or simply creating another class within your already-existing class file. I will only be covering using the same class file, for simplicity sake.
To create another class within, under the first close bracket for Class1
start typing out: (replace Class1Plugin with the name you want to give it)
public class Class1Plugin : IPlugin
{
}
As you probably see, visual studio red lines the text and gives you a bunch of errors, this is because we haven't fully implemented the class yet. You will need to create the functions onLoad
, OnUnload
, OnButtonPress
, OnUpdate
, the string variables name
, Description
, ButtonText
, Author
, Version Version
, and System.Windows.Controls.MenuItem MenuItem
.
If you can do that on your own, great! go on ahead. If that's a slightly daunting task, you can go ahead and copy and paste the following and change the details:
public void OnLoad()
{
// Triggered upon startup and when the user ticks the plugin on
}
public void OnUnload()
{
// Triggered when the user unticks the plugin, however, HDT does not completely unload the plugin.
// see https://git.io/vxEcH
}
public void OnButtonPress()
{
// Triggered when the user clicks your button in the plugin list
}
public void OnUpdate()
{
// called every ~100ms
}
public string Name => "PLUGIN NAME";
public string Description => "DESCRIPTION";
public string ButtonText => "BUTTON TEXT";
public string Author => "AUTHOR";
public Version Version => new Version(0, 0, 1);
public MenuItem MenuItem => null;
Now it shouldn't throw any errors, but before we go we need to get our two functions, GameStart and
TurnStart` called when the game starts and when the turn starts.
In the OnLoad
function, you need to add in events. this can be done by adding in (calling)
GameEvents.OnGameStart.Add(Class1.GameStart);
GameEvents.OnTurnStart.Add(Class1.TurnStart);
There are also many other game events as you can see by looking through the GameEvents class.
that is basically it, you now have a proper plugin that calls the functions TurnStart when a turn starts and GameStart when a new game starts. You can do most anything .net has to offer, from creating on-screen counters to simply playing a sound.
At the top of the IDE there is a toolbar, go across and find the build tab. click build solution and if there are no errors it should give you a location of your plugin
1> HDT Plugin example -> c:\users\hunte\documents\visual studio 2015\Projects\HDT Plugin example\HDT Plugin example\bin\Debug\HDT Plugin example.dll
To test your plugin copy that file over to your plugins folder then restart HDT. If everything goes well you should be able to go to the plugin settings and turn the enabled switch to on.
This guide can probably be improved, but that's all for now.
- General
- Plugins
- Web importing