I have bits of code which decompiles a small part of the existing program. I have added it to the proxy dll. The code to the existing functions is hooked through Detour and looks like below (gui.h and gui.cpp)
But now how do I call my own implementation of the gamemain function? Can someone may be point me to an existing post(s) where calling proxy dll replaced functions is described in detail.
Or / And if you don't mind spending time looking at the code below, I would appreciate the tips on how to make it work in the similar structure to the one I am using or may be there is another solution I should be considering.
Note, I do know the address for the gamemain function in the original exe.
gui.h
#pragma once
#include "world.h"
namespace gladius {
namespace gui {
//struct gladius::world::World* __fastcall getworld();
struct GUI {
//gladius::world::World* __fastcall gladius::gui::GUI::getWorld(gladius::gui::GUI* thisptr);
using GetWorld = gladius::world::World* (__fastcall*) (GUI* thisptr);
GetWorld getWorld;
};
GUI& get();
} //namespace gui
}
gui.cpp
#include "world.h"
#include "gui.h"
#include <array>
namespace gladius {
namespace gui {
static std::array<GUI, 1> functions = { {
// Steam
GUI{
(GUI::GetWorld)0x140b81074,
},
} };
GUI& get()
{
return functions[0];
}
}
}
This works. But now I want to change another function and replace it with my implementation. I.e. the function looks like this:
game.h
#pragma once
#include "world.h"
#include "game.h"
#include "gui.h"
namespace gladius {
struct Game {
//virtual int __thiscall main(gladius::Game* thisptr, int param_1, char** param_2, char** param_3);
int __thiscall gladius::Game::gamemain(gladius::Game* thisptr, int param_1, char** param_2, char** param_3)
{
gladius::gui::GUI guiInst;
gladius::world::World worldInst;
gladius::Game::initialize(this, param_1, param_2, param_3);
// proxy::gui::GUI::run(*(GUI**)(this + 0x28));
//worldInst = gladius::gui::GUI::getWorld(*(gladius::gui::GUI**)(this + 0x88));
gladius::world::World::CreateWorld(*(gladius::world::World**)(*(long long *)(this + 0x5e8) + 0x50));
gladius::Game::quit(this);
return 0;
}
void __fastcall gladius::Game::initialize(gladius::Game* thisptr, int a2, char** a3, char** a4);
void __fastcall gladius::Game::quit(gladius::Game* thisptr);
};
}