Другое С/С++ Вопрос - Ответ

yoonost

Известный
61
3
Че за хуйня, оригинал функции верни вместо этих rwssssGloball288, ты же не логику описываешь , а входные данные меняешь
не много не понял, можешь дать пример? если я верну ориг функции то как он тогда будет данные менять
 

yoonost

Известный
61
3
полный код кинь
radar.cpp:
#include "radar.h"

void radar::initialize() {
    hookTransformPos.set_dest(0x583480);
    hookTransformPos.set_cb(std::bind(&radar::transformPos, this, _1, _2, _3));
    hookTransformPos.install();
}

RwV2d* __cdecl radar::transformPos(const decltype(hookTransformPos)& hook, CVector2D* out, CVector2D* in) {
    if (FrontEndMenuManager.drawRadarOrMap) {
        out->x = FrontEndMenuManager.m_fMapZoom * in->x + FrontEndMenuManager.m_fMapBaseX;
        out->y = FrontEndMenuManager.m_fMapBaseY - FrontEndMenuManager.m_fMapZoom * in->y;
    }
    else {
        out->x = 0.5 * (94.0 * (RsGlobal.maximumWidth * 0.0015625)) + RsGlobal.maximumWidth * 0.0015625 * 40.0 + 94.0 * (RsGlobal.maximumWidth * 0.0015625) * in->x * 0.5;
        out->y = RsGlobal.maximumHeight - 0.002232143 * RsGlobal.maximumHeight * 104.0 + 76.0 * (0.002232143 * RsGlobal.maximumHeight) * 0.5 - 76.0 * (0.002232143 * RsGlobal.maximumHeight) * in->y * 0.5;
    }
    return hook.get_trampoline()(out, in);
}
radar.h:
#pragma once

#include <kthook/kthook.hpp>

#include <plugin.h>
#include <common.h>
#include <CSprite2d.h>
#include <CVector.h>
#include "CMenuManager.h"

using namespace plugin;
using namespace std::placeholders;

class radar {
public:
    void initialize();

private:
    kthook::kthook_simple<RwV2d* (__cdecl*) (CVector2D*, CVector2D*)> hookTransformPos {};
    RwV2d* __cdecl transformPos(const decltype(hookTransformPos)& hook, CVector2D* out, CVector2D* in);
};

inline radar g_radar;
 

AdCKuY_DpO4uLa

Адский дрочер
Проверенный
303
608
radar.cpp:
#include "radar.h"

void radar::initialize() {
    hookTransformPos.set_dest(0x583480);
    hookTransformPos.set_cb(std::bind(&radar::transformPos, this, _1, _2, _3));
    hookTransformPos.install();
}

RwV2d* __cdecl radar::transformPos(const decltype(hookTransformPos)& hook, CVector2D* out, CVector2D* in) {
    if (FrontEndMenuManager.drawRadarOrMap) {
        out->x = FrontEndMenuManager.m_fMapZoom * in->x + FrontEndMenuManager.m_fMapBaseX;
        out->y = FrontEndMenuManager.m_fMapBaseY - FrontEndMenuManager.m_fMapZoom * in->y;
    }
    else {
        out->x = 0.5 * (94.0 * (RsGlobal.maximumWidth * 0.0015625)) + RsGlobal.maximumWidth * 0.0015625 * 40.0 + 94.0 * (RsGlobal.maximumWidth * 0.0015625) * in->x * 0.5;
        out->y = RsGlobal.maximumHeight - 0.002232143 * RsGlobal.maximumHeight * 104.0 + 76.0 * (0.002232143 * RsGlobal.maximumHeight) * 0.5 - 76.0 * (0.002232143 * RsGlobal.maximumHeight) * in->y * 0.5;
    }
    return hook.get_trampoline()(out, in);
}
radar.h:
#pragma once

#include <kthook/kthook.hpp>

#include <plugin.h>
#include <common.h>
#include <CSprite2d.h>
#include <CVector.h>
#include "CMenuManager.h"

using namespace plugin;
using namespace std::placeholders;

class radar {
public:
    void initialize();

private:
    kthook::kthook_simple<RwV2d* (__cdecl*) (CVector2D*, CVector2D*)> hookTransformPos {};
    RwV2d* __cdecl transformPos(const decltype(hookTransformPos)& hook, CVector2D* out, CVector2D* in);
};

inline radar g_radar;
C++:
class radar
{
private:
    kthook::kthook_simple<void(__cdecl*)(CVector2D*, CVector2D*)> TransformRadarPointToScreenSpaceHook{};
    static void __cdecl TransformRadarPointToScreenSpace_HOOKED(const decltype(TransformRadarPointToScreenSpaceHook)& hook, CVector2D* out, CVector2D* in);
public:
    void initialize();
} g_radar;

void radar::initialize()
{
    TransformRadarPointToScreenSpaceHook.set_dest(0x583480);
    TransformRadarPointToScreenSpaceHook.set_cb(&TransformRadarPointToScreenSpace_HOOKED);
    TransformRadarPointToScreenSpaceHook.install();
}

void __cdecl radar::TransformRadarPointToScreenSpace_HOOKED(const decltype(TransformRadarPointToScreenSpaceHook)& hook, CVector2D* out, CVector2D* in) {
    if (FrontEndMenuManager.drawRadarOrMap) {
        out->x = FrontEndMenuManager.m_fMapZoom * in->x + FrontEndMenuManager.m_fMapBaseX;
        out->y = FrontEndMenuManager.m_fMapBaseY - FrontEndMenuManager.m_fMapZoom * in->y;
    }
    else {
        out->x = 0.5 * (94.0 * (RsGlobal.maximumWidth * 0.0015625)) + RsGlobal.maximumWidth * 0.0015625 * 40.0 + 94.0 * (RsGlobal.maximumWidth * 0.0015625) * in->x * 0.5;
        out->y = RsGlobal.maximumHeight - 0.002232143 * RsGlobal.maximumHeight * 104.0 + 76.0 * (0.002232143 * RsGlobal.maximumHeight) * 0.5 - 76.0 * (0.002232143 * RsGlobal.maximumHeight) * in->y * 0.5;
    }
    //ты ведь в тупую логику переписал?? если так, то не нужно вообще ориг. функцию вызывать, т.к. все рассчеты будут тут
    return;
}
еще я не тестил эту лабуду
 

yoonost

Известный
61
3
C++:
class radar
{
private:
    kthook::kthook_simple<void(__cdecl*)(CVector2D*, CVector2D*)> TransformRadarPointToScreenSpaceHook{};
    static void __cdecl TransformRadarPointToScreenSpace_HOOKED(const decltype(TransformRadarPointToScreenSpaceHook)& hook, CVector2D* out, CVector2D* in);
public:
    void initialize();
} g_radar;

void radar::initialize()
{
    TransformRadarPointToScreenSpaceHook.set_dest(0x583480);
    TransformRadarPointToScreenSpaceHook.set_cb(&TransformRadarPointToScreenSpace_HOOKED);
    TransformRadarPointToScreenSpaceHook.install();
}

void __cdecl radar::TransformRadarPointToScreenSpace_HOOKED(const decltype(TransformRadarPointToScreenSpaceHook)& hook, CVector2D* out, CVector2D* in) {
    if (FrontEndMenuManager.drawRadarOrMap) {
        out->x = FrontEndMenuManager.m_fMapZoom * in->x + FrontEndMenuManager.m_fMapBaseX;
        out->y = FrontEndMenuManager.m_fMapBaseY - FrontEndMenuManager.m_fMapZoom * in->y;
    }
    else {
        out->x = 0.5 * (94.0 * (RsGlobal.maximumWidth * 0.0015625)) + RsGlobal.maximumWidth * 0.0015625 * 40.0 + 94.0 * (RsGlobal.maximumWidth * 0.0015625) * in->x * 0.5;
        out->y = RsGlobal.maximumHeight - 0.002232143 * RsGlobal.maximumHeight * 104.0 + 76.0 * (0.002232143 * RsGlobal.maximumHeight) * 0.5 - 76.0 * (0.002232143 * RsGlobal.maximumHeight) * in->y * 0.5;
    }
    //ты ведь в тупую логику переписал?? если так, то не нужно вообще ориг. функцию вызывать, т.к. все рассчеты будут тут
    return;
}
еще я не тестил эту лабуду
не работает, проверь у себя
логику стандартную использую для теста хука, в будущем буду под плагин делать
 

penta

Участник
47
10
1720629659893.png

Проще говоря рег каллбэка крашит игру. самп р3
 
  • Ха-ха
Реакции: ARMOR

penta

Участник
47
10
C++:
#include "main.h"

bool isPluginInitialized = false;

//std::unique_ptr<CD3DRender> pRender = nullptr;

LRESULT __stdcall WndProcCallBack(SAMP::CallBacks::HookedStructs::stWndProcParams *params) {
   
    if (isPluginInitialized) {
        if (ImGui_ImplWin32_WndProcHandler(params->hWnd, params->uMsg, params->wParam, params->lParam)) {
            return 1;
        }
    }

    return 0;//retn null if all good
}

static bool isOpen = false;

HRESULT __stdcall D3DPresentHook(SAMP::CallBacks::HookedStructs::stPresentParams *params) {

    if (isPluginInitialized) {
        ImGui_ImplDX9_NewFrame();//вызывалось до инициализации имгуи, поэтому крашило
        ImGui_ImplWin32_NewFrame();
        ImGui::NewFrame();

        if (isOpen) {
            if (ImGui::Begin("Тестовое меню##1337", &isOpen, ImGuiWindowFlags_::ImGuiWindowFlags_NoSavedSettings)) {

                static bool bIsDemoWindowActive = false;
                ImGui::Checkbox("Демо", &bIsDemoWindowActive);
                if(bIsDemoWindowActive)
                    ImGui::ShowDemoWindow(&bIsDemoWindowActive);

                for (int i = 0; i != SAMP_MAX_PLAYERS; i++) {
                    if (SAMP::pSAMP->getPlayers()->iIsListed[i] == 0 ||
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][0] == 0 ||
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][1] == 0 ||
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][2] == 0)
                        continue;

                    ImGui::Text("PlayerID: %d, position: %0.f %0.f %0.f", i,
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][0],
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][1],
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][2]);
                   
                }

                if (ImGui::Button("Отправить пакет")) {
                    stOnFootData data = SAMP::pSAMP->getPlayers()->pLocalPlayer->onFootData;
                    data.fPosition[2] += 10.0f;

                    BitStream bs;
                    bs.Write<unsigned __int8>(ID_PLAYER_SYNC);
                    bs.Write((PCHAR)&data, sizeof(stOnFootData));

                    SAMP::pSAMP->getRakNet()->Send(&bs);
                }

                if (ImGui::Button("Отправить RPC's")) {
                    constexpr char message[] = "Тестовое сообщение";
                    BitStream bsSend;
                    bsSend.Write((std::uint8_t)std::strlen(message));
                    bsSend.Write(message, (std::uint8_t)std::strlen(message));
                    SAMP::pSAMP->getRakNet()->SendRPC(RPC_Chat, &bsSend);
                }

                if (ImGui::Button("SAMP::classes::")) { //WORK on R1 and R3
                    SAMP::classes::pChat->AddMessage(-1, "Тестовое сообщение");
                    SAMP::classes::pGame->SetCursorMode(SAMP::classes::CursorMode::CMODE_NONE, false);
                   
                }

                for (int i = 0; i != SAMP_MAX_PLAYERS; i++) {
                    if (!SAMP::pSAMP->getPlayers()->IsPlayerStreamed(i))
                        continue;

#if defined (SAMP_R1_COMPILE)
                    ImGui::Text("name of %d: %s", i, SAMP::pSAMP->getPlayers()->pRemotePlayer[i]->szPlayerName);
#elif defined (SAMP_R3_COMPILE)
                    ImGui::Text("name of %d: %s", i, SAMP::pSAMP->getPlayers()->pRemotePlayer[i]->PlayerName.c_str());
#endif
                }

                if (ImGui::Button("Plugin SDK Teleport")) {
                    CVector dest = FindPlayerPed()->GetPosition();
                    dest.z += 5.0f;
                    FindPlayerPed()->Teleport(dest, false);
                }
               
                static int vehID = 0;
                ImGui::InputInt("Vehicle ID", &vehID);
                if (ImGui::Button("тп кар")) {
                    if (SAMP::pSAMP->getVehicles()->IsVehicleStreamed(vehID)) {
                        SAMP::pSAMP->getVehicles()->GetCVehicleFromSAMPVehicleID(vehID)->Teleport(FindPlayerPed()->GetPosition(), false);
                    }
                }

               

                if (ImGui::Button("emul packet")) {
                    stOnFootData data = SAMP::pSAMP->getPlayers()->pLocalPlayer->onFootData;
                    BitStream bs;
                    bs.Write<unsigned __int8>(ID_PLAYER_SYNC);
                    bs.Write<unsigned __int16>(49);//playerID
                    bs.Write((PCHAR)&data, sizeof(stOnFootData));
                    SAMP::pSAMP->getRakNet()->EmulPacket(&bs);
                }

                if (ImGui::Button("emul rpc")) {
                    BitStream bs;
                    bs.Write<float>(0.0f);
                    bs.Write<float>(0.0f);
                    bs.Write<float>(0.5f);
                    SAMP::pSAMP->getRakNet()->EmulRPC(RPC_ScrSetPlayerVelocity, &bs);
                }

                ImGui::End();
            }
        }

       

        ImGui::EndFrame();
        ImGui::Render();
        ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
        //pRender->Initialize(params->pDevice);

        //render example
        //if (SUCCEEDED(pRender->BeginRender())) {
        //    pRender->D3DBox(100, 100, 100, 100, 0xFF00BECC);
        //    pRender->EndRender();
        //}
       
       
    }

    return D3D_OK;
}

HRESULT __stdcall D3DResetHook(SAMP::CallBacks::HookedStructs::stResetParams *params) {

    if (isPluginInitialized) {
        ImGui_ImplDX9_InvalidateDeviceObjects();
        //pRender->Invalidate();
    }

    return D3D_OK;
}

bool __stdcall RakClientSendHook(SAMP::CallBacks::HookedStructs::stRakClientSend *params) {

    if (params->bitStream->GetData()[0] == ID_PLAYER_SYNC) {
        params->bitStream->ResetReadPointer();
        params->bitStream->IgnoreBits(8);
        stOnFootData data = { 0 };
        params->bitStream->Read((PCHAR)&data, sizeof(stOnFootData));

        //data.fMoveSpeed[2] = 1.0f;

        params->bitStream->ResetWritePointer();
        params->bitStream->Write<unsigned __int8>(ID_PLAYER_SYNC);
        params->bitStream->Write((PCHAR)&data, sizeof(stOnFootData));
    }

    return true;
}

bool __stdcall RakClientRecvHook(SAMP::CallBacks::HookedStructs::stRakClientRecv* params) {
    return true;
}

bool __stdcall RakClientRPCHook(SAMP::CallBacks::HookedStructs::stRakClientRPC *params) {

    return true;
}

bool __stdcall RakClientRPCRecvHook(SAMP::CallBacks::HookedStructs::stRakClientRPCRecv *params) {

    return true;
}


void __cdecl cmd(char *params) {
    isOpen ^= true;
}

const char* checkAddress(const char* ipadress, const char* adresses[], size_t size) {
    for (size_t i = 0; i < size; ++i) {
        if (std::strcmp(ipadress, adresses[i]) == 0) {
            return adresses[i];
        }
    }
    return nullptr;
}


void __stdcall GameLoop() {
    static bool initialized = false;
    if (!initialized) {
        if (SAMP::pSAMP->LoadAPI()) {
            initialized = true;
           
            ImGui::CreateContext();
            ImGuiIO& io = ImGui::GetIO();
            io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\Arial.ttf", 16, NULL, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic());
            (void)io;
            ImGui_ImplWin32_Init(GetActiveWindow());
            ImGui_ImplDX9_Init(SAMP::CallBacks::pCallBackRegister->GetIDirect3DDevice9());
            ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
            //renderф
            //pRender = std::make_unique<CD3DRender>(128);

            //initialization
            SAMP::pSAMP->addClientCommand("menu", cmd);
            SAMP::pSAMP->addMessageToChat(-1, "SAMP API By AdCKuY_DpO4uLa loaded. %s", SAMP::pSAMP->getInfo()->szIP);
            char* ipadress = SAMP::pSAMP->getInfo()->szIP;
            const char* adresses[] = { "46.174.52.144", "37.230.137.194", "37.230.228.142" };
            const char* result = checkAddress(ipadress, adresses, sizeof(adresses) / sizeof(adresses[0]));

            if (!result) {
            }            //init raknet callbacks
            SAMP::CallBacks::pCallBackRegister->RegisterRakClientCallback(RakClientSendHook);//registed RakClient Send Hook
            SAMP::CallBacks::pCallBackRegister->RegisterRakClientCallback(RakClientRecvHook);//registed RakClient Recv Hook
            SAMP::CallBacks::pCallBackRegister->RegisterRakClientCallback(RakClientRPCHook);//registed RakClient RPC Hook
            SAMP::CallBacks::pCallBackRegister->RegisterRakClientCallback(RakClientRPCRecvHook);//registed RakClient RPC recv Hook   

            isPluginInitialized = true;
        }
    }
    if (initialized) {    //gameLoop

       
       

    }
}



int __stdcall DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
    switch (dwReason)
    {
        case DLL_PROCESS_ATTACH: {
            SAMP::Init();
            SAMP::CallBacks::pCallBackRegister->RegisterGameLoopCallback(GameLoop);//register gameloop hook
            SAMP::CallBacks::pCallBackRegister->RegisterWndProcCallback(WndProcCallBack);//register wnd proc hook
            SAMP::CallBacks::pCallBackRegister->RegisterD3DCallback(D3DPresentHook);//register D3D present hook
            SAMP::CallBacks::pCallBackRegister->RegisterD3DCallback(D3DResetHook);//register D3D reset hook
            printf("\n -> Plugin loaded (%d)\n", GetTickCount());
            break;
        }
        case DLL_PROCESS_DETACH: {
            SAMP::pSAMP->unregisterChatCommand(cmd);

            SAMP::ShutDown();

            ImGui_ImplDX9_Shutdown();
            ImGui_ImplWin32_Shutdown();
            ImGui::DestroyContext();

            printf("\n -> Plugin unloaded (%d)\n", GetTickCount());
            break;
        }
    }
    return true;
UPD: крашит 12 айди пакета

P.S код не мой
 
Последнее редактирование:

F0RQU1N and

Известный
1,311
497
C++:
#include "main.h"

bool isPluginInitialized = false;

//std::unique_ptr<CD3DRender> pRender = nullptr;

LRESULT __stdcall WndProcCallBack(SAMP::CallBacks::HookedStructs::stWndProcParams *params) {
  
    if (isPluginInitialized) {
        if (ImGui_ImplWin32_WndProcHandler(params->hWnd, params->uMsg, params->wParam, params->lParam)) {
            return 1;
        }
    }

    return 0;//retn null if all good
}

static bool isOpen = false;

HRESULT __stdcall D3DPresentHook(SAMP::CallBacks::HookedStructs::stPresentParams *params) {

    if (isPluginInitialized) {
        ImGui_ImplDX9_NewFrame();//вызывалось до инициализации имгуи, поэтому крашило
        ImGui_ImplWin32_NewFrame();
        ImGui::NewFrame();

        if (isOpen) {
            if (ImGui::Begin("Тестовое меню##1337", &isOpen, ImGuiWindowFlags_::ImGuiWindowFlags_NoSavedSettings)) {

                static bool bIsDemoWindowActive = false;
                ImGui::Checkbox("Демо", &bIsDemoWindowActive);
                if(bIsDemoWindowActive)
                    ImGui::ShowDemoWindow(&bIsDemoWindowActive);

                for (int i = 0; i != SAMP_MAX_PLAYERS; i++) {
                    if (SAMP::pSAMP->getPlayers()->iIsListed[i] == 0 ||
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][0] == 0 ||
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][1] == 0 ||
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][2] == 0)
                        continue;

                    ImGui::Text("PlayerID: %d, position: %0.f %0.f %0.f", i,
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][0],
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][1],
                        SAMP::pSAMP->getStreamedOutPlayerInfo()->fPlayerPos[i][2]);
                  
                }

                if (ImGui::Button("Отправить пакет")) {
                    stOnFootData data = SAMP::pSAMP->getPlayers()->pLocalPlayer->onFootData;
                    data.fPosition[2] += 10.0f;

                    BitStream bs;
                    bs.Write<unsigned __int8>(ID_PLAYER_SYNC);
                    bs.Write((PCHAR)&data, sizeof(stOnFootData));

                    SAMP::pSAMP->getRakNet()->Send(&bs);
                }

                if (ImGui::Button("Отправить RPC's")) {
                    constexpr char message[] = "Тестовое сообщение";
                    BitStream bsSend;
                    bsSend.Write((std::uint8_t)std::strlen(message));
                    bsSend.Write(message, (std::uint8_t)std::strlen(message));
                    SAMP::pSAMP->getRakNet()->SendRPC(RPC_Chat, &bsSend);
                }

                if (ImGui::Button("SAMP::classes::")) { //WORK on R1 and R3
                    SAMP::classes::pChat->AddMessage(-1, "Тестовое сообщение");
                    SAMP::classes::pGame->SetCursorMode(SAMP::classes::CursorMode::CMODE_NONE, false);
                  
                }

                for (int i = 0; i != SAMP_MAX_PLAYERS; i++) {
                    if (!SAMP::pSAMP->getPlayers()->IsPlayerStreamed(i))
                        continue;

#if defined (SAMP_R1_COMPILE)
                    ImGui::Text("name of %d: %s", i, SAMP::pSAMP->getPlayers()->pRemotePlayer[i]->szPlayerName);
#elif defined (SAMP_R3_COMPILE)
                    ImGui::Text("name of %d: %s", i, SAMP::pSAMP->getPlayers()->pRemotePlayer[i]->PlayerName.c_str());
#endif
                }

                if (ImGui::Button("Plugin SDK Teleport")) {
                    CVector dest = FindPlayerPed()->GetPosition();
                    dest.z += 5.0f;
                    FindPlayerPed()->Teleport(dest, false);
                }
              
                static int vehID = 0;
                ImGui::InputInt("Vehicle ID", &vehID);
                if (ImGui::Button("тп кар")) {
                    if (SAMP::pSAMP->getVehicles()->IsVehicleStreamed(vehID)) {
                        SAMP::pSAMP->getVehicles()->GetCVehicleFromSAMPVehicleID(vehID)->Teleport(FindPlayerPed()->GetPosition(), false);
                    }
                }

              

                if (ImGui::Button("emul packet")) {
                    stOnFootData data = SAMP::pSAMP->getPlayers()->pLocalPlayer->onFootData;
                    BitStream bs;
                    bs.Write<unsigned __int8>(ID_PLAYER_SYNC);
                    bs.Write<unsigned __int16>(49);//playerID
                    bs.Write((PCHAR)&data, sizeof(stOnFootData));
                    SAMP::pSAMP->getRakNet()->EmulPacket(&bs);
                }

                if (ImGui::Button("emul rpc")) {
                    BitStream bs;
                    bs.Write<float>(0.0f);
                    bs.Write<float>(0.0f);
                    bs.Write<float>(0.5f);
                    SAMP::pSAMP->getRakNet()->EmulRPC(RPC_ScrSetPlayerVelocity, &bs);
                }

                ImGui::End();
            }
        }

      

        ImGui::EndFrame();
        ImGui::Render();
        ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
        //pRender->Initialize(params->pDevice);

        //render example
        //if (SUCCEEDED(pRender->BeginRender())) {
        //    pRender->D3DBox(100, 100, 100, 100, 0xFF00BECC);
        //    pRender->EndRender();
        //}
      
      
    }

    return D3D_OK;
}

HRESULT __stdcall D3DResetHook(SAMP::CallBacks::HookedStructs::stResetParams *params) {

    if (isPluginInitialized) {
        ImGui_ImplDX9_InvalidateDeviceObjects();
        //pRender->Invalidate();
    }

    return D3D_OK;
}

bool __stdcall RakClientSendHook(SAMP::CallBacks::HookedStructs::stRakClientSend *params) {

    if (params->bitStream->GetData()[0] == ID_PLAYER_SYNC) {
        params->bitStream->ResetReadPointer();
        params->bitStream->IgnoreBits(8);
        stOnFootData data = { 0 };
        params->bitStream->Read((PCHAR)&data, sizeof(stOnFootData));

        //data.fMoveSpeed[2] = 1.0f;

        params->bitStream->ResetWritePointer();
        params->bitStream->Write<unsigned __int8>(ID_PLAYER_SYNC);
        params->bitStream->Write((PCHAR)&data, sizeof(stOnFootData));
    }

    return true;
}

bool __stdcall RakClientRecvHook(SAMP::CallBacks::HookedStructs::stRakClientRecv* params) {
    return true;
}

bool __stdcall RakClientRPCHook(SAMP::CallBacks::HookedStructs::stRakClientRPC *params) {

    return true;
}

bool __stdcall RakClientRPCRecvHook(SAMP::CallBacks::HookedStructs::stRakClientRPCRecv *params) {

    return true;
}


void __cdecl cmd(char *params) {
    isOpen ^= true;
}

const char* checkAddress(const char* ipadress, const char* adresses[], size_t size) {
    for (size_t i = 0; i < size; ++i) {
        if (std::strcmp(ipadress, adresses[i]) == 0) {
            return adresses[i];
        }
    }
    return nullptr;
}


void __stdcall GameLoop() {
    static bool initialized = false;
    if (!initialized) {
        if (SAMP::pSAMP->LoadAPI()) {
            initialized = true;
          
            ImGui::CreateContext();
            ImGuiIO& io = ImGui::GetIO();
            io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\Arial.ttf", 16, NULL, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic());
            (void)io;
            ImGui_ImplWin32_Init(GetActiveWindow());
            ImGui_ImplDX9_Init(SAMP::CallBacks::pCallBackRegister->GetIDirect3DDevice9());
            ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
            //renderф
            //pRender = std::make_unique<CD3DRender>(128);

            //initialization
            SAMP::pSAMP->addClientCommand("menu", cmd);
            SAMP::pSAMP->addMessageToChat(-1, "SAMP API By AdCKuY_DpO4uLa loaded. %s", SAMP::pSAMP->getInfo()->szIP);
            char* ipadress = SAMP::pSAMP->getInfo()->szIP;
            const char* adresses[] = { "46.174.52.144", "37.230.137.194", "37.230.228.142" };
            const char* result = checkAddress(ipadress, adresses, sizeof(adresses) / sizeof(adresses[0]));

            if (!result) {
            }            //init raknet callbacks
            SAMP::CallBacks::pCallBackRegister->RegisterRakClientCallback(RakClientSendHook);//registed RakClient Send Hook
            SAMP::CallBacks::pCallBackRegister->RegisterRakClientCallback(RakClientRecvHook);//registed RakClient Recv Hook
            SAMP::CallBacks::pCallBackRegister->RegisterRakClientCallback(RakClientRPCHook);//registed RakClient RPC Hook
            SAMP::CallBacks::pCallBackRegister->RegisterRakClientCallback(RakClientRPCRecvHook);//registed RakClient RPC recv Hook  

            isPluginInitialized = true;
        }
    }
    if (initialized) {    //gameLoop

      
      

    }
}



int __stdcall DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
    switch (dwReason)
    {
        case DLL_PROCESS_ATTACH: {
            SAMP::Init();
            SAMP::CallBacks::pCallBackRegister->RegisterGameLoopCallback(GameLoop);//register gameloop hook
            SAMP::CallBacks::pCallBackRegister->RegisterWndProcCallback(WndProcCallBack);//register wnd proc hook
            SAMP::CallBacks::pCallBackRegister->RegisterD3DCallback(D3DPresentHook);//register D3D present hook
            SAMP::CallBacks::pCallBackRegister->RegisterD3DCallback(D3DResetHook);//register D3D reset hook
            printf("\n -> Plugin loaded (%d)\n", GetTickCount());
            break;
        }
        case DLL_PROCESS_DETACH: {
            SAMP::pSAMP->unregisterChatCommand(cmd);

            SAMP::ShutDown();

            ImGui_ImplDX9_Shutdown();
            ImGui_ImplWin32_Shutdown();
            ImGui::DestroyContext();

            printf("\n -> Plugin unloaded (%d)\n", GetTickCount());
            break;
        }
    }
    return true;
UPD: крашит 12 айди пакета

P.S код не мой
мб потому что ты 2 раза регаешь коллбеки?)))
 

TokyoQq

Новичок
6
3
как написать silent aim
типо у меня есть координаты кости головы но я не знаю как изменить координаты пули
 
Последнее редактирование:
  • Ха-ха
Реакции: Z3roKwq и chromiusj

0x9

Новичок
9
1
как в samp_api создать команду с параметрами?
скиньте пример пожалуйста
 
  • Ха-ха
Реакции: F0RQU1N and