How would I call a function inside the game?

Kelsi235

Active member
Joined
Jun 2, 2019
Messages
53
Reaction score
4
I know that
Int32 sampSayAddress = "samp.dll" + 0x57f0

How do I call this with my message?
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
Here's an example in C of how you can define pointer to some function if you know its' address.
C:
// tested with: http://www.onlinegdb.com/online_c_compiler
#include <stdio.h>
void original_game_func(char * to_say){
    printf("%s\n", to_say);
}

void (*my_func)(char *) = 0x400586;

int main()
{
    printf("original_game_func is located at: 0x%X\n", original_game_func); // prints: 0x400586
    my_func("hello there");
    return 0;
}

Here's some more stuff you could find useful:
https://www.unknowncheats.me/forum/c-and-c-/106853-call-function-samp-dll.html

I have no way to test it now though...
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
Just tested it and it worked properly:
C++:
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"

#define FUNC_SAY 0x5820

void main() {

    Sleep(16000);

    DWORD SampDLL = (DWORD)GetModuleHandleA("samp.dll");
    void (*say)(const char*) = (void (*)(const char*)) (SampDLL + FUNC_SAY);

    while (true) {
        Sleep(3000);

        say("A");
    }
    
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        CreateThread(0, 0, (LPTHREAD_START_ROUTINE)main, 0, 0, 0);
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

I used the 0.3.7 RC3 client so the offset of the function is different from the one you posted, I found it here:
http://ugbase.eu/index.php?threads/collection-of-0-3-7-0-offsets.10651/page-3#post-116213
 
Top