From 3eba9f0041d418be91fc850300e70df000c893d2 Mon Sep 17 00:00:00 2001 From: jenzur Date: Thu, 23 Jan 2020 23:15:26 +0100 Subject: [PATCH] just creating folder here i guess --- AutismBotIngame/python/connectServer.py | 32 +++ AutismBotIngame/python/ingamerunning_2.py | 191 ++++++++++++++++++ .../python/ingamerunning_xdotool.py | 177 ++++++++++++++++ AutismBotIngame/python/start.sh | 38 ++++ AutismBotIngame/python/start2.sh | 3 + AutismBotIngame/python/start3.sh | 3 + AutismBotIngame/python/start4.sh | 5 + 7 files changed, 449 insertions(+) create mode 100644 AutismBotIngame/python/connectServer.py create mode 100644 AutismBotIngame/python/ingamerunning_2.py create mode 100644 AutismBotIngame/python/ingamerunning_xdotool.py create mode 100644 AutismBotIngame/python/start.sh create mode 100644 AutismBotIngame/python/start2.sh create mode 100644 AutismBotIngame/python/start3.sh create mode 100644 AutismBotIngame/python/start4.sh 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/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