Skip to content

Commit

Permalink
Reorganizes the UI a little bit (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadillzzz authored Apr 4, 2024
1 parent 9494af5 commit 7f07445
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 49 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_library(TOFInternal SHARED
hooks.cpp
logger/logger.cpp
menu/menu.cpp
menu/layout/layout.cpp
menu/dx12_impl.cpp
menu/dx11_impl.cpp
feats/anti_anti_cheat.cpp
Expand Down
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ std::vector<void *> registeredFeatures;

#define registerFeature(name) \
name::init(); \
Menu::registerMenu((void *)name::menu); \
registeredFeatures.push_back((void *)name::tick);

int MainThread(HINSTANCE hInstDLL) {
Expand Down
22 changes: 3 additions & 19 deletions src/menu/dx11_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Menu {
}

long __stdcall hookPresent(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT Flags) {
if (!initialized) {
if (!Menu::initialized) {
DXGI_SWAP_CHAIN_DESC desc;
pSwapChain->GetDesc(&desc);

Expand All @@ -46,35 +46,19 @@ namespace Menu {
ImGui_ImplWin32_Init(desc.OutputWindow);
ImGui_ImplDX11_Init(device, context);

initialized = true;
Menu::initialized = true;

Logger::success("Menu initialized with D3D11 backend");

window = desc.OutputWindow;
wndProc = (WNDPROC)SetWindowLongPtr((HWND)desc.OutputWindow, GWLP_WNDPROC, (LONG_PTR)WndProc);
}

ImGui::GetIO().MouseDrawCursor = showMenu;

if (initialized) {
if (GetAsyncKeyState(VK_INSERT) & 1) {
showMenu = !showMenu;
}
}

ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();

if (showMenu) {
ImGui::Begin("Menu", &showMenu);

for (auto &func : getRegisteredMenu()) {
((void (*)())func)();
}

ImGui::End();
}
Menu::render();

ImGui::Render();
context->OMSetRenderTargets(1, &mainRenderTargetView, NULL);
Expand Down
3 changes: 0 additions & 3 deletions src/menu/dx11_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Menu {
namespace DX11 {
static bool showMenu = false;
static bool initialized = false;

typedef long(__stdcall *D3D11Present)(IDXGISwapChain *, uint32_t, uint32_t);
static D3D11Present present = nullptr;
static WNDPROC wndProc = nullptr;
Expand Down
22 changes: 3 additions & 19 deletions src/menu/dx12_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Menu {
}

HRESULT APIENTRY hookPresent(IDXGISwapChain3 *pSwapChain, UINT SyncInterval, UINT Flags) {
if (!initialized) {
if (!Menu::initialized) {
if (SUCCEEDED(pSwapChain->GetDevice(__uuidof(ID3D12Device), (void **)&device))) {
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
Expand Down Expand Up @@ -110,7 +110,7 @@ namespace Menu {
descriptorHeapImGuiRender->GetCPUDescriptorHandleForHeapStart(),
descriptorHeapImGuiRender->GetGPUDescriptorHandleForHeapStart());

initialized = true;
Menu::initialized = true;

Logger::success("Menu initialized with D3D12 backend");

Expand All @@ -119,28 +119,12 @@ namespace Menu {
}
}

ImGui::GetIO().MouseDrawCursor = showMenu;

if (initialized) {
if (GetAsyncKeyState(VK_INSERT) & 1) {
showMenu = !showMenu;
}
}

if (commandQueue != nullptr) {
ImGui_ImplDX12_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();

if (showMenu) {
ImGui::Begin("Menu", &showMenu);

for (auto &func : getRegisteredMenu()) {
((void (*)())func)();
}

ImGui::End();
}
Menu::render();

ImGui::Render();

Expand Down
2 changes: 0 additions & 2 deletions src/menu/dx12_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace Menu {
namespace DX12 {
static bool showMenu = false;
static bool initialized = false;
static HWND windowHandle = nullptr;
static WNDPROC wndProc;
static ID3D12Device *device = nullptr;
Expand Down
37 changes: 37 additions & 0 deletions src/menu/layout/layout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "layout.hpp"
#include "../../feats/fov.hpp"
#include "../../feats/inf_jump.hpp"
#include "../../feats/login.hpp"
#include "../../feats/move_speed.hpp"
#include "../../feats/quest.hpp"
#include "../../feats/teleport_anywhere.hpp"
#include "../../feats/teleport_nucleus.hpp"

namespace Menu {
namespace Layout {
void render() {
ImGui::BeginTabBar("Menu");

if (ImGui::BeginTabItem("Player")) {
Feats::MoveSpeed::menu();
Feats::Fov::menu();
Feats::InfJump::menu();
ImGui::EndTabItem();
}

if (ImGui::BeginTabItem("World")) {
Feats::TeleportNucleus::menu();
Feats::TeleportAnywhere::menu();
Feats::Quest::menu();
ImGui::EndTabItem();
}

if (ImGui::BeginTabItem("Misc")) {
Feats::Login::menu();
ImGui::EndTabItem();
}

ImGui::EndTabBar();
}
} // namespace Layout
} // namespace Menu
5 changes: 5 additions & 0 deletions src/menu/layout/layout.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Menu {
namespace Layout {
void render();
}
}
23 changes: 20 additions & 3 deletions src/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#include "dx11_impl.hpp"
#include "dx12_impl.hpp"

#include "../logger/logger.hpp"
#include "layout/layout.hpp"
#include "menu.hpp"

namespace Menu {
std::vector<void *> menuToRender;
bool isUsingDx12 = false;
bool showMenu = false;
bool initialized = false;

void init() {
if (DX12::init()) {
Expand All @@ -25,8 +28,22 @@ namespace Menu {
}
}

void registerMenu(void *func) { menuToRender.push_back(func); }
void render() {
ImGui::GetIO().MouseDrawCursor = showMenu;

std::vector<void *> getRegisteredMenu() { return menuToRender; }
if (initialized) {
if (GetAsyncKeyState(VK_INSERT) & 1) {
showMenu = !showMenu;
}
}

if (showMenu) {
ImGui::Begin("TOF-SIH", &showMenu);

Menu::Layout::render();

ImGui::End();
}
}

} // namespace Menu
4 changes: 2 additions & 2 deletions src/menu/menu.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

namespace Menu {
extern bool initialized;
void init();
void shutdown();
void registerMenu(void *func);
std::vector<void *> getRegisteredMenu();
void render();
} // namespace Menu

0 comments on commit 7f07445

Please sign in to comment.