Guest User

Untitled

a guest
May 9th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. """Script to hotswap plugin from bakkesmod process.
  2.  
  3. 1. Connects to BakkesMod rcon
  4. 2. Unloads plugin
  5. 3. Replaces DLL file
  6. 4. Loads plugin
  7.  
  8. TODO: save config?
  9. """
  10. import sys, os, shutil, websockets, time
  11. import asyncio
  12.  
  13. bakkesmod_plugin_folder = "F:/SteamLibrary/steamapps/common/rocketleague/Binaries/Win32/bakkesmod/plugins/"
  14. bakkesmod_server = 'ws://127.0.0.1:9002'
  15. rcon_password = 'password'
  16. swap_file = ""
  17.  
  18. def replace_plugin_file():
  19.     filename = os.path.basename(swap_file)
  20.     dst_file = bakkesmod_plugin_folder + filename
  21.     print(dst_file)
  22.    
  23.     if os.path.exists(dst_file):
  24.         os.remove(dst_file)
  25.     shutil.copyfile(swap_file, dst_file)
  26.  
  27. async def main_loop():
  28.     try:
  29.         async with websockets.connect(bakkesmod_server, timeout=.1) as websocket:
  30.             await websocket.send('rcon_password ' + rcon_password)
  31.             auth_status = await websocket.recv()
  32.             assert auth_status == 'authyes'
  33.  
  34.             filename = os.path.basename(swap_file)
  35.             plugin_name = filename[0:filename.index('.')]
  36.             print("Copying " + filename + "")
  37.             await websocket.send("plugin unload " + plugin_name)
  38.             time.sleep(0.1)
  39.             replace_plugin_file()
  40.             time.sleep(0.1)
  41.             await websocket.send("plugin load " + plugin_name)
  42.     except:
  43.         replace_plugin_file()
  44.  
  45.  
  46. if __name__ == '__main__':
  47.     if len(sys.argv) == 1:
  48.         exit()
  49.  
  50.     swap_file = sys.argv[1]
  51.     asyncio.get_event_loop().run_until_complete(main_loop())
Add Comment
Please, Sign In to add comment