Standardize memory addresses across versions

This commit is contained in:
Kyle Coburn 2015-04-05 18:29:45 -07:00
parent 40d8f25a6d
commit 4e58eb7a94
9 changed files with 75 additions and 70 deletions

View File

@ -206,7 +206,7 @@ function movePP(name)
if not midx then if not midx then
return 0 return 0
end end
return memory.raw(0xD02C + midx) return memory.raw(0x102C + midx)
end end
battle.pp = movePP battle.pp = movePP

View File

@ -129,16 +129,16 @@ local function getMoves(who)--Get the moveset of us [0] or them [1]
local moves = {} local moves = {}
local base local base
if who == 1 then if who == 1 then
base = 0xCFED base = 0x0FED
else else
base = 0xD01C base = 0x101C
end end
for idx=0, 3 do for idx=0, 3 do
local val = memory.raw(base + idx) local val = memory.raw(base + idx)
if val > 0 then if val > 0 then
local moveTable = movelist.get(val) local moveTable = movelist.get(val)
if who == 0 then if who == 0 then
moveTable.pp = memory.raw(0xD02D + idx) moveTable.pp = memory.raw(0x102D + idx)
end end
moves[idx + 1] = moveTable moves[idx + 1] = moveTable
end end
@ -287,7 +287,7 @@ end
combat.activePokemon = activePokemon combat.activePokemon = activePokemon
local function isSleeping() local function isSleeping()
return memory.raw(0xD16F) > 1 return memory.raw(0x116F) > 1
end end
combat.isSleeping = isSleeping combat.isSleeping = isSleeping

View File

@ -210,8 +210,8 @@ while true do
end end
if STREAMING_MODE then if STREAMING_MODE then
local newSecs = memory.raw(0xDA44) local newSecs = memory.raw(0x1A44)
if newSecs ~= oldSecs and (newSecs > 0 or memory.raw(0xDA45) > 0) then if newSecs ~= oldSecs and (newSecs > 0 or memory.raw(0x1A45) > 0) then
bridge.time(utils.elapsedTime()) bridge.time(utils.elapsedTime())
oldSecs = newSecs oldSecs = newSecs
end end

View File

@ -52,7 +52,7 @@ local items = {
rock_slide = 248, rock_slide = 248,
} }
local ITEM_BASE = 0xD31E local ITEM_BASE = 0x131E
-- Data -- Data
@ -125,7 +125,7 @@ function inventory.teach(item, poke, replaceIdx, altPoke)
end end
function inventory.isFull() function inventory.isFull()
return memory.raw(0xD345) > 0 return memory.raw(0x1345) > 0
end end
function inventory.use(item, poke, midfight) function inventory.use(item, poke, midfight)

View File

@ -85,7 +85,7 @@ local data = {
} }
local function getAddress(index) local function getAddress(index)
return 0xD16B + index * 0x2C return 0x116B + index * 0x2C
end end
local function index(index, offset) local function index(index, offset)
@ -125,7 +125,7 @@ pokemon.indexOf = indexOf
function pokemon.battleMove(name) function pokemon.battleMove(name)
local mid = moveList[name] local mid = moveList[name]
for i=1,4 do for i=1,4 do
if mid == memory.raw(0xD01B + i) then if mid == memory.raw(0x101B + i) then
return i return i
end end
end end
@ -233,7 +233,7 @@ function pokemon.isEvolving()
end end
function pokemon.getExp() function pokemon.getExp()
return memory.raw(0xD17A) * 256 + memory.raw(0xD17B) return memory.raw(0x117A) * 256 + memory.raw(0x117B)
end end
function pokemon.inRedBar() function pokemon.inRedBar()

View File

@ -30,19 +30,19 @@ local memoryNames = {
main = 0x1FF5, main = 0x1FF5,
}, },
player = { player = {
name = 0xD158, name = 0x1158,
name2 = 0xD159, name2 = 0x1159,
moving = 0x1528, moving = 0x1528,
x = 0xD362, x = 0x1362,
y = 0xD361, y = 0x1361,
facing = 0x152A, facing = 0x152A,
repel = 0x10DB, repel = 0x10DB,
party_size = 0xD163, party_size = 0x1163,
}, },
game = { game = {
map = 0xD35E, map = 0x135E,
frames = 0xDA45, frames = 0x1A45,
battle = 0xD057, battle = 0x1057,
textbox = 0x0FC4, textbox = 0x0FC4,
}, },
shop = { shop = {
@ -52,9 +52,9 @@ local memoryNames = {
trashcans = 0x1773, trashcans = 0x1773,
}, },
pokemon = { pokemon = {
exp1 = 0xD179, exp1 = 0x1179,
exp2 = 0xD17A, exp2 = 0x117A,
exp3 = 0xD17B, exp3 = 0x117B,
}, },
battle = { battle = {
turns = 0x1067, turns = 0x1067,
@ -69,44 +69,49 @@ local memoryNames = {
critical = 0x105E, critical = 0x105E,
opponent_bide = 0x106F, opponent_bide = 0x106F,
opponent_id = 0xCFE5, opponent_id = 0x0FE5,
opponent_level = 0xCFF3, opponent_level = 0x0FF3,
opponent_type1 = 0xCFEA, opponent_type1 = 0x0FEA,
opponent_type2 = 0xCFEB, opponent_type2 = 0x0FEB,
our_id = 0xD014, our_id = 0x1014,
our_status = 0xD018, our_status = 0x1018,
our_level = 0xD022, our_level = 0x1022,
our_type1 = 0xD019, our_type1 = 0x1019,
our_type2 = 0xD01A, our_type2 = 0x101A,
}, },
} }
local doubleNames = { local doubleNames = {
pokemon = { pokemon = {
attack = 0xD17E, attack = 0x117E,
defense = 0xD181, defense = 0x1181,
speed = 0xD183, speed = 0x1183,
special = 0xD185, special = 0x1185,
}, },
battle = { battle = {
opponent_hp = 0xCFE6, opponent_hp = 0x0FE6,
opponent_max_hp = 0xCFF4, opponent_max_hp = 0x0FF4,
opponent_attack = 0xCFF6, opponent_attack = 0x0FF6,
opponent_defense = 0xCFF8, opponent_defense = 0x0FF8,
opponent_speed = 0xCFFA, opponent_speed = 0x0FFA,
opponent_special = 0xCFFC, opponent_special = 0x0FFC,
our_hp = 0xD015, our_hp = 0x1015,
our_max_hp = 0xD023, our_max_hp = 0x1023,
our_attack = 0xD025, our_attack = 0x1025,
our_defense = 0xD027, our_defense = 0x1027,
our_speed = 0xD029, our_speed = 0x1029,
our_special = 0xD02B, our_special = 0x102B,
}, },
} }
local function raw(address) local yellow = YELLOW
local function raw(address, forYellow)
if yellow and not forYellow and address > 0x0F12 and address < 0x1F00 then
address = address - 1
end
return memory.readbyte(address) return memory.readbyte(address)
end end
Memory.raw = raw Memory.raw = raw
@ -130,12 +135,12 @@ function Memory.double(section, key)
return raw(first) + raw(first + 1) return raw(first) + raw(first + 1)
end end
function Memory.value(section, key) function Memory.value(section, key, forYellow)
local memoryAddress = memoryNames[section] local memoryAddress = memoryNames[section]
if key then if key then
memoryAddress = memoryAddress[key] memoryAddress = memoryAddress[key]
end end
return raw(memoryAddress) return raw(memoryAddress, forYellow)
end end
return Memory return Memory

View File

@ -3,7 +3,7 @@ local menu = {}
local input = require "util.input" local input = require "util.input"
local memory = require "util.memory" local memory = require "util.memory"
local YELLOW = GAME_NAME == "yellow" local yellow = GAME_NAME == "yellow"
local sliding = false local sliding = false
@ -139,13 +139,13 @@ end
-- Options -- Options
function menu.setOption(name, desired) function menu.setOption(name, desired)
if YELLOW then if yellow then
local rowFor = { local rowFor = {
text_speed = 0, text_speed = 0,
battle_animation = 1, battle_animation = 1,
battle_style = 2 battle_style = 2
} }
local currentRow = memory.raw(0x0D3D) local currentRow = memory.raw(0x0D3D, true)
if menu.balance(currentRow, rowFor[name], true, false, true) then if menu.balance(currentRow, rowFor[name], true, false, true) then
input.press("Left") input.press("Left")
end end

View File

@ -3,17 +3,17 @@ local settings = {}
local memory = require "util.memory" local memory = require "util.memory"
local menu = require "util.menu" local menu = require "util.menu"
local YELLOW = GAME_NAME == "yellow" local yellow = YELLOW
local settings_menu local settings_menu
if YELLOW then if yellow then
settings_menu = 93 settings_menu = 93
else else
settings_menu = 94 settings_menu = 94
end end
local desired = {} local desired = {}
if YELLOW then if yellow then
desired.text_speed = 1 desired.text_speed = 1
desired.battle_animation = 128 desired.battle_animation = 128
desired.battle_style = 64 desired.battle_style = 64
@ -24,13 +24,13 @@ else
end end
local function isEnabled(name) local function isEnabled(name)
if YELLOW then if yellow then
local matching = { local matching = {
text_speed = 0xF, text_speed = 0xF,
battle_animation = 128, battle_animation = 128,
battle_style = 64 battle_style = 64
} }
local settingMask = memory.value("setting", "yellow_bitmask") local settingMask = memory.value("setting", "yellow_bitmask", true)
return bit.band(settingMask, matching[name]) == desired[name] return bit.band(settingMask, matching[name]) == desired[name]
else else
return memory.value("setting", name) == desired[name] return memory.value("setting", name) == desired[name]

View File

@ -67,9 +67,9 @@ end
-- TIME -- TIME
function utils.igt() function utils.igt()
local secs = memory.raw(0xDA44) local secs = memory.raw(0x1A44)
local mins = memory.raw(0xDA43) local mins = memory.raw(0x1A43)
local hours = memory.raw(0xDA41) local hours = memory.raw(0x1A41)
return secs + mins * 60 + hours * 3600 return secs + mins * 60 + hours * 3600
end end
@ -85,30 +85,30 @@ function utils.timeSince(prevTime)
local diff = currTime - prevTime local diff = currTime - prevTime
local timeString local timeString
if diff > 0 then if diff > 0 then
local secs = diff % 60
local mins = math.floor(diff / 60) local mins = math.floor(diff / 60)
local secs = mins % 60
timeString = clockSegment(mins)..":"..clockSegment(secs) timeString = clockSegment(mins)..":"..clockSegment(secs)
end end
return currTime, timeString return currTime, timeString
end end
function utils.elapsedTime() function utils.elapsedTime()
local secs = memory.raw(0xDA44) local secs = memory.raw(0x1A44)
if secs < 10 then if secs < 10 then
secs = "0"..secs secs = "0"..secs
end end
local mins = memory.raw(0xDA43) local mins = memory.raw(0x1A43)
if mins < 10 then if mins < 10 then
mins = "0"..mins mins = "0"..mins
end end
return memory.raw(0xDA41)..":"..mins..":"..secs return memory.raw(0x1A41)..":"..mins..":"..secs
end end
function utils.frames() function utils.frames()
local totalFrames = memory.raw(0xDA41) * 60 local totalFrames = memory.raw(0x1A41) * 60
totalFrames = (totalFrames + memory.raw(0xDA43)) * 60 totalFrames = (totalFrames + memory.raw(0x1A43)) * 60
totalFrames = (totalFrames + memory.raw(0xDA44)) * 60 totalFrames = (totalFrames + memory.raw(0x1A44)) * 60
return totalFrames + memory.raw(0xDA45) return totalFrames + memory.raw(0x1A45)
end end
return utils return utils