designer1337 / csgo-cheat-base

simple csgo internal base.
MIT License
242 stars 50 forks source link

utilities.hpp code #41

Closed bruhmoment21 closed 4 years ago

bruhmoment21 commented 4 years ago
    template<typename FuncType>
    __forceinline static FuncType call_virtual(void* ppClass, int index) {
        int* pVTable = *(int**)ppClass;
        int dwAddress = pVTable[index];
        return (FuncType)(dwAddress);
    }

why not to use this code everywhere to simplify things like shown below?

  void set_drawing_color(int r, int g, int b, int a = 255)
    {
        utilities::call_virtual<void(__thiscall*)(decltype(this), int, int, int, int) >(this, 15)(this, r, g, b, a);
    }
    void set_text_color(int r, int g, int b, int a = 255)
    {
        utilities::call_virtual<void(__thiscall*)(decltype(this), int, int, int, int) >(this, 25)(this, r, g, b, a);
    }
    void draw_polygon(int n, vertex_t* vertice, bool clip_vertices = true)
    {
        utilities::call_virtual<void(__thiscall*)(decltype(this), int, vertex_t*, bool) >(this, 106)(this, n, vertice, clip_vertices);
    }

instead of

  void set_drawing_color(int r, int g, int b, int a = 255) {
        using original_fn = void(__thiscall*)(i_surface*, int, int, int, int);
        return (*(original_fn * *)this)[15](this, r, g, b, a);
    }
    void set_text_color(int r, int g, int b, int a = 255) {
        using original_fn = void(__thiscall*)(i_surface*, int, int, int, int);
        return (*(original_fn * *)this)[25](this, r, g, b, a);
    }
    void draw_polygon(int n, vertex_t* vertice, bool clip_vertices = true) {
        using original_fn = void(__thiscall*)(i_surface*, int, vertex_t*, bool);
        return (*(original_fn * *)this)[106](this, n, vertice, clip_vertices);
    }
designer1337 commented 4 years ago

It was like this in original alpha's base and I prefer doing it this way, u can decide to use template or not or even write cool macro for it

cheers