Ejemplo n.º 1
0
bool CGamemodeManager::Load(char* gmFile)
{
	if (this->gmIsInit)
		Unload();

	FILE* f = fopen(gmFile, "rb");
	if (!f) return false;
	fclose(f);

	memset((void*)&(this->gmAMX), 0, sizeof(AMX));
	this->gmSleepTime = 0.0f;
	strcpy(szGameModeFileName, gmFile);

	int err = aux_LoadProgram(&(this->gmAMX), szGameModeFileName);
	if (err != AMX_ERR_NONE)
	{
		AMXPrintError(this, &(this->gmAMX), err);
		logprintf("Failed to load '%s' script.", szGameModeFileName);
		return false;
	}

	amx_CoreInit(&(this->gmAMX));
	amx_FloatInit(&(this->gmAMX));
	amx_StringInit(&(this->gmAMX));
	amx_FileInit(&(this->gmAMX));
	amx_TimeInit(&(this->gmAMX));
	//amx_DGramInit(&(this->gmAMX));
	amx_CustomInit(&(this->gmAMX));
	amx_sampDbInit(&(this->gmAMX));

	__Plugins->DoAmxLoad(&(this->gmAMX));

	this->gmIsInit = true;

	int tmp;
	if (!amx_FindPublic(&(this->gmAMX), "OnGameModeInit", &tmp))
		amx_Exec(&(this->gmAMX), (cell*)&tmp, tmp);

	__NetGame->filterscriptsManager->OnGameModeInit();

	cell ret = 0;
	err = amx_Exec(&(this->gmAMX), &ret, AMX_EXEC_MAIN);
	if (err == AMX_ERR_SLEEP)
	{
		this->gmIsSleeping = true;
		this->gmSleepTime = ((float)ret / 1000.0f);
	}
	else if (err != AMX_ERR_NONE)
	{
		this->gmIsSleeping = false;
		AMXPrintError(this, &(this->gmAMX), err);
	}

	return true;
}
Ejemplo n.º 2
0
int initialize_pawn_machine (pawn_machine *machine, const char* fname)
{
	int err;
	size_t memsize;
	void* buffer;

	machine->initialized = 0;

	memsize = aux_ProgramSize (fname);
	if (memsize == 0)
	{
		log_error ("Unable to determine memory size for Pawn file %s", fname);
		return 0;
	}

	buffer = malloc (memsize);
	if (buffer == NULL)
	{
		log_error ("unable to allocate memory for Pawn file %s", fname);
		return 0;
	}

	err = aux_LoadProgram (&(machine->amx), fname, buffer);
	if (err != AMX_ERR_NONE)
	{
		free (buffer);
		log_error ("unable to load Pawn file %s", fname);
		return 0;
	}

	// The amx_*Init functions return an error when not all natives
	// used in the amx script are defined, so we only need to check
	// the last Init (when we have defined our entire library).
	amx_ConsoleInit (&(machine->amx));
	amx_FloatInit (&(machine->amx));
	amx_StringInit (&(machine->amx));
	err = amx_ElInit (&(machine->amx));
	if (err != AMX_ERR_NONE)
	{
		free (buffer);
		log_error ("Unable to initialize all native functions for Pawn file %s", fname);
		return 0;
	}

	machine->buf_size = memsize;
	machine->buffer = buffer;
	machine->initialized = 1;

	return 1;
}
Ejemplo n.º 3
0
bool CNetwork::LoadScript(char *filename) {
    size_t memsize = aux_ProgramSize(filename);
    if(memsize == 0) {
        printf("Script file not found or corrupted\n");
        return false;
    }
	memset((void*)&inimod_amx, 0, sizeof(AMX));
    void * program = malloc(memsize);

    if (program == NULL) {
        printf("Memory allocation for script failed\n");
        return false;
    }
    if(!LoadProgram(filename,program)) {
        printf("Loading script into Abstract Machine failed\n");
        return false;
    }
	amx_CoreInit(&inimod_amx);
	amx_FloatInit(&inimod_amx);
	amx_StringInit(&inimod_amx);
	//amx_FileInit(&inimod_amx);
	amx_TimeInit(&inimod_amx);
    return true;
}