Skip to content

Commit a929804

Browse files
committed
implemented event api, added sample addon
1 parent 04b7909 commit a929804

30 files changed

+956
-49
lines changed

fake_client/fake_client.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "pch.h"
2+
#include <iostream>
3+
4+
int main()
5+
{
6+
std::cout << "fake_client start!\n";
7+
8+
std::cout << "Loading d3d9.dll \n";
9+
10+
HMODULE d3d9md = LoadLibrary(L"d3d9.dll");
11+
12+
if (!d3d9md)
13+
{
14+
std::cout << "d3d9.dll can't be loaded for some reason.\n";
15+
return -1;
16+
}
17+
18+
typedef IDirect3D9* (WINAPI* Direct3DCreate9Func)(UINT sdkver);
19+
20+
Direct3DCreate9Func origDirect3DCreate9 = (Direct3DCreate9Func)GetProcAddress(d3d9md, "Direct3DCreate9");
21+
22+
if (!origDirect3DCreate9)
23+
{
24+
std::cout << "d3d9.dll Direct3DCreate9 export not found.\n";
25+
return -1;
26+
}
27+
28+
std::cout << "calling Direct3DCreate9 \n";
29+
30+
IDirect3D9* res = origDirect3DCreate9(D3D_SDK_VERSION);
31+
32+
std::cout << "called Direct3DCreate9 \n";
33+
34+
std::cout << "exiting \n";
35+
36+
res->Release();
37+
38+
std::cout << "d3d9 com released \n";
39+
40+
FreeLibrary(d3d9md);
41+
42+
std::cout << "d3d9 lib released \n";
43+
44+
std::cout << "All fine! \n";
45+
46+
system("pause");
47+
48+
return 0;
49+
}

fake_client/fake_client.vcxproj

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>15.0</VCProjectVersion>
23+
<ProjectGuid>{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}</ProjectGuid>
24+
<Keyword>Win32Proj</Keyword>
25+
<RootNamespace>fakeclient</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v141</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v141</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v141</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v141</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
74+
<LinkIncremental>true</LinkIncremental>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
77+
<LinkIncremental>true</LinkIncremental>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
80+
<LinkIncremental>false</LinkIncremental>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
83+
<LinkIncremental>false</LinkIncremental>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
86+
<ClCompile>
87+
<PrecompiledHeader>Use</PrecompiledHeader>
88+
<WarningLevel>Level3</WarningLevel>
89+
<Optimization>Disabled</Optimization>
90+
<SDLCheck>true</SDLCheck>
91+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
<ConformanceMode>true</ConformanceMode>
93+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
94+
</ClCompile>
95+
<Link>
96+
<SubSystem>Console</SubSystem>
97+
<GenerateDebugInformation>true</GenerateDebugInformation>
98+
</Link>
99+
</ItemDefinitionGroup>
100+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
101+
<ClCompile>
102+
<PrecompiledHeader>Use</PrecompiledHeader>
103+
<WarningLevel>Level3</WarningLevel>
104+
<Optimization>Disabled</Optimization>
105+
<SDLCheck>true</SDLCheck>
106+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107+
<ConformanceMode>true</ConformanceMode>
108+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
109+
</ClCompile>
110+
<Link>
111+
<SubSystem>Console</SubSystem>
112+
<GenerateDebugInformation>true</GenerateDebugInformation>
113+
</Link>
114+
</ItemDefinitionGroup>
115+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
116+
<ClCompile>
117+
<PrecompiledHeader>Use</PrecompiledHeader>
118+
<WarningLevel>Level3</WarningLevel>
119+
<Optimization>MaxSpeed</Optimization>
120+
<FunctionLevelLinking>true</FunctionLevelLinking>
121+
<IntrinsicFunctions>true</IntrinsicFunctions>
122+
<SDLCheck>true</SDLCheck>
123+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
124+
<ConformanceMode>true</ConformanceMode>
125+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
126+
</ClCompile>
127+
<Link>
128+
<SubSystem>Console</SubSystem>
129+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
130+
<OptimizeReferences>true</OptimizeReferences>
131+
<GenerateDebugInformation>true</GenerateDebugInformation>
132+
</Link>
133+
</ItemDefinitionGroup>
134+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
135+
<ClCompile>
136+
<PrecompiledHeader>Use</PrecompiledHeader>
137+
<WarningLevel>Level3</WarningLevel>
138+
<Optimization>MaxSpeed</Optimization>
139+
<FunctionLevelLinking>true</FunctionLevelLinking>
140+
<IntrinsicFunctions>true</IntrinsicFunctions>
141+
<SDLCheck>true</SDLCheck>
142+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
143+
<ConformanceMode>true</ConformanceMode>
144+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
145+
</ClCompile>
146+
<Link>
147+
<SubSystem>Console</SubSystem>
148+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
149+
<OptimizeReferences>true</OptimizeReferences>
150+
<GenerateDebugInformation>true</GenerateDebugInformation>
151+
</Link>
152+
</ItemDefinitionGroup>
153+
<ItemGroup>
154+
<ClInclude Include="pch.h" />
155+
</ItemGroup>
156+
<ItemGroup>
157+
<ClCompile Include="fake_client.cpp" />
158+
<ClCompile Include="pch.cpp">
159+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
160+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
161+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
162+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
163+
</ClCompile>
164+
</ItemGroup>
165+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
166+
<ImportGroup Label="ExtensionTargets">
167+
</ImportGroup>
168+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Файлы ресурсов">
5+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
6+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
7+
</Filter>
8+
<Filter Include="headers">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="sources">
13+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
14+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="pch.h">
19+
<Filter>headers</Filter>
20+
</ClInclude>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClCompile Include="pch.cpp">
24+
<Filter>sources</Filter>
25+
</ClCompile>
26+
<ClCompile Include="fake_client.cpp">
27+
<Filter>sources</Filter>
28+
</ClCompile>
29+
</ItemGroup>
30+
</Project>

fake_client/pch.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "pch.h"

fake_client/pch.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef PCH_H
2+
#define PCH_H
3+
4+
// TODO: add headers that you want to pre-compile here
5+
#include <Windows.h>
6+
#include <d3d9.h>
7+
8+
9+
#endif //PCH_H
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#define gw2al_hashed_name unsigned long
3+
#define gw2al_hashed_name unsigned long long
44
#define gw2al_event_id unsigned long
55

66
typedef struct gw2al_addon_dsc {
@@ -43,7 +43,15 @@ typedef void(*gw2al_api_event_handler)(void* data);
4343
#define GW2AL_CORE_FUNN_QUERY_EVENT 11
4444
#define GW2AL_CORE_FUNN_TRIGGER_EVENT 12
4545
#define GW2AL_CORE_FUNN_CLIENT_UNLOAD 13
46-
#define GW2AL_CORE_FUNN_D3DCREATE_HOOK 14
46+
#define GW2AL_CORE_FUNN_LOG_TEXT 14
47+
#define GW2AL_CORE_FUNN_D3DCREATE_HOOK 15
48+
49+
typedef enum gw2al_log_level {
50+
LL_INFO = 0,
51+
LL_ERR,
52+
LL_WARN,
53+
LL_DEBUG
54+
} gw2al_log_level;
4755

4856
typedef struct gw2al_core_vtable {
4957
//converts string to hash for usage in other functions
@@ -70,15 +78,19 @@ typedef struct gw2al_core_vtable {
7078
//watch event can add a number of handlers on event name with priority
7179
//query event will get internal event id to speedup trigger_event calls
7280

73-
gw2al_api_ret (*watch_event)(gw2al_hashed_name name, gw2al_hashed_name subscriber, gw2al_api_event_handler handler, unsigned int priority);
74-
void (*unwatch_event)(gw2al_hashed_name name, gw2al_hashed_name subscriber);
81+
gw2al_api_ret (*watch_event)(gw2al_event_id id, gw2al_hashed_name subscriber, gw2al_api_event_handler handler, unsigned int priority);
82+
void (*unwatch_event)(gw2al_event_id id, gw2al_hashed_name subscriber);
7583
gw2al_event_id (*query_event)(gw2al_hashed_name name);
7684
unsigned int (*trigger_event)(gw2al_event_id id, void* data);
7785

7886
//unload function to delete properly unload things on client exit
7987

8088
void (*client_unload)();
8189

90+
//simple logging function
91+
92+
void (*log_text)(gw2al_log_level level, wchar_t* source, wchar_t* text);
93+
8294
} gw2al_core_vtable;
8395

8496
//addon must export this functions as

loader_core.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ VisualStudioVersion = 15.0.28307.329
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loader_core", "loader_core\loader_core.vcxproj", "{024CCE36-7DE3-4ACC-80E6-EF25F9894C11}"
77
EndProject
8+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fake_client", "fake_client\fake_client.vcxproj", "{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}"
9+
ProjectSection(ProjectDependencies) = postProject
10+
{024CCE36-7DE3-4ACC-80E6-EF25F9894C11} = {024CCE36-7DE3-4ACC-80E6-EF25F9894C11}
11+
EndProjectSection
12+
EndProject
13+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample_addons", "sample_addons", "{8AA3E837-7C1B-43AC-A468-219446479EED}"
14+
EndProject
15+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "custom_d3d9", "sample_addons\custom_d3d9\custom_d3d9.vcxproj", "{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}"
16+
EndProject
817
Global
918
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1019
Debug|x64 = Debug|x64
@@ -21,10 +30,29 @@ Global
2130
{024CCE36-7DE3-4ACC-80E6-EF25F9894C11}.Release|x64.Build.0 = Release|x64
2231
{024CCE36-7DE3-4ACC-80E6-EF25F9894C11}.Release|x86.ActiveCfg = Release|Win32
2332
{024CCE36-7DE3-4ACC-80E6-EF25F9894C11}.Release|x86.Build.0 = Release|Win32
33+
{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}.Debug|x64.ActiveCfg = Debug|x64
34+
{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}.Debug|x64.Build.0 = Debug|x64
35+
{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}.Debug|x86.ActiveCfg = Debug|Win32
36+
{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}.Debug|x86.Build.0 = Debug|Win32
37+
{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}.Release|x64.ActiveCfg = Release|x64
38+
{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}.Release|x64.Build.0 = Release|x64
39+
{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}.Release|x86.ActiveCfg = Release|Win32
40+
{33FC0BB7-E821-4B68-BB81-B16BD7F76C84}.Release|x86.Build.0 = Release|Win32
41+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Debug|x64.ActiveCfg = Debug|x64
42+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Debug|x64.Build.0 = Debug|x64
43+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Debug|x86.ActiveCfg = Debug|Win32
44+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Debug|x86.Build.0 = Debug|Win32
45+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Release|x64.ActiveCfg = Release|x64
46+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Release|x64.Build.0 = Release|x64
47+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Release|x86.ActiveCfg = Release|Win32
48+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Release|x86.Build.0 = Release|Win32
2449
EndGlobalSection
2550
GlobalSection(SolutionProperties) = preSolution
2651
HideSolutionNode = FALSE
2752
EndGlobalSection
53+
GlobalSection(NestedProjects) = preSolution
54+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C} = {8AA3E837-7C1B-43AC-A468-219446479EED}
55+
EndGlobalSection
2856
GlobalSection(ExtensibilityGlobals) = postSolution
2957
SolutionGuid = {34D8D1A4-06F2-4F24-9BA6-2B8C41FCA92E}
3058
EndGlobalSection

loader_core/d3d9_dll_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//Direct3DCreate9
44
extern "C" IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion) {
5-
return instance.OnD3DCreate(SDKVersion);
5+
return loader_core::instance.OnD3DCreate(SDKVersion);
66
}
77

88
extern "C" HRESULT WINAPI Direct3DCreate9Ex(

loader_core/dllmain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ BOOL APIENTRY DllMain( HMODULE hModule,
1212
case DLL_THREAD_DETACH:
1313
break;
1414
case DLL_PROCESS_DETACH:
15-
instance.SignalUnload();
15+
gw2al_core__client_unload();
1616
break;
1717
}
1818
return TRUE;

0 commit comments

Comments
 (0)