Skip to content

Commit

Permalink
Added Scaleform support for short, byte and double types
Browse files Browse the repository at this point in the history
Fixes #190
  • Loading branch information
justalemon committed Nov 23, 2024
1 parent 3a84f59 commit 00f5f12
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions LemonUI/Scaleform/BaseScaleform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,34 @@ public BaseScaleform(string sc)

#region Tools

private static void AddInteger(int number)
{
#if FIVEM
API.ScaleformMovieMethodAddParamInt(number);
#elif ALT
Alt.Natives.ScaleformMovieMethodAddParamInt(number);
#elif RAGEMP
Invoker.Invoke(0xC3D0841A0CC546A6, number);
#elif RPH
NativeFunction.CallByHash<int>(0xC3D0841A0CC546A6, number);
#elif SHVDN3 || SHVDNC
Function.Call((Hash)0xC3D0841A0CC546A6, number);
#endif
}
private static void AddFloat(float number)
{
#if FIVEM
API.ScaleformMovieMethodAddParamFloat(number);
#elif ALTV
Alt.Natives.ScaleformMovieMethodAddParamFloat(number);
#elif RAGEMP
Invoker.Invoke(0xD69736AAE04DB51A, number);
#elif RPH
NativeFunction.CallByHash<int>(0xD69736AAE04DB51A, number);
#elif SHVDN3 || SHVDNC
Function.Call((Hash)0xD69736AAE04DB51A, number);
#endif
}
private void CallFunctionBase(string function, params object[] parameters)
{
if (function == null)
Expand Down Expand Up @@ -131,19 +159,30 @@ private void CallFunctionBase(string function, params object[] parameters)
{
throw new ArgumentNullException(nameof(parameters), "Unexpected null function argument in parameters.");
}
else if (obj is int objInt)

// Short and Byte can be converted to integer
// Double can be converted to float (while loosing precision)
// I'm not sure about long when it comes to the RAGE Engine

if (obj is int objInt)
{
#if FIVEM
API.ScaleformMovieMethodAddParamInt(objInt);
#elif ALTV
Alt.Natives.ScaleformMovieMethodAddParamInt(objInt);
#elif RAGEMP
Invoker.Invoke(0xC3D0841A0CC546A6, objInt);
#elif RPH
NativeFunction.CallByHash<int>(0xC3D0841A0CC546A6, objInt);
#elif SHVDN3 || SHVDNC
Function.Call((Hash)0xC3D0841A0CC546A6, objInt);
#endif
AddInteger(objInt);
}
else if (obj is short objShort)
{
AddInteger(objShort);
}
else if (obj is byte objByte)
{
AddInteger(objByte);
}
else if (obj is float objFloat)
{
AddFloat(objFloat);
}
else if (obj is double objDouble)
{
AddFloat((float)objDouble);
}
else if (obj is string objString)
{
Expand All @@ -160,42 +199,13 @@ private void CallFunctionBase(string function, params object[] parameters)
Invoker.Invoke(Natives.AddTextComponentSubstringPlayerName, objString);
Invoker.Invoke(Natives.EndTextCommandScaleformString);
#elif RPH

NativeFunction.CallByHash<int>(0x80338406F3475E55, "STRING");
NativeFunction.CallByHash<int>(0x6C188BE134E074AA, objString);
NativeFunction.CallByHash<int>(0x362E2D3FE93A9959);
#elif SHVDN3 || SHVDNC
Function.Call((Hash)0x80338406F3475E55, "STRING");
Function.Call((Hash)0x6C188BE134E074AA, objString);
Function.Call((Hash)0x362E2D3FE93A9959);
#endif
}
else if (obj is float objFloat)
{
#if FIVEM
API.ScaleformMovieMethodAddParamFloat(objFloat);
#elif ALTV
Alt.Natives.ScaleformMovieMethodAddParamFloat(objFloat);
#elif RAGEMP
Invoker.Invoke(0xD69736AAE04DB51A, objFloat);
#elif RPH
NativeFunction.CallByHash<int>(0xD69736AAE04DB51A, objFloat);
#elif SHVDN3 || SHVDNC
Function.Call((Hash)0xD69736AAE04DB51A, objFloat);
#endif
}
else if (obj is double objDouble)
{
#if FIVEM
API.ScaleformMovieMethodAddParamFloat((float)objDouble);
#elif ALTV
Alt.Natives.ScaleformMovieMethodAddParamFloat((float)objDouble);
#elif RAGEMP
Invoker.Invoke(0xD69736AAE04DB51A, (float)objDouble);
#elif RPH
NativeFunction.CallByHash<int>(0xD69736AAE04DB51A, (float)objDouble);
#elif SHVDN3 || SHVDNC
Function.Call((Hash)0xD69736AAE04DB51A, (float)objDouble);
#endif
}
else if (obj is bool objBool)
Expand Down

0 comments on commit 00f5f12

Please sign in to comment.