Skip to content

Commit ead21ba

Browse files
committed
Fixed auto port switcher not working if the slippi username contained special characaters
1 parent f3602c0 commit ead21ba

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

source/main.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ end
7979

8080
memory.hook("slippi.player.*.name", "Slippi Auto Port Switcher", function(port, name)
8181
if PANEL_SETTINGS:IsSlippiNetplay() and PANEL_SETTINGS:IsSlippiAutoPortEnabled() then
82-
if PANEL_SETTINGS:GetSlippiUsername() == name then
82+
if PANEL_SETTINGS:GetSlippiUsername() == melee.convertStr(name) then
8383
PORT = port - 1
8484
CONTROLLER_PORT_DISPLAY = love.timer.getTime() + 1.5 -- Show the port display number for 3 seconds
8585
end

source/melee.lua

+37
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,41 @@ function melee.getPlayerColor(port)
263263
return PLAYER_COLORS[port] or color_white
264264
end
265265

266+
local char_replacement_map = {
267+
[0x8149] = "!", [0x8168] = "\"", [0x8194] = "#", [0x8190] = "$",
268+
[0x8193] = "%", [0x8195] = "&", [0x8166] = "'", [0x8169] = "(",
269+
[0x816A] = ")", [0x8196] = "*", [0x817B] = "+", [0x8143] = ",",
270+
[0x817C] = "-", [0x8144] = ".", [0x815E] = "/", [0x8146] = ":",
271+
[0x8147] = ";", [0x8183] = "<", [0x8181] = "=", [0x8184] = ">",
272+
[0x8148] = "?", [0x8197] = "@", [0x816D] = "[", [0x815F] = "\\",
273+
[0x816E] = "]", [0x814F] = "^", [0x8151] = "_", [0x814D] = "`",
274+
[0x816F] = "{", [0x8162] = "|", [0x8170] = "}", [0x8160] = "~",
275+
}
276+
277+
function melee.convertStr(str)
278+
local niceStr = ""
279+
local i = 1
280+
while i <= #str do
281+
local c1 = string.sub(str, i, i)
282+
local b1 = string.byte(c1)
283+
284+
if bit.band(b1, 0x80) == 0x80 then
285+
local c2 = string.sub(str, i + 1, i + 1)
286+
local b2 = string.byte(c2)
287+
288+
local b16 = bit.bor(bit.lshift(b1, 8), bit.lshift(b2, 0))
289+
290+
if char_replacement_map[b16] then
291+
niceStr = niceStr .. char_replacement_map[b16]
292+
end
293+
294+
i = i + 2
295+
else
296+
niceStr = niceStr .. c1
297+
i = i + 1
298+
end
299+
end
300+
return niceStr
301+
end
302+
266303
return melee

source/modules/extensions/string.lua

+12
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,16 @@ function string.enescapeURL(url)
220220
return gsub(url, "%%(%x%x)", function(hex)
221221
return char(tonumber(hex, 16))
222222
end)
223+
end
224+
225+
function string.fromhex(str)
226+
return (str:gsub('..', function (cc)
227+
return string.char(tonumber(cc, 16))
228+
end))
229+
end
230+
231+
function string.tohex(str)
232+
return (str:gsub('.', function (c)
233+
return string.format('%02X', string.byte(c))
234+
end))
223235
end

0 commit comments

Comments
 (0)