mirror of
https://github.com/notwa/mm
synced 2024-11-05 03:29:02 -08:00
add asm injection scripts
This commit is contained in:
parent
c142d4df33
commit
e29199c9e0
4 changed files with 1793 additions and 0 deletions
1
Lua/.gitignore
vendored
Normal file
1
Lua/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.State
|
80
Lua/inject.lua
Normal file
80
Lua/inject.lua
Normal file
|
@ -0,0 +1,80 @@
|
|||
require = require "depend"
|
||||
require "boilerplate"
|
||||
require "addrs.init"
|
||||
local assemble = require "inject.lips"
|
||||
|
||||
if version ~= "M US10" then
|
||||
print("Sorry, inject.lua is unimplemented for your version.")
|
||||
return
|
||||
end
|
||||
|
||||
local asm_path
|
||||
if bizstring then
|
||||
asm_path = "inject/crap.asm"
|
||||
else
|
||||
asm_path = "./mm/Lua/inject/crap.asm"
|
||||
end
|
||||
|
||||
local inject_addr, inject_maxlen, ow_addr, ow_before
|
||||
inject_addr = 0x780000
|
||||
inject_maxlen = 0x5A800
|
||||
ow_addr = 0x1749D0
|
||||
ow_before = 0x0C05CEC6
|
||||
--ow_addr = 0x174750
|
||||
--ow_before = 0x0C05D06A
|
||||
|
||||
local ss_fn = 'inject temp.State'
|
||||
|
||||
-- do it
|
||||
|
||||
local ow_after = 0x0C000000 + math.floor(inject_addr/4)
|
||||
if R4(ow_addr) ~= ow_before and R4(ow_addr) ~= ow_after then
|
||||
print("Can't inject -- game code is different!")
|
||||
return
|
||||
end
|
||||
|
||||
local ow_before_addr = (ow_before % 0x4000000)*4
|
||||
|
||||
local header = ("[overwritten]: 0x%08X\n"):format(ow_before_addr)
|
||||
header = header..[[
|
||||
sw ra, -4(sp)
|
||||
bal start
|
||||
subi sp, sp, 4
|
||||
jal @overwritten
|
||||
nop
|
||||
lw ra, 0(sp)
|
||||
jr
|
||||
addi sp, sp, 4
|
||||
start:
|
||||
]]
|
||||
|
||||
local inject = {}
|
||||
local add_inject = function(line)
|
||||
--print(line)
|
||||
table.insert(inject, tonumber(line, 16))
|
||||
end
|
||||
local true_offset = 0x80000000 + inject_addr
|
||||
assemble(header, add_inject, {unsafe=true, offset=true_offset})
|
||||
-- warning: assumes each line is 4 bytes long
|
||||
assemble(asm_path, add_inject, {unsafe=true, offset=true_offset + #inject*4})
|
||||
|
||||
if #inject > inject_maxlen then
|
||||
print("Assembly too large!")
|
||||
return
|
||||
end
|
||||
|
||||
for i, v in ipairs(inject) do
|
||||
W4(inject_addr + (i - 1)*4, v)
|
||||
end
|
||||
|
||||
-- finally, inject over jal
|
||||
printf('%08X: %08X', ow_addr, ow_after)
|
||||
W4(ow_addr, ow_after)
|
||||
|
||||
-- force code cache to be reloaded
|
||||
if bizstring then
|
||||
savestate.save(ss_fn)
|
||||
savestate.load(ss_fn)
|
||||
else
|
||||
m64p.reloadCode()
|
||||
end
|
156
Lua/inject/crap.asm
Normal file
156
Lua/inject/crap.asm
Normal file
|
@ -0,0 +1,156 @@
|
|||
// bomb tornado
|
||||
// originally written by RainingChain in Lua
|
||||
// rewritten in assembly by notwa
|
||||
|
||||
[global_context]: 0x803E6B20
|
||||
[link_actor]: 0x803FFDB0
|
||||
|
||||
[actorlist_offset]: 0x1CB0
|
||||
[actorlist_dead_space]: 0x4
|
||||
|
||||
[actor_x]: 0x24
|
||||
[actor_y]: 0x28
|
||||
[actor_z]: 0x2C
|
||||
[actor_prev]: 0x128
|
||||
[actor_next]: 0x12C
|
||||
[actor_bomb_timer]: 0x1F1
|
||||
|
||||
[at_bomb]: 0x0009
|
||||
|
||||
[rotate_amount]: 0x3E567750 // pi/15
|
||||
|
||||
// F12 = input (single), F0 = output (single), F4 = output (double)
|
||||
[sinf]: 0x80088350
|
||||
[cosf]: 0x80091F40
|
||||
|
||||
main:
|
||||
subi sp, sp, 20
|
||||
sw ra, 0(sp)
|
||||
sw a0, 4(sp)
|
||||
sw s1, 8(sp) // current actor ptr
|
||||
sw s3, 12(sp) // current actor type ptr
|
||||
sw s4, 16(sp) // current actor type index
|
||||
|
||||
li t0, @global_context
|
||||
addi s3, t0, @actorlist_offset
|
||||
li s4, 0
|
||||
|
||||
// update rotations
|
||||
la t0, rotations
|
||||
li t2, @rotate_amount
|
||||
li t9, 0
|
||||
rotate_loop:
|
||||
lw t1, 0(t0)
|
||||
mtc1 t1, F0
|
||||
mtc1 t2, F1
|
||||
add.s F0, F0, F1
|
||||
mfc1 t1, F0
|
||||
sw t1, 0(t0)
|
||||
addi t0, t0, 4
|
||||
addi t9, t9, 1
|
||||
li at, 6
|
||||
bne t9, at, rotate_loop
|
||||
nop
|
||||
la t0, rotations
|
||||
sw t0, current_rotation
|
||||
|
||||
typeloop:
|
||||
addi s3, s3, 4 // skip over count
|
||||
lw s1, 0(s3)
|
||||
|
||||
beq s1, r0, continue
|
||||
listloop:
|
||||
mov a0, s1
|
||||
bal process_actor
|
||||
lw s1, @actor_next(s1)
|
||||
bne s1, r0, listloop
|
||||
nop
|
||||
|
||||
continue:
|
||||
addi s3, s3, 4
|
||||
addi s4, s4, 1
|
||||
li t0, 12
|
||||
bne s4, t0, typeloop
|
||||
addi s3, s3, @actorlist_dead_space
|
||||
|
||||
lw ra, 0(sp)
|
||||
lw a0, 4(sp)
|
||||
lw s1, 8(sp)
|
||||
lw s3, 12(sp)
|
||||
lw s4, 16(sp)
|
||||
jr
|
||||
addi sp, sp, 20
|
||||
|
||||
process_actor: // args: a0. returns nothing.
|
||||
// TODO: ignore bomb explosions, they share the same type
|
||||
subi sp, sp, 16
|
||||
// 0(sp) reserved for sinf/cosf
|
||||
sw ra, 4(sp)
|
||||
sw s0, 8(sp) // result of sin
|
||||
sw s1, 12(sp) // result of cos
|
||||
lh t0, 0(a0)
|
||||
subiu t0, t0, @at_bomb
|
||||
bne t0, r0, process_actor_return
|
||||
nop
|
||||
li t0, 0x45
|
||||
sb t0, @actor_bomb_timer(a0)
|
||||
|
||||
lw t5, current_rotation
|
||||
lw t5, 0(t5)
|
||||
jal @sinf
|
||||
mtc1 t5, F12
|
||||
mfc1 s0, F0
|
||||
|
||||
lw t5, current_rotation
|
||||
lw t5, 0(t5)
|
||||
jal @cosf
|
||||
mtc1 t5, F12
|
||||
mfc1 s1, F0
|
||||
|
||||
li t1, @link_actor
|
||||
lw t2, @actor_x(t1)
|
||||
lw t3, @actor_y(t1)
|
||||
lw t4, @actor_z(t1)
|
||||
|
||||
li t0, 0x42960000 // 75
|
||||
mtc1 t0, F2
|
||||
|
||||
// process X
|
||||
mtc1 s0, F0
|
||||
mtc1 t2, F1
|
||||
mul.s F0, F0, F2
|
||||
add.s F0, F0, F1
|
||||
mfc1 t2, F0
|
||||
|
||||
// process Z
|
||||
mtc1 s1, F0
|
||||
mtc1 t4, F1
|
||||
mul.s F0, F0, F2
|
||||
add.s F0, F0, F1
|
||||
mfc1 t4, F0
|
||||
|
||||
sw t2, @actor_x(a0)
|
||||
sw t3, @actor_y(a0)
|
||||
sw t4, @actor_z(a0)
|
||||
|
||||
lw t5, current_rotation
|
||||
addi t5, t5, 4
|
||||
sw t5, current_rotation
|
||||
|
||||
process_actor_return:
|
||||
lw ra, 4(sp)
|
||||
lw s0, 8(sp)
|
||||
lw s1, 12(sp)
|
||||
jr
|
||||
addi sp, sp, 16
|
||||
|
||||
rotations:
|
||||
.word 0x00000000 // pi*0/6
|
||||
.word 0x40060a92 // pi*4/6
|
||||
.word 0x40860a92 // pi*8/6
|
||||
.word 0x40c90fdb // pi*12/6
|
||||
.word 0x41060a92 // pi*16/6
|
||||
.word 0x41278d36 // pi*20/6
|
||||
|
||||
current_rotation:
|
||||
.word 0
|
1556
Lua/inject/lips.lua
Normal file
1556
Lua/inject/lips.lua
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue