-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
156 lines (136 loc) · 4.7 KB
/
Copy pathmain.cpp
File metadata and controls
156 lines (136 loc) · 4.7 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
MapMaker plugin
Purpose:
Get a pre-formatted string from arma and save it to a text file
Retreive line from file and replace ; with , and add [ and ] to the end.
A single procedure call returns a single line, maintain a file pointer and use getNext
A function to create a file with filename
Append a line to the current file
Close the current file
A function to open a file
A function to list files
A function to delete a file
*/
/*
TO COMPILE ON LINUX WITH GCC
g++ -fpic -shared -m32 -o mapmaker.so main.cpp -Bstatic -l:/home/xealot/boost_stage/lib/libboost_system.a -l:/home/xealot/boost_stage/lib/libboost_date_time.a
replace the absolute paths with only relative ones like "libboost_system.a" if the system has static libraries installed
TO COMPILE ON WINDOWS WITH MINGW(GCC)
g++ -shared -o MapMaker.dll main.cpp -D_WIN32_WINNT=0x0501 -DWINVER=0x0501 "-LF:\Program Files (x86)\CodeBlocks\MinGW\lib" -lboost_system-mgw47-mt-1_55 -lboost_date_time-mgw47-mt-1_55 -lws2_32
replace the path to your boost libraries as needed
*/
// http://stackoverflow.com/questions/6924195/get-dll-path-at-runtime
// http://stackoverflow.com/questions/12643880/get-absolute-path-with-boostfilesystempath
// http://stackoverflow.com/questions/1681060/library-path-when-dynamically-loaded
/* Make a platform check here */
#include <boost/predef.h>
#if BOOST_OS_WINDOWS
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0601
#include <windows.h>
#elif BOOST_OS_LINUX
#endif
#define PLUGIN_VERSION "0.3"
#include "common.h"
#include "mapmanager.cpp"
#include "time.cpp"
using namespace std;
/* global var */
MapManager *mapManager = NULL;
#if BOOST_OS_WINDOWS
extern "C" int APIENTRY DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpvReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
//AllocConsole();
//freopen("CONOUT$", "w", stdout);
//break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif
string not_implemented() {
return "[]";
}
void write_response(char *output, int outputSize, const string& data) {
#if BOOST_COMP_MSVC
sprintf_s(output, outputSize-1, "%s", data.c_str());
#elif BOOST_COMP_GNUC
snprintf(output, outputSize-1, "%s", data.c_str());
#endif
}
/* A little messy, declare the exported function depending on compiler and OS */
#if BOOST_OS_WINDOWS
#if BOOST_COMP_GNUC
extern "C" __declspec(dllexport) void __stdcall _RVExtension(char *output, int outputSize, const char *function)
#elif BOOST_COMP_MSVC
extern "C" __declspec(dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function)
#endif
#elif BOOST_OS_LINUX
extern "C" void RVExtension(char *output, int outputSize, const char *function)
#endif
{
/* init MapManager */
if (!mapManager)
mapManager = new MapManager();
string s_function(function);
/* list - lists all files (takes no arguments) */
if (s_function == "list") {
write_response(output, outputSize, not_implemented());
}
/* read - reads one line (takes no arguments) */
else if (s_function == "read") {
string data = mapManager->read(); // reads the current line
write_response(output, outputSize, data);
}
/* close - closes the current opened file (takes no arguments) */
else if (s_function == "close") {
mapManager->close();
write_response(output, outputSize, "[true]");
}
/* Report a version to ARMA so scripts can detect our presence */
else if (s_function == "version") {
write_response(output, outputSize, PLUGIN_VERSION);
}
else if (s_function == "datetime") {
write_response(output, outputSize, MultiPlatform::getDate());
}
else {
/* Format of function should be function name;data*/
string function_ = s_function.substr(0, s_function.find(';'));
string data = s_function.substr(s_function.find(';') + 1, s_function.length());
/* open - opens a file or creates one if it doesnt exist */
if (function_ == "openRead") {
if (mapManager->openRead(data) == 0)
write_response(output, outputSize, "[true]");
else
write_response(output, outputSize, "[false]");
}
if (function_ == "openWrite") {
if (mapManager->openWrite(data) == 0)
write_response(output, outputSize, "[true]");
else
write_response(output, outputSize, "[false]");
}
/* write - appends a line to the current opened file */
else if (function_ == "write") {
if (mapManager->write(data) == 0)
write_response(output, outputSize, "[true]");
else
write_response(output, outputSize, "[false]");
}
/* delete - deletes a file */
else if (function_ == "delete") {
write_response(output, outputSize, not_implemented());
}
else {
/* Bad call. return an empty SQF array */
write_response(output, outputSize, not_implemented());
}
}
}