Skip to content

Commit

Permalink
v0.4.1-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
wyanido authored Sep 6, 2023
2 parents a5536d0 + 832cb60 commit 3eb61f5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ dashboard/locales
build
logs/*
node_modules
out
out

.vscode
src-tauri
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _Currently only English (USA, Europe) copies are supported._
| Pickup farming |||||
| Gift resets |||||
| Egg hatching |||||
| Static encounters || |||
| Static encounters || |||
| Thief farming |||||
| Fishing |||||
| Dust cloud farming | | |||
Expand Down
2 changes: 1 addition & 1 deletion dashboard/resources/app/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<img src="images/pokemon-icon/201-27.png" class="icon" id="icon">
Pokébot NDS
</div>
<span class="navbar-text text-monospace font-size-12">v0.4.0-alpha</span>
<span class="navbar-text text-monospace font-size-12">v0.4.1-alpha</span>
<ul class="navbar-nav d-flex d-md-flex">
<li class="nav-item nav-link px-10">
<a href="dashboard.html">
Expand Down
2 changes: 1 addition & 1 deletion dashboard/resources/app/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<img src="images/pokemon-icon/201-27.png" class="icon" id="icon">
Pokébot NDS
</div>
<span class="navbar-text text-monospace font-size-12">v0.4.0-alpha</span>
<span class="navbar-text text-monospace font-size-12">v0.4.1-alpha</span>
<ul class="navbar-nav d-flex d-md-flex">
<li class="nav-item nav-link px-10">
<button type="button" class="btn position-relative px-10 active">
Expand Down
65 changes: 58 additions & 7 deletions lua/methods_hgss.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@
-- DP FUNCTION OVERRIDES
-----------------------
function update_pointers()
offset.party_count = mdword(0x021D10EC) + 14
offset.party_data = offset.party_count + 4

offset.foe_count = mdword(0x21D4158) + 0x7574
offset.current_foe = offset.foe_count + 4
offset.mem_shift = mdword(0x21D4158) -- Value differs per reset

offset.map_header = mdword(0x21D2228) + 0x1244
if offset.mem_shift == 0 then
offset.mem_shift = 0xFFFFF -- Bad code, this is an improvised solution to multiple errors
end

offset.party_count = offset.mem_shift - 0x23F52 + 0xE
offset.party_data = offset.party_count + 4

offset.map_header = offset.mem_shift - 0x22DA4
offset.trainer_x = offset.map_header + 4 + 2
offset.trainer_y = offset.map_header + 12 + 2
offset.trainer_z = offset.map_header + 8 + 2

if mword(offset.map_header) == 340 then -- Bell Tower
-- Wild Ho-oh's data is located at a different address to standard encounters
-- May apply to other statics too -- research?
offset.foe_count = offset.mem_shift + 0x977C
else
offset.foe_count = offset.mem_shift + 0x7574
end
offset.current_foe = offset.foe_count + 4

-- console.log(string.format("%08X", offset.map_header))
end
Expand All @@ -24,7 +36,8 @@ function mode_starters()

-- Proceed until starters are loaded into RAM
while mdword(starter_pointer - 0x8) ~= 0 or mdword(starter_pointer - 0x4) == 0 do
press_sequence("A", 10)
local delay = math.random(6, 21) -- Mimic imperfect human inputs
press_sequence("A", delay)
end

if not config.hax then
Expand Down Expand Up @@ -52,6 +65,12 @@ function mode_starters()
-- Soft reset otherwise
press_button("Power")
wait_frames(30)

-- Wait a random number of frames before mashing A next reset
-- to decrease the odds of hitting similar seeds
local delay = math.random(1, 90)
console.debug("Delaying " .. delay .. " frames...")
wait_frames(delay)
end

function mode_voltorb_flip()
Expand Down Expand Up @@ -105,3 +124,35 @@ function mode_voltorb_flip()

press_sequence("A", 9)
end

function mode_static_encounters()
console.log("Waiting for battle to start...")

while not foe and not game_state.in_battle do
local delay = math.random(6, 21) -- Mimic imperfect human inputs
press_sequence("A", delay)
end

foe_is_target = pokemon.log(foe[1])

if not config.hax then
-- Wait for Pokémon to fully appear on screen
for i = 0, 22, 1 do
press_sequence("A", 6)
end
end

if foe_is_target then
pause_bot("Wild Pokémon meets target specs!")
else
console.log("Wild " .. foe[1].name .. " was not a target, resetting...")
press_button("Power")
wait_frames(30)
end

-- Wait a random number of frames before mashing A next reset
-- to decrease the odds of hitting similar seeds
local delay = math.random(1, 90)
console.debug("Delaying " .. delay .. " frames...")
wait_frames(delay)
end
32 changes: 22 additions & 10 deletions pokebot-nds.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-----------------------
-- INITIALIZATION
-----------------------
local BOT_VERSION = "0.4.0-alpha"
local BOT_VERSION = "0.4.1-alpha"

console.clear()
console.log("Running " .. _VERSION)
Expand Down Expand Up @@ -141,19 +141,31 @@ end

function get_game_state()
local map = mword(offset.map_header)
local in_game = (map ~= 0x0 and map <= MAP_HEADER_COUNT)

-- Update in-game values
if gen == 4 then -- gen 4 is always considered "in game" even before the title screen, so it always returns real data
return {
map_header = map,
map_name = map_names[map + 1],
trainer_x = mword(offset.trainer_x + 2),
trainer_y = to_signed(mword(offset.trainer_y + 2)),
trainer_z = mword(offset.trainer_z + 2),
in_battle = mbyte(offset.battle_indicator) == 0x41 and mbyte(offset.foe_count) > 0
}
if in_game then
return {
map_header = map,
map_name = map_names[map + 1],
trainer_x = mword(offset.trainer_x + 2),
trainer_y = to_signed(mword(offset.trainer_y + 2)),
trainer_z = mword(offset.trainer_z + 2),
in_battle = mbyte(offset.battle_indicator) == 0x41 and mbyte(offset.foe_count) > 0,
in_game = true
}
else
return {
map_header = 0,
map_name = "--",
trainer_x = 0,
trainer_y = 0,
trainer_z = 0,
in_game = false
}
end
else
local in_game = (map ~= 0x0 and map <= MAP_HEADER_COUNT)
if in_game then
return {
-- map_matrix = mdword(offset.map_matrix),
Expand Down

0 comments on commit 3eb61f5

Please sign in to comment.