- Joined
- May 5, 2008
- Messages
- 13
- Reaction score
- 1
Hello All,
for some reason when i try to hook the LevelUp function i cant get it working
if someone can see what is the problem it will be perfect.
when i try to Hook the Tick func everything working but keep repeating.
when i try to hook and do it on the LevelUp its not working at all.
(Using Core 2017)
#pragma comment(lib, "detours.lib")
#undef UNICODE
#include <cstdio>
#include <stdio.h>
#include "stdafx.h"
#include <windows.h>
#include <sstream>
#include "detours.h"
#include <process.h>
#pragma pack(1)
//The orginal Server Start function at 0x00424A40
static void (__stdcall *ServerStart)(int start) = (void (__stdcall*)(int start))0x00424A40;
static int (__thiscall *Tick)(void *thispointer) = (int (__thiscall*)(void*))0x00452620;
static int (__thiscall *LevelUp)(void *thispointer) = (int (__thiscall*)(void *))0x0045CC00;
static BOOL (__cdecl* WriteRed)(char* text, ...) = (BOOL (__cdecl*)(char* text, ...))0x004328C0;
static int (__stdcall *InsertItem)(int playerp, int type, int index, int amount, int prefix, int iid) = (int (__stdcall*)(int,int,int,int,int,int))0x004274A0;
//The original Server Console Write Blue function at 0x00432860
static BOOL (__cdecl *ConsoleWriteBlue)(const char* text, ...) = (BOOL (__cdecl*)(const char* text, ...))0x00432860;
//Our hooked Server Start function
void __stdcall Hooked_ServerStart(int start)
{
ServerStart(start); //Call normal Server start, if we wont do this, the server dont start
ConsoleWriteBlue("Jacobs Addons ...");
// Call Print Function after Server Start we should see an Hello World in Blue on Console
}
void __fastcall Hooked_LevelUp(void *thispointer, void* _edx)
{
int level = ((int*) thispointer)[15];
if (level == 75)
{
WriteRed("You Reached Level 75!");
ConsoleWriteBlue("Reached!");
InsertItem((int)thispointer,21,1,0,1,-1);
}
}
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)ServerStart, Hooked_ServerStart);
DetourAttach(&(PVOID&)LevelUp, Hooked_LevelUp);
//Insert our function into Mainserver
DetourTransactionCommit();
break;
}
case DLL_PROCESS_DETACH:
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)ServerStart, Hooked_ServerStart);
DetourDetach(&(PVOID&)LevelUp, Hooked_LevelUp);
//Detach our function
DetourTransactionCommit();
break;
}
}
return TRUE;
}
for some reason when i try to hook the LevelUp function i cant get it working
if someone can see what is the problem it will be perfect.
when i try to Hook the Tick func everything working but keep repeating.
when i try to hook and do it on the LevelUp its not working at all.
(Using Core 2017)
#pragma comment(lib, "detours.lib")
#undef UNICODE
#include <cstdio>
#include <stdio.h>
#include "stdafx.h"
#include <windows.h>
#include <sstream>
#include "detours.h"
#include <process.h>
#pragma pack(1)
//The orginal Server Start function at 0x00424A40
static void (__stdcall *ServerStart)(int start) = (void (__stdcall*)(int start))0x00424A40;
static int (__thiscall *Tick)(void *thispointer) = (int (__thiscall*)(void*))0x00452620;
static int (__thiscall *LevelUp)(void *thispointer) = (int (__thiscall*)(void *))0x0045CC00;
static BOOL (__cdecl* WriteRed)(char* text, ...) = (BOOL (__cdecl*)(char* text, ...))0x004328C0;
static int (__stdcall *InsertItem)(int playerp, int type, int index, int amount, int prefix, int iid) = (int (__stdcall*)(int,int,int,int,int,int))0x004274A0;
//The original Server Console Write Blue function at 0x00432860
static BOOL (__cdecl *ConsoleWriteBlue)(const char* text, ...) = (BOOL (__cdecl*)(const char* text, ...))0x00432860;
//Our hooked Server Start function
void __stdcall Hooked_ServerStart(int start)
{
ServerStart(start); //Call normal Server start, if we wont do this, the server dont start
ConsoleWriteBlue("Jacobs Addons ...");
// Call Print Function after Server Start we should see an Hello World in Blue on Console
}
void __fastcall Hooked_LevelUp(void *thispointer, void* _edx)
{
int level = ((int*) thispointer)[15];
if (level == 75)
{
WriteRed("You Reached Level 75!");
ConsoleWriteBlue("Reached!");
InsertItem((int)thispointer,21,1,0,1,-1);
}
}
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)ServerStart, Hooked_ServerStart);
DetourAttach(&(PVOID&)LevelUp, Hooked_LevelUp);
//Insert our function into Mainserver
DetourTransactionCommit();
break;
}
case DLL_PROCESS_DETACH:
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)ServerStart, Hooked_ServerStart);
DetourDetach(&(PVOID&)LevelUp, Hooked_LevelUp);
//Detach our function
DetourTransactionCommit();
break;
}
}
return TRUE;
}