Skip to content

Commit

Permalink
Update SDKs, more bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Jun 22, 2024
1 parent 81f4af3 commit 638ef32
Show file tree
Hide file tree
Showing 11 changed files with 850 additions and 90 deletions.
270 changes: 195 additions & 75 deletions include/cleo/CLEO.h

Large diffs are not rendered by default.

583 changes: 583 additions & 0 deletions include/cleo/CLEO_Utils.h

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions include/cleo/cleo_redux_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,8 @@ extern "C" {
/// since v6
/// Is end of arguments reached
bool IsEndOfArguments(Context ctx);
/// since v7
/// Triggers an event with the given name and data
void TriggerEvent(const char* name, const char* data);
}

Binary file modified lib/CLEO.lib
Binary file not shown.
Binary file modified lib/cleo_redux.lib
Binary file not shown.
Binary file modified lib/cleo_redux64.lib
Binary file not shown.
7 changes: 4 additions & 3 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#include <windows.h>
#include "opcodemgr.h"
#include "hook.h"

#ifdef RUNTIME_REDUX
#include "wrapper.hpp"
#else

#ifdef RUNTIME_CLEO
#include "MinHook.h"
#include "injector.hpp"

Expand Down Expand Up @@ -84,6 +83,8 @@ BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) {
if (id == HostId::SA_UNREAL) gGameVer = eGameVer::SA_DE;
if (id == HostId::BULLY) gGameVer = eGameVer::BullySE;
#endif
wOnGameLoadEvent(ScriptExData::Clear);

OpcodeMgr::RegisterCommands();
CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&ImGuiThread, nullptr, NULL, nullptr);
}
Expand Down
21 changes: 11 additions & 10 deletions src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ void Hook::SetMouseState(bool state) {
}

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

if (ImGui::GetIO().WantTextInput || (gGameVer > eGameVer::SA && mouseVisible)) {
#ifndef _WIN64
if (gGameVer == eGameVer::SA) {
reinterpret_cast<void(__cdecl*)()>(0x53F1E0)(); // CPad::ClearKeyboardHistory
if (ImGui::GetIO().WantTextInput || (gGameVer > eGameVer::SA && mouseVisible)) {
#ifndef _WIN64
if (gGameVer == eGameVer::SA) {
reinterpret_cast<void(__cdecl*)()>(0x53F1E0)(); // CPad::ClearKeyboardHistory
}
#endif
return 1;
}
#endif
return 1;
}

return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
Expand All @@ -69,8 +71,7 @@ HRESULT Hook::hkReset(IDirect3DDevice9* pDevice, D3DPRESENT_PARAMETERS* pPresent
}

void Hook::ProcessFrame(void* ptr) {
static bool init;
if (init) {
if (m_bInitialized) {
ProcessMouse();

// Scale the menu if game resolution changed
Expand Down Expand Up @@ -224,7 +225,7 @@ void Hook::ProcessFrame(void* ptr) {
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad | ImGuiConfigFlags_NoMouseCursorChange;

oWndProc = (WNDPROC)SetWindowLongPtr(hwnd, -4, (LRESULT)hkWndProc); // GWL_WNDPROC = -4
init = true;
m_bInitialized = true;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Hook {
static void InputWatcher();

public:
static inline bool m_bInitialized = false;

Hook() = delete;
Hook(Hook const&) = delete;
Expand Down
46 changes: 45 additions & 1 deletion src/scriptextender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#include <tuple>
#include "opcodemgr.h"
#include "notifypopup.h"
#include "imgui_internal.h"

extern enum class eGameVer;
extern eGameVer gGameVer;
extern ImGuiContext* GImGui;

class ScriptExData
{
Expand Down Expand Up @@ -106,7 +108,7 @@ class ScriptExData
* Due to some limitations we can't run the ImGui realtime with the script
* We run the ImGui frames independent of the script and cache the returns to return back to script
*/
Table<std::string, std::vector<ComData>> frameData;
static inline Table<std::string, std::vector<ComData>> frameData;
static inline std::vector<ScriptExData*> scripts; // ptr to all the scripts using ImGui
static inline bool showCursor; // global cursor state flag
static inline std::string curScriptID; // current script identifier
Expand Down Expand Up @@ -207,4 +209,46 @@ class ScriptExData
Hook::SetMouseState(showCursor);
m_nFramerate = (size_t)ImGui::GetIO().Framerate;
}

// Clears all the internal stuff
static void Clear() {
scripts.clear();
frameData.Clear();

// Clear ImGui internal states here
auto e = ImGui::GetCurrentContext();
if (Hook::m_bInitialized && e) {
e->Windows.clear_delete();
e->WindowsFocusOrder.clear();
e->WindowsTempSortBuffer.clear();
e->CurrentWindow = NULL;
e->CurrentWindowStack.clear();
e->WindowsById.Clear();
e->NavWindow = NULL;
e->HoveredWindow = e->HoveredWindowUnderMovingWindow = NULL;
e->ActiveIdWindow = e->ActiveIdPreviousFrameWindow = NULL;
e->MovingWindow = NULL;
e->ColorStack.clear();
e->StyleVarStack.clear();
e->OpenPopupStack.clear();
e->BeginPopupStack.clear();

e->TabBars.Clear();
e->CurrentTabBarStack.clear();
e->ShrinkWidthBuffer.clear();

e->ClipperTempData.clear_destruct();

e->Tables.Clear();
e->TablesTempData.clear_destruct();
e->DrawChannelsTempMergeBuffer.clear();

e->ClipboardHandlerData.clear();
e->MenusIdSubmittedThisFrame.clear();
e->InputTextState.ClearFreeMemory();

e->SettingsWindows.clear();
e->SettingsHandlers.clear();
}
}
};
9 changes: 8 additions & 1 deletion src/wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "pch.h"

#ifdef RUNTIME_CLEO
#include "../include/cleo/CLEO.h"
#define RTN_CONTINUE CLEO::OR_CONTINUE
Expand All @@ -22,6 +21,14 @@
#define RUNTIME_STR_LEN 128


static void wOnGameLoadEvent(void* func) {
#ifdef RUNTIME_CLEO
CLEO::CLEO_RegisterCallback(CLEO::eCallbackId::GameBegin, func);
#else
OnRuntimeInit((OnRuntimeInitCallback)func);
#endif
}

static void wGetStringParam(RUNTIME_CONTEXT ctx, char* label, unsigned char length) {
#ifdef RUNTIME_CLEO
CLEO_ReadStringOpcodeParam(ctx, label, length);
Expand Down

0 comments on commit 638ef32

Please sign in to comment.