Информация Полезные функции

kin4stat

mq-team
Всефорумный модератор
2,730
4,710
отключает и включает возможность открывать и закрывать таб (0.3.7-R1)
C++:
memcpy((void*)(GetModuleHandleA("samp.dll") + 0x6AD33), (BYTE*)"\x83\x3E\x01", 3);//отключить таб
memcpy((void*)(GetModuleHandleA("samp.dll") + 0x6AD33), (BYTE*)"\x83\x3E\x00", 3);//включить таб
Крашнет, т.к. протекцию памяти не снял. И вообще, с такой мелочью лучше в луа сниппеты
 
  • Ха-ха
Реакции: THERION

Gunborg Johansson

Потрачен
32
21
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
включает курсор (нужен plugin-sdk)
C++:
#ifdef IMGUI_VERSION
void show_cursor(bool show, bool is_imgui = false)
#else
void show_cursor(bool show)
#endif
{
    if (show) {
        patch::Nop(0x541DF5, 5); // don't call CControllerConfigManager::AffectPadFromKeyBoard
        patch::Nop(0x53F417, 5); // don't call CPad__getMouseState
        patch::SetRaw(0x53F41F, "\x33\xC0\x0F\x84", 4); // test eax, eax -> xor eax, eax
                                                        // jl loc_53F526 -> jz loc_53F526
        patch::PutRetn(0x6194A0); // disable RsMouseSetPos (ret)
#ifdef IMGUI_VERSION
        if(is_imgui) ImGui::GetIO().MouseDrawCursor = true; else
#endif
        static_cast<IDirect3DDevice9 *>(RwD3D9GetCurrentD3DDevice())->ShowCursor(TRUE);
    } else {
        patch::SetRaw(0x541DF5, "\xE8\x46\xF3\xFE\xFF", 5); // call CControllerConfigManager::AffectPadFromKeyBoard
        patch::SetRaw(0x53F417, "\xE8\xB4\x7A\x20\x00", 5); // call CPad__getMouseState
        patch::SetRaw(0x53F41F, "\x85\xC0\x0F\x8C", 4); // xor eax, eax -> test eax, eax
                                                        // jz loc_53F526 -> jl loc_53F526
        patch::SetUChar(0x6194A0, 0xE9); // jmp setup
        static_cast<IDirect3DDevice9 *>(RwD3D9GetCurrentD3DDevice())->ShowCursor(FALSE);
#ifdef IMGUI_VERSION
        ImGui::GetIO().MouseDrawCursor = false;
#endif
    }

    CPad::NewMouseControllerState.X = 0;
    CPad::NewMouseControllerState.Y = 0;
    Call<0x541BD0>(); // CPad::ClearMouseHistory
    Call<0x541DD0>(); // CPad::UpdatePads
}
Alternative realization (w/o plugin sdk):
C++:
void showCursor(bool state)
{
    using RwD3D9GetCurrentD3DDevice_t = LPDIRECT3DDEVICE9(__cdecl *)();

    auto rwCurrentD3dDevice{reinterpret_cast<
        RwD3D9GetCurrentD3DDevice_t>(0x7F9D50U)()};

    if (nullptr == rwCurrentD3dDevice) {
        return;
    }

    static DWORD
        updateMouseProtection,
        rsMouseSetPosProtFirst,
        rsMouseSetPosProtSecond;

    if (state)
    {
        ::VirtualProtect(reinterpret_cast<void *>(0x53F3C6U), 5U,
            PAGE_EXECUTE_READWRITE, &updateMouseProtection);

        ::VirtualProtect(reinterpret_cast<void *>(0x53E9F1U), 5U,
            PAGE_EXECUTE_READWRITE, &rsMouseSetPosProtFirst);

        ::VirtualProtect(reinterpret_cast<void *>(0x748A1BU), 5U,
            PAGE_EXECUTE_READWRITE, &rsMouseSetPosProtSecond);

        // NOP: CPad::UpdateMouse
        *reinterpret_cast<uint8_t *>(0x53F3C6U) = 0xE9U;
        *reinterpret_cast<uint32_t *>(0x53F3C6U + 1U) = 0x15BU;

        // NOP: RsMouseSetPos
        memset(reinterpret_cast<void *>(0x53E9F1U), 0x90, 5U);
        memset(reinterpret_cast<void *>(0x748A1BU), 0x90, 5U);

        rwCurrentD3dDevice->ShowCursor(TRUE);
    }
    else
    {
        // Original: CPad::UpdateMouse
        memcpy(reinterpret_cast<void *>(0x53F3C6U), "\xE8\x95\x6C\x20\x00", 5U);

        // Original: RsMouseSetPos
        memcpy(reinterpret_cast<void *>(0x53E9F1U), "\xE8\xAA\xAA\x0D\x00", 5U);
        memcpy(reinterpret_cast<void *>(0x748A1BU), "\xE8\x80\x0A\xED\xFF", 5U);

        using CPad_ClearMouseHistory_t = void(__cdecl *)();
        using CPad_UpdatePads_t = void(__cdecl *)();

        reinterpret_cast<CPad_ClearMouseHistory_t>(0x541BD0U)();
        reinterpret_cast<CPad_UpdatePads_t>(0x541DD0U)();

        ::VirtualProtect(reinterpret_cast<void *>(0x53F3C6U), 5U,
            updateMouseProtection, &updateMouseProtection);

        ::VirtualProtect(reinterpret_cast<void *>(0x53E9F1U), 5U,
            rsMouseSetPosProtFirst, &rsMouseSetPosProtFirst);

        ::VirtualProtect(reinterpret_cast<void *>(0x748A1BU), 5U,
            rsMouseSetPosProtSecond, &rsMouseSetPosProtSecond);

        rwCurrentD3dDevice->ShowCursor(FALSE);
    }
}
 

Gunborg Johansson

Потрачен
32
21
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Function for converting game 3D coordinates to screen coordinates (noticed that some use the self-written CalcScreenCoors function, lol)

C++:
namespace Game
{
    struct Vector
    {
        float x, y, z;

        Vector(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
        Vector() {x = y = z = 0;}
    };
}

Game::Vector convertGameCoordsToScreen(Game::Vector worldCoords)
{
    using CalcScreenCoors_t = bool(__cdecl *)(
        Game::Vector *, Game::Vector *, float *, float *);

    Game::Vector screenCoords;

    auto gameFunction{reinterpret_cast<CalcScreenCoors_t>(0x71DA00U)};

    float unusedParams[2U]{0};
    gameFunction(&worldCoords, &screenCoords,
        &unusedParams[0U], &unusedParams[1U]);

    return screenCoords;
}
 
Последнее редактирование:

sc6ut

неизвестный
Модератор
382
1,075
Отключает/Включает воиспроизвидение звука в гта (лишь не дает воиспрозвести новый звук, старые звуки не отключает).
C++:
void toggle_sound(bool toggle)
{
    DWORD Protect = PAGE_EXECUTE_READWRITE;
    VirtualProtect(reinterpret_cast<void*>(0x4D86B0), 8, Protect, &Protect);
    memcpy(reinterpret_cast<void*>(0x4D86B0), (toggle ? "\xB8\x00\x00\x00\x00\xC2\x1C\x00" : "\x51\x56\x57\x8B\x7C\x24\x10\x66"), 8);
    VirtualProtect(reinterpret_cast<void*>(0x4D86B0), 8, Protect, &Protect);
}
 

Gunborg Johansson

Потрачен
32
21
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Отключает/Включает воиспроизвидение звука в гта (лишь не дает воиспрозвести новый звук, старые звуки не отключает).
C++:
void toggle_sound(bool toggle)
{
    DWORD Protect = PAGE_EXECUTE_READWRITE;
    VirtualProtect(reinterpret_cast<void*>(0x4D86B0), 8, Protect, &Protect);
    memcpy(reinterpret_cast<void*>(0x4D86B0), (toggle ? "\xB8\x00\x00\x00\x00\xC2\x1C\x00" : "\x51\x56\x57\x8B\x7C\x24\x10\x66"), 8);
    VirtualProtect(reinterpret_cast<void*>(0x4D86B0), 8, Protect, &Protect);
}
Unsafe code, VirtualProtect function returns BOOL (using BOOL = int), u should check it out
 
  • Нравится
Реакции: MeG@LaDo[N] ^_^

kin4stat

mq-team
Всефорумный модератор
2,730
4,710
Unsafe code, VirtualProtect function returns BOOL (using BOOL = int), u should check it out
ok.
Alternative realization (w/o plugin sdk):
C++:
void showCursor(bool state)
{
    using RwD3D9GetCurrentD3DDevice_t = LPDIRECT3DDEVICE9(__cdecl *)();

    auto rwCurrentD3dDevice{reinterpret_cast<
        RwD3D9GetCurrentD3DDevice_t>(0x7F9D50U)()};

    if (nullptr == rwCurrentD3dDevice) {
        return;
    }

    static DWORD
        updateMouseProtection,
        rsMouseSetPosProtFirst,
        rsMouseSetPosProtSecond;

    if (state)
    {
        ::VirtualProtect(reinterpret_cast<void *>(0x53F3C6U), 5U,
            PAGE_EXECUTE_READWRITE, &updateMouseProtection);

        ::VirtualProtect(reinterpret_cast<void *>(0x53E9F1U), 5U,
            PAGE_EXECUTE_READWRITE, &rsMouseSetPosProtFirst);

        ::VirtualProtect(reinterpret_cast<void *>(0x748A1BU), 5U,
            PAGE_EXECUTE_READWRITE, &rsMouseSetPosProtSecond);

        // NOP: CPad::UpdateMouse
        *reinterpret_cast<uint8_t *>(0x53F3C6U) = 0xE9U;
        *reinterpret_cast<uint32_t *>(0x53F3C6U + 1U) = 0x15BU;

        // NOP: RsMouseSetPos
        memset(reinterpret_cast<void *>(0x53E9F1U), 0x90, 5U);
        memset(reinterpret_cast<void *>(0x748A1BU), 0x90, 5U);

        rwCurrentD3dDevice->ShowCursor(TRUE);
    }
    else
    {
        // Original: CPad::UpdateMouse
        memcpy(reinterpret_cast<void *>(0x53F3C6U), "\xE8\x95\x6C\x20\x00", 5U);

        // Original: RsMouseSetPos
        memcpy(reinterpret_cast<void *>(0x53E9F1U), "\xE8\xAA\xAA\x0D\x00", 5U);
        memcpy(reinterpret_cast<void *>(0x748A1BU), "\xE8\x80\x0A\xED\xFF", 5U);

        using CPad_ClearMouseHistory_t = void(__cdecl *)();
        using CPad_UpdatePads_t = void(__cdecl *)();

        reinterpret_cast<CPad_ClearMouseHistory_t>(0x541BD0U)();
        reinterpret_cast<CPad_UpdatePads_t>(0x541DD0U)();

        ::VirtualProtect(reinterpret_cast<void *>(0x53F3C6U), 5U,
            updateMouseProtection, &updateMouseProtection);

        ::VirtualProtect(reinterpret_cast<void *>(0x53E9F1U), 5U,
            rsMouseSetPosProtFirst, &rsMouseSetPosProtFirst);

        ::VirtualProtect(reinterpret_cast<void *>(0x748A1BU), 5U,
            rsMouseSetPosProtSecond, &rsMouseSetPosProtSecond);

        rwCurrentD3dDevice->ShowCursor(FALSE);
    }
}
 
  • Нравится
  • Ха-ха
Реакции: mzxer и sc6ut

ANZR

Известный
168
104
Возвращает координаты прицела на экране (подходит для всех разрешений).

C++:
void getCrossHairPos(int &crosshairPosX, int &crosshairPosY)
{
    int iHeight, iWidth;
    SF->getGame()->getScreenResolution(&iWidth, &iHeight);
    float chOff1 = *(float*)0xB6EC10, chOff2 = *(float*)0xB6EC14;
    crosshairPosX = iWidth * chOff2; // Координаты прицела по оси Z
    crosshairPosY = iHeight * chOff1; // Координаты прицела по оси Y
}

Использование:
С++:
int crosshairPosX, int crosshairPosY
getCrossHairPos(crosshairPosX, crosshairPosY);
 
  • Нравится
Реакции: gaZmanoV

bottom_text

Известный
673
317
0.3.7 R-1
Проверяет, открыт ли чат

C++:
bool isChatOpen() {
    return *reinterpret_cast<BYTE*>(*reinterpret_cast<DWORD*>(sampAddress + 0x12E350) + 0x3C);
}

Проверяет, открыт ли ScoreBoard(Tab)
C++:
bool isScoreBoardOpen() {
    return *reinterpret_cast<BYTE*>(*reinterpret_cast<DWORD*>(sampAddress + 0x21A0B4));
}
 

sc6ut

неизвестный
Модератор
382
1,075
кусок говнокода позволяющий получать название кнопки по ее айди и наоброт.
keys.h:
#include <cstdint>
#include <unordered_map>
#include <string_view>
 
static const std::unordered_map<uint32_t, std::string_view> g_keysIdToName {
    // letters
    { 65, "A" }, { 66, "B" }, { 67, "C" }, { 68, "D" },
    { 69, "E" }, { 70, "F" }, { 71, "G" }, { 72, "H" },
    { 73, "I" }, { 74, "J" }, { 75, "K" }, { 76, "L" },
    { 77, "M" }, { 78, "N" }, { 79, "O" }, { 80, "P" },
    { 81, "Q" }, { 82, "R" }, { 83, "S" }, { 84, "T" },
    { 85, "U" }, { 86, "V" }, { 87, "W" }, { 88, "X" },
    { 89, "Y" }, { 90, "Z" },
    // numbers
    { 48, "0" }, { 49, "1" }, { 50, "2" }, { 51, "3" },
    { 52, "4" }, { 53, "5" }, { 54, "6" }, { 55, "7" },
    { 56, "8" }, { 57, "9" },
    // f-keys
    { 112, "F1" }, { 113, "F2" }, { 114, "F3" }, { 115, "F4" },
    { 116, "F5" }, { 117, "F6" }, { 118, "F7" }, { 119, "F8" },
    { 120, "F9" }, { 121, "F10" }, { 122, "F11" }, { 123, "F12" },
    // numpad
    { 96, "NUM0" }, { 97, "NUM1" }, { 98, "NUM2" }, { 99, "NUM3" },
    { 100, "NUM4" }, { 101, "NUM5" }, { 102, "NUM6" }, { 103, "NUM7" },
    { 104, "NUM8" }, { 105, "NUM9" },
    // math opers
    { 106, "*" }, { 107, "+" }, { 108, "|" }, { 109, "-" }, { 110, "." },
    { 111, "/" },
    // other
    { 19, "PAUSE" }, { 35, "END" }, { 36, "HOME" }, { 45, "INSERT" },
    { 46, "DELETE" },
    { 160, "LSHIFT" }, { 161, "RSHIFT" }, { 162, "LCTRL" }, { 163, "RCTRL" },
    { 164, "LALT" }, { 165, "RALT" }
};

static const std::unordered_map<std::string_view, uint32_t> g_keysNameToId {
    // letters
    { "A", 65 }, { "B", 66 }, { "C", 67 }, { "D", 68 },
    { "E", 69 }, { "F", 70 }, { "G", 71 }, { "H", 72 },
    { "I", 73 }, { "J", 74 }, { "K", 75 }, { "L", 76 },
    { "M", 77 }, { "N", 78 }, { "O", 79 }, { "P", 80 },
    { "Q", 81 }, { "R", 82 }, { "S", 83 }, { "T", 84 },
    { "U", 85 }, { "V", 86 }, { "W", 87 }, { "X", 88 },
    { "Y", 89 }, { "Z", 90 },
    // numbers
    { "0", 48 }, { "1", 49 }, { "2", 50 }, { "3", 51 },
    { "4", 52 }, { "5", 53 }, { "6", 54 }, { "7", 55 },
    { "8", 56 }, { "9", 57 },
    // f-keys
    { "F1", 112 }, { "F2", 113 }, { "F3", 114 }, { "F4", 115 },
    { "F5", 116 }, { "F6", 117 }, { "F7", 118 }, { "F8", 119 },
    { "F9", 120 }, { "F10", 121 }, { "F11", 122 }, { "F12", 123 },
    // numpad
    { "NUM0", 96 }, { "NUM1", 97 }, { "NUM2", 98 }, { "NUM3", 99 },
    { "NUM4", 100 }, { "NUM5", 101 }, { "NUM6", 102 }, { "NUM7", 103 },
    { "NUM8", 104 }, { "NUM9", 105 },
    // math opers
    { "*", 106 }, { "+", 107 }, { "|", 108 }, { "-", 109 }, { ".", 110 },
    { "/", 111 },
    // other
    { "PAUSE", 19 }, { "END", 35 }, { "HOME", 36 }, { "INSERT", 45 },
    { "DELETE", 46 },
    { "LSHIFT", 160 }, { "RSHIFT", 161 }, { "LCTRL", 162 }, { "RCTRL", 163 },
    { "LALT", 164 }, { "RALT", 165 }
};
 

Smeruxa

Известный
1,295
680
Проверяет активность текст дравов ( sf api crmp )
C++:
bool check_textdraw_active() {
    bool text_draw_active = false;
    for (int i = 0; i <= SAMP_MAX_TEXTDRAWS; i++) {
        if (SF->getSAMP()->getNetGame()->pools->textdrawPool->IsExists(i))
            text_draw_active = true;
    }
    return text_draw_active;
}
 
  • Bug
Реакции: paulohardy

kin4stat

mq-team
Всефорумный модератор
2,730
4,710
Проверяет активность текст дравов ( sf api crmp )
C++:
bool check_textdraw_active() {
    bool text_draw_active = false;
    for (int i = 0; i <= SAMP_MAX_TEXTDRAWS; i++) {
        if (SF->getSAMP()->getNetGame()->pools->textdrawPool->IsExists(i))
            text_draw_active = true;
    }
    return text_draw_active;
}
C++:
bool check_textdraw_active() {
    for (int i = 0; i <= SAMP_MAX_TEXTDRAWS; i++) {
        if (SF->getSAMP()->getNetGame()->pools->textdrawPool->IsExists(i))
            return true;
    }
    return false;
}
 
  • Влюблен
Реакции: Smeruxa

vegas

Известный
637
444
Приведение строки к нижнему регистру, работает как с латиницей так и с кирилицей
C++:
string LowerString(string str)
{
    for (int i = 0; i < size(str); i++)
    {
        if (str[i] >= 'A' && str[i] <= 'Z') str[i] += 'z' - 'Z';
        if (str[i] >= 'А' && str[i] <= 'Я') str[i] += 'я' - 'Я';
    }
    return str;
}
 

ALF

Известный
Проверенный
320
537
Приведение строки к нижнему регистру, работает как с латиницей так и с кирилицей
C++:
string LowerString(string str)
{
    for (int i = 0; i < size(str); i++)
    {
        if (str[i] >= 'A' && str[i] <= 'Z') str[i] += 'z' - 'Z';
        if (str[i] >= 'А' && str[i] <= 'Я') str[i] += 'я' - 'Я';
    }
    return str;
}
ужасно
 
  • Нравится
Реакции: gaZmanoV и sc6ut

kin4stat

mq-team
Всефорумный модератор
2,730
4,710
Сделай лучше и выложи сюда
Работает с любой однобайтовой хуйней которую ты в нее запихнешь(при условии что у тебя такая же локаль стоит)
C++:
auto tolower = [](char* string, std::size_t str_size) -> void {
    std::use_facet<std::ctype<char>>(std::locale()).tolower(string, string + str_size);
}
Или например вот так:
C++:
auto tolower = [](std::string& str) -> void {
    std::transform(str.begin(), str.end(), [](unsigned char c){ return std::tolower(c); });
}
 
Последнее редактирование:
  • Нравится
Реакции: Z3roKwq, sc6ut и ALF