"bot library used before being setup", post-callback

Locked
coffeenet
Posts: 29
Joined: Mon Jan 10, 2011 6:05 am

"bot library used before being setup", post-callback

Post by coffeenet »

Hello,

Environment:
WindowsXP, Visual Studio 2008 professional edition.

Background:
* Sometime ago, I asked about removing the trap_ functionality from the program. Some of the people on this list kindly recommended me to bind the sdk with the engine into one binary. At first, I didn't know how to do that. But, after further investigation, it meant to mash all the files into one project (projects are five in ioquake3- cgame, game, ui_q3, quake3, ui) inside Visual Studio.
* I have started doing this. Now, I have moved the botlib folder (not windows explorer one, but the visual studio one.) from quake3 to game. This means that the botlib files (which includes the functions and variables in those files) used to exist inside ioquake3.exe, and now they exist inside qagamex86.dll file.
* A function called SV_BotInitBotLib() that exists inside the quake3 folder (ioquake3.exe). This function calls to a function called GetBotLibAPI(). GetBotLibAPI() exists inside qagamex86.dll (after my alteration).
** Therefore, SV_BotInitBotLib() is calling to an external symbol, it is calling to function outside ioquake.exe.
*** This is the compiling error that I have battled with the past week.

Trialed solutions:
1- Using __declspec(dllexport) and __declspec(dllimport):
* I have attempted to export/import this external symbol, GetBotLibAPI() from qagamex86.dll, SV_BotInitBotLib() to ioquake3.exe.
* This has silenced the compiler.
* This also has allowed the Game to launch without any errors.
** However, when I go into Single Game, an message in red appears continuously in the upper part of the screen that reads "bot library used before being setup".
** Furthermore, I cannot add any bots to the match.

2- Creating a callback function of GetBotLibAPI() - My preferred solution:
* Probably the code could explain this basic concept, here is the code snippets:
inside sv_bot.c file, inside ioquake3.exe:

Code: Select all

    func_GetBotLibAPI pGetBotLibAPI;
    HMODULE hLib;
void SV_BotInitBotLib(void) {
    botlib_import_t    botlib_import;
    //func_GetBotLibAPI pGetBotLibAPI;
    /*HMODULE */hLib = LoadLibrary(TEXT("qagamex86.dll"));

    if (hLib == NULL) {
        //Module not found, permission denied, ...
        return; //inform caller of error
    }

    pGetBotLibAPI = (func_GetBotLibAPI)GetProcAddress(hLib, TEXT("GetBotLibAPI"));//zgzg2020 for importing a function from an external library
    if ( pGetBotLibAPI == NULL) {
        //Function not found: try adding an _ to the start of the name
        ErrorExit(TEXT("GetProcessId"));
        return;
    }

    //unchanged
    //lines
    //of
    //code

    botlib_export = zgCBGetBotLibAPI(pGetBotLibAPI, BOTLIB_API_VERSION, &botlib_import);//zgzg2020
    //botlib_export = (botlib_export_t *)GetBotLibAPI( BOTLIB_API_VERSION, &botlib_import ); // the original function
    assert(botlib_export);     // somehow we end up with a zero import.
}

//zgzg2020 callback function
//This function has nothing that can change at runtime, hence a call to it can be placed inline.
//This effectively gets rid of this function and puts its code in the calling function. (not strictly true, but a simplified explanation)
botlib_export_t *zgCBGetBotLibAPI( func_GetBotLibAPI pzgCBGetBotLibAPI, int apiVersion, botlib_import_t *import ) {
////We just use the function variable as we would use any other function.
    return pzgCBGetBotLibAPI(apiVersion, import);
}
////
inside botlib.h, shared by both ioquake3.exe and qagamex86.dll:

Code: Select all

//We need to create a data type that defines the signature of the function GetBotLibAPI
typedef botlib_export_t *(* func_GetBotLibAPI)(int apiVersion, botlib_import_t *import);
 botlib_export_t *zgCBGetBotLibAPI( func_GetBotLibAPI pzgCBGetBotLibAPI, int apiVersion, botlib_import_t *import );
////
inside be_interface.c

Code: Select all

#define _DLLEXPORT __declspec(dllexport)// we need to export so that this function can be seen and be accessible from the outside of qagamex86.dll, where it resides, from ioquake3.exe
_DLLEXPORT botlib_export_t *GetBotLibAPI(int apiVersion, botlib_import_t *import) {//using define to avoid function name manipulations
//The code is as is, untouched.
}
* Now that all of this is out of the way, the results.
* The Compilation is successful.
* The Game launches successfully.
* However, when I run Single Game, for example, the same error as before. The error is:
** However, when I go into Single Game, a message in red appears continuously in the upper part of the screen that reads "bot library used before being setup".
** Furthermore, I cannot add any bots to the match.

-This is the current situation that I am in. This is where I need help.
# Why does this message appear?
# I take the reason why I cannot add bots is because it has not been setup yet.
* However, I have debugged the Game:
** I ran my version of the Game, with the callback. I followed the flow of the program up to where SV_BotInitBotLib() ends.
** I then ran an original version of the Game, without the callback, they both flows look the same. Furthermore, both versions of the botlib_export variables look the exactly the same in terms of contents and shape. (botlib_export is the variable that is retrieved from the callback function)
** Moreover, I have attempted to perform "step-in" at the location where callback function is called, and it successfully jumps to its location in the be_interface.c, from ioquake3.exe to inside qagamex86.dll.

# This is just the beginning of many changes to the program that I attempt on doing.
# Callback functions will be the backbone of my near future work. So, I will need to leave in there.
# The reasons for wanting to do this are very important for me, but too difficult to explain here. Therefore, I would appreciate it if it would be taken as such.
# Please help. How can I fix this bot library initialization problem with the usage of callback functions.

p.s. I mailed this to the mailing list as well, but I felt it was a good enough explanation of my problem, so I was hoping for extra help with it here too. Sorry for cross posting.
User avatar
MKJ
Posts: 32582
Joined: Fri Nov 24, 2000 8:00 am

Re: "bot library used before being setup", post-callback

Post by MKJ »

the good people of Programming Discussion can help you with this.
Locked