void CGamemodeManager::Unload() { for( _PlayerID playerid = 0; playerid < MAX_PLAYERS; playerid ++ ) { if( __NetGame->playerPool->GetSlotState( playerid ) ) { __NetGame->playerPool->GetPlayer( playerid )->GetKeyBinder()->OnGameModeUnloaded(); } } int tmp; if (!amx_FindPublic(&this->gmAMX, "OnGameModeExit", &tmp)) amx_Exec(&this->gmAMX, (cell*)&tmp, tmp); __NetGame->filterscriptsManager->OnGameModeExit(); if(__NetGame->scriptTimerManager) __NetGame->scriptTimerManager->DeleteForMode(&this->gmAMX); if (this->gmIsInit) { aux_FreeProgram(&this->gmAMX); __Plugins->DoAmxUnload(&this->gmAMX); amx_sampDbCleanup(&this->gmAMX); //amx_DGramCleanup(&this->gmAMX); amx_TimeCleanup(&this->gmAMX); amx_FileCleanup(&this->gmAMX); amx_StringCleanup(&this->gmAMX); amx_FloatCleanup(&this->gmAMX); amx_CoreCleanup(&this->gmAMX); } this->gmIsInit = false; this->gmIsSleeping = false; }
int main(int argc,char *argv[]) { extern int amx_ConsoleInit(AMX *amx); extern int amx_ConsoleCleanup(AMX *amx); extern int amx_CoreInit(AMX *amx); extern int amx_CoredCleanp(AMX *amx); size_t memsize; void *program; AMX amx; int index, err; cell amx_addr, *phys_addr; char output[128]; if (argc != 4) PrintUsage(argv[0]); if ((memsize = aux_ProgramSize(argv[1])) == 0) PrintUsage(argv[0]); program = malloc(memsize); if (program == NULL) ErrorExit(NULL, AMX_ERR_MEMORY); err = aux_LoadProgram(&amx, argv[1], program); if (err) ErrorExit(&amx, err); amx_ConsoleInit(amx); err = amx_CoreInit(amx); if (err) ErrorExit(&amx, err); err = amx_FindPublic(&amx, argv[2], &index); if (err) ErrorExit(&amx, err); err = amx_Allot(&amx, strlen(argv[3]) + 1, &amx_addr, &phys_addr); if (err) ErrorExit(&amx, err); amx_SetString(phys_addr, argv[3], 0); err = amx_Exec(&amx, NULL, index, 1, amx_addr); if (err) ErrorExit(&amx, err); amx_GetString(output, phys_addr); amx_Release(&amx, amx_addr); printf("%s returns %s\n", argv[1], output); amx_ConsoleCleanup(&amx); amx_CoreCleanup(&amx); amx_Cleanup(&amx); free(program); return 0; }
int main(int argc, char *argv[]) { size_t memsize; void *program; AMX amx; cell ret = 0; int err; if (argc != 2 || (memsize = aux_ProgramSize(argv[1])) == 0) ErrorExit("Usage: PRUN3 <filename>\n\n" "The filename must include the extension", 0); program = VirtualAlloc(NULL, memsize, MEM_RESERVE, PAGE_READWRITE); if (program == NULL) ErrorExit("Failed to reserve memory", 0); __try { err = aux_LoadProgram(&amx, argv[1], program); if (err != AMX_ERR_NONE) ErrorExit("Load error %d (invalid file format or version mismatch)", err); signal(SIGINT,sigabort); amx_CoreInit(&amx); err = aux_RegisterNatives(&amx); if (err != AMX_ERR_NONE) ErrorExit("The program uses native functions that this run-time does not provide", 0); err = amx_Exec(&amx, &ret, AMX_EXEC_MAIN); while (err == AMX_ERR_SLEEP) err = amx_Exec(&amx, &ret, AMX_EXEC_CONT); if (err != AMX_ERR_NONE) printf("Run time error %d on address %ld\n", err, amx.cip); else if (ret != 0) printf("%s returns %ld\n", argv[1], (long)ret); } __except (aux_CommitMemory(GetExceptionInformation(), program, memsize)) { /* nothing */ } /* try */ /* Decommitting memory that is not committed does not fail, so you can just * decommit all memory. Releasing memory that is partially committed fails, * even if you also include the MEM_RELEASE flag (tested on WIndows98), so * you must call VirtualFree twice in a row. */ VirtualFree(program, memsize, MEM_DECOMMIT); VirtualFree(program, 0, MEM_RELEASE); amx_CoreCleanup(&amx); return 0; }
void CNetwork::UnloadScript() { int val; if (!amx_FindPublic(&inimod_amx, "OnGameModeExit", &val)) amx_Exec(&inimod_amx, (cell*)&val, val); if (GMLoaded) { aux_FreeProgram(&inimod_amx); amx_TimeCleanup(&inimod_amx); //amx_FileCleanup(&inimod_amx); amx_StringCleanup(&inimod_amx); amx_FloatCleanup(&inimod_amx); amx_CoreCleanup(&inimod_amx); } GMLoaded = false; }