[Free] [Release] [C#] FXEvents a dynamic advanced event subsystem for FiveM

FxEvents an advanced event subsystem for FiveM

A C# advanced library to handle Events and Callbacks both client ↔ server

With FxEvents you can send and request strongly typized values between client and server using an advanced event handling process.
Signatures for each client are encrypted and using the provided binary serialization to it’s 2x times faster than Newtonsoft.Json, also you can hide event values from malicious clients!

To make it work you only need to add FXEvents.Client.dll or FXEvents.Server.dll and Newtonsoft.Json.dll (In case of json serialization) to your resource.
No need of any external library for binary serialization, the event system uses the internal MsgPack.dll provided with fivem itself!!

GitHub Page: GitHub - manups4e/FxEvents: An advanced event subsystem for FiveM
Download: Release First public release · manups4e/FxEvents · GitHub

Usage examples:

To Debug your resource:

To debug simply add this line in your resource fxmanifest.lua, FXEvents will debug your events and callbacks, displaying the time (milliseconds) they take to complete.

fxevents_debug_mode 'true'

:warning: Remember to remove or comment this line in production!

To mount an event:

// It can be declared also as normal events EventDispatcher.Mount("eventName", new Action<ISource, type1, type2>(MyMethod));
// public void MyMethod(ISource param, type1 param1, type2 param2) { ...code }
EventDispatcher.Mount("eventName", new Action<ISource, type1, type2>((source, val1, val2) =>    
{
  // code to be used inside the event.
  // ISource is the optional Interface provided that handles clients triggering the event.. is like the "[FromSource] Player player" parameter but can be derived and handled as you want! So you can directly load any User / Player / Client / whatever type that handles the player for you!
  // Clientside is the same thing without the ISource parameter
}));

To trigger an event

The library only works in client ↔ server communication… for the moment same side events are not working but the feature will be added in the future!

// clientside
EventDispatcher.Send("eventName", params);

// serverside
EventDispatcher.Send(Player, "eventName", params);
EventDispatcher.Send(List<Player>, "eventName", params);
EventDispatcher.Send(ISource, "eventName", params);
EventDispatcher.Send(List<ISource>, "eventName", params);

To trigger a callback

Mounting it

EventDispatcher.Mount("eventName", new Func<ISource, type1, type2, Task<returnType>>(async (source, val1, val2) =>    
{
  // code to be used inside the event.
  // ISource is the optional Interface provided that handles clients triggering the event.. is like the "[FromSource] Player player" parameter but can be derived and handled as you want! So you can directly load any User / Player / Client / whatever type that handles the player for you!
  // Clientside is the same thing without the ClientId parameter
  return val3
}));

Calling it

// clientside
type param = await EventDispatcher.Get<type>("eventName", params);

// serverside
type param = await EventDispatcher.Get<type>(ClientId, "eventName", params);
type param = await EventDispatcher.Get<type>(Player, "eventName", params);

Callbacks can be called serverside too because it might happen that the server needs info from certain clients and this will help you doing it.

The library comes with some goodies to help with customization and debugging serialization printing.

ToJson()

image

:warning: You need Newtonsoft.Json to make this work!!

string text = param.ToJson();

FromJson()

:warning: You need Newtonsoft.Json to make this work!!

type value = jsonText.FromJson<type>();

ToBytes()

byte[] bytes = param.ToBytes();

FromBytes()

type value = bytes.FromBytes<type>();

BytesToString

image

byte[] bytes = param.ToBytes();
string txt = bytes.BytesToString();

StringToBytes

byte[] bytes = txt.StringToBytes();
type value = bytes.FromBytes<type>();

FXEvents comes also with a Logger class that can be used to give “Info”, “Debug”, “Warning”, “Error” and “Fatal” messages.



FxEvents has reached its 3.0.0 version and it’s gonna bring most of the V2 features into mono V1 + extras.

Features:

  • New EventHub Class: Streamline your event management with our newly introduced EventHub class.
  • Enhanced Encryption:
    • Internally: Improved encryption between Client and Server using robust public/private key mechanisms.
    • Externally: Updated public API methods featuring SHA-256 encryption for enhanced security.
  • Advanced Event Management: Experience a new event management system that emulates the functionality of V2, without the previous bugs.
  • Event Attributes: Simplify event and callback definitions using the [FxEvent("Event name")] attribute.
  • Optimized Callback Handling: Enjoy faster response times with enhanced callback handling, allowing callbacks from Server to Client and back as an extra.
  • Improved Serialization: Updated MsgPack serialization code enhances performance and reduces binary data size.
  • Native ValueTuple Support: Full native support for ValueTuple in .NET Framework, eliminating the need for external NuGet libraries and enabling MsgPack serialization.
  • New EventHub initialization : Initializing EventHub now only requires you to call Initialize() method without parameters… encrypted event parameters are now SHA-256 encrypted based on resource name

Features taken from mono V2:

  • Introduced MsgPack native internal type conversion (thanks @thorium for your MsgPack and dedication to us… you’re the only element that deserved my respect)
  • Introduced mono V2 event binding
    • FxEvent attribute binds to All by default and can be changed in attribute constructor
    • EventDispatcher legacy Mount method binds automatically to All
    • EventHub Mount method requires to choose a binding
  • Introduced a basic Anti-Tamper system that uses a server event (fxevents:tamperingprotection) with parameters [source, endpoint, TamperType]
    • TamperType can be
      • REPEATED_MESSAGE_ID: someone tried to send the same event or a new event with an used ID
      • EDITED_ENCRYPTED_DATA: someone altered the encrypted data trying to change values making it impossible to decrypt
      • REQUESTED_NEW_PUBLIC_KEY: a client tried to request a new ID to change the encryption and thus edit the encryption

Some pictures:

As you can see GimmeAll2 and Gimmeall5 are not called as the event triggered is a local event.
Binding makes it so Remote events are only available to client/server communication and Local events only to same side communication while All is available to both and None makes the event invisible to any call possible.
Same approach applies to callbacks but only 1 can be registered.

Some neat internal conversion to handle your events and encryption the most fluid as possible.
:warning: Beware: if a conversion can’t be made, a throw is launched to avoid data corruption!

Code is accessible Yes
Subscription-based No
Lines (approximately) a lot but never enough
Requirements Client: .Net Framework 4.5.2 / Server: .Net Standard 2.0
Support Yes

A huge thanks to @lacoL for being a friend in the toughest of times :heart:

12 Likes

Very nice Resource! Thanks for your Release and your hard work! :heart:

1 Like

thanks :slight_smile:

buon lavoro! Will take a look at this when im done with my script.

Thanks ahahah

1 Like

Awesome thanks!

Updated to Version 2.1
Changelog: Fixed a bug on Server → Client → Server callbacks where the task was completed but not awaited causing a security critical error.

Updated to Version 2.2
Changelog: Comparing 2.1...2.2 · manups4e/FxEvents · GitHub

I know… i forgot to update the thread for all the new versions available… let me add a post for this next and maybe final version of FXEvents for mono V1

Why is this new version being released?

In our previous release, we promised a final version of our library. However, we have since added new features that we believe will greatly enhance the functionality and security of our library. This new release introduces encryption features to our library, enabling a higher level of data protection.

What’s new in this release?

We have added SHA256 encryption to the events system to ensure the “non-reversibility” of data sent in events. This means that once data has been sent, it cannot be easily reversed or altered.

The Initialize method now includes a new parameter: the encryption key. This key can be any string you choose, such as a password or a long number. You can generate a random password using the generatekey command on the server console. This key can then be used as the encryption key.

It’s important to note that FXEvents will not save the encrypted key anywhere. It’s your responsibility to store it securely and pass it to clients as necessary.

How to use the new encryption features

Here’s an example of how to use the new encryption features:

image

We’ve also added two new extension methods to the library:

  • void EncryptObject<T>(string passkey)
  • T DecryptObject<T>(string passkey)
    These methods serialize your instanced objects internally into binary code and then encrypt those very bytes with SHA256 encryption, so you won’t need to serialize before encrypting. Same thing for decryption.
    The passkey parameter is used to give you the flexibility to encrypt/decrypt with any key you want, as long as the keys are the same for encryption/decryption.
    These methods are also used with the initialized key internally to ensure events encryption.

What’s Changed

New Contributors

Full Changelog: Comparing 2.5...2.6 · manups4e/FxEvents · GitHub

You can download the released library on github or wait for the Nuget update :slight_smile:

it’s been a while… but we’re back!
A lot of things happened… but we’re still here doing our best in Mono V1 because we’re too lazy to convert to V2.
Fear no more!
FxEvents is updating to its 3.0.0 version and it’s gonna bring most of the V2 features into mono V1 + extras.

Features:

  • New EventHub Class: Streamline your event management with our newly introduced EventHub class.
  • Enhanced Encryption:
    • Internally: Improved encryption between Client and Server using robust public/private key mechanisms.
    • Externally: Updated public API methods featuring SHA-256 encryption for enhanced security.
  • Advanced Event Management: Experience a new event management system that emulates the functionality of V2, without the previous bugs.
  • Event Attributes: Simplify event and callback definitions using the [FxEvent("Event name")] attribute.
  • Optimized Callback Handling: Enjoy faster response times with enhanced callback handling, allowing callbacks from Server to Client and back as an extra.
  • Improved Serialization: Updated MsgPack serialization code enhances performance and reduces binary data size.
  • Native ValueTuple Support: Full native support for ValueTuple in .NET Framework, eliminating the need for external NuGet libraries and enabling MsgPack serialization.
  • New EventHub initialization : Initializing EventHub now only requires you to call Initialize() method without parameters… encrypted event parameters are now SHA-256 encrypted based on resource name

Features taken from mono V2:

  • Introduced MsgPack native internal type conversion (thanks @thorium for your MsgPack and dedication to us… you’re the only element that deserved my respect at this time)
  • Introduced mono V2 event binding
    • FxEvent attribute binds to All by default and can be changed in attribute constructor
    • EventDispatcher legacy Mount method binds automatically to All
    • EventHub Mount method requires to choose a binding
  • Introduced a basic Anti-Tamper system that uses a server event (fxevents:tamperingprotection) with parameters [source, endpoint, TamperType]
    • TamperType can be
      • REPEATED_MESSAGE_ID: someone tried to send the same event or a new event with an used ID
      • EDITED_ENCRYPTED_DATA: someone altered the encrypted data trying to change values making it impossible to decrypt
      • REQUESTED_NEW_PUBLIC_KEY: a client tried to request a new ID to change the encryption and thus edit the encryption

Some pictures:


As you can see GimmeAll2 and Gimmeall5 are not called as the event triggered is a local event.
Binding makes it so Remote events are only available to client/server communication and Local events only to same side communication while All is available to both and None makes the event invisible to any call possible.
Same approach applies to callbacks but only 1 can be registered.


Some neat internal conversion to handle your events and encryption the most fluid as possible.
:warning: Beware: if a conversion can’t be made, a throw is launched to avoid data corruption!


Wanna try it?
Find me on discord read my profile and join my awesome family! You’ll find the FxEvents forum post with the 3.0.0 RC3 release to test!
We’re near to the nuget release! :smiley:

FxEvents v3.0.1 is finally released!!
You can find it on Nuget or download it from here: manups4e (Manu) / Packages · GitHub