Skip to content

Commit

Permalink
Support more recent version of DirectWrite/D2D
Browse files Browse the repository at this point in the history
Fix a bug that will crash program in certain cases.
version info updated.
  • Loading branch information
snowie2000 committed Aug 30, 2016
1 parent ac11027 commit 28187cb
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 20 deletions.
7 changes: 4 additions & 3 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

#define _CRT_SECURE_NO_DEPRECATE 1
#ifdef _WIN64
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#define _WIN32_WINNT _WIN32_WINNT_WIN10
#define WINVER _WIN32_WINNT_VISTA
#else
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#define WINVER _WIN32_WINNT_WINXP
#define _WIN32_WINNT _WIN32_WINNT_WIN10
#define WINVER _WIN32_WINNT_WIN10
#endif
#define NTDDI_VERSION NTDDI_WIN10_RS1
#define WIN32_LEAN_AND_MEAN 1
#define UNICODE 1
#define _UNICODE 1
Expand Down
118 changes: 113 additions & 5 deletions directwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ void HookFactory(ID2D1Factory* pD2D1Factory) {
HOOK(ptr, CreateDevice3, 28);
}
}
{//factory4
CComPtr<ID2D1Factory4> ptr;
HRESULT hr = pD2D1Factory->QueryInterface(&ptr);
if (SUCCEEDED(hr)){
HOOK(ptr, CreateDevice4, 29);
}
}
{//factory5
CComPtr<ID2D1Factory5> ptr;
HRESULT hr = pD2D1Factory->QueryInterface(&ptr);
if (SUCCEEDED(hr)){
HOOK(ptr, CreateDevice5, 30);
}
}
}

void HookRenderTarget(ID2D1RenderTarget* pD2D1RenderTarget) {
Expand All @@ -80,12 +94,14 @@ void HookRenderTarget(ID2D1RenderTarget* pD2D1RenderTarget) {
CComQIPtr<ID2D1RenderTarget> ptr = pD2D1RenderTarget;

HOOK(ptr, CreateCompatibleRenderTarget, 12);
//HOOK(ptr, DrawGlyphRun2, 29);
HOOK(ptr, SetTextAntialiasMode, 34);
HOOK(ptr, SetTextRenderingParams, 36);

ID2D1Factory* pD2D1Factory;
pD2D1RenderTarget->GetFactory(&pD2D1Factory);
HookFactory(pD2D1Factory);
if (pD2D1Factory)
HookFactory(pD2D1Factory);
}
pD2D1RenderTarget->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_DEFAULT);
pD2D1RenderTarget->SetTextRenderingParams(g_D2DParams.RenderingParams);
Expand All @@ -103,7 +119,17 @@ void HookDevice(ID2D1Device* d2dDevice){
CComPtr<ID2D1Device2> ptr3;
hr = (d2dDevice)->QueryInterface(&ptr3);
if SUCCEEDED(hr) {
HOOK(ptr2, CreateDeviceContext3, 12);
HOOK(ptr3, CreateDeviceContext3, 12);
}
CComPtr<ID2D1Device3> ptr4;
hr = (d2dDevice)->QueryInterface(&ptr4);
if SUCCEEDED(hr) {
HOOK(ptr4, CreateDeviceContext4, 15);
}
CComPtr<ID2D1Device4> ptr5;
hr = (d2dDevice)->QueryInterface(&ptr5);
if SUCCEEDED(hr) {
HOOK(ptr5, CreateDeviceContext5, 16);
}
}

Expand Down Expand Up @@ -629,6 +655,38 @@ HRESULT WINAPI IMPL_CreateDeviceContext3(
return hr;
}

HRESULT WINAPI IMPL_CreateDeviceContext4(
ID2D1Device3* This,
D2D1_DEVICE_CONTEXT_OPTIONS options,
ID2D1DeviceContext3** deviceContext2
) {
HRESULT hr = ORIG_CreateDeviceContext4(
This,
options,
deviceContext2
);
if (SUCCEEDED(hr)) {
HookRenderTarget(*deviceContext2);
}
return hr;
}

HRESULT WINAPI IMPL_CreateDeviceContext5(
ID2D1Device4* This,
D2D1_DEVICE_CONTEXT_OPTIONS options,
ID2D1DeviceContext4** deviceContext
) {
HRESULT hr = ORIG_CreateDeviceContext5(
This,
options,
deviceContext
);
if (SUCCEEDED(hr)) {
HookRenderTarget(*deviceContext);
}
return hr;
}

HRESULT WINAPI IMPL_CreateDevice1(
ID2D1Factory1* This,
IDXGIDevice* dxgiDevice,
Expand Down Expand Up @@ -689,6 +747,46 @@ HRESULT WINAPI IMPL_CreateDevice3(
return hr;
}

HRESULT WINAPI IMPL_CreateDevice4(
ID2D1Factory4* This,
IDXGIDevice* dxgiDevice,
ID2D1Device3** d2dDevice3
){
HRESULT hr = ORIG_CreateDevice4(
This,
dxgiDevice,
d2dDevice3
);
if (SUCCEEDED(hr)) {
static bool loaded = false;
if (!loaded) {
loaded = true;
HookDevice(*d2dDevice3);
}
}
return hr;
}

HRESULT WINAPI IMPL_CreateDevice5(
ID2D1Factory5* This,
IDXGIDevice* dxgiDevice,
ID2D1Device4** d2dDevice4
){
HRESULT hr = ORIG_CreateDevice5(
This,
dxgiDevice,
d2dDevice4
);
if (SUCCEEDED(hr)) {
static bool loaded = false;
if (!loaded) {
loaded = true;
HookDevice(*d2dDevice4);
}
}
return hr;
}


bool MakeD2DParams(IDWriteFactory* dw_factory)
{
Expand Down Expand Up @@ -853,7 +951,7 @@ bool hookDirectWrite(IUnknown ** factory) //此函数需要改进以判断是否
{
//CoInitialize(NULL);
#ifdef DEBUG
MessageBox(NULL, L"HookDW", NULL, MB_OK);
//MessageBox(NULL, L"HookDW", NULL, MB_OK);
#endif
if (InterlockedExchange((LONG*)&bDWLoaded, true)) return false;

Expand Down Expand Up @@ -928,7 +1026,7 @@ void HookD2DDll()
_COM_Outptr_ IUnknown **factory
);
#ifdef DEBUG
MessageBox(0, L"HookD2DDll", NULL, MB_OK);
//MessageBox(0, L"HookD2DDll", NULL, MB_OK);
#endif
HMODULE d2d1 = LoadLibrary(_T("d2d1.dll"));
HMODULE dw = LoadLibrary(_T("dwrite.dll"));
Expand Down Expand Up @@ -1111,4 +1209,14 @@ HRESULT WINAPI IMPL_DrawGlyphRun(
}
MyDebug(L"DrawGlyphRun hooked");
return hr;
}
}

/*
void WINAPI IMPL_DrawGlyphRun2(
D2D1_POINT_2F baselineOrigin,
_In_ CONST DWRITE_GLYPH_RUN *glyphRun,
_In_ ID2D1Brush *foregroundBrush,
DWRITE_MEASURING_MODE measuringMode = DWRITE_MEASURING_MODE_NATURAL)
{
return ORIG_DrawGlyphRun2(baselineOrigin, glyphRun, foregroundBrush, measuringMode);
}*/
1 change: 1 addition & 0 deletions directwrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "easyhook.h"

#pragma once

#define HOOK_MANUALLY HOOK_DEFINE
#define HOOK_DEFINE(rettype, name, argtype) \
extern rettype(WINAPI * ORIG_##name) argtype; \
Expand Down
4 changes: 2 additions & 2 deletions doc/HOWTOBUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Here I will show you the steps I do to make the compilation.
- Freetype ([link](https://www.freetype.org/download.html))
- EasyHook ([link](http://easyhook.github.io/))
- or Detours(obsolete, better not use)
- Windows sdk ([link](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk))
- Windows sdk 10.0.14393.0 or later([link](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk))

3. **Building dependencies**
- FreeType
Expand Down Expand Up @@ -42,7 +42,7 @@ Here I will show you the steps I do to make the compilation.
4. **Build**

Last but simplest step. Put all files you builds in the above steps, set up VC++ folders and hit F7.
Last but simplest step. Put all files you builds in the above steps to MacType folder, set up VC++ folders and hit F7.
Enjoy.

FAQ
Expand Down
8 changes: 4 additions & 4 deletions gdidll.rc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_SYS_DEFAULT
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2016,216,0
PRODUCTVERSION 1,2016,216,0
FILEVERSION 1,2016,830,0
PRODUCTVERSION 1,2016,830,0
FILEFLAGSMASK 0x8L
#ifdef _DEBUG
FILEFLAGS 0x9L
Expand All @@ -43,13 +43,13 @@ BEGIN
VALUE "Comments", "Portions of this software are copyright (c) 2005-2012 The FreeType Project (www.freetype.org). All rights reserved."
VALUE "CompanyName", "2ch & THEMEX"
VALUE "FileDescription", "The Ultimate Font Rasterizer"
VALUE "FileVersion", "1.2016.0216.0"
VALUE "FileVersion", "1.2016.830.0"
VALUE "InternalName", "MacType"
VALUE "LegalCopyright", "(C) 460, 168, Higambana, 555 and sy567. All rights reserved. FlyingSnow republished"
VALUE "OriginalFilename", "MacType.dll"
VALUE "PrivateBuild", "False"
VALUE "ProductName", "The Ultimate Font Rasterizer"
VALUE "ProductVersion", "1.2016.0216.0"
VALUE "ProductVersion", "1.2016.830.0"
VALUE "URL", "http://mactype.themex.net http://drwatson.nobody.jp/gdi++/"
END
END
Expand Down
8 changes: 4 additions & 4 deletions gdipp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<IncludePath>D:\Archives\Documents\Visual Studio 2008\Projects\freetype-2.6.5\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\shared;$(IncludePath)</IncludePath>
<IncludePath>D:\Archives\Documents\Visual Studio 2008\Projects\freetype-2.6.5\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\shared;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ReferencePath>D:\Program Files\Microsoft Research\Detours Express 2.1\lib;$(ReferencePath)</ReferencePath>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<IncludePath>D:\Archives\Documents\Visual Studio 2008\Projects\freetype-2.6.5\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\shared;$(IncludePath)</IncludePath>
<IncludePath>D:\Archives\Documents\Visual Studio 2008\Projects\freetype-2.6.5\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\shared;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ReferencePath>D:\Program Files\Microsoft Research\Detours Express 2.1\lib;$(ReferencePath)</ReferencePath>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<IncludePath>D:\Archives\Documents\Visual Studio 2008\Projects\freetype-2.6.5\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\shared;$(IncludePath)</IncludePath>
<IncludePath>D:\Archives\Documents\Visual Studio 2008\Projects\freetype-2.6.5\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\shared;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -97,7 +97,7 @@
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<IncludePath>D:\Archives\Documents\Visual Studio 2008\Projects\freetype-2.6.5\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\shared;$(IncludePath)</IncludePath>
<IncludePath>D:\Archives\Documents\Visual Studio 2008\Projects\freetype-2.6.5\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\shared;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down
2 changes: 1 addition & 1 deletion hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID lpReserved)
switch(reason) {
case DLL_PROCESS_ATTACH:
#ifdef DEBUG
MessageBox(0, L"Load", NULL, MB_OK);
//MessageBox(0, L"Load", NULL, MB_OK);
#endif
g_dllInstance = instance;
//初期化順序
Expand Down
33 changes: 33 additions & 0 deletions hooklist.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ HOOK_MANUALLY(HRESULT, CreateDeviceContext3, (
ID2D1DeviceContext2** deviceContext
))

HOOK_MANUALLY(HRESULT, CreateDeviceContext4, (
ID2D1Device3* This,
D2D1_DEVICE_CONTEXT_OPTIONS options,
ID2D1DeviceContext3** deviceContext
))

HOOK_MANUALLY(HRESULT, CreateDeviceContext5, (
ID2D1Device4* This,
D2D1_DEVICE_CONTEXT_OPTIONS options,
ID2D1DeviceContext4** deviceContext
))

HOOK_MANUALLY(HRESULT, CreateTextFormat, (
IDWriteFactory* self,
__in_z WCHAR const* fontFamilyName,
Expand Down Expand Up @@ -300,4 +312,25 @@ HOOK_MANUALLY(HRESULT, CreateDevice3, (
IDXGIDevice* dxgiDevice,
ID2D1Device2** d2dDevice2
));

HOOK_MANUALLY(HRESULT, CreateDevice4, (
ID2D1Factory4* This,
IDXGIDevice* dxgiDevice,
ID2D1Device3** d2dDevice3
));

HOOK_MANUALLY(HRESULT, CreateDevice5, (
ID2D1Factory5* This,
IDXGIDevice* dxgiDevice,
ID2D1Device4** d2dDevice4
));

/*
HOOK_MANUALLY(void, DrawGlyphRun2, (
D2D1_POINT_2F baselineOrigin,
_In_ CONST DWRITE_GLYPH_RUN *glyphRun,
_In_ ID2D1Brush *foregroundBrush,
DWRITE_MEASURING_MODE measuringMode
));*/

//EOF
2 changes: 1 addition & 1 deletion settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "cache.h"
#include "hash_list.h"

#define MACTYPE_VERSION 20120404
#define MACTYPE_VERSION 20160830
#define MAX_FONT_SETTINGS 16
#define DEFINE_FS_MEMBER(name, param) \
int Get##name() const { return GetParam(param); } \
Expand Down

0 comments on commit 28187cb

Please sign in to comment.