fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosSimplified loading generic controller maps even further2bc742e

settings-overhaul
1.5 KiB59 linesraw
1local core = {}
2
3function core.loadGenericControllerMap(addr, game)
4	local controllers = {
5		[1] = addr + 0xC * 0,
6		[2] = addr + 0xC * 1,
7		[3] = addr + 0xC * 2,
8		[4] = addr + 0xC * 3,
9	}
10
11	local controller_struct = {
12		[0x0] = { type = "short",	name = "controller.%d.buttons.pressed" },
13		[0x2] = { type = "sbyte",	name = "controller.%d.joystick.x" },
14		[0x3] = { type = "sbyte",	name = "controller.%d.joystick.y" },
15		[0x4] = { type = "sbyte",	name = "controller.%d.cstick.x" },
16		[0x5] = { type = "sbyte",	name = "controller.%d.cstick.y" },
17		[0x6] = { type = "byte",	name = "controller.%d.analog.l" },
18		[0x7] = { type = "byte",	name = "controller.%d.analog.r" },
19		[0xA] = { type = "byte",	name = "controller.%d.plugged" },
20	}
21
22	for port, address in ipairs(controllers) do
23		for offset, info in pairs(controller_struct) do
24			game.memorymap[address + offset] = {
25				type = info.type,
26				debug = info.debug,
27				name = info.name:format(port),
28			}
29		end
30	end
31
32	game.translateAxis = core.translateAxis
33	game.translateTriggers = core.translateTriggers
34end
35
36local abs = math.abs
37
38-- These functions seem to apply to many games
39
40function core.translateAxis(x, y)
41	x = x/72
42	y = y/72
43
44	local near = 1 - (abs(abs(x) - abs(y))) * 0.72
45
46	local angle = math.atan2(x, y)
47	local mag = math.sqrt(x*x + y*y)
48
49	-- Amplify the magnitute when x,y values are headed towards a diagonal
50	return x + math.sin(angle) * mag * near * 0.28, y + math.cos(angle) * mag * near * 0.28
51end
52
53local min = math.min
54
55function core.translateTriggers(l, r)
56	return min(1, l/125), min(1, r/125)
57end
58
59return core