-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function level promotion detours for the CreateFont() family.
Yeah, I suck at inventing new terminology. Just read the comment, it should make more sense then.
- Loading branch information
Showing
5 changed files
with
130 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,60 @@ | ||
/** | ||
* Touhou Community Reliant Automatic Patcher | ||
* Main DLL | ||
* | ||
* ---- | ||
* | ||
* Win32 detour function level promotion. | ||
*/ | ||
|
||
#include "thcrap.h" | ||
#include "promote.h" | ||
|
||
/// CreateFont() family (promoting to CreateFontIndirectExA) | ||
/// ------------------- | ||
HFONT WINAPI promote_CreateFontA( | ||
__in int cHeight, | ||
__in int cWidth, | ||
__in int cEscapement, | ||
__in int cOrientation, | ||
__in int cWeight, | ||
__in DWORD bItalic, | ||
__in DWORD bUnderline, | ||
__in DWORD bStrikeOut, | ||
__in DWORD iCharSet, | ||
__in DWORD iOutPrecision, | ||
__in DWORD iClipPrecision, | ||
__in DWORD iQuality, | ||
__in DWORD iPitchAndFamily, | ||
__in_opt LPCSTR pszFaceName | ||
) | ||
{ | ||
CreateFontIndirectA_type target = (CreateFontIndirectA_type)detour_top( | ||
"gdi32.dll", "CreateFontIndirectA", (FARPROC)CreateFontIndirectU | ||
); | ||
return lower_CreateFontA(target, | ||
cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, | ||
bUnderline, bStrikeOut, iCharSet, iOutPrecision, | ||
iClipPrecision, iQuality, iPitchAndFamily, pszFaceName | ||
); | ||
} | ||
|
||
HFONT WINAPI promote_CreateFontIndirectA( | ||
__in CONST LOGFONTA *lplf | ||
) | ||
{ | ||
CreateFontIndirectExA_type target = (CreateFontIndirectExA_type)detour_top( | ||
"gdi32.dll", "CreateFontIndirectExA", (FARPROC)CreateFontIndirectExU | ||
); | ||
return lower_CreateFontIndirectA(target, lplf); | ||
} | ||
/// ------------------- | ||
|
||
void promote_mod_init(void) | ||
{ | ||
detour_chain("gdi32.dll", 0, | ||
"CreateFontIndirectA", promote_CreateFontIndirectA, | ||
"CreateFontA", promote_CreateFontA, | ||
NULL | ||
); | ||
} |
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,58 @@ | ||
/** | ||
* Touhou Community Reliant Automatic Patcher | ||
* Main DLL | ||
* | ||
* ---- | ||
* | ||
* Win32 detour function level promotion. | ||
*/ | ||
|
||
#pragma once | ||
|
||
/** | ||
* This module eliminates the redundancy in detouring certain Win32 function | ||
* families - sets of functions that act as wrappers of decreasing levels | ||
* around one functionality. | ||
* | ||
* This is done by detouring each individual wrapper with a function that | ||
* merely converts and passes each level's parameters to the next one | ||
* ("promoting"), terminating in an invocation of the detour chain for the | ||
* lowest-level function. | ||
* | ||
* Other modules would then only have to detour a single function - the | ||
* lowest-level one - to catch all calls to the whole family of functions, | ||
* instead of detouring every function and duplicating all the promotion | ||
* code required. | ||
* | ||
* For example, the CreateFont() family consists of three functions: | ||
* CreateFont(), CreateFontIndirect() and CreateFontIndirectEx(). With the | ||
* promotion module, it's enough to detour CreateFontIndirectEx() to catch | ||
* all three functions. | ||
*/ | ||
|
||
/// CreateFont() family (promoting to CreateFontIndirectExA) | ||
/// ------------------- | ||
HFONT WINAPI promote_CreateFontA( | ||
__in int cHeight, | ||
__in int cWidth, | ||
__in int cEscapement, | ||
__in int cOrientation, | ||
__in int cWeight, | ||
__in DWORD bItalic, | ||
__in DWORD bUnderline, | ||
__in DWORD bStrikeOut, | ||
__in DWORD iCharSet, | ||
__in DWORD iOutPrecision, | ||
__in DWORD iClipPrecision, | ||
__in DWORD iQuality, | ||
__in DWORD iPitchAndFamily, | ||
__in_opt LPCSTR pszFaceName | ||
); | ||
|
||
HFONT WINAPI promote_CreateFontIndirectA( | ||
__in CONST LOGFONTA *lplf | ||
); | ||
/// ------------------- | ||
|
||
// Because we want these to be as low as possible... Nifty. | ||
void promote_mod_init(void); |
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
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
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