Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement - SDL2 from CS:GO #2

Closed
aKalisch opened this issue Mar 1, 2018 · 2 comments
Closed

Improvement - SDL2 from CS:GO #2

aKalisch opened this issue Mar 1, 2018 · 2 comments
Labels
enhancement New feature or request

Comments

@aKalisch
Copy link

aKalisch commented Mar 1, 2018

As you currently link the SDL2.framework to the dylib statically it doesn't seem to be the best approach since you already have the libsdl2-2.0.0.dylib loaded through CS:GO.

For compiling the headers you could simply install SDL2 through brew:
brew install sdl2

Afterwards you can implement the SDL calls to your code like this:

#include <SDL2/SDL.h>

// ...
DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window* window, int* w, int* h) {
    typedef void(*currFn) (SDL_Window*, int*, int*);
    static currFn SDL_GetWindowSizeFn = reinterpret_cast<currFn>(dlsym(RTLD_DEFAULT, "SDL_GetWindowSize"));
    
    return SDL_GetWindowSizeFn(window, w, h);
}
// ...
DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_Window* window, SDL_GLContext context) {
    typedef int(*currFn) (SDL_Window*, SDL_GLContext);
    static currFn SDL_GL_MakeCurrentFn = reinterpret_cast<currFn>(dlsym(RTLD_DEFAULT, "SDL_GL_MakeCurrent"));
    
    return SDL_GL_MakeCurrentFn(window, context);
}
// ...

The good thing about this:

  • You don't need to change the imgui_impl_sdl.* to your implemented calls
  • You don't need a third-party library/class to get your hooks
  • You can share your library to others without having them installed SDL2
@dwnste
Copy link
Owner

dwnste commented Mar 1, 2018

It's a very good find. Can you maybe make a pulll request?

@dwnste dwnste added the enhancement New feature or request label Mar 1, 2018
@dwnste
Copy link
Owner

dwnste commented Mar 2, 2018

OK, I've updated everything.

@dwnste dwnste closed this as completed Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants