eomnibot_error Omnibot_LoadLibrary(int version, const char *lib, const char *path)
{
	eomnibot_error r = BOT_ERROR_NONE;
	g_BotLibrary = Omnibot_LL(OB_VA("%s/%s.so", path ? path : ".", lib));
	if(!g_BotLibrary)
	{
		g_BotLibrary = Omnibot_LL(OB_VA("./%s.so", lib));
	}
	if(!g_BotLibrary)
	{
		char *homeDir = getenv("HOME");
		if(homeDir)
			g_BotLibrary = Omnibot_LL(OB_VA("%s/omni-bot/%s.so", homeDir, lib));
	}
	if(!g_BotLibrary)
	{
		char *homeDir = getenv("HOME");
		if(homeDir)
			g_BotLibrary = Omnibot_LL(OB_VA("%s.so", lib));
	}
	if(!g_BotLibrary)
	{
		g_OmnibotLibPath.clear();
		r = BOT_ERROR_CANTLOADDLL;
	}
	else
	{
		Omnibot_Load_PrintMsg(OB_VA("Found Omni-bot: %s, Attempting to Initialize", g_OmnibotLibPath.c_str()));
		pfnGetFunctionsFromDLL pfnGetBotFuncs = 0;
		memset(&g_BotFunctions, 0, sizeof(g_BotFunctions));
		pfnGetBotFuncs = (pfnGetFunctionsFromDLL)GetProcAddress(g_BotLibrary, "ExportBotFunctionsFromDLL");
		if(!pfnGetBotFuncs)
		{
			r = BOT_ERROR_CANTGETBOTFUNCTIONS;
			Omnibot_Load_PrintErr(OB_VA("Omni-bot Failed with Error: %s", Omnibot_ErrorString(r)));
			OB_ShowLastError("GetProcAddress", dlerror());
		}
		else
		{
			r = pfnGetBotFuncs(&g_BotFunctions, sizeof(g_BotFunctions));
			if(r == BOT_ERROR_NONE)
			{
				Omnibot_Load_PrintMsg("Omni-bot Loaded Successfully");
				r = g_BotFunctions.pfnInitialize(g_InterfaceFunctions, version);
				g_IsOmnibotLoaded = (r == BOT_ERROR_NONE);
			}
		}
	}
	return r;
}
eomnibot_error Omnibot_LoadLibrary(int version, const char *lib, const char *path)
{
	eomnibot_error r = BOT_ERROR_NONE;
	g_BotLibrary = Omnibot_LL( OB_VA("%s\\%s.dll", path ? path : ".", lib) );
	if(g_BotLibrary == 0)
		g_BotLibrary = Omnibot_LL( OB_VA(".\\omni-bot\\%s.dll", lib) );
	if(g_BotLibrary == 0)
		g_BotLibrary = Omnibot_LL( OB_VA("%s.dll", lib) );
	if(g_BotLibrary == 0)
	{
		g_OmnibotLibPath.clear();
		r = BOT_ERROR_CANTLOADDLL;
	}
	else
	{
		Omnibot_Load_PrintMsg(OB_VA("Found Omni-bot: %s, Attempting to Initialize", g_OmnibotLibPath.c_str()));
		pfnGetFunctionsFromDLL pfnGetBotFuncs = 0;
		memset(&g_BotFunctions, 0, sizeof(g_BotFunctions));
		pfnGetBotFuncs = (pfnGetFunctionsFromDLL)GetProcAddress(g_BotLibrary, "ExportBotFunctionsFromDLL");
		if(pfnGetBotFuncs == 0)
		{
			r = BOT_ERROR_CANTGETBOTFUNCTIONS;
			Omnibot_Load_PrintErr(OB_VA("Omni-bot Failed with Error: %s", Omnibot_ErrorString(r)));
		}
		else
		{
			r = pfnGetBotFuncs(&g_BotFunctions, sizeof(g_BotFunctions));
			if(r == BOT_ERROR_NONE)
			{
				Omnibot_Load_PrintMsg("Omni-bot Loaded Successfully");
				r = g_BotFunctions.pfnInitialize(g_InterfaceFunctions, version);
				g_IsOmnibotLoaded = (r == BOT_ERROR_NONE);
			}

			// cs: removed else so interface errors can be printed
			if (r != BOT_ERROR_NONE)
			{
				Omnibot_Load_PrintErr(OB_VA("Omni-bot Failed with Error: %s", Omnibot_ErrorString(r)));
				Omnibot_FreeLibrary();
			}
		}
	}
	return r;
}
Exemple #3
0
/**
 * @brief Omnibot_LoadLibrary
 * @param[in] version
 * @param[in] lib
 * @param[in] path
 * @return
 */
eomnibot_error Omnibot_LoadLibrary(int version, const char *lib, const char *path)
{
	eomnibot_error r = BOT_ERROR_NONE;

#ifdef WIN32
#ifdef _WIN64
#define SUFFIX "_x64"
#else
#define SUFFIX
#endif
	g_BotLibrary = Omnibot_LL(OB_VA("%s\\%s" SUFFIX ".dll", path ? path : ".", lib));
	if (g_BotLibrary == 0)
	{
		g_BotLibrary = Omnibot_LL(OB_VA(".\\omni-bot\\%s" SUFFIX ".dll", lib));
	}
	if (g_BotLibrary == 0)
	{
		g_BotLibrary = Omnibot_LL(OB_VA("%s" SUFFIX ".dll", lib));
	}

#else
#ifdef __x86_64__
#define SUFFIX ".x86_64"
#else
#define SUFFIX
#endif
	g_BotLibrary = Omnibot_LL(OB_VA("%s/%s" SUFFIX ".so", path ? path : ".", lib));
	if (!g_BotLibrary)
	{
		g_BotLibrary = Omnibot_LL(OB_VA("./%s" SUFFIX ".so", lib));
	}
	if (!g_BotLibrary)
	{
		char *homeDir = getenv("HOME");
		if (homeDir)
		{
			g_BotLibrary = Omnibot_LL(OB_VA("%s/omni-bot/%s" SUFFIX ".so", homeDir, lib));
		}
	}
	if (!g_BotLibrary)
	{
		g_BotLibrary = Omnibot_LL(OB_VA("%s" SUFFIX ".so", lib));
	}
#endif

	if (g_BotLibrary == 0)
	{
		g_OmnibotLibPath.clear();
		r = BOT_ERROR_CANTLOADDLL;
	}
	else
	{
		Omnibot_Load_PrintMsg(OB_VA("Found Omni-bot: %s, Attempting to Initialize", g_OmnibotLibPath.c_str()));
		pfnGetFunctionsFromDLL pfnGetBotFuncs = 0;
		memset(&g_BotFunctions, 0, sizeof(g_BotFunctions));
		pfnGetBotFuncs = (pfnGetFunctionsFromDLL)GetProcAddress(g_BotLibrary, "ExportBotFunctionsFromDLL");
		if (pfnGetBotFuncs == 0)
		{
			r = BOT_ERROR_CANTGETBOTFUNCTIONS;
			OB_ShowLastError("GetProcAddress");
		}
		else
		{
			r = pfnGetBotFuncs(&g_BotFunctions, sizeof(g_BotFunctions));
			if (r == BOT_ERROR_NONE)
			{
				r = g_BotFunctions.pfnInitialize(g_InterfaceFunctions, version);
			}
		}
		g_IsOmnibotLoaded = (r == BOT_ERROR_NONE);
		if (g_IsOmnibotLoaded)
		{
			Omnibot_Load_PrintMsg("Omni-bot Loaded Successfully");
		}
		else
		{
			Omnibot_Load_PrintErr(OB_VA("Omni-bot Failed with Error: %s", Omnibot_ErrorString(r)));
			Omnibot_FreeLibrary();
		}
	}
	return r;
}