bool sqliteDB_dropTable ( sqlite3 *db, char *tableName )
{
	traceLastFunc( "sqliteDB_dropTable()" );

	int exist_check;
	char sql_cmd[64];
	char *errmsgs;

	if ( db == NULL || tableName == NULL )
	{
		Log ( "sqliteDB_dropTable: received %s", db == NULL ? "db = NULL" : "tableName = NULL" );
		return false;
	}

	exist_check = sqliteDB_checkTableExists( db, tableName );
	if ( exist_check != 1 )
	{
		// table already doesn't exist anymore
		if ( exist_check == 0 )
			return true;

		// some error
		return false;
	}
	
	_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "DROP TABLE '%s';", tableName );
	sqlite3_exec( db, sql_cmd, NULL, NULL, &errmsgs );
	if ( errmsgs != NULL )
	{
		Log( "SQLite - Error (exec drop table '%s'): %s", tableName, sqlite3_errmsg(db) );
		return false;
	}
	return true;
}
Beispiel #2
0
// update SAMPGTA ped translation structure
void update_translateGTASAMP_pedPool ( void )
{
	traceLastFunc( "update_translateGTASAMP_pedPool()" );
	if ( !g_Players )
		return;

	int iGTAID, i;
	for ( i = 0; i < SAMP_PLAYER_MAX; i++ )
	{
		if ( i == g_Players->sLocalPlayerID )
		{
			translateGTASAMP_pedPool.iSAMPID[0] = i;
			continue;
		}

		if ( isBadPtr_writeAny(g_Players->pRemotePlayer[i], sizeof(stRemotePlayer)) )
			continue;
		if ( isBadPtr_writeAny(g_Players->pRemotePlayer[i]->pPlayerData, sizeof(stRemotePlayerData)) )
			continue;
		if ( isBadPtr_writeAny(g_Players->pRemotePlayer[i]->pPlayerData->pSAMP_Actor, sizeof(stSAMPPed)) )
			continue;

		iGTAID = getPedGTAIDFromInterface( (DWORD *)g_Players->pRemotePlayer[i]->pPlayerData->pSAMP_Actor->pGTA_Ped );
		if ( iGTAID <= SAMP_PLAYER_MAX && iGTAID >= 0 )
		{
			translateGTASAMP_pedPool.iSAMPID[iGTAID] = i;
		}
	}
}
bool rec_sqlite_optimizeDatabase ()
{
	traceLastFunc( "rec_sqlite_optimizeTable()" );

	sqlite3 *rec_db;
	char *errmsgs;

	if ( sqlite3_open( REC_DB_NAME, &rec_db ) != SQLITE_OK )
	{
		Log( "SQLite - Error while connecting: %s", sqlite3_errmsg(rec_db) );
		sqlite3_close( rec_db );
		return false;
	}

	sqlite3_exec( rec_db, "VACUUM", NULL, NULL, &errmsgs );
	if ( errmsgs != NULL )
	{
		Log( "SQLite - Error (optimize): %s", sqlite3_errmsg(rec_db) );
		sqlite3_close( rec_db );
		return false;
	}

	cheat_state_text( "Database has been optimized" );

	sqlite3_close( rec_db );
	return true;
}
// ret: -1 = fail, 0 = not exist, 1 = exist
int sqliteDB_checkTableExists ( sqlite3 *db, char *tableName )
{
	traceLastFunc( "sqliteDB_checkTableExists()" );

	sqlite3_stmt *prep_stmt;
	char sql_cmd[256];

	if ( db == NULL || tableName == NULL )
	{
		Log ( "sqliteDB_checkTableExists: received %s", db == NULL ? "db = NULL" : "tableName = NULL" );
		return -1;
	}

	_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "SELECT name FROM sqlite_master WHERE type='table' AND name='%s';", tableName );
	if ( sqlite3_prepare_v2( db, sql_cmd, sizeof(sql_cmd), &prep_stmt, NULL ) != SQLITE_OK )
	{
		Log( "SQLite - Error (preparing statement to find '%s' table): %s", tableName, sqlite3_errmsg(db) );
		return -1;
	}
	sqlite3_step( prep_stmt );

	// if we receive some text the table exists
	if ( sqlite3_column_text( prep_stmt, 0 ) != NULL )
	{
		sqlite3_finalize( prep_stmt );
		return 1;
	}
	sqlite3_finalize( prep_stmt );
	return 0;
}
Beispiel #5
0
int patcher_remove ( struct patch_set *patch )
{
	traceLastFunc( "patcher_remove()" );

	int i;

	if ( patch->failed )
	{
		patch->failed = 0;
		return 1;
	}

	if ( patch->installed )
	{
		for ( i = 0; i < PATCHER_CHUNKS_MAX; i++ )
		{
			if ( patch->chunk[i].ptr == NULL )
				break;

			if ( !memcpy_safe((uint8_t *)patch->chunk[i].ptr, patch->chunk[i].data_orig, patch->chunk[i].len) )
				Log( "Failed to restore patch '%s' chunk %d", patch->name, i );
		}

		patch->installed = 0;

		//Log("Removed patch '%s'.", patch->name);
	}

	return 1;
}
Beispiel #6
0
void cheat_handle_emo ( struct vehicle_info *vehicle_info, struct actor_info *actor_info, float time_diff )
{
	traceLastFunc( "cheat_handle_emo()" );

	struct vehicle_info *vtemp;

	if ( !isBadPtr_GTA_pPed(actor_info) )
	{
		if ( KEY_PRESSED(set.key_self_destruct) )
			actor_info->hitpoints = 0.0f;
	}
	else if ( !isBadPtr_GTA_pVehicle(vehicle_info) )
	{
		actor_info = actor_info_get(ACTOR_SELF, 0);
		if ( actor_info->state == ACTOR_STATE_DRIVING && actor_info->vehicle->passengers[0] == actor_info )
		{
			if ( KEY_PRESSED(set.key_self_destruct) )
			{
				for ( vtemp = vehicle_info; vtemp != NULL; vtemp = vtemp->trailer )
				{
					if(vtemp == NULL) return;

					vtemp->hitpoints = 1.0f;
					cheat_vehicle_tires_set( vtemp, 1 );
					if ( !set.trailer_support )
						break;
				}
			}
		}
	}
}
bool HookedRakClientInterface::Send(BitStream * bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel)
{
	traceLastFunc("HookedRakClientInterface::Send(BitStream)");
	if (bitStream != nullptr)
	{
		if (!OnSendPacket(bitStream, priority, reliability, orderingChannel))
			return false;
	}
	return g_RakClient->GetInterface()->Send(bitStream, priority, reliability, orderingChannel);
}
bool HookedRakClientInterface::RPC(int* uniqueID, BitStream *parameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, bool shiftTimestamp)
{
	traceLastFunc("HookedRakClientInterface::RPC(BitStream)");
	if (uniqueID != nullptr)
	{
		if (!OnSendRPC(*uniqueID, parameters, priority, reliability, orderingChannel, shiftTimestamp))
			return false;
	}
	return g_RakClient->GetInterface()->RPC(uniqueID, parameters, priority, reliability, orderingChannel, shiftTimestamp);
}
bool HookedRakClientInterface::Send( BitStream * bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel )
{
	traceLastFunc( "HookedRakClientInterface::Send(BitStream)" );
	
	// use this if you wanna log outgoing packets
	/*BYTE packetId;
	bitStream->Read( packetId );*/

	return g_RakClient->GetRakClientInterface()->Send( bitStream, priority, reliability, orderingChannel );
}
Beispiel #10
0
void cmd_change_server_fav ( char *param )
{
	traceLastFunc( "cmd_change_server_fav()" );

	if ( strlen(param) == 0 )
	{
		addMessageToChatWindow( "/m0d_fav_server <server name/part of server name>" );
		addMessageToChatWindow( "In order to see the favorite server list type: /m0d_fav_server list" );
		return;
	}

	if ( strncmp(param, "list", 4) == 0 )
	{
		int count = 0;
		for ( int i = 0; i < INI_SERVERS_MAX; i++ )
		{
			if ( set.server[i].server_name == NULL )
				continue;

			count++;
			addMessageToChatWindow( "%s", set.server[i].server_name );
		}
		if ( count == 0 )
			addMessageToChatWindow( "No servers in favorite server list. Edit the ini file to add some." );
		return;
	}

	char	IP[257], LocalName[29];
	int		Port;
	strcpy( IP, g_SAMP->szIP );
	Port = g_SAMP->ulPort;
	strcpy( LocalName, getPlayerName(g_Players->sLocalPlayerID) );

	for ( int i = 0; i < INI_SERVERS_MAX; i++ )
	{
		if ( set.server[i].server_name == NULL || set.server[i].ip == NULL
			|| strlen(set.server[i].ip) < 7 || set.server[i].port == 0 )
			continue;

		if ( !findstrinstr((char *)set.server[i].server_name, param) )
			continue;

		if ( !set.use_current_name )
			setLocalPlayerName( set.server[i].nickname );

		strcpy( g_SAMP->szIP, set.server[i].ip );
		g_SAMP->ulPort = set.server[i].port;
		setPassword( set.server[i].password );
		joining_server = 1;
		return;
	}

	addMessageToChatWindow( "/m0d_fav_server <server name/part of server name>" );
	return;
}
Beispiel #11
0
CVector cheat_actor_getPositionUnder ( actor_info *ainfo )
{
	traceLastFunc( "cheat_vehicle_getPositionUnder()" );

	CVector offsetVector;
	float	*matrix = ainfo->base.matrix;
	offsetVector.fX = 0 * matrix[0] + 0 * matrix[4] - 1 * matrix[8];
	offsetVector.fY = 0 * matrix[1] + 0 * matrix[5] - 1 * matrix[9];
	offsetVector.fZ = 0 * matrix[2] + 0 * matrix[6] - 1 * matrix[10];
	return offsetVector;
}
char *rec_sqlite_getTableName( int RouteNum )
{
	traceLastFunc( "rec_sqlite_getTableName()" );

	sqlite3 *rec_db;
	sqlite3_stmt *prep_stmt;
	int prep_step_ret;
	char sql_cmd[64];
	char *cur_val;
	char *ret_val;
	int num_table;

	// start at -1 - array-pos, not actual num
	num_table = -1;
	ret_val = NULL;
	if ( sqlite3_open( REC_DB_NAME, &rec_db ) != SQLITE_OK )
	{
		Log( "SQLite - Error while connecting: %s", sqlite3_errmsg(rec_db) );
		sqlite3_close( rec_db );
		return NULL;
	}

	_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "SELECT name FROM sqlite_master WHERE type='table';" );
	if ( sqlite3_prepare_v2( rec_db, sql_cmd, sizeof(sql_cmd), &prep_stmt, NULL ) != SQLITE_OK )
	{
		Log( "SQLite - Error (preparing statement in getTableName): %s", sqlite3_errmsg(rec_db) );
		sqlite3_close( rec_db );
		return NULL;
	}
	prep_step_ret = sqlite3_step( prep_stmt );

	while ( prep_step_ret == SQLITE_ROW && ret_val == NULL )
	{
		cur_val = (char*)sqlite3_column_text( prep_stmt, 0 );
		// filter sqlite_* tables
		if ( strncmp(cur_val, "sqlite_", 7) != 0 )
			num_table++;

		if ( num_table == RouteNum )
		{
			ret_val = cur_val;
			_snprintf_s( rec_tempTableCpy, sizeof(rec_tempTableCpy)-1, "%s", cur_val );
			break;
		}

		prep_step_ret = sqlite3_step( prep_stmt );
	}

	sqlite3_finalize( prep_stmt );
	sqlite3_close( rec_db );
	if ( cur_val == NULL )
		return NULL;
	return &rec_tempTableCpy[0];
}
Packet *HookedRakClientInterface::Receive(void)
{
	traceLastFunc("HookedRakClientInterface::Receive");
	Packet *p = g_RakClient->GetInterface()->Receive();
	while (p != nullptr)
	{
		if (OnReceivePacket(p))
			break;
		g_RakClient->GetInterface()->DeallocatePacket(p);
	}
	return p;
}
bool HookedRakClientInterface::RPC( int* uniqueID, BitStream *parameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, bool shiftTimestamp )
{
	traceLastFunc( "HookedRakClientInterface::RPC(BitStream)" );
	
	// use this if you wanna log outgoing RPCs
	/*if ( *uniqueID != RPC_UpdateScoresPingsIPs )
	{
		int len = parameters ? parameters->GetNumberOfBytesUsed() : 0;
		Log( "< [RPC Send] %d, len: %d", *uniqueID, len );
	}*/

	return g_RakClient->GetRakClientInterface()->RPC( uniqueID, parameters, priority, reliability, orderingChannel, shiftTimestamp );
}
Beispiel #15
0
// sa-mp only
void cheat_handle_antiHijack ( actor_info *ainfo, vehicle_info *veh, float time_diff )
{
	return;
	if ( g_SAMP == NULL )
	//	return;

	traceLastFunc( "cheat_handle_antiHijack()" );

	if ( set.anti_carjacking && veh == NULL )
	{
		if ( cheat_state->_generic.got_vehicle_id )
			cheat_state->_generic.got_vehicle_id = false;
		if ( cheat_state->_generic.anti_carjackTick
		 &&	 cheat_state->_generic.anti_carjackTick < (GetTickCount() - 500)
		 &&	 cheat_state->_generic.car_jacked )
		{
			if ( cheat_state->_generic.car_jacked_last_vehicle_id == 0 )
			{
				showGameText( "~r~Unable To Unjack~w~!", 1000, 5 );
				cheat_state->_generic.anti_carjackTick = 0;
				cheat_state->_generic.car_jacked = false;
				return;
			}

			cheat_state->_generic.anti_carjackTick = 0;
			cheat_state->_generic.car_jacked = false;
			cheat_state->_generic.unrelatedToAnything = 1337;
			GTAfunc_PutActorInCar(GetVehicleByGtaId(cheat_state->_generic.car_jacked_last_vehicle_id));
			cheat_state->_generic.unrelatedToAnything = 0x1337;

			struct vehicle_info *veh = GetVehicleByGtaId( cheat_state->_generic.car_jacked_last_vehicle_id );
			//if ( veh != NULL )
			//	vect3_copy( cheat_state->_generic.car_jacked_lastPos, &veh->base.matrix[4 * 3] );
			showGameText( "~r~Car Unjacked~w~!", 1000, 5 );
			return;
		}
	}
	else if ( set.anti_carjacking )
	{
		if ( veh->passengers[0] == actor_info_get(ACTOR_SELF, 0) )
		{
			if ( !cheat_state->_generic.got_vehicle_id )
			{
				cheat_state->_generic.car_jacked_last_vehicle_id = getPlayerVehicleGTAScriptingID( ACTOR_SELF );
				if ( cheat_state->_generic.car_jacked_last_vehicle_id > 0 )
					cheat_state->_generic.got_vehicle_id = true;
			}
		}
	}
}
Beispiel #16
0
void cheat_handle_unfreeze ( struct vehicle_info *vehicle_info, struct actor_info *actor_info, float time_diff )
{
	traceLastFunc( "cheat_handle_unfreeze()" );

	if ( KEY_PRESSED(set.key_anti_freeze) )
	{
		GTAfunc_TogglePlayerControllable(0);
		GTAfunc_LockActor(0);
		pGameInterface->GetCamera()->RestoreWithJumpCut();
		
		// stop all animations
		if ( actor_info != NULL && !actor_info->pedFlags.bInVehicle )
			GTAfunc_DisembarkInstantly();
	}
}
Beispiel #17
0
static void cheat_main_vehicle ( double time_diff )
{
	traceLastFunc( "cheat_main_vehicle()" );

	struct vehicle_info *info = vehicle_info_get( VEHICLE_SELF, 0 );
	if ( info == NULL )
		return;

	cheat_handle_antiHijack( NULL, info, time_diff );

	// copy vehicle coords to cheat_state storage
	vect3_copy( &info->base.matrix[4 * 3], cheat_state->vehicle.coords );

	// the following functions can be found in cheat_generic.cpp
	cheat_handle_unfreeze( info, NULL, time_diff );
	cheat_handle_teleport( info, NULL, time_diff );
	cheat_handle_stick( info, NULL, time_diff );
	cheat_handle_freeze_vehicles( info, NULL );
	cheat_handle_hp( info, NULL, time_diff );
	cheat_handle_emo( info, NULL, time_diff );

	// the following functions can be found in cheat_vehicle.cpp
	cheat_handle_vehicle_protection( info, time_diff );
	cheat_handle_vehicle_unflip( info, time_diff );
	cheat_handle_vehicle_nitro( info, time_diff );
	cheat_handle_vehicle_air_brake( info, time_diff );
	cheat_handle_vehicle_warp( info, time_diff );
	cheat_handle_vehicle_quick_turn( info, time_diff );
	cheat_handle_vehicle_brake( info, time_diff );
	cheat_handle_vehicle_hop( info, time_diff );
	cheat_handle_vehicle_engine( info, time_diff );
	cheat_handle_vehicle_brakedance( info, time_diff );
	cheat_handle_vehicle_blinking_carlights( info, time_diff );
	cheat_handle_vehicle_fly( info, time_diff );
	cheat_handle_vehicle_keepTrailer( info, time_diff );
	cheat_handle_vehicle_repair_car( info, time_diff );
	cheat_handle_vehicle_spiderWheels( info, time_diff );
	//cheat_handle_vehicle_slowTeleport( info, time_diff );
#ifdef __CHEAT_VEHRECORDING_H__
	cheat_handle_vehicle_recording( info, time_diff );
#endif

	// these NEED to stay last, because they can remove the player from the vehicle
	cheat_handle_vehicle_fast_exit( info, time_diff );
	cheat_handle_exit_vehicle ( info, NULL );
}
int rec_sqlite_getNumTables ()
{
	traceLastFunc( "rec_sqlite_getNumTables()" );

	sqlite3 *rec_db;
	int numTables;

	if ( sqlite3_open( REC_DB_NAME, &rec_db ) != SQLITE_OK )
	{
		Log( "SQLite - Error while connecting: %s", sqlite3_errmsg(rec_db) );
		sqlite3_close( rec_db );
		return -1;
	}

	numTables = sqliteDB_getNumTables( rec_db, true );
	sqlite3_close( rec_db );
	return numTables;
}
Beispiel #19
0
// update SAMPGTA vehicle translation structure
void update_translateGTASAMP_vehiclePool ( void )
{
	traceLastFunc( "update_translateGTASAMP_vehiclePool()" );
	if ( !g_Vehicles )
		return;

	int iGTAID;
	for ( int i = 0; i <= SAMP_VEHICLE_MAX; i++ )
	{
		if ( g_Vehicles->iIsListed[i] != 1 )
			continue;
		if ( isBadPtr_writeAny(g_Vehicles->pSAMP_Vehicle[i], sizeof(stSAMPVehicle)) )
			continue;
		iGTAID = getVehicleGTAIDFromInterface( (DWORD *)g_Vehicles->pSAMP_Vehicle[i]->pGTA_Vehicle );
		if ( iGTAID <= SAMP_VEHICLE_MAX && iGTAID >= 0 )
		{
			translateGTASAMP_vehiclePool.iSAMPID[iGTAID] = i;
		}
	}
}
bool rec_sqlite_dropTable ( char *tableName )
{
	traceLastFunc( "rec_sqlite_dropTable()" );

	sqlite3 *rec_db;
	bool return_val = false;

	if ( sqlite3_open( REC_DB_NAME, &rec_db ) != SQLITE_OK )
	{
		Log( "SQLite - Error while connecting: %s", sqlite3_errmsg(rec_db) );
		sqlite3_close( rec_db );
		return false;
	}

	return_val = sqliteDB_dropTable(rec_db, tableName);
	if ( return_val == true )
		cheat_state_text( "Dropped table '%s'", tableName );

	sqlite3_close( rec_db );
	return return_val;
}
int sqliteDB_getNumTables ( sqlite3 *db, bool filter_sqlite_tables )
{
	traceLastFunc( "sqliteDB_getNumTables()" );

	sqlite3_stmt *prep_stmt;
	int prep_step_ret;
	char sql_cmd[64];
	int num_tables;

	if ( db == NULL )
	{
		Log ( "sqliteDB_getNumTables: received db = NULL" );
		return -1;
	}

	num_tables = 0;

	_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "SELECT name FROM sqlite_master WHERE type='table';" );
	if ( sqlite3_prepare_v2( db, sql_cmd, sizeof(sql_cmd), &prep_stmt, NULL ) != SQLITE_OK )
	{
		Log( "SQLite - Error (preparing statement in getNumTables): %s", sqlite3_errmsg(db) );
		return -1;
	}
	prep_step_ret = sqlite3_step( prep_stmt );

	while ( prep_step_ret == SQLITE_ROW )
	{
		// filter sqlite_* tables
		if ( filter_sqlite_tables == false
			|| strncmp((char*)sqlite3_column_text(prep_stmt,0), "sqlite_", 7) != 0 )
			num_tables++;

		prep_step_ret = sqlite3_step( prep_stmt );
	}

	sqlite3_finalize( prep_stmt );
	return num_tables;
}
Beispiel #22
0
static void cheat_main_actor ( double time_diff )
{
	traceLastFunc( "cheat_main_actor()" );

	struct actor_info	*info = actor_info_get( ACTOR_SELF, 0 );
	if ( info == NULL )
	{
		Log( "wtf, actor_info_get() returned NULL." );
		return;
	}

	cheat_handle_antiHijack( info, NULL, time_diff );

	vect3_copy( &info->base.matrix[4 * 3], cheat_state->actor.coords );
	cheat_handle_freeze_vehicles( NULL, info );
	cheat_handle_hp( NULL, info, time_diff );
	cheat_handle_teleport( NULL, info, time_diff );
	cheat_handle_unfreeze( NULL, info, time_diff );
	cheat_handle_emo( NULL, info, time_diff );

	// the following functions can be found in cheat_actor.cpp
	cheat_handle_actor_air_brake( info, time_diff );
	cheat_handle_stick( NULL, info, time_diff );
	cheat_handle_actor_autoaim( info, time_diff );

	// cheat_handle_SpiderFeet(info, time_diff);
	cheat_handle_actor_fly(info, time_diff);

	if ( set.custom_runanimation_enabled )
		pPedSelf_setMoveAnimation__array( set.custom_runanimation_id );


	// these NEED to stay last, because they can remove the player from the vehicle
	if ( info->pedFlags.bInVehicle )
		cheat_handle_vehicle_fast_exit( NULL, time_diff );
	cheat_handle_exit_vehicle ( NULL, info );
}
Beispiel #23
0
static int init ( void )
{
	traceLastFunc( "init()" );

	if ( g_hOrigDll == NULL )
	{
		if ( GetModuleFileName(g_hDllModule, g_szWorkingDirectory, sizeof(g_szWorkingDirectory) - 32) != 0 )
		{
			if ( strrchr(g_szWorkingDirectory, '\\') != NULL )
				*strrchr( g_szWorkingDirectory, '\\' ) = 0;
			else
				strcpy( g_szWorkingDirectory, "." );
		}
		else
		{
			strcpy( g_szWorkingDirectory, "." );
		}

		// Hello World
		Log( "Initializing exe24 mod" );
		Log( "Compiled: %s CL:%d", COMPILE_DT, COMPILE_VERSION );

		// log windows version for people that forget to report it
		WindowsInfo.osPlatform = (int) * (DWORD *)GTAvar_osPlatform;
		WindowsInfo.osVer = (int) * (DWORD *)GTAvar_osVer;
		WindowsInfo.winVer = (int) * (DWORD *)GTAvar_winVer;
		WindowsInfo.winMajor = (int) * (DWORD *)GTAvar_winMajor;
		if ( WindowsInfo.osPlatform == 2 )
			Log( "OS: Windows Version %d.%d.%d", WindowsInfo.winMajor, WindowsInfo.winVer, WindowsInfo.osVer );
		else
			Log( "OS: Not Windows (%d.%d.%d)", WindowsInfo.winMajor, WindowsInfo.winVer, WindowsInfo.osVer );

#pragma warning( disable : 4127 )
		if ( sizeof(struct vehicle_info) != 2584 )
		{
			Log( "sizeof(struct vehicle_info) == %d, aborting.", sizeof(struct vehicle_info) );
			return 0;
		}

		if ( sizeof(struct actor_info) != 1988 )
		{
			Log( "sizeof(struct actor_info) == %d, aborting.", sizeof(struct actor_info) );
			return 0;
		}
#pragma warning( default : 4127 )

		ini_load();
		if ( !set.i_have_edited_the_ini_file )
		{
			MessageBox( 0, "Error when starting exe24.info mod.","Error", 0 );
			return 0;
		}

		// get SAMP and set g_dwSAMP_Addr
		getSamp();

		// get actual d3d9.dll and proxy original D3D9Device
		char	filename[MAX_PATH];
		if (fileExists(".\\d3d9_exe24+.dll"))
		{
			strlcat(filename, ".\\d3d9_exe24+.dll", sizeof(filename));
		}
		else
		{
			GetSystemDirectory(filename, (UINT)(MAX_PATH - strlen("\\d3d9.dll") - 1));
			strlcat(filename, "\\d3d9.dll", sizeof(filename));
		}
		g_hOrigDll = LoadLibrary( filename );
		if ( g_hOrigDll == NULL )
		{
			Log( "Failed to load %s", filename );
			return 0;
		}
		orig_Direct3DCreate9 = ( D3DC9 ) GetProcAddress( g_hOrigDll, "Direct3DCreate9" );
		if ( orig_Direct3DCreate9 == NULL )
		{
			Log( "%s does not export Direct3DCreate9!?", filename );
			FreeLibrary( g_hOrigDll );
			return 0;
		}
	}

	return 1;
}
void cheat_handle_vehicle_recording ( struct vehicle_info *info, float time_diff )
{
	char buffer[512];
	float set_speed[3];
	float set_spin[3];

	if ( info == NULL || !set.recording_activated )
		return;
	
	traceLastFunc( "cheat_handle_vehicle_recording()" );
	
	// recording key
	if ( KEY_PRESSED(set.key_recording_record) )
	{
		if ( rec_state == RECORDING_RECORD )
		{
			rec_maxNum = rec_index;
			rec_state = RECORDING_OFF;
			return;
		}
		else if ( rec_state == RECORDING_OFF )
		{
			rec_state = RECORDING_RECORD;
			rec_maxNum = 0;
			rec_index = 0;
			rec_playNext = 0.0f;
		}
	}

	if ( KEY_PRESSED(set.key_recording_continueAfterFinish) )
		rec_continueAfterFin ^= 1;

	// play keys
	if ( (KEY_PRESSED(set.key_recording_play) || KEY_PRESSED(set.key_recording_customSpeed)
		|| KEY_PRESSED(set.key_recording_rev) || KEY_PRESSED(set.key_recording_rev_customSpeed)) )
	{
		// if record playing
		if ( rec_state >= RECORDING_PLAY )
		{
			 rec_state = RECORDING_OFF;
			 return;
		}
		else if ( rec_state == RECORDING_OFF )
		{
			// something to play?
			if ( rec_maxNum <= 0 )
			{
				rec_state = RECORDING_OFF;
				return;
			}

			rec_index = 0;
			rec_playNext = 0.0f;

			
			if ( KEY_PRESSED(set.key_recording_play) )
				rec_state = RECORDING_PLAY;
			else if ( KEY_PRESSED(set.key_recording_customSpeed) )
				rec_state = RECORDING_PLAY_CUSTOMSPEED;
			else if ( KEY_PRESSED(set.key_recording_rev) )
			{
				rec_index = (rec_maxNum-1);
				rec_state = RECORDING_PLAY_REV;
			}
			else if ( KEY_PRESSED(set.key_recording_rev_customSpeed) )
			{
				rec_index = (rec_maxNum-1);
				rec_state = RECORDING_PLAY_REV_CUSTOMSPEED;
			}

			// user set a maximum distance to entry point?
			if ( set.recording_maxDistToEntryPoint > 0.0f )
			{
				// check if current selected index is in maxRange, else look for a point closest
				// to the selected beginning, which is in the maxRange
				if ( vect3_dist(rec_pos[rec_index], &info->base.matrix[4*3]) > set.recording_maxDistToEntryPoint )
				{
					int i = rec_index;
					int rec_index_new = -1;

					// not a entry point we want (too far), lets find a better one
					while ( i >= 0 && i < rec_maxNum )
					{
						if ( vect3_dist(rec_pos[i], &info->base.matrix[4*3]) <= set.recording_maxDistToEntryPoint )
						{
							rec_index_new = i;
							break;
						}
						if ( rec_state == RECORDING_PLAY_REV || rec_state == RECORDING_PLAY_REV_CUSTOMSPEED )
							i--;
						else
							i++;
					}

					// nothing close enough found
					if ( rec_index_new == -1 )
					{
						rec_state = RECORDING_OFF;
						cheat_state_text( "Too far from route - maxDist: %0.2f", set.recording_maxDistToEntryPoint );
					}
					else
						rec_index = rec_index_new;
				}
			}
		}
	}

	if ( rec_state == RECORDING_RECORD )
	{
		pD3DFont->PrintShadow( 99, 250, D3DCOLOR_ARGB(255, 255, 0, 0), "Vehicle Recording" );

		if ( (TIME_TO_FLOAT(time_get()) - rec_playNext) < 0.0f )
			return;
		
		vect3_copy( &info->base.matrix[4*3+0], rec_pos[rec_index] );

		vect3_copy( &info->base.matrix[4*0+0], &rec_angle[rec_index][0] );
		vect3_copy( &info->base.matrix[4*1+0], &rec_angle[rec_index][3] );

		vect3_copy( info->spin, rec_spin[rec_index] );
		vect3_copy( info->speed, rec_speed[rec_index] );

		rec_index++;
		rec_playNext = TIME_TO_FLOAT(time_get()) + TIME_TO_FLOAT((float)MSEC_TO_TIME(REC_DEFAULT_WAITTIME));
		if ( rec_index == (REC_ARRAYSIZE-1) )
		{
			rec_maxNum = rec_index;
			rec_state = RECORDING_OFF;
		}
	}
	// >= because only play states should follow after RECORDING_PLAY
	else if ( rec_state >= RECORDING_PLAY )
	{
		// deactivate playing records while air brakeing/sticking
		if ( cheat_state->vehicle.air_brake || cheat_state->vehicle.stick )
		{
			rec_state = RECORDING_OFF;
			return;
		}

		// move into some better place (maybe hud?)
		_snprintf_s( buffer, sizeof(buffer)-1, "Vehicle Play Record%s%s", (rec_state == RECORDING_PLAY_REV
			|| rec_state == RECORDING_PLAY_REV_CUSTOMSPEED) ? " (Rev)" : "",
			rec_continueAfterFin ? " (Continuously)" : "" );
		_snprintf_s( buffer, sizeof(buffer)-1, "%s%s", buffer, (rec_state == RECORDING_PLAY_REV_CUSTOMSPEED
			|| rec_state == RECORDING_PLAY_CUSTOMSPEED) ? " (Custom Speed)" : "" );
		pD3DFont->PrintShadow( 99, 250, D3DCOLOR_ARGB(255, 0, 255, 0), buffer );

		// will need overtime variable for data row skipping
		float overtime = (TIME_TO_FLOAT(time_get()) - rec_playNext);

		// do nothing, if the planned next-frame time wasn't reached yet
		if ( overtime < 0.0f )
			return;
		
		vect3_copy( rec_pos[rec_index], &info->base.matrix[4*3+0] );

		vect3_copy( &rec_angle[rec_index][0], &info->base.matrix[4*0+0] );
		vect3_copy( &rec_angle[rec_index][3], &info->base.matrix[4*1+0] );

		vect3_copy( rec_spin[rec_index], set_spin );
		vect3_copy( rec_speed[rec_index], set_speed );		

		// multiply speed/spin (for ff mode) and set the playNextTick
		if ( rec_state == RECORDING_PLAY_CUSTOMSPEED || rec_state == RECORDING_PLAY_REV_CUSTOMSPEED )
		{
			vect3_mult( set_spin, set.recording_play_customSpeed, set_spin );
			vect3_mult( set_speed, set.recording_play_customSpeed, set_speed );

			// custom speed multiplier faster/higher than possible to play one by one?
			// if its not the first point (rec_playNext still default) skip a few 
			if ( overtime > 0.0f && rec_playNext != 0.0f )
			{
				// (now-plannedArrival) = overtime -> plannedArrival is way back in the past [so we gotta skip
				//   some of the rows to keep up with the recording/show it 'fluent' (or at least somehow timed correct)]

				// determine how many data rows we gotta skip ((now-plannedArrival)/timePerRow)
				float skipAble = overtime / (float)(TIME_TO_FLOAT((float)MSEC_TO_TIME(REC_DEFAULT_WAITTIME))/set.recording_play_customSpeed);
				if ( skipAble > 1.0f )
				{
					int skipAFew = ceil(skipAble);
					if ( skipAFew > 0 && rec_state >= RECORDING_PLAY_REV )
						rec_index -= skipAFew;
					else if ( skipAFew > 0 )
						rec_index += skipAFew;
				}
			}

			// calculate the time for the next data row
			rec_playNext = TIME_TO_FLOAT(time_get())
				+ (TIME_TO_FLOAT((float)MSEC_TO_TIME(REC_DEFAULT_WAITTIME))/set.recording_play_customSpeed );
		}
		else
		{
			// in case REC_DEFAULT_WAITTIME is too low, or this code is running on a slow computer
			// (or player tabbed/paused the game and refocuses the gta window)
			if ( overtime > 0.0f && rec_playNext != 0.0f )
			{
				// determine how many data rows we gotta skip
				float skipAble = overtime / (float)(TIME_TO_FLOAT(MSEC_TO_TIME(REC_DEFAULT_WAITTIME)));
				if ( skipAble > 1.0f )
				{
					int skipAFew = ceil(skipAble);
					if ( skipAFew > 0 && rec_state >= RECORDING_PLAY_REV )
						rec_index -= skipAFew;
					else if ( skipAFew > 0 )
						rec_index += skipAFew;
				}
			}

			rec_playNext = TIME_TO_FLOAT(time_get()) + TIME_TO_FLOAT(MSEC_TO_TIME(REC_DEFAULT_WAITTIME));
		}

		// inverse speed/spin (for rev mode) and set rec_index
		if ( rec_state >= RECORDING_PLAY_REV )
		{
			vect3_mult( set_spin, -1.0f, set_spin );
			vect3_mult( set_speed, -1.0f, set_speed );
			rec_index--;

			// reached end of recording
			if ( rec_index <= 0 )
			{
				if ( !rec_continueAfterFin )
					rec_state = RECORDING_OFF;
				else
				{
					if ( set.recording_maxDistToEntryPoint > 0.0f )
					{
						// deactivate, if new starting position is too far from this point
						if ( vect3_dist(rec_pos[rec_index], rec_pos[(rec_maxNum-1)]) > set.recording_maxDistToEntryPoint )
							rec_state = RECORDING_OFF;
					}
					rec_index = (rec_maxNum-1);
				}
			}
		}
		else
		{
			rec_index++;

			// reached end of recording
			if ( (rec_index >= (REC_ARRAYSIZE-1) || rec_index >= rec_maxNum) )
			{
				if ( !rec_continueAfterFin )
					rec_state = RECORDING_OFF;
				else
				{
					if ( set.recording_maxDistToEntryPoint > 0.0f )
					{
						// deactivate, if new starting position is too far from this point
						if ( vect3_dist(rec_pos[rec_index], rec_pos[0]) > set.recording_maxDistToEntryPoint )
							rec_state = RECORDING_OFF;
					}
					rec_index = 0;
				}
			}
		}	
		
		// copy new speed/spin after it has been adjusted for ff/rev mode
		vect3_copy( set_spin, info->spin );
		vect3_copy( set_speed, info->speed );			
	}
	else
	{
		rec_state = RECORDING_OFF;
	}
}
int HookedRakClientInterface::GetLowestPing( void ) const
{		
	traceLastFunc( "HookedRakClientInterface::GetLowestPing" );

	return g_RakClient->GetRakClientInterface()->GetLowestPing();
}
Beispiel #26
0
static int init ( void )
{
	traceLastFunc( "init()" );

	if ( g_hOrigDll == NULL )
	{
		if ( GetModuleFileName(g_hDllModule, g_szWorkingDirectory, sizeof(g_szWorkingDirectory) - 32) != 0 )
		{
			if ( strrchr(g_szWorkingDirectory, '\\') != NULL )
				*strrchr( g_szWorkingDirectory, '\\' ) = 0;
			else
				strcpy( g_szWorkingDirectory, "." );
		}
		else
		{
			strcpy( g_szWorkingDirectory, "." );
		}

		// Hello World
		Log( "Initializing %s", NAME );
		Log( "Compiled: %s CL:%d", COMPILE_DT, COMPILE_VERSION );

		// log windows version for people that forget to report it
		WindowsInfo.osPlatform = (int) * (DWORD *)GTAvar_osPlatform;
		WindowsInfo.osVer = (int) * (DWORD *)GTAvar_osVer;
		WindowsInfo.winVer = (int) * (DWORD *)GTAvar_winVer;
		WindowsInfo.winMajor = (int) * (DWORD *)GTAvar_winMajor;
		if ( WindowsInfo.osPlatform == 2 )
			Log( "OS: Windows Version %d.%d.%d", WindowsInfo.winMajor, WindowsInfo.winVer, WindowsInfo.osVer );
		else
			Log( "OS: Not Windows (%d.%d.%d)", WindowsInfo.winMajor, WindowsInfo.winVer, WindowsInfo.osVer );

		/*
		int D3D9UseVersion = (int)*(DWORD*)GTAvar__D3D9UseVersion;
		Log("D3D9UseVersion: %d", D3D9UseVersion);
		int DXVersion = (int)*(DWORD*)GTAvar__DXVersion;
		Log("DXVersion: %d", DXVersion);
		int windowsVersion = (int)*(DWORD*)GTAvar__windowsVersion;
		Log("windowsVersion: %d", windowsVersion);
		int CPUSupportsMMX = (int)*(DWORD*)__rwD3D9CPUSupportsMMX;
		int CPUSupports3DNow = (int)*(DWORD*)__rwD3D9CPUSupports3DNow;
		int CPUSupportsSSE = (int)*(DWORD*)__rwD3D9CPUSupportsSSE;
		int CPUSupportsSSE2 = (int)*(DWORD*)__rwD3D9CPUSupportsSSE2;
		if (!CPUSupportsMMX)
			Log("CPU Supports MMX: %d", CPUSupportsMMX);
		if (!CPUSupports3DNow)
			Log("CPU Supports 3DNow: %d", CPUSupports3DNow);
		if (!CPUSupportsSSE)
			Log("CPU Supports SSE: %d", CPUSupportsSSE);
		if (!CPUSupportsSSE2)
			Log("CPU Supports SSE2: %d", CPUSupportsSSE2);
		*/
#pragma warning( disable : 4127 )
		if ( sizeof(struct vehicle_info) != 2584 )
		{
			Log( "sizeof(struct vehicle_info) == %d, aborting.", sizeof(struct vehicle_info) );
			return 0;
		}

		if ( sizeof(struct actor_info) != 1988 )
		{
			Log( "sizeof(struct actor_info) == %d, aborting.", sizeof(struct actor_info) );
			return 0;
		}
#pragma warning( default : 4127 )

		ini_load();
		if ( !set.i_have_edited_the_ini_file )
		{
			MessageBox( 0, "Looks like you've not edited the .ini file like you were told to!\n""\n"
				"Before you can use mod_sa, you have to set \"i_have_edited_the_ini_file\" to true.\n"
				"We did this so you would read the INI file to see the configurability of mod_sa.\n",
				"You're a retard.", 0 );
			ShellExecute( 0, "open", "notepad", INI_FILE, g_szWorkingDirectory, SW_SHOW );
			return 0;
		}

		// get SAMP and set g_dwSAMP_Addr
		getSamp();

		// get actual d3d9.dll and proxy original D3D9Device
		char	filename[MAX_PATH];
		GetSystemDirectory( filename, (UINT) (MAX_PATH - strlen("\\d3d9.dll") - 1) );
		strlcat( filename, "\\d3d9.dll", sizeof(filename) );
		g_hOrigDll = LoadLibrary( filename );
		if ( g_hOrigDll == NULL )
		{
			Log( "Failed to load %s", filename );
			return 0;
		}
		orig_Direct3DCreate9 = ( D3DC9 ) GetProcAddress( g_hOrigDll, "Direct3DCreate9" );
		if ( orig_Direct3DCreate9 == NULL )
		{
			Log( "%s does not export Direct3DCreate9!?", filename );
			FreeLibrary( g_hOrigDll );
			return 0;
		}
	}

	return 1;
}
bool rec_sqlite_writeTable ()
{
	traceLastFunc( "rec_sqlite_writeTable()" );

	sqlite3 *rec_db;
	char sql_cmd[1024];
	char *errmsgs = NULL;
	int ret_exists;

	if ( rec_state == RECORDING_RECORD )
	{
		cheat_state_text( "Can't save while recording." );
		return false;
	}

	if ( rec_maxNum <= 0 )
	{
		cheat_state_text( "Nothing to be saved." );
		return false;
	}

	if ( sqlite3_open( REC_DB_NAME, &rec_db ) != SQLITE_OK )
	{
		Log( "SQLite - Error while connecting: %s", sqlite3_errmsg(rec_db) );
		sqlite3_close( rec_db );
		return false;
	}

	for ( int i = 0; i < 64; i++ ) // max default name
	{
		_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "route%i", i );
		ret_exists = sqliteDB_checkTableExists( rec_db, sql_cmd );
		// continue, if table already exists
		if ( ret_exists == 1 )
			continue;
		// quit function on fail
		if ( ret_exists == -1 )
		{
			sqlite3_close( rec_db );
			return false;
		}

		// create table with default name 'route..'
		_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "CREATE TABLE 'route%i'(", i );
		_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "%s 'index' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," \
			"'maxNum' INTEGER NULL DEFAULT NULL," \
			"'angle1' REAL NOT NULL,'angle2' REAL NOT NULL,'angle3' REAL NOT NULL,'angle4' REAL NOT NULL," \
			"'angle5' REAL NOT NULL,'angle6' REAL NOT NULL,"\
			"'spin1' REAL NOT NULL,'spin2' REAL NOT NULL,'spin3' REAL NOT NULL," \
			"'speed1' REAL NOT NULL,'speed2' REAL NOT NULL,'speed3' REAL NOT NULL," \
			"'pos1' REAL NOT NULL,'pos2' REAL NOT NULL,'pos3' REAL NOT NULL);"
			, sql_cmd );
		sqlite3_exec( rec_db, sql_cmd, NULL, NULL, &errmsgs );
		if ( errmsgs != NULL )
		{
			Log( "SQLite - Error (executing CREATE TABLE statement): %s", errmsgs );
			sqlite3_close( rec_db );
			return false;
		}

		// add our data into the new table
		for ( int j = 0; j < rec_maxNum && j < (REC_ARRAYSIZE-1); j++ )
		{
			if ( j != 0 )
				_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "INSERT INTO 'route%i' VALUES( null, null,", i );
			else
				_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "INSERT INTO 'route%i' VALUES( null, %i,", i, rec_maxNum );
			_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "%s %0.2f, %0.2f, %0.2f, %0.2f,"
				"%0.2f, %0.2f," \
				"%0.2f, %0.2f, %0.2f," \
				"%0.2f, %0.2f, %0.2f," \
				"%0.2f, %0.2f, %0.2f" \
				");", 
				sql_cmd, rec_angle[j][0], rec_angle[j][1], rec_angle[j][2], rec_angle[j][3], 
				rec_angle[j][4], rec_angle[j][5],
				rec_spin[j][0], rec_spin[j][1], rec_spin[j][2],
				rec_speed[j][0], rec_speed[j][1], rec_speed[j][2],
				rec_pos[j][0], rec_pos[j][1], rec_pos[j][2] );

			//Log( sql_cmd );
			sqlite3_exec( rec_db, sql_cmd, NULL, NULL, &errmsgs );
			if ( errmsgs != NULL )
			{
				Log( "SQLite - Error (executing INSERT INTO statement): %s", errmsgs );
				sqlite3_close( rec_db );
				return false;
			}
		}

		cheat_state_text( "saved to 'route%i'", i );
		break;
	}

	sqlite3_close( rec_db );
	return true;
}
bool rec_sqlite_loadTable ( char *tableName )
{
	traceLastFunc( "rec_sqlite_loadTable()" );

	sqlite3 *rec_db;
	sqlite3_stmt *prep_stmt;
	int prep_step_ret;
	char sql_cmd[1024];

	if ( sqlite3_open( REC_DB_NAME, &rec_db ) != SQLITE_OK )
	{
		Log( "SQLite - Error while connecting: %s", sqlite3_errmsg(rec_db) );
		sqlite3_close( rec_db );
		return false;
	}

	// return false, if error happens, or table doesn't exist
	if ( sqliteDB_checkTableExists( rec_db, tableName ) != 1 )
	{
		sqlite3_close( rec_db );
		cheat_state_text( "table doesn't exist" );
		return false;
	}

	// stop playing/recording when loading a new route
	rec_state = RECORDING_OFF;

	_snprintf_s( sql_cmd, sizeof(sql_cmd)-1, "SELECT * FROM '%s';", tableName );
	if ( sqlite3_prepare_v2( rec_db, sql_cmd, sizeof(sql_cmd), &prep_stmt, NULL ) != SQLITE_OK )
	{
		Log( "SQLite - Error (prepare statement to load from table '%s'): %s", tableName, sqlite3_errmsg(rec_db) );
		sqlite3_close( rec_db );
		return false;
	}

	// jump to first row and set the maxNum
	prep_step_ret = sqlite3_step( prep_stmt );
	rec_maxNum = sqlite3_column_int(prep_stmt,1);

	if ( rec_maxNum > (REC_ARRAYSIZE-1) || rec_maxNum <= 0 )
	{
		Log( "Recording - load table '%s': rec_maxNum(%i) is <= 0 or greater than maximum array size!", 
			tableName, rec_maxNum );
		sqlite3_finalize( prep_stmt );
		sqlite3_close( rec_db );

		cheat_state_text( "failed to load" );
		// we changed a variable, so set maxNum to 0, so it can't be 
		// causing problems when trying to play record
		rec_maxNum = 0;
		return false;
	}

	for ( int i = 0; i < rec_maxNum; i++ )
	{
		// load our data from the table
		// do not forget to adjust these offsets when changing table design
		for ( int j = 0; j < 6; j++ )
			rec_angle[i][j] = sqlite3_column_double( prep_stmt, j+2 );
		for ( int j = 0; j < 3; j++ )
		{
			rec_spin[i][j] = sqlite3_column_double( prep_stmt, j+8 );
			rec_speed[i][j] = sqlite3_column_double( prep_stmt, j+11 );
			rec_pos[i][j] = sqlite3_column_double( prep_stmt, j+14 );
		}

		prep_step_ret = sqlite3_step( prep_stmt );
		
		// step() returned some error/unexpected value?
		if ( prep_step_ret != SQLITE_ROW && prep_step_ret != SQLITE_DONE )
		{
			Log( "SQLite - Error (prepare statement to load from table '%s' - cycle %i): %s", tableName, i, sqlite3_errmsg(rec_db) );
			sqlite3_finalize( prep_stmt );
			sqlite3_close( rec_db );
			
			cheat_state_text( "failed to load" );
			// data has been changed.. destroy record for playback
			rec_maxNum = 0;
			return false;
		}

		// we somehow reached the end (end of rows/end of loop)
		if ( i == (rec_maxNum-1) || prep_step_ret == SQLITE_DONE )
		{
			// check if its only end of one = error while loading
			if ( i != (rec_maxNum-1) || prep_step_ret != SQLITE_DONE )
			{
				Log( "Problem while loading Recording '%s': %s - MaxNum %i - cycleNum %i",
					tableName,
					prep_step_ret == SQLITE_DONE ? "End of rows" : "Not at end of rows",
					rec_maxNum, i );
				sqlite3_finalize( prep_stmt );
				sqlite3_close( rec_db );

				cheat_state_text( "failed to load" );
				// we probably got incorrect data in the recording? - set maxNum to 0
				rec_maxNum = 0;
				return false;
			}

			// we reached the end of rows at expected time (when the loop reaches maxNum-1)
			cheat_state_text( "successfully loaded route" );
		}		
	}
	sqlite3_finalize( prep_stmt );
	sqlite3_close( rec_db );
	return true;
}
Beispiel #29
0
void cmd_change_server ( char *param )	//127.0.0.1 7777 Username Password
{
	traceLastFunc( "cmd_change_server()" );

	char	*result;
	bool	success = false;

	char	IP[257], LocalName[MAX_PLAYER_NAME];
	int		Port;
	strcpy( IP, g_SAMP->szIP );
	Port = g_SAMP->ulPort;
	strcpy( LocalName, getPlayerName(g_Players->sLocalPlayerID) );

	result = strtok( param, " :" );
	for ( int i = 0; i <= 4; i++ )
	{
		if ( result == NULL && !success )
		{
			addMessageToChatWindow( "USAGE: /m0d_change_server <ip> <port> <Username> <Server Password>" );
			addMessageToChatWindow( "Variables that are set to \"NULL\" (capitalized) will be ignored." );
			addMessageToChatWindow( "If you set the Password to \"NULL\" it is set to <no server password>." );
			addMessageToChatWindow( "Username and password can also be left out completely." );
			strcpy( g_SAMP->szIP, IP );
			g_SAMP->ulPort = Port;
			setLocalPlayerName( LocalName );
			return;
		}
		else if ( result == NULL && success )
		{
			joining_server = 1;
			return;
		}

		switch ( i )
		{
		case 0:
			if ( strcmp(result, "NULL") != 0 )
				strcpy( g_SAMP->szIP, result );
			break;

		case 1:
			if ( strcmp(result, "NULL") != 0 )
				g_SAMP->ulPort = atoi( result );
			success = true;
			break;

		case 2:
			if ( strcmp(result, "NULL") != 0 )
			{
				if ( strlen(result) > ALLOWED_PLAYER_NAME_LENGTH )
					addMessageToChatWindow( "Username was too long - adjusted size." );
				strncpy_s( LocalName, result, ALLOWED_PLAYER_NAME_LENGTH );
				setLocalPlayerName( LocalName );
			}
			break;

		case 3:
			if ( strcmp(result, "NULL") != 0 )
				setPassword( result );
			else
				setPassword( "" );
			break;

		default:
			{
				addMessageToChatWindow( "Too many variables." );
				addMessageToChatWindow( "USAGE: /m0d_change_server <ip> <port> <Username> <Server Password>" );
				addMessageToChatWindow( "Variables that are set to \"NULL\" (capitalized) will be ignored." );
				addMessageToChatWindow( "If you set the Password to \"NULL\" it is set to <no server password>." );
				addMessageToChatWindow( "Username and password can also be left out completely." );
				strcpy( g_SAMP->szIP, IP );
				g_SAMP->ulPort = Port;
				strcpy( LocalName, getPlayerName(g_Players->sLocalPlayerID) );
				if ( i >= 3 )
				{
					addMessageToChatWindow( "Setting password to <no server password>." );
					setPassword( "" );
				}

				return;
			}
		}

		result = strtok( NULL, " :" );
	}
}
Beispiel #30
0
// strtokstristr?
bool findstrinstr ( char *text, char *find )
{
	char	realtext[256];
	char	subtext[256];
	char	*result;
	char	*next;
	char	temp;
	int		i = 0;

	traceLastFunc( "findstrinstr()" );

	// can't find stuff that isn't there unless you are high
	if ( text == NULL || find == NULL )
		return false;

	// lower case text ( sizeof()-2 = 1 for array + 1 for termination after while() )
	while ( text[i] != NULL && i < (sizeof(realtext)-2) )
	{
		temp = text[i];
		if ( isupper(temp) )
			temp = tolower( temp );
		realtext[i] = temp;
		i++;
	}
	realtext[i] = 0;

	// replace unwanted characters/spaces with dots
	i = 0;
	while ( find[i] != NULL && i < (sizeof(subtext)-2) )
	{
		temp = find[i];
		if ( isupper(temp) )
			temp = tolower( temp );
		if ( !isalpha(temp) )
			temp = '.';
		subtext[i] = temp;
		i++;
	}
	subtext[i] = 0;

	// use i to count the successfully found text parts
	i = 0;

	// split and find every part of subtext/find in text
	result = &subtext[0];
	while ( *result != NULL )
	{
		next = strstr( result, "." );
		if ( next != NULL )
		{
			// more than one non-alphabetic character
			if ( next == result )
			{
				do
					next++;
				while ( *next == '.' );

				if ( *next == NULL )
					return (i != 0);
				result = next;
				next = strstr( result, "." );
				if ( next != NULL )
					*next = NULL;
			}
			else
				*next = NULL;
		}

		if ( strstr(realtext, result) == NULL )
			return false;

		if ( next == NULL )
			return true;

		i++;
		result = next + 1;
	}

	return false;
}