| nonelike |
08.10.2024 22:22 |
Цитата:
Сообщение от ARMOR
C++:
Код:
using
CChat__AddEntry
=
void
(
__thiscall
*
)
(
void
*
,
int
,
const
char
*
,
const
char
*
,
unsigned
long
,
unsigned
long
)
;
CChat__AddEntry pOriginalFunction
=
nullptr
;
void
*
SetCallHook
(
uintptr_t HookAddress
,
void
*
DetourFunction
)
{
uintptr_t OriginalFunction
=
*
reinterpret_cast
(
HookAddress
+
1
)
+
HookAddress
+
5
;
DWORD oldProt
;
VirtualProtect
(
reinterpret_cast
(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
PAGE_READWRITE
,
&
oldProt
)
;
*
reinterpret_cast
(
HookAddress
+
1
)
=
reinterpret_cast
(
DetourFunction
)
-
HookAddress
-
5
;
VirtualProtect
(
reinterpret_cast
(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
oldProt
,
&
oldProt
)
;
return
reinterpret_cast
(
OriginalFunction
)
;
}
void
__fastcall
HOOK_AddEntry
(
void
*
pChat
,
int
nType
,
const
char
*
szText
,
const
char
*
szPrefix
,
unsigned
long
textColor
,
unsigned
long
prefixColor
)
{
pOriginalFunction
(
pChat
,
nType
,
szText
,
szPrefix
,
textColor
,
prefixColor
)
;
}
if
(
uintptr_t dwSAMP
=
reinterpret_cast
(
GetModuleHandleA
(
"samp.dll"
)
)
;
dwSAMP
!=
0
)
{
pOriginalFunction
=
reinterpret_cast
(
SetCallHook
(
dwSAMP
+
0x67460
,
&
HOOK_AddEntry
)
)
;
}
Если все равно крашит - проблема в адресе или функции для хука
|
адрес брал с https://github.com/BlastHackNet/SAMP...R3-1/CChat.cpp
https://forum.antichat.xyz/attachments/28547032/
также глянул в иде, адреса совпадают на р3
крашит до сих пор
плюс:
Код:
#include "plugin.h"
#include
using
CChat__AddEntry
=
void
(
__thiscall
*
)
(
void
*
,
int
,
const
char
*
,
const
char
*
,
unsigned
long
,
unsigned
long
)
;
CChat__AddEntry pOriginalFunction
=
nullptr
;
void
*
SetCallHook
(
uintptr_t HookAddress
,
void
*
DetourFunction
)
{
uintptr_t OriginalFunction
=
*
reinterpret_cast
(
HookAddress
+
1
)
+
HookAddress
+
5
;
DWORD oldProt
;
VirtualProtect
(
reinterpret_cast
(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
PAGE_READWRITE
,
&
oldProt
)
;
*
reinterpret_cast
(
HookAddress
+
1
)
=
reinterpret_cast
(
DetourFunction
)
-
HookAddress
-
5
;
VirtualProtect
(
reinterpret_cast
(
HookAddress
+
1
)
,
sizeof
(
uintptr_t
)
,
oldProt
,
&
oldProt
)
;
return
reinterpret_cast
(
OriginalFunction
)
;
}
void
__fastcall
HOOK_AddEntry
(
void
*
pChat
,
int
nType
,
const
char
*
szText
,
const
char
*
szPrefix
,
unsigned
long
textColor
,
unsigned
long
prefixColor
)
{
std
::
cout
: "
ref
(
)
==
nullptr
)
return
game_loop_hook
.
call_original
(
)
;
initialized
=
true
;
if
(
uintptr_t dwSAMP
=
reinterpret_cast
(
GetModuleHandleA
(
"samp.dll"
)
)
;
dwSAMP
!=
0
)
{
pOriginalFunction
=
reinterpret_cast
(
SetCallHook
(
dwSAMP
+
0x67460
,
&
HOOK_AddEntry
)
)
;
}
return
game_loop_hook
.
call_original
(
)
;
}
void
c_plugin
::
attach_console
(
)
{
if
(
!
AllocConsole
(
)
)
return
;
FILE
*
f
;
freopen_s
(
&
f
,
"CONOUT$"
,
"w"
,
stdout
)
;
freopen_s
(
&
f
,
"CONOUT$"
,
"w"
,
stderr
)
;
freopen_s
(
&
f
,
"CONIN$"
,
"r"
,
stdin
)
;
}
c_plugin
::
c_plugin
(
HMODULE hmodule
)
:
hmodule
(
hmodule
)
{
attach_console
(
)
;
game_loop_hook
.
add
(
&
c_plugin
::
game_loop
)
;
}
c_plugin
::
~
c_plugin
(
)
{
rakhook
::
destroy
(
)
;
}
|