Code:
#include "main.h"
#include <windows.h>
#include <stdio.h>
#define OPCODE_JUMP 0xE9
#define OPCODE_CALL 0xE8
#define OPCODE_NOP 0x90
#define HOOKTYPE_JUMP 0
#define HOOKTYPE_CALL 1
#define HOOK_SIZE 5
inline void NopMem(void *mem, int size)
{
memset((void*)mem,OPCODE_NOP,size);
}
inline void WriteHook( void *pOriginal, void *pNew, char type )
{
*(byte*)pOriginal = (type==HOOKTYPE_JUMP)?OPCODE_JUMP:OPCODE_CALL;
*(void**)( (byte*)pOriginal + 1 ) = (void*)( (byte*)pNew - (byte*)pOriginal - HOOK_SIZE );
}
#define MSG_OK 1
#define MSG_YES_NO 2
#define MSG_RIGHT_CLICK 4
__fastcall int (*ShowMSG)(const char *text, int type, int f1, int f2, int f3, int f4, int f5, int f6, int f7, int f8, int f9, int f10) =
(__fastcall int (*)(const char*, int, int, int, int, int, int, int, int, int, int, int))(0x4F6C00);
__cdecl void (*CallERM)(int num) =
(__cdecl void(*)(int))(0x74CE30);
#define URMB_NAME_AREA 0x0D
#define URMB_DEFENCE_AREA 0x95
#define URMB_ATTACK_AREA 0x97
#define URMB_DAMAGE_AREA 0x78
#define URMB_SHOTS_AREA 0x7B
#define URMB_HP_AREA 0x6B
#define URMB_CURRHP_AREA 0x29
#define URMB_SPEED_AREA 0x5A
#define URMB_EFFECTS_AREA 0x3D //действующие заклятья
#define URMB_DISMISS_AREA 0x39 //кнопка "Уволить"
#define URMB_OK_AREA 0x72 //кнопка "Ок"
#define URMB_UPGRADE_AREA 0x30 //стрелки апгрейда
#define URMB_MAGIC_AREA 0x14 //кнопка каста у волшебных драконов
#define URMB_NUMBER_AREA 0x23 //количество существ в стеке
BOOL NewMsg(unsigned char type, int unit)
{
char buf[200];
if(type==URMB_NAME_AREA)
{
sprintf(buf,"%02X %i", type, unit);
ShowMSG(buf,MSG_RIGHT_CLICK,-1, -1, -1, 0, -1, 0, -1, 0, -1, 0);
return true;
}
if(type==URMB_MAGIC_AREA)
{
ShowMSG("Колдовать/атаковать",MSG_RIGHT_CLICK,-1, -1, -1, 0, -1, 0, -1, 0, -1, 0);
return true;
}
if(type==URMB_EFFECTS_AREA)
{
CallERM(4001);
return true;
}
return false;
}
__fastcall int hook_5F4E84(const char *text, int type, int f1, int f2, int f3, int f4, int f5, int f6, int f7, int f8, int f9, int f10)
{
register void *eax asm("eax");
register void *ebx asm("ebx");
unsigned char unit = ((char*)ebx)[0x60];
if(NewMsg((int)eax,unit))
return 0;
else
return ShowMSG(text, type, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10);
}
extern "C" __stdcall BOOL DllMain( HINSTANCE hInstanceDLL, DWORD Reason, void *pReserved )
{
switch (Reason)
{
case DLL_PROCESS_ATTACH:
{
WriteHook((void*)0x5F4E84,(void*)hook_5F4E84,HOOKTYPE_CALL);
} break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}