Improving the event transpiling/patching system a bit
Fixed the following issues:
Classes annotated with multiple EventPatch attributes were getting their patches applied twice with dynamic patching
EventTranspilerInjector.InjectDeniableEvent was generating the wrong IL code for the existing player events
Broke up the method into internal sub methods (planned to be used for CodeMatcher extensions as well
Properly copy labels onto new instruction so branching is preserved
The CriticallyInjure and Healing events were not being transpiled correctly
They now emit correctly when being critically injured and healed back from critical
Event Example
Given the following handlers:
Events.Handlers.Player.CriticallyInjure += @event =>
{
Log.Info($"Player {@event.Player.playerUsername} is being critically injured.");
Log.Info($"Health: {@event.Player.health}");
};
Events.Handlers.Player.Healing += @event =>
{
Log.Info($"Player {@event.Player.playerUsername} is being healed.");
Log.Info($"Health: {@event.Player.health}");
};
We see the following output when taking damage which drops health below 10:
[11/18/2023 1:54 AM (08.339s)] [Info] [LethalAPI.Core] Player dhkatz is being critically injured.
[11/18/2023 1:54 AM (08.342s)] [Info] [LethalAPI.Core] Health: 5
After waiting a bit we are healed back up to 20 and are no longer critically injured:
[11/18/2023 1:54 AM (22.575s)] [Info] [LethalAPI.Core] Player dhkatz is being healed.
[11/18/2023 1:54 AM (22.579s)] [Info] [LethalAPI.Core] Health: 20
Improving the event transpiling/patching system a bit
Fixed the following issues:
EventPatch
attributes were getting their patches applied twice with dynamic patchingEventTranspilerInjector.InjectDeniableEvent
was generating the wrong IL code for the existing player eventsCodeMatcher
extensions as wellCriticallyInjure
andHealing
events were not being transpiled correctlyEvent Example
Given the following handlers:
We see the following output when taking damage which drops health below 10:
After waiting a bit we are healed back up to 20 and are no longer critically injured: