diff --git a/README.md b/README.md index c2e402f..ab27862 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ To compile the DLL: ## TODO -- Clean up the d3d9 hooks +[DONE] Clean up the d3d9 hooks - Add more hooks to game events - Plugins - Find IDE independent way to create DLL diff --git a/source/blur_console.cpp b/source/blur_console.cpp index a23e00a..947718c 100644 --- a/source/blur_console.cpp +++ b/source/blur_console.cpp @@ -9,7 +9,7 @@ -//TODO: command handler, close button, tab complete, colours, game input +//TODO: buttons, better screen, DWORD WINAPI input_thread(void* arg) { std::cout << "HELLO WORLD :: Console has been created!" << std::endl; std::string* input = (std::string*) arg; @@ -19,33 +19,17 @@ DWORD WINAPI input_thread(void* arg) { char c = NULL; char prompt = '+'; while (true) { + //UP1 \x1b^[[1A + //DOWN1 \x1b^[[1B std::cout << "\r" << prompt << " " << *input; c = _getch(); if ((c == EOF) || (c == '\n') || (c == '\r')) { //parse the stuff std::cout << std::endl; - cmd_args = split(*input, " "); + cmd = *input; input->clear(); - if (!cmd_args.empty()) { - cmd = cmd_args[0]; - if (cmd == "hey") { - blurAPI->console.print("blurAPI->console.print() from console thread"); - } else if (cmd == "name") { - if (cmd_args.size() == 2) { - if (blurAPI->set_LAN_name(cmd_args[1])) { - blurAPI->console.print("Name changed to ["+cmd_args[1]+"], exit multiplayer menu to use it."); - blurAPI->config.user_name = cmd_args[1]; - } else { - blurAPI->console.print("Could not change name to ["+cmd_args[1]+"]"); - } - } else if (cmd_args.size() == 1) { - blurAPI->console.print("Current name is [" + blurAPI->config.user_name + "]"); - } else { - blurAPI->console.print("USAGE: name "); - } - } else if (cmd == "fps") { - blurAPI->console.print(" " + std::to_string((float) blurAPI->config.fps)); - } - } + blurAPI->console.cmd_handler(cmd); + prompt = '='; + cmd.clear(); } else if (c == '\b') { if (!input->empty()) { prompt = '-'; @@ -65,18 +49,24 @@ DWORD WINAPI input_thread(void* arg) { gameConsole::gameConsole() { (void)_setmode(_fileno(stdout), _O_U16TEXT); //let me use unicode some day + // enabling VT100 style in current console + HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD l_mode; + GetConsoleMode(hStdout, &l_mode); + SetConsoleMode(hStdout, l_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN); AllocConsole(); freopen_s(&f, "CONOUT$", "w", stdout); std::cout.clear(); std::cin.clear(); freopen_s(&f, "CONIN$", "r", stdin); SetConsoleTitle("BLUR CONSOLE"); - input = new std::string; //we should do this differently... + input = new std::string; //not like this... } void gameConsole::start() { std::cout << "Loading console..." << std::endl; + std::ios_base::sync_with_stdio(false); HANDLE input_thread_handle = CreateThread(NULL, 0, input_thread, input, 0, NULL); } @@ -100,6 +90,42 @@ void gameConsole::print(std::string text) { } +bool gameConsole::cmd_handler(std::string cmd) { + bool isCmd = false; + std::vector cmd_args = split(cmd, " "); + if (!cmd_args.empty()) { + if (cmd_args[0] == "hey") { + print("blurAPI->console.print(HELLO!)"); + isCmd = true; + } else if (cmd_args[0] == "name") { + if (cmd_args.size() > 1) { + if ((cmd_args[1].front() == '"') && (cmd_args.back().back() == '"')) { + std::vector tmp = split(cmd, "\""); + if (tmp.size() == 2) { + if (blurAPI->set_LAN_name(tmp[1])) { + print("Name changed to \""+tmp[1]+"\", exit multiplayer menu to use it."); + blurAPI->config.user_name = tmp[1]; + } else { + print("Unable to change name to \""+tmp[1]+"\""); + } + } else { + print("*Error* USAGE: name \"your_username\""); + } + } else { + print("*Error*(Try with quotes?) USAGE: name \"your_username\""); + } + } else { + print("Current name is \"" + blurAPI->config.user_name + "\""); + } + isCmd = true; + } else if (cmd_args[0] == "fps") { + print(" " + std::to_string((float) blurAPI->config.fps)); + isCmd = true; + } + } + return isCmd; +} + //util func to split strings std::vector split(std::string str, std::string delim) { std::vector tokens; diff --git a/source/blur_console.h b/source/blur_console.h index f7610ce..b872a61 100644 --- a/source/blur_console.h +++ b/source/blur_console.h @@ -5,6 +5,8 @@ std::vector split(std::string str, std::string delim); + + struct gameConsole { FILE* f; std::string* input; @@ -12,5 +14,6 @@ struct gameConsole { void start(); void print(std::string t); void close(); + bool cmd_handler(std::string cmd); }; diff --git a/source/d3d9.cpp b/source/d3d9.cpp index 869283b..8cae152 100644 --- a/source/d3d9.cpp +++ b/source/d3d9.cpp @@ -26,6 +26,7 @@ bool WINAPI DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved) { +/* D3D9 HOOKED FUNCTIONS */ void init_d3d9_hooks() { char sz_dll[MAX_PATH]; GetSystemDirectory(sz_dll, MAX_PATH); @@ -51,7 +52,6 @@ void init_d3d9_hooks() { } -/* D3D9 HOOKED FUNCTIONS */ //called when the game renders a frame HRESULT f_IDirect3DDevice9::Present(CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion) { @@ -112,6 +112,7 @@ HRESULT f_IDirect3DDevice9::Present(CONST RECT *pSourceRect, CONST RECT *pDestRe } +//when game starts HRESULT f_iD3D9::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface) { LPDIRECT3DDEVICE9 *temp = ppReturnedDeviceInterface; @@ -132,6 +133,7 @@ HRESULT f_iD3D9::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWi } +//changing resolution / toggle fullscreen HRESULT f_IDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS *pPresentationParameters) { // NOTE: call onLostDevice for custom D3D components here. @@ -144,7 +146,7 @@ HRESULT f_IDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS *pPresentationParameters } - +//when frame is done rendering HRESULT f_IDirect3DDevice9::EndScene() { static bool bPressed = false; static bool bDrawBox = false;