EXPORT int String_ReplaceText(ScriptString& str, ScriptString& text, ScriptString& replacement) { int size=text.length(); if(!size) return 0; int size_rep=replacement.length(); string st=str.c_std_str(); int pos=st.find(text.c_std_str(),0); int num=0; while(pos>=0) { st.replace(pos,size,replacement.c_std_str()); pos=st.find(text.c_std_str(),pos+size_rep); num++; } str=st; return num; }
// todo: remove and replace with fonline-provided callers EXPORT void RunScript(const ScriptString& scriptfunc, int p0, int p1, int p2, const ScriptString& p3) { int delim = scriptfunc.c_std_str().find("@"); if(delim == -1) return; string modulename = scriptfunc.c_std_str().substr(0, delim); string funcname = scriptfunc.c_std_str().substr(delim + 1); asIScriptModule* module = ASEngine->GetModule(modulename.c_str()); if(!module) return; asIScriptFunction* script_func = module->GetFunctionByName(funcname.c_str()); if(!script_func) return; asIScriptContext* ctx = ASEngine->CreateContext(); ctx->Prepare(script_func); ctx->SetArgDWord(0, p0); ctx->SetArgDWord(1, p1); ctx->SetArgDWord(2, p2); ctx->SetArgObject(3, (void*)&p3); ctx->Execute(); ctx->Release(); }
bool ParseLocalScriptName( const ScriptString& scriptfunc, string& module, string& function ) { int pos = scriptfunc.c_std_str().find_first_of( "@" ); if( pos > 0 ) { string moduleName = scriptfunc.c_std_str().substr( 0, pos ); string functionDecl = "void "; functionDecl += scriptfunc.c_std_str().substr( pos + 1 ); #if defined(__CLIENT) functionDecl += "(int,int,int,string@,int[]@)"; #elif defined(__SERVER) functionDecl += "(Critter&,int,int,int,string@,int[]@)"; #endif module = moduleName; function = functionDecl; return( true ); } else return( false ); }