int UnloadPlugin(struct PluginList* q, char** errorMsg) {
    struct NativePluginInfo* pi = (struct NativePluginInfo*)(q->loaderInfo);
    
    int error = 0;
    if (pi != NULL && pi->module) {
        TRY {
            pi->endPlugin(pi->module);
        } EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
            error = error_plugin_crash_on_unload;
        }

        FreeLibrary(pi->module);
        pi->module = NULL;
        
        q->loaderInfo = NULL;
        c_del(pi);
    }
Beispiel #2
0
static void g_Data(dyad_Event *e) {
    FILE *fp;
    char name[20],v[10];
    int ver=c_version();
    sprintf(name,"2048.1.%X.save",ver);
    sprintf(v,"%X",ver);
    if(NULL!=strstr((char*)e->data,v)){
        if((fp=fopen(name,"w+"))) {
            fprintf(fp,"%s",e->data);
        }
        fclose(fp);
        pthread_mutex_lock(&MBoard);
        curs=1;
        c_readFromDisk(1,false);
        pthread_mutex_unlock(&MBoard);
    }else if(memcmp(e->data, "UP", 2)==0){
        pthread_mutex_lock(&MBoard);
		attack[1][attacktimes[1]++]=2;
        curs=0;
        Eat(EUP);GetRandNums();
        pthread_mutex_unlock(&MBoard);
		pthread_cond_signal(&CNet);
	}else if(memcmp(e->data, "DOWN", 4)==0){
        pthread_mutex_lock(&MBoard);
		attack[1][attacktimes[1]++]=3;
        curs=0;
        Eat(EDOWN);GetRandNums();
        pthread_mutex_unlock(&MBoard);
		pthread_cond_signal(&CNet);
	}else if(memcmp(e->data, "LEFT", 4)==0){
        pthread_mutex_lock(&MBoard);
		attack[1][attacktimes[1]++]=4;
        curs=0;
        Eat(ELEFT);GetRandNums();
        pthread_mutex_unlock(&MBoard);
		pthread_cond_signal(&CNet);
	}else if(memcmp(e->data, "RIGHT", 5)==0){
        pthread_mutex_lock(&MBoard);
		attack[1][attacktimes[1]++]=5;
        curs=0;
        Eat(ERIGHT);GetRandNums();
        pthread_mutex_unlock(&MBoard);
		pthread_cond_signal(&CNet);
	}else if(memcmp(e->data, "BOOM", 4)==0){
        pthread_mutex_lock(&MBoard);
		attack[1][attacktimes[1]++]=6;
        curs=0;
        int y,x;
		if(sscanf(e->data,"BOOM %d %d",&y,&x)==2){
			c_boom(y,x);
		}
        pthread_mutex_unlock(&MBoard);
		pthread_cond_signal(&CNet);
	}else if(memcmp(e->data, "DEL", 3)==0){
        pthread_mutex_lock(&MBoard);
		attack[1][attacktimes[1]++]=1;
        curs=0;
        int y,x;
		if(sscanf(e->data,"DEL %d %d",&y,&x)==2){
			c_del(y,x);
		}
        pthread_mutex_unlock(&MBoard);
		pthread_cond_signal(&CNet);
	}
    pthread_cond_signal(&CBoard);
}
int LoadPlugin(struct PluginList* q, HWND hSlit, char** errorMsg) {
    struct NativePluginInfo* pInfo = c_new(struct NativePluginInfo);
    int error = 0;
    bool useslit;
    int r;
    char plugin_path[MAX_PATH];

    for (;;)
    {
        //---------------------------------------
        // load the dll
        if (0 == FindRCFile(plugin_path, q->path, NULL)) {
            error = error_plugin_dll_not_found;
            break;
        }

        r = SetErrorMode(0); // enable 'missing xxx.dll' system message
        pInfo->module = LoadLibrary(plugin_path);
        SetErrorMode(r);

        if (NULL == pInfo->module)
        {
            r = GetLastError();
            // char buff[200]; win_error(buff, sizeof buff);
            // dbg_printf("LoadLibrary::GetLastError %d: %s", r, buff);
            if (ERROR_MOD_NOT_FOUND == r)
                error = error_plugin_dll_needs_module;
            else
                error = error_plugin_does_not_load;
            break;
        }

        //---------------------------------------
        // grab interface functions
        LoadFunction(pInfo, beginPlugin);
        LoadFunction(pInfo, beginPluginEx);
        LoadFunction(pInfo, beginSlitPlugin);
        LoadFunction(pInfo, endPlugin);
        LoadFunction(pInfo, pluginInfo);

        //---------------------------------------
        // check interfaces
        if(!pInfo->endPlugin)
            BreakWithCode(error, error_plugin_missing_entry);
        
        // check whether plugin supports the slit
        q->canUseSlit = !!pInfo->beginPluginEx || !!pInfo->beginSlitPlugin;
        
        if(!q->canUseSlit)
            q->useSlit = false;

        useslit = hSlit && q->useSlit;

        if (!useslit && !pInfo->beginPluginEx && !pInfo->beginPlugin)
            BreakWithCode(error, error_plugin_missing_entry);

        //---------------------------------------
        // inititalize plugin
        TRY
        {
            if (useslit) {
                if (pInfo->beginPluginEx)
                    r = pInfo->beginPluginEx(pInfo->module, hSlit);
                else
                    r = pInfo->beginSlitPlugin(pInfo->module, hSlit);
            } else {
                if (pInfo->beginPlugin)
                    r = pInfo->beginPlugin(pInfo->module);
                else
                    r = pInfo->beginPluginEx(pInfo->module, NULL);
            }

            if (BEGINPLUGIN_OK == r) {
                q->loaderInfo = pInfo;
                q->inSlit = useslit;
            } else if (BEGINPLUGIN_FAILED_QUIET != r) {
                error = error_plugin_fail_to_load;
            }

        }
        EXCEPT(EXCEPTION_EXECUTE_HANDLER)
        {
            error = error_plugin_crash_on_load;
        }
        break;
    }

    // clean up after error
    if(error) {
        if (pInfo->module)
            FreeLibrary(pInfo->module);

        q->loaderInfo = NULL;
        c_del(pInfo);
    }

    return error;
}