From bc29b5b97dbce6d22aeefc6304683d6150df175a Mon Sep 17 00:00:00 2001 From: jenzur Date: Wed, 22 Apr 2020 00:17:28 +0200 Subject: [PATCH] minor updates to improve the bot tracking players ingame, still a lot left to do probably --- AutismBotIngame/python/ingamerunning_2.py | 191 ------------------ .../python/ingamerunning_xdotool.py | 177 ---------------- AutismBotIngame/python/start.sh | 2 +- AutismBotIngame/python/start2.sh | 3 - AutismBotIngame/python/start3.sh | 3 - AutismBotIngame/python/start4.sh | 2 +- 6 files changed, 2 insertions(+), 376 deletions(-) delete mode 100644 AutismBotIngame/python/ingamerunning_2.py delete mode 100644 AutismBotIngame/python/ingamerunning_xdotool.py delete mode 100644 AutismBotIngame/python/start2.sh delete mode 100644 AutismBotIngame/python/start3.sh diff --git a/AutismBotIngame/python/ingamerunning_2.py b/AutismBotIngame/python/ingamerunning_2.py deleted file mode 100644 index 7d87fc56..00000000 --- a/AutismBotIngame/python/ingamerunning_2.py +++ /dev/null @@ -1,191 +0,0 @@ -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 deleted file mode 100644 index 14422a8c..00000000 --- a/AutismBotIngame/python/ingamerunning_xdotool.py +++ /dev/null @@ -1,177 +0,0 @@ -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 index cf54d8af..6329f32a 100644 --- a/AutismBotIngame/python/start.sh +++ b/AutismBotIngame/python/start.sh @@ -3,7 +3,7 @@ #glxinfo #source venv/bin/activate export SDL_VIDEO_X11_VISUALID="0x0e5" #0x0e5 -python connectServer.py +python3.8 connectServer.py ###Nomachine related diff --git a/AutismBotIngame/python/start2.sh b/AutismBotIngame/python/start2.sh deleted file mode 100644 index 91527d86..00000000 --- a/AutismBotIngame/python/start2.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/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 deleted file mode 100644 index 07f83931..00000000 --- a/AutismBotIngame/python/start3.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/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 index 9e7f81dc..bda03189 100644 --- a/AutismBotIngame/python/start4.sh +++ b/AutismBotIngame/python/start4.sh @@ -1,5 +1,5 @@ #!/bin/bash #source venv/bin/activate -python ingamefollowct.py +python3.8 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