diff --git a/AutismBotIngame/python/connectServer.py b/AutismBotIngame/python/connectServer.py new file mode 100644 index 00000000..143588b8 --- /dev/null +++ b/AutismBotIngame/python/connectServer.py @@ -0,0 +1,32 @@ +import logging +import subprocess +from time import sleep + +#export SDL_VIDEO_X11_VISUALID= #"0x074" +#textmode is no video output, what botox used + + +#-connect 151,80.230.149:27015 + + +#subprocess.call(["steam", "steam://install/240"]) + +#sleep(20) +#server_ip_ze = "151.80.230.149:27015" +#subprocess.Popen(["steam", "steam://connect/" + server_ip_ze]) + +#steam steam://connect/151.80.230.149:27015 +#steam steam://connect/151.80.230.149:27019/test132 + +#-nopreload seemingly prevents from joining servers +#cd /home/nonroot/.steam/ +#./steam.sh -applaunch 240 -textmode -novid -nosound -noipx -nojoy -noshaderapi -condebug +exec looptest.cfg +# + +def joinsteam(): + subprocess.Popen(["steam", "-login", "username","password"]) + sleep(25) + subprocess.Popen(["/home/nonroot/.steam/steam.sh", "-applaunch 240 -textmode -novid -nosound -noipx -nojoy -noshaderapi -condebug +exec looptest.cfg"]) + +if __name__ == '__main__': + joinsteam() \ No newline at end of file diff --git a/AutismBotIngame/python/ingamefollowct.py b/AutismBotIngame/python/ingamefollowct.py new file mode 100644 index 00000000..32693429 --- /dev/null +++ b/AutismBotIngame/python/ingamefollowct.py @@ -0,0 +1,119 @@ +import os +import subprocess +import atexit +import time +import threading +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() + +def writeCfgInput(Input): + with open(looptestPath, 'w') as f: + f.write(Input) + +def getconsoleOutputForStatus(input): + randomlygeneratedString = id_generator(11) + str = "status; wait 5; sm_botfindString {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString) + print('writeCfgInput') + writeCfgInput(str) + checkConsoleOutput(randomlygeneratedString) + incrementer = 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 + +def getConsoleOutputForTeams(): + teamvalues = ['Spectactor', 'Terrorist', 'Counter-Terrorist'] + randomlygeneratedString = id_generator(11) + str = "sm_teaminfo; wait 50; sm_botfindString {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 + + + +def checkConsoleOutput(input): + bool = False + #print('entered checkconsole output') + while not bool: + with open(consolelogPath, 'r') as f: + for line in f: + if input in line: + #print('line: ', line, ' \ninput: ', input) + bool = True + break + +def resetCfgInputShortWait(): + #getpos + randomlygeneratedString = id_generator(11) + print('randomlygeneratedString: ', randomlygeneratedString) + str = "wait 5; sm_botfindString {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString) + with open(looptestPath, 'w') as f: + f.write(str) + checkConsoleOutput(randomlygeneratedString) + +def exit_handler(): + resetCfgInputShortWait() + +def joinTeam(): + clearconsolelog() + randomlygeneratedString = id_generator(11) + str = "jointeam 2; wait 2; zspawn; wait 1; sm_botfindString {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString) + writeCfgInput(str) + checkConsoleOutput(randomlygeneratedString) + +def checkbotteam(): + print('reached checkbotteam') + clearconsolelog() + team = getConsoleOutputForTeams() + print('team value: ', team) + if "Spectactor" in team: + joinTeam() + +def checkIfConnected(): + clearconsolelog() + str1 = "connect 151.80.230.149:27015; wait 500; exec looptest.cfg;" + if (getconsoleOutputForStatus("hostname:")): + writeCfgInput(str1) + time.sleep(2) + resetCfgInputShortWait() + checkbotteam() + resetCfgInputShortWait() + followPlayer() + threading.Timer(60.0 * 5, checkIfConnected).start() + +def followPlayer(): + #randomlygeneratedString = id_generator(11) + default_input = "+attack; wait 1; cl_minmodels 1; wait 5; setang 0 180 0; wait 1;" + writeCfgInput(default_input) + #print('start of method \n') + + +if __name__ == '__main__': + atexit.register(exit_handler) + clearconsolelog() + resetCfgInputShortWait() + checkIfConnected() \ No newline at end of file diff --git a/AutismBotIngame/python/ingamerunning_2.py b/AutismBotIngame/python/ingamerunning_2.py new file mode 100644 index 00000000..7d87fc56 --- /dev/null +++ b/AutismBotIngame/python/ingamerunning_2.py @@ -0,0 +1,191 @@ +import os +import subprocess +import time, threading +import atexit +from random import randrange, choice + +currentmap = "" + +#condebug instead of condump, remove all condump entries, instead read from console.log, remove deleteConDump Calls +#perharps instead of opening constantly opening once and somehow updating might be more efficient + +def clearconsolelog(): + open('/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/console.log', 'w').close() + +def readMapFromConsoleLog(): + with open('/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/console.log', 'r') as f: + for line in f: + #print('line: ', line) + if '[SM] The current map is ' in line: + currentmap = line[line.find('map is ') + len('map is '):line.rfind('.')] + return currentmap + return "" + +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 checkConsoleOutput(input): + bool = False + while not bool: + with open('/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/console.log', 'r') as f: + for line in f: + if input in line: + #print('line: ', line, ' \ninput: ', input) + bool = True + break + +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) + checkConsoleOutput("setpos") + +def findcurrentmap(): + currentmap = "" + clearconsolelog() + while not currentmap: + try: + #print("post resetcfg") + writeCfgInput("say currentmap; wait 1; exec looptest.cfg;") + time.sleep(0.02) + currentmap = readMapFromConsoleLog() + except OSError: + #print('failed opening file') + pass + resetCfgInputShortWait() + clearconsolelog() + print("currentmap is: {}".format(currentmap)) + return currentmap + + +def deleteCondump(): + [os.remove(os.path.join("/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/",f)) for f in os.listdir("/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/") if f.startswith("condump")] + + +def joinTeam(): + print("reached joinTeam") + str = "jointeam 2; wait 2; zspawn; wait 1; exec looptest.cfg;" + writeCfgInput(str) + checkConsoleOutput("zspawn") + +def floatconverter(Array, index): + return float(Array[index].replace('\U00002013', '-').replace(';', '')) + +def findClosestCt(originPosition): + PositionArray = originPosition.split() + #print('PositionArray: ', PositionArray) + xAxis = floatconverter(PositionArray, 0) + yAxis = floatconverter(PositionArray, 1) + zAxis = floatconverter(PositionArray, 2) + x = 0.0 + y = 0.0 + z = 0.0 + defaultDistance = 1000000.0 + #use CTOrigin to find, input comes from plugin spammed all 3 seconds + checkConsoleOutput("CTOrigin:") + try: + with open('/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/console.log', 'r') as f: + playerOrigin = [0, 0, 0] + for line in f: + #print('line: ', line) + if 'CTOrigin:' in line: + #print('found origin line: ', line) + playerArray = line[10:].split() + playerArray[2].replace(";", "") + print('playerArray: ', playerArray) + playerOrigin[0] = floatconverter(PositionArray, 0) + playerOrigin[1] = floatconverter(PositionArray, 1) + playerOrigin[2] = floatconverter(PositionArray, 2) + xValue = xAxis - playerOrigin[0] + yValue = yAxis - playerOrigin[1] + zValue = zAxis - playerOrigin[2] + if xValue < 0: xValue * -1 + if yValue < 0: yValue * -1 + if zValue < 0: zValue * -1 + totalDistance = xValue + yValue + zValue + if totalDistance < defaultDistance: + defaultDistance = totalDistance + x = playerOrigin[0] + y = playerOrigin[1] + z = playerOrigin[2] + except OSError: + print('failed opening file readorigin') + return (x, y ,z) + + +def readOrigin(): + originPosition = "" + writeCfgInput("getpos; wait 1; exec looptest.cfg;") + while not originPosition: + try: + with open('/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/console.log', 'r') as f: + for line in f: + if 'setpos' in line: + originPosition = line[line.find('setpos') + len('setpos'):line.rfind(';setang')] + break + except OSError: + #print('failed opening file readorigin') + pass + return originPosition + + +def findDirection(x, y, z, originPosition): + directions = ["forward", "back", "moveleft", "moveright"] + PositionArray = originPosition.split() + xAxis = floatconverter(PositionArray, 0) + yAxis = floatconverter(PositionArray, 1) + zAxis = floatconverter(PositionArray, 2) + print('xAxis, yAxis , zAxis', xAxis, yAxis, zAxis) + print('x, y , z', x, y, z) + if x > xAxis + 200 : return directions[1] + elif x < xAxis - 200 : return directions[0] + elif y > yAxis + 200 : return directions[3] + elif y < yAxis - 200 : return directions[2] + return choice(directions) + +def followPlayer(): + direction = "" + prev_direction = "forward" + default_input = "+attack; wait 1; cl_minmodels 1; wait 5; setang 0 180 0; wait 1;" + while True: + try: + print("start of try") + originPosition = readOrigin() + #print('originPosition: ', originPosition) + CrouchOrJump = "wait 1; -duck; wait 1; +jump; wait 1; -jump;" + if randrange(0, 10) > 8: + CrouchOrJump = "wait 1; +duck;" + x, y, z = findClosestCt(originPosition) + if x != 0.0: + clearconsolelog() + resetCfgInputShortWait() + direction = findDirection(x, y ,z, originPosition) + print('movedirection: ', direction) + str = "" + if direction != prev_direction: + str = "{} -{}; wait 1; +{}; {} wait 1; exec looptest.cfg;".format(default_input, prev_direction, direction, CrouchOrJump) + prev_direction = direction + else: + str = "{} +{}; {} wait 1; exec looptest.cfg;".format(default_input, direction, CrouchOrJump) + writeCfgInput(str) + checkConsoleOutput(str) + except ValueError as err: + print('ValueError occured: ', err) + pass + +def exit_handler(): + #deleteCondump() + resetCfgInputShortWait() + +if __name__ == '__main__': + atexit.register(exit_handler) + resetCfgInputShortWait() + currentmap = findcurrentmap() + joinTeam() + #circlespin() + resetCfgInputShortWait() + followPlayer() + #exploreMap(currentmap) + #loadMapPattern(currentmap) + #final idea: send printchat to bot for movement input from plugin \ No newline at end of file diff --git a/AutismBotIngame/python/ingamerunning_xdotool.py b/AutismBotIngame/python/ingamerunning_xdotool.py new file mode 100644 index 00000000..14422a8c --- /dev/null +++ b/AutismBotIngame/python/ingamerunning_xdotool.py @@ -0,0 +1,177 @@ +import os +import subprocess +import time, threading +import os +# COMMENTS +#sm_track_movement jenz +#direct input +#xdotool search --name "Counter-Strike Source - OpenGL" key m + +#setxkbmap -layout dk +#xdotool search --name "Counter-Strike Source - OpenGL" +#xdotool windowfocus 10488872 / 31457297 // 67108881 +# keydown +# COMMENTS OVER + +def processType(type): + subprocess.call(["xdotool", "type", type]) + +def processKeys(key): + subprocess.call(["xdotool", "key", key]) + +def findPosOrigin(line): + originPost = line[line.find('setpos ') + len('setpos'):line.rfind(';setang')] + print('originPost: ', originPost) + return originPost + +def deleteCondump(): + [os.remove(os.path.join("/home/john/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/",f)) for f in os.listdir("/home/john/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/") if f.startswith("condump")] + +def processLine(line): + if '[SM] The current map is ' in line: + processType("say") + processKeys("space") + processType("currentmap") + processKeys("space") + processType("is") + processKeys("space") + currentmap = line[line.find('map is ') + len('map is '):line.rfind('.')] + processType(currentmap) + processKeys("Return") + global currentFilename + currentFilename = str(currentmap) + +def reachgetDifference(reachpos, getpos): + #print('reachpos: ', reachpos) + #print('getpos: ', getpos) + if getpos[1] == '-': + getpos = getpos[2:] + if reachpos[1] == '-': + reachpos = reachpos[2:] + reachposAxis = float(reachpos[0].strip('"')) + getposAxis = float(getpos[0].strip('"')) + if reachposAxis - 50.0 < getposAxis: + processType("setang") + processKeys("space") + processType("0") + processKeys("space") + processType("180") + processKeys("space") + processType("0") + processKeys("Return") + return True + elif reachposAxis + 50.0 > getposAxis: + processType("setang") + processKeys("space") + processType("0") + processKeys("space") + processType("0") + processKeys("space") + processType("0") + processKeys("Return") + return True + return False + +def readmovement(line): + doubleString = "setang " + processphase = 0; + characterString = "" + for index, character in enumerate(line): + #print('character: ', character) + if processphase == 0: + if character.isspace(): + continue + if character.isalpha(): + if character != characterString: + processKeys("minus") + if character == "w": + characterString = "forward" + elif character == "s": + characterString = "back" + print('characterString: ', characterString) + print('character: ', character) + processType(characterString) + processKeys("Return") + time.sleep(0.5) + processKeys("plus") + if character == "w": + characterString = "forward" + elif character == "s": + characterString = "back" + processType(characterString) + print('characterString2: ', characterString) + processKeys("Return") + characterString = character + processphase += 1 + if processphase == 1: + if character.isdigit() or character == '.': + doubleString += character + elif character.isspace() and len(doubleString) > 10: + doubleString += " " + if line[index + 1] == "o": + processType(doubleString) + processKeys("Return") + doubleString = "" + processphase += 1 + if processphase == 2: + if not character.isdigit() and not doubleString: + continue + elif character.isdigit() or character == '.': + doubleString += character + elif character.isspace() and doubleString and not line[index + 1].isalpha(): + doubleString += " " + else: + reachpos = doubleString.split() + getpos = ["0.0", "0.0", "0.0"] + while reachgetDifference(reachpos, getpos): + processType("clear") + processKeys("Return") + processType("getpos") + processKeys("Return") + time.sleep(2) + processType("condump") + processKeys("Return") + time.sleep(2) + with open('/home/john/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/condump000.txt') as f: + for line in f: + if 'setpos' in line: + getpos = findPosOrigin(line) + break + time.sleep(2) + deleteCondump() + processphase = 0 + doubleString = "setang " + +def findcurrentmap(): + subprocess.call(["xdotool", "search", "--name", "Counter-Strike Source - OpenGL", "windowactivate"]) + #clear console field before retrieving info + processKeys("Return") + #clean console prompt + processType("clear") + processKeys("Return") + processType("say") + processKeys("space") + processType("currentmap") + processKeys("Return") + time.sleep(2) + processType("condump") + processKeys("Return") + time.sleep(2) + with open('/home/john/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/condump000.txt') as f: + for line in f: + processLine(line) + time.sleep(2) + deleteCondump() + #subprocess.call(["xdotool", "key", "Escape"]) + #subprocess.call(["xdotool", "key", "o"]) + +def mapmovementpattern(): + stringfile = "/home/nonroot/zeeman/maps/%s.txt" % (currentFilename) + with open(stringfile) as f: + for line in f: + readmovement(line) + +if __name__ == '__main__': + deleteCondump() + findcurrentmap() + mapmovementpattern() \ No newline at end of file diff --git a/AutismBotIngame/python/start.sh b/AutismBotIngame/python/start.sh new file mode 100644 index 00000000..cf54d8af --- /dev/null +++ b/AutismBotIngame/python/start.sh @@ -0,0 +1,38 @@ +#!/bin/bash +#very important one to fix BEFORE steamlogin +#glxinfo +#source venv/bin/activate +export SDL_VIDEO_X11_VISUALID="0x0e5" #0x0e5 +python connectServer.py + + +###Nomachine related + +#/etc/NX/nxserver --startsession --virtual --type unix-console + +#sudo nano /usr/NX/etc/node.cfg + +#/usr/NX/bin/nxserver --startsession --virtual --type unix-console + +#UNITY +#DefaultDesktopCommand "/etc/X11/Xsession 'gnome-session -session=ubuntu'" + +#run nxserver with sudo + + # sudo /etc/NX/nxserver --useradd john --system + #https://www.nomachine.com/DT04O00139#7.1 + + #/usr/NX/bin/nxclient + + #/etc/NX/nxserver has to be turned on and active with a user for + #/usr/NX/bin/nxclient + #/usr/NX/bin/nxplayer can connect to desktop + + #sudo /etc/NX/nxserver --restart + #sudo /usr/NX/bin/nxserver --restart + + +#default desktop command without folder, put as startxfce4 or gnome-session --session=gnome + + + diff --git a/AutismBotIngame/python/start2.sh b/AutismBotIngame/python/start2.sh new file mode 100644 index 00000000..91527d86 --- /dev/null +++ b/AutismBotIngame/python/start2.sh @@ -0,0 +1,3 @@ +#!/bin/bash +#source venv/bin/activate +python ingamerunning_2.py \ No newline at end of file diff --git a/AutismBotIngame/python/start3.sh b/AutismBotIngame/python/start3.sh new file mode 100644 index 00000000..07f83931 --- /dev/null +++ b/AutismBotIngame/python/start3.sh @@ -0,0 +1,3 @@ +#!/bin/bash +#source venv/bin/activate +python rejoinze.py \ No newline at end of file diff --git a/AutismBotIngame/python/start4.sh b/AutismBotIngame/python/start4.sh new file mode 100644 index 00000000..9e7f81dc --- /dev/null +++ b/AutismBotIngame/python/start4.sh @@ -0,0 +1,5 @@ +#!/bin/bash +#source venv/bin/activate +python ingamefollowct.py + +#dont need x2go connection for hl2 process or ./steam.sh -textmode, both work with regular ssh if logged in already \ No newline at end of file diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp new file mode 100644 index 00000000..722e9e3d --- /dev/null +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -0,0 +1,121 @@ +#pragma semicolon 1 + +#define DEBUG + +#define PLUGIN_AUTHOR "jenz" +#define PLUGIN_VERSION "1.00" + +#include +#include + +#pragma newdecls required + +bool outputspam[MAXPLAYERS + 1]; +int ticksCooldown = 66; // 66 tick per second +int botTicker; + +public Plugin myinfo = +{ + name = "coordinates for the bot", + author = PLUGIN_AUTHOR, + description = "hello ", + version = PLUGIN_VERSION, + url = "" +}; + +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; +} + +//---------------------------------------------------------------------------------------------------- +// 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 "); + 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; +} + +//---------------------------------------------------------------------------------------------------- +// 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) + { + 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]); + } + } + botTicker++; + } +} + +stock bool IsValidClient(int client) +{ + if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client)) + { + return true; + } + return false; +} + +public void OnClientPostAdminCheck(int client) +{ + //STEAM_0:1:34783317 + //STEAM_0:1:60189040 + //[U:1:120378081] + 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; + } +} \ No newline at end of file