Home > OS >  Already defined in dllmain.obj
Already defined in dllmain.obj

Time:05-21

I'm trying to clean a bit my code moving some parts to they .h and .cpp files.

The problem is that when I try to compile, I get a "already defined" error.

I know there are several questions like this one. But I've checked several times and I don't see any duplicated definition, also can't see anything outside it's place. Can't detect where is the problem...

It's a dll code:

#include "pch.h"
#include "includes.h"

DWORD WINAPI HackThread(HMODULE hModule)
{
    //find_main_window(GetCurrentProcessId());
    InitFunctions();

    AllocConsole();
    FILE* f;
    freopen_s(&f, "CONOUT$", "w", stdout);       
    
    // init modules
    std::cout << "moduleBase: " << std::hex << moduleBase << std::endl;
    uintptr_t map = (uintptr_t)((moduleBase   dwMap));    
    std::cout << "map: " << map << std::endl;
    uintptr_t protocolGame = (uintptr_t)((moduleBase   m_protocolGame));
    std::cout << "protocolGame: " << protocolGame << std::endl;

    // offsets
    constexpr ptrdiff_t offset_itemId = 0x2C;
    constexpr ptrdiff_t offset_itemCount = 0x30;    

    // get localplayer
    DWORD LocalPlayerPointer = (DWORD)((moduleBase   dwLocalPlayer));        
    DWORD LocalPlayerAddress = *(DWORD*)LocalPlayerPointer;
    // enable after testing when moving to loop: if (LocalPlayer == 0 || LocalPlayerPointer == 0) continue;
    std::cout << "LocalPlayerPointer: " << LocalPlayerPointer << std::endl;
    std::cout << "LocalPlayerAddress: " << LocalPlayerAddress << std::endl;

    // wait for activate
    while (!GetAsyncKeyState(VK_END))
    {
        Sleep(10);
    }
    //system("cls");

    // read inventory
    for (int i = 0; i <= Const::InventorySlot::LastInventorySlot; i  ) {
        DWORD buffer = 0, itemId = 0, itemCount = 0;
        getInventoryItem(LocalPlayerAddress, &buffer, i);
        if (buffer != 0) {
            itemId = *(DWORD*)(buffer   offset_itemId);
            itemCount = *(DWORD*)(buffer   offset_itemCount);
        }
        if (itemId != 0) {
            std::cout << "Item" << i << ": " << std::hex << buffer << std::endl;
            std::cout << "ID: " << std::dec << itemId << " x" << itemCount << std::endl;
        }
    }    

    // get tiles
    TileList tiles;
    getTiles(map, &tiles, 7);
    for (TilePtr tile : tiles) {
        DWORD buffer;
        // getTopCreature
        getTopCreature(tile, &buffer);
        // check if creature isLocalPlayer
        if (buffer != 0 && buffer != LocalPlayerAddress) {
            std::cout << "buffer: " << std::hex << buffer << std::endl;
            // findItemInContainers
            DWORD item = 0;
            uintptr_t itemid = 3198; //hmm
            findItemInContainers(LocalPlayerPointer, &item, itemid, 1);
            if (item != 0) {
                std::cout << "Item " << std::dec << itemid << " found: " << std::hex << item << std::endl;
                std::cout << "(DWORD*)&tile: " << (DWORD*)&tile << std::endl;
                std::cout << "&tile: " << &tile << std::endl;
                std::cout << "*tile: " << *tile << std::endl;
                std::cout << "tile: " << tile << std::endl;
                // shoot
                useWith(LocalPlayerPointer, &item, (DWORD*)&tile, 0); // ERROR IS HERE IN PARAMETER (DWORD*)&tile
                                                                      // the game will try to call [(DWORD*)&tile   0x20] then break
                break;
            }
            else {
                std::cout << "Item " << itemid << " not found: " << std::dec << itemid << std::endl;
            }
        }            
    }        

    std::cout << "sleeping 3 seconds" << std::endl;
    Sleep(3000);
    std::cout << "ready" << std::endl;

    // wait for activate
    while (!GetAsyncKeyState(VK_END))
    {
        Sleep(10);
    }

    // stop follow
    cancelFollow(LocalPlayerPointer);
    std::cout << "Stopped follow" << std::endl;    

    // sendinput
    /*
    SendMsg(WM_KEYDOWN, VK_F1);
    SendMsg(WM_KEYUP, VK_F1);
    */

    // wait for END then detach
    std::cout << "Press ESC to remove hook" << std::endl;
    while (!GetAsyncKeyState(VK_ESCAPE))
    {
      // aimbot        
        // get target
        DWORD attacking = isAttacking(LocalPlayerPointer);

        // get who is attacking X
        /*DWORD buffer;
        getAttackingCreature(LocalPlayer, &buffer);
        std::cout << "buffer: " << buffer << std::endl;*/                    

      // manatrainer        
        double mana = getMana(LocalPlayerAddress);
        std::cout << "Mana: " << std::dec << mana << std::endl;
        if (mana > MANA_TO_RUNE) {
            talkChannel(LocalPlayerPointer, 1, 0, SPELL_TO_USE);
            Sleep(3000);
            // useItem
            DWORD buffer = 0, itemId = 0, itemCount = 0;
            getInventoryItem(LocalPlayerAddress, &buffer, Const::InventorySlot::InventorySlotAmmo);
            if (buffer != 0) {
                std::cout << "sending useItem()" << std::endl;
                itemId = *(DWORD*)(buffer   offset_itemId);
                itemCount = *(DWORD*)(buffer   offset_itemCount);
                useItem(LocalPlayerPointer, &buffer);
            }
        }         

        Sleep(10);
    }

    fclose(f);
    FreeConsole();
    FreeLibraryAndExitThread(hModule, 0);
    return 0;
}


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

The includes.h looks like this:

#pragma once
#include <Windows.h>
#include <iostream>
#include "constants.h"
#include <vector>
#include <list>
//#include "stdext/shared_object.h"
//#include "inputs.h"
#include "declarations.h"
#include "functions.h"
#include "offsets.h"

Functions.h

#pragma once
#include "includes.h"

void InitFunctions();

uintptr_t moduleBase;

// getMana
typedef double(__thiscall* _getMana)(DWORD localplayer);
_getMana getMana;
// isAttacking
typedef int(__thiscall* _isAttacking)(DWORD localplayer);
_isAttacking isAttacking;
// getInventoryItem
typedef DWORD(__thiscall* _getInventoryItem)(DWORD localplayer, DWORD* buffer, uintptr_t index);
_getInventoryItem getInventoryItem;
// cancelFollow
typedef DWORD(__thiscall* _cancelFollow)(DWORD localplayer);
_cancelFollow cancelFollow;
// findItemInContainers
typedef DWORD(__thiscall* _findItemInContainers)(DWORD localplayer, DWORD* buffer, uintptr_t id, uintptr_t type);
_findItemInContainers findItemInContainers;
// talkChannel
typedef DWORD(__thiscall* _talkChannel)(DWORD localplayer, uintptr_t mode, uintptr_t channelId, const std::string& message);
_talkChannel talkChannel;
// useWith
typedef void(__thiscall* _useWith)(DWORD localplayer, DWORD* item, DWORD* toThing, uintptr_t subType);
_useWith useWith;
// getAttackingCreature
typedef DWORD(__thiscall* _getAttackingCreature)(DWORD localplayer, DWORD* buffer);
_getAttackingCreature getAttackingCreature;
// useItem    
typedef void(__thiscall* _useItem)(DWORD localplayer, DWORD* item);
_useItem useItem;
// get tiles
typedef void(__thiscall* _getTiles)(DWORD map, TileList* buffer, uintptr_t floor);
_getTiles getTiles;
// getTopCreature
typedef void(__thiscall* _getTopCreature)(TilePtr tile, DWORD* buffer);
_getTopCreature getTopCreature;

And functions.cpp

#include "pch.h"
#include "includes.h"

void InitFunctions(){
    // get base address
    moduleBase = (uintptr_t)GetModuleHandle(L"NewHorizon_DirectX.exe");
    _getMana getMana;
    getMana = (_getMana)(moduleBase   0x5A830);
    isAttacking = (_isAttacking)(moduleBase   0x734A0);
    getInventoryItem = (_getInventoryItem)(moduleBase   0x949C0);
    cancelFollow = (_cancelFollow)(moduleBase   0x73420);
    findItemInContainers = (_findItemInContainers)(moduleBase   0x78710);
    talkChannel = (_talkChannel)(moduleBase   0x79340);
    useWith = (_useWith)(moduleBase   0x78220);
    getAttackingCreature = (_getAttackingCreature)(moduleBase   0x93F90);
    useItem = (_useItem)(moduleBase   0x77E60);
    getTiles = (_getTiles)(moduleBase   0x142860);
    getTopCreature = (_getTopCreature)(moduleBase   0x192BC0);
}

When I try to compile, I get this errors:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2005 "unsigned int moduleBase" (?moduleBase@@3IA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "double (__thiscall* getMana)(unsigned long)" (?getMana@@3P6ENK@ZA) already defined in dllmain.obj  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "int (__thiscall* isAttacking)(unsigned long)" (?isAttacking@@3P6EHK@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* getInventoryItem)(unsigned long,unsigned long *,unsigned int)" (?getInventoryItem@@3P6EKKPAKI@ZA) already defined in dllmain.obj    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* cancelFollow)(unsigned long)" (?cancelFollow@@3P6EKK@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* findItemInContainers)(unsigned long,unsigned long *,unsigned int,unsigned int)" (?findItemInContainers@@3P6EKKPAKII@ZA) already defined in dllmain.obj  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* talkChannel)(unsigned long,unsigned int,unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?talkChannel@@3P6EKKIIABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@ZA) already defined in dllmain.obj   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "void (__thiscall* useWith)(unsigned long,unsigned long *,unsigned long *,unsigned int)" (?useWith@@3P6EXKPAK0I@ZA) already defined in dllmain.obj  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* getAttackingCreature)(unsigned long,unsigned long *)" (?getAttackingCreature@@3P6EKKPAK@ZA) already defined in dllmain.obj  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "void (__thiscall* useItem)(unsigned long,unsigned long *)" (?useItem@@3P6EXKPAK@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "void (__thiscall* getTiles)(unsigned long,class std::list<unsigned long *,class std::allocator<unsigned long *> > *,unsigned int)" (?getTiles@@3P6EXKPAV?$list@PAKV?$allocator@PAK@std@@@std@@I@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "void (__thiscall* getTopCreature)(unsigned long *,unsigned long *)" (?getTopCreature@@3P6EXPAK0@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK1169 one or more multiply defined symbols found  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Release\Tibia Internal.dll    1   

How should I use the .h and .cpp files correctly to don't get this error?

EDIT: as @AleXelton suggests I'm removing #include "includes.h" from functions.cpp and looks like this when compile:

Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0020   identifier "moduleBase" is undefined    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  5   
Error (active)  E0020   identifier "getMana" is undefined   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  6   
Error (active)  E0020   identifier "_getMana" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  6   
Error (active)  E0020   identifier "isAttacking" is undefined   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  7   
Error (active)  E0020   identifier "_isAttacking" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  7   
Error (active)  E0020   identifier "getInventoryItem" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  8   
Error (active)  E0020   identifier "_getInventoryItem" is undefined Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  8   
Error (active)  E0020   identifier "cancelFollow" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  9   
Error (active)  E0020   identifier "_cancelFollow" is undefined Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  9   
Error (active)  E0020   identifier "findItemInContainers" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  10  
Error (active)  E0020   identifier "_findItemInContainers" is undefined Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  10  
Error (active)  E0020   identifier "talkChannel" is undefined   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  11  
Error (active)  E0020   identifier "_talkChannel" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  11  
Error (active)  E0020   identifier "useWith" is undefined   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  12  
Error (active)  E0020   identifier "_useWith" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  12  
Error (active)  E0020   identifier "getAttackingCreature" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  13  
Error (active)  E0020   identifier "_getAttackingCreature" is undefined Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  13  
Error (active)  E0020   identifier "useItem" is undefined   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  14  
Error (active)  E0020   identifier "_useItem" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  14  
Error (active)  E0020   identifier "getTiles" is undefined  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  15  
Error (active)  E0020   identifier "_getTiles" is undefined Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  15  
Error (active)  E0020   identifier "getTopCreature" is undefined    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  16  
Error (active)  E0020   identifier "_getTopCreature" is undefined   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  16  
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  5   
Error   C2065   'getMana': undeclared identifier    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  6   
Error   C2065   '_getMana': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  6   
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  6   
Error   C2065   'isAttacking': undeclared identifier    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  7   
Error   C2065   '_isAttacking': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  7   
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  7   
Error   C2065   'getInventoryItem': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  8   
Error   C2065   '_getInventoryItem': undeclared identifier  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  8   
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  8   
Error   C2065   'cancelFollow': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  9   
Error   C2065   '_cancelFollow': undeclared identifier  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  9   
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  9   
Error   C2065   'findItemInContainers': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  10  
Error   C2065   '_findItemInContainers': undeclared identifier  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  10  
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  10  
Error   C2065   'talkChannel': undeclared identifier    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  11  
Error   C2065   '_talkChannel': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  11  
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  11  
Error   C2065   'useWith': undeclared identifier    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  12  
Error   C2065   '_useWith': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  12  
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  12  
Error   C2065   'getAttackingCreature': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  13  
Error   C2065   '_getAttackingCreature': undeclared identifier  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  13  
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  13  
Error   C2065   'useItem': undeclared identifier    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  14  
Error   C2065   '_useItem': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  14  
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  14  
Error   C2065   'getTiles': undeclared identifier   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  15  
Error   C2065   '_getTiles': undeclared identifier  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  15  
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  15  
Error   C2065   'getTopCreature': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  16  
Error   C2065   '_getTopCreature': undeclared identifier    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  16  
Error   C2065   'moduleBase': undeclared identifier Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.cpp  16  

I added #include functions.h instead and I get the same first results:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK1169 one or more multiply defined symbols found  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Release\Tibia Internal.dll    1   
Error   LNK2005 "unsigned int moduleBase" (?moduleBase@@3IA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "double (__thiscall* getMana)(unsigned long)" (?getMana@@3P6ENK@ZA) already defined in dllmain.obj  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "int (__thiscall* isAttacking)(unsigned long)" (?isAttacking@@3P6EHK@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* getInventoryItem)(unsigned long,unsigned long *,unsigned int)" (?getInventoryItem@@3P6EKKPAKI@ZA) already defined in dllmain.obj    Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* cancelFollow)(unsigned long)" (?cancelFollow@@3P6EKK@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* findItemInContainers)(unsigned long,unsigned long *,unsigned int,unsigned int)" (?findItemInContainers@@3P6EKKPAKII@ZA) already defined in dllmain.obj  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* talkChannel)(unsigned long,unsigned int,unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?talkChannel@@3P6EKKIIABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@ZA) already defined in dllmain.obj   Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "void (__thiscall* useWith)(unsigned long,unsigned long *,unsigned long *,unsigned int)" (?useWith@@3P6EXKPAK0I@ZA) already defined in dllmain.obj  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "unsigned long (__thiscall* getAttackingCreature)(unsigned long,unsigned long *)" (?getAttackingCreature@@3P6EKKPAK@ZA) already defined in dllmain.obj  Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "void (__thiscall* useItem)(unsigned long,unsigned long *)" (?useItem@@3P6EXKPAK@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "void (__thiscall* getTiles)(unsigned long,class std::list<unsigned long *,class std::allocator<unsigned long *> > *,unsigned int)" (?getTiles@@3P6EXKPAV?$list@PAKV?$allocator@PAK@std@@@std@@I@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   
Error   LNK2005 "void (__thiscall* getTopCreature)(unsigned long *,unsigned long *)" (?getTopCreature@@3P6EXPAK0@ZA) already defined in dllmain.obj Tibia Internal  C:\Users\Adrian\Documents\cracking\Tibia Internal\Tibia Internal\functions.obj  1   

CodePudding user response:

functions.h declares a bunch of global variables. Any .cpp file that includes functions.h (ie, by including includes.h) will get its own copy of those variables. Hence, the "already defined" errors when the linker tries to bring the compiled units together into the final executable.

If your goal is to share those variables between .cpp files, you need to declare the variables as extern in functions.h file, and then define the actual variables in functions.cpp, eg:

Functions.h

#pragma once
#include "includes.h"

void InitFunctions();

extern uintptr_t moduleBase;

// getMana
typedef double(__thiscall* _getMana)(DWORD localplayer);
extern _getMana getMana;
// isAttacking
typedef int(__thiscall* _isAttacking)(DWORD localplayer);
extern _isAttacking isAttacking;
// getInventoryItem
typedef DWORD(__thiscall* _getInventoryItem)(DWORD localplayer, DWORD* buffer, uintptr_t index);
extern _getInventoryItem getInventoryItem;
// cancelFollow
typedef DWORD(__thiscall* _cancelFollow)(DWORD localplayer);
extern _cancelFollow cancelFollow;
// findItemInContainers
typedef DWORD(__thiscall* _findItemInContainers)(DWORD localplayer, DWORD* buffer, uintptr_t id, uintptr_t type);
extern _findItemInContainers findItemInContainers;
// talkChannel
typedef DWORD(__thiscall* _talkChannel)(DWORD localplayer, uintptr_t mode, uintptr_t channelId, const std::string& message);
extern _talkChannel talkChannel;
// useWith
typedef void(__thiscall* _useWith)(DWORD localplayer, DWORD* item, DWORD* toThing, uintptr_t subType);
extern _useWith useWith;
// getAttackingCreature
typedef DWORD(__thiscall* _getAttackingCreature)(DWORD localplayer, DWORD* buffer);
extern _getAttackingCreature getAttackingCreature;
// useItem    
typedef void(__thiscall* _useItem)(DWORD localplayer, DWORD* item);
extern _useItem useItem;
// get tiles
typedef void(__thiscall* _getTiles)(DWORD map, TileList* buffer, uintptr_t floor);
extern _getTiles getTiles;
// getTopCreature
typedef void(__thiscall* _getTopCreature)(TilePtr tile, DWORD* buffer);
extern _getTopCreature getTopCreature;

functions.cpp

#include "pch.h"
#include "functions.h"

uintptr_t moduleBase;
_getMana getMana;
_isAttacking isAttacking;
_getInventoryItem getInventoryItem;
_cancelFollow cancelFollow;
_findItemInContainers findItemInContainers;
_talkChannel talkChannel;
_useWith useWith;
_getAttackingCreature getAttackingCreature;
_useItem useItem;
_getTiles getTiles;
_getTopCreature getTopCreature;

void InitFunctions(){
    // get base address
    moduleBase = (uintptr_t)GetModuleHandle(L"NewHorizon_DirectX.exe");
    getMana = (_getMana)(moduleBase   0x5A830);
    isAttacking = (_isAttacking)(moduleBase   0x734A0);
    getInventoryItem = (_getInventoryItem)(moduleBase   0x949C0);
    cancelFollow = (_cancelFollow)(moduleBase   0x73420);
    findItemInContainers = (_findItemInContainers)(moduleBase   0x78710);
    talkChannel = (_talkChannel)(moduleBase   0x79340);
    useWith = (_useWith)(moduleBase   0x78220);
    getAttackingCreature = (_getAttackingCreature)(moduleBase   0x93F90);
    useItem = (_useItem)(moduleBase   0x77E60);
    getTiles = (_getTiles)(moduleBase   0x142860);
    getTopCreature = (_getTopCreature)(moduleBase   0x192BC0);
}
  •  Tags:  
  • c
  • Related