| 365 | |
| 366 | #ifdef CC_BUILD_PLUGINS |
| 367 | static void LoadPlugin(const cc_string* path, void* obj, int isDirectory) { |
| 368 | void* lib; |
| 369 | void* verSym; /* EXPORT int Plugin_ApiVersion = GAME_API_VER; */ |
| 370 | void* compSym; /* EXPORT struct IGameComponent Plugin_Component = { (whatever) } */ |
| 371 | int ver; |
| 372 | if (isDirectory) return; |
| 373 | |
| 374 | /* ignore accepted.txt, deskop.ini, .pdb files, etc */ |
| 375 | if (!String_CaselessEnds(path, &DynamicLib_Ext)) return; |
| 376 | /* don't try to load 32 bit plugins on 64 bit OS or vice versa */ |
| 377 | if (sizeof(void*) == 4 && String_ContainsConst(path, "_64.")) return; |
| 378 | if (sizeof(void*) == 8 && String_ContainsConst(path, "_32.")) return; |
| 379 | |
| 380 | lib = DynamicLib_Load2(path); |
| 381 | if (!lib) { Logger_DynamicLibWarn("loading", path); return; } |
| 382 | |
| 383 | verSym = DynamicLib_Get2(lib, "Plugin_ApiVersion"); |
| 384 | if (!verSym) { Logger_DynamicLibWarn("getting version of", path); return; } |
| 385 | compSym = DynamicLib_Get2(lib, "Plugin_Component"); |
| 386 | if (!compSym) { Logger_DynamicLibWarn("initing", path); return; } |
| 387 | |
| 388 | ver = *((int*)verSym); |
| 389 | if (ver < GAME_API_VER) { |
| 390 | Chat_Add1("&c%s plugin is outdated! Try getting a more recent version.", path); |
| 391 | return; |
| 392 | } else if (ver > GAME_API_VER) { |
| 393 | Chat_Add1("&cYour game is too outdated to use %s plugin! Try updating it.", path); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | Game_AddComponent((struct IGameComponent*)compSym); |
| 398 | } |
| 399 | |
| 400 | static void LoadPlugins(void) { |
| 401 | static const cc_string dir = String_FromConst("plugins"); |
nothing calls this directly
no test coverage detected