Skip to content

Commit fe363ac

Browse files
committed
initial sample code
1 parent 46984cc commit fe363ac

18 files changed

+580
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@
3030
*.exe
3131
*.out
3232
*.app
33+
34+
.vs/*
35+
bin/*
36+
*.vcxproj.user

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "dep/imgui"]
2+
path = dep/imgui
3+
url = https://github.com/gw2-addon-loader/imgui

Source.def

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LIBRARY gw2addon_gw2addon.dll
2+
EXPORTS
3+
gw2addon_get_description
4+
gw2addon_load
5+
gw2addon_unload

dep/gw2al_api.h

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#pragma once
2+
3+
#define gw2al_hashed_name unsigned long long
4+
#define gw2al_event_id unsigned long
5+
6+
typedef struct gw2al_addon_dsc {
7+
const wchar_t* name;
8+
const wchar_t* description;
9+
unsigned char majorVer;
10+
unsigned char minorVer;
11+
unsigned int revision;
12+
13+
gw2al_addon_dsc* dependList;
14+
} gw2al_addon_dsc;
15+
16+
//api return codes
17+
18+
typedef enum gw2al_api_ret {
19+
GW2AL_OK,
20+
GW2AL_FAIL,
21+
GW2AL_IN_USE,
22+
GW2AL_NOT_FOUND,
23+
GW2AL_BAD_DLL,
24+
GW2AL_DEP_NOT_LOADED,
25+
GW2AL_DEP_OUTDATED,
26+
GW2AL_DEP_STILL_LOADED,
27+
GW2AL_STATIC_LIMIT_HIT
28+
} gw2al_api_ret;
29+
30+
//used to handle events
31+
typedef void(*gw2al_api_event_handler)(void* data);
32+
33+
#define GW2AL_CORE_FUNN_HASH_NAME 1
34+
#define GW2AL_CORE_FUNN_REG_FUN 2
35+
#define GW2AL_CORE_FUNN_UNREG_FUN 3
36+
#define GW2AL_CORE_FUNN_QUERY_FUN 4
37+
#define GW2AL_CORE_FUNN_FILL_VTBL 5
38+
#define GW2AL_CORE_FUNN_UNLOAD_ADDON 6
39+
#define GW2AL_CORE_FUNN_LOAD_ADDON 7
40+
#define GW2AL_CORE_FUNN_QUERY_ADDON 8
41+
#define GW2AL_CORE_FUNN_WATCH_EVENT 9
42+
#define GW2AL_CORE_FUNN_UNWATCH_EVENT 10
43+
#define GW2AL_CORE_FUNN_QUERY_EVENT 11
44+
#define GW2AL_CORE_FUNN_TRIGGER_EVENT 12
45+
#define GW2AL_CORE_FUNN_CLIENT_UNLOAD 13
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;
55+
56+
typedef struct gw2al_core_vtable {
57+
//converts string to hash for usage in other functions
58+
gw2al_hashed_name (*hash_name)(wchar_t* name);
59+
60+
//register/unregister user functions to be called by other addons
61+
gw2al_api_ret (*register_function)(void* function, gw2al_hashed_name name);
62+
void (*unregister_function)(gw2al_hashed_name name);
63+
64+
//query function pointer from registered list
65+
void* (*query_function)(gw2al_hashed_name name);
66+
67+
//fills table of functions using query_function
68+
void (*fill_vtable)(gw2al_hashed_name* nameList, void** vtable);
69+
70+
//functions to unload/load addons
71+
gw2al_api_ret (*unload_addon)(gw2al_hashed_name name);
72+
gw2al_api_ret (*load_addon)(wchar_t* name);
73+
74+
//function to get currently loaded addon description
75+
gw2al_addon_dsc* (*query_addon)(gw2al_hashed_name name);
76+
77+
//simple event api
78+
//watch event can add a number of handlers on event name with priority
79+
//query event will get internal event id to speedup trigger_event calls
80+
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);
83+
gw2al_event_id (*query_event)(gw2al_hashed_name name);
84+
unsigned int (*trigger_event)(gw2al_event_id id, void* data);
85+
86+
//unload function to delete properly unload things on client exit
87+
88+
void (*client_unload)();
89+
90+
//simple logging function
91+
92+
void (*log_text)(gw2al_log_level level, wchar_t* source, wchar_t* text);
93+
94+
} gw2al_core_vtable;
95+
96+
//addon must export this functions as
97+
//gw2addon_get_description
98+
//gw2addon_load
99+
//gw2addon_unload
100+
101+
typedef gw2al_addon_dsc* (*gw2al_addon_get_dsc_proc)();
102+
typedef gw2al_api_ret(*gw2al_addon_load_proc)(gw2al_core_vtable* core_api);
103+
typedef gw2al_api_ret(*gw2al_addon_unload_proc)(int gameExiting);

dep/gw2al_lib_imgui.h

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#pragma once
2+
3+
#include <gw2al_api.h>
4+
#include <imgui.h>
5+
6+
#define LIB_IMGUI_DEP_ENTRY { L"lib_imgui", L" ", 1, 0, 1, 0 }
7+
8+
template<typename UserHandler>
9+
class lib_imgui
10+
{
11+
const wchar_t* getContextExportName = L"lib_imgui_get_context";
12+
const wchar_t* guiDrawEventName = L"lib_imgui_draw_event";
13+
14+
gw2al_hashed_name getContextExportNameHash = 0;
15+
gw2al_hashed_name guiDrawEventNameHash = 0;
16+
gw2al_event_id guiDrawEventId = 0;
17+
18+
static lib_imgui<UserHandler>& instance();
19+
20+
typedef void* (*procType)();
21+
void* (*getImguiContextProc)();
22+
static void drawEventHandler(void* imguiContext)
23+
{
24+
ImGui::SetCurrentContext((ImGuiContext*)imguiContext);
25+
instance().handler.draw();
26+
}
27+
28+
gw2al_core_vtable* gAPI = nullptr;
29+
gw2al_hashed_name subscriber = 0;
30+
31+
UserHandler handler;
32+
33+
void initInternal(gw2al_core_vtable* in_api, gw2al_hashed_name addonNameHash, unsigned int priorityOverride)
34+
{
35+
gAPI = in_api;
36+
37+
getContextExportNameHash = gAPI->hash_name((wchar_t*)getContextExportName);
38+
guiDrawEventNameHash = gAPI->hash_name((wchar_t*)guiDrawEventName);
39+
guiDrawEventId = gAPI->query_event(guiDrawEventNameHash);
40+
41+
getImguiContextProc = (procType)gAPI->query_function(getContextExportNameHash);
42+
subscriber = addonNameHash;
43+
gAPI->watch_event(guiDrawEventId, addonNameHash, &drawEventHandler, priorityOverride);
44+
45+
ImGui::SetCurrentContext((ImGuiContext*)getImguiContextProc());
46+
handler.init();
47+
}
48+
49+
public:
50+
void init(gw2al_core_vtable* in_api, const wchar_t* addonName, unsigned int priorityOverride = 0)
51+
{
52+
initInternal(in_api, in_api->hash_name((wchar_t*)addonName), priorityOverride);
53+
}
54+
55+
void init(gw2al_core_vtable* in_api, gw2al_hashed_name addonNameHash, unsigned int priorityOverride = 0)
56+
{
57+
initInternal(in_api, addonNameHash, priorityOverride);
58+
}
59+
60+
void deinit()
61+
{
62+
gAPI->unwatch_event(guiDrawEventId, subscriber);
63+
handler.deinit();
64+
}
65+
66+
UserHandler* operator->()
67+
{
68+
return &handler;
69+
}
70+
71+
ImGuiContext* getImguiContext()
72+
{
73+
return (ImGuiContext*)getImguiContextProc();
74+
}
75+
};
76+
77+
/*
78+
class UserInterface
79+
{
80+
UserInterface() = default;
81+
82+
void init()
83+
{
84+
//called after lib_imgui init with setted up imgui context
85+
}
86+
87+
void draw()
88+
{
89+
//called every frame to draw interface if not hidden
90+
}
91+
92+
void deinit()
93+
{
94+
//called at deinit
95+
}
96+
}
97+
98+
//somewhere in addon instance
99+
100+
lib_imgui<UserInterface> ui;
101+
102+
template<>
103+
inline lib_imgui<Gui>& lib_imgui<Gui>::instance()
104+
{
105+
return ui;
106+
}
107+
108+
*/

dep/imgui

Submodule imgui added at d9ebe46

gw2addon.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29728.190
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gw2addon", "gw2addon.vcxproj", "{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Release|x64 = Release|x64
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Debug|x64.ActiveCfg = Debug|x64
15+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Debug|x64.Build.0 = Debug|x64
16+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Release|x64.ActiveCfg = Release|x64
17+
{BDCB35C3-8ED9-4A6E-A346-D16F17D4600C}.Release|x64.Build.0 = Release|x64
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B4AB9663-402C-42D7-94ED-864553319B48}
24+
EndGlobalSection
25+
EndGlobal

gw2addon.vcxproj

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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|x64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>x64</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|x64">
9+
<Configuration>Release</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<VCProjectVersion>16.0</VCProjectVersion>
15+
<ProjectGuid>{AE0B7438-0B6E-497E-BE0C-117FE82D2770}</ProjectGuid>
16+
<RootNamespace>gw2addon</RootNamespace>
17+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
18+
</PropertyGroup>
19+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
21+
<ConfigurationType>DynamicLibrary</ConfigurationType>
22+
<UseDebugLibraries>true</UseDebugLibraries>
23+
<PlatformToolset>v142</PlatformToolset>
24+
<CharacterSet>Unicode</CharacterSet>
25+
</PropertyGroup>
26+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
27+
<ConfigurationType>DynamicLibrary</ConfigurationType>
28+
<UseDebugLibraries>false</UseDebugLibraries>
29+
<PlatformToolset>v142</PlatformToolset>
30+
<WholeProgramOptimization>true</WholeProgramOptimization>
31+
<CharacterSet>Unicode</CharacterSet>
32+
</PropertyGroup>
33+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
34+
<ImportGroup Label="ExtensionSettings">
35+
</ImportGroup>
36+
<ImportGroup Label="Shared">
37+
</ImportGroup>
38+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
39+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
40+
</ImportGroup>
41+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
42+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
43+
</ImportGroup>
44+
<PropertyGroup Label="UserMacros" />
45+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
46+
<LinkIncremental>true</LinkIncremental>
47+
<TargetName>gw2addon_$(ProjectName)</TargetName>
48+
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\addons\$(ProjectName)\</OutDir>
49+
<IncludePath>$(ProjectDir)\dep\imgui;$(ProjectDir)\src;$(IncludePath);$(ProjectDir)\dep</IncludePath>
50+
</PropertyGroup>
51+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
52+
<LinkIncremental>false</LinkIncremental>
53+
<TargetName>gw2addon_$(ProjectName)</TargetName>
54+
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\addons\$(ProjectName)\</OutDir>
55+
<IncludePath>$(ProjectDir)\dep\imgui;$(ProjectDir)\src;$(IncludePath);$(ProjectDir)\dep</IncludePath>
56+
</PropertyGroup>
57+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
58+
<ClCompile>
59+
<PrecompiledHeader>Use</PrecompiledHeader>
60+
<WarningLevel>Level3</WarningLevel>
61+
<Optimization>Disabled</Optimization>
62+
<SDLCheck>true</SDLCheck>
63+
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
64+
<ConformanceMode>true</ConformanceMode>
65+
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
66+
</ClCompile>
67+
<Link>
68+
<SubSystem>Windows</SubSystem>
69+
<GenerateDebugInformation>true</GenerateDebugInformation>
70+
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
71+
</Link>
72+
</ItemDefinitionGroup>
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
74+
<ClCompile>
75+
<PrecompiledHeader>Use</PrecompiledHeader>
76+
<WarningLevel>Level3</WarningLevel>
77+
<Optimization>MaxSpeed</Optimization>
78+
<FunctionLevelLinking>true</FunctionLevelLinking>
79+
<IntrinsicFunctions>true</IntrinsicFunctions>
80+
<SDLCheck>true</SDLCheck>
81+
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
82+
<ConformanceMode>true</ConformanceMode>
83+
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
84+
</ClCompile>
85+
<Link>
86+
<SubSystem>Windows</SubSystem>
87+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
88+
<OptimizeReferences>true</OptimizeReferences>
89+
<GenerateDebugInformation>true</GenerateDebugInformation>
90+
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
91+
</Link>
92+
</ItemDefinitionGroup>
93+
<ItemGroup>
94+
<ClInclude Include="dep\imgui\imconfig.h" />
95+
<ClInclude Include="dep\imgui\imgui.h" />
96+
<ClInclude Include="dep\imgui\imgui_internal.h" />
97+
<ClInclude Include="src/stdafx.h" />
98+
<ClInclude Include="src/targetver.h" />
99+
<ClInclude Include="src\addon.h" />
100+
<ClInclude Include="src\Gui.h" />
101+
<ClInclude Include="src\Main.h" />
102+
</ItemGroup>
103+
<ItemGroup>
104+
<ClCompile Include="dep\imgui\imgui.cpp" />
105+
<ClCompile Include="dep\imgui\imgui_draw.cpp" />
106+
<ClCompile Include="src/stdafx.cpp">
107+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
108+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
109+
</ClCompile>
110+
<ClCompile Include="src\addon.cpp" />
111+
<ClCompile Include="src\Gui.cpp" />
112+
<ClCompile Include="src\Main.cpp" />
113+
</ItemGroup>
114+
<ItemGroup>
115+
<None Include="Source.def" />
116+
</ItemGroup>
117+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
118+
<ImportGroup Label="ExtensionTargets">
119+
</ImportGroup>
120+
</Project>

0 commit comments

Comments
 (0)