-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
2,212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#pragma once | ||
#include <windows.h> | ||
|
||
#define CALLVOID(a) ((void (__cdecl *)())a)() | ||
#define CALLVOIDRETCHAR(a) ((char (__cdecl *)())a)() | ||
#define READPVOID(a) (*(void **)a) | ||
#define READCHAR(a) (*(char *)a) | ||
|
||
class CPatch | ||
{ | ||
private: | ||
inline static void Patch(void* address, void* data, int size) | ||
{ | ||
unsigned long protect[2]; | ||
VirtualProtect(address, size, PAGE_EXECUTE_READWRITE, &protect[0]); | ||
memcpy(address, data, size); | ||
VirtualProtect(address, size, protect[0], &protect[1]); | ||
} | ||
public: | ||
inline static void Nop(int address, int size) | ||
{ | ||
unsigned long protect[2]; | ||
VirtualProtect((void *)address, size, PAGE_EXECUTE_READWRITE, &protect[0]); | ||
memset((void *)address, 0x90, size); | ||
VirtualProtect((void *)address, size, protect[0], &protect[1]); | ||
} | ||
inline static bool CheckChar(int address, unsigned char value) | ||
{ | ||
unsigned long protect[2]; | ||
unsigned char dummy = value; | ||
VirtualProtect((void *)address, 1, PAGE_EXECUTE_READ, &protect[0]); | ||
memcpy(&dummy, (void *)address, 1); | ||
VirtualProtect((void *)address, 1, protect[0], &protect[1]); | ||
return (dummy == value); | ||
} | ||
inline static void RedirectCall(int address, void *func) | ||
{ | ||
int temp = 0xE8; | ||
Patch((void *)address, &temp, 1); | ||
temp = (int)func - ((int)address + 5); | ||
Patch((void *)((int)address + 1), &temp, 4); | ||
} | ||
inline static void RedirectJump(int address, void *func) | ||
{ | ||
int temp = 0xE9; | ||
Patch((void *)address, &temp, 1); | ||
temp = (int)func - ((int)address + 5); | ||
Patch((void *)((int)address + 1), &temp, 4); | ||
} | ||
inline static void RedirectJZ(int address, void *func) | ||
{ | ||
int temp = 0x840F; | ||
Patch((void *)address, &temp, 2); | ||
temp = (int)func - ((int)address + 6); | ||
Patch((void *)((int)address + 2), &temp, 4); | ||
} | ||
inline static void SetChar(int address, char value) | ||
{ | ||
Patch((void *)address, &value, 1); | ||
} | ||
inline static void SetShort(int address, short value) | ||
{ | ||
Patch((void *)address, &value, 2); | ||
} | ||
inline static void SetInt(int address, int value) | ||
{ | ||
Patch((void *)address, &value, 4); | ||
} | ||
inline static void SetFloat(int address, float value) | ||
{ | ||
Patch((void *)address, &value, 4); | ||
} | ||
inline static void SetPointer(int address, void *value) | ||
{ | ||
Patch((void *)address, &value, 4); | ||
} | ||
|
||
inline static void Set(int address, void* data, int size) | ||
{ | ||
Patch((void*)address, data, size); | ||
} | ||
}; | ||
|
||
template<typename T> | ||
inline static void CALL(int address, void *func, T &CB) | ||
{ | ||
if ( *(int*)(address + 1) + (address + 5) != (int)func) | ||
{ | ||
CB = reinterpret_cast <T>(*(int*)(address + 1) + (address + 5)); | ||
CPatch::RedirectCall(address, func); | ||
} | ||
} | ||
|
||
template <typename T> | ||
inline void *FUNC2PTR(T o) | ||
{ | ||
auto member = o; | ||
void*& ptr = (void*&)member; | ||
return ptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
premake5 vs2010 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
local function addSrcFiles( prefix ) | ||
return prefix .. "/*cpp", prefix .. "/*.h" | ||
end | ||
|
||
|
||
workspace "MHWSF" | ||
configurations { "Release" } | ||
location "build" | ||
|
||
files { addSrcFiles("src") } | ||
|
||
includedirs { "src" } | ||
includedirs { "inc" } | ||
|
||
project "MHWSF" | ||
kind "SharedLib" | ||
language "C++" | ||
targetdir "bin/%{cfg.buildcfg}" | ||
targetextension ".asi" | ||
characterset ("MBCS") | ||
|
||
filter "configurations:Release" | ||
defines { "NDEBUG" } | ||
optimize "On" | ||
flags { "StaticRuntime" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#define DEFAULT_SCREEN_WIDTH ((float)(640)) | ||
#define DEFAULT_SCREEN_HEIGHT ((float)(480)) | ||
#define DEFAULT_ASPECT_RATIO (4.0f/3.0f) | ||
#define SCREEN_WIDTH (GetScrn().fWidth) | ||
#define SCREEN_HEIGHT (GetScrn().fHeight) | ||
#define SCREEN_ASPECT_RATIO GetScrnAspectRatio() | ||
|
||
#define SCREEN_SCALE_AR(a) ((a) * DEFAULT_ASPECT_RATIO / SCREEN_ASPECT_RATIO) | ||
#define SCREEN_STRETCH_X(a) ((a) * GetScrn().fWidthScale) | ||
#define SCREEN_STRETCH_Y(a) ((a) * GetScrn().fHeightScale) | ||
#define SCREEN_SCALE_X(a) SCREEN_SCALE_AR(SCREEN_STRETCH_X(a)) | ||
#define SCREEN_SCALE_Y(a) SCREEN_STRETCH_Y(a) | ||
|
||
#define SCREEN_SCLX(x) ( SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * (x)) / SCREEN_WIDTH ) | ||
|
||
#define SCREEN_WIDTH_4_3 SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH) | ||
|
||
#define SCREEN_FC(x) ( (SCREEN_WIDTH/2 - SCREEN_WIDTH_4_3/2) + SCREEN_SCALE_X((x)) ) | ||
#define SCREEN_FR(x) ( (SCREEN_WIDTH - SCREEN_WIDTH_4_3 ) + SCREEN_SCALE_X((x)) ) | ||
#define SCREEN_FL(x) ( SCREEN_SCALE_X((x)) ) | ||
#define SCREEN_FROM_RIGHT(x) ( SCREEN_FR(DEFAULT_SCREEN_WIDTH * (x)) / SCREEN_WIDTH ) | ||
#define SCREEN_FROM_LEFT(x) ( SCREEN_FL(DEFAULT_SCREEN_WIDTH * (x)) / SCREEN_WIDTH ) | ||
#define SCREEN_FROM_CENTER(x) ( SCREEN_FC(DEFAULT_SCREEN_WIDTH * (x)) / SCREEN_WIDTH ) | ||
|
||
struct SCRN_T { float fWidth, fHeight, fInvWidth, fInvHeight, fWidthScale, fHeightScale, HudStretch; }; | ||
|
||
inline SCRN_T &GetScrn() | ||
{ | ||
return *(SCRN_T *)0x7D3440; | ||
} | ||
|
||
static float GetScrnAspectRatio() | ||
{ | ||
float stretch = (GetScrn().fHeight / GetScrn().fWidth) / (GetScrn().fHeightScale / GetScrn().fWidthScale); | ||
return stretch * DEFAULT_ASPECT_RATIO / GetScrn().HudStretch; | ||
} |
Oops, something went wrong.