├── LICENSE ├── README.md ├── game-monitor.py ├── monitor.py ├── packaged.json ├── setup.bat └── start-monitor.bat /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Mumble 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XToys Game Monitor 2 | Have sex toys react to events in a video game. For use with the https://xtoys.app website. 3 | 4 | # Setup Instructions 5 | 1. Download all files. 6 | 2. Run setup.bat which will register XToys Game Monitor as a Chrome Native Messaging source. 7 | 3. Install Python and all the required python dependencies: 8 | ``` 9 | pip install pymem 10 | pip install multiprocessing 11 | pip install elevate 12 | ``` 13 | 14 | # Usage 15 | 1. On https://xtoys.app add an XToys Game Monitor block and a relevant script. 16 | 2. Start the XToys Game Monitor block. 17 | 3. Install the XToys Webpage Monitor Chrome extension when prompted. 18 | 4. Start the script. 19 | -------------------------------------------------------------------------------- /game-monitor.py: -------------------------------------------------------------------------------- 1 | import time 2 | import threading 3 | import pymem 4 | import json 5 | from multiprocessing.connection import Client 6 | from elevate import elevate 7 | import logging 8 | import traceback 9 | import string 10 | import win32api 11 | import win32con 12 | 13 | # This file must be run as admin so that it has permission to read process memory 14 | elevate(show_console=False) 15 | 16 | formatter = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(module)s - %(message)s') 17 | handler = logging.FileHandler('xtoys.log', mode = 'w') 18 | handler.setFormatter(formatter) 19 | logger = logging.getLogger('xtoys') 20 | logger.setLevel(logging.DEBUG) 21 | logger.addHandler(handler) 22 | 23 | class GameMonitor: 24 | def __init__(self): 25 | self.pm = None 26 | self.modules = {} 27 | self.variables = {} 28 | 29 | def monitor_game(self, state, comm): 30 | logger = logging.getLogger('xtoys') 31 | try: 32 | while True: 33 | if self.pm is None: 34 | # No data defined 35 | if 'name' not in state: 36 | time.sleep(1) 37 | continue 38 | # Try to find game 39 | try: 40 | self.pm = pymem.Pymem(state['name']) 41 | except Exception as e: 42 | time.sleep(1) 43 | continue 44 | 45 | logger.debug(state['name'] + ' game found') 46 | 47 | # Find all base addresses 48 | modules_list = list(self.pm.list_modules()) 49 | for module in modules_list: 50 | self.modules[module.name] = module 51 | 52 | state["game_active"] = True 53 | comm.send_message({ "event": "active_changed", "state": True }) 54 | 55 | # Loop through state values 56 | for name, scan_entry in state['scan_data'].items(): 57 | changed = False 58 | 59 | if 'address' not in scan_entry: 60 | # Find final address 61 | address = 0 62 | stop_address = 0x7fffffffffff 63 | if 'start_from_type' in scan_entry and 'start_from' in scan_entry: 64 | start_from = scan_entry['start_from'] 65 | start_from_type = scan_entry['start_from_type'] 66 | if start_from_type == 'module': 67 | if start_from not in self.modules: 68 | scan_entry['address'] = -1 69 | scan_entry['result'] = -1 70 | logger.debug(scan_entry['name'] + ': ' + start_from + ' module not found') 71 | continue # Skipping if invalid module name was given for this scan_entry 72 | module = self.modules[start_from] 73 | address = module.lpBaseOfDll 74 | stop_address = address + module.SizeOfImage 75 | elif start_from_type == 'variable': 76 | if start_from not in self.variables: 77 | scan_entry['address'] = -1 78 | scan_entry['result'] = -1 79 | logger.debug(scan_entry['name'] + ': ' + start_from + ' variable not found') 80 | continue # Skipping if invalid variable name was given for this scan_entry 81 | address = self.variables[start_from] 82 | elif start_from_type == 'static': 83 | address = start_from 84 | 85 | if 'aob' in scan_entry: 86 | bytesArr = bytes.fromhex(scan_entry['aob'].replace('.', '2E')) 87 | page_address = address 88 | while page_address < stop_address: 89 | next_page, found_address = pymem.pattern.scan_pattern_page(self.pm.process_handle, page_address, bytesArr) 90 | if found_address: 91 | address = found_address 92 | break 93 | page_address = next_page 94 | 95 | if 'offset' in scan_entry: 96 | address += scan_entry['offset'] 97 | 98 | if 'pointers' in scan_entry: 99 | pointers = scan_entry['pointers'] 100 | address = self.pm.read_int(address) 101 | for pointer in pointers[:-1]: 102 | address = self.pm.read_int(address + pointer) 103 | address = address + pointers[-1] 104 | 105 | self.variables[name] = address 106 | scan_entry['address'] = address 107 | logger.debug(name + ': Address ' + hex(address)) 108 | 109 | address = scan_entry['address'] 110 | if address == -1: # Skip scan_entries where we failed to find a valid address 111 | continue 112 | # read in the value we're looking for 113 | val_type = scan_entry['type'] 114 | result = None 115 | if val_type == 'char': 116 | result = self.pm.read_char(address) 117 | elif val_type == 'short': 118 | result = self.pm.read_short(address) 119 | elif val_type == 'int': 120 | result = self.pm.read_int(address) 121 | elif val_type == 'long': 122 | result = self.pm.read_long(address) 123 | elif val_type == 'longlong': 124 | result = self.pm.read_longlong(address) 125 | elif val_type == 'double': 126 | result = self.pm.read_double(address) 127 | elif val_type == 'float': 128 | result = self.pm.read_float(address) 129 | elif val_type == 'string': 130 | result = self.pm.read_string(address, scan_entry['length']) 131 | elif val_type == 'bytes': 132 | result = int.from_bytes(self.pm.read_bytes(address, scan_entry['length']), 'big') 133 | if 'result' not in scan_entry or result != scan_entry['result']: 134 | scan_entry['result'] = result 135 | logger.debug(name + ': Value ' + str(result)) 136 | changed = True 137 | 138 | # If something changed notify the other process so it can send the data to the XToys Chrome extension 139 | if changed: 140 | comm.send_message({"event": "entry_changed", "name": name, "scan_data": scan_entry }) 141 | time.sleep(0.1) 142 | 143 | except Exception: 144 | logger.debug(traceback.format_exc()) 145 | 146 | class Communication: 147 | def __init__(self): 148 | address = ('localhost', 6000) 149 | while True: 150 | try: 151 | self.conn = Client(address, authkey=b'xtoysnotverysecretkey') 152 | return 153 | except Exception as e: 154 | time.sleep(1) 155 | 156 | # Send message to other process 157 | def send_message(self, message): 158 | self.conn.send(message) 159 | 160 | # Listen for messages from other process 161 | def monitor_loop(self, state, game_monitor): 162 | 163 | logger = logging.getLogger('xtoys') 164 | 165 | try: 166 | while True: 167 | message = self.conn.recv() 168 | logger.debug('Message from XToys: ' + message) 169 | json_data = json.loads(message) 170 | action = json_data['action'] 171 | if action == 'set_name': 172 | # If XToys asked to change games, clear existing process monitor 173 | if 'name' in state and state['name'] != json_data['name']: 174 | game_monitor.pm = None 175 | state['game_active'] = False 176 | # Some sanitiziation to remove invalid characters from the filename XToys sent Game Monitor 177 | valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits) 178 | pending_name = ''.join(c for c in json_data['name'] if c in valid_chars) 179 | self.request_permission(pending_name, state) 180 | elif action == 'set_scan_entry': 181 | name = json_data['name'] 182 | state['scan_data'][name] = json_data['scan_data'] 183 | except Exception: 184 | logger.debug(traceback.format_exc()) 185 | 186 | def request_permission(self, game_name, state): 187 | choice = win32api.MessageBox(None, 'XToys is requesting to monitor ' + game_name + '. Allow access?', 'Permission Request', win32con.MB_YESNO | win32con.MB_ICONQUESTION | win32con.MB_SYSTEMMODAL) 188 | if choice == win32con.IDYES: 189 | state['name'] = game_name 190 | 191 | def main(): 192 | state = { 193 | "scan_data": {} 194 | } 195 | 196 | communication = Communication() 197 | game_monitor = GameMonitor() 198 | 199 | thread = threading.Thread(target=game_monitor.monitor_game, args=(state,communication)) 200 | thread.daemon = True 201 | thread.start() 202 | 203 | communication.monitor_loop(state, game_monitor) 204 | 205 | if __name__ == '__main__': 206 | main() 207 | -------------------------------------------------------------------------------- /monitor.py: -------------------------------------------------------------------------------- 1 | import time 2 | import sys 3 | import threading 4 | import struct 5 | import json 6 | from multiprocessing.connection import Listener 7 | import os 8 | 9 | class GameMonitorCommunication: 10 | def __init__(self): 11 | address = ('localhost', 6000) # family is deduced to be 'AF_INET' 12 | self.listener = Listener(address, authkey=b'xtoysnotverysecretkey') 13 | self.conn = self.listener.accept() 14 | 15 | # Send message to other process 16 | def send_message(self, message): 17 | self.conn.send(message) 18 | 19 | # Listen for messages from other process and immediately pass through to Chrome extension 20 | def monitor_loop(self, chrome_ext): 21 | while True: 22 | message = self.conn.recv() 23 | chrome_ext.send_message(message) 24 | 25 | class ChromeExtensionCommunication: 26 | def encode_message(self, messageContent): 27 | encodedContent = json.dumps(messageContent).encode('utf-8') 28 | encodedLength = struct.pack('@I', len(encodedContent)) 29 | return {'length': encodedLength, 'content': encodedContent} 30 | 31 | # Send message to Chrome extension 32 | def send_message(self, message): 33 | encoded_message = self.encode_message(message) 34 | sys.stdout.buffer.write(encoded_message['length']) 35 | sys.stdout.buffer.write(encoded_message['content']) 36 | sys.stdout.buffer.flush() 37 | 38 | # Listen for messages from Chrome extension and immediately pass through to other process 39 | def monitor_loop(self, game_monitor): 40 | while True: 41 | raw_length = sys.stdin.buffer.read(4) 42 | if not raw_length: 43 | sys.exit(0) 44 | message_length = struct.unpack('i', raw_length)[0] 45 | message = sys.stdin.buffer.read(message_length).decode('utf-8') 46 | game_monitor.send_message(message) 47 | 48 | def main(): 49 | version = "1.1" 50 | 51 | # Launch other process (exe if Game Monitor has been compiled, python file otherwise) 52 | if getattr(sys, 'frozen', False): 53 | os.system('START /b game-monitor.exe') 54 | elif __file__: 55 | os.system('START /b python game-monitor.py') 56 | 57 | game_monitor = GameMonitorCommunication() 58 | chrome_ext = ChromeExtensionCommunication() 59 | 60 | chrome_ext.send_message({ "version": version }) 61 | 62 | thread = threading.Thread(target=game_monitor.monitor_loop, args=(chrome_ext,)) 63 | thread.daemon = True 64 | thread.start() 65 | 66 | chrome_ext.monitor_loop(game_monitor,) 67 | 68 | if __name__ == '__main__': 69 | main() 70 | -------------------------------------------------------------------------------- /packaged.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app.xtoys.gamemonitor", 3 | "description": "XToys Game Monitor", 4 | "path": "start-monitor.bat", 5 | "type": "stdio", 6 | "allowed_origins": [ 7 | "chrome-extension://hhddbheipffnedlmnefnkjeplkgbajij/" 8 | ] 9 | } -------------------------------------------------------------------------------- /setup.bat: -------------------------------------------------------------------------------- 1 | REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\app.xtoys.gamemonitor" /ve /t REG_SZ /d "%~dp0package.json" /f 2 | -------------------------------------------------------------------------------- /start-monitor.bat: -------------------------------------------------------------------------------- 1 | @Echo OFF 2 | python monitor.py %* --------------------------------------------------------------------------------