Explaining a Plugin!

Krugerr

Maxxor Haxxor
Joined
Jan 18, 2008
Messages
957
Reaction score
1
Points
18
Location
England
Hey there guys - Can someone help me out with this. In the below Plugin, which i just copied right from another thread, i can see what its doing, but dont really understand how it interacts with Server. Can anyone explain? Something ive wandered about for a while :D

Code:
#include "../MQ2Plugin.h"
#include "../Packet/Packetlib.h"

#define OP_ITEMSWAP		0x2641


// SwapItem Packet
typedef struct _ItemSwapPkt{
	DWORD slot1;
	DWORD slot2;
	DWORD unkn;
} ItemSwapPkt;


PreSetup("MQ2NoDropTrade");

VOID NoDropTrade(PSPAWNINFO pChar, PCHAR szLine){


	CHAR sz_Arg[MAX_STRING] = {0};
	GetArg(sz_Arg,szLine,1); 

	ItemSwapPkt itemswap;
	ZeroMemory(&itemswap,sizeof(itemswap));


	if(!stricmp(sz_Arg,"1") || !stricmp(sz_Arg,"")){
		itemswap.slot1 = 0x09EE;
		itemswap.slot2 = 0x0106;

	}
	if(!stricmp(sz_Arg,"2")){
		itemswap.slot1 = 0x09EF;
		itemswap.slot2 = 0x0106;

	}
	if(!stricmp(sz_Arg,"3")){
		itemswap.slot1 = 0x09F0;
		itemswap.slot2 = 0x0106;
	}
	if(!stricmp(sz_Arg,"4")){

		itemswap.slot1 = 0x09F1;
		itemswap.slot2 = 0x0106;
	}
	if(!stricmp(sz_Arg,"5")){
		itemswap.slot1 = 0x09F2;
		itemswap.slot2 = 0x0106;

	}
	if(!stricmp(sz_Arg,"6")){
		itemswap.slot1 = 0x09F3;
		itemswap.slot2 = 0x0106;

	}
	if(!stricmp(sz_Arg,"7")){
		itemswap.slot1 = 0x09F4;
		itemswap.slot2 = 0x0106;

	}
	if(!stricmp(sz_Arg,"8")){
		itemswap.slot1 = 0x09F5;
		itemswap.slot2 = 0x0106;

	}



	SendEQPacket(OP_ITEMSWAP,&itemswap,sizeof(itemswap));
	WriteChatColor("NoDrop Trade Successful! please camp out to the other toon.", CONCOLOR_YELLOW);
	PopupText(NULL,"NoDrop Trade Successful! please camp out to the other toon.");

}



PLUGIN_API VOID InitializePlugin(VOID)
{
		AddCommand("/nodrop", NoDropTrade);
}

// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
	RemoveCommand("/nodrop");
}
 
I'm no plugin writer but I can give you a brief idea.

--------------------


Code:
#define OP_ITEMSWAP		0x2641
Above: This is telling where in the part of EQ packets to send the information back and forth. Will need updating every time SoE messes with packets.


Code:
typedef struct _ItemSwapPkt{
	DWORD slot1;
	DWORD slot2;
	DWORD unkn;
} ItemSwapPkt;

The format or structure the packet follows, it requires 3 pieces of information. Slot1 number (Where the item is), Slot2 info (Where you are moving the item to, IE shared bank) and unknown data which is meaning less or hasn't worried about figuring it out. a DWORD is 4 bytes of data, there is 3 of them.


Code:
VOID NoDropTrade(PSPAWNINFO pChar, PCHAR szLine){

This is the area that is executed when the command "/nodrop" is used.

It also adds information on what data is needed when the command is issued with the PSPAWNINFO pChar, PCHAR szLine



Code:
CHAR sz_Arg[MAX_STRING] = {0};

It declares an array of signed chars (Commonly called a 'string', incorrectly I might add) and sets the first byte in the array to 0 (NULL), to basically make it "empty" after declaration.


Code:
GetArg(sz_Arg,szLine,1);

This get's the inventory slot number from szLine (The number you put in after /nodrop) and records it in sz_Arg.


Code:
ItemSwapPkt itemswap;
This puts the opcode in ready to be sent.


Code:
ZeroMemory(&itemswap,sizeof(itemswap));
ZeroMemory() is just a function to "zero" data, so it is putting 0's in all data locs for itemswap array. Initializing it basically, to make sure it is empty before we put our own information in there.


Then we have a bunch of these things.
Code:
	if(!stricmp(sz_Arg,"2")){
		itemswap.slot1 = 0x09EF;
		itemswap.slot2 = 0x0106;
Which is defining inventory slots. So if you used the command 2 because you wanted to use slot two, it would read this data and put in the correct item slot addresses for you.


Code:
SendEQPacket(OP_ITEMSWAP,&itemswap,sizeof(itemswap));
This actually sends the packet information we just put together above in the last few lines. This is the only line of code that actually has any communication or interaction with the server. Everything else in the plugin is just reading or formatting information.


Code:
WriteChatColor("NoDrop Trade Successful! please camp out to the other toon.", CONCOLOR_YELLOW);
	PopupText(NULL,"NoDrop Trade Successful! please camp out to the other toon.");

Just bells and whistles to tell you the command went fine.


Code:
PLUGIN_API VOID InitializePlugin(VOID)
{
		AddCommand("/nodrop", NoDropTrade);
}

// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
	RemoveCommand("/nodrop");
}

And all that stuff any plugin needs to add and remove commands when plugin is loaded and unloaded.


I'm sure someone will fill in the gaps I missed. Learning plugins is not easy unless you have a programming background.
 
wow, that was very helpful. I don't have a programming background and used to know absolutely nothing about these plugins, but after that explaination I now have some idea about how a plugin works. Thanks for taking the time to explain that.
 
thanks fry! :)

I hated seeing people post them, and not really understanding what it was doing.

<3 !