2022-06-23 09:46:38 +08:00
using System ;
using System.Collections.Generic ;
using System.Text ;
using System.Security.Cryptography ;
namespace RageCoop.Core.Scripting
{
/// <summary>
///
/// </summary>
public static class CustomEvents
{
static MD5 Hasher = MD5 . Create ( ) ;
static Dictionary < int , string > Hashed = new Dictionary < int , string > ( ) ;
2022-07-01 14:39:43 +08:00
internal static readonly int SetWeather = Hash ( "RageCoop.SetWeather" ) ;
2022-07-01 19:02:38 +08:00
internal static readonly int OnPedDeleted = Hash ( "RageCoop.OnPedDeleted" ) ;
internal static readonly int OnVehicleDeleted = Hash ( "RageCoop.OnVehicleDeleted" ) ;
2022-07-01 14:39:43 +08:00
internal static readonly int SetAutoRespawn = Hash ( "RageCoop.SetAutoRespawn" ) ;
2022-07-03 10:46:24 +08:00
internal static readonly int SetDisplayNameTag = Hash ( "RageCoop.SetDisplayNameTag" ) ;
2022-07-01 14:39:43 +08:00
internal static readonly int NativeCall = Hash ( "RageCoop.NativeCall" ) ;
internal static readonly int NativeResponse = Hash ( "RageCoop.NativeResponse" ) ;
internal static readonly int AllResourcesSent = Hash ( "RageCoop.AllResourcesSent" ) ;
2022-07-02 17:14:56 +08:00
internal static readonly int ServerPropSync = Hash ( "RageCoop.ServerPropSync" ) ;
2022-07-03 15:28:28 +08:00
internal static readonly int ServerBlipSync = Hash ( "RageCoop.ServerBlipSync" ) ;
2022-07-03 10:46:24 +08:00
internal static readonly int SetEntity = Hash ( "RageCoop.SetEntity" ) ;
2022-07-02 17:14:56 +08:00
internal static readonly int DeleteServerProp = Hash ( "RageCoop.DeleteServerProp" ) ;
2022-07-03 10:46:24 +08:00
internal static readonly int DeleteEntity = Hash ( "RageCoop.DeleteEntity" ) ;
2022-07-03 15:28:28 +08:00
internal static readonly int DeleteServerBlip = Hash ( "RageCoop.DeleteServerBlip" ) ;
2022-07-04 21:29:13 +08:00
internal static readonly int CreateVehicle = Hash ( "RageCoop.CreateVehicle" ) ;
2022-06-23 09:46:38 +08:00
/// <summary>
/// Get a Int32 hash of a string.
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
/// <exception cref="ArgumentException">The exception is thrown when the name did not match a previously computed one and the hash was the same.</exception>
public static int Hash ( string s )
{
var hash = BitConverter . ToInt32 ( Hasher . ComputeHash ( Encoding . UTF8 . GetBytes ( s ) ) , 0 ) ;
string name ;
lock ( Hashed )
{
if ( Hashed . TryGetValue ( hash , out name ) )
{
if ( name ! = s )
{
throw new ArgumentException ( $"Hashed value has collision with another name:{name}, hashed value:{hash}" ) ;
}
else
{
return hash ;
}
}
else
{
Hashed . Add ( hash , s ) ;
return hash ;
}
}
}
}
}