Ensiss / pokebot

A bot (trying) to play Pokemon Fire Red
MIT License
13 stars 2 forks source link

DMA #4

Closed Nauktis closed 7 years ago

Nauktis commented 8 years ago

Hi,

I stumbled upon your project as I was playing myself with some LUA scripts for Pokemon Red. I looked at how you get the position of the player on the map and I was wondering I that could be done in LUA directly.

I know this is DMA protected RAM and that the location is stored at 0x3005008. The problem is that this pointer is huge (e.g. 806E835) so this goes far beyond the WRAM.

This is my sample code:

while true do
    local ptr = memory.readdwordunsigned(INTERNAL_OFFSET + 0x5008)
    print("Position X = " .. memory.readwordunsigned(ptr))

    for i = 0, 200 do
        vba.frameadvance()
    end
end

Could you help me?

jonese1234 commented 8 years ago

Dont know if this helps but:

player = {
        name = 0x1158,
        name2 = 0x1159,
        moving = 0x1528,
        x = 0x1362,
        y = 0x1361,
        facing = 0x152A,
        repel = 0x10DB,
        party_size = 0x1163,
        inventory_count = 0x131D,
        bicycle = 0x1700,
        pikachu_x = 0x02F5,
    },

These are some memory values for pokemon red

function Player.position()
    return Memory.value("player", "x"), Memory.value("player", "y")
end

I guess you could do something like this.

Ensiss commented 8 years ago

What you are doing seems to work for me.

> =pb.getPlayer():getX()
9
> =mem.get8(mem.get32(0x3005008)) 
9

You should check how your memory.read functions work and if INTERNAL_OFFSET is correctly set.

Nauktis commented 8 years ago

Which emulator are you using? I'm having problems compiling mirror/vbam

Ensiss commented 8 years ago

This projects is also an emulator itself, thanks to the libvbam, so the emulator I'm using is ./pokebot.

Did you follow these directions ? What errors are you getting ? Also this project is developped on Linux and no effort has been made to make it work on Windows so that may be your problem.

jonese1234 commented 8 years ago

I tried running it and i get this error Error

Ensiss commented 8 years ago

Alright I finally found the issue. The rom version I used since the beginning was Firered (U) (V1.0) and using version 1.1 changes some offsets and crashes pokebot. You can find the right file pretty easily if you search for Firered 1.0, and to check if you got the right one, its md5sum is e26ee0d44e809351c8ce2d73c7400cdd.

I'll update the description to specify that. Thanks for finding that problem.

jonese1234 commented 8 years ago

Ok got it working, however it currently only gets upto this point.

Pic

I was wondering how far and what it currently is meant to do?

Ensiss commented 8 years ago

Yep the intro is not automatically skipped right now. It's a part that's probably going to be hardcoded because it only happens once and is pretty easy. The current demo assumes that you have a pokemon and that you are in Pallet Town, and does nothing if that's not the case.

If you want to test what the bot is capable of right now, there's a simple script there that talks to a bunch of people and moves around in the starting village, then goes to run in the bushes to farm exp. To test it start a new game, get your first pokemon and then save the game when you're in Pallet Town. When restarting the pokebot, it should move around on its own. Note that you can use the pokebot like a normal emulator to play if it's not doing anything (not sure what the keys for a and b are, try things like w, x, q or a).

The goal of the project is to have a bot that plays the game really on its own, in the sense that he's going to have to compute where to go and what to do based on the game data and memory instead of having to manually set up a route to follow. Currently the focus is mainly on developping a lua framework complex enough to allow the creation of such a bot.

This a rough current state of the project:

I realize that the project is lacking some documentation and user-friendliness, I should probably make a better demo and add explanations to the readme or something...

jonese1234 commented 8 years ago

Okay, very cool.

I sadly dont know any C++ so cannot really help you on that side, but i have and am working on This Project Which is kind of similar to your project but for pokemon red, and well its also a lot less run on your own, more hardcoded.

I will help if i can, but its a very interesting thing you have, so keep up the work!

Ensiss commented 8 years ago

Thanks ! I saw that project a little while ago already, it's really awesome! The ideas are similar indeed, but the goals and approaches are so different that the projects end up being really unique, it's great. Good luck on your project!