ruadath Posted December 28, 2016 Share Posted December 28, 2016 (edited) Hey guys, I revisited this game recently in an attempt to crack the RNG formula and found it somewhat easier than expected. In particular, I already managed to crack the PRNG, so that I can calculate all of the random numbers in advance. My only issue is... interpretation... while my script readily obtains the 32 bit hexadecimal numbers produced by the game's RNG, I haven't been able to figure out how the game converts these values to a random number between 0 and 99 (it's not as simple as division like it was in the GBA games). I can do stuff in game to get the associated random number for any string, but I'm looking for a mathematical formula so I can get a lua script ready and post it to the website. If anyone has some experience with figuring out this kind of stuff, I'd appreciate some help. For anyone interested in helping, I can grab data relatively quickly by modifying Lena's in game HP growth rate and giving her a first level up to figure out what the value is. Hopefully we can wrap this up fairly quickly and get this up and running! Edited December 30, 2016 by ruadath Quote Link to comment Share on other sites More sharing options...
eclipse Posted December 28, 2016 Share Posted December 28, 2016 There's some data here. Match up whatever your script spits out with the random numbers generated by the times shown. See if you can find a pattern. Quote Link to comment Share on other sites More sharing options...
ruadath Posted December 28, 2016 Author Share Posted December 28, 2016 (edited) It's not an issue of not being to generate the data (and in particular, I'm not trying to figure out the clock seeds yet). Right now the issue is that I have a bunch of data in a spreadsheet that looks like HEX RN ABB6 BA1A 0 923D 5A37 2 But I'm unable to figure out a general pattern from these examples. I tried doing this bit by bit (figuring out values for 0000 0001, then 0000 0002, then 0000 0004, etc.), but this approach doesn't seem to be working because the function isn't linear (or at least, this isn't apparent). Once I figure this out, I'll be able to get a lua script ready easily, since I already figured out how the game moves form 1 hex string to the next. Edited December 28, 2016 by ruadath Quote Link to comment Share on other sites More sharing options...
eclipse Posted December 28, 2016 Share Posted December 28, 2016 How much data do you have so far? Quote Link to comment Share on other sites More sharing options...
Master Thunderblade Posted December 29, 2016 Share Posted December 29, 2016 Could you provide the spreadsheet with all the data you've gathered so far?It's nearly impossible to find the correlation between two rows of numbers, when you only have two samples to work with... Quote Link to comment Share on other sites More sharing options...
ruadath Posted December 29, 2016 Author Share Posted December 29, 2016 (edited) Sorry, I've been a bit busy with family stuff yesterday and today, but I'll get a spreadsheet up soon. I actually realized there was an error (an off by one error in mapping 32 bit strings and 0-99 numbers) in my data collection process, so hopefully when I get around to regenerating stuff later today/tomorrow it will be easier to figure out the pattern. Edited December 29, 2016 by ruadath Quote Link to comment Share on other sites More sharing options...
ruadath Posted December 30, 2016 Author Share Posted December 30, 2016 OK, I got the whole thing now. It was actually as simple as taking the value mod 2^30 and then mod 100. So I've got all that I need to write a lua script now, and the only thing left before we can say the RNG is completely cracked is figuring out how the DS clock seed works. Quote Link to comment Share on other sites More sharing options...
ruadath Posted December 30, 2016 Author Share Posted December 30, 2016 (edited) Lua script is now available function nextrng(r1) local seed = {0x18EE6547,0x8C7732AF, 0x463B9957, 0xA31DCCA7} return AND(XOR(r1, SHIFT(r1, -3), SHIFT(r1, -4), SHIFT(r1, 3), SHIFT(r1, 4), seed[r1%4+1]),0xFFFFFFFF) end function rngsim(n) local rngbase=0x02196E08 local result = { memory.readword(rngbase)+memory.readword(rngbase+2)*65536 } for i = 2, n do result[i] = nextrng(result[i-1]) end return result end while true do local nsim = 47 rngs = rngsim(503) for i = 1, nsim do gui.text(236, 8*(i-1)-190, string.format("%3d", (rngs[i]%2147483648)%100)) end gui.text(160,-190,"Previous RN:") emu.frameadvance() end EDIT: Clock function is monic and linear in seconds, which means any initial seed is possible. This means for TAS/LTC planning purposes, it suffices to hack the initial RNG state to whatever you want since it is always possible (and very easy) to calculate a clock time that will generate the desired seed. Edited January 1, 2017 by ruadath Quote Link to comment Share on other sites More sharing options...
eclipse Posted December 30, 2016 Share Posted December 30, 2016 In other words, it's possible to do a TAS run? If so, that would be interesting, to say the least! Mapping all the numbers needed would be a hell of a task, though. Quote Link to comment Share on other sites More sharing options...
ruadath Posted December 30, 2016 Author Share Posted December 30, 2016 (edited) Vykan already completed a TAS on normal mode in just over 12 minutes without being able to view the RNG at all With this script, RNG manipulation becomes possible, and this should hopefully allow for a significant time shave, either by skipping the prologue by doing H1 instead of normal mode, or by optimizing NM with crits/riskier strats. Edited December 30, 2016 by ruadath Quote Link to comment Share on other sites More sharing options...
SSJDennis Posted December 30, 2016 Share Posted December 30, 2016 So this is the project you were talking about XD Why not do it in H5? Plan out all the dodges and crits, you will hit like 8mins if you rush. Worst part about that video is skipping the entire enemy phase, really made it no fun to watch. Quote Link to comment Share on other sites More sharing options...
ruadath Posted January 1, 2017 Author Share Posted January 1, 2017 (edited) There is something wrong with the script. The numbers it gives are right most of the time but not always. I'll figure this out and provide an update as soon as I do. EDIT: OK I figured it out, and update the script accordingly. Edited January 1, 2017 by ruadath Quote Link to comment Share on other sites More sharing options...
Vykan_12 Posted January 5, 2017 Share Posted January 5, 2017 (edited) FYI, I'm probably doing an H5 TAS given Ruadath's breakthroughs Edited January 5, 2017 by Vykan_12 Quote Link to comment Share on other sites More sharing options...
ruadath Posted January 5, 2017 Author Share Posted January 5, 2017 That would be fun to see. Using more people than just Marth is always interesting. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.