From 77dc787c4baa17859534639df8c823de46ae089c Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 04:30:22 -0300 Subject: [PATCH 01/10] Added basics of the Bink Video class --- LemonUI/Elements/ScaledBink.cs | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 LemonUI/Elements/ScaledBink.cs diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs new file mode 100644 index 0000000..9e723f9 --- /dev/null +++ b/LemonUI/Elements/ScaledBink.cs @@ -0,0 +1,67 @@ +#if ALTV +using AltV.Net.Client; +#elif FIVEM +using CitizenFX.Core.Native; +#elif RAGEMP +using RAGE.Game; +#elif RPH +using Rage.Native; +#elif SHVDN3 || SHVDNC +using GTA.Native; +#endif +using System; +using System.Drawing; + +namespace LemonUI.Elements +{ + /// + /// A Bink Video file. + /// + public class ScaledBink : BaseElement + { + #region Fields + + private string name = string.Empty; + private int id = 0; + + #endregion + + #region Constructors + + /// + /// Creates a new Bink Video playback. + /// + /// The name of the bik file. + /// The position of the video window. + /// The size of the video window. + public ScaledBink(string name, PointF pos, SizeF size) : base(pos, size) + { + this.name = name ?? throw new ArgumentNullException(nameof(name)); + +#if ALTV + id = Alt.Natives.SetBinkMovie(name); +#elif FIVEM + id = API.SetBinkMovie(name); +#elif RAGEMP + id = Invoker.Invoke(0xfc36643f7a64338f, name); +#elif RPH + id = NativeFunction.CallByHash(0xfc36643f7a64338f, name); +#elif SHVDN3 || SHVDNC + id = Function.Call(Hash.SET_BINK_MOVIE, name); +#endif + } + + #endregion + + #region Functions + + /// + /// Draws the Bink Movie at the specified location. + /// + public override void Draw() + { + } + + #endregion + } +} From 48e4a6119beea03f0a6f4946f6df370c650a64f5 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 15:42:25 -0300 Subject: [PATCH 02/10] Added extra constructor to skip the position and size --- LemonUI/Elements/ScaledBink.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs index 9e723f9..22cd4df 100644 --- a/LemonUI/Elements/ScaledBink.cs +++ b/LemonUI/Elements/ScaledBink.cs @@ -28,6 +28,13 @@ public class ScaledBink : BaseElement #region Constructors + /// + /// Creates a new Bink Video playback. + /// + /// The name of the bik file. + public ScaledBink(string name) : this(name, PointF.Empty, SizeF.Empty) + { + } /// /// Creates a new Bink Video playback. /// From c19b372ac00b4a6ac845b9f992060298dfaa62bb Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 15:43:15 -0300 Subject: [PATCH 03/10] Make sure to properly calculate the position from the center --- LemonUI/Elements/ScaledBink.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs index 22cd4df..6aed18e 100644 --- a/LemonUI/Elements/ScaledBink.cs +++ b/LemonUI/Elements/ScaledBink.cs @@ -68,6 +68,13 @@ public ScaledBink(string name, PointF pos, SizeF size) : base(pos, size) public override void Draw() { } + /// + public override void Recalculate() + { + base.Recalculate(); + relativePosition.X += relativeSize.Width * 0.5f; + relativePosition.Y += relativeSize.Height * 0.5f; + } #endregion } From 392957c7496447be4e2e9b50749af0ad42dfd863 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 15:43:27 -0300 Subject: [PATCH 04/10] Added drawing calls for Bink --- LemonUI/Elements/ScaledBink.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs index 6aed18e..b25a111 100644 --- a/LemonUI/Elements/ScaledBink.cs +++ b/LemonUI/Elements/ScaledBink.cs @@ -67,6 +67,22 @@ public ScaledBink(string name, PointF pos, SizeF size) : base(pos, size) /// public override void Draw() { +#if ALTV + Alt.Natives.PlayBinkMovie(id); + Alt.Natives.DrawBinkMovie(id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); +#elif FIVEM + API.PlayBinkMovie(id); + API.DrawBinkMovie(id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); +#elif RAGEMP + Invoker.Invoke(0xE178310643033958, id); + Invoker.Invoke(0x7118E83EEB9F7238, id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); +#elif RPH + NativeFunction.CallByHash(0xE178310643033958, id); + NativeFunction.CallByHash(0x7118E83EEB9F7238, id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); +#elif SHVDN3 || SHVDNC + Function.Call(Hash.PLAY_BINK_MOVIE, id); + Function.Call(Hash.DRAW_BINK_MOVIE, id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); +#endif } /// public override void Recalculate() From 9467f7e67e95b51291018de4bf13cf1a03b85594 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 15:45:23 -0300 Subject: [PATCH 05/10] Added extra constructor to skip the position of the bink video --- LemonUI/Elements/ScaledBink.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs index b25a111..dfd2570 100644 --- a/LemonUI/Elements/ScaledBink.cs +++ b/LemonUI/Elements/ScaledBink.cs @@ -39,6 +39,14 @@ public ScaledBink(string name) : this(name, PointF.Empty, SizeF.Empty) /// Creates a new Bink Video playback. /// /// The name of the bik file. + /// The size of the video window. + public ScaledBink(string name, SizeF size) : this(name, PointF.Empty, size) + { + } + /// + /// Creates a new Bink Video playback. + /// + /// The name of the bik file. /// The position of the video window. /// The size of the video window. public ScaledBink(string name, PointF pos, SizeF size) : base(pos, size) From 87e790472ef82f911947b245cff57545c3f225f9 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 15:55:04 -0300 Subject: [PATCH 06/10] Moved Bink Movie name to a property --- LemonUI/Elements/ScaledBink.cs | 42 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs index dfd2570..0a1fabd 100644 --- a/LemonUI/Elements/ScaledBink.cs +++ b/LemonUI/Elements/ScaledBink.cs @@ -26,6 +26,34 @@ public class ScaledBink : BaseElement #endregion + #region Properties + + /// + /// The name of the Bink Video file. + /// + public string Name + { + get => name; + set + { + name = value ?? throw new ArgumentNullException(nameof(value)); + +#if ALTV + id = Alt.Natives.SetBinkMovie(name); +#elif FIVEM + id = API.SetBinkMovie(name); +#elif RAGEMP + id = Invoker.Invoke(0xfc36643f7a64338f, name); +#elif RPH + id = NativeFunction.CallByHash(0xfc36643f7a64338f, name); +#elif SHVDN3 || SHVDNC + id = Function.Call(Hash.SET_BINK_MOVIE, name); +#endif + } + } + + #endregion + #region Constructors /// @@ -51,19 +79,7 @@ public ScaledBink(string name, SizeF size) : this(name, PointF.Empty, size) /// The size of the video window. public ScaledBink(string name, PointF pos, SizeF size) : base(pos, size) { - this.name = name ?? throw new ArgumentNullException(nameof(name)); - -#if ALTV - id = Alt.Natives.SetBinkMovie(name); -#elif FIVEM - id = API.SetBinkMovie(name); -#elif RAGEMP - id = Invoker.Invoke(0xfc36643f7a64338f, name); -#elif RPH - id = NativeFunction.CallByHash(0xfc36643f7a64338f, name); -#elif SHVDN3 || SHVDNC - id = Function.Call(Hash.SET_BINK_MOVIE, name); -#endif + Name = name ?? throw new ArgumentNullException(nameof(name)); } #endregion From 70b73a5ac99b032ed63022cff6dc49f28f775a02 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 16:26:06 -0300 Subject: [PATCH 07/10] Adedd function to stop a Bink Video --- LemonUI/Elements/ScaledBink.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs index 0a1fabd..e33a0d6 100644 --- a/LemonUI/Elements/ScaledBink.cs +++ b/LemonUI/Elements/ScaledBink.cs @@ -106,6 +106,26 @@ public override void Draw() #elif SHVDN3 || SHVDNC Function.Call(Hash.PLAY_BINK_MOVIE, id); Function.Call(Hash.DRAW_BINK_MOVIE, id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); +#endif + } + /// + /// Stops the playback of the Bink Video. + /// + /// + /// If is called after this function. playback will start again. + /// + public void Stop() + { +#if ALTV + Alt.Natives.StopBinkMovie(id); +#elif FIVEM + API.StopBinkMovie(id); +#elif RAGEMP + Invoker.Invoke(0x63606A61DE68898A, id); +#elif RPH + NativeFunction.CallByHash(0x63606A61DE68898A, id); +#elif SHVDN3 || SHVDNC + Function.Call(Hash.STOP_BINK_MOVIE, id); #endif } /// From 46283008330e62cf15c723fb4a47e0949ce6019f Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 16:34:52 -0300 Subject: [PATCH 08/10] Make the bink video id disposable --- LemonUI/Elements/ScaledBink.cs | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs index e33a0d6..23df25a 100644 --- a/LemonUI/Elements/ScaledBink.cs +++ b/LemonUI/Elements/ScaledBink.cs @@ -17,7 +17,7 @@ namespace LemonUI.Elements /// /// A Bink Video file. /// - public class ScaledBink : BaseElement + public class ScaledBink : BaseElement, IDisposable { #region Fields @@ -91,6 +91,11 @@ public ScaledBink(string name, PointF pos, SizeF size) : base(pos, size) /// public override void Draw() { + if (id == -1) + { + return; + } + #if ALTV Alt.Natives.PlayBinkMovie(id); Alt.Natives.DrawBinkMovie(id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); @@ -116,6 +121,11 @@ public override void Draw() /// public void Stop() { + if (id == -1) + { + return; + } + #if ALTV Alt.Natives.StopBinkMovie(id); #elif FIVEM @@ -128,6 +138,30 @@ public void Stop() Function.Call(Hash.STOP_BINK_MOVIE, id); #endif } + /// + /// Disposes the Bink Video ID. + /// + public void Dispose() + { + if (id == -1) + { + return; + } + +#if ALTV + Alt.Natives.ReleaseBinkMovie(id); +#elif FIVEM + API.ReleaseBinkMovie(id); +#elif RAGEMP + Invoker.Invoke(0x04D950EEFA4EED8C, id); +#elif RPH + NativeFunction.CallByHash(0x04D950EEFA4EED8C, id); +#elif SHVDN3 || SHVDNC + Function.Call(Hash.RELEASE_BINK_MOVIE, id); +#endif + + id = -1; + } /// public override void Recalculate() { From e6402e2c2a04a991cdb347c21e51ff2daa6037c7 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 16:35:21 -0300 Subject: [PATCH 09/10] Added finalizer so the bink video id gets released --- LemonUI/Elements/ScaledBink.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs index 23df25a..6afb078 100644 --- a/LemonUI/Elements/ScaledBink.cs +++ b/LemonUI/Elements/ScaledBink.cs @@ -84,6 +84,15 @@ public ScaledBink(string name, PointF pos, SizeF size) : base(pos, size) #endregion + #region Finalizer + + /// + /// Finalizes an instance of the class. + /// + ~ScaledBink() => Dispose(); + + #endregion + #region Functions /// From 05eece6d0b76794fc584cfe61a0cbb92a9f56c74 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 21:20:17 -0300 Subject: [PATCH 10/10] Make the Bink ID a property --- LemonUI/Elements/ScaledBink.cs | 63 ++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/LemonUI/Elements/ScaledBink.cs b/LemonUI/Elements/ScaledBink.cs index 6afb078..6a27a6a 100644 --- a/LemonUI/Elements/ScaledBink.cs +++ b/LemonUI/Elements/ScaledBink.cs @@ -22,12 +22,15 @@ public class ScaledBink : BaseElement, IDisposable #region Fields private string name = string.Empty; - private int id = 0; #endregion #region Properties + /// + /// The ID of the Bink Video Instance. + /// + public int Id { get; private set; } = -1; /// /// The name of the Bink Video file. /// @@ -39,15 +42,15 @@ public string Name name = value ?? throw new ArgumentNullException(nameof(value)); #if ALTV - id = Alt.Natives.SetBinkMovie(name); + Id = Alt.Natives.SetBinkMovie(name); #elif FIVEM - id = API.SetBinkMovie(name); + Id = API.SetBinkMovie(name); #elif RAGEMP - id = Invoker.Invoke(0xfc36643f7a64338f, name); + Id = Invoker.Invoke(0xfc36643f7a64338f, name); #elif RPH - id = NativeFunction.CallByHash(0xfc36643f7a64338f, name); + Id = NativeFunction.CallByHash(0xfc36643f7a64338f, name); #elif SHVDN3 || SHVDNC - id = Function.Call(Hash.SET_BINK_MOVIE, name); + Id = Function.Call(Hash.SET_BINK_MOVIE, name); #endif } } @@ -100,26 +103,26 @@ public ScaledBink(string name, PointF pos, SizeF size) : base(pos, size) /// public override void Draw() { - if (id == -1) + if (Id == -1) { return; } #if ALTV - Alt.Natives.PlayBinkMovie(id); - Alt.Natives.DrawBinkMovie(id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); + Alt.Natives.PlayBinkMovie(Id); + Alt.Natives.DrawBinkMovie(Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); #elif FIVEM - API.PlayBinkMovie(id); - API.DrawBinkMovie(id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); + API.PlayBinkMovie(Id); + API.DrawBinkMovie(Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); #elif RAGEMP - Invoker.Invoke(0xE178310643033958, id); - Invoker.Invoke(0x7118E83EEB9F7238, id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); + Invoker.Invoke(0xE178310643033958, Id); + Invoker.Invoke(0x7118E83EEB9F7238, Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); #elif RPH - NativeFunction.CallByHash(0xE178310643033958, id); - NativeFunction.CallByHash(0x7118E83EEB9F7238, id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); + NativeFunction.CallByHash(0xE178310643033958, Id); + NativeFunction.CallByHash(0x7118E83EEB9F7238, Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); #elif SHVDN3 || SHVDNC - Function.Call(Hash.PLAY_BINK_MOVIE, id); - Function.Call(Hash.DRAW_BINK_MOVIE, id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); + Function.Call(Hash.PLAY_BINK_MOVIE, Id); + Function.Call(Hash.DRAW_BINK_MOVIE, Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255); #endif } /// @@ -130,21 +133,21 @@ public override void Draw() /// public void Stop() { - if (id == -1) + if (Id == -1) { return; } #if ALTV - Alt.Natives.StopBinkMovie(id); + Alt.Natives.StopBinkMovie(Id); #elif FIVEM - API.StopBinkMovie(id); + API.StopBinkMovie(Id); #elif RAGEMP - Invoker.Invoke(0x63606A61DE68898A, id); + Invoker.Invoke(0x63606A61DE68898A, Id); #elif RPH - NativeFunction.CallByHash(0x63606A61DE68898A, id); + NativeFunction.CallByHash(0x63606A61DE68898A, Id); #elif SHVDN3 || SHVDNC - Function.Call(Hash.STOP_BINK_MOVIE, id); + Function.Call(Hash.STOP_BINK_MOVIE, Id); #endif } /// @@ -152,24 +155,24 @@ public void Stop() /// public void Dispose() { - if (id == -1) + if (Id == -1) { return; } #if ALTV - Alt.Natives.ReleaseBinkMovie(id); + Alt.Natives.ReleaseBinkMovie(Id); #elif FIVEM - API.ReleaseBinkMovie(id); + API.ReleaseBinkMovie(Id); #elif RAGEMP - Invoker.Invoke(0x04D950EEFA4EED8C, id); + Invoker.Invoke(0x04D950EEFA4EED8C, Id); #elif RPH - NativeFunction.CallByHash(0x04D950EEFA4EED8C, id); + NativeFunction.CallByHash(0x04D950EEFA4EED8C, Id); #elif SHVDN3 || SHVDNC - Function.Call(Hash.RELEASE_BINK_MOVIE, id); + Function.Call(Hash.RELEASE_BINK_MOVIE, Id); #endif - id = -1; + Id = -1; } /// public override void Recalculate()