Solution to the infamous passengers-from-nowhere bug
Moderator: Locomotion Moderators
-
- Engineer
- Posts: 65
- Joined: 09 Aug 2006 16:02
- Location: Wassenaar, the Netherlands
- Contact:
Solution to the infamous passengers-from-nowhere bug
The latest version of Loco Station Fixer, v1.2, is at the bottom of this post!
Hello everyone,
It's been a while since I posted on TT-Forums, but I'm still around! In the past few days I've searched half the forum to see if anyone has managed to fix the well-known bug that causes passengers (and also mail) to appear at what seems to be any random station in the middle of nowhere. I were surprised to find nothing on the forums (and I looked really carefully - if I just missed it, blame the search!), and I got really curious about why this is happening. So I ended up actually fixing it myself - it even turned out to be rather easy to fix.
I've read the topic about modifying Locomotion, which clearly states it's illegal to edit Loco.exe and thus to create patches for it. Luckily, I've no idea how I would actually patch the .exe.
Instead, I've written a simple 'trainer-like' patch in Java (it's a .jar file -- I lack the C skills to do the same in C, but pretty much anything on earth runs Java nowadays anyway). It just sits waiting for you to start the game, and once you do so it moves a few bytes around in the game's memory to get this bug out of existance. So, the patch doesn't change Loco.exe in any way - in fact, once you've closed the game again, absolutely nothing has changed at all. Admittedly though, strictly speaking, it does temporarily modify 3 instructions in Locomotion's code. My question is, mostly to the moderators in here, would you consider that to be an illegal program? If not, I'll be happy to share it here, of course.
Greetings,
Jerry
EDIT: Yay, I released it!
EDIT: Now also v1.2
Hello everyone,
It's been a while since I posted on TT-Forums, but I'm still around! In the past few days I've searched half the forum to see if anyone has managed to fix the well-known bug that causes passengers (and also mail) to appear at what seems to be any random station in the middle of nowhere. I were surprised to find nothing on the forums (and I looked really carefully - if I just missed it, blame the search!), and I got really curious about why this is happening. So I ended up actually fixing it myself - it even turned out to be rather easy to fix.
I've read the topic about modifying Locomotion, which clearly states it's illegal to edit Loco.exe and thus to create patches for it. Luckily, I've no idea how I would actually patch the .exe.
Instead, I've written a simple 'trainer-like' patch in Java (it's a .jar file -- I lack the C skills to do the same in C, but pretty much anything on earth runs Java nowadays anyway). It just sits waiting for you to start the game, and once you do so it moves a few bytes around in the game's memory to get this bug out of existance. So, the patch doesn't change Loco.exe in any way - in fact, once you've closed the game again, absolutely nothing has changed at all. Admittedly though, strictly speaking, it does temporarily modify 3 instructions in Locomotion's code. My question is, mostly to the moderators in here, would you consider that to be an illegal program? If not, I'll be happy to share it here, of course.
Greetings,
Jerry
EDIT: Yay, I released it!
EDIT: Now also v1.2
Last edited by Jerrythabest on 03 Mar 2012 14:34, edited 3 times in total.
Re: Solution to the infamous passengers-from-nowhere bug
Very interesting, I hope you get to release this.
Can you elaborate on why you think it happens only at certain places? I've got a scenario where large amounts of mail is generated at several, but not all 'nowhere' stations. I'm sure I've seen it with other cargos as well, in earlier games.
A fix would be very welcome, but I'd love to know why. I might then be tempted to play with it more, which may just result in me sharing a mod or two of my own some day.
Can you elaborate on why you think it happens only at certain places? I've got a scenario where large amounts of mail is generated at several, but not all 'nowhere' stations. I'm sure I've seen it with other cargos as well, in earlier games.
A fix would be very welcome, but I'd love to know why. I might then be tempted to play with it more, which may just result in me sharing a mod or two of my own some day.
-
- Engineer
- Posts: 65
- Joined: 09 Aug 2006 16:02
- Location: Wassenaar, the Netherlands
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
Well, I know exactly what goes wrong and what the game is doing, but it's very complicated to explain what is happening.
The problem is in a piece of code that produces a certain type of cargo around a house or office building (that is, everything that is not an industry) so it happens with mail too.
So, for the REALLY curious people out there, I'm going to explain what's going on. I'll take that challenge Can get a bit technical, though, so be warned.
The function that is responsible for the production of cargo around, say, a house, is called with the following arguments: the coordinates of the house, its dimensions (usually 1x1 or 2x2), and the type of cargo that must be spawned around that. For multi-tile buildings, the coordinates given should be that of the tile with the lowest coördinates (which is the northernmost tile).
The first thing the game does, is step 4 tiles back in either direction and change the dimensions to be 8 tiles wider in both directions. That's what we could call the "inverse catchment area" or so. The building is going to catch the stations around it. So, for a 1x1 tile building, the dimensions are 9x9 now.
Then, the game enters what programmers will know to be a "nested loop": the game steps through the tiles one by one, one line at a time. For this, at the start a copy is made of the coordinates and the dimension values.
In the nested loop, the tile at the current coordinates is searched for stations, the "width" value is decreased (9x9 becomes 9x8) and the X-coordinate is moved forward by one tile. This is done repeatedly until the "width" value becomes 0; so at that point the game has searched 9 sequential tiles for stations. Then, the Y-coordinate is moved forward by one tile, the "length" value is decreased, and the X-coordinate and the "width" value are reset to what they were when we created a copy of them (so, dimensions are now to 8x9: we've finished the first line).
Another line of 9 tiles is searched for stations; after that, the "length" value is decreased to 7 and so on, until it reaches zero. At that point, the game should have searched the full 9x9 tiles around the building for stations.
After this loop, a certain amount of the specified cargo is spawned at each of the stations it found.
Now that's what the function *should* be doing. Instead, as we all know, it derails completely and dumps cargo at seemingly random stations.
What happens is this: the game builds up a list of (at most 15) station numbers (which range from 0 to 1023). The list always ends in a -1 value. These numbers are stored in memory as two-byte values; the upper byte ranges from 0 to 3 depending on the station number: <255 = 0; 256 to 511 = 1; 512 to 767 = 2, 768 to 1023 = 3. The -1 value is stored as two bytes with value 255 (this is the most technical part -- google "signed vs unsigned" or something like that).
Now, when the game finds a certain station, it starts walking through the list it has built up so far and it reads out the values until it reaches either the station it has just found on the map (in which case it has already seen that station on another tile and does nothing) or the -1 value (in which case it adds this station's number to the list and moves the -1 value one slot further). The point is: when reading a value from the list, the game overwrites the dimension values it used to keep track of how many tiles it still had to check for stations!
So follow this...
The game hasn't found any stations around the building yet (so this list starts with the -1 value). As soon as it finds one (say, number #0001), it reads out this -1 value, which results in the dimensions to be set to 255x255. The game will start looking on the next 255 tiles in a row unless it finds another staton! Let's say it doesn't find one there, so at some point the dimension values reach 255x0 and the game shifts to the next line.
As the dimensions were stored before entering the nested loop, they are restored to "sane" values (i.e. 8x9). Somewhere in this line of 9 tiles, the game finds another station (with a different number than the first one, let's say this station is #0540). It again starts reading the list again, overwriting the dimension values. It first sees the other station in the list, setting the dimensions to 1x0, and then the -1 list terminator, setting the dimensions again to 255x255. So the game scans another 255 tiles from here.
Then, we end up on the third line (dimensions are now 7x9). Let's say the game finds another platform of station #0540 here. It starts reading its list again; first finding station #0001 which sets the dimensions to 1x0, then station #0540 which sets the dimensions to 28x2. Because it finds the same station again, the game immediately stops traversing the list and continues scanning tiles. As the "width" value is now 2, it will only search one more tile before it reaches 0 and jumps to the next line again. So, in this case, the game actually scans too little tiles. Thus: it won't produce cargo on any other stations in this line of tiles. That's why it doesn't happen all the time. In fact, it may even end up not producing cargo on a station that is well within the "reverse cachment area" of the building!
Now you see that it actually took me little effort to get a 100% working way to reproduce this: just build two stations in the same tile line, where one catches the building. Because of this bug, the other will get picked up while scanning tiles anyway. Now it's up to you to use this information to build a station that doesn't get any cargo from the office blocks that are standing right next to it!
I hope this was somewhere near understandable
Greetings,
Jerry
The problem is in a piece of code that produces a certain type of cargo around a house or office building (that is, everything that is not an industry) so it happens with mail too.
So, for the REALLY curious people out there, I'm going to explain what's going on. I'll take that challenge Can get a bit technical, though, so be warned.
The function that is responsible for the production of cargo around, say, a house, is called with the following arguments: the coordinates of the house, its dimensions (usually 1x1 or 2x2), and the type of cargo that must be spawned around that. For multi-tile buildings, the coordinates given should be that of the tile with the lowest coördinates (which is the northernmost tile).
The first thing the game does, is step 4 tiles back in either direction and change the dimensions to be 8 tiles wider in both directions. That's what we could call the "inverse catchment area" or so. The building is going to catch the stations around it. So, for a 1x1 tile building, the dimensions are 9x9 now.
Then, the game enters what programmers will know to be a "nested loop": the game steps through the tiles one by one, one line at a time. For this, at the start a copy is made of the coordinates and the dimension values.
In the nested loop, the tile at the current coordinates is searched for stations, the "width" value is decreased (9x9 becomes 9x8) and the X-coordinate is moved forward by one tile. This is done repeatedly until the "width" value becomes 0; so at that point the game has searched 9 sequential tiles for stations. Then, the Y-coordinate is moved forward by one tile, the "length" value is decreased, and the X-coordinate and the "width" value are reset to what they were when we created a copy of them (so, dimensions are now to 8x9: we've finished the first line).
Another line of 9 tiles is searched for stations; after that, the "length" value is decreased to 7 and so on, until it reaches zero. At that point, the game should have searched the full 9x9 tiles around the building for stations.
After this loop, a certain amount of the specified cargo is spawned at each of the stations it found.
Now that's what the function *should* be doing. Instead, as we all know, it derails completely and dumps cargo at seemingly random stations.
What happens is this: the game builds up a list of (at most 15) station numbers (which range from 0 to 1023). The list always ends in a -1 value. These numbers are stored in memory as two-byte values; the upper byte ranges from 0 to 3 depending on the station number: <255 = 0; 256 to 511 = 1; 512 to 767 = 2, 768 to 1023 = 3. The -1 value is stored as two bytes with value 255 (this is the most technical part -- google "signed vs unsigned" or something like that).
Now, when the game finds a certain station, it starts walking through the list it has built up so far and it reads out the values until it reaches either the station it has just found on the map (in which case it has already seen that station on another tile and does nothing) or the -1 value (in which case it adds this station's number to the list and moves the -1 value one slot further). The point is: when reading a value from the list, the game overwrites the dimension values it used to keep track of how many tiles it still had to check for stations!
So follow this...
The game hasn't found any stations around the building yet (so this list starts with the -1 value). As soon as it finds one (say, number #0001), it reads out this -1 value, which results in the dimensions to be set to 255x255. The game will start looking on the next 255 tiles in a row unless it finds another staton! Let's say it doesn't find one there, so at some point the dimension values reach 255x0 and the game shifts to the next line.
As the dimensions were stored before entering the nested loop, they are restored to "sane" values (i.e. 8x9). Somewhere in this line of 9 tiles, the game finds another station (with a different number than the first one, let's say this station is #0540). It again starts reading the list again, overwriting the dimension values. It first sees the other station in the list, setting the dimensions to 1x0, and then the -1 list terminator, setting the dimensions again to 255x255. So the game scans another 255 tiles from here.
Then, we end up on the third line (dimensions are now 7x9). Let's say the game finds another platform of station #0540 here. It starts reading its list again; first finding station #0001 which sets the dimensions to 1x0, then station #0540 which sets the dimensions to 28x2. Because it finds the same station again, the game immediately stops traversing the list and continues scanning tiles. As the "width" value is now 2, it will only search one more tile before it reaches 0 and jumps to the next line again. So, in this case, the game actually scans too little tiles. Thus: it won't produce cargo on any other stations in this line of tiles. That's why it doesn't happen all the time. In fact, it may even end up not producing cargo on a station that is well within the "reverse cachment area" of the building!
Now you see that it actually took me little effort to get a 100% working way to reproduce this: just build two stations in the same tile line, where one catches the building. Because of this bug, the other will get picked up while scanning tiles anyway. Now it's up to you to use this information to build a station that doesn't get any cargo from the office blocks that are standing right next to it!
I hope this was somewhere near understandable
Greetings,
Jerry
Re: Solution to the infamous passengers-from-nowhere bug
Thanx for that. It's because I've done some programming, that I was curious. So I did follow your explanation and know what an unsigned int is. I can also appreciate what a piece of detective work that must have been!
I mentioned, I thought I'd seen it with other cargo types in the past, that would have been in combo with other mods (buildings as industries) which I don't now use. But I do still see it with mail, so you've answered a long standing issue I had.
I'll certainly be using your fix, assuming you get to release it. I'll be watching this space closely. Thanx again for putting in the time and effort.
I mentioned, I thought I'd seen it with other cargo types in the past, that would have been in combo with other mods (buildings as industries) which I don't now use. But I do still see it with mail, so you've answered a long standing issue I had.
I'll certainly be using your fix, assuming you get to release it. I'll be watching this space closely. Thanx again for putting in the time and effort.
-
- Engineer
- Posts: 65
- Joined: 09 Aug 2006 16:02
- Location: Wassenaar, the Netherlands
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
So, I just tried to build a station that won't recieve the cargo that belongs to it...
Also note the insane amount of passengers I'm producing. All I did was to start the Weatherworld scenario and build one bus stop in every 3 tiles in all of the Northeastern villages. They start producing and "sharing" so much cargo that you can't possiby clear them no matter what you try.Re: Solution to the infamous passengers-from-nowhere bug
That would be a nice challengeJerrythabest wrote: They start producing and "sharing" so much cargo that you can't possiby clear them no matter what you try.
Hodie Mihi Cras Tibi
-
- Engineer
- Posts: 65
- Joined: 09 Aug 2006 16:02
- Location: Wassenaar, the Netherlands
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
WOT NO COMMENT!
I'm suprised to see no comment at all from the moderaters, who are usually so hot on "you can't mod the .exe" (rightly so, by the way, copyright'n'all that!)
Of course this approach could also be a vehicle for other bug fixes (if you can thnk of any) and for that matter game mods (to some extent) as well as bugs. After all it's a human who defines the difference!
This approach is not changing the .exe, and it sounds reasonable to me, even though as a programmer myself (in certain fields, Java not amongst them.), it is slightly alarming that anyone can change the behaviour of your hard graft. But such is digital life! That has always and will always be the case.
So come on, are we going to encourage Jerrythabest, or not?
I'm suprised to see no comment at all from the moderaters, who are usually so hot on "you can't mod the .exe" (rightly so, by the way, copyright'n'all that!)
Of course this approach could also be a vehicle for other bug fixes (if you can thnk of any) and for that matter game mods (to some extent) as well as bugs. After all it's a human who defines the difference!
This approach is not changing the .exe, and it sounds reasonable to me, even though as a programmer myself (in certain fields, Java not amongst them.), it is slightly alarming that anyone can change the behaviour of your hard graft. But such is digital life! That has always and will always be the case.
So come on, are we going to encourage Jerrythabest, or not?
- Illegal_Alien
- Tycoon
- Posts: 7824
- Joined: 29 Sep 2004 20:07
- Location: Kingdom of Far Far Away
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
If he thinks he can fix it he should. No need to encourage anyone.
:: Looking for the Locomotion section? Scroll down on the forum index or click here. :: See all releases in Locomotion section? Clicky here! :: Click here for the best tool ever! :: .datCrawler try it! ::
Following roadmap for releases: Whats a roadmap?
Releases of LocoTrains can be found by checking the posts of: LocoTrains - Goold old AMI Trains member of the first hour.
I have Private Messaging disabled, because of the stupid questions i get in my PM box.
Want to talk to me? Get on the #tycoon and #locomotion channel on OFTC thingy. :: Evolution of men: Loosing more braincells, everytime you post...
Following roadmap for releases: Whats a roadmap?
Releases of LocoTrains can be found by checking the posts of: LocoTrains - Goold old AMI Trains member of the first hour.
I have Private Messaging disabled, because of the stupid questions i get in my PM box.
Want to talk to me? Get on the #tycoon and #locomotion channel on OFTC thingy. :: Evolution of men: Loosing more braincells, everytime you post...
Re: Solution to the infamous passengers-from-nowhere bug
Good news!
T'was just that he'd asked for clarification before he released his fix.
Go Jerry... (did I just say that!)
T'was just that he'd asked for clarification before he released his fix.
Go Jerry... (did I just say that!)
- Illegal_Alien
- Tycoon
- Posts: 7824
- Joined: 29 Sep 2004 20:07
- Location: Kingdom of Far Far Away
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
I think he can speak for himself. And not some random guy saying something.
:: Looking for the Locomotion section? Scroll down on the forum index or click here. :: See all releases in Locomotion section? Clicky here! :: Click here for the best tool ever! :: .datCrawler try it! ::
Following roadmap for releases: Whats a roadmap?
Releases of LocoTrains can be found by checking the posts of: LocoTrains - Goold old AMI Trains member of the first hour.
I have Private Messaging disabled, because of the stupid questions i get in my PM box.
Want to talk to me? Get on the #tycoon and #locomotion channel on OFTC thingy. :: Evolution of men: Loosing more braincells, everytime you post...
Following roadmap for releases: Whats a roadmap?
Releases of LocoTrains can be found by checking the posts of: LocoTrains - Goold old AMI Trains member of the first hour.
I have Private Messaging disabled, because of the stupid questions i get in my PM box.
Want to talk to me? Get on the #tycoon and #locomotion channel on OFTC thingy. :: Evolution of men: Loosing more braincells, everytime you post...
-
- Engineer
- Posts: 65
- Joined: 09 Aug 2006 16:02
- Location: Wassenaar, the Netherlands
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
Well, I agree with Bit that it's somewhat disappointing to see that no TT-Forums moderator has replied on my initial question yet (whether I am allowed to release this program on the forums).
One could of course interpret this as "they don't mind, there's no problem", but I'm still rather hesitant to just post it here and see whether I make people happy or angry with it.
One could of course interpret this as "they don't mind, there's no problem", but I'm still rather hesitant to just post it here and see whether I make people happy or angry with it.
Re: Solution to the infamous passengers-from-nowhere bug
I've bought this to the attention of the other moderators and Owen. We'll let you know the outcome of our discussion.
|||| My OTTD/TTDP pics ||||Currently slighty obsessed with getting Platinum Trophies||||Retired moderator||||
-
- Engineer
- Posts: 65
- Joined: 09 Aug 2006 16:02
- Location: Wassenaar, the Netherlands
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
Hey Badger,
Thank you for taking it into consideration Hope to hear from you guys soon.
Jerry
Thank you for taking it into consideration Hope to hear from you guys soon.
Jerry
- orudge
- Administrator
- Posts: 25137
- Joined: 26 Jan 2001 20:18
- Skype: orudge
- Location: Banchory, UK
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
I see no reason not to allow this. Distributing modified binaries is one thing, distributing a program that simply modifies the program's memory is quite different, and seems fine to me.
Perhaps I'll have a think about a new wording for the "EXE editing is illegal" warning topic at some point.
Perhaps I'll have a think about a new wording for the "EXE editing is illegal" warning topic at some point.
- Illegal_Alien
- Tycoon
- Posts: 7824
- Joined: 29 Sep 2004 20:07
- Location: Kingdom of Far Far Away
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
Thank you for the quick response Now lets get some crazy stuff done (You just need to click the right buttons to get response )
:: Looking for the Locomotion section? Scroll down on the forum index or click here. :: See all releases in Locomotion section? Clicky here! :: Click here for the best tool ever! :: .datCrawler try it! ::
Following roadmap for releases: Whats a roadmap?
Releases of LocoTrains can be found by checking the posts of: LocoTrains - Goold old AMI Trains member of the first hour.
I have Private Messaging disabled, because of the stupid questions i get in my PM box.
Want to talk to me? Get on the #tycoon and #locomotion channel on OFTC thingy. :: Evolution of men: Loosing more braincells, everytime you post...
Following roadmap for releases: Whats a roadmap?
Releases of LocoTrains can be found by checking the posts of: LocoTrains - Goold old AMI Trains member of the first hour.
I have Private Messaging disabled, because of the stupid questions i get in my PM box.
Want to talk to me? Get on the #tycoon and #locomotion channel on OFTC thingy. :: Evolution of men: Loosing more braincells, everytime you post...
-
- Engineer
- Posts: 65
- Joined: 09 Aug 2006 16:02
- Location: Wassenaar, the Netherlands
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
That's great news I'll post it soon -- I'm not at home right now so I can't upload it from here
@ Illegal_Alien: Did you mean the PM button? In that case, I should've done that right away Or did you report my post as being copyright-infringing? Either way, thanks a lot
@ Illegal_Alien: Did you mean the PM button? In that case, I should've done that right away Or did you report my post as being copyright-infringing? Either way, thanks a lot
-
- Transport Coordinator
- Posts: 263
- Joined: 16 Oct 2006 22:45
Re: Solution to the infamous passengers-from-nowhere bug
In essence,m this does exactly the same process as the lsp, except it deals with the passengers in the middle of no where bug. If the two could be combined well, that would be awesome
-
- Engineer
- Posts: 65
- Joined: 09 Aug 2006 16:02
- Location: Wassenaar, the Netherlands
- Contact:
Re: Solution to the infamous passengers-from-nowhere bug
I'm not sure about the lsp, but I think it would be a good idea to incorporate more bugfixes into this program. We could make it a grand patch that solves all of earth's Locomotion's problems So if you've got any candidate bugs that need to get fixed, I could look into them of course
Re: Solution to the infamous passengers-from-nowhere bug
LSP? I did wonder whether I'd seen a similar approach for something before, but I couldn't think what to search for. Searching for LSP has given me nothing. Could you expand?
For what it's worth, I agree that in essence a combined 'Locofix' would be preferable, launched before the game in a simple batch file. (We'll be wanting mods in it next!) What's the betting one's written in C++ the other Java?
For what it's worth, I agree that in essence a combined 'Locofix' would be preferable, launched before the game in a simple batch file. (We'll be wanting mods in it next!) What's the betting one's written in C++ the other Java?
Who is online
Users browsing this forum: No registered users and 14 guests