How do I fix an unhandled exception in my dll?

0

Im writing an aimbot for a game called assault cube and I have written a function to grab all of the players in the game. Im currently trying to get the team of the player that my function gets, but for some weird reason I get an error. The Error: Unhandled exception at 0x08ED66D0 (finalaimbot.dll) in ac_client.exe: 0xC0000005: Access violation reading location 0x000003CA.

This is really weird because the address im reading from is way higher than 0x3CA.

// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include <windows.h>
#include <iostream>
#include <string>

DWORD EntityList = 0x50F4F8;
DWORD Player = *reinterpret_cast<int*>(0x50F4F4);
DWORD OnlinePlayers = 0x50F500;

DWORD MouseX = 0x40;
DWORD MouseY = 0x44;

DWORD HeadX = 0x4;
DWORD HeadY = 0x8;
DWORD HeadZ = 0xC;

DWORD Team = 0x3C2;

using namespace std;

struct vec3 {
    float x, y, z;
};
float GetDistance3D(vec3 m_pos, vec3 en_pos)
{
    float res = (float)(sqrt(((en_pos.x - m_pos.x) * (en_pos.x - m_pos.x)) + ((en_pos.y - m_pos.y) * (en_pos.y - m_pos.y)) + ((en_pos.z - m_pos.z) * (en_pos.z - m_pos.z))));
    return res;
}
void aim(vec3 pos) {// function for aiming at a position
    *reinterpret_cast<float*>(Player + MouseX) = pos.x;
    *reinterpret_cast<float*>(Player + MouseY) = pos.y;
}
DWORD WINAPI MainThread(LPVOID lpArgs) {
    while (true) {
        int onlinePlayers = *reinterpret_cast<int*>(OnlinePlayers);
        int myTeam = *reinterpret_cast<int*>(Player + Team);
        vec3 MyPos;

        MyPos.x = *reinterpret_cast<float*>(Player + HeadX);
        MyPos.y = *reinterpret_cast<float*>(Player + HeadX);
        MyPos.z = *reinterpret_cast<float*>(Player + HeadX);
        if (onlinePlayers > 1) {
            for (DWORD x = 0x4; x <= (0x4 * (onlinePlayers - 1)); x += 0x4) {
                DWORD EnemyBase = *reinterpret_cast<int*>(EntityList + x);
                DWORD EnemyTeam = *reinterpret_cast<int*>(EnemyBase + Team);
                vec3 EnemyPos;

                EnemyPos.x = *reinterpret_cast<float*>(EnemyBase + HeadX);
                EnemyPos.y = *reinterpret_cast<float*>(EnemyBase + HeadY);
                EnemyPos.z = *reinterpret_cast<float*>(EnemyBase + HeadZ);

                float Distance = GetDistance3D(MyPos, EnemyPos);
                if (EnemyTeam == myTeam) {
                    MessageBoxA(0, "Enemy is on your team", "Enemy Detected", 0);
                }
                else {
                    MessageBoxA(0, "Enemy is not on your team", "Enemy Detected", 0);
                }
            }
        }
    }
}

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

c++
memory
asked on Stack Overflow Mar 22, 2021 by WyattDigitalz

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0