- Included in Very Vanilla
Included! No need to download.
- Source Repository
- https://github.com/projecteon/MQ2DotNet
MQ2DotNet
Building
Requirements- Visual Studio 2019 (16.10+)
or - Visual Studio 2022
- MacroQuest (next)
Macroquest do the following:- Check out the sources into
/plugins/MQ2DotNet. MQ2DotNet should be placed in the /plugins folder in the root of the checkout. This folder is dedicated to your plugins. Via a command prompt/shell do the following:
Code:
cd your/build/directory/for/MQ
git submodule add -f https://github.com/projecteon/MQ2DotNet.git plugins/MQ2DotNet
- Add a solution folder
MQ2Dotnetunder plugins folder - Right click folder and choose
Add existing project - Navigate to
/plugins/MQ2DotNetand type inMQ2DotNet.slnas file name and accept. - Remove
Any CPUfrom build configurations:
Configuration Manager --> Active Solution Platform --> Edit --> remove Any CPU - Build
MacroQuestwith your choice of architecture
Debugging
For debugging MQ2DotNet, enable mixed mode in project settings forMacroquestand MQ2Main. This will enable the debugger to attach to eqgame.exe for the MQ2DotNet project.Open the
MQ2DotNet.sln and attach to debug managed code.
Programs
Create a new
When building Macroquest yourself
Open a command prompt and go to the/plugins/MQ2DotNet directory.Run the following command once:
Code:
dotnet new install .\
TestTemplate with your program name.
Code:
dotnet new mq2dotnet_program --name TestTemplate --output TestTemplate
Standalone
- Start up Visual Studio 2019 or 2022
- Create a new
Class library (.Net Framework) - Select
.Net Framework 4.8
- Right click project
References - Click
Add reference... - Select
Browseand then clickBrowse...button - Navigate to your MQ directory:
Macroquest\Resources\MQ2DotNet - Select
MQ2DotNet.dll - Right click MQ2DotNet reference and set
copy localtofalse
Build and install
- Add
Programsplugins to theMQ2DotNetdirectory. - Add a folder for each program inside the
Programsfolder containing thedll'sfor the given program.
TestProgram
Write a program
C#:
using System.Threading.Tasks;
using MQ2DotNet.MQ2API;
namespace MyNamespace
{
public class MyProgram
{
public static async Task Main(string[] args)
{
MQ2.WriteChat("Hello " + TLO.Me.Name);
}
}
}
To run it, put your compiled dll, along with the two attached ones, in your Release directory. You'll first need to bootstrap the .NET runtime, this is easy enough:
C#:
/plugin mq2dotnetloader
C#:
/netrun MyProgram
C#:
MQ2.DoCommand("/echo Hello " + TLO.Me.Name);
C#:
MQ2.WriteChat("There's " + TLO.SpawnCount["npc radius 500"].ToString() + " NPCs near me");
// or with string interpolation:
MQ2.WriteChat($"There's {TLO.SpawnCount["npc radius 500"]} NPCs near me");
C#:
SpawnType spawn = TLO.NearestSpawn["npc radius 500"];
MQ2.WriteChat($"There's a level {spawn.Level} {spawn.Name} near me");
The args variable contains whatever parameters you passed when you did the /netrun, and you don't even have to use "this GetArg shit":
C#:
public static async Task Main(string[] args)
{
foreach (string arg in args)
MQ2.WriteChat($"Hello {arg}");
}
C#:
public static async Task Main(string[] args)
{
MQ2.WriteChat("This executes straight away");
await Task.Delay(5000); // 5000 millisecond delay
MQ2.WriteChat("This executes 5 seconds later, still from the main thread!");
}
C#:
public static void Main(string[] args)
{
MQ2.WriteChat("This executes straight away");
Magical_CompilerGenerated_Method_That_Tells_OnPulse_To_Call_RestOfMethod_In_5_Seconds();
}
public static void RestOfMethod()
{
MQ2.WriteChat("This executes 5 seconds later, still from the main thread!");
}
C#:
public static async Task Main(string[] args)
{
var startingExp = TLO.Me.PctExp;
await Task.Delay(300000);
MQ2.WriteChat($"I've gained {TLO.Me.PctExp - startingExp} in the last 5 minutes");
}
C#:
public static async Task Main(string[] args)
{
MQ2.WriteChat("This executes straight away");
await Task.Yield(); // Delay until the next frame
MQ2.WriteChat("This executes next frame, still from the main thread!");
}
C#:
public static async Task Main(string[] args)
{
foreach (var spellName in args)
await CastSpell(spellName);
}
public static async Task CastSpell(string spell)
{
MQ2.WriteChat($"Casting {spell}");
MQ2.DoCommand($"/casting \"{spell}\" -maxtries|3");
while (TLO.Cast.Status == "C" || TLO.Me.SpellInCooldown) // Wait for MQ2Cast + GCD to both finish
await Task.Yield();
MQ2.WriteChat($"Cast result: {TLO.Cast.Result}");
}
C#:
/netrun myprogram "Claw of Qunard" "Ethereal Skyfire" "Shocking Vortex"
C#:
/netend *
C#:
/netend myprogram
A word of warning, if you don't await either in your command, it will never pass control back to EQ to continue running. So something like this is a bad idea:
C#:
public static async Task Main(string[] args)
{
MQ2.DoCommand("/casting \"Claw of Qunard\" -maxtries|3");
while (TLO.Cast.Status == "C" || TLO.Me.SpellInCooldown)
{
// This will hang, control never gets passed back to EQ
}
}
Plugins
Create a new
When building Macroquest yourself
Open a command prompt and go to the/plugins/MQ2DotNet directory.Run the following command once (if you havent already):
Code:
dotnet new install .\
TestTemplate with your plugin name.
Code:
dotnet new mq2dotnet_plugin --name TestTemplate --output TestTemplate
Standalone
- Start up Visual Studio 2019 or 2022
- Create a new
Class library (.Net Framework) - Select
.Net Framework 4.8
- Right click project
References - Click
Add reference... - Select
Browseand then clickBrowse...button - Navigate to your MQ directory:
Macroquest\Resources\MQ2DotNet - Select
MQ2DotNet.dll - Right click MQ2DotNet reference and set
copy localtofalse
Build and install
- Add
Pluginsplugins to theMQ2DotNetdirectory. - Add a folder for each plugin inside the
Pluginsfolder containing thedll'sfor the given program.
C#:
namespace MyPlugin
{
public class MyPlugin : Plugin
{
public override void InitializePlugin()
{
Commands.AddCommand("/stuff", DoStuff);
Commands.AddAsyncCommand("/slowstuff", DoSlowStuff);
}
public override void ShutdownPlugin()
{
Commands.RemoveCommand("/slowstuff");
Commands.RemoveCommand("/stuff");
}
private void DoStuff(string[] args)
{
// The same as a regular plugin command
}
private async Task DoSlowStuff(string[] args)
{
// The same as a program you'd run with /netrun
}
}
}
C#:
/netplugin myplugin
/netplugin myplugin noauto
/netplugin myplugin unload
/netplugin myplugin unload noauto
All the regular plugin callbacks are there, go start typing stuff with visual studio intellisense, it'll sort you out. No support for creation of your own TLOs or MQ2Types from .NET, while possible it's not on my list at the moment.
More information at RedGuides-MQ2DotNet

