static int GM_CDECL gmfFileSeek(gmThread * a_thread) // return false on error
{
  gmUserObject * fileObject = a_thread->ThisUserObject();
  GM_ASSERT(fileObject->m_userType == s_gmFileType);

  GM_CHECK_NUM_PARAMS(2);
  GM_CHECK_INT_PARAM(offset, 0);
  GM_CHECK_INT_PARAM(origin, 1);

  if(    origin != SEEK_CUR 
      && origin != SEEK_END 
      && origin != SEEK_SET )
  {
    return GM_EXCEPTION;
  }

  int result = fseek((FILE*)fileObject->m_user, offset, origin);
  if(result != 0)
  {
    a_thread->PushInt(false);
  }
  a_thread->PushInt(true);

  return GM_OK;
}
Example #2
0
// string string.SetAt(int a_index, int a_char);
// Returns string with modified character at offset, or original string if index out of range.
static int GM_CDECL gmStringSetAt(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_INT_PARAM(index, 0);
  GM_CHECK_INT_PARAM(newChar, 1);

  const gmVariable * var = a_thread->GetThis();

  GM_ASSERT(var->m_type == GM_STRING);

  gmStringObject * strObj = (gmStringObject *) GM_OBJECT(var->m_value.m_ref);
  const char * str = (const char *) *strObj;
  int strLength = strObj->GetLength();

  if(index < 0 || index >= strLength)
  {
    a_thread->PushString(strObj); //Return original string if index out of range
    return GM_OK;
  }

  char * buffer = (char *) alloca(strLength + 1); 
  memcpy(buffer, str, strLength + 1); //Copy old string
  buffer[index] = (char)newChar; //Set character in string

  a_thread->PushNewString(buffer, strLength);
  return GM_OK;
}
Example #3
0
// int randint(int a_min, int a_max);
// returned number is >= a_min and < a_max (exclusive of max)
static int GM_CDECL gmfRandInt(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(2);
  GM_CHECK_INT_PARAM(min, 0);
  GM_CHECK_INT_PARAM(max, 1);
  
  a_thread->PushInt( gmRandomInt(min, max) );

  return GM_OK;
}
Example #4
0
static int GM_CDECL gmfFireTeamApply( gmThread *a_thread )
{
	CHECK_THIS_BOT();
	GM_CHECK_NUM_PARAMS( 1 );
	GM_CHECK_INT_PARAM( fireteamnum, 0 );
	InterfaceFuncs::FireTeamApply( native, fireteamnum );
	return GM_OK;
}
Example #5
0
	static int GM_CDECL gmfEnable(gmThread * a_thread)
	{
		GM_CHECK_NUM_PARAMS(1);
		GM_CHECK_INT_PARAM(enable, 0);

		VirtualMachine::Get()->GetConsole().Enable(enable != 0);
		return GM_OK;
	}
Example #6
0
// function: BotPush
//		Set the bots push flag.
//
//
// Parameters:
//
//		int push - 0 or 1
//
// Returns:
//		none
static int GM_CDECL gmfDisableBotPush( gmThread *a_thread )
{
	CHECK_THIS_BOT();
	GM_CHECK_NUM_PARAMS( 1 );
	GM_CHECK_INT_PARAM( botPush, 0 );

	InterfaceFuncs::DisableBotPush( native, botPush );
	return GM_OK;
}
Example #7
0
// function: ChangeSpawnPoint
//		Changes the bots active spawn point
//
// Parameters:
//
//		int - Spawn point to change to
//
// Returns:
//		none
static int GM_CDECL gmfChangeSpawnPoint( gmThread *a_thread )
{
	CHECK_THIS_BOT();
	GM_CHECK_NUM_PARAMS( 1 );
	GM_CHECK_INT_PARAM( spawnpoint, 0 );

	InterfaceFuncs::ChangeSpawnPoint( native, spawnpoint );
	return GM_OK;
}
Example #8
0
	static int GM_CDECL gmfSetSwapFreeze(gmThread * a_thread)
	{
		GM_CHECK_NUM_PARAMS(1);
		GM_CHECK_INT_PARAM(swap_freeze, 0);

		g_swap_freeze = swap_freeze != 0;

		return GM_OK;
	}
Example #9
0
	static int GM_CDECL putShort(gmThread* a_thread)
	{
		GM_CHECK_NUM_PARAMS(1);
		GM_CHECK_INT_PARAM(data, 0);

		gmByteBuffer* buf = (gmByteBuffer*)a_thread->ThisUser_NoChecks();
		buf->m_byteBuffer->append<short>((short)data);
		return GM_OK;
	}
Example #10
0
// void randseed(int a_seed);
static int GM_CDECL gmfRandSeed(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_INT_PARAM(seed, 0);
  
  srand(seed);
  
  return GM_OK;
}
Example #11
0
// function: ChangeSecondaryWeapon
//		Sets the bots secondary weapon to a new weapon to use upon respawn
//
// Parameters:
//
//		int - weapon id to choose for secondary weapon
//
// Returns:
//		int - true if success, false if error
static int GM_CDECL gmfBotPickSecondaryWeapon( gmThread *a_thread )
{
	CHECK_THIS_BOT();
	GM_CHECK_NUM_PARAMS( 1 );
	GM_CHECK_INT_PARAM( weaponId, 0 );

	bool bSucess = InterfaceFuncs::SelectSecondaryWeapon( native, (ET_Weapon)weaponId );
	a_thread->PushInt( bSucess ? 1 : 0 );
	return GM_OK;
}
Example #12
0
static int GM_CDECL gmfFileWriteChar(gmThread * a_thread) // int, return char written, or NULL on error
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_INT_PARAM(c, 0);

  gmUserObject * fileObject = a_thread->ThisUserObject();
  GM_ASSERT(fileObject->m_userType == s_gmFileType);
  if(fileObject->m_user)
  {
    int r = fputc(c, (FILE *) fileObject->m_user);
    if(r != EOF) a_thread->PushInt(r);
  }
  return GM_OK;
}
Example #13
0
// int string.GetAt(int a_index);
// Returns character at offset or null if index out of range.
static int GM_CDECL gmStringGetAt(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_INT_PARAM(index, 0);

  const gmVariable * var = a_thread->GetThis();

  GM_ASSERT(var->m_type == GM_STRING);

  gmStringObject * strObj = (gmStringObject *) GM_OBJECT(var->m_value.m_ref);
  const char * str = (const char *) *strObj;

  if(index < 0 || index >= strObj->GetLength())
  {
    a_thread->PushNull(); //Return null if index out of range
    return GM_OK;
  }

  a_thread->PushInt(str[index]);
  return GM_OK;
}
Example #14
0
static int GM_CDECL gmfStringRightAt(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_INT_PARAM(index, 0);

  const gmVariable * var = a_thread->GetThis();
  
  GM_ASSERT(var->m_type == GM_STRING);

  gmStringObject * strObj = (gmStringObject *) GM_OBJECT(var->m_value.m_ref);
  const char * str = (const char *) *strObj;
  
  int length = strObj->GetLength();
  index = gmClamp(0, index, length);
  int count = (length - index);
  char * buffer = (char *) alloca(count + 1);
  memcpy(buffer, str + index, count);
  buffer[count] = 0;

  a_thread->PushNewString(buffer, count);

  return GM_OK;
}
Example #15
0
static int GM_CDECL gmfFileFindGetAttribute(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_INT_PARAM(attribute, 0);

  GM_ASSERT(a_thread->GetThis()->m_type == s_gmFileFindType);
  gmFileFindUser * fileFind = (gmFileFindUser *) a_thread->ThisUser();

  DWORD attr = 0;
  if(attribute == 'r')
  {
    attr = FILE_ATTRIBUTE_READONLY;
  }
  else if(attribute == 'a')
  {
    attr = FILE_ATTRIBUTE_ARCHIVE;
  }
  else if(attribute == 's')
  {
    attr = FILE_ATTRIBUTE_SYSTEM;
  }
  else if(attribute == 'h')
  {
    attr = FILE_ATTRIBUTE_HIDDEN;
  }
  else if(attribute == 'd')
  {
    attr = FILE_ATTRIBUTE_DIRECTORY;
  }
  else if(attribute == 'c')
  {
    attr = FILE_ATTRIBUTE_COMPRESSED;
  }

  a_thread->PushInt((fileFind->m_findData.dwFileAttributes & attr) ? 1 : 0);
  return GM_OK;
}