예제 #1
0
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerWeaponShot(int playerid, int weaponid, int hittype, int hitid, float x, float y, float z)
{
	if (hittype == BULLET_HIT_TYPE_PLAYER_OBJECT)
	{
		boost::unordered_map<int, Player>::iterator p = core->getData()->players.find(playerid);
		if (p != core->getData()->players.end())
		{
			for (boost::unordered_map<int, int>::iterator i = p->second.internalObjects.begin(); i != p->second.internalObjects.end(); ++i)
			{
				if (i->second == hitid)
				{
					int objectid = i->first;
					for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
					{
						int amxIndex = 0;
						if (!amx_FindPublic(*a, "OnPlayerShootDynamicObject", &amxIndex))
						{
							amx_Push(*a, amx_ftoc(z));
							amx_Push(*a, amx_ftoc(y));
							amx_Push(*a, amx_ftoc(x));
							amx_Push(*a, static_cast<cell>(objectid));
							amx_Push(*a, static_cast<cell>(weaponid));
							amx_Push(*a, static_cast<cell>(playerid));
							amx_Exec(*a, NULL, amxIndex);
						}
					}
					break;
				}
			}
		}
	}
	else if (hittype == BULLET_HIT_TYPE_VEHICLE)
	{
		for (boost::unordered_map<int, int>::iterator i = core->getData()->internalVehicles.begin(); i != core->getData()->internalVehicles.end(); ++i)
		{
			if (i->second == hitid)
			{
				int vehicleid = i->first;
				for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
				{
					int amxIndex = 0;
					if (!amx_FindPublic(*a, "OnPlayerShootDynamicVehicle", &amxIndex))
					{
						amx_Push(*a, amx_ftoc(z));
						amx_Push(*a, amx_ftoc(y));
						amx_Push(*a, amx_ftoc(x));
						amx_Push(*a, static_cast<cell>(vehicleid));
						amx_Push(*a, static_cast<cell>(weaponid));
						amx_Push(*a, static_cast<cell>(playerid));
						amx_Exec(*a, NULL, amxIndex);
					}
				}
				break;
			}
		}
	}
	return true;
}
예제 #2
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;
}
예제 #3
0
파일: prun3.c 프로젝트: 1847123212/QuadPawn
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;
}
예제 #4
0
void CGamemodeManager::Frame(float time)
{
	if (!this->gmIsInit)
		return;

	if (!this->gmIsSleeping)
		return;

	if (this->gmSleepTime > 0.0f)
	{
		this->gmSleepTime -= time;
	}
	else
	{
		cell ret;
		int err = amx_Exec(&(this->gmAMX), &ret, AMX_EXEC_CONT);
		if (err == AMX_ERR_SLEEP)
		{
			this->gmIsSleeping = true;
			this->gmSleepTime = ((float)ret / 1000.0f);
		}
		else
		{
			this->gmIsSleeping = false;
			AMXPrintError(this, &(this->gmAMX), err);
		}
	}
}
예제 #5
0
// forward OnServerSendRPC(player_id, rpc_id, BitStream:bs);
bool Callbacks::OnServerSendRPC(int player_id, int rpc_id, RakNet::BitStream *bs)
{
	cell retval{};

	auto &AMXs = Callbacks::GetAmxMap();

	for (auto &i : AMXs)
	{
		auto amx = i.first;
		const auto &public_data = i.second._public_on_server_send_rpc;

		if (public_data.exists)
		{
			if (bs)
				bs->ResetReadPointer();

			amx_Push(amx, reinterpret_cast<cell>(bs));
			amx_Push(amx, static_cast<cell>(rpc_id));
			amx_Push(amx, static_cast<cell>(player_id));

			amx_Exec(amx, &retval, public_data.id);

			if (retval == 0)
				return false;
		}
	}

	return true;
}
예제 #6
0
int Handler::HandleModule(const char *module, bool isClass)
{
    if (m_iModFunc < 0)
        return 0;

    /**
     * This is the most minimalistic handler of them all
     */

    cell hea_addr, *phys_addr, retval;
    Debugger *pd;

    pd = DisableDebugHandler(m_pAmx);

    //temporarily set prenit
    m_pAmx->flags |= AMX_FLAG_PRENIT;
    amx_Push(m_pAmx, isClass ? 1 : 0);
    amx_PushString(m_pAmx, &hea_addr, &phys_addr, module, 0, 0);
    int err = amx_Exec(m_pAmx, &retval, m_iModFunc);
    amx_Release(m_pAmx, hea_addr);
    m_pAmx->flags &= ~AMX_FLAG_PRENIT;

    EnableDebugHandler(m_pAmx, pd);

    if (err != AMX_ERR_NONE)
        return 0;

    return (int)retval;
}
예제 #7
0
파일: pawn_ctrl.c 프로젝트: z80/supply
static void pawnExec( Pawn * pawn )
{
    chSysLock();
        pawn->isRunning = 0;
    chSysUnlock();
    uint32_t i;
    unsigned char * tmp = (unsigned char *)&pawn->amx;
    for ( i=0; i<sizeof( pawn->amx ); i++ )
        tmp[i] = 0;
    pawn->amx.data = (uint8_t *)pawn->memblock;
    uint8_t * rom = (uint8_t *)(PAWN_FLASH_START + PAWN_PAGE_SIZE * PAWN_START_PAGE);
    pawn->result = amx_Init( &pawn->amx, rom );
    if ( pawn->result != AMX_ERR_NONE )
        return;

    static cell ret = 0;
    chSysLock();
        pawn->isRunning = 1;
    chSysUnlock();

    pawn->error = amx_Exec( &pawn->amx, &ret, AMX_EXEC_MAIN );
    pawn->result = ret;
    amx_Cleanup( &pawn->amx );

    chSysLock();
        pawn->isRunning = 0;
    chSysUnlock();
}
예제 #8
0
// forward OnQueryError(connectionId, query[], callback[], errno, error[]);
int Script::OnQueryError(unsigned int connectionId, const char* query, const char* callback, int error_number, const char* error) {
	if (OnQueryError_index_ == CallbackNotFoundIndex)
		return 0;

	// Attempt to find the OnQueryError callback in the script.
	if (OnQueryError_index_ == 0) {
		if (amx_FindPublic(runtime_, "OnQueryError", &OnQueryError_index_) != AMX_ERR_NONE) {
			OnQueryError_index_ = CallbackNotFoundIndex;
			return 0;
		}
	}

	cell returnValue, stringCell[3], *physicalCell;

	// Push the arguments to OnQueryError in reverse order.
	amx_PushString(runtime_, &stringCell[0], &physicalCell, error, 0, 0);
	amx_Push(runtime_, error_number);
	amx_PushString(runtime_, &stringCell[1], &physicalCell, callback, 0, 0);
	amx_PushString(runtime_, &stringCell[2], &physicalCell, query, 0, 0);
	amx_Push(runtime_, connectionId);

	// Execute and get the return value.
	amx_Exec(runtime_, &returnValue, OnQueryError_index_);

	// Clean up the strings we pushed to Pawn's stack.
	amx_Release(runtime_, stringCell[0]);
	amx_Release(runtime_, stringCell[1]);
	amx_Release(runtime_, stringCell[2]);

	return returnValue;
}
예제 #9
0
// forward OnConnectionAttempt(connectionHandle, bool: succeeded, server[], username[], errno, error[]);
int Script::OnConnectionAttempt(unsigned int connectionId, bool succeeded, const char* server, const char* username, int error_number, const char* error) {
	if (OnConnectionAttempt_index_ == CallbackNotFoundIndex)
		return 0;

	// Attempt to find the OnConnectionAttempt callback in the script.
	if (OnConnectionAttempt_index_ == 0) {
		if (amx_FindPublic(runtime_, "OnConnectionAttempt", &OnConnectionAttempt_index_) != AMX_ERR_NONE) {
			OnConnectionAttempt_index_ = CallbackNotFoundIndex;
			return 0;
		}
	}

	cell returnValue, stringCell[3], *physicalCell;

	// We've now got the callback. Push the arguments in reverse order.
	amx_PushString(runtime_, &stringCell[0], &physicalCell, error, 0, 0);
	amx_Push(runtime_, error_number);
	amx_PushString(runtime_, &stringCell[1], &physicalCell, username, 0, 0);
	amx_PushString(runtime_, &stringCell[2], &physicalCell, server, 0, 0);
	amx_Push(runtime_, succeeded);
	amx_Push(runtime_, connectionId);

	// Execute and get the return value.
	amx_Exec(runtime_, &returnValue, OnConnectionAttempt_index_);

	// Clean up the strings we pushed to Pawn's stack.
	amx_Release(runtime_, stringCell[0]);
	amx_Release(runtime_, stringCell[1]);
	amx_Release(runtime_, stringCell[2]);

	return returnValue;
}
예제 #10
0
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;
}
예제 #11
0
PLUGIN_EXPORT bool PLUGIN_CALL OnVehicleRespray(int playerid, int vehicleid, int color1, int color2)
{
	for (boost::unordered_map<int, int>::iterator i = core->getData()->internalVehicles.begin(); i != core->getData()->internalVehicles.end(); ++i)
	{
		if (i->second == vehicleid)
		{
			for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
			{
				int amxIndex = 0;
				if (!amx_FindPublic(*a, "OnDynamicVehicleRespray", &amxIndex))
				{
					amx_Push(*a, static_cast<cell>(color2));
					amx_Push(*a, static_cast<cell>(color1));
					amx_Push(*a, static_cast<cell>(i->first));
					amx_Push(*a, static_cast<cell>(playerid));
					amx_Exec(*a, NULL, amxIndex);
				}
			}
			boost::unordered_map<int, Item::SharedVehicle>::iterator p = core->getData()->vehicles.find(i->first);
			if (p != core->getData()->vehicles.end())
			{
				p->second->color1 = color1; 
				p->second->color2 = color2; 
			}
			break;
		}
	}
	return true;
}
예제 #12
0
파일: SAMP.cpp 프로젝트: Jusonex/V8ForSA
AmxArgument SAMP::CallAmxFunction(const std::string& functionName, const AmxArguments& arguments)
{
    if (!ms_pAmxVM)
        return false;

    // Push arguments onto the stack
    for (const auto& argument : arguments.GetList())
    {
        switch (argument.GetType())
        {
        case eAmxArgumentType::Boolean:
            amx_Push(ms_pAmxVM, static_cast<cell>(argument.GetBool()));
            break;
        case eAmxArgumentType::Number:
            amx_Push(ms_pAmxVM, static_cast<cell>(argument.GetNumber()));
            break;
        case eAmxArgumentType::String:
            cell amx_addr, *amx_physaddr;
            amx_PushString(ms_pAmxVM, &amx_addr, &amx_physaddr, argument.GetString(), 0, 0);
            break;
        }
    }
    
    // Call function
    cell amx_return;
    amx_Exec(ms_pAmxVM, &amx_return, AMX_EXEC_MAIN);

    return AmxArgument(amx_return);
}
예제 #13
0
PLUGIN_EXPORT bool PLUGIN_CALL OnVehicleDamageStatusUpdate(int vehicleid, int playerid)
{
	for (boost::unordered_map<int, int>::iterator i = core->getData()->internalVehicles.begin(); i != core->getData()->internalVehicles.end(); ++i)
	{
		if (i->second == vehicleid)
		{
			for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
			{
				int amxIndex = 0;
				if (!amx_FindPublic(*a, "OnDynamicVehDamageStatusUpdate", &amxIndex))
				{
					amx_Push(*a, static_cast<cell>(playerid));
					amx_Push(*a, static_cast<cell>(i->first));
					amx_Exec(*a, NULL, amxIndex);
				}
			}
			boost::unordered_map<int, Item::SharedVehicle>::iterator p = core->getData()->vehicles.find(i->first);
			if (p != core->getData()->vehicles.end())
			{		
				/*
				if (!p->second->touched)
				{
					p->second->touched = true;
					core->getStreamer()->movingVehicles.insert(p->second);
				}
				*/
				p->second->lastUpdatedTick = GetTickCount();
				GetVehicleDamageStatus(i->first, &p->second->panels, &p->second->doors, &p->second->lights, &p->second->tires);
			}
			break;
		}
	}
	return true;
}
예제 #14
0
int ProfilerHandler::Exec(cell *retval, int index) {
  if (profiler_.call_stack()->is_empty()) {
    switch (state_) {
      case PROFILER_ATTACHING:
        if (!Attach()) {
          break;
        }
        // fallthrough
      case PROFILER_STARTING:
        CompleteStart();
        break;
    }
  }
  if (state_ == PROFILER_STARTED) {
    try {
      int error = profiler_.ExecHook(retval, index, amx_Exec);
      if (state_ == PROFILER_STOPPING
          && profiler_.call_stack()->is_empty()) {
        CompleteStop();
      }
      return error;
    } catch (const std::exception &e) {
      PrintException(e);
    }
  }
  return amx_Exec(amx(), retval, index);
}
예제 #15
0
PLUGIN_EXPORT bool PLUGIN_CALL OnTrailerUpdate(int playerid, int vehicleid)
{
	for (boost::unordered_map<int, int>::iterator i = core->getData()->internalVehicles.begin(); i != core->getData()->internalVehicles.end(); ++i)
	{
		if (i->second == vehicleid)
		{
			for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
			{
				int amxIndex = 0;
				cell ret = 1;
				if (!amx_FindPublic(*a, "OnDynamicTrailerUpdate", &amxIndex))
				{
					amx_Push(*a, static_cast<cell>(i->first));
					amx_Push(*a, static_cast<cell>(playerid));
					amx_Exec(*a, &ret, amxIndex);

					if(!ret) return false;
				}
			}
			boost::unordered_map<int, Item::SharedVehicle>::iterator p = core->getData()->vehicles.find(i->first);
			if (p != core->getData()->vehicles.end())
			{		
				if (!p->second->touched)
				{
					p->second->touched = true;
					core->getStreamer()->movingVehicles.insert(p->second);
				}
				p->second->lastUpdatedTick = GetTickCount();
			}
			break;
		}
	}
	return true;
}
예제 #16
0
PLUGIN_EXPORT bool PLUGIN_CALL OnVehicleMod(int playerid, int vehicleid, int componentid)
{
	for (boost::unordered_map<int, int>::iterator i = core->getData()->internalVehicles.begin(); i != core->getData()->internalVehicles.end(); ++i)
	{
		if (i->second == vehicleid)
		{
			for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
			{
				int amxIndex = 0;
				if (!amx_FindPublic(*a, "OnDynamicVehicleMod", &amxIndex))
				{
					amx_Push(*a, static_cast<cell>(componentid));
					amx_Push(*a, static_cast<cell>(i->first));
					amx_Push(*a, static_cast<cell>(playerid));
					amx_Exec(*a, NULL, amxIndex);
				}
			}
			boost::unordered_map<int, Item::SharedVehicle>::iterator p = core->getData()->vehicles.find(i->first);
			if (p != core->getData()->vehicles.end())
			{
				if (!Utility::isInContainer(p->second->carmods, componentid))
				{
					Utility::addToContainer(p->second->carmods, componentid);
				}
			}
			break;
		}
	}
	return true;
}
예제 #17
0
파일: fixes.cpp 프로젝트: Open-GTO/Fixes2
//__declspec(naked)
//__cdecl
int
	FIXES_logprintf(char * str, ...)
{
	va_list ap;
	char
		dst[1024];
	va_start(ap, str);
	vsnprintf(dst, 1024, str, ap);
	va_end(ap);
	printf("%s\n", dst);
	// So we can use "printf" without getting stuck in endless loops.
	if (!bInPrint)
	{
		for (int i = 0; i != 17; ++i)
		{
			if (gAMXPtr[i] != -1)
			{
				cell
					ret,
					addr;
				amx_PushString(gAMXFiles[i], &addr, 0, dst, 0, 0);
				amx_Exec(gAMXFiles[i], &ret, gAMXPtr[i]);
				amx_Release(gAMXFiles[i], addr);
				if (ret == 1)
				{
					return 1;
				}
			}
		}
	}
	return 1;
}
예제 #18
0
bool CCallbackManager::OnRemoteRCONPacket(unsigned int binaryAddress, int port, char *password, bool success, char* command)
{
	int idx = -1;
	cell ret = 1;
	for(std::vector<AMX*>::const_iterator iter = m_vecAMX.begin(); iter != m_vecAMX.end(); ++iter)
	{
		if(!amx_FindPublic(*iter, "OnRemoteRCONPacket", &idx))
		{
			cell amx_addr, *phys_addr;
			
			in_addr in;
			in.s_addr = binaryAddress;

			amx_PushString(*iter, &amx_addr, &phys_addr, command, 0, 0);
			amx_Push(*iter, static_cast<cell>(success));
			amx_PushString(*iter, &amx_addr, &phys_addr, password, 0, 0);
			amx_Push(*iter, static_cast<cell>(port));
			amx_PushString(*iter, &amx_addr, &phys_addr, inet_ntoa(in), 0, 0);
			amx_Exec(*iter, &ret, idx);
			amx_Release(*iter, amx_addr);

			if (!ret) return 0;
		}
	}
	return !!ret;
}
예제 #19
0
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerGiveDamageActor(int playerid, int actorid, float amount, int weaponid, int bodypart)
{
	for (boost::unordered_map<int, int>::iterator i = core->getData()->internalActors.begin(); i != core->getData()->internalActors.end(); ++i)
	{
		if (i->second == actorid)
		{
			int actorid = i->first;
			for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
			{
				int amxIndex = 0;
				if (!amx_FindPublic(*a, "OnPlayerGiveDamageDynamicActor", &amxIndex))
				{
					amx_Push(*a, static_cast<cell>(bodypart));
					amx_Push(*a, static_cast<cell>(weaponid));
					amx_Push(*a, amx_ftoc(amount));
					amx_Push(*a, static_cast<cell>(actorid));
					amx_Push(*a, static_cast<cell>(playerid));
					amx_Exec(*a, NULL, amxIndex);
				}
			}
			break;
		}
	}
	return true;
}
예제 #20
0
파일: wrapper.cpp 프로젝트: venerdi/sampgdk
static int AMXAPI amx_ExecHookProc(AMX *amx, cell *retval, int index) {
	amx_ExecHook.Remove();

	bool canDoExec = true;
	if (index == AMX_EXEC_MAIN) {
		gamemode = amx;
		sampgdk::Wrapper::GetInstance().CallPublicHook(amx, retval, "OnGameModeInit");
	} else {
		if (amx == gamemode && index != AMX_EXEC_CONT) {
			canDoExec = sampgdk::Wrapper::GetInstance().CallPublicHook(amx, retval, currentPublic.c_str());
		}
		if (index == AMX_EXEC_GDK) {
			amx->stk += amx->paramcount * sizeof(cell);
			amx->paramcount = 0;
		}
	}

	int error = AMX_ERR_NONE;
	if (canDoExec) {
		error = amx_Exec(amx, retval, index);
		if (index == AMX_EXEC_GDK) {
			error = AMX_ERR_NONE;
		}
	}

	amx_ExecHook.Reinstall();
	return error;
}
예제 #21
0
int main(int argc,char *argv[])
{
  extern AMX_NATIVE_INFO console_Natives[];
  extern AMX_NATIVE_INFO core_Natives[];

  AMX amx;
  cell ret = 0;
  int err;

  if (argc != 2)
    PrintUsage(argv[0]);

  err = aux_LoadProgram(&amx, argv[1], NULL);
  if (err != AMX_ERR_NONE)
    ErrorExit(&amx, err);

  amx_Register(&amx, console_Natives, -1);
  err = amx_Register(&amx, core_Natives, -1);
  if (err != AMX_ERR_NONE)
    ErrorExit(&amx, err);

  err = amx_Exec(&amx, &ret, AMX_EXEC_MAIN);
  if (err != AMX_ERR_NONE)
    ErrorExit(&amx, err);
  printf("%s returns %ld\n", argv[1], (long)ret);

  aux_FreeProgram(&amx);
  return 0;
}
예제 #22
0
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerSelectObject(int playerid, int type, int objectid, int modelid, float x, float y, float z)
{
	if (type == SELECT_OBJECT_PLAYER_OBJECT)
	{
		boost::unordered_map<int, Player>::iterator p = core->getData()->players.find(playerid);
		if (p != core->getData()->players.end())
		{
			for (boost::unordered_map<int, int>::iterator i = p->second.internalObjects.begin(); i != p->second.internalObjects.end(); ++i)
			{
				if (i->second == objectid)
				{
					int objectid = i->first;
					for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
					{
						int amxIndex = 0;
						if (!amx_FindPublic(*a, "OnPlayerSelectDynamicObject", &amxIndex))
						{
							amx_Push(*a, amx_ftoc(z));
							amx_Push(*a, amx_ftoc(y));
							amx_Push(*a, amx_ftoc(x));
							amx_Push(*a, static_cast<cell>(modelid));
							amx_Push(*a, static_cast<cell>(objectid));
							amx_Push(*a, static_cast<cell>(playerid));
							amx_Exec(*a, NULL, amxIndex);
						}
					}
					break;
				}
			}
		}
	}
	return false;
}
예제 #23
0
//General "Network" / Gamemode AMX Code
void CNetwork::OnServerChangeMap() {
	printf("OnServerChangeMap() has been called.\n");
	int idx;
	cell ret = 0;
	CBaseEntity *entity = new CBaseEntity;
	Precache *precache = new Precache;

	CBasePlayer *pPlayer = new CBasePlayer();
	//Dump all the clients from the table because the map was changed..
	for(size_t i=0; i<ReadInt32(SVS_MAXCLIENTS); i++) {
		if(pPlayer->IsClientConnected(i)) {
			if(pPlayer->IsClientOnTable(i)) {
				OnClientDisconnect(i, REASON_MAPCHANGE);
			}
		}
	}
	delete pPlayer;
	//amx push would go below here.. (So we can push the OnServerChangeMap data to the loaded AMX script later)
	if (!amx_FindPublic(&inimod_amx, "OnServerChangeMap", &idx)) {
		amx_Exec(&inimod_amx, &ret, idx);
		precache->PreloadCached(false); //Don't delete anything the users precached..
	}
	if((long)ret == 1) {
		printf("ret returned %d\n", ret);
	}
	entity->OnServerChangeMap();
	delete entity;
	delete precache;
}
예제 #24
0
PLUGIN_EXPORT bool PLUGIN_CALL OnVehicleSpawn(int vehicleid)
{
	for (boost::unordered_map<int, int>::iterator i = core->getData()->internalVehicles.begin(); i != core->getData()->internalVehicles.end(); ++i)
	{
		if (i->second == vehicleid)
		{
			for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
			{
				int amxIndex = 0;
				if (!amx_FindPublic(*a, "OnDynamicVehicleSpawn", &amxIndex))
				{
					amx_Push(*a, static_cast<cell>(i->first));
					amx_Exec(*a, NULL, amxIndex);
				}
			}
			boost::unordered_map<int, Item::SharedVehicle>::iterator p = core->getData()->vehicles.find(i->first);
			if (p != core->getData()->vehicles.end())
			{
				if (p->second->touched)
				{
					p->second->touched = false;
					p->second->used = true;
				}
			}
			break;
		}
	}
	return true;
}
예제 #25
0
파일: pawn_loader.c 프로젝트: glockwork/dfu
int pawnExec( Pawn * p )
{
    int err;
    cell retVal;
    err = amx_Exec( &p->amx, &retVal, AMX_EXEC_MAIN );
    return (err == AMX_ERR_NONE) ? PAWN_OK : PAWN_ERR_EXEC;
}
void Streamer::executeCallbacks()
{
	for (std::vector<boost::tuple<bool, int, int> >::const_iterator c = areaCallbacks.begin(); c != areaCallbacks.end(); ++c)
	{
		if (c->get<0>())
		{
			for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
			{
				int amxIndex = 0;
				if (!amx_FindPublic(*a, "OnPlayerEnterDynamicArea", &amxIndex))
				{
					amx_Push(*a, static_cast<cell>(c->get<1>()));
					amx_Push(*a, static_cast<cell>(c->get<2>()));
					amx_Exec(*a, NULL, amxIndex);
				}
			}
		}
		else
		{
			for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
			{
				int amxIndex = 0;
				if (!amx_FindPublic(*a, "OnPlayerLeaveDynamicArea", &amxIndex))
				{
					amx_Push(*a, static_cast<cell>(c->get<1>()));
					amx_Push(*a, static_cast<cell>(c->get<2>()));
					amx_Exec(*a, NULL, amxIndex);
				}
			}
		}
	}
	areaCallbacks.clear();
	for (std::vector<int>::const_iterator c = objectCallbacks.begin(); c != objectCallbacks.end(); ++c)
	{
		for (std::set<AMX*>::iterator a = core->getData()->interfaces.begin(); a != core->getData()->interfaces.end(); ++a)
		{
			int amxIndex = 0;
			if (!amx_FindPublic(*a, "OnDynamicObjectMoved", &amxIndex))
			{
				amx_Push(*a, static_cast<cell>(*c));
				amx_Exec(*a, NULL, amxIndex);
			}
		}
	}
	objectCallbacks.clear();
}
예제 #27
0
int CNetwork::OnServerThink( void ) {
	int idx;
	cell ret = 0;
	if(!amx_FindPublic(&inimod_amx, "ServerThink", &idx)) {
		amx_Exec(&inimod_amx, &ret, idx);
	}
	return (int)ret;
}
예제 #28
0
int FilterScript::Init(cell *retval) {
  int error, index;
  error = amx_FindPublic(&amx_, "OnFilterScriptInit", &index) == AMX_ERR_NONE;
  if (error != AMX_ERR_NONE) {
    error = amx_Exec(&amx_, retval, index) == AMX_ERR_NONE;
  }
  return error;
}
예제 #29
0
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick()
{
	while(!amxQueue.empty()) 
	{
		int amx_idx;
		attackData toamx;

		std::list<AMX *>::iterator end = amxList.end();

		aat_Debug("* ProcessTick() is not empty, executing...");

		boost::mutex::scoped_lock lock(gMutex);
		toamx = amxQueue.front();
		amxQueue.pop();
		lock.unlock();

		for(std::list<AMX *>::iterator amx = amxList.begin(); amx != end; amx++) 
		{
			if(toamx.type > 4)
			{
				cell amxAddress;

				if(!amx_FindPublic(*amx, "OnRemoteAttackAttempt", &amx_idx)) 
				{
					amx_PushString(*amx, &amxAddress, NULL, toamx.data.c_str(), NULL, NULL);
					amx_Push(*amx, (toamx.type - 5));

					amx_Exec(*amx, NULL, amx_idx);

					amx_Release(*amx, amxAddress);
				}
			}
			else
			{
				if(!amx_FindPublic(*amx, "OnIngameAttackAttempt", &amx_idx)) 
				{
					amx_Push(*amx, atoi(toamx.data.c_str()));
					amx_Push(*amx, toamx.type);
					
					amx_Exec(*amx, NULL, amx_idx);
				}
			}
		}
	}
}
예제 #30
0
int CNetwork::ExecMain() {
    cell ret;
    this->err = amx_Exec(&inimod_amx, &ret, AMX_EXEC_MAIN);
    if (err != AMX_ERR_NONE)
        Error( this->err);
    if (ret != 0)
        printf("Returns %ld\n", (long)ret);
    return ret;
}