diff --git a/AutismBotIngame/README.md b/AutismBotIngame/README.md index 82495e93..b413d741 100644 --- a/AutismBotIngame/README.md +++ b/AutismBotIngame/README.md @@ -1,3 +1,14 @@ -# Description # +# requirements +steam account, x2go or nomachine or VNC etc etc +steam account with css purchased +# launch commands +./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi -condebug +exec looptest.cfg -- two files are used. looptest.cfg is a file for constant input while the console.log file serves as constant output. \ No newline at end of file +autoexec.cfg: +alias loop "exec looptest.cfg; wait 5; loop;"; wait 5; loop; + + + +# environment settings needed +use glxinfo to get information about ID's, for example 0x0e5 +export SDL_VIDEO_X11_VISUALID="0x0e5" diff --git a/AutismBotIngame/python/ingamefollowct.py b/AutismBotIngame/python/ingamefollowct.py index dc291630..b82b00d7 100644 --- a/AutismBotIngame/python/ingamefollowct.py +++ b/AutismBotIngame/python/ingamefollowct.py @@ -1,59 +1,57 @@ import os import subprocess import atexit +import re from threading import Timer import string import random looptestPath = '/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg' consolelogPath = '/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/console.log' -iterationCap = 150 def id_generator(size=6, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) def clearconsolelog(): open(consolelogPath, 'w').close() + connectionTimer = Timer(20.0, clearconsolelog) + #daemon true kills thread instead of deadlock waiting in case program exits + connectionTimer.daemon = True + connectionTimer.start() def writeCfgInput(Input): with open(looptestPath, 'w') as f: f.write(Input) -def getconsoleOutputForStatus(input): +def getconsoleOutputForStatus(): randomlygeneratedString = id_generator(11) - str = "status; wait 5; {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString) + str = "status; wait 5; {0}; wait 5;".format(randomlygeneratedString) print('writeCfgInput') writeCfgInput(str) checkConsoleOutput(randomlygeneratedString) - incrementer = 0 + server_str = "" + player_count = 0 with open(consolelogPath, 'r') as f: for line in f: - incrementer += 1 - if incrementer > iterationCap: return True #cap before leaving the file again - if input in line: return False #found hostname which means connected - return True + if "udp/ip :" in line: server_str = line[9:].strip() + if "players :" in line: player_count = int(line[9:].split()[0].strip()) + return (server_str, player_count) -def getConsoleOutputForTeams(): - teamvalues = ['Spectactor', 'Terrorist', 'Counter-Terrorist'] +def get_output_if_spec(): randomlygeneratedString = id_generator(11) - str = "sm_teaminfo; wait 50; {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString) - while True: - 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 - previousStr = "" - checkConsoleOutput(randomlygeneratedString) - with open(consolelogPath, 'r') as f: - for line in f: - print('getConsoleOutputForTeams line: ', line) - if randomlygeneratedString in line: - if teamvalues[2] in previousStr: return teamvalues[2] - elif teamvalues[1] in previousStr: return teamvalues[1] - return teamvalues[0] - previousStr = line + str = "zspawn; wait 50; {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." + checkConsoleOutput(randomlygeneratedString) + with open(consolelogPath, 'r') as f: + for line in f: + if targetstr in line: return True + return False + - def checkConsoleOutput(input): bool = False #print('entered checkconsole output') @@ -69,54 +67,120 @@ def resetCfgInputShortWait(): #getpos randomlygeneratedString = id_generator(11) print('randomlygeneratedString: ', randomlygeneratedString) - str = "wait 50; {0}; wait 50; exec looptest.cfg;".format(randomlygeneratedString) + str = "{0}; wait 5;".format(randomlygeneratedString) with open(looptestPath, 'w') as f: f.write(str) checkConsoleOutput(randomlygeneratedString) + def exit_handler(): - print('exithandler') - #resetCfgInputShortWait() + print('reached exithandler') + str = "wait 5;" + with open(looptestPath, 'w') as f: + f.write(str) def joinTeam(): - clearconsolelog() randomlygeneratedString = id_generator(11) - str = "jointeam 2; wait 2; zspawn; wait 1; {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString) + str = "jointeam 2; wait 2; zspawn; wait 1; {0}; wait 5;".format(randomlygeneratedString) writeCfgInput(str) checkConsoleOutput(randomlygeneratedString) def checkbotteam(): - print('reached checkbotteam') - clearconsolelog() - team = getConsoleOutputForTeams() - print('team value: ', team) - if "Spectactor" in team: - joinTeam() + team = get_output_if_spec() + if team: joinTeam() def checkIfConnected(): - clearconsolelog() randomlygeneratedString = id_generator(11) - str1 = "connect 151.80.230.149:27015; wait 5; {0}; wait 500; exec looptest.cfg;".format(randomlygeneratedString) - if (getconsoleOutputForStatus("hostname:")): + str1 = "connect 151.80.230.149:27015; wait 5; {0}; wait 50; ".format(randomlygeneratedString) + server_str, player_count = getconsoleOutputForStatus() + if "Zombie Escape" not in server_str: writeCfgInput(str1) - checkConsoleOutput(randomlygeneratedString) - resetCfgInputShortWait() + elif player_count > 58: + writeCfgInput("connect 151.80.230.149:27016; wait 5; {0}; wait 50;").format(randomlygeneratedString) + checkConsoleOutput(randomlygeneratedString) + resetCfgInputShortWait() + print('reached checkbotteam:') checkbotteam() resetCfgInputShortWait() - followPlayer() + connectionTimer = Timer(60.0 * 5, 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 + +def get_player_info(): + movement_input = [] + ct_angles = [] + while not movement_input or not ct_angles: + with open(consolelogPath, 'r') as f: + for line in f: + if "movement_input_:" in line: + movement_input.append(line[16:].strip()) + if "ct_eye_angles_:" in line: + ct_angles = line[15:].split() + ct_angles = [element.strip() for element in ct_angles] + return (movement_input, ct_angles) + +def getBotOrgin(botOrigin): + #x -> z -> y coordAxis order + botOrigin = [x.strip() 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(): - randomlygeneratedString = id_generator(11) #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; exec looptest.cfg;".format(randomlygeneratedString) - writeCfgInput(default_input) - checkConsoleOutput(randomlygeneratedString) - #print('start of method \n') + #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() + randomlygeneratedString = id_generator(11) + strInput = "+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 + "; wait 5;" + print('strInput: ', strInput) + writeCfgInput(strInput) + checkConsoleOutput(randomlygeneratedString) + connectionTimer = Timer(2.5, followPlayer) + connectionTimer.daemon = True + connectionTimer.start() + +def deadlock(): + try: + while True: 42 == 42 + except KeyboardInterrupt: + pass if __name__ == '__main__': atexit.register(exit_handler) clearconsolelog() resetCfgInputShortWait() - checkIfConnected() \ No newline at end of file + checkIfConnected() + followPlayer() + print('reached deadlock') + deadlock() + +#autoexec.cfg: +#alias loop "exec looptest.cfg; wait 5; loop;"; wait 5; loop; \ No newline at end of file diff --git a/AutismBotIngame/python/rejoinze.py b/AutismBotIngame/python/rejoinze.py deleted file mode 100644 index 5c38c37c..00000000 --- a/AutismBotIngame/python/rejoinze.py +++ /dev/null @@ -1,24 +0,0 @@ -import subprocess -import threading -import time - -def resetCfgInputShortWait(): - str = "wait 1; getpos; wait 1; exec looptest.cfg;" - with open('/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg', 'w') as f: - f.write(str) - -def writeCfgInput(Input): - with open('/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg', 'w') as f: - f.write(Input) - -def rejoinze(): - threading.Timer(60.0 * 20, rejoinze).start() - open('/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/console.log', 'w').close() - writeCfgInput("connect 151.80.230.149:27015; wait 500; exec looptest.cfg;") - time.sleep(2) - resetCfgInputShortWait() - #server_ip_ze = "151.80.230.149:27015" - #subprocess.Popen(["steam", "steam://connect/" + server_ip_ze]) - -if __name__ == '__main__': - rejoinze() \ No newline at end of file diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index 722e9e3d..a1d20b6d 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -13,6 +13,7 @@ bool outputspam[MAXPLAYERS + 1]; int ticksCooldown = 66; // 66 tick per second int botTicker; +int targethuman = 0; public Plugin myinfo = { @@ -26,26 +27,6 @@ public Plugin myinfo = public void OnPluginStart() { RegConsoleCmd("sm_botfindString", Cmd_findBotString); - RegConsoleCmd("sm_teaminfo", Cmd_teamInfo); -} - -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public Action Cmd_teamInfo(int client, int args) -{ - if (!IsValidClient(client)) - return Plugin_Handled; - if (!outputspam[client]) - return Plugin_Handled; - int clientteamvalue = GetClientTeam(client); - if (clientteamvalue == 3) - PrintToChat(client, "(Counter-Terrorist)"); - else if (clientteamvalue == 2) - PrintToChat(client, "(Terrorist)"); - else - PrintToChat(client, "(Spectactor)"); - return Plugin_Handled; } //---------------------------------------------------------------------------------------------------- @@ -73,6 +54,23 @@ public void OnClientDisconnect(int client) outputspam[client] = false; } +stock void TraceEye(const int client, float pos[3]) +{ + 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); +} + +public bool TraceEntityFilterPlayer( int entity, int contentsMask ) +{ + return ( entity > GetMaxClients() || !entity ); +} + //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- @@ -84,13 +82,58 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float if (botTicker > ticksCooldown) { botTicker = 0; - for (int i = 1; i <= MaxClients; i++) - if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != client) - { - float clientorigin[3]; - GetClientAbsOrigin(i, clientorigin); - PrintToChat(client, "CTOrigin: %f %f %f;", clientorigin[0], clientorigin[1], clientorigin[2]); - } + if (targethuman && (GetClientTeam(targethuman) != 3 || !IsPlayerAlive(targethuman))) + { + targethuman = 0; + } + if (!targethuman) + { + float pos_client[3]; + TraceEye(client, pos_client); + float lowest_distance = 1000000.0; + for (int i = 1; i <= MaxClients; i++) + if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != client) + { + float pos_i[3]; + TraceEye(client, 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); + if (dist < lowest_distance) + { + lowest_distance = dist; + targethuman = i; + } + } + } + //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]); + if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed") & IN_FORWARD) + { + PrintToChat(client, "movement_input_: +forward"); + } + if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed") & IN_BACK) + { + PrintToChat(client, "movement_input_: +back"); + } + if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed") & IN_LEFT) + { + PrintToChat(client, "movement_input_: +moveleft"); + } + if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed") & IN_RIGHT) + { + PrintToChat(client, "movement_input_: +moveright"); + } + if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed" ) & IN_JUMP) + { + PrintToChat(client, "movement_input_: +jump"); + } + PrintToChat(client, "ct_eye_angles_: %f %f %f", clientangles[0], clientangles[1], clientangles[2]); } botTicker++; }