Skip to content

Commit

Permalink
Make example script work for unknown hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed May 4, 2022
1 parent c922105 commit afd6876
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 35 deletions.
23 changes: 15 additions & 8 deletions resource/imgui_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference path=".config/sa.d.ts" />

//
// ImGuiRedux Example Script
//
Expand All @@ -11,6 +10,14 @@ var gRadioBtn = 1
var gTimerExample = false
var gPrevTimer = 0

function textBox(text)
{
if (["gta3", "vc", "sa", "gta3_unreal", "vc_unreal", "sa_unreal"].includes(HOST))
{
showTextBox(text)
}
}

while (true)
{
/*
Expand Down Expand Up @@ -64,37 +71,37 @@ while (true)
let size = ImGui.GetScalingSize("S0", 2, false)
if (ImGui.Button("Normal button 1", size.x, size.y))
{
showTextBox("Normal button 1 was pressed")
textBox("Normal button 1 was pressed")
}
ImGui.SameLine()
if (ImGui.Button("Normal button 2", size.x, size.y))
{
showTextBox("Normal button 2 was pressed")
textBox("Normal button 2 was pressed")
}

ImGui.Spacing()

size = ImGui.GetScalingSize("S1", 3, false)
if (ImGui.ButtonColored("CB 1", 1.0, 0.0, 0.0, 1.0, size.x, size.y))
{
showTextBox("Color button 1 was pressed")
textBox("Color button 1 was pressed")
}
ImGui.SameLine()
if (ImGui.ButtonColored("CB 2", 0.0, 1.0, 0.0, 1.0, size.x, size.y))
{
showTextBox("Color button 2 was pressed")
textBox("Color button 2 was pressed")
}
ImGui.SameLine()
if (ImGui.ButtonColored("CB 3", 0.0, 0.0, 1.0, 1.0, size.x, size.y))
{
showTextBox("Color button 3 was pressed")
textBox("Color button 3 was pressed")
}

size = ImGui.GetScalingSize("S2", 1, false)
ImGui.Text("Tip: Click the below area")
if (ImGui.ButtonInvisible("Invis button", size.x, size.y))
{
showTextBox("Invisible button was pressed")
textBox("Invisible button was pressed")
}
if (ImGui.IsItemHovered("HOver"))
{
Expand Down Expand Up @@ -167,7 +174,7 @@ while (true)
// This code has 5 second delay
if (gTimerExample && (TIMERA - gPrevTimer > 5000))
{
showTextBox("Timer test message")
textBox("Timer test message")
gPrevTimer = TIMERA
}

Expand Down
Binary file added resource/opengl32.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pch.h"
#include <windows.h>
#include "opcodemgr.h"
#include "d3dhook.h"
#include "hook.h"
#include "injector.hpp"

void ImGuiThread(void* param)
Expand Down Expand Up @@ -39,7 +39,7 @@ void ImGuiThread(void* param)
}
}

if (!D3dHook::InjectHook(&ScriptExData::DrawFrames))
if (!Hook::Inject(&ScriptExData::DrawFrames))
{
Log("[ImGuiRedux] Failed to inject dxhook.");
MessageBox(HWND_DESKTOP, "Failed to inject dxhook..", "ImGuiRedux", MB_ICONERROR);
Expand Down
24 changes: 12 additions & 12 deletions src/d3dhook.cpp → src/hook.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "pch.h"
#include "d3dhook.h"
#include "hook.h"
#include "kiero.h"
#include "MinHook.h"
#include "imgui_impl_dx9.h"
Expand All @@ -10,17 +10,17 @@

extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

bool D3dHook::GetMouseState()
bool Hook::GetMouseState()
{
return mouseShown;
}

void D3dHook::SetMouseState(bool state)
void Hook::SetMouseState(bool state)
{
mouseShown = state;
}

LRESULT D3dHook::hkWndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT Hook::hkWndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);

Expand All @@ -36,14 +36,14 @@ LRESULT D3dHook::hkWndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
}

HRESULT D3dHook::hkReset(IDirect3DDevice9* pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
HRESULT Hook::hkReset(IDirect3DDevice9* pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
{
ImGui_ImplDX9_InvalidateDeviceObjects();

return oReset(pDevice, pPresentationParameters);
}

void D3dHook::ProcessFrame(void* ptr)
void Hook::ProcessFrame(void* ptr)
{
if (!ImGui::GetCurrentContext())
{
Expand Down Expand Up @@ -205,25 +205,25 @@ void D3dHook::ProcessFrame(void* ptr)
}
}

HRESULT D3dHook::hkEndScene(IDirect3DDevice9* pDevice)
HRESULT Hook::hkEndScene(IDirect3DDevice9* pDevice)
{
ProcessFrame(pDevice);
return oEndScene(pDevice);
}

HRESULT D3dHook::hkPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags)
HRESULT Hook::hkPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags)
{
ProcessFrame(pSwapChain);
return oPresent(pSwapChain, SyncInterval, Flags);
}

BOOL D3dHook::hkGlSwapBuffer(HDC hDc)
BOOL Hook::hkGlSwapBuffer(HDC hDc)
{
ProcessFrame(nullptr);
return oGlSwapBuffer(hDc);
}

void D3dHook::ProcessMouse()
void Hook::ProcessMouse()
{
static bool curState;
if (curState != mouseShown)
Expand Down Expand Up @@ -303,7 +303,7 @@ void D3dHook::ProcessMouse()
}
}

bool D3dHook::InjectHook(void *pCallback)
bool Hook::Inject(void *pCallback)
{
static bool hookInjected;
if (hookInjected)
Expand Down Expand Up @@ -367,7 +367,7 @@ bool D3dHook::InjectHook(void *pCallback)
return hookInjected;
}

void D3dHook::RemoveHook()
void Hook::Remove()
{
pCallbackFunc = nullptr;
#ifdef _WIN64
Expand Down
12 changes: 6 additions & 6 deletions src/d3dhook.h → src/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <GL/gl.h>
#pragma warning(pop)

class D3dHook
class Hook
{
private:
using f_EndScene = HRESULT(CALLBACK*)(IDirect3DDevice9*);
Expand Down Expand Up @@ -38,12 +38,12 @@ class D3dHook
static BOOL CALLBACK hkGlSwapBuffer(HDC hDc);
public:

D3dHook() = delete;
D3dHook(D3dHook const&) = delete;
void operator=(D3dHook const&) = delete;
Hook() = delete;
Hook(Hook const&) = delete;
void operator=(Hook const&) = delete;

static bool GetMouseState();
static bool InjectHook(void *pCallback);
static void RemoveHook();
static bool Inject(void *pCallback);
static void Remove();
static void SetMouseState(bool state);
};
4 changes: 2 additions & 2 deletions src/scriptextender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string>
#include "cleo_redux_sdk.h"
#include "table.hpp"
#include "d3dhook.h"
#include "hook.h"
#include <functional>
#include <any>
#include <tuple>
Expand Down Expand Up @@ -157,7 +157,7 @@ class ScriptExData
}

// update stuff
D3dHook::SetMouseState(showCursor);
Hook::SetMouseState(showCursor);
m_nFramerate = (size_t)ImGui::GetIO().Framerate;
}
};
5 changes: 0 additions & 5 deletions tools/premake5.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

----------------------------
-- Premake Project Generator
----------------------------

workspace "ImGuiRedux"
configurations {
"Debug",
Expand Down

0 comments on commit afd6876

Please sign in to comment.