Skip to content

Instantly share code, notes, and snippets.

@samfromcadott
Last active June 17, 2023 21:35
Show Gist options
  • Save samfromcadott/c7162cf32217e3bdbda757b7427d7bec to your computer and use it in GitHub Desktop.
Save samfromcadott/c7162cf32217e3bdbda757b7427d7bec to your computer and use it in GitHub Desktop.
-- Script for first person in Silent Hill in BizHawk
--
-- Submit improvments at https://gist.github.com/samfromcadott
--
-- Copyright 2021 Sam Jackson
-----------------------------
-- Memory addresses
-----------------------------
harryAddress = {
x = 0x0BA024,
y = 0x0BA028,
z = 0x0BA02C,
yaw = 0x0BA032
}
camAddress = {
pitch = 0x0B9D88,
yaw = 0x0B9D8A,
roll = 0x0B9D8C,
x = 0x0B9D20,
y = 0x0B9D24,
z = 0x0B9D28
}
-- Address 0x0B9D00 controls focal length
-- Functions
-----------------------------
function radian(angle)
-- Converts from Silent Hill's angles (4096 per rotation) to radians
return angle * math.pi/2048
end
function getHarry()
return {
x = memory.read_s32_le(harryAddress.x),
y = memory.read_s32_le(harryAddress.y),
z = memory.read_s32_le(harryAddress.z),
yaw = memory.read_u16_le(harryAddress.yaw)
}
end
-- Start up
-----------------------------
freeCam = false
headHeight = 6000
cameraOffset = 2900
-- Main loop
-----------------------------
while true do
harry = getHarry()
-- The camera should be moved forward into Harry's head
facing = {
x = math.sin(radian(harry.yaw)),
y = 0.0,
z = math.cos(radian(harry.yaw))
}
-- Transform the camera
-- Location
memory.write_s32_le(camAddress.x, harry.x+facing.x*cameraOffset)
memory.write_s32_le(camAddress.y, harry.y-headHeight)
memory.write_s32_le(camAddress.z, harry.z+facing.z*cameraOffset)
-- Rotation
memory.write_u16_le(camAddress.pitch, 0)
memory.write_u16_le(camAddress.yaw, harry.yaw)
memory.write_u16_le(camAddress.roll, 0)
emu.frameadvance()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment