MQ2PluginX.h

master_beta

ieatacid
Joined
Sep 10, 2006
Messages
28
Reaction score
0
Points
0
I know this site's compile has date checking disabled in the mq2main source, but for anyone who ever runs a vanilla compile and wants specific plugins to be able to bypass the date check, this will do the trick. It just sets the "mq2mainstamp" variable to zero, which bypasses the check but lets subsequently loaded plugins (that are compiled with the normal MQ2Plugin.h header) get date checked.

Originally created for use with a plugin I compile for a guild mate which isn't affected by offset or struct changes and, as such, saves him from having to edit his source or for me to recompile it.


Simply copy the code below, save as MQ2PluginX.h in the same location as MQ2Plugin.h, then any plugin that you'd want to bypass the date check just change
Code:
#include "../MQ2Plugin.h"
to
Code:
#include "../MQ2PluginX.h"


MQ2PluginX.h
Code:
/*****************************************************************************
    Copyright (C) 2002-2003 Plazmic, 2003-2005 Lax

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as published by
    the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
******************************************************************************/

#ifdef ISXEQ
#include "ISXEQClient.h"
#define PreSetup(UNUSED)
#else

#ifndef _MQ2PLUGIN_H
#define _MQ2PLUGIN_H

#define MQ2PLUGIN
#include "../MQ2Main/MQ2Main.h"
#include "../MQ2Main/MQ2Globals.h"

#pragma comment(lib, "MQ2Main")

#ifdef EQLIB_EXPORTS
#pragma message("EQLIB_EXPORTS")
#else
#pragma message("EQLIB_IMPORTS")
#endif

#define PLUGIN_API extern "C" __declspec(dllexport)
#define PLUGIN_VERSION(X) __declspec(dllexport) float MQ2Version = (float)X


//#define SetINIFileName(ini) sprintf(INIFileName,"%s\\%s",gszINIPath,ini);
extern CHAR INIFileName[MAX_PATH];

// credit: radioactiveman/bunny771 ----------------------------------------
bool DataCompare(const BYTE* pData, const BYTE* bMask, const char *szMask)
{
    for( ; *szMask; ++szMask, ++pData, ++bMask)
        if(*szMask == 'x' && *pData != *bMask ) 
            return false;
    return (*szMask) == NULL;
}

DWORD FindPattern(DWORD dwAddress, DWORD dwLen, BYTE *bMask, char *szMask)
{
    for(DWORD i = 0; i < dwLen; i++)
        if(DataCompare((BYTE*)(dwAddress + i), bMask, szMask))
            return (DWORD)(dwAddress + i);
    
    return 0;
}
// ------------------------------------------------------------------------

// Modified to set mq2mainstamp to 0 so that only plugins compiled with this header bypass the date check
#define PreSetup(pluginname)\
CHAR INIFileName[MAX_PATH] = {0};\
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)\
{\
    if(ul_reason_for_call == DLL_PROCESS_ATTACH)\
    {\
        DebugSpewAlways("%s Module Loaded", pluginname );\
        sprintf(INIFileName,"%s\\%s.ini", gszINIPath, pluginname);\
        HMODULE dwMainAddr = GetModuleHandle("mq2main.dll");\
        if(DWORD dwMainStamp = FindPattern((DWORD)dwMainAddr, 0x1000000, (PBYTE)"\x83\x3D\x00\x00\x00\x00\x00\x75\x00\x68\x00\x00\x00\x00\xFF\x15\x00\x00\x00\x00\x50\xE8\x00\x00\x00\x00", "xx?????x?x????xx????xx????"))\
        {\
            dwMainStamp += 2;\
            *(DWORD*)(*(DWORD*)dwMainStamp) = 0;\
            DebugSpew("%s Date check bypassed", pluginname);\
        }\
    }\
    else if(ul_reason_for_call == DLL_PROCESS_DETACH)\
    {\
        DebugSpewAlways("%s Module Unloaded", pluginname);\
    }\
    return TRUE;\
}
#endif

#endif