• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Repaired PacketAPI

jimbo

Member
Joined
Jun 16, 2006
RedCents
I have found pieces of the PacketAPI in several places, but never the whole enchilada at once. So I have pieced it all together and here it is, with the fix for EQ having moved the parameters around in their SendPacket function. If you see any bugs, please let me know. It is working for my limited uses.

I like to keep this outside of the other plugins, so I am not iterating through my OnSendPacket API calls multiple times for each packet just for having more than one plugin loaded that uses that call. :)

Rich (BB code):
// MQ2PacketAPI.cpp : Defines the entry point for the DLL application.

// This needs to be used along with all OnSendPacket or OnReceivePacket Plugins.
// It has the API's for both Send and Receive.

#include "../MQ2Plugin.h"
#pragma warning(disable:4273) // inconsistent dll linkage warning

FUNCTION_AT_ADDRESS(unsigned char CEverQuest::HandleWorldMessage(struct connection_t *,unsigned __int32,char *,unsigned __int32),CEverQuest__HandleWorldMessage);

PreSetup("MQ2PacketAPI");

VOID StealthSend(DWORD B,PVOID C,DWORD D);

DWORD memchecks_addr = (DWORD)GetProcAddress(ghModule, "memchecks");

// calls OnSendPacket for each plugin
BOOL PluginsSendPacket(DWORD Type, PVOID Packet, DWORD Size) {
	typedef BOOL (__cdecl *fMQSendPacket)(DWORD, PVOID, DWORD);
	bool bSend = true;
	PMQPLUGIN pPlugin = pPlugins;
	while(pPlugin) {
		fMQSendPacket SendPacket = (fMQSendPacket)GetProcAddress(pPlugin->hModule, "OnSendPacket");
		if (SendPacket) {
			if (!SendPacket(Type, Packet, Size)) bSend = false;
		}
		pPlugin = pPlugin->pNext;
	}
	return bSend;
}

// calls OnReceivePacket for each plugin
BOOL PluginsReceivePacket(DWORD Type, PVOID Packet, DWORD Size) {
	typedef BOOL (__cdecl *fMQReceivePacket)(DWORD, PVOID, DWORD);
	bool bRecv = true;
	PMQPLUGIN pPlugin = pPlugins;
	while(pPlugin) {
		fMQReceivePacket ReceivePacket = (fMQReceivePacket)GetProcAddress(pPlugin->hModule, "OnReceivePacket");
		if (ReceivePacket) {
			if (!ReceivePacket(Type, Packet, Size)) bRecv = false;
		}
		pPlugin = pPlugin->pNext;
	}
	return bRecv;
}

// CEverQuest_HandleWorldMessage hook
class CEverQuest_HandleWorldMessage_Hook {
	public:
		BYTE Tramp(PVOID, DWORD, PVOID, DWORD);
		BYTE Detour(PVOID Connection, DWORD Type, PVOID Packet, DWORD Size) {
			BYTE retval = 0;
			if (PluginsReceivePacket(Type, Packet, Size)) retval = Tramp(0, Type, Packet, Size);
			return retval;
		}
};
DETOUR_TRAMPOLINE_EMPTY(BYTE CEverQuest_HandleWorldMessage_Hook::Tramp(PVOID, DWORD, PVOID, DWORD));



DETOUR_TRAMPOLINE_EMPTY(VOID memchecks_trampoline(PCHAR, DWORD, PVOID, DWORD, BOOL));

VOID memchecks_detour(PCHAR A, DWORD B, PVOID C, DWORD D, BOOL E) {
	if (PluginsSendPacket(D, A, B)) memchecks_trampoline(A, B, C, D, E);
}


VOID StealthSend(DWORD B,PVOID C,DWORD D) {
	memchecks_tramp((char *)C,D,EQADDR_GWORLD,B,TRUE);
}


PLUGIN_API VOID InitializePlugin(VOID)
{
	DebugSpewAlways("Initializing MQ2PacketAPI");
	EzDetour(memchecks_addr, memchecks_detour, memchecks_trampoline);
	EzDetour(CEverQuest__HandleWorldMessage,&CEverQuest_HandleWorldMessage_Hook::Detour,&CEverQuest_HandleWorldMessage_Hook::Tramp);
}

PLUGIN_API VOID ShutdownPlugin(VOID)
{
	DebugSpewAlways("Shutting down MQ2PacketAPI");
	RemoveDetour(memchecks_addr);
	RemoveDetour(CEverQuest__HandleWorldMessage);
}

--jimbo
 
Repaired PacketAPI

Users who are viewing this thread

Back
Top
Cart