1+ -- ScaleformLib by aaronlink127#0127
2+
3+ -- local natives, so we dont need to require natives (even though most scripts that require this would probably require them already, so there would be no cost to using them here, i just like this)
4+ local function HAS_SCALEFORM_MOVIE_LOADED (scaleformHandle )native_invoker .begin_call ()native_invoker .push_arg_int (scaleformHandle )native_invoker .end_call (" 85F01B8D5B90570E" )return native_invoker .get_return_value_bool ()end
5+ local function DRAW_SCALEFORM_MOVIE (scaleformHandle ,x ,y ,width ,height ,red ,green ,blue ,alpha ,unk )native_invoker .begin_call ()native_invoker .push_arg_int (scaleformHandle )native_invoker .push_arg_float (x )native_invoker .push_arg_float (y )native_invoker .push_arg_float (width )native_invoker .push_arg_float (height )native_invoker .push_arg_int (red )native_invoker .push_arg_int (green )native_invoker .push_arg_int (blue )native_invoker .push_arg_int (alpha )native_invoker .push_arg_int (unk )native_invoker .end_call (" 54972ADAF0294A93" )end
6+ local function DRAW_SCALEFORM_MOVIE_FULLSCREEN (scaleform ,red ,green ,blue ,alpha ,unk )native_invoker .begin_call ()native_invoker .push_arg_int (scaleform )native_invoker .push_arg_int (red )native_invoker .push_arg_int (green )native_invoker .push_arg_int (blue )native_invoker .push_arg_int (alpha )native_invoker .push_arg_int (unk )native_invoker .end_call (" 0DF606929C105BE1" )end
7+ local function DRAW_SCALEFORM_MOVIE_3D (scaleform ,posX ,posY ,posZ ,rotX ,rotY ,rotZ ,p7 ,p8 ,p9 ,scaleX ,scaleY ,scaleZ ,p13 )native_invoker .begin_call ()native_invoker .push_arg_int (scaleform )native_invoker .push_arg_float (posX )native_invoker .push_arg_float (posY )native_invoker .push_arg_float (posZ )native_invoker .push_arg_float (rotX )native_invoker .push_arg_float (rotY )native_invoker .push_arg_float (rotZ )native_invoker .push_arg_float (p7 )native_invoker .push_arg_float (p8 )native_invoker .push_arg_float (p9 )native_invoker .push_arg_float (scaleX )native_invoker .push_arg_float (scaleY )native_invoker .push_arg_float (scaleZ )native_invoker .push_arg_int (p13 )native_invoker .end_call (" 87D51D72255D4E78" )end
8+ local function DRAW_SCALEFORM_MOVIE_3D_SOLID (scaleform ,posX ,posY ,posZ ,rotX ,rotY ,rotZ ,p7 ,p8 ,p9 ,scaleX ,scaleY ,scaleZ ,p13 )native_invoker .begin_call ()native_invoker .push_arg_int (scaleform )native_invoker .push_arg_float (posX )native_invoker .push_arg_float (posY )native_invoker .push_arg_float (posZ )native_invoker .push_arg_float (rotX )native_invoker .push_arg_float (rotY )native_invoker .push_arg_float (rotZ )native_invoker .push_arg_float (p7 )native_invoker .push_arg_float (p8 )native_invoker .push_arg_float (p9 )native_invoker .push_arg_float (scaleX )native_invoker .push_arg_float (scaleY )native_invoker .push_arg_float (scaleZ )native_invoker .push_arg_int (p13 )native_invoker .end_call (" 1CE592FDC749D6F5" )end
9+ local function SET_SCALEFORM_MOVIE_AS_NO_LONGER_NEEDED (scaleformHandle )native_invoker .begin_call ()native_invoker .push_arg_pointer (scaleformHandle )native_invoker .end_call (" 1D132D614DD86811" )end
10+ local function REQUEST_SCALEFORM_MOVIE (scaleformName )native_invoker .begin_call ()native_invoker .push_arg_string (scaleformName )native_invoker .end_call (" 11FE353CF9733E6F" )return native_invoker .get_return_value_int ()end
11+ local function BEGIN_SCALEFORM_MOVIE_METHOD (scaleform ,methodName )native_invoker .begin_call ()native_invoker .push_arg_int (scaleform )native_invoker .push_arg_string (methodName )native_invoker .end_call (" F6E48914C7A8694E" )return native_invoker .get_return_value_bool ()end
12+ local function END_SCALEFORM_MOVIE_METHOD ()native_invoker .begin_call ()native_invoker .end_call (" C6796A8FFA375E53" )end
13+ -- again, localized natives, except in a table so that i can give different types different push functions automatically
14+ local scaleform_types = {
15+ [" number" ]= function (value )native_invoker .begin_call ()native_invoker .push_arg_float (value )native_invoker .end_call (" D69736AAE04DB51A" )end ,
16+ [" string" ]= function (value )native_invoker .begin_call ()native_invoker .push_arg_string (value )native_invoker .end_call (" E83A3E3557A56640" )end ,
17+ [" boolean" ]= function (value )native_invoker .begin_call ()native_invoker .push_arg_bool (value )native_invoker .end_call (" C58424BA936EB458" )end
18+ }
19+ -- generic call scaleform function
20+ local function CallScaleformMethod (sf , method , ...)
21+ local args = {... }
22+ if BEGIN_SCALEFORM_MOVIE_METHOD (sf , method ) then
23+ for i = 1 ,# args do
24+ local arg = args [i ]
25+ local type = type (arg )
26+ local push_f = scaleform_types [type ]
27+ if push_f then
28+ push_f (arg )
29+ else
30+ error (" Invalid type passed to scaleform method: " .. type )
31+ end
32+ end
33+ END_SCALEFORM_MOVIE_METHOD ()
34+ --[[ this error, while nice to have for debugging, is probably not nice for release code
35+ else
36+ error("Scaleform movie method fail (Scaleform not loaded?)") ]]
37+ end
38+ end
39+ local ScaleformFunctions = {
40+ draw = function (self , x , y , w , h )
41+ DRAW_SCALEFORM_MOVIE (self .id , x , y , w , h , 255 , 255 , 255 , 255 , 1 )
42+ end ,
43+ draw_fullscreen = function (self )
44+ DRAW_SCALEFORM_MOVIE_FULLSCREEN (self .id , 255 , 255 , 255 , 255 , 1 )
45+ end ,
46+ draw_3d = function (self , pos , rot , size )
47+ pos = pos or {x = 0 ,y = 0 ,z = 0 }
48+ rot = rot or {x = 0 ,y = 0 ,z = 0 }
49+ size = size or {x = 1 ,y = 1 ,z = 1 }
50+ DRAW_SCALEFORM_MOVIE_3D (self .id , pos .x , pos .y , pos .z , rot .x , rot .y , rot .z , 0 , 2 , 0 , size .x , size .y , size .z , 1 )
51+ end ,
52+ draw_3d_solid = function (self , pos , rot , size )
53+ pos = pos or {x = 0 ,y = 0 ,z = 0 }
54+ rot = rot or {x = 0 ,y = 0 ,z = 0 }
55+ size = size or {x = 1 ,y = 1 ,z = 1 }
56+ DRAW_SCALEFORM_MOVIE_3D_SOLID (self .id , pos .x , pos .y , pos .z , rot .x , rot .y , rot .z , 0 , 2 , 0 , size .x , size .y , size .z , 1 )
57+ end ,
58+ delete = function (self )
59+ local mem = memory .alloc (4 )
60+ memory .write_int (mem , self .id )
61+ -- part of the hacky solution
62+ util .spoof_script (" stats_controller" ,function ()
63+ SET_SCALEFORM_MOVIE_AS_NO_LONGER_NEEDED (mem )
64+ end )
65+ memory .free (mem )
66+ end
67+ }
68+ local metaScaleform = {
69+ __index = function (self , key )
70+ return ScaleformFunctions [key ] or function (...)
71+ CallScaleformMethod (self .id , key , ... )
72+ end
73+ end
74+ }
75+ local function Scaleform (id )
76+ if type (id ) == " string" then
77+ -- this spoof script is a hacky solution to certain problems (mainly with instructional_buttons) but should work
78+ util .spoof_script (" stats_controller" ,function ()
79+ id = REQUEST_SCALEFORM_MOVIE (id )
80+ end )
81+ while not HAS_SCALEFORM_MOVIE_LOADED (id ) do
82+ util .yield ()
83+ end
84+ end
85+ local tbl = {id = id }
86+ setmetatable (tbl ,metaScaleform )
87+ return tbl
88+ end
89+ return Scaleform
0 commit comments