20 #if defined(__NetBSD__) || defined(__OpenBSD__)
21 #include <sys/param.h>
28 #include <sys/types.h>
31 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
32 #include <SDL_syswm.h>
42 MumbleManager *mumbleManager =
nullptr;
45 MumbleManager::MumbleManager() :
49 mMapBase[0] = mMapBase[1] = mMapBase[2] = 0.;
53 MumbleManager::~MumbleManager()
58 UnmapViewOfFile(mLinkedMem);
62 munmap(mLinkedMem,
sizeof(LinkedMem));
69 uint16_t MumbleManager::getMapId(std::string mapName)
72 if (mapName.size() != 5 || mapName[3] !=
'-')
78 mapName = mapName.substr(0, 3) + mapName[4];
79 res =
CAST_U16(atoi(mapName.c_str()));
84 void MumbleManager::setMapBase(uint16_t mapid)
86 mMapBase[0] = 10000.0F * (mapid & 0x1F);
88 mMapBase[1] = 1000.0F * (mapid & 0x3F);
90 mMapBase[2] = 10000.0F * (mapid & 0x1F);
104 HANDLE hMapObject = OpenFileMappingW(FILE_MAP_ALL_ACCESS,
105 FALSE, L
"MumbleLink");
108 logger->
log1(
"MumbleManager::init can't open MumbleLink");
112 mLinkedMem =
reinterpret_cast<LinkedMem *
>(MapViewOfFile(hMapObject,
113 FILE_MAP_ALL_ACCESS, 0, 0,
sizeof(LinkedMem)));
117 CloseHandle(hMapObject);
118 hMapObject =
nullptr;
119 logger->
log1(
"MumbleManager::init can't map MumbleLink");
126 snprintf(memName,
sizeof(memName),
"/MumbleLink.%u", getuid());
128 const int shmfd = shm_open(memName, O_RDWR, S_IRUSR | S_IWUSR);
133 " open shared memory MumbleLink");
137 mLinkedMem =
static_cast<LinkedMem *
>(mmap(
nullptr,
138 sizeof(LinkedMem), PROT_READ | PROT_WRITE,
139 MAP_SHARED, shmfd, 0));
141 if (mLinkedMem ==
reinterpret_cast<void *
>(-1))
143 mLinkedMem =
nullptr;
144 logger->
log1(
"MumbleManager::init can't map MumbleLink");
150 wcsncpy(mLinkedMemCache.name, L
"ManaPlus", 256);
151 wcsncpy(mLinkedMemCache.description, L
"ManaPlus Plugin", 2048);
152 mLinkedMemCache.uiVersion = 2;
164 mLinkedMemCache.fAvatarFront[1] = 0.0F;
169 mLinkedMemCache.fAvatarTop[0] = 0.0F;
170 mLinkedMemCache.fAvatarTop[1] = 1.0F;
171 mLinkedMemCache.fAvatarTop[2] = 0.0F;
173 mLinkedMemCache.fCameraFront[0] = 0.0F;
174 mLinkedMemCache.fCameraFront[1] = 0.0F;
175 mLinkedMemCache.fCameraFront[2] = 1.0F;
177 mLinkedMemCache.fCameraTop[0] = 0.0F;
178 mLinkedMemCache.fCameraTop[1] = 1.0F;
179 mLinkedMemCache.fCameraTop[2] = 0.0F;
181 mLinkedMemCache.uiTick++;
184 void MumbleManager::setPlayer(
const std::string &userName)
191 mbstowcs(mLinkedMemCache.identity, userName.c_str(), 256);
192 mLinkedMemCache.uiTick ++;
194 PRAGMA8(GCC diagnostic ignored
"-Wclass-memaccess")
195 memcpy(mLinkedMem, &mLinkedMemCache,
sizeof(mLinkedMemCache));
199 void MumbleManager::setAction(
const int action)
210 mLinkedMemCache.fAvatarPosition[1] = 1.5F;
213 mLinkedMemCache.fAvatarPosition[1] = 1.0F;
217 mLinkedMemCache.fAvatarPosition[1] = 0.0F;
220 mLinkedMemCache.fAvatarPosition[1] += mMapBase[1];
221 mLinkedMemCache.fCameraPosition[1] = mLinkedMemCache.fAvatarPosition[1];
223 mLinkedMemCache.uiTick++;
225 PRAGMA8(GCC diagnostic ignored
"-Wclass-memaccess")
226 memcpy(mLinkedMem, &mLinkedMemCache,
sizeof(mLinkedMemCache));
230 void MumbleManager::setPos(
const int tileX,
const int tileY,
240 mLinkedMemCache.fAvatarPosition[0] =
static_cast<float>(tileX)
242 mLinkedMemCache.fAvatarPosition[2] =
static_cast<float>(tileY)
249 mLinkedMemCache.fCameraPosition[0] = mLinkedMemCache.fAvatarPosition[0];
250 mLinkedMemCache.fCameraPosition[2] = mLinkedMemCache.fAvatarPosition[2];
257 mLinkedMemCache.fAvatarFront[0] = 0.0F;
258 mLinkedMemCache.fAvatarFront[2] = 1.0F;
261 mLinkedMemCache.fAvatarFront[0] = 0.0F;
262 mLinkedMemCache.fAvatarFront[2] = -1.0F;
265 mLinkedMemCache.fAvatarFront[0] = 1.0F;
266 mLinkedMemCache.fAvatarFront[2] = 0.0F;
269 mLinkedMemCache.fAvatarFront[0] = -1.0F;
270 mLinkedMemCache.fAvatarFront[2] = 0.0F;
276 mLinkedMemCache.uiTick ++;
278 PRAGMA8(GCC diagnostic ignored
"-Wclass-memaccess")
279 memcpy(mLinkedMem, &mLinkedMemCache,
sizeof(mLinkedMemCache));
283 void MumbleManager::setMap(
const std::string &mapName)
292 setMapBase(getMapId(mapName));
296 void MumbleManager::setServer(
const std::string &serverName)
302 if (
size >
sizeof(mLinkedMemCache.context) - 1)
303 size =
sizeof(mLinkedMemCache.context) - 1;
305 memset(mLinkedMemCache.context, 0,
sizeof(mLinkedMemCache.context));
307 PRAGMA8(GCC diagnostic ignored
"-Wclass-memaccess")
308 memcpy(mLinkedMemCache.context, serverName.c_str(),
size);
310 mLinkedMemCache.context[
size] =
'\0';
311 mLinkedMemCache.context_len =
size;
312 mLinkedMemCache.uiTick ++;
314 PRAGMA8(GCC diagnostic ignored
"-Wclass-memaccess")
315 memcpy(mLinkedMem, &mLinkedMemCache,
sizeof(mLinkedMemCache));
bool getBoolValue(const std::string &key) const
void log1(const char *const log_text)
uint16_t getCrc16(const std::string &str)