Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Tue Oct 16, 2018 1:21 pm

All times are UTC




Post new topic  Reply to topic  [ 61 posts ]  Go to page 1 2 3 4 Next
Author Message
PostPosted: Wed Feb 15, 2012 10:31 pm 
Offline
Engineer
Engineer

Joined: Wed Aug 09, 2006 4:02 pm
Posts: 65
Location: Wassenaar, the Netherlands
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.
Attachment:
File comment: The bug in full force! To reproduce: 1) build a station near houses, 2) make sure the map points North, 3) follow the row of tiles to the lower right (SE) until you're in the middle of nowhere, 4) build another station at this same row of tiles.
bug.png [483.57 KiB]
Downloaded 4 times

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.
Attachment:
File comment: A screenshot of the program waiting for Locomotion to start up.
screenshot.png
screenshot.png [ 12.67 KiB | Viewed 4495 times ]

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 ;)
Attachment:
File comment: Loco Station Fixer v1.2!
From the Changelog:
2012-03-03 1.2
- Loco Station Fixer is now compatible with the Long Station Patch.
- If you run Loco Station Fixer a second time, it will now detect that the game
is already patched.

Locomotion Station Fixer v1.2.zip [1.18 MiB]
Downloaded 154 times


Last edited by Jerrythabest on Sat Mar 03, 2012 2:34 pm, edited 3 times in total.

Top
   
PostPosted: Wed Feb 22, 2012 3:00 am 
Offline
Engineer
Engineer

Joined: Fri Jul 09, 2010 11:21 am
Posts: 18
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.


Top
   
PostPosted: Wed Feb 22, 2012 7:55 pm 
Offline
Engineer
Engineer

Joined: Wed Aug 09, 2006 4:02 pm
Posts: 65
Location: Wassenaar, the Netherlands
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 :lol: 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


Top
   
PostPosted: Wed Feb 22, 2012 11:44 pm 
Offline
Engineer
Engineer

Joined: Fri Jul 09, 2010 11:21 am
Posts: 18
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.


Top
   
PostPosted: Fri Feb 24, 2012 3:17 pm 
Offline
Engineer
Engineer

Joined: Wed Aug 09, 2006 4:02 pm
Posts: 65
Location: Wassenaar, the Netherlands
So, I just tried to build a station that won't recieve the cargo that belongs to it...
Attachment:
File comment: A station that won't get its cargo because of the same bug. To reproduce: 1) Build at least 256 stations elsewhere, 2) make sure the map points North, 3) build two platforms/bus stops for the same station in a line from NW to SE, 4) build another station in the same line. As long as all nearby buildings catch all 3 platforms/stops, the last one won't get any cargo.
bug-no_cargo.png [692.36 KiB]
Downloaded 4 times
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.


Top
   
PostPosted: Sat Feb 25, 2012 10:09 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Tue Dec 02, 2003 4:01 pm
Posts: 2109
Location: Belgium
Jerrythabest wrote:
They start producing and "sharing" so much cargo that you can't possiby clear them no matter what you try.

That would be a nice challenge :D

_________________
Hodie Mihi Cras Tibi


Top
   
PostPosted: Sat Feb 25, 2012 7:14 pm 
Offline
Engineer
Engineer

Joined: Wed Aug 09, 2006 4:02 pm
Posts: 65
Location: Wassenaar, the Netherlands
Here, try it ;)
Attachment:
busy stations.SV5 [1.32 MiB]
Downloaded 145 times


Top
   
PostPosted: Tue Feb 28, 2012 8:29 pm 
Offline
Engineer
Engineer

Joined: Fri Jul 09, 2010 11:21 am
Posts: 18
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?


Top
   
PostPosted: Tue Feb 28, 2012 9:08 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Sep 29, 2004 8:07 pm
Posts: 7822
Location: Kingdom of Far Far Away
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...


Top
   
PostPosted: Tue Feb 28, 2012 9:24 pm 
Offline
Engineer
Engineer

Joined: Fri Jul 09, 2010 11:21 am
Posts: 18
Good news!

T'was just that he'd asked for clarification before he released his fix.

Go Jerry... (did I just say that!)


Top
   
PostPosted: Tue Feb 28, 2012 9:58 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Sep 29, 2004 8:07 pm
Posts: 7822
Location: Kingdom of Far Far Away
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...


Top
   
PostPosted: Tue Feb 28, 2012 10:19 pm 
Offline
Engineer
Engineer

Joined: Wed Aug 09, 2006 4:02 pm
Posts: 65
Location: Wassenaar, the Netherlands
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.


Top
   
PostPosted: Tue Feb 28, 2012 10:31 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sun Sep 10, 2006 7:12 pm
Posts: 6999
Location: Adwick-Le-Street.
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||||


Top
   
PostPosted: Tue Feb 28, 2012 10:40 pm 
Offline
Engineer
Engineer

Joined: Wed Aug 09, 2006 4:02 pm
Posts: 65
Location: Wassenaar, the Netherlands
Hey Badger,

Thank you for taking it into consideration :D Hope to hear from you guys soon.

Jerry


Top
   
PostPosted: Tue Feb 28, 2012 10:41 pm 
Offline
Administrator
Administrator
User avatar

Joined: Fri Jan 26, 2001 8:18 pm
Posts: 23877
Skype: orudge
Location: Banchory, UK
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.

_________________
Owen Rudge
owenrudge.net | Owen's Transport Tycoon Station | Owen's Locomotion Depot | The Transport Tycoon Wiki


Top
   
PostPosted: Tue Feb 28, 2012 10:59 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Sep 29, 2004 8:07 pm
Posts: 7822
Location: Kingdom of Far Far Away
Thank you for the quick response :) Now lets get some crazy stuff done :) (You just need to click the right buttons to get response :P)

_________________
:: 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...


Top
   
PostPosted: Wed Feb 29, 2012 7:52 am 
Offline
Engineer
Engineer

Joined: Wed Aug 09, 2006 4:02 pm
Posts: 65
Location: Wassenaar, the Netherlands
That's great news :D I'll post it soon -- I'm not at home right now so I can't upload it from here :wink:

@ Illegal_Alien: Did you mean the PM button? In that case, I should've done that right away :P Or did you report my post as being copyright-infringing? :twisted: Either way, thanks a lot :p


Top
   
PostPosted: Wed Feb 29, 2012 11:26 am 
Offline
Transport Coordinator
Transport Coordinator

Joined: Mon Oct 16, 2006 10:45 pm
Posts: 263
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 :D


Top
   
PostPosted: Wed Feb 29, 2012 3:33 pm 
Offline
Engineer
Engineer

Joined: Wed Aug 09, 2006 4:02 pm
Posts: 65
Location: Wassenaar, the Netherlands
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 ;)


Top
   
PostPosted: Wed Feb 29, 2012 4:01 pm 
Offline
Engineer
Engineer

Joined: Fri Jul 09, 2010 11:21 am
Posts: 18
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?


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 61 posts ]  Go to page 1 2 3 4 Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.