none
Wrapping function call in ASM with C++ function via Detours RRS feed

  • General discussion

  • Using X86DBG and IDA, I've found a function that's called every frame in Fallout: New Vegas, that displays the player's menu screen. There is an API called New Vegas Script Extender, which allows me to write directly to the process' memory through C++, with access to the game's pointers, records, classes, and such.

    The function being called in the game's assembly code is TryToOpenPipboy. I've located the address where it's called in the game's main loop 0x0070E913, as well as the address of the function itself 0x0070F4E0. If I were to use CheatEngine, it would be trivial to wrap the function call and inject the custom code, as all that is abstracted away; type in the code, and it takes care of everything else. I was informed that Microsoft Detours trivializes this, so I've got it included.

    I think I've done it properly in C++, but the compiler throws the following five errors:

    Error	LNK2019	unresolved external symbol "public: unsigned long __thiscall TESObjectREFR::GetItemCount(class TESForm *)" (?GetItemCount@TESObjectREFR@@QAEKPAVTESForm@@@Z) referenced in function "void __cdecl EquipPlayerPipboy(void)" (?EquipPlayerPipboy@@YAXXZ)
    Error	LNK2019	unresolved external symbol _DetourTransactionBegin@0 referenced in function "void __cdecl MessageHandler(struct NVSEMessagingInterface::Message *)" (?MessageHandler@@YAXPAUMessage@NVSEMessagingInterface@@@Z)	
    Error	LNK2019	unresolved external symbol _DetourTransactionCommit@0 referenced in function "void __cdecl MessageHandler(struct NVSEMessagingInterface::Message *)" (?MessageHandler@@YAXPAUMessage@NVSEMessagingInterface@@@Z)
    Error	LNK2019	unresolved external symbol _DetourUpdateThread@4 referenced in function "void __cdecl MessageHandler(struct NVSEMessagingInterface::Message *)" (?MessageHandler@@YAXPAUMessage@NVSEMessagingInterface@@@Z)
    Error	LNK2019	unresolved external symbol _DetourAttach@8 referenced in function "void __cdecl MessageHandler(struct NVSEMessagingInterface::Message *)" (?MessageHandler@@YAXPAUMessage@NVSEMessagingInterface@@@Z)
    Error	LNK1120	5 unresolved externals	aaafyty_pipboy_remover	S:\Games\Fallout New Vegas\Data\nvse\plugins\aaafyty_pipboy_remover.dll	1	
    

    Archive of the project (requires 2013 toolset to compile): https://mega.nz/#!aglEQYRb!psWJBcPLX7VCZ9R0npUvuRmmHDYuUG2d8sFMd9Jml70

    Why are these errors being thrown?

    Friday, September 20, 2019 9:08 PM

All replies

  • You should always read unresolved external symbol as the linker telling you "you told me to call this function but I can't find it".

    The most likely cause is that you are missing the library or you are linking against the wrong version of it.

    Annoyingly, this is the kind of problem that we can give guidance on, but you are the one who has to do the real work.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Saturday, September 21, 2019 3:07 PM
  • Remember that calling a function in an external library requires two steps: using a #include to make the prototypes available to the compiler, and adding a .lib at link time so the linker can fix up the references.  You skipped the second step.

    Note, however, that the missing TESObjectREFR::GetItemCount function is YOUR bug.  You may have the wrong parameters in the function definition, or you may just have forgotten to write it.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, September 24, 2019 4:48 AM