A 'Deep' Dive into Sonny's Code
3 years ago
New Zealand

So as promised, I've been looking into Sonny's code for the past few days and have some things to report (and to not report).

The first is as to how the game determines what items drop after a battle. As I feared, it uses Math.random() as the powerhouse behind its 'randomness'. The reason this is a problem is because you can't seed Math.random(). Seeding basically means that if you input the same 'seed' into the random number generator, it would output the same results. So because of that, at the moment I have no idea how to consistently get the drops that we desire (MSH plz).

The second thing, and this didn't really have to with speedrunning but my inner code geek came out, was that I found out how the game creates items and enemies/allies. Nothing much here that's useful for routing, but it was fun to mess around with item stats and flavour text. Here's an example of what I did: https://twitter.com/AzureStarPlayer/status/1339138161872576512?s=20

And finally, the formulas for how the game calculates damage. The good news is that I'm pretty sure I found them. The bad news is that I'm going to have to do some debugging in order to find out how it works. The issue is mainly due to me not really understanding the structure of actionscript. There are variables in the formulas that are declared somewhere that I can't see, and therefore I don't know what they are or what possible values they should have. My plan right now is to have the program spit out the values for those variables as I play the game, and hopefully from that I can deduce what they're meant to represent.

So that's what I've got so far. Nothing too impressive, but hopefully I'll have something in the coming weeks.

EvenEden, LuniRSC and 4 others like this
Belgium

Today I decided to do a pretty low-effort attempt at looking a bit into the code of Sonny as well by using a Flash decompiler to (among other useless things) look at the hex dump of the game and while I didn't find anything very conclusive I did find this one interesting extract somewhere https://media.discordapp.net/attachments/883843846511947817/1015661504797868103/unknown.png the rare item variables aren't mentioned anywhere else in the entire rest of the hex dump as far as I'm aware so I wasn't able to find anything about it, and I also wasn't able to quickly find a way of looking into the code on a simpler level of complexity, but this leaves me to speculate that the game treats these "rare items" differently from regular items (which it certainly feels like to me, an example of this is that to me it feels like shaman of blades drops tribal weapons way more than 8% of the time specifically the first time you fight them in training, although that might just be me going absolutely insane, maybe it just has those extra things to handle the extra slot it needs to draw for the rare item) (the fact that they, for example MSH/shaman weapons/blade of light, also drop completely independently of other items further strengthens my belief that they might be treated differently than it seems). Did you find any indications of this in the code and could you send me a copy of or link to the source code of the game?

Edited by the author 1 year ago
IschmarVI likes this
Germany

yeah, it seems to treat rare items differently. My guess would be that there is several "slots", essentially one per enemy or so for a "regular" item. And then, on top of that, there is a chance, that a "rare" items drops on that stage, that is likely independent of the actual enemies on that stage (e.g. Moonstruck Horrors never drops twice on a stage even if it has several enemies).

New Zealand

From what I remember during my code digging, item drops are not attached to enemies but rather the battle itself. I'll have to look into the 'itemRareDropper' to see if it does anything special.

IschmarVI likes this
Romania

You might be interested in this: https://i.imgur.com/SiINVsp.png

New Zealand

Huh, I didn't think it was still possible to modify Flash games since it got canned.

Lower Saxony, Germany

this is absolutely amazing, appreciate the efforts!

stealing_society likes this
Romania

Decompiling the raw .swf spits out pure ActionScript haha. I used JPEXS. I wonder how modding the game would affect speedrunning..

EDIT: Would a hand-crafted "perfect RNG" run be valid? I believe such a run could hit sub 11 mins.

Edited by the author 1 year ago
Germany

as long as the actual run is done on the unmodified version of the game, it would be valid, yes.

However, if you are running on a modified version, you are effectively playing a different game.

Edited by the author 1 year ago
Romania

I meant that, since the game seems so easy to mod, a modified version of the game that gives you better chances is visually identical to the original one. How would runs then be verified?

New Zealand

One method I could think of is playing the game on Flashpoint. To my knowledge, you can't modify the game there and the item eating glitch works there.