Example #1
0
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
bool VoidBot::PublicCommands(const char* SessionID, const String& Command)
{
// todo: these should all be busted out into their own functions

	// "Message For" command
	String keyword("message for");
	int32 pos = WholeWordPos(Command, keyword.Cstr());
	if( B_ERROR != pos )
	{
		if( 2048 < Command.Length() )
		{
			SendMessage(SessionID, "There is _no way_ I can remember all that, please phrase the message shorter.");
			return true;
		}

		pos += keyword.Length();
		String name(GetNick(Command, pos));
		if( 0 == name.Length() )
		{
			SendMessage(SessionID, "Please specify a nick!");
			return true;
		}

		if( B_ERROR != name.IndexOf(' ') )
		{
			// name with space, adjust for delimiter chars.
			pos += 2;
		}

		pos += name.Length() + 1;

		if( (int32)Command.Length() < (pos - 1) )
		{
			SendMessage(SessionID, "Please specify a message.");
			return true;
		}

		String message("Message from ");
		message += fData.UserByID(SessionID)->Name();
		message += " Left at";
		message += " [";
		message += Time();
		message += "]";
		message += ": ";
		message += Command.Substring(pos);
		fMessagesForName[name].push_back(message);
		SendPrivateMessage(SessionID, "Will there be anything else?.");
		fReportedNewMessages[name] = false;
		return true;
	}

	// "Seen" command
	keyword = "seen";
	pos = WholeWordPos(Command, keyword.Cstr());
	if( -1 != pos )
	{
		pos += keyword.Length();

		String name(GetNick(Command, pos));
		if( 0 == name.Length() )
		{
			SendMessage(SessionID, "Please specify a nick!");
			return true;
		}

		if( fLastWords.find(name.Cstr()) != fLastWords.end() )
		{
			String info(name);
			info += " was last seen ";
			info += fLastWords[name.Cstr()];
			SendMessage(SessionID, info.Cstr());
		}
		else
		{
			String negatory("No, I haven't seen ");
			negatory += name;
			SendMessage(SessionID, negatory.Cstr());
		}
		return true;
	}

		//*****************<FORTUNE ADDED BY MISZA>************************//
	pos = WholeWordPos(Command, "fortune");
	if(-1 != pos)
	{
		FILE *fp = popen ("fortune", "r");
		if(fp != NULL)
		{
			char ch;
			String cool= "\n";

			while((ch = fgetc(fp))!= EOF)
			{
				cool += ch;
			}

			fclose(fp);
			if(cool != "\n")
			{
				cool = cool.Substring(0,(cool.Length()-1));
				SendPrivateMessage(SessionID,cool.Cstr());
			}
		}
		return true;
	}
	//*****************</FORTUNE ADDED BY MISZA>************************//

	// "GMTime" command
	pos = WholeWordPos(Command, "gmtime");
	if( -1 != pos )
	{
		String info("The time is: ");
		info += Time();
		SendMessage(SessionID, info.Cstr());
		return true;
	}

	// "Time" command
	pos = WholeWordPos(Command, "time");
	if( -1 != pos )
	{
		String info("The time is: ");
		info += MyTime();
		SendMessage(SessionID, info.Cstr());
		return true;
	}

	// "iTime" command
	pos = WholeWordPos(Command, "itime");
	if( -1 != pos )
	{
		String info("The time is: ");
		info += NetTime();
		SendMessage(SessionID, info.Cstr());
		return true;
	}

	// "Atrus" Prevent messages to bebop
	keyword = "message for bebop";
	pos = WholeWordPos(Command, keyword.Cstr());
	if( B_ERROR != pos )
	{
		SendPrivateMessage(SessionID, "You didn't say the magic word...");

			return true;
	}

	// "Atrus" Prevent messages to Atrus
	keyword = "message for Atrus";
	pos = WholeWordPos(Command, keyword.Cstr());
	if( B_ERROR != pos )
	{
		SendPrivateMessage(SessionID, "You didn't say the magic word...");

			return true;
	}

	// "Atrus" Prevent messages to Bubbles
	keyword = "message for Bubbles";
	pos = WholeWordPos(Command, keyword.Cstr());
	if( B_ERROR != pos )
	{
		SendPrivateMessage(SessionID, "You didn't say the magic word...");

			return true;
	}

	// "Atrus" Prevent messages to FAQbot
	keyword = "message for FAQbot";
	pos = WholeWordPos(Command, keyword.Cstr());
	if( B_ERROR != pos )
	{
		SendPrivateMessage(SessionID, "You didn't say the magic word...");

			return true;
	}

	// "Messages" command
	pos = WholeWordPos(Command, "messages");
	if( B_ERROR != pos )
	{
		bool messages = false;
		uint32 quantity = 0;
		const char* name = fData.UserByID(SessionID)->Name();

		if( fMessagesForName.find(name) != fMessagesForName.end() )
		{
			quantity = fMessagesForName[name].size();

			if( quantity != 0 )
			{
				messages = true;
			}
		}

		if( true == messages )
		{
			for( uint32 i = 0; i < quantity; i++ )
			{
				SendPrivateMessage(SessionID, fMessagesForName[name][i].Cstr());
			}

			fMessagesForName[name].clear();
			fReportedNewMessages[name] = true;
		}
		else
		{
			String reply("Sorry ");
			reply += fData.UserByID(SessionID)->Name();
			reply += ", You get nothing and like it!";
			SendPrivateMessage(SessionID, reply.Cstr());
		}

		return true;
	}

	// "Version" command
	pos = WholeWordPos(Command, "version");
	if( B_ERROR != pos )
	{
		// The version string is made up of MAJOR_RELEASE.MINOR_RELEASE.BUG_FIXES
		SendPrivateMessage(SessionID, "I am at version 2.1 (MUSCLE " MUSCLE_VERSION_STRING ")");
		return true;
	}

	pos = WholeWordPos(Command, "catsup");
	if( B_ERROR != pos )
	{
		// Figure out how many lines of chat to return
		pos++;
		pos += strlen("catsup");

		uint32 lines;
		if( (uint32)pos < Command.Length() )
		{
			lines = (uint32)atoi(&(Command.Cstr()[pos]));
			if( 0 == lines )
			{
				lines = kDefaultChatHistory;
			}
		}
		else
		{
			lines = 25;
		}

		if( lines > fChatHistory.size() )
		{
			lines = fChatHistory.size();
		}

		String chatText("\n");
		for( uint32 i = lines; i > 0 ; i-- )
		{
			chatText += fChatHistory[i-1];
			chatText += "\n";
		}

		SendPrivateMessage(SessionID, chatText.Cstr());
		return true;
	}

	// "Email" command
	keyword = "email";
	pos = WholeWordPos(Command, keyword.Cstr());
	if( -1 != pos )
	{
		pos += keyword.Length();

		String name(GetNick(Command, pos));
		if( 0 == name.Length() )
		{
			SendPrivateMessage(SessionID, "Please specify a nick!");
			return true;
		}

		{
			String fullname(botPath);
			fullname += "/email/";
			fullname += name;
			if(!SendTextfile(SessionID, fullname.Cstr(), false))
			{
				SendPrivateMessage(SessionID, "No email address found for that nick!");
			}
			return true;
		}
	}

	// "Gimme" command (v.2)
	keyword = "gimme";
	pos = WholeWordPos(Command, keyword.Cstr());
	if( -1 != pos )
	{
		pos += keyword.Length();

		String name(GetNick(Command, pos));
		if( 0 == name.Length() )
		{
			SendPrivateMessage(SessionID, "Please specify help page!");
			return true;
		}

		{
			String fullname(botPath);
			fullname += "/faq/";
			fullname += name;
			return SendTextfile(SessionID, fullname.Cstr(), false);
		}
	}

	// Do all one word commands (aka send text file with same name to user)
	String name(Command.Substring( Command.IndexOf(" ") + 1));
	if ( 0 < name.Length() )
	{
		String fullname(botPath);
		fullname += "/commands/";
		fullname += name.Cstr();
		return SendTextfile(SessionID, fullname.Cstr(), false);
	}

	return false;
}
Example #2
0
void main()
{
	if (!CONFIG::get("saveFile", fileName))
	{
		char *pValue;
		size_t len;
		errno_t err = _dupenv_s(&pValue, &len, "USERPROFILE");
		if (err)
			fileName = string("C:\\savedcoords.txt");
		else
			fileName = string(pValue) + "\\Documents\\Rockstar Games\\GTA V\\savedcoords.txt";
	}

	sendPlayerMessage("GTAV DevHelper by Funtik Initialized");
	sendPlayerMessage("Press F6 to open chat textbox");

	auto loadEntities = []()
	{
		if (!CONFIG::loadList("devhelper/vehicles.txt", vehicles))
			sendPlayerMessage("Can not load devhelper/vehicles.txt", 255, 0, 0);
		else
		{
			maxVehNr = vehicles.size() - 1;
			sendPlayerMessage("Vehicles loaded", 0, 255, 0);
		}

		if (!CONFIG::loadList("devhelper/peds.txt", peds))
			sendPlayerMessage("Can not load devhelper/peds.txt", 255, 0, 0);
		else
		{
			maxPedNr = peds.size() - 1;
			sendPlayerMessage("Peds loaded", 0, 255, 0);
		}

		if (!CONFIG::loadList("devhelper/objects.txt", objects))
			sendPlayerMessage("Can not load devhelper/objects.txt", 255, 0, 0);
		else
		{
			maxObjNr = objects.size() - 1;
			sendPlayerMessage("Objects loaded", 0, 255, 0);
		}
	};
	thread(loadEntities).detach();

	while (true)
	{
		Player player = PLAYER::PLAYER_ID();
		Ped playerPed = PLAYER::PLAYER_PED_ID();
		if (ENTITY::DOES_ENTITY_EXIST(playerPed))
		{
			Hash model = ENTITY::GET_ENTITY_MODEL(playerPed);
			if (ENTITY::IS_ENTITY_DEAD(playerPed) || PLAYER::IS_PLAYER_BEING_ARRESTED(player, TRUE))
			{
				if (model != GAMEPLAY::GET_HASH_KEY("player_zero") &&
					model != GAMEPLAY::GET_HASH_KEY("player_one") &&
					model != GAMEPLAY::GET_HASH_KEY("player_two"))
				{
					model = GAMEPLAY::GET_HASH_KEY("player_zero");
					STREAMING::REQUEST_MODEL(model);
					while (!STREAMING::HAS_MODEL_LOADED(model))
						WAIT(0);
					PLAYER::SET_PLAYER_MODEL(player, model);
					PED::SET_PED_DEFAULT_COMPONENT_VARIATION(playerPed);
					STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(model);
					while (ENTITY::IS_ENTITY_DEAD(PLAYER::PLAYER_PED_ID()) || PLAYER::IS_PLAYER_BEING_ARRESTED(player, TRUE))
						WAIT(0);
				}
			}
		}
		if (modKitId != -1)
		{
			VEHICLE::SET_VEHICLE_MOD_KIT(lastVehId, modKitId);
			sendPlayerMessage("Your car\'s modkit changed", 0, 255, 0);
			modKitId = -1;
		}
		if (vehCreateId != -1)
		{
			stringstream buff;
			DWORD model = (vehCreateId == -2) ? vehHash : GAMEPLAY::GET_HASH_KEY((char *)vehicles[vehCreateId].c_str());
			buff << "Loading vehicle [" << vehCreateId << "] " << ((vehCreateId == -2) ? vehName : vehicles[vehCreateId]) << ", Hash = 0x" << std::hex << model;
			sendPlayerMessage(buff.str());
			if (STREAMING::IS_MODEL_IN_CDIMAGE(model) && STREAMING::IS_MODEL_A_VEHICLE(model))
			{
				STREAMING::REQUEST_MODEL(model);
				while (!STREAMING::HAS_MODEL_LOADED(model)) WAIT(0);
				Vector3 coords = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(PLAYER::PLAYER_PED_ID(), 0.0, 5.0, 0.0);
				Vehicle veh = VEHICLE::CREATE_VEHICLE(model, coords.x, coords.y, coords.z, 0.0, 1, 1);
				VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(veh);

				ENTITY::SET_ENTITY_HEADING(veh, ENTITY::GET_ENTITY_HEADING(PLAYER::PLAYER_PED_ID()));
				PED::SET_PED_INTO_VEHICLE(PLAYER::PLAYER_PED_ID(), veh, -1);

				WAIT(0);
				STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(model);
				ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&veh);
				sendPlayerMessage(string("Vehicle ") + ((vehCreateId == -2) ? vehName : vehicles[vehCreateId]) + " created.", 0, 255, 0);
			}
			else
			{
				sendPlayerMessage("Error when creating vehicle", 255, 0, 0);
			}
			vehCreateId = -1;
		}
		if (chatEnabled)
		{
			GRAPHICS::DRAW_RECT(0.0f, 0.0f, 0.9f, 0.645f, 0, 0, 0, 200);
			size_t first = (chatLines.size() > 10) ? (chatLines.size() - 10) : 0;
			for (size_t i = first, c = 0; i < chatLines.size(); ++i, ++c)
			{
				drawText(chatLines[i].text, 0.0f, ((float)c)*(0.03f), chatLines[i].r, chatLines[i].g, chatLines[i].b);
			}
			
		}
		if (chatWrite)
		{
			string chatText(curChatText);
			chatText.insert(chatText.begin() + cursorPos, '_');
			GRAPHICS::DRAW_RECT(0.0f, 0.340f, 0.9f, 0.040f, 125, 125, 125, 255);
			drawText("> " + chatText, 0.0f, 0.330f, 255, 255, 255);
			UI::SET_PAUSE_MENU_ACTIVE(false);
		}
		if (pedId != -1)
		{
			Hash skin = (pedId == -2) ? pedHash : GAMEPLAY::GET_HASH_KEY((char*)peds[pedId].c_str());
			if (STREAMING::IS_MODEL_IN_CDIMAGE(skin) && STREAMING::IS_MODEL_VALID(skin))
			{
				STREAMING::REQUEST_MODEL(skin);
				while (!STREAMING::HAS_MODEL_LOADED(skin))
					WAIT(0);
				PLAYER::SET_PLAYER_MODEL(PLAYER::PLAYER_ID(), skin);
				PED::SET_PED_DEFAULT_COMPONENT_VARIATION(PLAYER::PLAYER_PED_ID());
				STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(skin);
				sendPlayerMessage(string("Your model changed to ") + ((pedId == -2) ? pedName : peds[pedId]), 0, 200, 0);
			}
			else
				sendPlayerMessage("Unknown error!", 255, 0, 0);
			pedId = -1;
		}
		if (objectEditor)
		{
			/*for (unsigned i = 0; i < lil::Object::_data.size(); ++i)
			{
				Vector3 pos = lil::Object::_data[i]->GetPosition();
				GRAPHICS::DRAW_DEBUG_TEXT_2D("Object", pos.x, pos.y, pos.z, 255, 255, 255, 255);
			}*/
			Vector3 pos = playerObject->GetPosition();
			Vector3 rot = playerObject->GetRotation();
			drawText("Object parameters:", 0.1f, 0.8f, 255, 255, 255);
			char buff[256];
			sprintf_s(buff, "Position X: %.4f", pos.x);
			drawText(buff, 0.01f, 0.815f, 255, 255, 255);
			sprintf_s(buff, "Position Y: %.4f", pos.y);
			drawText(buff, 0.01f, 0.83f, 255, 255, 255);
			sprintf_s(buff, "Position Z: %.4f", pos.z);
			drawText(buff, 0.01f, 0.845f, 255, 255, 255);

			sprintf_s(buff, "Rotation X: %.4f", rot.x);
			drawText(buff, 0.01f, 0.86f, 255, 255, 255);
			sprintf_s(buff, "Rotation Y: %.4f", rot.y);
			drawText(buff, 0.01f, 0.875f, 255, 255, 255);
			sprintf_s(buff, "Rotation Z: %.4f", rot.z);
			drawText(buff, 0.01f, 0.89f, 255, 255, 255);
		}
		if (objId != -1)
		{
			Hash object = (objId == -2) ? pedHash : GAMEPLAY::GET_HASH_KEY((char*)objects[objId].c_str());
			if (STREAMING::IS_MODEL_VALID(object))
			{
				STREAMING::REQUEST_MODEL(object);
				while (!STREAMING::HAS_MODEL_LOADED(object))
					WAIT(0);
				if (!objectEditor)
				{
					objectEditor = true;
					GRAPHICS::SET_DEBUG_LINES_AND_SPHERES_DRAWING_ACTIVE(true);
					UI::DISPLAY_HUD(false);
					UI::DISPLAY_RADAR(false);
				}
				lil::Object *curObj = new lil::Object(object, objPos.x, objPos.y, objPos.z);
				playerObject = curObj;

				STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(object);
				ENTITY::SET_ENTITY_VISIBLE(PLAYER::PLAYER_PED_ID(), false);
				PLAYER::SET_PLAYER_CONTROL(PLAYER::PLAYER_ID(), false, 0);
				if(!CAM::DOES_CAM_EXIST(playerCam))
					playerCam = CAM::CREATE_CAMERA(0x19286a9, 0);
				if (CAM::DOES_CAM_EXIST(playerCam)) {
					CAM::SET_CAM_ACTIVE(playerCam, 1);
					CAM::RENDER_SCRIPT_CAMS(true, 0, playerCam, true, 0);
					playerObject->PointCam(playerCam);
				}
				sendPlayerMessage(string("Object created ") + ((objId == -2) ? objName : objects[objId]), 0, 200, 0);
			}
			else
				sendPlayerMessage("Unknown error!", 255, 0, 0);
			objId = -1;
		}
		WAIT(0);
	}
}