Author Topic: Imperishable Night oddity...  (Read 12290 times)

EthanSilver

  • Lunatic Programmer
  • Got squid, will travel.
    • Ethan Silver's Junkpile - Hacks and translation patches
Imperishable Night oddity...
« on: March 01, 2013, 10:52:38 PM »
NOTE
A patch has been released to fix this. Download it here.



So I was testing something in IN when, during a throwaway run in which I didn't get enough time orbs to unlock the boss's last spell, the last spell occurred anyway.



What gives? I was under the impression that the last spell only triggers when you've met the time orb requirement by the end of the boss's last spellcard. Am I getting how last spells work wrong or is this a bug? Both wikis state you must be playing on normal or higher (hard, so, no problem there) and meet the time orb requirements; I couldn't find any mention of special cases that would otherwise trigger a last spell. The only thing I could think of is that I was playing in practice mode - don't really see why that would make a difference though (to confirm, I tried it and the last spell didn't trigger this time, though I had WAY less time orbs).

Does the game just "give" you last spells if you're within a hair's breadth of getting them, or does the game estimate the number of time orbs you'll have at the end of the last spellcard and is sometimes off by a few points?
« Last Edit: April 20, 2013, 04:19:08 AM by EthanSilver »


Latest works
The Strongest

Goldom

  • Whee
Re: Imperishable Night oddity...
« Reply #1 on: March 01, 2013, 11:47:21 PM »
I've seen a few people mention this before. Someone normally attributes it to a rounding error, though I don't know if they have any evidence of that.

Karisa

  • Extend!
  • *
  • High scores are meant to be broken.
Re: Imperishable Night oddity...
« Reply #2 on: March 02, 2013, 12:14:33 AM »
I've never had it occur for me, but I have some theories. You may have noticed that the last spell appears before the time orbs from the final normal spell are fully collected? That means the game has to determine whether or not to show the last spell, without simply using your current time orb count.

One possibility is that instead of counting up the on-screen time orbs and adding them to your total (like it probably should), the game assumes you're collecting a set amount of time orbs from that spell, even if the actual amount may be slightly less. Another is that the game does count up the on-screen time orbs, but a few time orbs may somehow despawn. Not that either of these seem that likely, but they're the best I can think of.

Kosachi

  • Te-Te-Te-Te-Tenko
  • Hinanai Tenko~
Re: Imperishable Night oddity...
« Reply #3 on: March 02, 2013, 12:37:48 AM »
One possible theory could maybe be that the last spell doesn't trigger with the on screen time counter, but with a separate, total orb counter. If you did exceptionally well in the previous stages, maybe it will still trigger? The game figures that the set, upper amount is what you should have collected and assumes you don't do significantly better than that.

Also, is this a Marisa only thing or it can happen to any boss? This interests me.
I finally got ahead!

Karisa

  • Extend!
  • *
  • High scores are meant to be broken.
Re: Imperishable Night oddity...
« Reply #4 on: March 02, 2013, 12:47:48 AM »
He said it was practice mode. And I doubt that would be the case, since I've had Lunatic runs in the past where I collected over 10000 time orbs in stage 1, but then had a disastrous deathbomb-filled stage 3 or 5 and failed to reach the last spell.

But that gives me an idea... is it possible that if you reach the time orb requirement, but then drop below it due to dying/deathbombing, the game still gives you the last spell?


Re: Imperishable Night oddity...
« Reply #6 on: March 02, 2013, 12:55:32 AM »
Did you save the replay? I'd like to check something if you did. Namely, I was able to replicate this using cheat engine. I found there are 3 values relating to time. First is a counter for your total time gained/lost during the full run, so it doesn't reset after stages. The other 2 count the current stage and reset to 0 every new stage.
When I changed one of those 2 values it changed my time counter, but changing the other value didn't seem to have any affect... until i activated the Last Word
As you can see by the image, I set my time to 8492 for practice stage B, but I set the other time value to over the required 8500 and I got the card.


Edit: ahh, I found something interesting... when you die normally both of those time values will decrease by the same amount, but when I die with a low enough time value, it reduces that third value by less than the second, so it would end up being higher at the end of the stage. I'm willing to bet you died or deathbombed early in your run.

« Last Edit: March 02, 2013, 01:09:23 AM by Feenixtrite »

EthanSilver

  • Lunatic Programmer
  • Got squid, will travel.
    • Ethan Silver's Junkpile - Hacks and translation patches
Re: Imperishable Night oddity...
« Reply #7 on: March 02, 2013, 01:15:25 AM »
You may have noticed that the last spell appears before the time orbs from the final normal spell are fully collected?
Heh. I've been going back and forth and rewriting this post a lot.

The game does appear to wait until all time orbs are collected before triggering the last spell. I had the same idea and tried a run of stage 1 (and later, 2 and 4) to confirm it. Unfortunately the game waited until the last time orb was auto-collected to start the last spell declaration (like, pretty much the exact frame) in all three attempts. I figured maybe the game estimates, auto-collects, then declares, but rejected that idea because it sounded stupid - why bother to estimate the time orbs the player will have if you're going to wait until after they've been collected to declare the last spell anyway? But then I remembered a special situation in which time orbs are not auto-collected: getting killed off as the spellcard is ending. Time orbs take a while to fall and I doubt the game will idle until the very last time orb is gone, so my theory is...

1- Estimate the time orbs the player can collect. This is so we can declare ASAP.
2- Auto-collect the time orbs. If the player died and comes back, no auto-collection takes place.
3- Once the auto-collect "timer" runs out, whether time orbs were auto-collected or not, declare if the estimate says we will.

If the player is alive, no problem: time orbs are auto-collected and immediately after they're all gone the game starts the last spell. If the player died, however, we have a problem: waiting for the player to manually collect time orbs (or for them to fall offscreen) would mean having the boss idle/removed for a fairly long period of time. So this is why we make an estimate: the player will PROBABLY collect 'n' time orbs once they come back but we're not going to wait to find out to avoid interrupting gameplay for too long.

I didn't die when facing Marisa, but that shouldn't matter if the estimate itself is bugged (ex: maybe a bullet has time to despawn between the estimate and the conversion to time orbs).



@Feenixtrite
I didn't save a replay. I suppose I could poke through my assembly dump and see what comes up... Gimme a lil' bit.
« Last Edit: March 02, 2013, 01:52:30 AM by EthanSilver »


Latest works
The Strongest

Nindella

  • That cat!
  • Nyaaa...
    • Youtube Page!
Re: Imperishable Night oddity...
« Reply #8 on: March 02, 2013, 01:19:01 AM »
Oh, this has happened to me a couple of times during my Lunatic runs of IN, I mostly notice it on Wriggle.

Never really thought too much of it though, haha, but it certainly is an interesting thing to figure out...  (I have no idea why it happens!  :V)
Youtube Channel!
Please check it out for Touhou commentaries, LPs, piano transcriptions and more!
My Touhou replays!

Re: Imperishable Night oddity...
« Reply #9 on: March 02, 2013, 01:30:14 AM »
Well it seems like I have it figured out. The third value is the important one. That's what needs to be at or above the target. The second value is just your displayed value. If your death occurs when you have low enough time, the second value drops to zero, but the third value, for some reason, does not drop to zero. Repeated deaths with low time increase the gap between displayed time and the actual value until you get stuff like 8486/8500 getting last words.

Drake

  • *
Re: Imperishable Night oddity...
« Reply #10 on: March 02, 2013, 01:49:09 AM »
Tested for rounding errors. It's a bit difficult since forcing the values to be 7190 (/7200) doesn't update immediately and you have to make sure you don't get any time orbs at the end, without dying, because dying cleaves the time values and the forced values don't update after then since you don't collect any time orbs. Ha.

anyways no rounding

It doesn't make sense for there to be anyways, that takes even more calculation that just saying if x>y. I was assuming something silly like round(x/y) which would round to 1 given you had 7190/7200. But yeah no. It seems to be from said other non-shown time value but I haven't seen enough to say how it works.

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

EthanSilver

  • Lunatic Programmer
  • Got squid, will travel.
    • Ethan Silver's Junkpile - Hacks and translation patches
Re: Imperishable Night oddity...
« Reply #11 on: March 02, 2013, 01:52:56 AM »
Bah, you people post too fast. ;D

@Feenixtrite
Ok. Might've found something.
objGame.objPlayer.0x3C: (value 1) Current amount of time orbs.
objGame.objPlayer.0x44: (value 2) Total amount of time orbs for this stage.

One of those values (0x3C) is actively updated and used but the other (0x44) is only used in 00418220, which adds parameter_1 time orbs. Both values are updated when time orbs are obtained/lost except for one situation: when losing time orbs. The relevant pseudocode looks like this...

Code: [Select]
...
if( P08_Quantity < 0)
if( [[L04_GameObj+08]+3c] < -P08_Quantity)
[[L04_GameObj+08]+3c] = 00000000
return

[[L04_GameObj+08]+3c] = [[L04_GameObj+08]+3c] + P08_Quantity
[[L04_GameObj+08]+44] = [[L04_GameObj+08]+44] + P08_Quantity
...

Notice anything? When losing time orbs, if we have less orbs remaining than what we want to lose, we set 0x3C to 0 (instead of subtracting and getting a negative number) BUT NOT 0x44. This means losing time orbs past 0 will only affect 0x3C and not 0x44, leaving the latter with whatever it had in the first place (ie, a higher value than 0x3C now has). So while the displayed value is under the required amount of time orbs, the internal value can be several hundred points off.

Edit: Seems you figured that out as well. :)

Edit 2: For those who want it, here's a link to the unaltered 00418220 routine. ecx is loaded up with the main "game" object and the stack contains the quantity to alter the time orbs by.



Okay, wrote a patch for this. Because, why not. :D Download

Just run it in your IN folder. It'll create the file "th08e-timefix.exe" and leave your original exe untouched. Enjoy!
« Last Edit: March 02, 2013, 08:51:34 PM by EthanSilver »


Latest works
The Strongest

Seppo Hovi

Re: Imperishable Night oddity...
« Reply #12 on: March 03, 2013, 07:08:16 AM »
At this point I must note that you should not advertise code-altering patches for IN until you have tested that it gets accepted by Royalflare, who have banned things such as the english patch for IN.

Also, from the few times I have triggered this bug, it has never seemed too effective to the game itself and the runs with it happening tend to be garbage anyway, so I see no reason to fix it.

I have no name

  • Dodge ALL the bullets
Re: Imperishable Night oddity...
« Reply #13 on: March 03, 2013, 07:23:43 AM »
At this point I must note that you should not advertise code-altering patches for IN until you have tested that it gets accepted by Royalflare, who have banned things such as the english patch for IN.
If you're going for super-competitive scores sure, but who really cares if you're just playing for fun?  That's like saying because SDA doesn't accept emulator runs, no one should ever do anything related to GAMING on emulators...but they're useful for practice, fine for just playing on, great for testing, etc.

Seppo Hovi

Re: Imperishable Night oddity...
« Reply #14 on: March 03, 2013, 07:49:49 AM »
People improve as time passes. Patches might get forgotten on and therefore your runs might get accidentally invalidated due to having installed a completely useless fix three years ago.

Oh, and super competitive players tend to play for fun. Or at least I do.
« Last Edit: March 03, 2013, 07:51:44 AM by Vee »

I have no name

  • Dodge ALL the bullets
Re: Imperishable Night oddity...
« Reply #15 on: March 03, 2013, 08:01:17 AM »
Patches might get forgotten on and therefore your runs might get accidentally invalidated due to having installed a completely useless fix three years ago.
Just run it in your IN folder. It'll create the file "th08e-timefix.exe" and leave your original exe untouched. Enjoy!
Doesn't seem like a problem to me.

Oh, and super competitive players tend to play for fun. Or at least I do.
Oh trust me, I know this from the speedrunning community.  My point is not that disobeying rules in serious competition, no matter where you rank on it should be ok, but that if you're just playing for fun, it doesn't matter at all.  I've played through Threads of Fate on emulator, I wouldn't do a run without the actual disc since emulators are inconsistent and stuff (and I see where you're coming from on that), but there is nothing wrong with using patches or anything to just play the game.

I'm not trying to start another argument either, but you state your opinions like they are the law and anyone doing otherwise is playing wrong and then talk down to anyone who disagrees.  Or at least that's my impression.

tl;dr, not responding any further, I see where you're coming from but in casual play who really cares what patches are and are not used

EthanSilver

  • Lunatic Programmer
  • Got squid, will travel.
    • Ethan Silver's Junkpile - Hacks and translation patches
Re: Imperishable Night oddity...
« Reply #16 on: March 03, 2013, 08:48:02 AM »
At this point I must note that you should not advertise code-altering patches for IN until you have tested that it gets accepted by Royalflare, who have banned things such as the english patch for IN.
As insignificant as it is, this is a bug (albeit a very minor one). Bugs are meant to be fixed. And I sincerely doubt ZUN is going to release a patch for IN - it's an old game and he's got other things to focus on. If this makes IN better in even a tiny way to at least one person, I've done my job right and the effort was worthwhile.

Seriously, I mean no offense - I don't know Royalflare. But AFAIK he has no more ownership of the Touhou franchise than I do. If you have an issue with this, don't download it. If it makes your IN experience better, it's out there and available. Don't let your personal views of what Touhou should be or shouldn't be prevent others from enjoying it in their own way.

By the way, I think you can be safe in the knowledge that your "really good" runs probably don't even come close to triggering this. If your pride and joy is a run where you played so poorly as to drop below 0 time orbs, your concerns may be misplaced. This is more of a beginner issue, and not in the least bit the game's intended behavior.
« Last Edit: March 03, 2013, 08:58:37 AM by EthanSilver »


Latest works
The Strongest

Drake

  • *
Re: Imperishable Night oddity...
« Reply #17 on: March 03, 2013, 09:31:25 AM »
Wait so why should I apply a patch to fix this anyways

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

Kosachi

  • Te-Te-Te-Te-Tenko
  • Hinanai Tenko~
Re: Imperishable Night oddity...
« Reply #18 on: March 03, 2013, 11:52:24 AM »
Wait so why should I apply a patch to fix this anyways
If you tend to die very early in your runs, just apply the patch to have your game display your true value of time orbs instead of the false one like has been mentioned above. This will remove the possibility of activating a last word without you having enough displayed time orbs to do so.
I finally got ahead!

Sakurei

  • Banned
  • Frequently repeated unapologetic hostility
    • My Blog
Re: Imperishable Night oddity...
« Reply #19 on: March 03, 2013, 01:59:10 PM »
I will be very honest now. I think this has already gotten way more attention than it should have. it's a bug so minor that it might as well be ignored. come on guys, it's as you said, the game is old and ZUN didn't fix it back then. I am sure many people have had it happen before, but why does it matter? if you're going to pick on something like "it's not displaying my time orbs correctly" then cover up the right part of you screen and stop whining about it.

this has really gone way too far already. I have to agree with seppo here.

Karisa

  • Extend!
  • *
  • High scores are meant to be broken.
Re: Imperishable Night oddity...
« Reply #20 on: March 03, 2013, 03:06:47 PM »
What's this about the game not displaying the correct time orb count? As far as I know, the game is already displaying the correct time orb count. At least, I've never seen the "time" value in the clear bonus not match up to the displayed time orb count times 1000. I thought the bug was that last spells are sometimes activated when you've just barely missed the time orb requirement, apparently caused by the unlikely situation (except in stage 6, but it's irrelevant there) of dying very early in the stage?

Also, whether a fix is a good idea or not depends. If an unofficial bug-fix patch can result in desynced replays, it probably isn't much use for players planning to share their replays (except maybe if it's a major gameplay change like fixing MoF MarisaB). Not that I think you shouldn't have released it; there's still novelty value to a patch like this.

Kosachi

  • Te-Te-Te-Te-Tenko
  • Hinanai Tenko~
Re: Imperishable Night oddity...
« Reply #21 on: March 03, 2013, 03:57:42 PM »
What's this about the game not displaying the correct time orb count? As far as I know, the game is already displaying the correct time orb count. At least, I've never seen the "time" value in the clear bonus not match up to the displayed time orb count times 1000. I thought the bug was that last spells are sometimes activated when you've just barely missed the time orb requirement, apparently caused by the unlikely situation (except in stage 6, but it's irrelevant there) of dying very early in the game?
When losing time orbs, if we have less orbs remaining than what we want to lose, we set 0x3C to 0 (instead of subtracting and getting a negative number) BUT NOT 0x44. This means losing time orbs past 0 will only affect 0x3C and not 0x44, leaving the latter with whatever it had in the first place (ie, a higher value than 0x3C now has). So while the displayed value is under the required amount of time orbs, the internal value can be several hundred points off.
I finally got ahead!

Drake

  • *
Re: Imperishable Night oddity...
« Reply #22 on: March 04, 2013, 12:26:33 AM »
If you tend to die very early in your runs, just apply the patch to have your game display your true value of time orbs instead of the false one like has been mentioned above. This will remove the possibility of activating a last word without you having enough displayed time orbs to do so.
and why is this a bad thing in any context whatsoever

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

Zil

Re: Imperishable Night oddity...
« Reply #23 on: March 04, 2013, 12:56:20 AM »
At least, I've never seen the "time" value in the clear bonus not match up to the displayed time orb count times 1000.
So the clear bonus agrees with the displayed time orb count even in a run where you triggered the last spell without having enough time orbs? Then would the patch result in the clear bonus appearing to be lower than it should be, or would using the patch actually give you a higher clear bonus?

Karisa

  • Extend!
  • *
  • High scores are meant to be broken.
Re: Imperishable Night oddity...
« Reply #24 on: March 04, 2013, 01:50:54 AM »
Actually, I haven't been able to trigger this glitch myself either.

See this replay. Stage 1 ends with 2689/2700 time orbs, with the hidden value (that doesn't decrease as much when your time orb count is reduced to 0 from dying/deathbombing) of 2720 according to Cheat Engine. But Wriggle didn't use her last spell, the game still increased the time by 1 hour, and the clear bonus said 2689000 as expected.

If someone could provide a replay where the glitch actually occurs, that would be nice.

Tengukami

  • Breaking news. Any season.
  • *
  • I said, with a posed look.
Re: Imperishable Night oddity...
« Reply #25 on: March 04, 2013, 01:54:48 AM »
and why is this a bad thing in any context whatsoever

I agree. IN is my favorite game in the series, and I don't see how the patch is anything but an improvement. Like Ethan pointed out, this is something that corrects a very, very minor bug that is of no consequence in the larger scheme of gameplay. It's akin to correcting a typo rather than editing the paragraph. I don't see how making the inexact exact is an issue. Especially on account of it not overwriting the original .exe.

"Human history and growth are both linked closely to strife. Without conflict, humanity would have no impetus for growth. When humans are satisfied with their present condition, they may as well give up on life."

EthanSilver

  • Lunatic Programmer
  • Got squid, will travel.
    • Ethan Silver's Junkpile - Hacks and translation patches
Re: Imperishable Night oddity...
« Reply #26 on: March 04, 2013, 02:13:09 AM »
So the clear bonus agrees with the displayed time orb count even in a run where you triggered the last spell without having enough time orbs? Then would the patch result in the clear bonus appearing to be lower than it should be, or would using the patch actually give you a higher clear bonus?
The displayed time orbs are correct, however the internal value (which is used for the calculations involving time orbs) is not. Both values are unsigned (meaning they cannot take a negative value) so certain precautions must be taken to avoid letting them become "negative" or they'll actually come out as Really, Really Big Numbers (tm). We do this for the displayed value but forget to do anything at all for the internal value. You don't actually lose any time orbs when death-bombing with less points than what the penalty would make you lose.

So, in the first place, the last spell is not supposed to be triggered in the instances you describe - it does but that's because the bug causes the game to forget to update the internal value. Assuming you do meet the time orb requirements but have death-bombed with the patched exe on the other hand, the game will count your time orbs as being (deathbombPenalty* - timeWhenDeathbombing) lower each time the bug is triggered (which is exactly the displayed value's value, and the real amount of time orbs you should actually have).

* Forgot how much it was. ;)
« Last Edit: March 04, 2013, 02:15:03 AM by EthanSilver »


Latest works
The Strongest

Kosachi

  • Te-Te-Te-Te-Tenko
  • Hinanai Tenko~
Re: Imperishable Night oddity...
« Reply #27 on: March 04, 2013, 02:27:29 AM »
and why is this a bad thing in any context whatsoever
I agree that this is a tiny error. I also don't think it's a bad thing at all; but if someone out there doesn't like the issue for whatever reason, they have the option to fix it.
« Last Edit: March 04, 2013, 02:49:07 AM by Kogasa Tatara »
I finally got ahead!

Massaca

  • すやぁ...
Re: Imperishable Night oddity...
« Reply #28 on: March 04, 2013, 08:49:44 AM »
If someone could provide a replay where the glitch actually occurs, that would be nice.

At Wriggle. 2499/2500. Ignore the terribleness >_>