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

Export PS replays to be openable on 3DS games #4804

Open
ReZeroEmiria opened this issue Aug 10, 2018 · 15 comments
Open

Export PS replays to be openable on 3DS games #4804

ReZeroEmiria opened this issue Aug 10, 2018 · 15 comments

Comments

@ReZeroEmiria
Copy link

Hello, I'd like to know if it would somehow be possible for a showdown replay saved as a file which can be then imported into the 3ds games as a battle replay?

Battle replays on the 3ds are only 11kb in size so I don't think it'd be too difficult to record and format all of the actions that happen in a showdown battle into the appropriate hexadecimal values so the 3ds games can read this?

@Zarel
Copy link
Member

Zarel commented Aug 11, 2018

This would be really nice, but unfortunately two things prevent this:

  1. As far as I know, no one has managed to successfully reverse-engineer exactly how a 3DS replay is stored.

  2. In-game replays store starting teams, starting RNG seed, and a list of decisions. We don't yet have full RNG accuracy – see Turn Order needs to be handled how it is in-game #1157 – so we wouldn't be able to reproduce the same games as in-game.

@Zarel
Copy link
Member

Zarel commented Aug 11, 2018

Normally I'd leave open feature requests that are unlikely to implement, on the off chance someone else wants to, but for this one, I think I'll close it. If Project Pokémon ever gets to the point where this is possible, someone will probably do it then.

@ReZeroEmiria
Copy link
Author

I'd like to do some digging into replay files, do you know of any documentation that has been compiled of such research?

I know of this tool: https://github.com/Lyviaff/7G-Replay-Editor
It doesn't edit anything aside from graphical aspects of a replay however. Could be useful to know what areas NOT to edit though.

I'm currently editing hex values of a replay file I have to get a feel for what variables do what, I'm sure this would help this project out. I'm fairly new to this however and would appreciate any advice on what other steps I can take to see if we can make this happen!

@Zarel
Copy link
Member

Zarel commented Aug 12, 2018

Oh, I think that means they've at least managed to decrypt replays. This could be really useful, actually.

@ReZeroEmiria
Copy link
Author

I'm also doing some testing to figure out what offsets are responsible for what , from what I can tell , the beginning bits are all the graphics that show up in the VS Recorder, things like Outcome of the battle , player passport pictures, sprites of team, maybe even type of battle, although my research so far is strictly for singles no restrictions since I feel this would be the most used format.

I'm going to be testing out Pokemon with very little variations to see if I can pinpoint the areas responsible for things like PID,Species,Gender,Nature,Ability,Item, IV's, EV's and such.

Should I post my findings on here or is another method preferred? First time I've done this sort of thing, haha!

@Zarel
Copy link
Member

Zarel commented Aug 16, 2018

This is the sort of research Project Pokémon is very interested in, so you might want to post it in their forums. Do link your thread from here, though, because I'm also interested in this.

@ReZeroEmiria
Copy link
Author

Sorry for not replying here for a while, I've made considerable progress with this. I'm currently in the process of "making" my own replay based on a showdown replay. I'm merely putting everything I've found in my research to recreate a battle's actions into a replay for the 3ds games. So far it is going well,
I think I have figured out how the battle actions and Pokemon data works. However I have come across the problem of the RNG. Things like Min/Max Damage, Critical Hits, and Additional Effects of moves. I believe I found the location of the initial seed though. After examining multiple replays I found that 4 bytes were always different unless I was looking at two replays of the same battle. I changed these 4 bytes and then an additional effect that triggered on turn one of my battle (Ancient Power's +1 in all stats) did not trigger.

Given the information of where the seed is and many replays to study the results of a seed, is there anything you think you can do to generate a seed that would give the exact same results as a showdown replay ?

I.e.

Turn 1
1st player: Miss Attack ( of X accuracy)
2nd player: No effect (Minimum Damage)
Turn 2
1st player: Critical Hit (Minimum Damage)
2nd Player: Scald inflict burn on 1st Player .

I'm not sure how Battle RNG works as most of the RNG research I've seen is related to encounters and hatching eggs. However, shouldn't the replay store the frames or other information of every turn? Looking into the replays hasn't yielded anything indicating storage of other information except a starting seed at the beginning of the battle, I'm wondering if this is the starting seed at the beginning of the battle in real time or if the game just generates a seed that replicates the battle as it happened?

By the way would running PokeCalc during a battle yield any useful information? I tried doing so on my two consoles while watching a replay thinking that maybe some seed would show up on both simultaneously, but the tool is made for shiny encounters so I don't know if battle RNG information would even be displayed here.

@Zarel
Copy link
Member

Zarel commented Aug 18, 2018

@Marty-D How much work would it be to update the sim to be RNG-compatible with US/UM?

@ReZeroEmiria This is really interesting how far you've gotten. The main problem is that unless we know exactly how the RNG works at every step, we can't match it.

I'm not saying it's impossible, but it would require detailed knowledge of how the in-game RNG works.

@Marty-D
Copy link
Collaborator

Marty-D commented Aug 18, 2018

I couldn't even give an educated guess since I don't know anything about the in-game RNG.

@Zarel
Copy link
Member

Zarel commented Aug 18, 2018

An in-game replay should store:

  • starting teams
  • starting seed
  • everyone's choices every turn

All other information is re-simulated live when the games play back a replay.

The starting seed is the same starting seed as the battle itself.

I don't know anything about PokéCalc so I don't know how it would be used.

@ReZeroEmiria
Copy link
Author

@Zarel I went on the Project Pokemon Discord and one of the users said the following:

"new battle -> get a random seed
any RNG call -> advance RNG, get next random value

it'd be a lot of trial and error
pokecheck still has the battle video src code available
http://vsplayer.pokecheck.org/?src

might be beneficial to try to get bvid battle exectution working first, as it's the 'known correct' result
gen6/7 use the same RNG, it's their new standard
https://github.com/wwwwwwzx/3DSRNGTool/tree/master/3DSRNGTool/RNG"

They're far more knowledgeable on this matter than I, I just figured this may be of help, if you'd like , join the discord and check the dev channel: https://discord.gg/66PzPgD

@kwsch
Copy link

kwsch commented Aug 18, 2018

one of the users

aka me ;)

I had done work reversing the battle video format back in xy, it's the same format in future games (give or take). Crude parser for reading turn instructions is included. Not pretty, but explored the format!
https://github.com/kwsch/pkBV

alt text

The bvid in the img can be seen here ingame; just a "Battle RNG" critfest with an always-zero seed.

PKHeX has some utility code to rip out parties from dumped battle vidoes.

As with Pokecheck back in the day, finding desyncs is mutually beneficial for finding battle emulation inaccuracies, and helping for bvid->showdown quick video preview emulation.

@Zarel
Copy link
Member

Zarel commented Aug 19, 2018

@kwsch What would really help me is a list of example replays, with a list of exactly where the RNG was called, and how the value was used each time.

(Maybe I would actually be able to close #1157 with that knowledge)

@kwsch
Copy link

kwsch commented Aug 19, 2018

afaik nobody has logged bvid->rand call results; I don't own a 3ds and am not particularly interested in this area...

I haven't bothered checking lately, but based on what I've seen from browsing the disassembly, it should be roughly the same rand() call ordering as prior games but with a different rand() method generating the random values.

https://www.smogon.com/forums/threads/past-gen-rng-research.61090/page-31#post-3693066

The game codebase doesn't change drastically between generations, just updates to add in new mechanics / structures. Shouldn't be too hard to plot rand results if a similar tool to RNG Reporter's Researcher window is made. I'm pretty sure the battle RNG uses its own dedicated SFMT.

@Zarel
Copy link
Member

Zarel commented Aug 19, 2018

@kwsch PS has never been accurate, but there's not an obvious reason why, to me. It would be very useful to compare the RNG calls PS makes with the RNG calls the games make.

I don't even need you to log RNG calls directly from the games; it would be enough to log RNG calls from the Pokécheck Gen 5 VS player.

I guess I could do it myself, but I don't particularly understand the code and am in the middle of some other work.

@Zarel Zarel changed the title Battle replay Feature Suggestion? Export PS replays to be openable on 3DS games Feb 20, 2019
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

No branches or pull requests

4 participants