some updates and still got stuff to do

This commit is contained in:
jenzur 2020-02-28 22:00:22 +01:00
parent a2c8a96d1a
commit ee9b446838
2 changed files with 180 additions and 165 deletions

View File

@ -1,7 +1,6 @@
import os
import subprocess
import atexit
import re
from threading import Timer
import string
import random
@ -24,7 +23,7 @@ def clearconsolelog():
if clearbool:
clearbool = False
open(consolelogPath, 'w').close()
print('cleaned console')
#print('cleaned console')
connectionTimer = Timer(3.0, switchbool)
#daemon true kills thread instead of deadlock waiting in case program exits
connectionTimer.daemon = True
@ -35,32 +34,43 @@ def writeCfgInput(Input):
f.write(Input)
def getconsoleOutputForStatus():
randomlygeneratedString = id_generator(11)
str = "status; wait 5; {0}; wait 5;".format(randomlygeneratedString)
writeCfgInput(str)
checkConsoleOutput(randomlygeneratedString)
server_str = ""
player_count = 0
with open(consolelogPath, 'r') as f:
for line in f:
if "udp/ip :" in line: server_str = line[9:].strip()
if "players :" in line: player_count = int(line[9:].split()[0].strip())
print('server_str: ', server_str, '\nplayer_count: ', player_count)
return (server_str, player_count)
i = 0
while i < 8:
time.sleep(0.25)
randomlygeneratedString = id_generator(11)
str = "status; wait 5; {0}; wait 5;".format(randomlygeneratedString)
writeCfgInput(str)
checkConsoleOutput(randomlygeneratedString)
server_str = ""
player_count = 0
with open(consolelogPath, 'r') as f:
for line in f:
try:
if "udp/ip" in line: server_str = line[9:].strip()
if "players " in line: player_count = int(line[9:].split()[0].strip())
except Exception:
pass
if server_str:
print('server_str: ', server_str, '\nplayer_count: ', player_count)
return (server_str, player_count)
i += 1
return ("None", "None")
def get_output_if_spec():
randomlygeneratedString = id_generator(11)
str = "zspawn; wait 50; {0}; wait 5;".format(randomlygeneratedString)
str = "zspawn; wait 500; {0}; wait 5;".format(randomlygeneratedString)
writeCfgInput(str)
#is sm_team a command to show team?
#maybe instead say !teaminfo, add sourcemod command to autism_bot_info.sp to print team to chat instead
targetstr = "This feature requires that you are on a team."
failurestr = "Unknown command \"zspawn\""
alivestr = "This feature requires that you are dead."
checkConsoleOutput(randomlygeneratedString)
with open(consolelogPath, 'r') as f:
for line in f:
if alivestr in line: return 2
if targetstr in line: return 1
if failurestr in line: return 2
if failurestr in line: return 0
return 0
def checkConsoleOutput(input):
@ -92,7 +102,6 @@ def exit_handler():
with open(looptestPath, 'w') as f:
f.write(str)
def joinTeam():
randomlygeneratedString = id_generator(11)
str = "jointeam 2; wait 2; zspawn; wait 1; {0}; wait 5;".format(randomlygeneratedString)
@ -106,7 +115,7 @@ def checkbotteam():
if state == 1:
joinTeam()
break
if state == 0:
if state == 2:
break
resetCfgInputShortWait()
connectionTimer = Timer(20.0, checkbotteam)
@ -118,12 +127,12 @@ def checkIfConnected():
server_str, player_count = getconsoleOutputForStatus()
connectionTimer = None
if "27015" not in server_str:
str1 = "connect 151.80.230.149:27015; wait 5; {0}; wait 1500; ".format(randomlygeneratedString)
str1 = "connect 151.80.230.149:27015; {0}; wait 500;".format(randomlygeneratedString)
writeCfgInput(str1)
checkConsoleOutput(randomlygeneratedString)
elif player_count > 58:
elif player_count > 63:
#TODO check team differently because zspawn unknown command on zr server
writeCfgInput("connect 151.80.230.149:27016; wait 5; {0}; wait 1500;".format(randomlygeneratedString))
writeCfgInput("connect 151.80.230.149:27016; {0}; wait 5;".format(randomlygeneratedString))
checkConsoleOutput(randomlygeneratedString)
connectionTimer = Timer(60.0 * 15, checkIfConnected)
resetCfgInputShortWait()
@ -132,78 +141,114 @@ def checkIfConnected():
#daemon true kills thread instead of deadlock waiting in case program exits
connectionTimer.daemon = True
connectionTimer.start()
def getBotOrigin():
randomlygeneratedString = id_generator(11)
str = "getpos; wait 1; {0}; wait 5;".format(randomlygeneratedString)
writeCfgInput(str)
checkConsoleOutput(randomlygeneratedString)
previousStr = ""
with open(consolelogPath, 'r') as f:
for line in f:
if randomlygeneratedString in line:
try:
coords = re.search('setpos (.*);setang', previousStr).group(1).strip().split()
print('coords: ', coords)
return coords
except AttributeError as err:
pass
previousStr = line
return None
#print('finished checkIfConnected')
def get_player_info():
movement_input = []
ct_angles = []
while not movement_input and not ct_angles:
ct_origin_diff = []
ct_origin_position = []
ct_distance = 0
while True:
with open(consolelogPath, 'r') as f:
for line in f:
if "movement_input_specific:" in line:
try:
movement = line.split("movement_input_specific:", 1)[1]
movement = movement.replace("\n", "")
try:
for line in f:
print('line: ', line)
if "movement_input_specific:" in line and len(line) > 26:
movement_input = line.split("movement_input_specific:", 1)[1].split("+")
movement_input = [element.replace("\n", "") for element in movement_input]
#print('movement: ', movement)
movement_input.append(movement)
except IndexError:
pass
if "ct_eye_angles_:" in line:
try:
if "ct_eye_angles_:" in line:
ct_angles = line.split("ct_eye_angles_:", 1)[1].split("+")
except IndexError:
pass
ct_angles = [element.strip() for element in ct_angles]
return (movement_input, ct_angles)
ct_angles = [element.strip() for element in ct_angles]
if "player_origin_diff:" in line:
ct_origin_diff = line.split("player_origin_diff:", 1)[1].split("+")
ct_origin_diff = [element.strip() for element in ct_origin_diff]
ct_origin_diff = [float(element) for element in ct_origin_diff]
if "player_origin_position:" in line:
ct_origin_position = line.split("player_origin_position:", 1)[1].split("+")
ct_origin_position = [element.strip() for element in ct_origin_position]
if "player_lowest_distance:" in line:
ct_distance = line.split("player_lowest_distance:", 1)[1].strip()
ct_distance = float(ct_distance)
if movement_input and ct_angles and ct_origin_diff and ct_origin_position and ct_distance:
return (movement_input, ct_angles, ct_origin_diff, ct_origin_position, ct_distance)
except (UnicodeDecodeError, IndexError):
pass
def getBotOrgin(botOrigin):
#x -> z -> y coordAxis order
botOrigin = [x.strip() for x in botOrigin]
botOrigin = [x.replace(";", "") for x in botOrigin]
#botOrigin = [x.replace(";", "") for x in botOrigin]
botIntorigin0 = float(botOrigin[0])
botIntorigin1 = float(botOrigin[1])
botIntorigin2 = float(botOrigin[2])
#bot coordinates might be usefull?
return [botIntorigin0, botIntorigin1, botIntorigin2]
def followPlayer():
def getBotOrigin():
while True:
str = "getpos; wait 1; wait 5;"
writeCfgInput(str)
previousStr = ""
with open(consolelogPath, 'r') as f:
for line in f:
if "setpos" in line:
try:
print('found setpos line: ', line)
coords = line.split("setpos")[1].split(";setang")[0].split()
#print('coords: ', coords)
return getBotOrgin(coords)
except IndexError as err:
pass
previousStr = line
def followPlayer(remaining_instructions = [], indexCounter = 0, previousmoment = []):
#setang 0 180 0;
#default_input = "+attack; wait 50; cl_minmodels; wait 50; +right; wait 50; +jump; wait 50; -jump; wait 50; +forward; wait 50; {0}; wait 5;".format(randomlygeneratedString)
#writeCfgInput(default_input)
#botOrigin = getBotOrigin()
movement_input, ct_angles = get_player_info()
print('movement_input: ', movement_input, '\nct_angles: ', ct_angles)
botOrigin = getBotOrigin()
movement_input, ct_angles, ct_origin_diff, ct_origin_position, ct_distance = get_player_info()
print('movement_input: ', movement_input, '\nct_angles: ', ct_angles, "\nct_origin_diff: ", ct_origin_diff, "\nct_origin_position: ", ct_origin_position, "\nct_distance: ", ct_distance, "\nbotOrigin: ", botOrigin)
randomlygeneratedString = id_generator(11)
strInput = "-forward; wait 5; -back; wait 5; -moveleft; wait 5; -moveright; wait 5; -jump; wait 5; +attack; wait 5; cl_minmodels 1; wait 5; {0}; wait 5; setang {1} {2} {3}; wait 5;".format(randomlygeneratedString, ct_angles[0], ct_angles[1], ct_angles[2])
for movement in movement_input:
strInput += movement
strInput += "; wait 5;"
#print('strInput: ', strInput)
remaining_instructions.append([movement_input, ct_angles])
strInput = "-jump; wait 5; +attack; wait 5; cl_minmodels 1; wait 5; setang 0 180 0; wait 5;".format(ct_angles[0], ct_angles[1], ct_angles[2])
#strInput += "-forward; wait 5; -back; wait 5; -moveleft; wait 5; -moveright; wait 5; "
if ct_distance > 250:
remaining_instructions = []
indexCounter = 0
#0 180 0: W = X axis greater minus, S = X axis greater plus, A = Y axis greater minus, D = Y axis greater plus
if botOrigin[0] + 50 > ct_origin_diff[0]:
strInput += "wait 5; +forward;"
elif botOrigin[0] - 50 < ct_origin_diff[0]:
strInput += "wait 5; +back;"
if botOrigin[1] + 50 > ct_origin_diff[1]:
strInput += "wait 5; +moveleft;"
elif botOrigin[1] - 50 < ct_origin_diff[1]:
strInput += "wait 5; +moveright;"
print('ct_distance > 250:')
else:
(movement, angles) = remaining_instructions[indexCounter]
if previousmoment != movement:
strInput += "-forward; wait 5; -back; wait 5; -moveleft; wait 5; -moveright; wait 5; "
previousmoment = movement
strInput = strInput.replace("setang 0 180 0;", "setang {0} {1} {2};".format(angles[0], angles[1], angles[2]))
for move in movement:
strInput += "+"
strInput += move
strInput += "; "
indexCounter += 1
strInput += " wait 5; {0}; ".format(randomlygeneratedString)
print('strInput: ', strInput)
writeCfgInput(strInput)
checkConsoleOutput(randomlygeneratedString)
clearconsolelog()
connectionTimer = Timer(1.0, followPlayer)
connectionTimer = Timer(0.2, followPlayer, args=(remaining_instructions, indexCounter))
connectionTimer.daemon = True
connectionTimer.start()
def deadlock():
try:
while True: 42 == 42

View File

@ -10,9 +10,7 @@
#pragma newdecls required
bool outputspam[MAXPLAYERS + 1];
int ticksCooldown = 48; // 66 tick per second
int botTicker;
int present = 0;
int targethuman = 0;
public Plugin myinfo =
@ -24,127 +22,101 @@ public Plugin myinfo =
url = ""
};
public void OnPluginStart()
{
RegConsoleCmd("sm_botfindString", Cmd_findBotString);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Cmd_findBotString(int client, int args)
{
if (!IsValidClient(client))
return Plugin_Handled;
if (!outputspam[client])
return Plugin_Handled;
if (args != 1)
{
ReplyToCommand(client, "[SM] Usage botfindString <string>");
return Plugin_Handled;
}
char sTarget[65];
GetCmdArg(1, sTarget, sizeof(sTarget));
PrintToChat(client, sTarget);
return Plugin_Handled;
}
public void OnClientDisconnect(int client)
{
outputspam[client] = false;
if (present == client)
present = 0;
}
stock void TraceEye(const int client, float pos[3])
public void OnPluginStart()
{
float vAngles[3], vOrigin[3];
GetClientEyePosition(client, vOrigin);
GetClientEyeAngles(client, vAngles);
TR_TraceRayFilter(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceEntityFilterPlayer);
if(TR_DidHit())
TR_GetEndPosition(pos);
//hooks
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
}
public bool TraceEntityFilterPlayer( int entity, int contentsMask )
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
return ( entity > GetMaxClients() || !entity );
targethuman = 0;
}
//TODO FINISH MOVING OVER, RECURSIVE OR 1 SEC TIMER JUST instead of using OnPlayerRunCmdPost
public void recursivePressing()
public void OnMapStart()
{
if (targethuman && (GetClientTeam(targethuman) != 3 || !IsPlayerAlive(targethuman)))
CreateTimer(0.3, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public bool TraceEntityFilterPlayer(int entity, int contentsMask)
{
return (entity > GetMaxClients() || !entity);
}
public Action recursive_pressing(Handle timer, any data)
{
//PrintToChatAll("present: %N", present);
if (present)
{
targethuman = 0;
}
if (!targethuman)
{
float pos_client[3];
TraceEye(client, pos_client);
float client_coord[3];
float xyz[3];
float lowest_distance = 1000000.0;
float pos_client[3];
GetClientAbsOrigin(present, pos_client);
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != client)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != present)
{
float pos_i[3];
TraceEye(client, pos_i);
GetClientAbsOrigin(i, pos_i);
float dx = pos_client[0] - pos_i[0];
float dy = pos_client[1] - pos_i[1];
float dz = FloatAbs(pos_client[2] - pos_i[2]);
float dist = SquareRoot(dx*dx + dy*dy + dz*dz);
//PrintToChatAll("dist: %f", dist);
if (dist < lowest_distance)
{
lowest_distance = dist;
targethuman = i;
client_coord = pos_i;
xyz[0] = dx;
xyz[1] = dy;
xyz[2] = dz;
}
}
}
//maybe this holds some order?
float clientorigin[3];
float clientangles[3];
GetClientAbsOrigin(targethuman, clientorigin);
GetClientAbsAngles(targethuman, clientangles);
//PrintToChat(client, "player_start_origin: %f %f %f", clientorigin[0], clientorigin[1], clientorigin[2]);
int keys = GetClientButtons(targethuman);
if (keys & IN_FORWARD)
{
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+forward");
}
if (keys & IN_BACK)
{
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+back");
}
if (keys & IN_LEFT)
{
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+moveleft");
}
if (keys & IN_RIGHT)
{
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+moveright");
}
if (keys & IN_JUMP)
{
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+jump");
}
ServerCommand("sm_psay #[U:1:120378081] ct_eye_angles_:%f+%f+%f", clientangles[0], clientangles[1], clientangles[2]);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
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 (IsPlayerAlive(client) && outputspam[client])
{
if (botTicker > ticksCooldown)
if (IsValidClient(targethuman))
{
botTicker = 0;
//PrintToChatAll("targethuman: %N", targethuman);
float clientangles[3];
GetClientAbsAngles(targethuman, clientangles);
int keys = GetClientButtons(targethuman);
char keyinput[256];
if (keys & IN_FORWARD)
{
StrCat(keyinput, sizeof(keyinput), "forward+");
}
if (keys & IN_BACK)
{
StrCat(keyinput, sizeof(keyinput), "back+");
}
if (keys & IN_MOVELEFT)
{
StrCat(keyinput, sizeof(keyinput), "moveleft+");
}
if (keys & IN_MOVERIGHT)
{
StrCat(keyinput, sizeof(keyinput), "moveright+");
}
if (keys & IN_JUMP)
{
StrCat(keyinput, sizeof(keyinput), "jump+");
}
//PrintToChatAll("keyinput: %s", keyinput);
//PrintToChatAll("xyz[0], xyz[1], xyz[2]: %f %f %f", xyz[0], xyz[1], xyz[2]);
//PrintToChatAll("lowest_distance: %f", lowest_distance);
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:%s", keyinput);
ServerCommand("sm_psay #[U:1:120378081] ct_eye_angles_:%f+%f+%f", clientangles[0], clientangles[1], clientangles[2]);
ServerCommand("sm_psay #[U:1:120378081] player_origin_diff:%f+%f+%f", xyz[0], xyz[1], xyz[2]);
ServerCommand("sm_psay #[U:1:120378081] player_origin_position:%f+%f+%f", client_coord[0], client_coord[1], client_coord[2]);
ServerCommand("sm_psay #[U:1:120378081] player_lowest_distance:%f", lowest_distance);
}
botTicker++;
}
return Plugin_Handled;
}
stock bool IsValidClient(int client)
@ -164,10 +136,8 @@ public void OnClientPostAdminCheck(int client)
//[U:1:69566635]
char auth[50];
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
//PrintToChatAll("client: %N \nAuth: %s", client, auth);
outputspam[client] = false;
if (StrEqual("[U:1:120378081]", auth, false))
{
outputspam[client] = true;
}
present = client;
else if (StrEqual("STEAM_0:1:60189040", auth, false))
present = client;
}