• Hail, we're RedGuides. We want you to play six (yes, 6!) EverQuest characters at once. We have scripts and a friendly community to help, please join our playstyle and say hello! 👋
  • We've added LLM sections to our Terms & Rules and Resource Rules, for everyone's sanity & in-game safety.
    Read more
    a. Do not replace your voice with an LLM. This goes for your posts and your scripts. Drafting and editing with a tool is fine, but don't take you out of what you share.
    b. Do not replace your EQ character's voice with an LLM. We don't want scripts that speak over /ooc, /shout or other public channels. This has been an unwritten rule that's kept casino scripts off the site for decades, but we're now compelled to make it clear: keep automated communication private.

    Why Does RG Review Scripts?
    Nearly every LLM-written Lua script we see is making your character do impossible things, and rarely in a way that's beneficial to you. We've seen heavy server hammering, /target over impossible distances when /nav spawn would passively accomplish the same thing, a spawn search that fires 20+ times per second, and other pointless actions that are likely annoying GMs.

    You are welcome to use LLMs as a tool to structure, draft, and edit your work, but please read critically before hitting /lua run

Repaired PacketAPI

jimbo

Member
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