From 97fd78ba1bf2a20636f9c0dd2c17fd5cfbe89f35 Mon Sep 17 00:00:00 2001 From: zig-for Date: Wed, 3 May 2023 14:35:14 -0700 Subject: [PATCH] LADX: fix bizhawk 2.9 (#1784) --- data/lua/common.lua | 6 ++++++ data/lua/connector_ladx_bizhawk.lua | 7 +++++-- data/lua/socket.lua | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/data/lua/common.lua b/data/lua/common.lua index 93caf9bdb4b8..81b450504c7b 100644 --- a/data/lua/common.lua +++ b/data/lua/common.lua @@ -1,3 +1,5 @@ +print("Loading AP lua connector script") + local lua_major, lua_minor = _VERSION:match("Lua (%d+)%.(%d+)") lua_major = tonumber(lua_major) lua_minor = tonumber(lua_minor) @@ -101,3 +103,7 @@ function checkBizhawkVersion() end return true end + +function stripPrefix(s, p) + return (s:sub(0, #p) == p) and s:sub(#p+1) or s +end diff --git a/data/lua/connector_ladx_bizhawk.lua b/data/lua/connector_ladx_bizhawk.lua index e318015cb053..69ff6ff13731 100644 --- a/data/lua/connector_ladx_bizhawk.lua +++ b/data/lua/connector_ladx_bizhawk.lua @@ -43,12 +43,12 @@ local socket = require("socket") -local udp = socket.udp() +local udp = socket.socket.udp() +require('common') udp:setsockname('127.0.0.1', 55355) udp:settimeout(0) - while true do -- Attempt to lessen the CPU load by only polling the UDP socket every x frames. -- x = 10 is entirely arbitrary, very little thought went into it. @@ -97,6 +97,7 @@ while true do end elseif command == "READ_CORE_MEMORY" then local _, address, length = string.match(data, "(%S+) (%S+) (%S+)") + address = stripPrefix(address, "0x") address = tonumber(address, 16) length = tonumber(length) @@ -116,12 +117,14 @@ while true do udp:sendto(reply, msg_or_ip, port_or_nil) elseif command == "WRITE_CORE_MEMORY" then local _, address = string.match(data, "(%S+) (%S+)") + address = stripPrefix(address, "0x") address = tonumber(address, 16) local to_write = {} local i = 1 for byte_str in string.gmatch(data, "%S+") do if i > 2 then + byte_str = stripPrefix(byte_str, "0x") table.insert(to_write, tonumber(byte_str, 16)) end i = i + 1 diff --git a/data/lua/socket.lua b/data/lua/socket.lua index 696f53a3279b..0005c3273ffb 100644 --- a/data/lua/socket.lua +++ b/data/lua/socket.lua @@ -58,6 +58,8 @@ else _ENV = M -- for 5.2 end +M.socket = socket + ----------------------------------------------------------------------------- -- Exported auxiliar functions -----------------------------------------------------------------------------