summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/main.cpp
blob: 22fabbbdef2a9ceb7b899776d1a4ce854619a62c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "stdafx.h"

int hLangpack;

HINSTANCE g_hInstance;

CMLua *g_mLua;

HANDLE g_hCLibsFolder;
HANDLE g_hScriptsFolder;

HNETLIBUSER hNetlib = nullptr;

PLUGININFOEX pluginInfo =
{
	sizeof(PLUGININFOEX),
	__PLUGIN_NAME,
	PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
	__DESCRIPTION,
	__AUTHOR,
	__COPYRIGHT,
	__AUTHORWEB,
	UNICODE_AWARE,
	// {27d41d81-991f-4dc6-8749-b0321c87e694}
	{ 0x27d41d81, 0x991f, 0x4dc6, { 0x87, 0x49, 0xb0, 0x32, 0x1c, 0x87, 0xe6, 0x94 } }

};

DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
{
	g_hInstance = hInstance;

	return TRUE;
}

extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
	return &pluginInfo;
}

int OnModulesLoaded(WPARAM, LPARAM)
{
	g_hCLibsFolder = FoldersRegisterCustomPathT(MODULE, "CLibsFolder", MIRLUA_PATHT, TranslateT("C libs folder"));
	g_hScriptsFolder = FoldersRegisterCustomPathT(MODULE, "ScriptsFolder", MIRLUA_PATHT, TranslateT("Scripts folder"));

	HookEvent(ME_OPT_INITIALISE, CMLuaOptions::OnOptionsInit);

	InitIcons();

	g_mLua = new CMLua();
	g_mLua->Load();

	return 0;
}

INT_PTR Call(WPARAM wParam, LPARAM lParam)
{
	return g_mLua->Call(wParam, lParam);
}

INT_PTR Exec(WPARAM wParam, LPARAM lParam)
{
	return g_mLua->Exec(wParam, lParam);
}

INT_PTR Eval(WPARAM wParam, LPARAM lParam)
{
	return g_mLua->Eval(wParam, lParam);
}

extern "C" int __declspec(dllexport) Load(void)
{
	mir_getLP(&pluginInfo);

	HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);

	NETLIBUSER nlu = {};
	nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS;
	nlu.szDescriptiveName.a = MODULE;
	nlu.szSettingsModule = MODULE;
	hNetlib = Netlib_RegisterUser(&nlu);

	PROTOCOLDESCRIPTOR pd = { 0 };
	pd.cbSize = sizeof(pd);
	pd.szName = MODULE;
	pd.type = PROTOTYPE_FILTER;
	Proto_RegisterModule(&pd);

	hRecvMessage = CreateHookableEvent(MODULE PSR_MESSAGE);
	CreateProtoServiceFunction(MODULE, PSR_MESSAGE, FilterRecvMessage);

	CreateServiceFunction(MS_LUA_CALL, Call);
	CreateServiceFunction(MS_LUA_EXEC, Exec);
	CreateServiceFunction(MS_LUA_EVAL, Eval);

	return 0;
}

extern "C" int __declspec(dllexport) Unload(void)
{
	delete g_mLua;

	if (hNetlib)
	{
		Netlib_CloseHandle(hNetlib);
		hNetlib = nullptr;
	}

	return 0;
}