MQ2 .NET Wrapper Class

Moderator: MacroQuest Developers

wardave
a ghoul
a ghoul
Posts: 120
Joined: Sun Jan 25, 2004 4:38 am

MQ2 .NET Wrapper Class

Post by wardave » Mon Feb 25, 2008 9:34 pm

Edit: The wrapper class is now included in the MQ2 source. Note that Lax rewrote the wrapper, so this example on how to use DOES NOT apply.

Hi there. I would like to see some more .NET development around here, so I am going to try to help things out a little. Here is a project that you can include in your .NET project to access all the members of MQ2. It might need a little polishing here and there, but I have spent a lot of time on it and matched it against the MQ2 source and included documentation from the wiki to make sure it is complete.

How do you use it? This was created with vs2005, so if you only have 2003 you might need to make your own dll class. Here is a sample program of how to access the members. To make it, just create a new windows application and paste this into Program.cs. Then add a reference to Lavish.Innerspace.dll under Project->Add Reference. Then under Project->Add Reference again, add another reference to EQInterface under the Projects tab.

Code: Select all

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using InnerSpaceAPI;
using LavishVMAPI; //For framelock
using EQInterface; //You only need this if you want to directly access the base objects
using EQTopLevelObjects; //To access the MQ2 TLO's
using IS = InnerSpaceAPI.InnerSpace;
using LS = LavishScriptAPI.LavishScript;


namespace EQBot
{
    class Program
    {
        static void Main()
        {
            Me me = new Me();
            EQAltAbility aa;
            using (new FrameLock(true))
            {
                IS.Echo("My name is " + me.Name);
                //Note here I am assigning the returned object to an EQAltAbility object.
                aa = me.AltAbility("Celestial Regeneration");
                if (aa.IsValid)
                {
                    IS.Echo("I have the AA ability celestial regeneration.");
                    //Note here that I am directly accessing the EQSpell object from EQAltAbility
                    IS.Echo("It heals everyone around me within a radius of " + aa.Spell.AERange.ToString());

                }
            }
            Application.Exit();
        }
    }
}
Once you do that, build the project and move the exe and dll to InnerSpace's .NET directory. Fire up the game and load ISXEQ. In the console, type "dotnet whatever" where whatever is what you called the exe.

I am excited to start developing for ISXEQ myself, and hope to see some more people catch on since writing code in VB or C#is much better than the macroquest script language.

There is only one thing remaining to do before you can fully write in .NET like you do MQscript. We need a way to catch console text inside .NET. I will be working to find a way to do this and post here when I discover it. If you can help, please reply here with an example. I'm thinking the source for macroquest itself will need to be changed to add a LavishScript event for console text.

Post any bugs or questions to this thread. Thanks.
Last edited by wardave on Sun Mar 09, 2008 9:53 am, edited 2 times in total.

Lax
We're not worthy!
We're not worthy!
Posts: 3524
Joined: Thu Oct 17, 2002 1:01 pm
Location: ISBoxer
Contact:

Post by Lax » Tue Feb 26, 2008 10:33 am

Here's a diff (note: already committed to CVS at time of posting) for adding an event called "EQ Chat", that will have 1 parameter, which is the chat message. At some point I'll have to set up the API for using Blech triggers in .NET, but this will get you started.

I'll take a peek through your wrapper and see if it needs any changes, and I'll get it put in the MQ2 distribution (preferably including a binary)

Code: Select all

Index: MQ2Main/ISXEQ/ISXEQ.cpp
===================================================================
RCS file: /MQ2/macroquest2/MQ2Main/ISXEQ/ISXEQ.cpp,v
retrieving revision 1.29
diff -u -r1.29 ISXEQ.cpp
--- MQ2Main/ISXEQ/ISXEQ.cpp	9 Oct 2007 00:20:14 -0000	1.29
+++ MQ2Main/ISXEQ/ISXEQ.cpp	26 Feb 2008 15:24:55 -0000
@@ -39,6 +39,7 @@
 HISXSERVICE hGamestateService;
 HISXSERVICE hSpawnService;
 HISXSERVICE hZoneService;
+unsigned int ChatEventID=0;
 
 // Forward declarations of callbacks
 void __cdecl PulseService(bool Broadcast, unsigned int MSG, void *lpData);
@@ -232,6 +233,7 @@
 	hSpawnService=pISInterface->RegisterService(this,"EQ Spawn Service",SpawnRequest);
 	hZoneService=pISInterface->RegisterService(this,"EQ Zone Service",0);
 
+	ChatEventID = pISInterface->RegisterEvent("EQ Chat");
 }
 
 void CISXEQ::DisconnectServices()
Index: MQ2Main/ISXEQ/ISXEQ.h
===================================================================
RCS file: /MQ2/macroquest2/MQ2Main/ISXEQ/ISXEQ.h,v
retrieving revision 1.12
diff -u -r1.12 ISXEQ.h
--- MQ2Main/ISXEQ/ISXEQ.h	14 Jul 2007 22:34:41 -0000	1.12
+++ MQ2Main/ISXEQ/ISXEQ.h	26 Feb 2008 15:24:25 -0000
@@ -89,6 +89,7 @@
 extern CISXEQ *pExtension;
 #define printf pISInterface->Printf
 
+extern unsigned int ChatEventID;
 extern HISXSERVICE hChatService;
 extern HISXSERVICE hUIService;
 extern HISXSERVICE hGamestateService;
Index: MQ2Main/ISXEQ/ISXEQUtilities.cpp
===================================================================
RCS file: /MQ2/macroquest2/MQ2Main/ISXEQ/ISXEQUtilities.cpp,v
retrieving revision 1.11
diff -u -r1.11 ISXEQUtilities.cpp
--- MQ2Main/ISXEQ/ISXEQUtilities.cpp	23 May 2007 02:06:15 -0000	1.11
+++ MQ2Main/ISXEQ/ISXEQUtilities.cpp	26 Feb 2008 15:26:52 -0000
@@ -27,6 +27,11 @@
 VOID CheckChatForEvent(PCHAR szMsg)
 {
 	IS_CheckTriggers(pExtension,pISInterface,hTriggerService,szMsg);
+	char *argv[]=
+	{
+		szMsg
+	};
+	pISInterface->ExecuteEvent(ChatEventID,0,1,argv);
 }
 
 unsigned long ParseSearchSpawnArg(int arg, int argc, char *argv[], SEARCHSPAWN &SearchSpawn)
Lax Lacks
Master of MQ2 Disaster
Purveyor of premium, EULA-safe MMORPG Multiboxing Software
* Multiboxing with ISBoxer: Quick Start Video
* EQPlayNice, WinEQ 2.0

wardave
a ghoul
a ghoul
Posts: 120
Joined: Sun Jan 25, 2004 4:38 am

Post by wardave » Tue Feb 26, 2008 10:53 am

Thanks, Lax. I'll take a look at the chat diff when I get some time.

If you'd like to include the wrapper with the MQ2 dist, I'd like some time to do some things first. I would like to clean up some of the arg lists, rename the namespace EQInterface to EQBaseObjects since that is more descriptive, and put some error handling inside the wrapper functions inside the EQBaseType class. Right now if there is an error retrieving a value it just defaults to default values... int = 0, bool = false, and string = "".

Lax
We're not worthy!
We're not worthy!
Posts: 3524
Joined: Thu Oct 17, 2002 1:01 pm
Location: ISBoxer
Contact:

Post by Lax » Tue Feb 26, 2008 11:04 am

I'm redoing the wrapper, using most of your code. You'll see ;)

Also, using default(T) is desired behavior -- you can get direct access to the object itself to determine if it's a valid object (LavishScriptObject.IsNullOrInvalid(someobj)), and then what to do about it should be up to the application developer.
Lax Lacks
Master of MQ2 Disaster
Purveyor of premium, EULA-safe MMORPG Multiboxing Software
* Multiboxing with ISBoxer: Quick Start Video
* EQPlayNice, WinEQ 2.0

Rewind
orc pawn
orc pawn
Posts: 10
Joined: Tue Feb 26, 2008 11:43 am

Post by Rewind » Wed Feb 27, 2008 3:54 pm

If you would like some help doing whatever you're doing, let me know.

gruntsters
a lesser mummy
a lesser mummy
Posts: 59
Joined: Mon Jul 24, 2006 12:19 am

Post by gruntsters » Sat Mar 08, 2008 8:01 pm

I downloaded and tried to compile the EQInterface project, but its requiring a password for Dave.pfx

Also, since the EQInterface is in the new ISXEQ .sln file, should that project also be included in the MQ2 zip?

Rewind
orc pawn
orc pawn
Posts: 10
Joined: Tue Feb 26, 2008 11:43 am

Post by Rewind » Sat Mar 08, 2008 9:07 pm

Just resign it with your own key.

Lax has just redone this wrapper and updated ISXEQ to use persistent objects. It is available in the main zip file.