Skip to content

feat(codegen): GameEventsGenerator add FieldOverrides#1

Open
isMADAO wants to merge 2 commits intoswiftly-solution:mainfrom
isMADAO:main
Open

feat(codegen): GameEventsGenerator add FieldOverrides#1
isMADAO wants to merge 2 commits intoswiftly-solution:mainfrom
isMADAO:main

Conversation

@isMADAO
Copy link
Copy Markdown

@isMADAO isMADAO commented Apr 25, 2026

The types provided in the .gameevents files may not always match reality. We can override specific fields as needed.

I changed the hitgroup field in the player_hurt and player_death events to the HitGroup_t type. This is a breaking change and may affect existing plugins, but it's friendlier from a user-experience standpoint.

swiftly-solution/swiftlys2#307

@skuzzis
Copy link
Copy Markdown
Member

skuzzis commented Apr 25, 2026

Did you try to see if it works with plugins that still have the old API? like the plugins built with the old data types to see if it still works with the new binary

@isMADAO
Copy link
Copy Markdown
Author

isMADAO commented Apr 25, 2026

Testing in progress

@isMADAO
Copy link
Copy Markdown
Author

isMADAO commented Apr 25, 2026

plugin sw2 version

1.2.2 & 1.3.2

Test code

[GameEventHandler(HookMode.Post)]
public HookResult OnPlayerHurtPost(EventPlayerHurt eventObj)
{
    if (eventObj.UserIdPlayer is not { IsValid: true }) return HookResult.Continue;
    var pawnHealth = eventObj.UserIdPlayer.PlayerPawn!.Health;
    var eventHealth = eventObj.Health;
    Core.PlayerManager.SendChat($"OnPlayerHurtTest>> pawnHealth[{pawnHealth}], eventHealth[{eventHealth}], HitGroup[{eventObj.HitGroup}]");
    return HookResult.Continue;
}

Error

TestPlugin | 04/26 06:28:37 | Error | SwiftlyS2.Core.GameEvents.GameEventCallback
TestPlugin | Error in event player_hurt callback from context TestPlugin
System.MissingMethodException: Method not found: 'Byte SwiftlyS2.Shared.GameEventDefinitions.EventPlayerHurt.get_Health()'.
at HookResult TestPlugin.TestPlugin.OnPlayerHurtPost(EventPlayerHurt eventObj) in E:\workspace\cs2plugin\sw2-plugins\TestPlugin\src\TestPlugin.cs:72
at HookResult TestPlugin.TestPlugin.OnPlayerHurtPost(EventPlayerHurt eventObj) in E:\workspace\cs2plugin\sw2-plugins\TestPlugin\src\TestPlugin.cs:72
at HookResult SwiftlyS2.Core.GameEvents.GameEventCallback`1.<.ctor>b__9_0(uint hash, IntPtr pEvent, IntPtr pDontBroadcast) in
E:\workspace\cs2plugin\swiftlys2\managed\src\SwiftlyS2.Core\Modules\GameEvents\GameEventCallback.cs:90

Looks more serious than I thought.

@isMADAO
Copy link
Copy Markdown
Author

isMADAO commented Apr 25, 2026

Here are all my changes: isMADAO/swiftlys2@29c78f1

@skuzzis
Copy link
Copy Markdown
Member

skuzzis commented Apr 25, 2026

yeah, i understand that, the issue is that we need to keep compatibility with the old code, maybe add new methods to act like how you want, but with a new name, something like HealthInt

@skuzzis
Copy link
Copy Markdown
Member

skuzzis commented Apr 25, 2026

instead of replacing the old ones

@isMADAO
Copy link
Copy Markdown
Author

isMADAO commented Apr 26, 2026

If it were only special schema types like HitGroup_t, I'd be fine with either keeping the old byte type or adding a new method to access it, because both can correctly represent the parameter value. But for parameters like health and armor, their original types can no longer correctly hold the parameter value — and this might only be a subset of the affected parameters. If we add an extra accessor method for every single one of them just to get the value correctly, I think it would bloat the framework and be somewhat misleading.

@skuzzis
Copy link
Copy Markdown
Member

skuzzis commented Apr 26, 2026

you can add a new method, and i think the name would be the original name + Typed

@isMADAO
Copy link
Copy Markdown
Author

isMADAO commented Apr 26, 2026

Adding new methods would preserve compatibility, but as I said, it would bloat the framework. And the overridden field types are simply wrong — for something like health, the byte-typed version really shouldn't stick around. I think it'd be worth starting a discussion on Discord to get other developers' opinions. For most plugins using the affected game events, all that's needed is recompiling against the new version of SW2. If we're going to drop the old ones, we should at least do a full pass over the commonly used game events and ship a reasonably complete set of fixes — or add a separate custom game-event class module, mark the old versions as deprecated, and remove them in a future release.

@isMADAO
Copy link
Copy Markdown
Author

isMADAO commented Apr 26, 2026

https://discord.com/channels/1419042580980699159/1421117496169074719/1497902943935008799
I've switched to generating the code by adding new fields instead of modifying the type of the existing ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants