diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index a6cac369..da23f30a 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -11,6 +11,7 @@ #include #include #include +#include #include int target_friend_afk_counter[MAXPLAYERS][MAXPLAYERS + 1]; @@ -18,12 +19,12 @@ int target_friend[MAXPLAYERS + 1]; int target_enemy[MAXPLAYERS + 1]; bool human_too_close[MAXPLAYERS + 1]; bool bot_follow_tp[MAXPLAYERS + 1]; -int buttons_old[MAXPLAYERS + 1]; -int flags_old[MAXPLAYERS + 1]; int ports[7] = {48470, 48471, 48472, 48473, 48474, 48479, 48480}; //last three indexes are ports its sending udp from in plugin int server_ports[2] = {27015, 27035}; //server ports: ze, ze2 float client_old_coords[MAXPLAYERS + 1][3]; float targetfriend_prev_coords[MAXPLAYERS + 1][3]; +int has_to_jump_bots[MAXPLAYERS + 1]; +float coords_run_cmd[MAXPLAYERS + 1][3]; bool chat_cooldown = false; //socket for bot input @@ -33,6 +34,10 @@ Handle global_socket; Handle g_hTimer_pressing = null; Handle g_hTimer_bot_connect = null; +//cmdrun handle for gamedata txt +Handle g_hGetRunCmdPre; + + public Plugin myinfo = { name = "coordinates for the bot", @@ -51,6 +56,39 @@ public void OnPluginStart() target_enemy[i] = 0; OnClientPostAdminCheck(i); } + + Handle hGameConf; + if ((hGameConf = LoadGameConfigFile("OnPlayerRunCmdPre.games")) == INVALID_HANDLE) + { + SetFailState("Couldnt load \"OnPlayerRunCmd.games\" game config!"); + return; + } + + //CBasePlayer::PlayerRunCommand(CUserCmd*, IMoveHelper*) + int iGetRunCmdPre; + if ((iGetRunCmdPre = GameConfGetOffset(hGameConf, "GetRunCmdPre")) == -1) + { + delete hGameConf; + SetFailState("GameConfGetOffset(hGameConf, \"GetRunCmdPre\") failed!"); + return; + } + + if ((g_hGetRunCmdPre = DHookCreate(iGetRunCmdPre, HookType_Entity, ReturnType_Int, ThisPointer_CBaseEntity, OnGetRunCmdPre)) == INVALID_HANDLE) + { + delete hGameConf; + SetFailState("DHookCreate(iGetRunCmdPre, HookType_Entity, ReturnType_Int, ThisPointer_CBaseEntity, OnGetRunCmdPre) failed!"); + return; + } + + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && is_bot_player(i)) + { + if (g_hGetRunCmdPre != INVALID_HANDLE) + DHookEntity(g_hGetRunCmdPre, false, i); + } + } + //talking RegConsoleCmd("sm_autism", cmd_talk, "talking to the bot through java application"); RegConsoleCmd("sm_botrtv", cmd_botrtv, "making bots rtv"); @@ -64,6 +102,66 @@ public void OnPluginStart() g_hTimer_pressing = CreateTimer(0.30, recursive_pressing, _, TIMER_REPEAT); } + +public MRESReturn OnGetRunCmdPre(int entity, Handle hReturn) +{ + if (!IsValidEntity(entity)) + return MRES_Ignored; + + //check here if fell off edge, if did change some boolean around tell it to OnPlayerRunCmd when still on ground there + if (IsValidClient(entity) && IsPlayerAlive(entity) && !(GetEntityFlags(entity) & FL_ONGROUND) && !has_to_jump_bots[entity]) + { + has_to_jump_bots[entity] = 1; + } + + return MRES_Supercede; +} + + +public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon, int& subtype, int& cmdnum, int& tickcount, int& seed, int mouse[2]) +{ + //we use info we just got from OnPlayerRunCmdPre to determine if to jump + if (!IsValidClient(client) || !IsPlayerAlive(client) || !is_bot_player(client)) return Plugin_Continue; + if ((GetEntityMoveType(client) & MOVETYPE_LADDER) || GetEntProp(client, Prop_Data, "m_nWaterLevel") != 0) + { + return Plugin_Continue; + } + //make sure fell of an edge instead of actually jumping + //the implementation can still fail a bit in some cases but has to do for now. + // problems when using mousewheel, spacebar jumping seems to work + if (buttons & IN_JUMP && has_to_jump_bots[client] == 1) + { + has_to_jump_bots[client] = 2; + return Plugin_Continue; + } + if (has_to_jump_bots[client] == 1) + { + //teleport back on ground so can jump + TeleportEntity(client, coords_run_cmd[client], NULL_VECTOR, NULL_VECTOR); + buttons |= IN_JUMP; //jump + has_to_jump_bots[client] = 2; + CreateTimer(1.5, reset_jump, client); + } + else if (GetEntityFlags(client) & FL_ONGROUND) + { + GetEntPropVector(client, Prop_Send, "m_vecOrigin", coords_run_cmd[client]); + if (has_to_jump_bots[client] == 2) + { + has_to_jump_bots[client] = 0; + } + } + return Plugin_Continue; +} + +public Action reset_jump(Handle hTimer, int client) +{ + if (IsValidClient(client)) + { + has_to_jump_bots[client] = 0; + } + return Plugin_Continue; +} + public void OnPluginEnd() { if (g_hTimer_pressing != null) @@ -271,7 +369,9 @@ public Action bot_check_connect(Handle timer, any data) { //revert again to either 10 or 55 int max_allowed_players = 55; - if (client_count > max_allowed_players) + char current_map[128]; + GetCurrentMap(current_map, sizeof(current_map)); + if (client_count > max_allowed_players || StrEqual(current_map, "ze_paranoid_rezurrection_v11_9", false)) { Format(msg, sizeof(msg), "connect to ze2"); send_socket_msg(msg, strlen(msg), ports[0]); @@ -308,76 +408,7 @@ public Action bot_check_connect(Handle timer, any data) return Plugin_Continue; } -/* -public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype, - int cmdnum, int tickcount, int seed, const int mouse[2]) -{ - if (!IsClientInGame(client)) return; - if (is_bot_player(client)) - { - int flags = GetEntityFlags(client); - if (!(flags & FL_ONGROUND) && (flags_old[client] & FL_ONGROUND) && !(buttons_old[client] & IN_JUMP) && !(buttons & IN_JUMP) && (GetEntityMoveType(client) != MOVETYPE_LADDER) && GetEntProp(client, Prop_Data, "m_nWaterLevel") == 0) - { - float Vel[3], feet_origin[3], ground_pos[3], downwards[3]; - float velocity_addition_z_axis = 300.0; //300.0 - GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel); - Vel[2] += velocity_addition_z_axis; - - GetClientAbsOrigin(client, feet_origin); - downwards[0] = 90.0; - downwards[1] = 0.0; - downwards[2] = 0.0; - TR_TraceRayFilter(feet_origin, downwards, MASK_SOLID, RayType_Infinite, TraceRayDontHitSelf, client); - if (TR_DidHit()) - { - TR_GetEndPosition(ground_pos); - feet_origin[2] -= 10.0; - float ground_distance = GetVectorDistance(feet_origin, ground_pos); - if (ground_distance > 80) - { - float angles_eye[3]; - GetClientEyeAngles(client, angles_eye); - //feet_origin[2] += 10.0; - TR_TraceRayFilter(feet_origin, angles_eye, MASK_SOLID, RayType_Infinite, TraceRayDontHitSelf, client); - if (TR_DidHit()) - { - TR_GetEndPosition(ground_pos); - ground_distance = GetVectorDistance(feet_origin, ground_pos); - float forward_distance = GetVectorDistance(feet_origin, ground_pos); - if (forward_distance > 280) - { - float ClientPos[3]; - float Result[3]; - GetClientEyePosition(client, ClientPos); - MakeVectorFromPoints(ClientPos, ground_pos, Result); - NegateVector(Result); - GetVectorAngles(Result, Result); - TeleportEntity(client, NULL_VECTOR, Result, NULL_VECTOR); - bot_avoid_edge[client] = 0; - ApplyBoost(client, 350.0); - } - } - } - } - //SetEntPropVector(client, Prop_Data, "m_vecBaseVelocity", Vel); - TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel); - } - buttons_old[client] = buttons; - flags_old[client] = flags; - } -} -*/ -//this was for turning around to prevent falling off edges -void ApplyBoost(int client, float amount){ - float direction[3], vel[3]; - GetEntPropVector(client, Prop_Data, "m_vecVelocity", vel); - NormalizeVector(vel, direction); - ScaleVector(direction, amount); - AddVectors(vel, direction, vel); - TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vel); - //SetEntPropVector(client, Prop_Data, "m_vecBaseVelocity", vel); -} public bool is_bot_player(int client) { @@ -464,7 +495,8 @@ public Action recursive_pressing(Handle timer, any data) float friend_prev[3]; GetClientEyePosition(client, ClientPos); //if the bot cant see him anymore he around corner or teleported most likley. - //therefore a small distance check should also be needed + //therefore a small distance check should also be needed to assure that the bots take the + //teleporter float distance_prev_friend_prior = get_power_distance(previous_friend, targetfriend_prev_coords[client]); GetEntPropVector(previous_friend, Prop_Send, "m_vecOrigin", friend_prev); if (!IsPointVisible(ClientPos, friend_prev) && distance_prev_friend_prior > 500.0) @@ -646,13 +678,13 @@ public void trace_hulling_bot(int client) send_socket_msg(message, strlen(message), ports[1]); } if (is_autism_bot3(client)) - { + { send_socket_msg(message, strlen(message), ports[2]); - } + } if (is_autism_bot4(client)) { send_socket_msg(message, strlen(message), ports[3]); - } + } return; } //something blocks floor crouch @@ -890,6 +922,15 @@ public void OnClientPostAdminCheck(int client) target_friend_afk_counter[i][client] = 0; } } + if (is_bot_player(client)) + { + if (g_hGetRunCmdPre != INVALID_HANDLE) + DHookEntity(g_hGetRunCmdPre, false, client); + } + coords_run_cmd[client][0] = 0.0; + coords_run_cmd[client][1] = 0.0; + coords_run_cmd[client][2] = 0.0; + has_to_jump_bots[client] = 0; //checks if ze or ze2 int i_port = GetConVarInt(FindConVar("hostport")); char msg[generic_length]; @@ -960,11 +1001,15 @@ public void OnClientDisconnect(int client) client_old_coords[client][0] = 0.0; client_old_coords[client][1] = 0.0; client_old_coords[client][2] = 0.0; + coords_run_cmd[client][0] = 0.0; + coords_run_cmd[client][1] = 0.0; + coords_run_cmd[client][2] = 0.0; targetfriend_prev_coords[client][0] = 0.0; targetfriend_prev_coords[client][1] = 0.0; targetfriend_prev_coords[client][2] = 0.0; human_too_close[client] = false; bot_follow_tp[client] = false; + has_to_jump_bots[client] = 0; for (int i = 1; i <= MaxClients; i++) { if (IsValidClient(i) && is_bot_player(i) && i != client) diff --git a/AutismBotIngame/scripting/gamedata/OnPlayerRunCmdPre.games.txt b/AutismBotIngame/scripting/gamedata/OnPlayerRunCmdPre.games.txt new file mode 100644 index 00000000..53c911b1 --- /dev/null +++ b/AutismBotIngame/scripting/gamedata/OnPlayerRunCmdPre.games.txt @@ -0,0 +1,14 @@ +"Games" +{ + "cstrike" + { + "Offsets" + { + "GetRunCmdPre" + { + "windows" "419" + "linux" "420" + } + } + } +}