Skip to content

Commit

Permalink
0.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
RElesgoe committed Dec 18, 2015
1 parent 920148c commit 6fb0814
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/ddraw.c → src/ddraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
#pragma comment( lib, "user32" )
#pragma comment( lib, "gdi32" )

#define CINTERFACE
#include <windows.h>
#include <ddraw.h>

void HookFonts(void);

struct {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[256];
Expand Down Expand Up @@ -73,8 +76,8 @@ HRESULT GoFullscreen( void )
}
ddraw->lpVtbl->Release( ddraw );
}
FreeLibrary( ddraw_dll );
}
FreeLibrary( ddraw_dll );
}
}
return DDERR_GENERIC;
Expand Down Expand Up @@ -186,6 +189,9 @@ BOOL __stdcall DllEntryPoint( HINSTANCE hDll, DWORD dwReason, LPVOID lpvReserved
ButtonWndProc_original = wc.lpfnWndProc;
wc.lpfnWndProc = ButtonWndProc;
RegisterClass( &wc );

// Disable AntiAliased Fonts
HookFonts();
}

if( dwReason == DLL_PROCESS_DETACH )
Expand Down
81 changes: 81 additions & 0 deletions src/no_aa.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Disable AntiAliased Fonts via hot-patch of gdi's CreateFont/Indirect

#include <windows.h>

typedef HFONT (__stdcall* CREATEFONTINDIRECTA)( CONST LOGFONT* );
typedef HFONT (__stdcall* CREATEFONTA)( int,int,int,int,int,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCTSTR );

CREATEFONTINDIRECTA CreateFontIndirectA_origproc;
CREATEFONTA CreateFontA_origproc;

// hook a system dll on Windows XP SP2 or later
// returns the address of the original_proc on success, null on failure
#pragma intrinsic( memcmp )
void* HotPatch( void* target, void* hookproc )
{
DWORD dwPrevProtect;
char* patch_address;
void* original_proc;

original_proc = NULL;

patch_address = ((char*)target) - 5;

// entry point could be at the top of a page if function is not hot-patch-able
// so VirtualProtect first to make sure patch_address is readable
if( VirtualProtect( patch_address, 7, PAGE_EXECUTE_WRITECOPY, &dwPrevProtect ) )
{
// make sure it is a hotpatchable image... check for 5 nops followed by mov edi,edi
if( !memcmp( "\x90\x90\x90\x90\x90\x8B\xFF", patch_address, 7 ) ||
!memcmp( "\xCC\xCC\xCC\xCC\xCC\x8B\xFF", patch_address, 7 ) )
{
// overwrite the pad nops above the function entry point with a jump
patch_address[0] = '\xE9';
*((DWORD*)(&patch_address[1])) = ((char*)hookproc) - patch_address - 5; // relative address

// 8B FF == mov edi,edi
// overwrite the functions entry point with a short jmp to the long jmp we just wrote...
*((WORD*)(&patch_address[5])) = 0xf9eb; // EB F9 == JMP SHORT $-5

original_proc = (void*) (((char*)target) + 2); // hop over hook
}
VirtualProtect( patch_address, 7, dwPrevProtect, &dwPrevProtect ); // restore protection
}
return original_proc;
}

#pragma intrinsic( memcpy )
HFONT __stdcall CreateFontIndirectA_hookproc( CONST LOGFONTA* lplf )
{
LOGFONTA lf;
memcpy( &lf, lplf, sizeof(lf) );
lf.lfQuality = NONANTIALIASED_QUALITY;
return CreateFontIndirectA_origproc( &lf );
}

HFONT __stdcall CreateFontA_hookproc( int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight,
DWORD fdwItalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet,
DWORD fdwOutputPrecision, DWORD fdwClipPrecision, DWORD fdwQuality, DWORD fdwPitchAndFamily,
LPCTSTR lpszFace )
{
fdwQuality = NONANTIALIASED_QUALITY;
return CreateFontA_origproc( nHeight, nWidth, nEscapement, nOrientation, fnWeight,
fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet,
fdwOutputPrecision, fdwClipPrecision, fdwQuality, fdwPitchAndFamily,
lpszFace );
}

void HookFonts(void)
{
HMODULE gdi_dll;

gdi_dll = GetModuleHandle("GDI32.dll");

CreateFontA_origproc = (CREATEFONTA) HotPatch(
GetProcAddress( gdi_dll, "CreateFontA" ),
CreateFontA_hookproc );

CreateFontIndirectA_origproc = (CREATEFONTINDIRECTA) HotPatch(
GetProcAddress( gdi_dll, "CreateFontIndirectA" ),
CreateFontIndirectA_hookproc );
}
7 changes: 5 additions & 2 deletions src/proxy_dll.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="usp10.lib imm32.lib"
OutputFile="ddraw.dll"
LinkIncremental="1"
GenerateManifest="false"
Expand Down Expand Up @@ -185,13 +184,17 @@
</References>
<Files>
<File
RelativePath=".\ddraw.c"
RelativePath=".\ddraw.cpp"
>
</File>
<File
RelativePath=".\dpiaware.manifest"
>
</File>
<File
RelativePath=".\no_aa.cpp"
>
</File>
<File
RelativePath=".\resource.rc"
>
Expand Down
6 changes: 3 additions & 3 deletions src/resource.rc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <windows.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,0,1
PRODUCTVERSION 0,0,0,1
FILEVERSION 0,0,0,2
PRODUCTVERSION 0,0,0,2
FILEFLAGSMASK 63
FILEFLAGS 0
FILEOS VOS_UNKNOWN
Expand All @@ -14,7 +14,7 @@ FILESUBTYPE VFT2_UNKNOWN
BLOCK "040904E4" /* LANG_ENGLISH/SUBLANG_DEFAULT, CP 1252 */
{
VALUE "FileDescription", "compatibility ddraw proxy for war2bne"
VALUE "FileVersion", "0.1"
VALUE "FileVersion", "0.2"
VALUE "LegalCopyright", "www.bitpatch.com"
}
}
Expand Down

0 comments on commit 6fb0814

Please sign in to comment.