Left 4 Dead 2

Left 4 Dead 2

评价数不足
rpg服.
由 miru 制作
按一下按键自动退出不想进的房间
   
奖励
收藏
已收藏
取消收藏
g
autoexec.cfg 里加
bind f7 "clear; status; wait 100; condump;" bind f8 "disconnect"

安装python跟module
pip install keyboard psutil
py脚本直接让AI写的,自己改keywords
点进房间按F7自动过滤房间名字然后断开连接
import os import time import keyboard import psutil import winreg import re keywords = ["rpg0", "rpg1"] target_process = "left4dead2.exe" def find_steam_path(): try: with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Valve\Steam") as key: steam_path, _ = winreg.QueryValueEx(key, "SteamPath") return steam_path.replace("/", "\\") except Exception: return None def find_left4dead2_install(): steam_path = find_steam_path() if not steam_path: print("Could not find Steam installation path in registry.") return None library_file = os.path.join(steam_path, "steamapps", "libraryfolders.vdf") # Regex to find library paths, e.g., "path" "E:\\SteamLibrary" path_regex = re.compile(r'^\s*"path"\s+"(.+?)"', re.IGNORECASE) # Regex to find app IDs, e.g., "550" "0" app_regex = re.compile(r'^\s*"550"\s+"(\d+)"', re.IGNORECASE) current_path = None found_game_path = None all_libraries = [] try: with open(library_file, "r", encoding="utf-8", errors="ignore") as f: for line in f: path_match = path_regex.search(line) if path_match: # Found a new library path. Store it. path = path_match.group(1).replace('\\\\', '\\') current_path = os.path.join(path, "steamapps", "common") if current_path not in all_libraries: all_libraries.append(current_path) # print(f"Parsing library: {current_path}") # Debug line continue # Move to next line if current_path: # We are inside a library block, check for app 550 app_match = app_regex.search(line) if app_match: # Found app 550! This is the correct library. print(f"Found app 550 in library: {current_path}") found_game_path = os.path.join(current_path, "Left 4 Dead 2", "left4dead2") if os.path.isdir(found_game_path): print(f"Verified game install at: {found_game_path}") return found_game_path else: print(f"Found app 550 entry, but path is invalid: {found_game_path}") # Keep searching, maybe it's in another VDF entry? (unlikely) found_game_path = None # Reset except FileNotFoundError: print(f"Could not find library file: {library_file}") except Exception as e: print(f"Error parsing {library_file}: {e}") print("\nCould not find app 550 in libraryfolders.vdf. Fallback scanning...") default_game_path = os.path.join(steam_path, "steamapps", "common", "Left 4 Dead 2", "left4dead2") if os.path.isdir(default_game_path): print(f"Found game at default Steam path (fallback): {default_game_path}") return default_game_path print("Default path failed. Scanning all found libraries by folder name...") for base in all_libraries: if base == os.path.join(steam_path, "steamapps", "common"): continue # Already checked this one candidate = os.path.join(base, "Left 4 Dead 2", "left4dead2") if os.path.isdir(candidate): print(f"Found game at: {candidate} (fallback scan)") return candidate print("Could not find 'Left 4 Dead 2/left4dead2' folder in any Steam library.") return None def is_process_running(name): for proc in psutil.process_iter(attrs=["name"]): try: if proc.info["name"] and proc.info["name"].lower() == name.lower(): return True except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): pass return False def check_hostname_and_delete(file_path): time.sleep(0.5) # Give the game time to write the file if not os.path.exists(file_path): print("File not found (condump000.txt).") return try: with open(file_path, "r", encoding="utf-8-sig", errors="ignore") as f: for line in f: if line.lower().startswith("hostname:"): hostname = line.split(":", 1)[1].strip() print(f"Detected hostname: {hostname}") if any(k in hostname for k in keywords): print(">>> Keyword found — pressing F8 (disconnect).") keyboard.press_and_release("f8") else: print(">>> No keyword found.") break # Stop after finding the hostname # This block should be outside the 'with open' block # to ensure the file is closed before attempting to delete. try: os.remove(file_path) print("File deleted (condump000.txt).") except Exception as e: print(f"Failed to delete file: {e}") except Exception as e: print(f"Error reading file: {e}") # === MAIN SCRIPT === print("--- L4D2 Hostname Monitor ---") # === AUTO-DETECT GAME PATH === l4d2_dir = find_left4dead2_install() if not l4d2_dir: print("\n-----------------------------------------------------------------") print("Error: Could not find 'Left 4 Dead 2/left4dead2' folder automatically.") print("Please enter the path to your 'left4dead2' folder manually") print(r"(e.g., E:\SteamLibrary\steamapps\common\Left 4 Dead 2\left4dead2)") print("-----------------------------------------------------------------") l4d2_dir = input("> ").strip('"') if not os.path.isdir(l4d2_dir): print("Path not found. Exiting.") time.sleep(3) exit() file_path = os.path.join(l4d2_dir, "condump000.txt") print(f"\nMonitoring file: {file_path}") print("Monitoring for F7... (Press Ctrl+F6 to quit)") print("Will also auto-exit if Left 4 Dead 2 closes.") while True: try: # exit if process closes if not is_process_running(target_process): print(f"{target_process} not running — exiting script.") break # exit on Ctrl+F6 if keyboard.is_pressed("ctrl") and keyboard.is_pressed("f6"): print("Ctrl+F6 pressed — exiting script.") break # F7 triggers check if keyboard.is_pressed("f7"): print("-------------------------") print("F7 pressed — checking hostname...") # Ensure file doesn't exist from a previous run if os.path.exists(file_path): try: os.remove(file_path) print("Removed old condump file.") except Exception as e: print(f"Could not remove old condump file: {e}") # This assumes F7 is bound to 'condump' in your autoexec.cfg # The script will now wait for the file to be created. check_hostname_and_delete(file_path) time.sleep(0.5) # Debounce: prevent multiple checks from one keypress time.sleep(0.05) except Exception as e: print(f"An unexpected error occurred: {e}") break print("Script terminated.")