"GW2LIB::Font font" required?

Issue #4 resolved
Former user created an issue

I found an interesting bug (at least when using the SampleApp as a starting point.

I stripped the SampleApp to the bare minimum (removed the ESP callback function, and the font initialization), and found that if "GW2LIB::Font font" is present then the console window comes up just fine. However as soon as I get rid of that line, it stops working; the dll is still injected, but it does not respond to pressing the Home key to make it quit. Any ideas what is happening?

This is essentially what I have:

#include "gw2lib.h"
#include <sstream>
#include <thread>
#include <chrono>

// Need this line for GW2LIB to work...
GW2LIB::Font font;

void GW2LIB::gw2lib_main()
{
    while (GetAsyncKeyState(VK_HOME) >= 0)
    {
              // do some stuff
    }
}

Comments (11)

  1. rafzi repo owner

    I tested your code and it works fine for me in both cases. The "Font" construction doesn't do anything relevant. Did you omit additional code in the while?

  2. Ryan

    Yea, I'm doing some socket related stuff, but I'm not using the Font class in that code. I also tried commenting out the rest of the code I added so that it would be identical to the above, and I still have the same problem. I'll commit the code I have to github in the next day or two and can post a link.

  3. rafzi repo owner

    Sorry, I don't have the time to debug your code. I cannot reproduce your issue with the snippet given above.

  4. Ryan

    I understand. It builds fine either way, just that it only runs properly when I include that line which means I guess I'd better include that line.

  5. hairys

    Making an observation here, I'm getting the issue ryan is describing, dll loads, but no code is executed and it shows it's still loaded in proc explorer. I noticed with the Font line removed, the file size of the dll is 10K (testing 32-bit). When I add that line back, it's 89K, as if it suddenly linked all the gw2lib code into the final dll. Knowing this, I changed that line to something random from the lib:

    GW2LIB::Agent ag;
    

    and the dll loaded properly. I'm guessing you have to actually use something from gw2lib.h for it to be linked properly. Probably some weird optimization the compiler is doing.

  6. hairys

    Also, you don't have to make any global variables. You just need to use something from gw2lib, like so:

    #include "gw2lib.h"
    #include <sstream>
    #include <thread>
    #include <chrono>
    
    void GW2LIB::gw2lib_main()
    {
        GW2LIB::Agent ag;
        while (GetAsyncKeyState(VK_HOME) >= 0)
        {
    
        }
    }
    

    or any other lib you're including. The linker is aggressively trying to optimize your code.

  7. hairys

    @ryan-ahitb I checked out your code and you don't appear to be using anything from gw2lib. MumbleLink seems redundant compared to what gw2lib offers :) Or you could forgo gw2lib and make a straight dll hooked up to MumbleLink instead. Just inject like any other dll.

  8. rafzi repo owner

    @hairys Good catch! I was not able to reproduce the issue, because I did a build with incremental linking. With a full rebuild I'm seeing that hacklib is not starting up at all. Like @hairys noted this is because there is no reference to the main.cpp object file that contains hacklib startup via static initilization.

    The most obvious solution should be to decide to either use the library or not use it. The only functionality you seem to use is the DLL entry point, which is a functionality of hacklib (see Main.h), not hacklib_gw2.

    If you really want to keep it this way you also have the option to turn off this specific linker optimization with "/OPT:NOREF".

    This actually is a dependency issue of this library, but I can't think of a legitimate way to use this library like you do. Any fix I can think of would make usage less convenient and straightforward.

  9. Ryan

    That makes sense. I was planning on adding functionality that would use hacklib_gw2 but it needs more work before it would be ready.

  10. Log in to comment