-
Notifications
You must be signed in to change notification settings - Fork 12
/
Plugin.cpp
85 lines (65 loc) · 1.95 KB
/
Plugin.cpp
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
//
// Language plugin support
//
#include "VirtuaNESres.h"
#include "Pathlib.h"
#include "DebugOut.h"
#include "Plugin.h"
typedef INT (__cdecl *GETVLPVERSION)();
typedef void (__cdecl *GETVLPLANGUAGE)( LPSTR );
typedef LCID (__cdecl *GETVLPLOCALEID)();
INT CPlugin::m_PluginID = 0;
INT CPlugin::m_PluginNum = 0;
CPlugin::PLUGIN CPlugin::m_Plugin[PLUGIN_MAX];
HINSTANCE CPlugin::LoadPlugin()
{
return LoadPluginID( m_PluginID );
}
HINSTANCE CPlugin::LoadPluginID( INT nID )
{
return ::LoadLibrary( m_Plugin[nID].Path );
}
BOOL CPlugin::FindPlugin( LPCSTR lpModulePath )
{
m_PluginNum = 0;
string Path = CPathlib::MakePath( lpModulePath, "*.vlp" );
WIN32_FIND_DATA find;
HANDLE hFind = ::FindFirstFile( Path.c_str(), &find );
if( hFind == INVALID_HANDLE_VALUE )
return FALSE;
HINSTANCE hDLL;
GETVLPVERSION GetVlpVersion = NULL;
GETVLPLANGUAGE GetVlpLanguage = NULL;
GETVLPLOCALEID GetVlpLocaleID = NULL;
BOOL bFind = TRUE;
while( bFind ) {
if( (hDLL = ::LoadLibrary( find.cFileName )) ) {
GetVlpVersion = (GETVLPVERSION) ::GetProcAddress( hDLL, "GetVlpVersion" );
GetVlpLanguage = (GETVLPLANGUAGE)::GetProcAddress( hDLL, "GetVlpLanguage" );
GetVlpLocaleID = (GETVLPLOCALEID)::GetProcAddress( hDLL, "GetVlpLocaleID" );
if( !(!GetVlpVersion || !GetVlpLanguage || !GetVlpLocaleID) ) {
INT ver = GetVlpVersion();
if( ver >= VIRTUANES_PLUGIN_VERSION ) {
m_Plugin[m_PluginNum].LocaleID = GetVlpLocaleID();
string Path = CPathlib::MakePath( lpModulePath, find.cFileName );
::strcpy( m_Plugin[m_PluginNum].Path, Path.c_str() );
GetVlpLanguage( m_Plugin[m_PluginNum].Language );
m_PluginNum++;
}
}
::FreeLibrary( hDLL );
}
bFind = ::FindNextFile( hFind, &find );
if( m_PluginNum >= PLUGIN_MAX )
break;
}
::FindClose( hFind );
LCID lcid = ::GetUserDefaultLCID();
for( INT no = 0; no < m_PluginNum; no++ ) {
if( m_Plugin[no].LocaleID == lcid ) {
m_PluginID = no;
return TRUE;
}
}
return TRUE;
}