Skip to content

Commit 9407409

Browse files
committed
BizHawk 2.8+ support
There may be regressions, hit me up in the issues if you find any.
1 parent fa3ec96 commit 9407409

3 files changed

Lines changed: 73 additions & 16 deletions

File tree

ScriptHawk.lua

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,51 @@ if emu.getluacore == nil then -- 2.2.2 (March 2018)
1515
end
1616
end
1717

18+
-- 2.8 (Feb 2022)
19+
if math.atan2 == nil then
20+
-- Stop the console spam for deprecated ops
21+
emu.getluacore = client.get_lua_engine;
22+
bit = require "lib.pngLua.numberlua";
23+
bit.check = function(value, _bit)
24+
return (bit.band(value, bit.lshift(1, _bit))) ~= 0;
25+
end
26+
bit.set = function(value, _bit)
27+
return (bit.bor(value, bit.lshift(1, _bit)));
28+
end
29+
bit.clear = function(value, _bit)
30+
return (bit.band(value, bit.bnot(bit.lshift(1, _bit))));
31+
end
32+
33+
-- atan2 polyfill
34+
math.atan2 = function(y, x)
35+
if x == 0 then
36+
if y == 0 then
37+
return 0;
38+
end
39+
if y < 0 then
40+
return -(math.pi / 2);
41+
else
42+
return (math.pi / 2);
43+
end
44+
end
45+
46+
local r = math.atan(y/x);
47+
48+
if x > 0 then
49+
return r;
50+
end
51+
52+
if y < 0 then
53+
r = r - math.pi;
54+
else
55+
r = r + math.pi;
56+
end
57+
58+
local tau = math.pi * 2;
59+
return r - math.floor(r / tau + 0.5) * tau;
60+
end
61+
end
62+
1863
---------------
1964
-- Libraries --
2065
---------------

games/dk64.lua

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6470,21 +6470,21 @@ function Game.getTempFlagName(byte, tempbit)
64706470
return "Unknown at "..toHexString(byte)..">"..tempbit;
64716471
end
64726472

6473-
function setTempFlag(byte,tempBit)
6473+
function setTempFlag(byte, tempBit)
64746474
local temp_flag_value = mainmemory.readbyte(temp_flag_boundaries.start[Game.version] + byte);
6475-
temp_flag_value = bit.set(temp_flag_value,tempBit);
6475+
temp_flag_value = bit.set(temp_flag_value, tempBit);
64766476
mainmemory.writebyte(temp_flag_boundaries.start[Game.version] + byte, temp_flag_value);
64776477
end
64786478

6479-
function clearTempFlag(byte,tempBit)
6479+
function clearTempFlag(byte, tempBit)
64806480
local temp_flag_value = mainmemory.readbyte(temp_flag_boundaries.start[Game.version] + byte);
6481-
temp_flag_value = bit.clear(temp_flag_value,tempBit);
6481+
temp_flag_value = bit.clear(temp_flag_value, tempBit);
64826482
mainmemory.writebyte(temp_flag_boundaries.start[Game.version] + byte, temp_flag_value);
64836483
end
64846484

6485-
function checkTempFlag(byte,tempBit)
6485+
function checkTempFlag(byte, tempBit)
64866486
local temp_flag_value = mainmemory.readbyte(temp_flag_boundaries.start[Game.version] + byte);
6487-
local return_value = bit.check(temp_flag_value,tempBit);
6487+
local return_value = bit.check(temp_flag_value, tempBit);
64886488
if return_value then
64896489
print(Game.getTempFlagName(byte, tempBit).." is SET");
64906490
else
@@ -8013,13 +8013,15 @@ end
80138013
function Game.getCurrentAnimationIndexAndSize()
80148014
local current_animation_start_pointer = Game.getCurrentAnimationStartPointer();
80158015
local animation_block_pointer = Game.getAnimationBlockPointer();
8016-
local diff = ((current_animation_start_pointer - animation_block_pointer) - 0x80000000);
8017-
for i=0, animation_count do
8018-
if diff == mainmemory.read_u32_be(animation_block_pointer + i*0x4) then
8019-
local size = mainmemory.read_u32_be(animation_block_pointer + (i+1)*0x4) - diff; --next entry for size calc
8020-
--for some reason, there are empty animations, so continue until size != 0
8021-
if size ~= 0 then
8022-
return {i, size};
8016+
if (isPointer(animation_block_pointer)) then
8017+
local diff = ((current_animation_start_pointer - animation_block_pointer) - RDRAMBase);
8018+
for i=0, animation_count do
8019+
if diff == mainmemory.read_u32_be(animation_block_pointer + i*0x4) then
8020+
local size = mainmemory.read_u32_be(animation_block_pointer + (i+1)*0x4) - diff; --next entry for size calc
8021+
--for some reason, there are empty animations, so continue until size != 0
8022+
if size ~= 0 then
8023+
return {i, size};
8024+
end
80238025
end
80248026
end
80258027
end

games/sonic_all_stars_racing.lua

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local Game = {
2121
squish_memory_table = true,
2222
Memory = { -- Version order: US, Europe
2323
player_pointer = {0x236238, 0},
24+
boost_flame_size = {0x798, 0},
2425
x_velocity = {0xA7C, 0}, -- s16.16le, relative to player
2526
z_velocity = {0xA84, 0}, -- s16.16le, relative to player
2627
x_position = {0x6C, 0}, -- s16.16le, relative to player
@@ -108,6 +109,14 @@ function Game.setZVelocity(value)
108109
end
109110
end
110111

112+
function Game.getBoostFlameSize()
113+
local player = Game.getPlayer();
114+
if isRAM(player) then
115+
return mainmemory.read_s1616_le(player + Game.Memory.boost_flame_size);
116+
end
117+
return 0;
118+
end
119+
111120
function Game.getVelocity()
112121
return math.abs(Game.getXVelocity()) + math.abs(Game.getZVelocity());
113122
end
@@ -119,10 +128,11 @@ Game.OSD = {
119128
{"Y", category="position"},
120129
{"Z", category="position"},
121130
{"Separator"},
122-
{"X Velocity", Game.getXVelocity, category="position"},
123-
{"Z Velocity", Game.getZVelocity, category="position"},
131+
{"X Velocity", Game.getXVelocity},
132+
{"Z Velocity", Game.getZVelocity},
124133
{"Separator"},
125-
{"Velocity", Game.getVelocity, category="position"},
134+
{"Velocity", Game.getVelocity},
135+
{"Boost Flame", Game.getBoostFlameSize},
126136
{"Separator"},
127137
{"dY", category="positionStats"},
128138
{"dXZ", category="positionStats"},

0 commit comments

Comments
 (0)