Update AutismBotIngame/python/ingamefollowct.py
This commit is contained in:
parent
2e4ce56cf5
commit
3067dc423c
@ -3,6 +3,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import atexit
|
import atexit
|
||||||
|
import pwd
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
import random
|
import random
|
||||||
@ -17,8 +18,17 @@ import glob
|
|||||||
restart_time = datetime.datetime.now() + datetime.timedelta(hours=3)
|
restart_time = datetime.datetime.now() + datetime.timedelta(hours=3)
|
||||||
block_connection = False
|
block_connection = False
|
||||||
the_undesired_crash_counter = 0 #hate this monkey solution
|
the_undesired_crash_counter = 0 #hate this monkey solution
|
||||||
|
shoot_distance = 450.0
|
||||||
|
shoot_burst_cycles = 4
|
||||||
|
enemy_chase_distance = 450.0
|
||||||
|
team_follow_distance = 800.0
|
||||||
|
infect_chase_distance = 300.0
|
||||||
|
momentum_hold_seconds = 1.4
|
||||||
|
min_forward_wait = 6
|
||||||
|
max_forward_wait = 12
|
||||||
|
last_forward_time = 0.0
|
||||||
|
|
||||||
whoami = subprocess.getoutput(["whoami"])
|
whoami = subprocess.getoutput("whoami")
|
||||||
with open(f'/home/{whoami}/ze_runner/config.json') as jsonfile:
|
with open(f'/home/{whoami}/ze_runner/config.json') as jsonfile:
|
||||||
data_ports = json.load(jsonfile)
|
data_ports = json.load(jsonfile)
|
||||||
looptestPath = f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg"
|
looptestPath = f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg"
|
||||||
@ -48,12 +58,9 @@ def clean_up_files():
|
|||||||
#due to steam child processes.
|
#due to steam child processes.
|
||||||
#even with steam turned offline might there be chromium web browsers left over from steam who still hold processes open.
|
#even with steam turned offline might there be chromium web browsers left over from steam who still hold processes open.
|
||||||
#only kind of potential issues from this is steam cloud being out of sync, which is really fucking irrelevant.
|
#only kind of potential issues from this is steam cloud being out of sync, which is really fucking irrelevant.
|
||||||
subprocess.Popen(["rm -rf /tmp/steam*"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()[0]
|
for pattern in ["/tmp/steam*", "/tmp/dbus*", "/tmp/pressure*", "/tmp/tigervnc*", "/tmp/dumps*", "/dev/shm/u100*"]:
|
||||||
subprocess.Popen(["rm -rf /tmp/dbus*"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()[0]
|
for path in glob.glob(pattern):
|
||||||
subprocess.Popen(["rm -rf /tmp/pressure*"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()[0]
|
subprocess.run(["rm", "-rf", path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
subprocess.Popen(["rm -rf /tmp/tigervnc*"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()[0]
|
|
||||||
subprocess.Popen(["rm -rf /tmp/dumps*"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()[0]
|
|
||||||
subprocess.Popen(["rm -rf /dev/shm/u100*"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()[0]
|
|
||||||
#users should only have permissions to delete their own files probably
|
#users should only have permissions to delete their own files probably
|
||||||
|
|
||||||
#check if any bz2 files left over.
|
#check if any bz2 files left over.
|
||||||
@ -61,19 +68,17 @@ def clean_up_files():
|
|||||||
file_size = None
|
file_size = None
|
||||||
while True:
|
while True:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
stdout, stderr = subprocess.Popen(["ls", "-l", f], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
if not os.path.exists(f):
|
||||||
if stderr: break #finished downloading, bz2 file is removed.
|
break # finished downloading, bz2 file is removed.
|
||||||
if stdout:
|
cur_file_size = os.path.getsize(f)
|
||||||
cur_file_size = stdout.decode().split("autismbots")[1].strip().split(" ")[0]
|
if file_size == cur_file_size:
|
||||||
if file_size == cur_file_size:
|
# delete the bz2 file if its not progressing downloading
|
||||||
#delete the bz2 file if its not progressing downloading
|
subprocess.run(["rm", "-rf", f], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
#print("deleting file: ", f)
|
break
|
||||||
subprocess.Popen(["rm", "-rf", f], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
file_size = cur_file_size
|
||||||
break
|
|
||||||
file_size = cur_file_size
|
|
||||||
|
|
||||||
#clean up the game cache as it otherwise just keeps growing in gigabyte size
|
#clean up the game cache as it otherwise just keeps growing in gigabyte size
|
||||||
subprocess.Popen(["rm", "-rf", f"/home/{whoami}/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cache"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
subprocess.run(["rm", "-rf", f"/home/{whoami}/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cache"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
print('reached exithandler')
|
print('reached exithandler')
|
||||||
@ -82,7 +87,7 @@ def exit_handler():
|
|||||||
kill_owned_process("pidof xterm")
|
kill_owned_process("pidof xterm")
|
||||||
|
|
||||||
clean_up_files()
|
clean_up_files()
|
||||||
subprocess.getoutput([f"pkill -9 -u {whoami}"])
|
subprocess.getoutput(f"pkill -9 -u {whoami}")
|
||||||
|
|
||||||
def bot_process_movement(input_line):
|
def bot_process_movement(input_line):
|
||||||
dist_target = input_line[input_line.index("dist_target:") + len("dist_target:"):input_line.index("enemy_distance")]
|
dist_target = input_line[input_line.index("dist_target:") + len("dist_target:"):input_line.index("enemy_distance")]
|
||||||
@ -94,27 +99,44 @@ def bot_process_movement(input_line):
|
|||||||
dist_target = float(dist_target)
|
dist_target = float(dist_target)
|
||||||
enemy_distance = float(enemy_distance)
|
enemy_distance = float(enemy_distance)
|
||||||
targeteam = int(targeteam)
|
targeteam = int(targeteam)
|
||||||
#request by bane that bots should simply not infect people shrug
|
|
||||||
strInput = "-attack; wait 2; -use; wait 5; -attack; wait 5; cl_minmodels 1; wait 2; +use; wait 5; "
|
global last_forward_time
|
||||||
|
strInput = "cl_minmodels 1; wait 2; "
|
||||||
|
|
||||||
if targeteam == 3:
|
if targeteam == 3:
|
||||||
strInput = "-attack; wait 2; -use; wait 5; -attack; wait 5; cl_minmodels 1; wait 2; +use; wait 5; "
|
strInput = "cl_minmodels 1; wait 2; "
|
||||||
#python has no switches and such
|
|
||||||
if state in [5, 7]:
|
# Keep movement fluid: avoid frequent full stops.
|
||||||
strInput += "-forward; wait 2; use weapon_knife; wait 5;"
|
should_push_forward = False
|
||||||
elif state >= 3:
|
if state >= 3 or state == 1 or state == 8:
|
||||||
strInput += "use weapon_knife; wait 5; +forward; wait 2;"
|
should_push_forward = True
|
||||||
elif state == 0:
|
if dist_target > team_follow_distance or enemy_distance <= enemy_chase_distance:
|
||||||
strInput += "use weapon_p90; wait 2; -forward; wait 2;"
|
should_push_forward = True
|
||||||
elif state == 1:
|
if time.time() - last_forward_time < momentum_hold_seconds:
|
||||||
strInput += "wait 2; use weapon_elite; wait 3; +forward; wait 2;"
|
should_push_forward = True
|
||||||
elif state == 2:
|
|
||||||
strInput += "-forward; wait 2; use weapon_elite; wait 3;"
|
if should_push_forward:
|
||||||
elif state == 8:
|
strInput += "+forward; wait 2;"
|
||||||
strInput += "use weapon_knife; wait 5; +forward; wait 2;"
|
last_forward_time = time.time()
|
||||||
|
else:
|
||||||
|
strInput += "wait 2;"
|
||||||
|
|
||||||
#print('dist_target: ', dist_target, ' enemy distance: ', enemy_distance, ' targeteam: ', targeteam, ' state:', state)
|
#print('dist_target: ', dist_target, ' enemy distance: ', enemy_distance, ' targeteam: ', targeteam, ' state:', state)
|
||||||
if state not in [0, 2, 5, 7, 8]:
|
if dist_target > team_follow_distance:
|
||||||
|
# Favor forward movement when drifting away from teammates.
|
||||||
|
strInput += f"+forward; wait {random.randint(min_forward_wait, max_forward_wait)}; "
|
||||||
|
elif enemy_distance <= enemy_chase_distance:
|
||||||
|
# Close enemy: keep pressure by closing distance.
|
||||||
|
strInput += f"+forward; wait {random.randint(min_forward_wait, max_forward_wait)}; "
|
||||||
|
if enemy_distance <= infect_chase_distance:
|
||||||
|
# Chase and attack at close range.
|
||||||
|
strInput += "+forward; wait 10; +attack; wait 20; -attack; "
|
||||||
|
if dist_target <= team_follow_distance:
|
||||||
|
# Keep subtle strafes to avoid robotic straight lines.
|
||||||
strInput = strinput_append(strInput, 2)
|
strInput = strinput_append(strInput, 2)
|
||||||
|
if enemy_distance <= shoot_distance:
|
||||||
|
for _ in range(shoot_burst_cycles):
|
||||||
|
strInput += "+attack; wait 12; -attack; wait 4; "
|
||||||
#print('strInput final:', strInput)
|
#print('strInput final:', strInput)
|
||||||
writeCfgInput(strInput)
|
writeCfgInput(strInput)
|
||||||
|
|
||||||
@ -160,7 +182,7 @@ def restart_sdl_and_steam():
|
|||||||
cmd = f'vncserver -localhost no -geometry 1x1 -depth 24'
|
cmd = f'vncserver -localhost no -geometry 1x1 -depth 24'
|
||||||
#cmd = f'vncserver -localhost no -geometry 800x800 -depth 24'
|
#cmd = f'vncserver -localhost no -geometry 800x800 -depth 24'
|
||||||
#print(f'cmd: {cmd}')
|
#print(f'cmd: {cmd}')
|
||||||
subprocess.getoutput([cmd])
|
subprocess.getoutput(cmd)
|
||||||
print('reached .bashrc executing steam and variables')
|
print('reached .bashrc executing steam and variables')
|
||||||
|
|
||||||
def bot_connect(data):
|
def bot_connect(data):
|
||||||
@ -176,14 +198,16 @@ def cpulimit_pid_of_game():
|
|||||||
# ' > /dev/null' redirects stdout to /dev/null
|
# ' > /dev/null' redirects stdout to /dev/null
|
||||||
# '2>&1' redirects stderr to the same place as stdout
|
# '2>&1' redirects stderr to the same place as stdout
|
||||||
pid = return_user_owned_pid("pidof cstrike_linux64")
|
pid = return_user_owned_pid("pidof cstrike_linux64")
|
||||||
|
if pid is None:
|
||||||
|
return
|
||||||
cmd = f"cpulimit --pid={pid} --limit=25 --background > /dev/null 2>&1"
|
cmd = f"cpulimit --pid={pid} --limit=25 --background > /dev/null 2>&1"
|
||||||
#cmd = f"cpulimit --pid={pid} --limit=55 --background > /dev/null 2>&1"
|
#cmd = f"cpulimit --pid={pid} --limit=55 --background > /dev/null 2>&1"
|
||||||
subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE).communicate()[0]
|
subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
|
||||||
|
|
||||||
def my_file_created_function(event_path):
|
def my_file_created_function(event_path):
|
||||||
#print(f"New file created: {event_path}")
|
#print(f"New file created: {event_path}")
|
||||||
if event_path.startswith("/tmp/source_engine") and event_path.endswith(".lock"):
|
if event_path.startswith("/tmp/source_engine") and event_path.endswith(".lock"):
|
||||||
subprocess.Popen([f"rm -rf {event_path}"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
subprocess.run(["rm", "-rf", event_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
return
|
return
|
||||||
if not event_path.lower().endswith(".bsp.bz2"):
|
if not event_path.lower().endswith(".bsp.bz2"):
|
||||||
return
|
return
|
||||||
@ -194,20 +218,16 @@ def my_file_created_function(event_path):
|
|||||||
file_size = None
|
file_size = None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
stdout, stderr = subprocess.Popen(["ls", "-l", event_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
if not os.path.exists(event_path):
|
||||||
if stderr:
|
|
||||||
#print('stderr: ', stderr)
|
|
||||||
print(f'finished the bz2 file {event_path}')
|
print(f'finished the bz2 file {event_path}')
|
||||||
break
|
break
|
||||||
|
|
||||||
#print('stdout: ', stdout)
|
owner = pwd.getpwuid(os.stat(event_path).st_uid).pw_name
|
||||||
user = stdout.decode().split("autismbots")[0]
|
if whoami == owner: # we are the user that owns the file on disk
|
||||||
if whoami in user: #we are the user that owns the file on disk
|
cur_file_size = os.path.getsize(event_path)
|
||||||
cur_file_size = stdout.decode().split("autismbots")[1].strip().split(" ")[0]
|
|
||||||
if file_size == cur_file_size:
|
if file_size == cur_file_size:
|
||||||
#print('cur_file_size: ', cur_file_size, ' stdout decode: ', stdout.decode())
|
|
||||||
print(f"Deleting {event_path} due to being stuck on download.")
|
print(f"Deleting {event_path} due to being stuck on download.")
|
||||||
subprocess.Popen(["rm", "-rf", event_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
subprocess.run(["rm", "-rf", event_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
continue
|
continue
|
||||||
file_size = cur_file_size
|
file_size = cur_file_size
|
||||||
else:
|
else:
|
||||||
@ -243,6 +263,10 @@ def handle_bz2_files():
|
|||||||
observer.start()
|
observer.start()
|
||||||
return observer
|
return observer
|
||||||
|
|
||||||
|
def bot_process_surf(input_line):
|
||||||
|
# Placeholder to avoid crashes until surfing behavior is implemented.
|
||||||
|
return
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
atexit.register(exit_handler)
|
atexit.register(exit_handler)
|
||||||
local_port = data_ports['udp_port']
|
local_port = data_ports['udp_port']
|
||||||
@ -259,7 +283,7 @@ if __name__ == '__main__':
|
|||||||
maps_folder_size = float(maps_folder_size[:-1])
|
maps_folder_size = float(maps_folder_size[:-1])
|
||||||
if maps_folder_size > 40.0:
|
if maps_folder_size > 40.0:
|
||||||
for f in glob.glob(f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download/maps/*"):
|
for f in glob.glob(f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download/maps/*"):
|
||||||
subprocess.Popen(["rm", "-rf", f], stdout=subprocess.PIPE).communicate()
|
subprocess.run(["rm", "-rf", f], stdout=subprocess.PIPE)
|
||||||
|
|
||||||
restart_sdl_and_steam()
|
restart_sdl_and_steam()
|
||||||
is_bot_connected_to_ze2 = False
|
is_bot_connected_to_ze2 = False
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user