mirror of
https://github.com/WinDurango/WinDurango.git
synced 2026-01-06 03:09:42 -06:00
Added Forza debbuging and fixed XMemSetAllocationHooks.
This commit is contained in:
committed by
GitHub
parent
cc92c485a8
commit
5e97f7d430
40
dlls/kernelx/ForzaThreadHook_X.h
Normal file
40
dlls/kernelx/ForzaThreadHook_X.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
|
||||
struct CForzaThread
|
||||
{
|
||||
DWORD Id;
|
||||
HANDLE Handle;
|
||||
DWORD StackSize;
|
||||
DWORD AffinityMask;
|
||||
DWORD Priority;
|
||||
char Name[128];
|
||||
};
|
||||
|
||||
struct FmodThread
|
||||
{
|
||||
void* virtualtable;
|
||||
char Name[256];
|
||||
};
|
||||
|
||||
DWORD(*P_StartForzaThread_X)(CForzaThread*, LPTHREAD_START_ROUTINE, LPVOID);
|
||||
|
||||
DWORD(*P_FmodThreadProc_X)(FmodThread*);
|
||||
|
||||
DWORD D_StartForzaThread_X(CForzaThread* Thread, LPTHREAD_START_ROUTINE StartAddress, LPVOID Parameter)
|
||||
{
|
||||
WCHAR ThreadName[128];
|
||||
ZeroMemory(ThreadName, sizeof(ThreadName));
|
||||
DWORD r = P_StartForzaThread_X(Thread, StartAddress, Parameter);
|
||||
MultiByteToWideChar(CP_UTF8, 0, Thread->Name, 128, ThreadName, 128);
|
||||
SetThreadDescription(Thread->Handle, ThreadName);
|
||||
return r;
|
||||
}
|
||||
|
||||
DWORD D_FmodThreadProc_X(FmodThread* Thread)
|
||||
{
|
||||
WCHAR ThreadName[256];
|
||||
MultiByteToWideChar(CP_UTF8, 0, Thread->Name, 256, ThreadName, 256);
|
||||
SetThreadDescription(GetCurrentThread(), ThreadName);
|
||||
return P_FmodThreadProc_X(Thread);
|
||||
}
|
||||
@@ -1,46 +1,115 @@
|
||||
#include "pch.h"
|
||||
#include "hooks.h"
|
||||
|
||||
// note from unixian: i used this since using appxlauncher requires me attaching to the game after it launches
|
||||
#define WINDURANGO_WAIT_FOR_DEBUGGER 0
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID reserved)
|
||||
{
|
||||
if (DetourIsHelperProcess()) return TRUE;
|
||||
|
||||
if (dwReason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
// note from unixian: some games do not create a console window, so if one isn't already created, we create one.
|
||||
if (!GetConsoleWindow())
|
||||
{
|
||||
AllocConsole();
|
||||
FILE* stream;
|
||||
freopen_s(&stream, "CONOUT$", "w", stdout);
|
||||
SetConsoleTitleA("WinDurango Debug Console");
|
||||
}
|
||||
|
||||
#if WINDURANGO_WAIT_FOR_DEBUGGER
|
||||
printf("Waiting for debugger...\n");
|
||||
while (!IsDebuggerPresent())
|
||||
Sleep(1);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
DetourRestoreAfterWith();
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourAttach(&reinterpret_cast<PVOID&>(TrueRoGetActivationFactory), RoGetActivationFactory_Hook);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
else if (dwReason == DLL_PROCESS_DETACH)
|
||||
{
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourDetach(&reinterpret_cast<PVOID&>(TrueRoGetActivationFactory), RoGetActivationFactory_Hook);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
#include "pch.h"
|
||||
#include "hooks.h"
|
||||
#include "ForzaThreadHook_X.h"
|
||||
#include "kernelx.h"
|
||||
|
||||
// note from unixian: i used this since using appxlauncher requires me attaching to the game after it launches
|
||||
#define WINDURANGO_WAIT_FOR_DEBUGGER 0
|
||||
|
||||
//Rodrigo Todescatto: For debbuging Forza.
|
||||
#define RETURN_IF_FAILED(hr) if (FAILED(hr)) return hr
|
||||
#define FORZADEBUG
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID reserved)
|
||||
{
|
||||
winrt::hstring GamePackage = winrt::Windows::ApplicationModel::Package::Current().Id().FamilyName();
|
||||
|
||||
InitializeCriticalSection(&XMemSetAllocationHooksLock_X);
|
||||
|
||||
if (DetourIsHelperProcess()) return TRUE;
|
||||
|
||||
if (dwReason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
// note from unixian: some games do not create a console window, so if one isn't already created, we create one.
|
||||
if (!GetConsoleWindow())
|
||||
{
|
||||
AllocConsole();
|
||||
FILE* stream;
|
||||
freopen_s(&stream, "CONOUT$", "w", stdout);
|
||||
SetConsoleTitleA("WinDurango Debug Console");
|
||||
}
|
||||
|
||||
#ifdef FORZADEBUG
|
||||
//Rodrigo Todescatto: Forza Horizon 2 Demo.
|
||||
if (GamePackage == L"265E1020-Anthem_8wekyb3d8bbwe")
|
||||
{
|
||||
printf("Forza Horizon 2 Demo\n");
|
||||
*(void**)&P_StartForzaThread_X = (char*)GetModuleHandleW(nullptr) + 0xFE6920;
|
||||
if (FAILED(P_StartForzaThread_X))
|
||||
{
|
||||
printf("P_StartForzaThread_X failed!\n");
|
||||
OutputDebugStringW(L"P_StartForzaThread_X failed!\n");
|
||||
}
|
||||
if (SUCCEEDED(P_StartForzaThread_X))
|
||||
{
|
||||
printf("P_StartForzaThread_X succeeded!\n");
|
||||
OutputDebugStringW(L"P_StartForzaThread_X succeeded!\n");
|
||||
}
|
||||
RETURN_IF_FAILED(HRESULT_FROM_WIN32(DetourAttach((void**)&P_StartForzaThread_X, &D_StartForzaThread_X)));
|
||||
}
|
||||
//Rodrigo Todescatto: Forza Horizon 2.
|
||||
if (GamePackage == L"Anthem_8wekyb3d8bbwe")
|
||||
{
|
||||
printf("Forza Horizon 2\n");
|
||||
*(void**)&P_StartForzaThread_X = (char*)GetModuleHandleW(nullptr) + 0x1081A90;
|
||||
if (FAILED(P_StartForzaThread_X))
|
||||
{
|
||||
printf("P_StartForzaThread_X failed!\n");
|
||||
OutputDebugStringW(L"P_StartForzaThread_X failed!\n");
|
||||
}
|
||||
if (SUCCEEDED(P_StartForzaThread_X))
|
||||
{
|
||||
printf("P_StartForzaThread_X succeeded!\n");
|
||||
OutputDebugStringW(L"P_StartForzaThread_X succeeded!\n");
|
||||
}
|
||||
*(void**)&P_FmodThreadProc_X = (char*)GetModuleHandleW(nullptr) + 0x19D3F80;
|
||||
if (FAILED(P_FmodThreadProc_X))
|
||||
{
|
||||
printf("P_FmodThreadProc_X failed!\n");
|
||||
OutputDebugStringW(L"P_FmodThreadProc_X failed!\n");
|
||||
}
|
||||
if (SUCCEEDED(P_FmodThreadProc_X))
|
||||
{
|
||||
printf("P_FmodThreadProc_X succeeded!\n");
|
||||
OutputDebugStringW(L"P_FmodThreadProc_X succeeded!\n");
|
||||
}
|
||||
RETURN_IF_FAILED(HRESULT_FROM_WIN32(DetourAttach((void**)&P_StartForzaThread_X, &D_StartForzaThread_X)));
|
||||
RETURN_IF_FAILED(HRESULT_FROM_WIN32(DetourAttach((void**)&P_FmodThreadProc_X, &D_FmodThreadProc_X)));
|
||||
}
|
||||
//Rodrigo Todescatto: Forza Motorsport 5.
|
||||
if (GamePackage == L"Forza_8wekyb3d8bbwe")
|
||||
{
|
||||
printf("Forza Motorsport 5");
|
||||
}
|
||||
//Rodrigo Todescatto: Forza Horizon 2 Presents Fast & Furious.
|
||||
if (GamePackage == L"Spire_8wekyb3d8bbwe")
|
||||
{
|
||||
printf("Forza Horizon 2 Presents Fast & Furious");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WINDURANGO_WAIT_FOR_DEBUGGER
|
||||
printf("Waiting for debugger...\n");
|
||||
while (!IsDebuggerPresent())
|
||||
Sleep(1);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
DetourRestoreAfterWith();
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourAttach(&reinterpret_cast<PVOID&>(TrueRoGetActivationFactory), RoGetActivationFactory_Hook);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
else if (dwReason == DLL_PROCESS_DETACH)
|
||||
{
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourDetach(&reinterpret_cast<PVOID&>(TrueRoGetActivationFactory), RoGetActivationFactory_Hook);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -5,10 +5,6 @@
|
||||
#include "CoreApplicationWrapperX.h"
|
||||
#include <windows.applicationmodel.core.h>
|
||||
|
||||
|
||||
|
||||
#define IsXboxCallee() IsXboxAddress(_ReturnAddress())
|
||||
|
||||
/* This function is used to compare the class name of the classId with the classIdName. */
|
||||
inline bool IsClassName(HSTRING classId, const char* classIdName)
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,63 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
typedef NTSTATUS(NTAPI* NtAllocateVirtualMemory_t)(
|
||||
HANDLE ProcessHandle,
|
||||
PVOID* BaseAddress,
|
||||
ULONG_PTR ZeroBits,
|
||||
PSIZE_T RegionSize,
|
||||
ULONG AllocationType,
|
||||
ULONG Protect
|
||||
);
|
||||
|
||||
typedef NTSTATUS(NTAPI* NtFreeVirtualMemory_t)(
|
||||
HANDLE ProcessHandle,
|
||||
PVOID* BaseAddress,
|
||||
PSIZE_T RegionSize,
|
||||
ULONG FreeType
|
||||
);
|
||||
|
||||
// THE VALUES FOR NAMES ARE GUESSED, BUT NAMES ARE CORRECT (THAT HOW ENUM SHOULD LOOK LIKE)
|
||||
enum CONSOLE_TYPE {
|
||||
CONSOLE_TYPE_XBOX_ONE = 1,
|
||||
CONSOLE_TYPE_XBOX_ONE_S = 2,
|
||||
CONSOLE_TYPE_XBOX_ONE_X = 3,
|
||||
CONSOLE_TYPE_XBOX_ONE_X_DEVKIT = 4
|
||||
};
|
||||
|
||||
typedef struct _SYSTEMOSVERSIONINFO {
|
||||
UINT8 MajorVersion;
|
||||
UINT8 MinorVersion;
|
||||
UINT16 BuildNumber;
|
||||
UINT16 Revision;
|
||||
} SYSTEMOSVERSIONINFO, * LPSYSTEMOSVERSIONINFO;
|
||||
|
||||
typedef struct _PROCESSOR_SCHEDULING_STATISTICS {
|
||||
UINT64 RunningTime;
|
||||
UINT64 IdleTime;
|
||||
UINT64 GlobalTime;
|
||||
} PROCESSOR_SCHEDULING_STATISTICS, * PPROCESSOR_SCHEDULING_STATISTICS;
|
||||
|
||||
typedef struct _TOOLINGMEMORYSTATUS {
|
||||
DWORD dwLength;
|
||||
DWORD dwReserved;
|
||||
DWORDLONG ullTotalMem;
|
||||
DWORDLONG ullAvailMem;
|
||||
DWORDLONG ulPeakUsage;
|
||||
DWORDLONG ullPageTableUsage;
|
||||
} TOOLINGMEMORYSTATUS, * PTOOLINGMEMORYSTATUS, * LPTOOLINGMEMORYSTATUS;
|
||||
|
||||
typedef struct _TITLEMEMORYSTATUS {
|
||||
DWORD dwLength;
|
||||
DWORD dwReserved;
|
||||
DWORDLONG ullTotalMem;
|
||||
DWORDLONG ullAvailMem;
|
||||
DWORDLONG ullLegacyUsed;
|
||||
DWORDLONG ullLegacyPeak;
|
||||
DWORDLONG ullLegacyAvail;
|
||||
DWORDLONG ullTitleUsed;
|
||||
DWORDLONG ullTitleAvail;
|
||||
} TITLEMEMORYSTATUS, * PTITLEMEMORYSTATUS, * LPTITLEMEMORYSTATUS;
|
||||
|
||||
__int64 sub_18001BB8C();
|
||||
|
||||
NTSTATUS sub_18001BCA0(HINSTANCE hInstance, DWORD forwardReason, LPVOID lpvReserved);
|
||||
#pragma once
|
||||
|
||||
typedef NTSTATUS(NTAPI* NtAllocateVirtualMemory_t)(
|
||||
HANDLE ProcessHandle,
|
||||
PVOID* BaseAddress,
|
||||
ULONG_PTR ZeroBits,
|
||||
PSIZE_T RegionSize,
|
||||
ULONG AllocationType,
|
||||
ULONG Protect
|
||||
);
|
||||
|
||||
typedef NTSTATUS(NTAPI* NtFreeVirtualMemory_t)(
|
||||
HANDLE ProcessHandle,
|
||||
PVOID* BaseAddress,
|
||||
PSIZE_T RegionSize,
|
||||
ULONG FreeType
|
||||
);
|
||||
|
||||
// THE VALUES FOR NAMES ARE GUESSED, BUT NAMES ARE CORRECT (THAT HOW ENUM SHOULD LOOK LIKE)
|
||||
enum CONSOLE_TYPE {
|
||||
CONSOLE_TYPE_XBOX_ONE = 1,
|
||||
CONSOLE_TYPE_XBOX_ONE_S = 2,
|
||||
CONSOLE_TYPE_XBOX_ONE_X = 3,
|
||||
CONSOLE_TYPE_XBOX_ONE_X_DEVKIT = 4
|
||||
};
|
||||
|
||||
typedef struct _SYSTEMOSVERSIONINFO {
|
||||
UINT8 MajorVersion;
|
||||
UINT8 MinorVersion;
|
||||
UINT16 BuildNumber;
|
||||
UINT16 Revision;
|
||||
} SYSTEMOSVERSIONINFO, * LPSYSTEMOSVERSIONINFO;
|
||||
|
||||
typedef struct _PROCESSOR_SCHEDULING_STATISTICS {
|
||||
UINT64 RunningTime;
|
||||
UINT64 IdleTime;
|
||||
UINT64 GlobalTime;
|
||||
} PROCESSOR_SCHEDULING_STATISTICS, * PPROCESSOR_SCHEDULING_STATISTICS;
|
||||
|
||||
typedef struct _TOOLINGMEMORYSTATUS {
|
||||
DWORD dwLength;
|
||||
DWORD dwReserved;
|
||||
DWORDLONG ullTotalMem;
|
||||
DWORDLONG ullAvailMem;
|
||||
DWORDLONG ulPeakUsage;
|
||||
DWORDLONG ullPageTableUsage;
|
||||
} TOOLINGMEMORYSTATUS, * PTOOLINGMEMORYSTATUS, * LPTOOLINGMEMORYSTATUS;
|
||||
|
||||
typedef struct _TITLEMEMORYSTATUS {
|
||||
DWORD dwLength;
|
||||
DWORD dwReserved;
|
||||
DWORDLONG ullTotalMem;
|
||||
DWORDLONG ullAvailMem;
|
||||
DWORDLONG ullLegacyUsed;
|
||||
DWORDLONG ullLegacyPeak;
|
||||
DWORDLONG ullLegacyAvail;
|
||||
DWORDLONG ullTitleUsed;
|
||||
DWORDLONG ullTitleAvail;
|
||||
} TITLEMEMORYSTATUS, * PTITLEMEMORYSTATUS, * LPTITLEMEMORYSTATUS;
|
||||
|
||||
__int64 sub_18001BB8C();
|
||||
|
||||
NTSTATUS sub_18001BCA0(HINSTANCE hInstance, DWORD forwardReason, LPVOID lpvReserved);
|
||||
|
||||
static CRITICAL_SECTION XMemSetAllocationHooksLock_X;
|
||||
@@ -1,48 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#define FAILED(hr) (((HRESULT)(hr)) < 0)
|
||||
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
|
||||
#define RETURN_IF_FAILED(hr) if (FAILED(hr)) return hr
|
||||
#define THROW_IF_FAILED(hr) if (FAILED(hr)) throw hr
|
||||
|
||||
#define IsXboxCallee() IsXboxAddress(_ReturnAddress())
|
||||
|
||||
#define GetXDKVersion() "10.0.19041.0"
|
||||
|
||||
BOOL IsXboxModule(HMODULE module)
|
||||
{
|
||||
wchar_t moduleFilePath[MAX_PATH];
|
||||
if (GetModuleFileNameW(module, moduleFilePath, MAX_PATH) > 0)
|
||||
{
|
||||
std::wstring moduleFileName(moduleFilePath);
|
||||
wprintf(L"%ls\n", moduleFileName.c_str());
|
||||
|
||||
wchar_t exeFilePath[MAX_PATH];
|
||||
if (GetModuleFileNameW(NULL, exeFilePath, MAX_PATH) > 0)
|
||||
{
|
||||
std::wstring exeDir(exeFilePath);
|
||||
size_t pos = exeDir.find_last_of(L"\\/");
|
||||
if (pos != std::wstring::npos) {
|
||||
exeDir = exeDir.substr(0, pos);
|
||||
}
|
||||
|
||||
if (moduleFileName.find(exeDir) == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
inline BOOL IsXboxAddress(const PVOID Address)
|
||||
{
|
||||
HMODULE hModule;
|
||||
|
||||
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, static_cast<LPCWSTR>(Address), &hModule))
|
||||
return FALSE;
|
||||
|
||||
return IsXboxModule(hModule);
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#define FAILED(hr) (((HRESULT)(hr)) < 0)
|
||||
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
|
||||
#define RETURN_IF_FAILED(hr) if (FAILED(hr)) return hr
|
||||
#define THROW_IF_FAILED(hr) if (FAILED(hr)) throw hr
|
||||
|
||||
#define IsXboxCallee() IsXboxAddress(_ReturnAddress())
|
||||
|
||||
#define GetXDKVersion() "10.0.19041.0"
|
||||
|
||||
BOOL IsXboxModule(HMODULE module)
|
||||
{
|
||||
return module == GetModuleHandleW(nullptr);
|
||||
}
|
||||
|
||||
inline BOOL IsXboxAddress(const PVOID Address)
|
||||
{
|
||||
HMODULE hModule;
|
||||
|
||||
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, static_cast<LPCWSTR>(Address), &hModule))
|
||||
return FALSE;
|
||||
|
||||
return IsXboxModule(hModule);
|
||||
}
|
||||
Reference in New Issue
Block a user