Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. void PushCClosure(const void* func, DWORD n) {
  2. try {
  3. r_lua_pushcclosure(RLS, (int)func, n);
  4. }
  5. catch (...) {};
  6. }
  7.  
  8. void rlua_pushobject(DWORD pRobloxState, TValue* value) {
  9. auto& topa = *(TValue * *)(pRobloxState + top);
  10. *topa = *value;
  11. ++topa;
  12. }
  13.  
  14. int Debug_GetMetaTable(lua_State* L) {
  15. if (lua_gettop(L) == 0) {
  16. luaL_error(L, "'debug.getrawmetatable' needs 1 argument.");
  17. return 0;
  18. }
  19. Wrap(RLS, L, 1);
  20. if (r_lua_getmetatable(RLS, -1) == 0) {
  21. lua_pushnil(L);
  22. return 0;
  23. }
  24. UnWrap(L, RLS, -1);
  25. return 1;
  26. }
  27.  
  28. int Debug_GetRegistry(lua_State* L) {
  29. r_lua_pushvalue(RLS, LUA_REGISTRYINDEX);
  30. return 1;
  31. }
  32.  
  33. static int Debug_setfenv(lua_State* L) {
  34. luaL_checktype(L, 2, LUA_TTABLE);
  35. lua_settop(L, 2);
  36. if (lua_setfenv(L, 1) == 0)
  37. luaL_error(L, LUA_QL("setfenv")
  38. " cannot change environment of given object");
  39. return 1;
  40. }
  41.  
  42. static int auxupvalue(lua_State* L, int get) {
  43. const char* name;
  44. int n = luaL_checkint(L, 2);
  45. luaL_checktype(L, 1, LUA_TFUNCTION);
  46. if (lua_iscfunction(L, 1)) return 0;
  47. name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
  48. if (name == NULL) return 0;
  49. lua_pushstring(L, name);
  50. lua_insert(L, -(get + 1));
  51. return get + 1;
  52. }
  53.  
  54. static int Debug_getupvalue(lua_State* L) {
  55. return auxupvalue(L, 1);
  56. }
  57.  
  58. static int Debug_setupvalue(lua_State* L) {
  59. luaL_checkany(L, 3);
  60. return auxupvalue(L, 0);
  61. }
  62.  
  63.  
  64. static int custom_checkcaller(lua_State* L) {
  65. r_lua_pushboolean(RLS, true);
  66. return 1;
  67. }
  68.  
  69. int CrashRoblox(lua_State* L) {
  70. exit(10);
  71. return 0;
  72. }
  73.  
  74. static lua_State* getthread(lua_State* L, int* arg) {
  75. if (lua_isthread(L, 1)) {
  76. *arg = 1;
  77. return lua_tothread(L, 1);
  78. }
  79. else {
  80. *arg = 0;
  81. return L;
  82. }
  83. }
  84.  
  85. int setreadonly(lua_State* L) {
  86. DWORD index2address = (DWORD)r_lua_index2(RLS, -1);
  87. *(BYTE*)(*(DWORD*)index2address + 10) = lua_toboolean(L, -1);
  88. return 0;
  89. }
  90. int metatable_handler(lua_State* L)
  91. {
  92. UnWrap(L, RLS, lua_upvalueindex(1));
  93. const char* key = lua_tostring(L, 2);
  94. r_lua_getmetatable(RLS, -1);
  95. r_lua_setreadonly(RLS, -1, 0);
  96. UnWrap(L, RLS, 3);
  97. r_lua_setfield(RLS, -2, key);
  98.  
  99. r_lua_pop(RLS, 2);
  100. return 0;
  101. }
  102. int getRawMetaTable(lua_State* L)
  103. {
  104. UnWrap(L, RLS, 1);
  105.  
  106. r_lua_getmetatable(RLS, -1);
  107. r_lua_setreadonly(RLS, -1, 0);
  108.  
  109. Wrap(RLS, L, -1);
  110.  
  111. lua_newtable(L);
  112. {
  113. lua_pushvalue(L, 1);
  114. lua_pushcclosure(L, metatable_handler, 1);
  115. lua_setfield(L, -2, "__newindex");
  116. }
  117. lua_setmetatable(L, -2);
  118. return 1;
  119. }
  120.  
  121. int getgenv(lua_State* L) {
  122. lua_pushvalue(L, LUA_GLOBALSINDEX);
  123. Wrap(RLS, L, -1);
  124. return 1;
  125. }
  126.  
  127. int getreg(lua_State* L) {
  128. lua_pushvalue(L, LUA_REGISTRYINDEX);
  129. Wrap(RLS, L, -1);
  130. return 1;
  131. }
  132.  
  133. int getrenv(lua_State* L) {
  134. lua_pushvalue(L, int(RLS));
  135. Wrap(RLS, L, -1);
  136. return 1;
  137. }
  138.  
  139. static int loadstring(lua_State* L) {
  140. size_t l;
  141. const char* s = luaL_checklstring(L, 1, &l);
  142. const char* chunkname = luaL_optstring(L, 2, s);
  143. return load_aux(L, luaL_loadbuffer(L, s, l, chunkname));
  144. }
  145.  
  146. void lua_setfield(DWORD L, int idx, const char* k) {
  147. r_lua_pushvalue(L, idx);
  148. if (r_lua_getmetatable(L, -1)) {
  149. r_lua_getfield(L, -1, "__newindex");
  150. r_lua_pushvalue(L, -3);
  151. r_lua_pushstring(L, k);
  152. r_lua_pushvalue(L, -6);
  153. r_lua_pop(L, 3);
  154. }
  155. else {
  156. std::cout << "0\n";
  157. r_lua_pop(L, 1);
  158. lua_setfield(L, idx, k);
  159. }
  160. }
  161.  
  162. r_TValue* r_gettop(int rlua_State) {
  163. return *(r_TValue * *)(rlua_State + 16);
  164. }
  165. int setrawmetatable_impl(lua_State* rlua_State) {
  166. if (r_lua_gettop(RLS) < 2) {
  167. r_lua_pushboolean(RLS, 0);
  168. r_lua_pushstring(RLS, "2 or more arguments expected");
  169. return 2;
  170. }
  171.  
  172. r_TValue* top = r_gettop(RLS);
  173. r_TValue* obj1 = top - 1;
  174. r_TValue* obj0 = top - 2;
  175.  
  176. if (!(obj0->tt == R_LUA_TTABLE || obj0->tt == R_LUA_TUSERDATA) || !(obj1->tt == R_LUA_TNIL || obj1->tt == R_LUA_TTABLE)) {
  177. r_lua_pushboolean(RLS, 0);
  178. r_lua_pushstring(RLS, "bad argument types");
  179. return 2;
  180. }
  181.  
  182. r_lua_setmetatable(RLS, 1);
  183. r_lua_pushboolean(RLS, 1);
  184. return 1;
  185. }
  186.  
  187. static int GC(lua_State* Thread) {
  188. void* UD = lua_touserdata(Thread, 1);
  189. if (RLS) {
  190. r_lua_rawgeti(RLS, LUA_REGISTRYINDEX, (int)UD);
  191. if (r_lua_type(RLS, -1) <= R_LUA_TNIL) {
  192. lua_pushnil(Thread);
  193. lua_rawseti(Thread, LUA_REGISTRYINDEX, (int)UD);
  194. }
  195. }
  196. return 0;
  197. }
  198.  
  199. int getupvalues(lua_State* L)
  200. {
  201. lua_pushvalue(L, 1);
  202. lua_newtable(L);
  203.  
  204. int idx = 1;
  205. while (true)
  206. {
  207. const char* name = lua_getupvalue(L, -2, idx);
  208.  
  209. if (!name)
  210. {
  211. break;
  212. }
  213.  
  214. lua_setfield(L, -2, name);
  215. idx++;
  216. }
  217. return 1;
  218. }
  219.  
  220. int error(lua_State* thread) {
  221. std::string errorstr = lua_tostring(thread, -1);
  222. int type = lua_tonumber(thread, -2);
  223. std::string finalerror = "error('"; finalerror = finalerror + errorstr; finalerror = finalerror + "')";
  224. luaL_dostring(thread, finalerror.c_str());
  225. return 1;
  226. }
  227.  
  228. int newcclosure(lua_State* L) {
  229. lua_pushvalue(L, 1);
  230. return 1;
  231. }
  232.  
  233. int getsenv(lua_State* LS) {
  234. lua_pushvalue(LS, LUA_ENVIRONINDEX);
  235. Wrap(RLS, LS, -1);
  236. return 1;
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement