Skip to content

Commit

Permalink
fps crash fix, new notifs, resolution bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ermaccer committed Dec 19, 2021
1 parent 5d18b93 commit 1ea1778
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 18 deletions.
15 changes: 14 additions & 1 deletion MK11Hook/MK11Hook.vcxproj.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommand>
</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>
</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommand>
</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>
</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion MK11Hook/code/MKCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ void MKCharacter::SetT800Status(bool status)

bool MKCharacter::IsCrouching()
{
return ((bool(__fastcall*)(MKCharacter*))_addr(0x14047ADB0))(this);
return ((bool(__fastcall*)(MKCharacter*))_addr(0x14047ADE0))(this);
}
30 changes: 25 additions & 5 deletions MK11Hook/code/eNotifManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,59 @@
#include <iostream>
#include <Windows.h>
#include "..\imgui\imgui.h"
#include "..\eDirectX11Hook.h"

eNotificationManager* Notifications = new eNotificationManager();

void eNotificationManager::Init()
{
m_bIsNotificationActive = false;
m_tTimer = GetTickCount64();
m_fNotifAlpha = 1.0;
}

void eNotificationManager::Update()
{
if (GetTickCount64() - m_tTimer <= m_nNotificationTime) return;
m_tTimer = GetTickCount64();
UpdateAlpha();
}

void eNotificationManager::UpdateAlpha()
{
// actually needed if game is locked at 60 anyway?

float delta = 1.0f / 60.0f;

if (eDirectX11Hook::ms_bInit)
delta = 1.0f / ImGui::GetIO().Framerate;


float alphaSpeed = 0.8f;

m_fNotifAlpha = max(m_fNotifAlpha - delta * alphaSpeed, 0.0f);


if (m_fNotifAlpha <= 0)
m_bIsNotificationActive = false;

m_bIsNotificationActive = false;
}

void eNotificationManager::Draw()
{
if (m_bIsNotificationActive)
{
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_fNotifAlpha);
ImGui::SetNextWindowPos(ImVec2(5, 10));
ImGui::SetNextWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x - 15.0f, 0.0f));
ImGui::Begin("notif", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs
| ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing);
ImGui::TextUnformatted(szMessageBuffer);
ImGui::End();
ImGui::PopStyleVar(1);
}
}

void eNotificationManager::SetNotificationTime(int time)
{
m_nNotificationTime = time;
m_fNotifAlpha = time / 1000.0f;
}

void eNotificationManager::PushNotification(const char * format, ...)
Expand Down
6 changes: 2 additions & 4 deletions MK11Hook/code/eNotifManager.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#pragma once
#include "mk10utils.h"

class eNotificationManager {
public:
char szMessageBuffer[2048] = {};
bool m_bIsNotificationActive;
int m_nNotificationTime;
int64 m_tTimer;

float m_fNotifAlpha;

void Init();

void Update();
void UpdateAlpha();
void Draw();
void SetNotificationTime(int time);
void PushNotification(const char* format, ...);
Expand Down
7 changes: 2 additions & 5 deletions MK11Hook/code/mk11menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ void MK11Menu::Draw()

ImGui::Separator();
ImGui::Checkbox("Force Camera To Move", &m_bForceCameraUpdate);
ImGui::SameLine(); ShowHelpMarker("Check this option if the game you can't move camera anymore in win poses and some cinematics.");
ImGui::SameLine(); ShowHelpMarker("Check this option if you can't move camera anymore in win poses and some cinematics.");

ImGui::Separator();
if (GetObj(PLAYER1) && GetObj(PLAYER2))
Expand Down Expand Up @@ -1422,6 +1422,7 @@ void MK11Menu::UpdateMouse()
void MK11Menu::DrawSettings()
{
ImGui::SetNextWindowPos({ ImGui::GetIO().DisplaySize.x / 2.0f, ImGui::GetIO().DisplaySize.y / 2.0f }, ImGuiCond_Once, { 0.5f, 0.5f });
ImGui::SetNextWindowSize({ 54 * ImGui::GetFontSize(), 54 * ImGui::GetFontSize() }, ImGuiCond_Once);
ImGui::Begin("Settings", &m_bSubmenuActive[SUBMENU_SETTINGS]);

static int settingID = 0;
Expand Down Expand Up @@ -1477,10 +1478,6 @@ void MK11Menu::DrawSettings()

ImGui::EndChild();

ImGui::End();



ImGui::End();
}

Expand Down
45 changes: 44 additions & 1 deletion MK11Hook/eDirectX11Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <chrono>

Present eDirectX11Hook::m_pPresent;
ResizeBuffers eDirectX11Hook::m_pResizeBuffers;
HWND eDirectX11Hook::ms_hWindow;
WNDPROC eDirectX11Hook::ms_pWndProc;
ID3D11Device* eDirectX11Hook::pDevice;
Expand Down Expand Up @@ -67,6 +68,7 @@ inline bool ShouldHookDX(float timeout = 2.5f)
void eDirectX11Hook::Init()
{
m_pPresent = 0;
m_pResizeBuffers = 0;
pDevice = 0;
pContext = 0;
ms_bFirstDraw = true;
Expand Down Expand Up @@ -230,7 +232,7 @@ HRESULT __stdcall eDirectX11Hook::Present(IDXGISwapChain * pSwapChain, UINT Sync

if (ms_bFirstDraw)
{
Notifications->SetNotificationTime(7500);
Notifications->SetNotificationTime(4500);
Notifications->PushNotification("MK11Hook %s is running! Press F1 (or L3+R3 on a controller if controller support enabled) to open the menu. Build date: %s\n", MK11HOOK_VERSION, __DATE__);
ms_bFirstDraw = false;
}
Expand Down Expand Up @@ -274,6 +276,46 @@ LRESULT __stdcall eDirectX11Hook::WndProc(const HWND hWnd, UINT uMsg, WPARAM wPa
return CallWindowProc(ms_pWndProc, hWnd, uMsg, wParam, lParam);
}

HRESULT __stdcall eDirectX11Hook::ResizeBuffers(IDXGISwapChain * pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags)
{
// somehow pdevice handle is missing in mk11 and i2? no idea
if (pDevice)
{
if (mainRenderTargetView)
{
pContext->OMSetRenderTargets(0, 0, 0);
mainRenderTargetView->Release();
}
}


HRESULT result = m_pResizeBuffers(pSwapChain, BufferCount, Width, Height, NewFormat, SwapChainFlags);

if (pDevice)
{
ID3D11Texture2D* pBackBuffer;
pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)& pBackBuffer);
pDevice->CreateRenderTargetView(pBackBuffer, NULL, &mainRenderTargetView);
pBackBuffer->Release();

D3D11_VIEWPORT viewport;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = Width;
viewport.Height = Height;



pContext->OMSetRenderTargets(1, &mainRenderTargetView, NULL);
pContext->RSSetViewports(1, &viewport);

}

return result;
}

DWORD __stdcall DirectXHookThread(LPVOID lpReserved)
{
if (ShouldHookDX(2.5f))
Expand All @@ -285,6 +327,7 @@ DWORD __stdcall DirectXHookThread(LPVOID lpReserved)
if (kiero::init(kiero::RenderType::D3D11) == kiero::Status::Success)
{
kiero::bind(8, (void**)&eDirectX11Hook::m_pPresent, eDirectX11Hook::Present);
kiero::bind(13, (void**)&eDirectX11Hook::m_pResizeBuffers, eDirectX11Hook::ResizeBuffers);
init_hook = true;
}
} while (!init_hook);
Expand Down
4 changes: 3 additions & 1 deletion MK11Hook/eDirectX11Hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam


typedef HRESULT(__stdcall* Present) (IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags);
typedef HRESULT(__stdcall* ResizeBuffers) (IDXGISwapChain * pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags);

class eDirectX11Hook {
public:
static Present m_pPresent;
static ResizeBuffers m_pResizeBuffers;
static HWND ms_hWindow;
static WNDPROC ms_pWndProc;
static ID3D11Device* pDevice;
Expand All @@ -33,7 +35,7 @@ class eDirectX11Hook {
static void ReloadImGuiFont();
static HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags);
static LRESULT __stdcall WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

static HRESULT __stdcall ResizeBuffers(IDXGISwapChain * pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags);
};


Expand Down

0 comments on commit 1ea1778

Please sign in to comment.