Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Pokemon Red plugin #176

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MaciekBaron
Copy link
Contributor

I was hoping to do a WIP review as there's a lot of code, please let me know what you think - thanks!

TODO

  • Add player position/location functions (currently we only get current map)
  • Determine game_area size and logic (there is overworld mode, battles and menus)
  • Determine (if needed) fitness scoring

Copy link
Owner

@Baekalfen Baekalfen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked into all details, but what you've done so far looks really good!

Comment on lines +68 to +81
def get_int_at_address(self, address, size=2):
"""Returns an integer from a given address of a specified size."""
bytes = []
for i in range(size):
bytes.append(self.pyboy.get_memory_value(address + i))
return int.from_bytes(bytes, byteorder=BYTE_ORDER)

def set_int_at_address(self, address, value, size=2):
"""Sets an integer at a given address of a specified size."""
bytes = value.to_bytes(2, byteorder=BYTE_ORDER)
i = 0
for byte in bytes:
self.pyboy.set_memory_value(address + i, byte)
i += 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These probably belong elsewhere. Maybe on the PyBoy object itself. Are these for the user of the plugin?

Comment on lines +83 to +104
def set_text(self, text, address):
"""Sets text at address.

Will always add a string terminator (80) at the end.
"""
i = 0
for character in text:
try:
self.pyboy.set_memory_value(address + i, get_character_index(character))
i += 1
except:
pass
self.pyboy.set_memory_value(address + i, constants.STRING_TERMINATOR)

def set_rom_text(self, text, bank, address):
i = 0
for character in text:
try:
self.pyboy.override_memory_value(bank, address + i, get_character_index(character))
i += 1
except:
pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These helper functions look like they should be hidden?

@krs013 krs013 marked this pull request as draft September 30, 2020 02:17
@hexiro
Copy link

hexiro commented Sep 7, 2022

This looks very good, but it hasn't been updated in a while. Do you think it would be a good idea to merge the WIP state so more people can view it and update it? If not, that's okay, I'll just clone it into my local codebase.

@Baekalfen
Copy link
Owner

This looks very good, but it hasn't been updated in a while. Do you think it would be a good idea to merge the WIP state so more people can view it and update it? If not, that's okay, I'll just clone it into my local codebase.

AFAIK, it's not in a complete working state, so I think it would give the wrong impression to people if we merged it. But you are more than welcome to clone it and work on it. I'll gladly merge it, if we can get it to a workable state.

@hexiro
Copy link

hexiro commented Sep 7, 2022

This looks very good, but it hasn't been updated in a while. Do you think it would be a good idea to merge the WIP state so more people can view it and update it? If not, that's okay, I'll just clone it into my local codebase.

AFAIK, it's not in a complete working state, so I think it would give the wrong impression to people if we merged it. But you are more than welcome to clone it and work on it. I'll gladly merge it, if we can get it to a workable state.

I can attempt to expand it
based on existing information. How much more needs to be done for it to be worthy of a merge?

@Baekalfen
Copy link
Owner

How much more needs to be done for it to be worthy of a merge?

Practically anything that shows a useable example. For example a proof-of-concept of doing a battle and/or navigating the world.

@MaciekBaron
Copy link
Contributor Author

Hey guys, sorry for abandoning this. There's a proof of concept showing this working in my interactive Twitch app: https://github.com/MaciekBaron/poke-rb-interactive

Can help with progressing this further.

@hexiro
Copy link

hexiro commented Sep 8, 2022

Hey guys, sorry for abandoning this. There's a proof of concept showing this working in my interactive Twitch app: https://github.com/MaciekBaron/poke-rb-interactive

Can help with progressing this further.

This is very cool!

As for suggestion I have, I think it would be cool to have more commands to handle interactive aspects of the game.
some examples of possibilities:

battle:
active_moves() -> tuple of 1-4 moves of current mon
attack_with_move(MOVE) -> finds what move slot that move is in or errors?
attack_with_move_slot(1)
run()
bag_items()
use_item(ITEM)
is_attacking() -> enemies' mon's healthbar is being drained after attacking
is_being_attacked() -> users' mon's healthbar is being drained after being attacked

overworld:
is_facing_obstacle()
is_in_dialogue / is_in_cutscene()

These are some things that I think would make the overall experience of using the wrapper easier for the user, although all of these might not be worth the effort. If you would like, i could attempt to implement the ones that don't require reading or setting memory namely, run, use_item, attack_with_move.

let me know what you think about these suggestions!

@MaciekBaron
Copy link
Contributor Author

I think those sound good!

We can also nick the constants I prepared for the other project: https://github.com/MaciekBaron/poke-rb-interactive/blob/master/pkmn/constants.py

@hexiro
Copy link

hexiro commented Sep 8, 2022

I think those sound good!

We can also nick the constants I prepared for the other project: https://github.com/MaciekBaron/poke-rb-interactive/blob/master/pkmn/constants.py

Quite and extensive list you've got there. Very nice! Although might I suggest making, Moves, Status, etc enums.

@hexiro
Copy link

hexiro commented Sep 9, 2022

after a lot of testing i've found that the memory address FFB0 - Value copied to WY at VBlank (description from https://datacrystal.romhacking.net/wiki/Pokémon_Red/Blue:RAM_map#Graphics_scroll_values)

is set to 144 when playing normally,
or it's set to 0 if things in the overworld are not moving (my best guess at what's happening).

I'm not sure the technical reason, but It appears as though one could check if the user is in some kind of dialogue with an NPC or object (like a sign) around the world if they're not in battle (can be checked more precisely) and they're not in the start menu, (again, has exact memory locations for checking this specifically)

Hopefully this information can be useful, and let me know if you know a more consistent method of checking this.

@SnarkAttack
Copy link

Is there any interesting in continued work on this particular pull request? Intending to do some RL on Pokemon Red and some of the features added in here would be interesting to have access to, but it's been a hot second since anyone touched this branch and I'm unsure whether I should be respecting this branch or just roll my own code in a different fork.

@Baekalfen
Copy link
Owner

Is there any interesting in continued work on this particular pull request? Intending to do some RL on Pokemon Red and some of the features added in here would be interesting to have access to, but it's been a hot second since anyone touched this branch and I'm unsure whether I should be respecting this branch or just roll my own code in a different fork.

If you want to restart the efforts in a new fork/PR, then that's very welcome. I don't think the original author will come back and finish this.

Once you submit a PR, we can consider if it replaces all the features in this PR. But we'll keep it here as reference until then

@MaciekBaron
Copy link
Contributor Author

Sorry everyone, got really busy and didn't get to finish this. Happy for people to use the data/code from this.

@SnarkAttack
Copy link

Thanks for the work you did @MaciekBaron, I am using this PR to get a head start.

@Pokeglitch
Copy link

Is there any interesting in continued work on this particular pull request? Intending to do some RL on Pokemon Red and some of the features added in here would be interesting to have access to, but it's been a hot second since anyone touched this branch and I'm unsure whether I should be respecting this branch or just roll my own code in a different fork.

I have started a pokered plugin as well: https://github.com/Pokeglitch/PyBoyPokered

I have it separate from the "built in" game_wrapper_pokemongen1 for now, since I am using the "dynamic plugins" branch for ease of development, but incorporating it in the future should only require a few tweaks.

But I'll be happy to make this part of a group effort

@Baekalfen
Copy link
Owner

Baekalfen commented Nov 7, 2023

I have it separate from the "built in" game_wrapper_pokemongen1 for now, since I am using the "dynamic plugins" branch for ease of development, but incorporating it in the future should only require a few tweaks.

I'm glad that somebody found it. If you join on Discord and provide examples and feedback on how you use it, I might be able to merge it in soon.

EDIT:
"it" being the dynamic plugins

@SnarkAttack
Copy link

@Pokeglitch I'm fine if you want your branch to be the main dev branch and we cherry pick things out of mine here that we want to keep. Having the dynamic plugins working as well as the breakpoints seem like really nice core features, most of what I've done at this point is just Python classes for encapsulating data access calls and is probably easier to drag and drop to another repo.

@Baekalfen
Copy link
Owner

Linking this to: #233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants