Last active
August 29, 2015 14:27
-
-
Save vittee/e83df2f9621a4885656c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <system_error> | |
#include <Windows.h> | |
namespace GameUI { | |
typedef int(__thiscall *noarg_meth_t)(void*); | |
typedef int(__thiscall *onearg_meth_t)(void*, void*); | |
class TaskBar | |
{ | |
private: | |
HMODULE handle; | |
void** inst_var; | |
// | |
onearg_meth_t runcmd_meth; | |
noarg_meth_t open_options_dialog; | |
noarg_meth_t open_create_multiplayer_game_dialog; | |
noarg_meth_t open_load_demo_dialog; | |
noarg_meth_t open_save_game_dialog; | |
noarg_meth_t open_load_game_dialog; | |
noarg_meth_t open_new_game_dialog; | |
noarg_meth_t open_player_list_dialog; | |
noarg_meth_t open_change_game_dialog; | |
noarg_meth_t quit; | |
public: | |
TaskBar(uintptr_t inst_var_addr) | |
{ | |
handle = GetModuleHandle("GameUI.dll"); | |
if (!handle) { | |
throw std::runtime_error("GameUI module was not loaded"); | |
} | |
// | |
uintptr_t image_base = (uintptr_t)handle; | |
inst_var = (void**)(image_base + inst_var_addr); | |
// | |
#define METH(a, t) (t) (image_base + a) | |
#define METH_NONE(a) METH(a, noarg_meth_t) | |
#define METH_ONE(a) METH(a, onearg_meth_t) | |
runcmd_meth = METH_ONE(0x2D1E0); | |
open_options_dialog = METH_NONE(0x2DB40); | |
open_create_multiplayer_game_dialog = METH_NONE(0x2DC10); | |
open_load_demo_dialog = METH_NONE(0x2DBB0); | |
open_save_game_dialog = METH_NONE(0x2DAE0); | |
open_load_game_dialog = METH_NONE(0x2DA80); | |
open_new_game_dialog = METH_NONE(0x2DA20); | |
open_player_list_dialog = METH_NONE(0x2E0C0); | |
open_change_game_dialog = METH_NONE(0x2E060); | |
quit = METH_NONE(0x2D950); | |
#undef METH | |
#undef METH_NONE | |
#undef METH_ONE | |
} | |
~TaskBar() | |
{ | |
} | |
#define METH_NONE_CALL(m) m(*inst_var) | |
int RunCmd(char *cmd) | |
{ | |
return runcmd_meth(*inst_var, cmd); | |
} | |
int OpenOptionsDialog() | |
{ | |
return METH_NONE_CALL(open_options_dialog); | |
} | |
int OpenCreateMultiplayerGameDialog() | |
{ | |
return METH_NONE_CALL(open_create_multiplayer_game_dialog); | |
} | |
int OpenLoadDemoDialog() | |
{ | |
return METH_NONE_CALL(open_load_demo_dialog); | |
} | |
int OpenSaveGameDialog() | |
{ | |
return METH_NONE_CALL(open_save_game_dialog); | |
} | |
int OpenLoadGameDialog() | |
{ | |
return METH_NONE_CALL(open_load_game_dialog); | |
} | |
int OpenNewGameDialog() | |
{ | |
return METH_NONE_CALL(open_new_game_dialog); | |
} | |
int OpenPlayerListDialog() | |
{ | |
return METH_NONE_CALL(open_player_list_dialog); | |
} | |
int OpenChangeGameDialog() | |
{ | |
return METH_NONE_CALL(open_change_game_dialog); | |
} | |
int Quit() | |
{ | |
return METH_NONE_CALL(quit); | |
} | |
#undef METH_NONE_CALL | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment