sschoener / cities-skylines-detour

Proof of concept for a simple detour for functions in Cities: Skylines (or more generally: Unity 5 x64 on Windows.)
MIT License
84 stars 9 forks source link

Patching of some methods does not appar to work. #1

Closed mabako closed 9 years ago

mabako commented 9 years ago

Hey!

I've been using this for a while and it's been mostly just been great.

However, the following two methods I've tried patching (currently if false'd), and when I tried enabling them (albeit they're copied out from dotPeek 1:1) they do not work:

https://github.com/mabako/cities-skylines-unlimiter/blob/master/Zones/FakeZoneBlock.cs#L200 https://github.com/mabako/cities-skylines-unlimiter/blob/master/Zones/FakeBuilding.cs#L14

Do you have any idea why this is? Any help would be greatly appreciated.

sschoener commented 9 years ago

Hi, what exactly do you mean by they do not work? Does it crash the game? Or does the game stop upgrading buildings? Have you tried adding logging to see whether the patched method is called at all?

mabako commented 9 years ago

Placing new zones or removing existing zones has no effect, so you can unzone your whole city and all buildings persist. Likewise, zoned areas without buildings will never spawn buildings.

sschoener commented 9 years ago

But your patch code is called?

mabako commented 9 years ago

If I add Unity's Application.Quit() as the first line of either function, it's quitting Cities: Skylines, so I'm fairly sure it calls my code.

sschoener commented 9 years ago

Good, then it should not be a problem with the patching. I unfortunately cannot help you with problems concerning the game logic.

mabako commented 9 years ago

Is there perhaps any difference in how C# calls struct methods? Both ZoneBlock and Building seem to be structs.

sschoener commented 9 years ago

None that I know of. If the detour is called and its arguments are sensible, then I do not see how this could be related to the redirection. There are all sorts of things that can go wrong when patching in your custom code, but if the patching fails, your game will crash in 99.9% of the cases. If it was related to structs, then all the other methods that you are patching within that struct should show similar errors. I do not have the time to go over the whole of your code and check that you do not mess with the game data in bad ways, but I suspect that the error is to be found there.

mabako commented 9 years ago

Fixed it by replacing the methods which called said struct methods, instead of replacing the struct methods directly. Not sure that's how it should be, but hey ho.