/* bbexit - return tree for _epilogue(&afunc)' */ static void bbexit(Symbol yylink, Symbol f, Tree e) { static Symbol epilogue; if (epilogue == 0) { epilogue = mksymbol(EXTERN, "_epilogue", ftype(inttype, voidptype)); epilogue->defined = 0; } walk(vcall(epilogue, voidtype, pointer(idtree(afunc)), NULL), 0, 0); }
/* bbentry - return tree for _prologue(&afunc, &YYlink)' */ static void bbentry(Symbol yylink, Symbol f) { static Symbol prologue; afunc = genident(STATIC, array(voidptype, 4, 0), GLOBAL); if (prologue == 0) { prologue = mksymbol(EXTERN, "_prologue", ftype(inttype, voidptype)); prologue->defined = 0; } walk(vcall(prologue, voidtype, pointer(idtree(afunc)), pointer(idtree(yylink)), NULL), 0, 0); }
/* point_hook - called at each execution point */ static void point_hook(void *cl, Coordinate *cp, Tree *e) { Tree t; /* add breakpoint test to *e: (_Nub_bpflags[i] != 0 && _Nub_bp(i), *e) */ t = tree(AND, voidtype, (*optree[NEQ])(NE, rvalue((*optree['+'])(ADD, pointer(idtree(nub_bpflags)), cnsttree(inttype, Seq_length(pickle->spoints)))), cnsttree(inttype, 0L)), vcall(nub_bp, voidtype, cnsttree(inttype, Seq_length(pickle->spoints)), NULL)); if (*e) *e = tree(RIGHT, (*e)->type, t, *e); else *e = t; Seq_addhi(pickle->spoints, sym_spoint(sym_coordinate(cp->file ? cp->file : string(""), cp->x, cp->y), tail())); }
void ScriptMgr::LoadScripts() { if(HookInterface::getSingletonPtr() == NULL) new HookInterface; Log.Success("Server", "Loading External Script Libraries..."); std::string Path; std::string FileMask; Path = PREFIX; Path += '/'; #ifdef WIN32 /*Path = Config.MainConfig.GetStringDefault( "Script", "BinaryLocation", "script_bin" ); Path += "\\";*/ FileMask = ".dll"; #else #ifndef __APPLE__ FileMask = ".so"; #else FileMask = ".dylib"; #endif #endif Arcpro::FindFilesResult findres; std::vector< ScriptingEngine_dl > Engines; Arcpro::FindFiles(Path.c_str(), FileMask.c_str(), findres); uint32 count = 0; while(findres.HasNext()) { std::stringstream loadmessage; std::string fname = Path + findres.GetNext(); Arcpro::DynLib* dl = new Arcpro::DynLib(fname.c_str()); loadmessage << " " << dl->GetName() << " : "; if(!dl->Load()) { loadmessage << "ERROR: Cannot open library."; LOG_ERROR(loadmessage.str().c_str()); delete dl; continue; } else { exp_get_version vcall = reinterpret_cast< exp_get_version >(dl->GetAddressForSymbol("_exp_get_version")); exp_script_register rcall = reinterpret_cast< exp_script_register >(dl->GetAddressForSymbol("_exp_script_register")); exp_get_script_type scall = reinterpret_cast< exp_get_script_type >(dl->GetAddressForSymbol("_exp_get_script_type")); if((vcall == NULL) || (rcall == NULL) || (scall == NULL)) { loadmessage << "ERROR: Cannot find version functions."; LOG_ERROR(loadmessage.str().c_str()); delete dl; continue; } else { const char *version = vcall(); uint32 stype = scall(); if( strcmp( version, BUILD_HASH_STR ) != 0 ) { loadmessage << "ERROR: Version mismatch."; LOG_ERROR(loadmessage.str().c_str()); delete dl; continue; } else { loadmessage << ' ' << std::string( BUILD_HASH_STR ) << " : "; if((stype & SCRIPT_TYPE_SCRIPT_ENGINE) != 0) { ScriptingEngine_dl se; se.dl = dl; se.InitializeCall = rcall; se.Type = stype; Engines.push_back(se); loadmessage << "delayed load"; } else { rcall(this); dynamiclibs.push_back(dl); loadmessage << "loaded"; } LOG_BASIC(loadmessage.str().c_str()); count++; } } } } if(count == 0) { LOG_ERROR(" No external scripts found! Server will continue to function with limited functionality."); } else { Log.Success("Server", "Loaded %u external libraries.", count); Log.Success("Server", "Loading optional scripting engine(s)..."); for(std::vector< ScriptingEngine_dl >::iterator itr = Engines.begin(); itr != Engines.end(); ++itr) { itr->InitializeCall(this); dynamiclibs.push_back(itr->dl); } Log.Success("Server", "Done loading scripting engine(s)..."); } }
void SystemManager::Init() { /* Loading system for win32 */ #ifdef WIN32 string search_path = "./Plugins/*.dll"; WIN32_FIND_DATA data; uint32 count = 0; HANDLE find_handle = FindFirstFile( search_path.c_str(), &data ); if(find_handle == INVALID_HANDLE_VALUE) WriteConsole("No external scripts found." ); else { do { string full_path = data.cFileName; HMODULE mod = LoadLibrary( full_path.c_str() ); if( mod == 0 ) printf("Loading %s failed, crc=0x%p\r\n", data.cFileName, reinterpret_cast< uint32* >( mod )); else { // find version import exp_get_version vcall = (exp_get_version)GetProcAddress(mod, "_exp_get_version"); exp_script_update ucall = (exp_script_update)GetProcAddress(mod, "_exp_script_update"); exp_script_register rcall = (exp_script_register)GetProcAddress(mod, "_exp_script_register"); exp_get_script_type scall = (exp_get_script_type)GetProcAddress(mod, "_exp_get_script_type"); if(vcall == 0 || rcall == 0 || scall == 0 || ucall == 0) { printf("Loading %s failed, version info not found\r\n", data.cFileName); FreeLibrary(mod); } else { uint32 version = vcall(); uint32 stype = scall(); uint32 versionhigh = SCRIPTLIB_HIPART(version), versionlow = SCRIPTLIB_LOPART(version); std::stringstream cmsg; cmsg << "Loading " << data.cFileName << ", crc:0x" << reinterpret_cast< uint32* >( mod ); cmsg << ", Version:" << versionhigh << " " << versionlow << " delayed loading."; ScriptDLLs se; se.Handle = mod; se.InitializeCall = rcall; se.UpdateCall = ucall; se.Type = stype; se.highrev = versionhigh; se.lowrev = versionlow; DLLScriptVector.push_back( se ); WriteConsole(cmsg.str()); ++count; } } }while(FindNextFile(find_handle, &data)); FindClose(find_handle); printf("Loading %u external libraries.\r\n", count); for(vector<ScriptDLLs>::iterator itr = DLLScriptVector.begin(); itr != DLLScriptVector.end(); itr++) (*itr).InitializeCall(this); } #else /* Loading system for *nix */ struct dirent ** list; int filecount = scandir(PREFIX "/lib/", &list, 0, 0); uint32 count = 0; if(!filecount || !list || filecount < 0) WriteConsole("No external scripts found."); else { char *ext; while(filecount--) { ext = strrchr(list[filecount]->d_name, '.'); #ifdef HAVE_DARWIN if (ext != NULL && strstr(list[filecount]->d_name, ".0.dylib") == NULL && !strcmp(ext, ".dylib")) { #else if (ext != NULL && !strcmp(ext, ".so")) { #endif string full_path = "../lib/" + string(list[filecount]->d_name); SCRIPT_MODULE mod = dlopen(full_path.c_str(), RTLD_NOW); printf(" %s : 0x%p : ", list[filecount]->d_name, mod); if(mod == 0) printf("error! [%s]\r\n", dlerror()); else { // find version import exp_get_version vcall = (exp_get_version)dlsym(mod, "_exp_get_version"); exp_script_update ucall = (exp_script_update)dlsym(mod, "_exp_script_update"); exp_script_register rcall = (exp_script_register)dlsym(mod, "_exp_script_register"); exp_get_script_type scall = (exp_get_script_type)dlsym(mod, "_exp_get_script_type"); if(vcall == 0 || rcall == 0 || scall == 0 || ucall == 0) { WriteConsole("version functions not found!"); dlclose(mod); } else { int32 version = vcall(); uint32 stype = scall(); uint32 versionhigh = SCRIPTLIB_HIPART(version), versionlow = SCRIPTLIB_LOPART(version); ScriptDLLs se; se.Handle = mod; se.InitializeCall = rcall; se.UpdateCall = ucall; se.Type = stype; se.highrev = versionhigh; se.lowrev = versionlow; DLLScriptVector.push_back( se ); printf("v%u.%u : loaded.\r\n", versionhigh, versionlow); rcall(this); ++count; } } } free(list[filecount]); } free(list); WriteConsole(""); printf("Loaded %u external libraries.", count); WriteConsole(""); WriteConsole("Loading optional scripting engines..."); for(vector<ScriptingEngine>::iterator itr = ScriptEngines.begin(); itr != ScriptEngines.end(); itr++) itr->InitializeCall(this); WriteConsole("Done loading script engines..."); } #endif } void SystemManager::WriteConsole(const char* message) { Console::Write(gcnew System::String(message)+"\r\n"); }
void ScriptMgr::LoadScripts() { if(!HookInterface::getSingletonPtr()) new HookInterface; sLog.outString("Loading External Script Libraries..."); sLog.outString(""); string start_path = Config.MainConfig.GetStringDefault("Script", "BinaryLocation", "script_bin") + "\\"; string search_path = start_path + "*."; /* Loading system for win32 */ #ifdef WIN32 search_path += "dll"; WIN32_FIND_DATA data; uint32 count = 0; HANDLE find_handle = FindFirstFile(search_path.c_str(), &data); if(find_handle == INVALID_HANDLE_VALUE) sLog.outError(" No external scripts found! Server will continue to function with limited functionality."); else { do { string full_path = start_path + data.cFileName; HMODULE mod = LoadLibrary(full_path.c_str()); printf(" %s : 0x%.08X : ", data.cFileName, ((uint32)mod)); if(mod == 0) printf("error!\n"); else { // find version import exp_get_version vcall = (exp_get_version)GetProcAddress(mod, "_exp_get_version"); exp_script_register rcall = (exp_script_register)GetProcAddress(mod, "_exp_script_register"); if(vcall == 0 || rcall == 0) { printf("version functions not found!\n"); FreeLibrary(mod); } else { uint32 version = vcall(); if(UINT32_LOPART(version) == SCRIPTLIB_VERSION_MINOR && UINT32_HIPART(version) == SCRIPTLIB_VERSION_MAJOR) { _handles.push_back(((SCRIPT_MODULE)mod)); printf("v%u.%u : ", UINT32_HIPART(version), UINT32_LOPART(version)); rcall(this); printf("loaded.\n"); ++count; } else { FreeLibrary(mod); printf("version mismatch!\n"); } } } } while(FindNextFile(find_handle, &data)); FindClose(find_handle); sLog.outString(""); sLog.outString("Loaded %u external libraries.", count); sLog.outString(""); } #else /* Loading system for *nix */ struct dirent ** list; int filecount = scandir(PREFIX "/lib/", &list, 0, 0); uint32 count = 0; if(!filecount || !list || filecount < 0) sLog.outError(" No external scripts found! Server will continue to function with limited functionality."); else { char *ext; while(filecount--) { ext = strrchr(list[filecount]->d_name, '.'); if (ext != NULL && !strcmp(ext, ".so")) { string full_path = "../lib/" + string(list[filecount]->d_name); SCRIPT_MODULE mod = dlopen(full_path.c_str(), RTLD_NOW); printf(" %s : 0x%08X : ", list[filecount]->d_name, (unsigned int)mod); if(mod == 0) printf("error! [%s]\n", dlerror()); else { // find version import exp_get_version vcall = (exp_get_version)dlsym(mod, "_exp_get_version"); exp_script_register rcall = (exp_script_register)dlsym(mod, "_exp_script_register"); if(vcall == 0 || rcall == 0) { printf("version functions not found!\n"); dlclose(mod); } else { uint32 version = vcall(); if(UINT32_LOPART(version) == SCRIPTLIB_VERSION_MINOR && UINT32_HIPART(version) == SCRIPTLIB_VERSION_MAJOR) { _handles.push_back(((SCRIPT_MODULE)mod)); printf("v%u.%u : ", UINT32_HIPART(version), UINT32_LOPART(version)); rcall(this); printf("loaded.\n"); ++count; } else { dlclose(mod); printf("version mismatch!\n"); } } } } free(list[filecount]); } free(list); sLog.outString(""); sLog.outString("Loaded %u external libraries.", count); sLog.outString(""); } #endif }