88
99
1010local PreviewService = require (" includes.services.PreviewService" )
11- local function ClearPreview ()
12- PreviewService :Clear ()
13- end
11+ local ClearPreview = function () PreviewService :Clear () end
12+
1413
1514--- @class BlipData
1615--- @field handle integer
1716--- @field owner integer
1817--- @field alpha integer
1918
20- --- @enum eAPIVersion
21- Enums .eAPIVersion = {
22- V1 = 1 , -- YimMenu V1 (Lua54)
23- V2 = 2 , -- YimLuaAPI (Lua 54)
24- L54 = 99 , -- Mock environment (Lua54)
19+ --- @enum eGameBranch
20+ Enums .eGameBranch = {
21+ LAGECY = 1 ,
22+ ENHANCED = 2 ,
23+ MOCK = 99 ,
2524}
2625
2726--- @enum eBackendEvent
@@ -32,7 +31,7 @@ Enums.eBackendEvent = {
3231}
3332
3433--- @enum eEntityType
35- Enums .eEntityType = {
34+ Enums .eEntityType = {
3635 Invalid = - 1 ,
3736 Ped = 1 ,
3837 Vehicle = 2 ,
@@ -41,8 +40,8 @@ Enums.eEntityType = {
4140
4241-- Global Singleton.
4342--- @class Backend
44- --- @field private api_version eAPIVersion
45- local Backend = {
43+ --- @field private m_game_branch eGameBranch
44+ local Backend = {
4645 __version = " " ,
4746 target_build = " " ,
4847 target_version = " " ,
@@ -79,28 +78,30 @@ local Backend = {
7978 [Enums .eEntityType .Vehicle ] = 15 ,
8079 [Enums .eEntityType .Object ] = 35 ,
8180 },
81+ --- @type table<string , fun ( handle : handle ): any>
82+ FeatureEntityHandlers = {}
8283}
83- Backend .__index = Backend
84+ Backend .__index = Backend
8485
8586--- @param name string
8687--- @param script_version string
8788--- @param game_version ? GAME_VERSION
8889function Backend :init (name , script_version , game_version )
89- local api_ver = self :GetAPIVersion ()
90- self .api_version = api_ver
90+ local branch = self :GetGameBranch ()
91+ self .m_game_branch = branch
9192 self .script_name = name
9293 self .__version = script_version
93- self .target_build = game_version and game_version [api_ver ].build or " any"
94- self .target_version = game_version and game_version [api_ver ].online or " any"
94+ self .target_build = game_version and game_version [branch ].build or " any"
95+ self .target_version = game_version and game_version [branch ].online or " any"
9596
96- require (" includes.lib.compat" ).SetupEnv (self .api_version )
97+ require (" includes.lib.compat" ).SetupEnv (self .m_game_branch )
9798 return self
9899end
99100
100- --- @return eAPIVersion
101- function Backend :GetAPIVersion ()
102- if (self .api_version ) then
103- return self .api_version
101+ --- @return eGameBranch
102+ function Backend :GetGameBranch ()
103+ if (self .m_game_branch ) then
104+ return self .m_game_branch
104105 end
105106
106107 if (not script or (type (script ) ~= " table" )) then
@@ -109,36 +110,37 @@ function Backend:GetAPIVersion()
109110 error (" Failed to load: Unknown or unsupported Lua environment." )
110111 end
111112
112- self .api_version = Enums .eAPIVersion . L54
113- return self .api_version
113+ self .m_game_branch = Enums .eGameBranch . MOCK
114+ return self .m_game_branch
114115 end
115116
116117 if (type (script [" run_in_callback" ]) == " function" ) then
117118 error (" YimMenuV2 is not supported. If you want to run this script in GTA V Enhanced, download YimLuaAPI." )
118119 end
119120
120121 if (not menu_event or not menu_event .Wndproc ) then
121- error (" Unknown or unsupported game branch ." )
122+ error (" Unknown or unsupported API ." )
122123 end
123124
124- local ylapi_func = _G [" get_game_branch" ]
125- if (type (ylapi_func ) ~= " function" ) then
126- self .api_version = Enums .eAPIVersion .V1
127- return self .api_version
125+ --- @type (fun (): integer )?
126+ local get_game_branch = _G [" get_game_branch" ]
127+ if (type (get_game_branch ) ~= " function" ) then
128+ self .m_game_branch = Enums .eGameBranch .LAGECY
129+ return self .m_game_branch
128130 end
129131
130- local branch = ylapi_func ()
132+ local branch = get_game_branch ()
131133 if (type (branch ) ~= " number" or branch > 1 ) then
132134 error (" Failed to load: Unknown or unsupported game branch." )
133135 end
134136
135- self .api_version = branch + 1
136- return self .api_version
137+ self .m_game_branch = branch + 1 -- Our own eGameBranch starts at 1 to make it compatible with Lua table indices. YimLuaAPI's naturally starts at 0
138+ return self .m_game_branch
137139end
138140
139141--- @return boolean
140142function Backend :IsMockEnv ()
141- return self :GetAPIVersion () == Enums .eAPIVersion . L54
143+ return self :GetGameBranch () == Enums .eGameBranch . MOCK
142144end
143145
144146--- @return boolean
@@ -274,18 +276,18 @@ function Backend:RemoveBlip(owner)
274276 self .CreatedBlips [owner ] = nil
275277end
276278
279+ --- @param name string
280+ --- @param callback fun ( handle : handle ): any
281+ function Backend :RegisterFeatureEntityHandler (name , callback )
282+ self .FeatureEntityHandlers [name ] = callback
283+ end
284+
277285--- @param handle integer
278286function Backend :CheckFeatureEntities (handle )
279- if Decorator :ExistsOn (handle , " EntityForge" ) then
280- EntityForge :RemoveEntityByHandle (handle )
281- end
282-
283- if Decorator :ExistsOn (handle , " BillionaireServices" ) then
284- BillionaireServices :RemoveEntityByHandle (handle )
285- end
286-
287- if Decorator :ExistsOn (handle , " YimActions" ) then
288- YimActions .CompanionManager :RemoveCompanionByHandle (handle )
287+ for featName , callback in pairs (self .FeatureEntityHandlers ) do
288+ if (Decorator :ExistsOn (handle , featName )) then
289+ callback (handle )
290+ end
289291 end
290292end
291293
0 commit comments