remove hook wrappers and directly call Hook::addr() at the start of MainLoop(), add console redirection

This commit is contained in:
Daniel S. 2019-11-20 20:51:38 +01:00
parent 20a4d53b22
commit e2464653c7
1 changed files with 16 additions and 20 deletions

View File

@ -1,5 +1,4 @@
#include <string> #include <string>
#include <sstream>
#include <vector> #include <vector>
#include <map> #include <map>
#include <iomanip> #include <iomanip>
@ -18,15 +17,18 @@ using namespace std;
#include "Hook.h" #include "Hook.h"
#include "VMT_Hook.h" #include "VMT_Hook.h"
#include "D3D8_Hook.h" #include "D3D8_Hook.h"
#include "REPL.h"
bool do_sleep=true;
HMODULE hD3D8Dll = 0; HMODULE hD3D8Dll = 0;
bool initialized = false; bool initialized = false;
bool running = true; bool running = true;
bool redirect_console = false;
HMODULE mod = 0; HMODULE mod = 0;
void DllUnload(HMODULE); void DllUnload(HMODULE);
void hook_exit(); int hooked_console(const char *);
void H_Exit();
size_t size_ht(HashTable<EntityList> *ht) size_t size_ht(HashTable<EntityList> *ht)
{ {
@ -119,9 +121,13 @@ size_t dump_ht(HashTable<Entity> *ht)
void MainLoop(HMODULE mod) void MainLoop(HMODULE mod)
{ {
Sleep(100); Sleep(100);
hook_exit(); Hook::addr(reinterpret_cast<void *>(P_SCRAP_EXIT), H_Exit);
Hook::addr(reinterpret_cast<void *>(P_D3DCHECK),hook_d3d8);
Hook::addr(reinterpret_cast<void *>(P_CON_HANDLER), hooked_console);
overlay=true;
cout << "[*] Starting main Loop" << endl; cout << "[*] Starting main Loop" << endl;
cout << endl; cout << endl;
cout << "[F2 ] Redirect game console to ScapHacks console" << endl;
cout << "[F3 ] Unload ScrapHacks" << endl; cout << "[F3 ] Unload ScrapHacks" << endl;
cout << "[F5 ] Show Overlay" << endl; cout << "[F5 ] Show Overlay" << endl;
cout << "[F6 ] Show Alarm status" << endl; cout << "[F6 ] Show Alarm status" << endl;
@ -134,11 +140,14 @@ void MainLoop(HMODULE mod)
while (running) while (running)
{ {
Sleep(100); Sleep(100);
while (key_down('F')) while (key_down('F'))
{ {
scrap_exec("dbg.brake()"); scrap_exec("dbg.brake()");
} }
if (key_down_norepeat(VK_F2))
{
redirect_console = !redirect_console;
}
if (key_down_norepeat(VK_F3)) if (key_down_norepeat(VK_F3))
{ {
break; break;
@ -148,6 +157,7 @@ void MainLoop(HMODULE mod)
{ {
overlay = !overlay; overlay = !overlay;
} }
if (key_down_norepeat(VK_F6)) if (key_down_norepeat(VK_F6))
{ {
@ -193,33 +203,19 @@ void InitConsole()
SetupConsole(me); SetupConsole(me);
} }
void handle_command(const char *cmd)
{
cout << "CMD: " << cmd << endl;
scrap_log(0x00ff00, "HAXX: ");
scrap_log(0x00ff00, cmd);
scrap_log(0x00ff00, "\n");
return;
}
int hooked_console(const char *cmd) int hooked_console(const char *cmd)
{ {
typedef int(_cdecl * t_func)(const char *); typedef int(_cdecl * t_func)(const char *);
shared_ptr<Hook> hook = Hook::get(hooked_console);
if (cmd[0] == '$') if (cmd[0] == '$')
{ {
handle_command(++cmd); handle_command(++cmd);
return 0; return 0;
} }
shared_ptr<Hook> hook = Hook::get(hooked_console);
int ret = hook->func<t_func>(cmd); int ret = hook->func<t_func>(cmd);
return ret; return ret;
} }
void hook_console()
{
Hook::addr(reinterpret_cast<void *>(P_CON_HANDLER), hooked_console);
}
void H_Exit() void H_Exit()
{ {
typedef void(_cdecl * t_func)(void); typedef void(_cdecl * t_func)(void);