Integer overflow bug

Discuss PoP1 for DOS here.
duke
Efendi
Efendi
Posts: 7
Joined: October 2nd, 2010, 4:03 am

Integer overflow bug

Post by duke »

My brother and I used to do some crazy things with this game, playing it hours on end. I can't even begin to recall all the bugs and tricks we discovered, but here's some I do remember, in case anyone doesn't know about them. They're mostly vague, but it's been a long time. These all apply to the DOS version.

Level 12 hang-on bug

Not sure if anyone's encountered this before. It was a bug I found back in the day some may find interesting. It can be duplicated in all versions of Prince of Persia 1, though the behavior seems to be different now, possibly due to emulation or CPU cycles.

At the top of level 12, on the screen to the right of where you fight yourself, if you stand on the 2 block platform at the very bottom and use the 2 block running trick to do a running jump left off the screen while holding shift to hang on to a ledge, the screen will change several times in a matter of a second, and you'll fall from the ceiling to the ground on the screen where you fight yourself.

Thing is, this was far more interesting when I originally used to reproduce it. These days, you fall to the ground, lose a triangle of health, and not much else happens, but when I used to exploit this bug back on my old 286, you would fall to the ground, lose a triangle of health, but would be "misaligned" with the ground tiles. You would not be standing in the center of them, but right up against the back wall. If you bumped into anything which caused the Prince to make the "uh" sound, it would realign you. You could still interact with the environment, so climbing up, making tiles fall, etc, but the amusing thing was that because you weren't standing properly on the floor tiles, your nemesis would not be on the screen, and the sword would still be lying there, which you could pick up. This would effectively bug level 12 and make it impossible to complete.

Has anyone ever discovered this before, or am I the first?

Level 8

Ahh, level 8, home to the toughest swordsman in the game. My brother and I used to force this guard into the spikes each time we played through. It's tough, since he doesn't want to be pushed back. If you can survive switching places with him, you can lure him over, but then you have to make it back!

Also, if you're quick enough, you can make it back through the gate near the end before it closes and the mouse has to save you. Then, you can watch with amusement as he saves nobody. To do so, you have to time things properly so you can run and jump non-stop and not be hit by the blade traps.

Dead, but not dead

I recall several instances where we would manipulate guard death. One was the blade trap. If you knock a guard into a blade trap, and then hit him with your sword just as the blade closes, he'll survive (given he has health left), and the blade will have blood on it. Another trick had to do with freefalling, though I don't remember exactly what we did. I believe we knocked a guard off a high ledge and used the screen flipping trick (detailed below) to time when we'd change screens. If changed as he was 1 ledge length or less from the floor, you could stop him from dying, as it would somehow see it as a 1 ledge length fall.

Moving guards

When in combat, you can back up and get guards to follow you many places. This can be amusing since you can take guards to areas where they otherwise would not be and this can create amusing (and sometimes helpful) results.

Backing up off the screen

When in combat, you can use guards to help you bypass otherwise impassable obstacles. While backing up off the current screen, if you time your keypresses just right, you can keep the screen from switching over to the new one for a lengthy period of time. In some cases, this is long (and buggy) enough to back you through closed gates and sometimes solid walls. This also allows you to control when the screen switches over. At any point while using this trick, simply stop all movement and the screen will change. A specific place where you can use this bug to your advantage is at the beginning of level 5. Go right, hit the purple guard down to the bottom level. Jump back down and use him to back onto the screen to the left of the screen where you entered the level. If everything goes well, you'll find yourself on the other side of the gate on the bottom level.

Hit from behind

In employing the above two tricks, we discovered that you can actually back up through other live guards. What happens is that once the screen changes (and it's one where there's another guard), you'll find yourself behind the undisturbed guard, out of combat. This is because the game won't allow you to fight more than one guard at a time, so the guard you were fighting is blocked from following you on screen. If I recall, you can bring him back if you return to the previous screen and let him come after you while you can't see him. Anyway, the undisturbed guard. Making any noise will obviously wake this guard up, but if you time things just so, you can get the screen to flip so you're within striking distance of the out of combat guard while he's facing the other way. Striking any guard who's not in combat will kill him in a single blow.

Block + swing sword trick

This is much more useful in Prince 2, but does have limited effectiveness in Prince 1. If you press up to block and while in the middle of the move press the attack button, it will create a very well-rounded maneuver that will keep you almost completely safe while allowing you to also be offensive. It allows you to block and quickly follow up with a swing. In Prince 1, this has limited effectiveness because it can really only be used defensively. You have to wait for guards to advance and then use the move. However, in Prince 2, doing this maneuver will advance the Prince. Each time moves him forward by a couple pixels. As such, this makes you almost completely untouchable against all guards in the game, but unfortunately does not work on other enemies, including the infamous heads. This is because guards generally attack when you're advancing and hold their position when you're attacking. Using this move causes you to do both simultaneously.


This is all I can think of for now. Hope you guys find some or all of these amusing. I know I did when I first discovered them.

Duke

[Edit: This thread was called "Prince of Persia bugs and tricks" but there was already a thread like that from 2009. --Norbert]
Kaslghnoon
Sultan
Sultan
Posts: 153
Joined: February 27th, 2010, 8:35 pm
Location: United States

Re: Prince of Persia bugs and tricks

Post by Kaslghnoon »

duke wrote:Level 12 hang-on bug

Not sure if anyone's encountered this before. It was a bug I found back in the day some may find interesting. It can be duplicated in all versions of Prince of Persia 1, though the behavior seems to be different now, possibly due to emulation or CPU cycles.

At the top of level 12, on the screen to the right of where you fight yourself, if you stand on the 2 block platform at the very bottom and use the 2 block running trick to do a running jump left off the screen while holding shift to hang on to a ledge, the screen will change several times in a matter of a second, and you'll fall from the ceiling to the ground on the screen where you fight yourself.

Thing is, this was far more interesting when I originally used to reproduce it. These days, you fall to the ground, lose a triangle of health, and not much else happens, but when I used to exploit this bug back on my old 286, you would fall to the ground, lose a triangle of health, but would be "misaligned" with the ground tiles. You would not be standing in the center of them, but right up against the back wall. If you bumped into anything which caused the Prince to make the "uh" sound, it would realign you. You could still interact with the environment, so climbing up, making tiles fall, etc, but the amusing thing was that because you weren't standing properly on the floor tiles, your nemesis would not be on the screen, and the sword would still be lying there, which you could pick up. This would effectively bug level 12 and make it impossible to complete.

Has anyone ever discovered this before, or am I the first?
It depends on when you discovered this. I personally did not know of this bug until I saw a speed run on YouTube back in 2007. Judging by posts on this forum, getting the sword in level 12 is dated back to 2005: viewtopic.php?f=73&t=468

One thing I recently saw in another YouTube speed run is that the same level 12 bug can be exploited in level 10:
http://www.youtube.com/watch?v=FJRmrFzw ... iv#t=2m22s
Bug is around 2:22
duke
Efendi
Efendi
Posts: 7
Joined: October 2nd, 2010, 4:03 am

Re: Prince of Persia bugs and tricks

Post by duke »

Nice. It looks like a more generic bug that works as long as you're in a situation where the level architecture will allow you to exploit it. Guess I should've figured with the crazy gamers today that a bug like this couldn't go undiscovered.

And now that I see it, I was remembering incorrectly. The way he did it in level 12 is how we used to reproduce it. And we discovered it back in the early 90s on my old 286. I'm not claiming to be the first, just wanted to know if it was known about or not.

Thanks for the video links. Interesting!
Eagle-Head Priest 97
Wise Scribe
Wise Scribe
Posts: 342
Joined: July 11th, 2009, 4:28 am
Location: Somewhere in the Milky Way
Contact:

Re: Prince of Persia bugs and tricks

Post by Eagle-Head Priest 97 »

I figured it out with my brother some time ago. We were playing the heck out of it!
Former Member of popuw.com/forum
Image
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Prince of Persia bugs and tricks

Post by David »

duke wrote:Level 12 hang-on bug

(...) though the behavior seems to be different now, possibly due to emulation or CPU cycles.
Actually, the difference may be because this trick can be done at two places on level 12.
One place is the room right to the shadow's room. If you do that here, the prince will fall into the shadow's room.
The other place is below this room. If you do that here, the prince will climb up through the floor.

Also, I think I've found the cause of the bug.
I've put together two screenshots showing the prince hanging at the correct and at the incorrect places. The distance between the two cases is 256 pixels.
So, probably an integer wraparound (also called integer overflow) happens here.
Since the game forgets to change the screen after the prince grabs the ledge, he is shown at the very bottom of the screen.
The Y coordinate is stored in 1 byte and when the game wants to increase the Y coordinate, it will change from 255 to 0, causing the prince to appear in the room above.
Andrew
Wise Scribe
Wise Scribe
Posts: 313
Joined: July 16th, 2009, 4:39 pm

Re: Prince of Persia bugs and tricks

Post by Andrew »

David wrote: Also, I think I've found the cause of the bug.
I've put together two screenshots showing the prince hanging at the correct and at the incorrect places. The distance between the two cases is 256 pixels.
So, probably an integer wraparound (also called integer overflow) happens here.
Since the game forgets to change the screen after the prince grabs the ledge, he is shown at the very bottom of the screen.
The Y coordinate is stored in 1 byte and when the game wants to increase the Y coordinate, it will change from 255 to 0, causing the prince to appear in the room above.
Where are the screenshots? Also, I love such investigative analysis (your theory sounds like the most plausible explanation BTW). It's like being a forensic detective and trying to solve the puzzle by delving into the code! :)
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Prince of Persia bugs and tricks

Post by David »

Here is the screenshot: http://princepersia.freeweb.hu/en/room_bug.htm
Andrew wrote:your theory sounds like the most plausible explanation BTW
Why, were there other explanations?
Andrew
Wise Scribe
Wise Scribe
Posts: 313
Joined: July 16th, 2009, 4:39 pm

Re: Prince of Persia bugs and tricks

Post by Andrew »

David wrote:Why, were there other explanations?
Not that I know of! :) Just that given the symptoms, your diagnosis seems to be most likely the correct one.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Prince of Persia bugs and tricks

Post by Norbert »

David wrote:Here is the screenshot: http://princepersia.freeweb.hu/en/room_bug.htm
I've created a new collage image. (David's website is down and the Internet Archive doesn't have the image stored.)
This is the location of the new image. Also embedded into this post, below:

Image
tacosalad
Sheikh
Sheikh
Posts: 48
Joined: October 3rd, 2005, 6:03 am
Location: Oregon, USA
Contact:

Re: Integer overflow bug

Post by tacosalad »

For what it's worth, I can confirm the Integer Overflow bug was already present in the earliest Apple II version of the game.

There are two places you can trigger it in level 12: at the platform shown in Norbert's diagram above, or from the platform at the top of the same tower above. In 1989 my college dorm-mates liked the second variation because it looked so spectacular like the "prince just popped out of the ceiling!"

We also discovered the Apple II version also included cheat-like Easter Eggs that weren't carried forward into any other version of PoP (AFAIK). On level 8, if you pushed the first guard onto the door switch during a sword fight it would (naturally) open the door. If you then struck down the guard so he fell onto the switch you would hear the sound of other doors opening--which was especially peculiar because the door normally operated by the switch was already open so there shouldn't have been any sound. We discovered this trick opened all the gates throughout the whole level except the last!

Level 2 had a switch that exhibited the same behavior--it made a distinctly different door opening sound if you killed a guard on it even though the door was already open--but we could never find what had been opened when we triggered it.
User avatar
mk1995
The Prince of Persia
The Prince of Persia
Posts: 1160
Joined: February 27th, 2009, 10:09 pm
Location: Germany

Re: Integer overflow bug

Post by mk1995 »

tacosalad wrote:On level 8, if you pushed the first guard onto the door switch during a sword fight it would (naturally) open the door. If you then struck down the guard so he fell onto the switch you would hear the sound of other doors opening[...]
"The" door switch? Does it work with any button or only in the above-mentioned cases?
Image
Just to make something clear: I will not reply to daft PMs like "Where can I find X?" or "Can you give me a link to Y?". Most of your questions are likely answerable if only you took your bloody time to look through these forums and use Google if all else fails. Sheesh...
tacosalad
Sheikh
Sheikh
Posts: 48
Joined: October 3rd, 2005, 6:03 am
Location: Oregon, USA
Contact:

Re: Integer overflow bug

Post by tacosalad »

mk1995 wrote:
tacosalad wrote:On level 8, if you pushed the first guard onto the door switch during a sword fight it would (naturally) open the door. If you then struck down the guard so he fell onto the switch you would hear the sound of other doors opening[...]
"The" door switch? Does it work with any button or only in the above-mentioned cases?
Sorry, I didn't describe it very clearly so I've attached a diagram.

AFAIK this bonus existed only on the Apple II version of PoP.

If you kill the first guard so he falls on the switch for the exit door for that room, it will instead open two other doors in the level and it will hold them open so the prince won't need to race the clock to get through those doors later.

But there's a penalty for pulling this trick: once the guard falls, that door switch no longer holds open the door to exit the room you're in so you must get out before the door closes!! If the exit door closes, it stays closed.
cheat-like bonus on Apple II PoP
cheat-like bonus on Apple II PoP
There's a similar behavior at a switch in level 2, but we never located what door it opened. Now that the Apple source code is available I've considered trying to figure it out.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Integer overflow bug

Post by Norbert »

tacosalad wrote:[...], it will instead open two other doors in the level and it will hold them open so the prince won't need to race the clock to get through those doors later.
Three gates, to be exact. ;)

These are the normal open/closed statuses of the gates (image is clickable):

Image

These are the statuses of the gates when the guard is on that particular raise button (image is clickable):

Image

The first image in the collage is where the raise button is, the other screens are, from left to right, where all the gates are to the right of the exit door.

(Yes, I felt like playing the Apple II version for a change...)
tacosalad
Sheikh
Sheikh
Posts: 48
Joined: October 3rd, 2005, 6:03 am
Location: Oregon, USA
Contact:

Re: Integer overflow bug

Post by tacosalad »

Norbert wrote:Three gates, to be exact. ;)
Outside the dorm I had never encountered anyone else who shared this experience. I'm totally thrilled you replicated it!

Can you confirm whether I remembered the odd behaviors accurately: 1) when the guard falls, there's a telltale sound of a gate opening even though the gate already seems to be open, and 2) after the guard falls, the switch no longer operates the gate so it might close permanently if you don't hurry through.

I haven't played the Apple II version since 1993, so some details are fuzzy. Some time ago I thought there were three of these trick door switches in the game, but now I can only recall the specifics of two:
  • Level 8 - I remember this trick fairly well because I used it regularly to bypass those annoyingly-timed doors, and so did my college roommate.
  • Level 2 - Killing the second guard (I think) on the nearby door switch causes the same telltale behaviours as level 8--there's an unexplained sound of another gate opening, and the switch no longer opens the gate it should. But this one's a mystery: we never discovered what gate that had been opened, if any. In fact, killing the guard on the switch made the level harder because you could become trapped if the gate closed.
  • Level ? - During the 90's I used to tell people there was a third switch that exhibited this behavior, but I can't remember where it could have been. But it's been so long, maybe I just remember searching for a third--maybe there wasn't another.
The mysterious behavior on level 2 still intrigues me. I wonder if it was a remnant of an bonus feature Jordan Mechner initially planned but later removed. Maybe the cheat feature on level 8 was also intended to be removed (as it was on other platforms) but it slipped in accidentally?

Anyone have access to the C-64 port? It was partly derived from the un-commented Apple II code, so maybe it includes these behaviors too.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Integer overflow bug

Post by Norbert »

tacosalad wrote:1) when the guard falls, there's a telltale sound of a gate opening even though the gate already seems to be open, and 2) after the guard falls, the switch no longer operates the gate so it might close permanently if you don't hurry through.
1) I think so, but I'd have to replay the game up to that point to be sure. (It is happening for sure in level 2 though (after the battle victory music). I just checked that, see below.)
2) Yep.(*) Which is a different behavior than, for example, the DOS version, where the gate would stay open indefinitely.
(*) Exception: if one of the gates opened by the special stuff that happens is the gate that would've normally been opened by the raise tile in question.
tacosalad wrote:Level 2 - Killing the second guard (I think) on the nearby door switch causes the same telltale behaviours as level 8--there's an unexplained sound of another gate opening, and the switch no longer opens the gate it should. But this one's a mystery: we never discovered what gate that had been opened, if any. In fact, killing the guard on the switch made the level harder because you could become trapped if the gate closed.
I hope you don't mind that I'm spoiling the mystery then, but it's permanently(**) opening the gate in the next room.
(**) There is a drop tile in the next room, so the left gate can be closed again, and then opened again by the 'invisible' raise button on the right.

This is the normal situation:

Image

This is when the guard dies on the raise button:

Image
tacosalad wrote:Level ? - During the 90's I used to tell people there was a third switch that exhibited this behavior, but I can't remember where it could have been.
I guess someone could play through the whole game, making sure all guards die on raise buttons. :)
Maybe I'll give it a shot and record the whole thing, I do know which gates should be closed by default...
tacosalad wrote:Anyone have access to the C-64 port?
Well, anyone can download the port and the crack.
Again, someone would have to give it a try.
Post Reply