[Windows Mobile Development and Hacking General] sztupy:
ExtLua 0.1

SztupY productions proudly presents: ExtLua

ExtLua is a DLL proxy for Manila3D-s lua.dll that will grab the luaL_newstate function, and add user made functions to Manila3D.

FAQ:

1. That's fine... but what is it good for?

Well: unfortunately loadlib is disabled in M3D's lua implementation, so there is no easy way to add user made libraries to Manila3D. The only way seemed to create a DLL proxy to do this stuff.

2. How does it work?

aul.dll is the proxy, which will proxy all functions back to lua.dll, except for luaL_newstate. When it encounters luaL_newstate calls, it will inject the lua_State with user made functions.

3. Why aul.dll?

Because it's lua backwards :) I tried to make this dll as lua.dll and rename the original lua.dll to something else, but unfortunately that didn't work out. M3D starts, but no lua functions will run if the original lua.dll is not named lua.dll (I've tried proxying using ARM assembly functions, dll redirections and function proxying, but neither one worked fine (the error was the same with all: lua starts, but no scripts will run, instead they crash when they rty to access global functions, like "require") ). But lua.dll works fine if it's called lua.dll, and an other dll (my aul.dll) is using DLL redirection to do the job.

4. How to install?

Unfortunately because the proxy is not named lua.dll therefore mode9.dll and manila2.exe must be patched to work. The patching is very easy and can be done with all versions of M3D. Simply run a hexeditor (like HxD) and replace all occurences (should be only one) of "lua.dll" to "aul.dll". But because the files are changed, you have to resign them using signtool :(. After changing them simply copy them back to the Windows directory. Copy aul.dll there too.

5. How to create user functions?

Use the provided luasdk to create a DLL file (it should export a function called lua_addawesomestuff), that will do the initialization. The provided SDK can be used to create lua modules (that don't use Q16.16 numbers, I have to implement some functions for them too). The sample application will provide you with a "power" module that has one function called "restart". For example if you want to soft reset your device when you click on a picture then modify 4aefb03d_manila to the following:

(...)

OnPhotoTouchRelease = function(loc_0)
Camera3DHitFeedback:Release()
if gnPhotoTouchPressY ~= -1 and loc_0._xmouse < CameraSprit.Position.x and noImage2DCamera._visible == false then
power.restart();
end
gnPhotoTouchPressY = -1
end

(...)

After this simply "luac -s" it back, and copy to the Windows directory. Now you have a soft reset button within M3D :)

6. How will ExtLua know which DLL's to load?

There is a registry key called "HKLM\Software\SztupY\ExtLua". Add your DLL here. For example:

HKEY_LOCAL_MACHINE\Software\SztupY\ExtLua
"1"="\Windows\luasdk.dll"

of course you might want to use a GUID instead of "1". ExtLua will enumerate all attributes in the key and load the DLL's. It logs this loading into "\ExtLua.log"

7. How to contribute?

Please patch your M3D, and install aul.dll to your device even if you don't plan to use this functionality. Then please send me feedback whether M3D is stable/unstable/slower/faster/eats more memory/etc. with the patches applied. It'd be great some time, if M3D providers/ROM cookers would put patched M3D's into their installers/ROMs, because user made functions can be easily installed afterwards (it only involves copying a dll, and adding a registry entry).

All files can be downloaded from the usual place: http://winmo.sztupy.hu/luadec.html

Because I'm using xboxmod's 1.8.5c M3D, I already uploaded a patched version of that Manila3D. I also added signtool, the luaext sdk, and the aul.dll there too.

To try out whether this works with your Manila3D, get a demo application from here