-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
patch spawn/despawn vehicle using new harmony #864
Comments
if CustomSpawn is copy of the original method then we we should replace CustomSpawn with the harmony patch. |
No quick way. I think we have to read carefully about these codes and find out the difference. |
But the original code was also copy pasted from decompiler why should it be so hard to compare decompiler code with decompiler code? There is a shit ton of code out there so any automation we develop could be useful and reduce the risk of human error |
Seems I spotted that some time ago: #462 I think it would be very useful for TMPE to know when vehicles spawn/unspawn (no idea which is best approach for that). For example, if we eventually start reserving parking spaces for vehicles, we will need to know if they despawn unexpectedly so we can un-reserve their parking space. We could also maybe detect many vehicles despawning at same location = likely broken node bug (or at least we could stack trace to get some idea of the code path that led to despawning). |
@aubergine10 we already receive notification when vehicle spawn/despawns using redirection. I am saying we are now able to do it with harmony |
@aubergine10 There is only one line of custom code (functionally speaking) the method is recursive so where the original code calls Spawn, the redirected method calls custom spawn. so its equivalent. All we need to do is a post fix (which is what I suspect from almost every custom AI) EDIT: It is going to feel really good deleting a shit ton of code. maybe keep the original as text since the code is easier to read than the de-compiler? |
I don't think we should keep the original tbh, as it will go stale if base game gets updated. Hopefully if we're just doing postfixes on |
then why do we keep
|
Re: BTW, I looking at the code in screenshots above, note that there are two different call contexts:
So I think we need two postfixes? One for the vanilla |
@aubergine10 no. only one change (unless if I am making a mistake)
Note that on the left there is an equivalent recursive call for vehicle and each trailer (if applicable) - ie. it can be called more than once per invocation of parent method. So this line provides no new logic and does not need to be patched. Actually It would have made no difference if this line called |
Based on the current way the code works: Let say vehicle has 2 trailers. That's 3 times So I don't see how we can replicate that with only one patch around the vanilla Unless the plan is to call The current way it works, |
More clarity: If there is a truck with 2 trailers attached, TMPE will currently see:
|
I think you are wrong. You are confused about how recursive calls work. in the custom code CustomSpawn() // truck
CustomSpawn() // trailer 1
OnSpawnVehicle() // trailer 1
CustomSpawn() // trailer 2
OnSpawnVehicle() // trailer 2
OnSpawnVehicle() // truck EDIT: This is what happens if the truck has 4 trailers: |
Ah, the parent method is Bah, there's actually two loops that contain recursive spawn. The more I look at the vanilla As far as I know, there's never anything that has side-vehicles or vertical trailers. Assuming it's always a start vehicle followed by zero or more trailers, it should be possible to just to create and configure those vehicles with a few simple iterations without going recursive and thus reduce call stack and gc. |
Ok, so there are some wierd vehicle configs that require that extra code in the vanilla Spawn() methods. So yeah, there's no need for TMPE to replicate those methods, just postfix the event. Earlier I didn't realise it was recursive method (snippets in images didn't show what the parent method was) hence confusion. |
#864 replaced CustomVehicle redirection with harmony patches.
damn I fixed this ages ago! |
TMPE is now harmony only. |
this code is commented out:
TMPE/TLM/TLM/Patch/_Vehicle/SpawnPatch.cs
Line 12 in 37b71da
TMPE/TLM/TLM/Patch/_Vehicle/UnspawnPatch.cs
Line 12 in 37b71da
Once I moved to harmony 2 should we uncomment this?
VehicleStateManager
no longer exists but we can callOnSpawnVehicle();
instead. that method is already being called fromCustomVehicle.CustomSpawn()
so maybe I should deleteVehicle.Spawn/DespawnPatch
The text was updated successfully, but these errors were encountered: