Advertisement
Thar0

DebugServer.js for decomp

May 29th, 2021 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // based on the pre-decomp https://github.com/MNGoldenEagle/DebugConsole/blob/master/DebugServer.js
  2.  
  3. var debugServer = new Server({port:411});
  4. var socket = null;
  5.  
  6. // default baserom location for function
  7. var proutSyncPrintf = 0x800021B0
  8.  
  9. // decomp map file path
  10. path_to_map_file = "path/to/z64.map"
  11.  
  12. // set function location from map file if provided
  13. if (path_to_map_file != "") {
  14.     var is_prout_pattern = /                0x00000000([\da-fA-F]{8})                is_proutSyncPrintf/
  15.     var map_content = fs.readFile(path_to_map_file)
  16.  
  17.     if (map_content == false) {
  18.         throw new Error("Failed to open map file for reading\n");
  19.     }
  20.     proutSyncPrintf = parseInt("0x" + is_prout_pattern.exec(map_content.toString())[1])
  21. }
  22.  
  23. debugServer.on('connection', function(newSocket) {
  24.     socket = newSocket;
  25.     console.print("Connection to client established.\n");
  26.     socket.write("Server reporting ready status.\n");
  27.    
  28.     newSocket.on('close', function() {
  29.         console.print("Connection to client lost.\n");
  30.         socket = null;
  31.     });
  32. });
  33.  
  34. events.onexec(proutSyncPrintf, function() {
  35.     var addr = gpr.a1;
  36.     var len = gpr.a2;
  37.    
  38.     var str = mem.getblock(addr, len);
  39.    
  40.     if (socket !== null) {
  41.         socket.write(str);
  42.     }
  43. });
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement