JD2022-TU1/main/extern/Camcam/LIBS/Mixer/Lua/luaflib.c

39 lines
No EOL
928 B
C

#include "DEFINES.H"
#define luaflib_c
#define LUA_LIB
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include <windows.h>
#include <tchar.h>
static int uaf_getrootdir(lua_State *L) {
const size_t max_size = 512;
WCHAR value[max_size] = {};
DWORD size = sizeof(value); // Important that the size be initialized with the buffer size for RegQueryValueEx
HKEY key;
HRESULT hr = RegOpenCurrentUser(KEY_READ, &key);
hr = RegOpenKeyEx(key, _T("Software\\Ubisoft\\UbiArt\\UAF"), 0, KEY_READ, &key);
hr = RegQueryValueExW(key, L"rootDir", 0, NULL, (LPBYTE)value, &size);
char rootdir[max_size] = {};
wcstombs(rootdir, value, max_size);
lua_pushstring(L, rootdir);
return 1;
}
static const luaL_Reg syslib[] = {
{"getrootdir", uaf_getrootdir},
{NULL, NULL}
};
LUALIB_API int luaopen_uaf(lua_State *L) {
luaL_register(L, LUA_UAFLIBNAME, syslib);
return 1;
}