-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathKeeperSpeechImp.c
130 lines (107 loc) · 3.15 KB
/
KeeperSpeechImp.c
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/******************************************************************************/
// Free implementation of Bullfrog's Dungeon Keeper strategy game.
/******************************************************************************/
/** @file KeeperSpeechImp.c
* Import functions for KeeperSpeech module.
* @par Purpose:
* To for the corresponding platform load and make KeeperSpeech functions available.
* If KeeperSpeech is not available for platform, functions return gracefully and
* pretend that nothing happens.
* @par Comment:
* None.
* @author KeeperFX Team
* @date 2011
* @par Copying and copyrights:
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
/******************************************************************************/
#include "KeeperSpeech.h"
#ifdef WIN32
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
static HINSTANCE ks_lib;
#endif
struct
{
fpKeeperSpeechErrorMessage error_message;
fpKeeperSpeechExit exit;
fpKeeperSpeechPopEvent pop_event;
fpKeeperSpeechClearEvents clear_events;
} static ks_fn;
static void clean_up()
{
#ifdef WIN32
if (ks_lib) {
FreeLibrary(ks_lib);
ks_lib = NULL;
}
#endif
memset(&ks_fn, 0, sizeof(ks_fn));
}
KEEPERSPEECH_REASON KeeperSpeechInit(void)
{
fpKeeperSpeechInit init;
KEEPERSPEECH_REASON reason;
init = NULL;
#ifdef WIN32
if (ks_lib) {
return KSR_ALREADY_INIT;
}
ks_lib = LoadLibrary("KeeperSpeech.dll");
if (!ks_lib) {
return KSR_NO_LIB_INSTALLED;
}
init = (fpKeeperSpeechInit) GetProcAddress(ks_lib, "KeeperSpeechInit");
ks_fn.error_message = (fpKeeperSpeechErrorMessage) GetProcAddress(ks_lib, "KeeperSpeechErrorMessage");
ks_fn.exit = (fpKeeperSpeechExit) GetProcAddress(ks_lib, "KeeperSpeechExit");
ks_fn.pop_event = (fpKeeperSpeechPopEvent) GetProcAddress(ks_lib, "KeeperSpeechPopEvent");
ks_fn.clear_events = (fpKeeperSpeechClearEvents) GetProcAddress(ks_lib, "KeeperSpeechClearEvents");
//check for critical functions
if (!init ||
!ks_fn.error_message ||
!ks_fn.exit) {
clean_up();
return KSR_NO_LIB_INSTALLED;
}
#endif
//check in case of unimplemented platform
if (!init) {
return KSR_NO_LIB_INSTALLED;
}
reason = init();
if (reason != KSR_OK) {
clean_up();
}
return reason;
}
const char * KeeperSpeechErrorMessage(KEEPERSPEECH_REASON reason)
{
if (ks_fn.error_message) {
return ks_fn.error_message(reason);
}
return "KeeperSpeech module not found";
}
void KeeperSpeechExit(void)
{
if (ks_fn.exit) {
ks_fn.exit();
}
clean_up();
}
KEEPERSPEECH_REASON KeeperSpeechPopEvent(KEEPERSPEECH_EVENT * ev)
{
if (ks_fn.pop_event) {
return ks_fn.pop_event(ev);
}
return KSR_NOMOREEVENTS;
}
void KeeperSpeechClearEvents(void)
{
if (ks_fn.clear_events) {
ks_fn.clear_events();
}
}