Skip to content

Commit

Permalink
LADX: fix bizhawk 2.9 (ArchipelagoMW#1784)
Browse files Browse the repository at this point in the history
  • Loading branch information
zig-for authored May 3, 2023
1 parent a60f370 commit 97fd78b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions data/lua/common.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
7 changes: 5 additions & 2 deletions data/lua/connector_ladx_bizhawk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions data/lua/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ else
_ENV = M -- for 5.2
end

M.socket = socket

-----------------------------------------------------------------------------
-- Exported auxiliar functions
-----------------------------------------------------------------------------
Expand Down

0 comments on commit 97fd78b

Please sign in to comment.