Advertisement
mavythegamer

Mum source

Oct 15th, 2018
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.99 KB | None | 0 0
  1. #pragma once
  2. #include "globals.h"
  3. #include <string>
  4. #include <vector>
  5. #include "r_lua.h"
  6. #include "HttpGet.h"
  7. #include "Sk8r.h"
  8. extern "C" {
  9. #include "Lua\lua.h"
  10. #include "Lua\lua.hpp"
  11. #include "Lua\lualib.h"
  12. #include "Lua\lauxlib.h"
  13. #include "Lua\luaconf.h"
  14. #include "Lua\llimits.h"
  15. }
  16.  
  17. int registry;
  18.  
  19. namespace Bridge
  20. {
  21.     DWORD m_rL;
  22.     lua_State* m_L;
  23.  
  24.     void push(lua_State* L, DWORD rL, int index);
  25.     void push(DWORD rL, lua_State* L, int index);
  26.  
  27.     int rbxFunctionBridge(DWORD rL);
  28.     int vanillaFunctionBridge(lua_State* L);
  29.     LONG WINAPI vehHandler(PEXCEPTION_POINTERS ex);
  30.     VOID VehHandlerpush();
  31.     std::vector<int> int3breakpoints;
  32.     int resumea(DWORD thread);
  33. }
  34.  
  35. namespace Bridge
  36. {
  37.     LONG WINAPI vehHandler(PEXCEPTION_POINTERS ex)
  38.     {
  39.         switch (ex->ExceptionRecord->ExceptionCode)
  40.         {
  41.         case (DWORD)0x80000003L:
  42.         {
  43.             if (ex->ContextRecord->Eip == int3breakpoints[0])
  44.             {
  45.                 ex->ContextRecord->Eip = (DWORD)(Bridge::rbxFunctionBridge);
  46.                 return EXCEPTION_CONTINUE_EXECUTION;
  47.             }
  48.  
  49.             if (ex->ContextRecord->Eip == int3breakpoints[1])
  50.             {
  51.                 ex->ContextRecord->Eip = (DWORD)(Bridge::resumea);
  52.                 return EXCEPTION_CONTINUE_EXECUTION;
  53.             }
  54.             return -1;
  55.         }
  56.         default: return 0;
  57.         }
  58.         return 0;
  59.     }
  60.  
  61.     DWORD locateINT3() {
  62.         DWORD _s = x(0x400000);
  63.         const char i3_8opcode[8] = { 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC };
  64.         for (int i = 0; i < MAX_INT; i++) {
  65.             if (memcmp((void*)(_s + i), i3_8opcode, sizeof(i3_8opcode)) == 0) {
  66.                 return (_s + i);
  67.             }
  68.         }
  69.         return NULL;
  70.     }
  71.  
  72.     VOID VehHandlerpush()
  73.     {
  74.         int3breakpoints.push_back(locateINT3());
  75.         int3breakpoints.push_back(locateINT3());
  76.         AddVectoredExceptionHandler(1, vehHandler);
  77.     }
  78.  
  79.     void push(lua_State* L, DWORD rL, int index)
  80.     {
  81.         switch (lua_type(L, index))
  82.         {
  83.         case LUA_TLIGHTUSERDATA:
  84.             r_lua_pushlightuserdata(rL, nullptr);
  85.  
  86.             break;
  87.         case LUA_TNIL:
  88.             r_lua_pushnil(rL);
  89.             break;
  90.         case LUA_TNUMBER:
  91.             r_lua_pushnumber(rL, lua_tonumber(L, index));
  92.             break;
  93.         case LUA_TBOOLEAN:
  94.             r_lua_pushboolean(rL, lua_toboolean(L, index));
  95.             break;
  96.         case LUA_TSTRING:
  97.             r_lua_pushstring(rL, lua_tostring(L, index));
  98.             break;
  99.         case LUA_TTHREAD:
  100.             r_lua_newthread(rL);
  101.             break;
  102.         case LUA_TFUNCTION:
  103.             lua_pushvalue(L, index);
  104.             r_lua_pushnumber(rL, luaL_ref(L, LUA_REGISTRYINDEX));
  105.             r_lua_pushcclosure(rL, Bridge::int3breakpoints[0], 1);
  106.             break;
  107.         case LUA_TTABLE:
  108.             lua_pushvalue(L, index);
  109.             r_lua_newtable(rL);
  110.             lua_pushnil(L);
  111.             while (lua_next(L, -2) != LUA_TNIL)
  112.             {
  113.                 Bridge::push(L, rL, -2);
  114.                 Bridge::push(L, rL, -1);
  115.                 r_lua_settable(rL, -3);
  116.                 lua_pop(L, 1);
  117.             }
  118.             lua_pop(L, 1);
  119.             break;
  120.         case LUA_TUSERDATA:
  121.             lua_pushvalue(L, index);
  122.             lua_gettable(L, LUA_REGISTRYINDEX);
  123.             if (!lua_isnil(L, -1))
  124.                 r_lua_getfield(rL, LUA_REGISTRYINDEX, lua_tostring(L, -1));
  125.             else
  126.                 r_lua_newuserdata(rL, 0);
  127.             lua_pop(L, 1);
  128.             break;
  129.         default: break;
  130.         }
  131.     }
  132.  
  133.     void push(DWORD rL, lua_State* L, int index)
  134.     {
  135.         switch (r_lua_type(rL, index))
  136.         {
  137.         case R_LUA_TLIGHTUSERDATA:
  138.             lua_pushlightuserdata(L, nullptr);
  139.             break;
  140.         case R_LUA_TNIL:
  141.             lua_pushnil(L);
  142.             break;
  143.         case R_LUA_TNUMBER:
  144.             lua_pushnumber(L, r_lua_tonumber(rL, index));
  145.             break;
  146.         case R_LUA_TBOOLEAN:
  147.             lua_pushboolean(L, r_lua_toboolean(rL, index));
  148.             break;
  149.         case R_LUA_TSTRING:
  150.             lua_pushstring(L, r_lua_tostring(rL, index));
  151.             break;
  152.         case R_LUA_TTHREAD:
  153.             lua_newthread(L);
  154.             break;
  155.         case R_LUA_TFUNCTION:
  156.             r_lua_pushvalue(rL, index);
  157.             lua_pushnumber(L, r_luaL_ref(rL, LUA_REGISTRYINDEX));
  158.             lua_pushcclosure(L, vanillaFunctionBridge, 1);
  159.             break;
  160.         case R_LUA_TTABLE:
  161.             r_lua_pushvalue(rL, index);
  162.             lua_newtable(L);
  163.             r_lua_pushnil(rL);
  164.             while (r_lua_next(rL, -2) != R_LUA_TNIL)
  165.             {
  166.                 Bridge::push(rL, L, -2);
  167.                 Bridge::push(rL, L, -1);
  168.                 lua_settable(L, -3);
  169.                 r_lua_pop(rL, 1);
  170.             }
  171.             r_lua_pop(rL, 1);
  172.             break;
  173.         case R_LUA_TUSERDATA:
  174.             r_lua_pushvalue(rL, index);
  175.             r_lua_pushstring(rL, std::to_string(++registry).c_str());
  176.  
  177.             r_lua_pushvalue(rL, -2);
  178.             r_lua_settable(rL, LUA_REGISTRYINDEX);
  179.             r_lua_pop(rL, 1);
  180.             lua_newuserdata(L, 0);
  181.             lua_pushvalue(L, -1);
  182.             lua_pushstring(L, std::to_string(registry).c_str());
  183.             lua_settable(L, LUA_REGISTRYINDEX);
  184.             r_lua_getmetatable(rL, index);
  185.  
  186.             Bridge::push(rL, L, -1);
  187.             r_lua_pop(rL, 1);
  188.             lua_setmetatable(L, -2);
  189.             break;
  190.         default: break;
  191.         }
  192.     }
  193.  
  194.     static int resume(lua_State* thread)
  195.     {
  196.         lua_State* L = lua_tothread(thread, lua_upvalueindex(1));
  197.         const int nargs = lua_gettop(thread);
  198.         lua_xmove(thread, L, nargs);
  199.         return lua_resume(L, nargs);
  200.         lua_close(L);
  201.  
  202.     }
  203.  
  204.     int resumea(DWORD thread)
  205.     {
  206.         lua_State* L = (lua_State*)r_lua_touserdata(thread, lua_upvalueindex(1));
  207.         const int nargs = r_lua_gettop(thread);
  208.         for (int arg = 1; arg <= nargs; ++arg)
  209.             Bridge::push(thread, L, arg);
  210.         return lua_resume(L, nargs);
  211.         lua_close(L);
  212.  
  213.     }
  214.  
  215.     int vanillaFunctionBridge(lua_State* L)
  216.     {
  217.         r_lua_pushstring(m_rL, std::to_string(++registry).c_str());
  218.         DWORD rL = r_lua_newthread(m_rL);
  219.         r_lua_settable(m_rL, LUA_REGISTRYINDEX);
  220.  
  221.         int key = lua_tonumber(L, lua_upvalueindex(1));
  222.  
  223.         r_lua_rawgeti(rL, LUA_REGISTRYINDEX, key);
  224.  
  225.         for (int arg = 1; arg <= lua_gettop(L); ++arg)
  226.             Bridge::push(L, rL, arg);
  227.  
  228.         if (r_lua_pcall(rL, lua_gettop(L), LUA_MULTRET, 0))
  229.         {
  230.             const char* errormessage = r_lua_tostring(rL, -1, 0);
  231.  
  232.             if (!errormessage || strlen(errormessage) == 0)
  233.                 errormessage = "Error occoured, no output from Lua\n";
  234.  
  235.             if (strcmp(errormessage, "attempt to yield across metamethod/C-call boundary") == 0)
  236.             {
  237.  
  238.                 r_lua_pop(rL, 1);
  239.                 lua_pushthread(L);
  240.                 lua_pushcclosure(L, &resume, 1);
  241.                 Bridge::push(L, rL, -1);
  242.  
  243.                 return lua_yield(L, 0);
  244.             }
  245.             printf("Embox Vanilla Error: %s\n", r_lua_tostring(rL, -1));
  246.             return 0;
  247.             MessageBoxA(NULL, "SUCCESS VANILLA", "vanillabridge", NULL);
  248.             delete[] errormessage;
  249.         }
  250.  
  251.         int args = 0;
  252.  
  253.         for (int arg = 1; arg <= r_lua_gettop(rL); ++arg, ++args)
  254.             Bridge::push(rL, L, arg);
  255.  
  256.         r_lua_settop(rL, 0);
  257.  
  258.         return args;
  259.         lua_close(L);
  260.         MessageBoxA(NULL, "SUCCESS VANILLA 2", "vanillabridge", NULL);
  261.     }
  262.  
  263.     int rbxFunctionBridge(DWORD rL)
  264.     {
  265.  
  266.         lua_pushstring(m_L, std::to_string(++registry).c_str());
  267.         lua_State* L = lua_newthread(m_L);
  268.         lua_settable(m_L, LUA_REGISTRYINDEX);
  269.  
  270.         int key = r_lua_tonumber(rL, lua_upvalueindex(1));
  271.  
  272.         lua_rawgeti(L, LUA_REGISTRYINDEX, key);
  273.  
  274.         for (int arg = 1; arg <= r_lua_gettop(rL); ++arg)
  275.             Bridge::push(rL, L, arg);
  276.  
  277.         switch (lua_pcall(L, r_lua_gettop(rL), LUA_MULTRET, 0))
  278.         {
  279.        
  280.        
  281.         case LUA_YIELD:
  282.  
  283.             r_lua_pushlightuserdata(m_rL, (void*)L);
  284.             r_lua_pushcclosure(m_rL, Bridge::int3breakpoints[1], 1);
  285.             return -1;
  286.         case LUA_ERRRUN:
  287.                 printf("Embox Roblox Error: %s\n", lua_tostring(L, -1));
  288.                 return -1;
  289.         default: break;
  290.         }
  291.  
  292.         int args = 0;
  293.  
  294.         for (int arg = 1; arg <= lua_gettop(L); ++arg, ++args)
  295.             Bridge::push(L, rL, arg);
  296.  
  297.         lua_settop(L, 0);
  298.  
  299.         return args;
  300.         lua_close(L);
  301.  
  302.     }
  303.  
  304.     static int newwait(lua_State* L) {
  305.         r_lua_getglobal(m_rL, "wait");
  306.         int ArgCount = 0;
  307.         for (int x = lua_gettop(L); x != 0; x -= 1) {
  308.             push(L, m_rL, x * -1);
  309.             ArgCount += 1;
  310.         }
  311.         r_lua_pcall(m_rL, ArgCount, 0, 0);
  312.         return ArgCount;
  313.     }
  314.  
  315.     static int newspawn(lua_State* L) {
  316.         r_lua_getglobal(m_rL, "spawn");
  317.         int ArgCount = 0;
  318.         for (int x = lua_gettop(L); x != 0; x -= 1) {
  319.             push(L, m_rL, x * -1);
  320.             ArgCount += 1;
  321.         }
  322.         r_lua_pcall(m_rL, ArgCount, 0, 0);
  323.         return ArgCount;
  324.     }
  325.  
  326.     void toClipboard(const std::string &s) {
  327.         OpenClipboard(0);
  328.         EmptyClipboard();
  329.         HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, s.size());
  330.         if (!hg) {
  331.             CloseClipboard();
  332.             return;
  333.         }
  334.         memcpy(GlobalLock(hg), s.c_str(), s.size());
  335.         GlobalUnlock(hg);
  336.         SetClipboardData(CF_TEXT, hg);
  337.         CloseClipboard();
  338.         GlobalFree(hg);
  339.     }
  340.  
  341.     void fn_toclipboard(lua_State *L) {
  342.         std::string tc = lua_tostring(L, -1);
  343.         toClipboard(tc);
  344.     }
  345.  
  346.     int MouseButton1Down(lua_State* L) {
  347.         INPUT input;
  348.         input.type = INPUT_MOUSE;
  349.         memset(&input.mi, 0, sizeof(MOUSEINPUT));
  350.         input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;
  351.         SendInput(1, &input, sizeof(input));
  352.         return 0;
  353.     }
  354.  
  355.     int MouseButton2Down(lua_State* L) {
  356.         INPUT input;
  357.         input.type = INPUT_MOUSE;
  358.         memset(&input.mi, 0, sizeof(MOUSEINPUT));
  359.         input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP;
  360.         SendInput(1, &input, sizeof(input));
  361.         return 0;
  362.     }
  363.  
  364.     int MouseButton1Up(lua_State* L) {
  365.         INPUT input;
  366.         input.type = INPUT_MOUSE;
  367.         memset(&input.mi, 0, sizeof(MOUSEINPUT));
  368.         input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
  369.         SendInput(1, &input, sizeof(input));
  370.         return 0;
  371.     }
  372.  
  373.     int MouseButton2Up(lua_State* L) {
  374.         INPUT input;
  375.         input.type = INPUT_MOUSE;
  376.         memset(&input.mi, 0, sizeof(MOUSEINPUT));
  377.         input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
  378.         SendInput(1, &input, sizeof(input));
  379.         return 0;
  380.     }
  381. /* HttpGet yeet */
  382.     static int Lua_GetSite(lua_State* L) {
  383.         lua_pushstring(L, std::string(DownloadURL(lua_tostring(L, -1))).c_str());
  384.         return 1;
  385.     };
  386.  
  387.     static int MT__index(lua_State *L) {
  388.         std::string key = std::string(lua_tolstring(L, -1, NULL));
  389.         if (key == std::string("HttpGet")) {
  390.             lua_pushcfunction(L, Lua_GetSite);
  391.         }
  392.         else if (key == std::string("GetObjects")) {
  393.             lua_pushcfunction(L, Custom_GetObjects);
  394.         }
  395.         else {
  396.             push(L, m_rL, 1);
  397.             r_lua_getfield(m_rL, -1, key.c_str());
  398.             push(m_rL, L, -1);
  399.         };
  400.         return 1;
  401.     };
  402.  
  403.     int MT__newindex(lua_State *L) {
  404.         const char* key = lua_tostring(L, -2);
  405.         push(L, m_rL, -3);
  406.         push(L, m_rL, -1);
  407.         r_lua_setfield(m_rL, -2, key);
  408.         r_lua_pop(m_rL, 1);
  409.         return 1;
  410.     }
  411.  
  412.     int getgenv(lua_State *L) {
  413.         lua_pushvalue(m_L, LUA_GLOBALSINDEX);
  414.         Bridge::push(m_rL, L, -1);
  415.         return 1;
  416.     }
  417.  
  418.     int getreg(lua_State *L) {
  419.         lua_pushvalue(m_L, LUA_REGISTRYINDEX);
  420.         Bridge::push(m_rL, L, -1);
  421.         return 1;
  422.     }
  423.  
  424.     void RegisterCF(lua_State *L) {
  425.         lua_register(L, "wait", reinterpret_cast<lua_CFunction>(newwait));
  426.         lua_register(L, "spawn", reinterpret_cast<lua_CFunction>(newspawn));
  427.         lua_register(L, "clipboardset", (lua_CFunction)fn_toclipboard);
  428.         //lua_register(L, "loadfile", (lua_CFunction)loadfile);
  429.         lua_register(L, "getreg", getreg);
  430.         lua_register(L, "getgenv", getgenv);
  431.     }
  432.  
  433.     void AddFunction(lua_State* L, std::string Name, lua_CFunction function) {
  434.         lua_newtable(L);
  435.         lua_pushcfunction(L, function);
  436.         lua_setglobal(L, Name.c_str());
  437.         lua_settop(L, 0);
  438.     }
  439.  
  440.     void RegisterMT(lua_State *L) {
  441.         lua_newtable(L);
  442.         lua_pushcfunction(L, MT__index);
  443.         lua_setfield(L, -2, "__index");
  444.         lua_pushcfunction(L, MT__newindex);
  445.         lua_setfield(L, -2, "__newindex");
  446.         lua_pushstring(L, "The metatable is locked");
  447.         lua_setfield(L, -2, "__metatable");
  448.         lua_setfield(L, LUA_REGISTRYINDEX, "MetaTableMagic");
  449.     }
  450.  
  451.     void PushGlobal1(DWORD rL, lua_State* L, const char* s)
  452.     {
  453.         r_lua_getglobal(rL, s);
  454.         Bridge::push(rL, L, -1);
  455.         lua_setglobal(L, s);
  456.         r_lua_pop(rL, 1);
  457.     }
  458.  
  459. /* Ugh, i am David. These are all things that it loads i think.... Ya know more than me so ya prob know */
  460.         PushGlobal1(m_rL, L, "Axes");
  461.         PushGlobal1(m_rL, L, "BrickColor");
  462.         PushGlobal1(m_rL, L, "CFrame");
  463.         PushGlobal1(m_rL, L, "Color3");
  464.         PushGlobal1(m_rL, L, "ColorSequence");
  465.         PushGlobal1(m_rL, L, "ColorSequenceKeypoint");
  466.         PushGlobal1(m_rL, L, "NumberRange");
  467.         PushGlobal1(m_rL, L, "NumberSequence");
  468.         PushGlobal1(m_rL, L, "NumberSequenceKeypoint");
  469.         PushGlobal1(m_rL, L, "PhysicalProperties");
  470.         PushGlobal1(m_rL, L, "Ray");
  471.         PushGlobal1(m_rL, L, "Rect");
  472.         PushGlobal1(m_rL, L, "Region3");
  473.         PushGlobal1(m_rL, L, "Region3int16");
  474.         PushGlobal1(m_rL, L, "TweenInfo");
  475.         PushGlobal1(m_rL, L, "UDim");
  476.         PushGlobal1(m_rL, L, "UDim2");
  477.         PushGlobal1(m_rL, L, "Vector2");
  478.         PushGlobal1(m_rL, L, "Vector2int16");
  479.         PushGlobal1(m_rL, L, "Vector3");
  480.         PushGlobal1(m_rL, L, "Vector3int16");
  481.         PushGlobal1(m_rL, L, "Enum");
  482.         PushGlobal1(m_rL, L, "Faces");
  483.         PushGlobal1(m_rL, L, "Instance");
  484.         PushGlobal1(m_rL, L, "math");
  485.         PushGlobal1(m_rL, L, "warn");
  486.         PushGlobal1(m_rL, L, "typeof");
  487.         PushGlobal1(m_rL, L, "type");
  488.         PushGlobal1(m_rL, L, "spawn");
  489.         PushGlobal1(m_rL, L, "Spawn");
  490.         PushGlobal1(m_rL, L, "print");
  491.         PushGlobal1(m_rL, L, "printidentity");
  492.         PushGlobal1(m_rL, L, "ypcall");
  493.         PushGlobal1(m_rL, L, "Wait");
  494.         PushGlobal1(m_rL, L, "wait");
  495.         PushGlobal1(m_rL, L, "delay");
  496.         PushGlobal1(m_rL, L, "Delay");
  497.         PushGlobal1(m_rL, L, "tick");
  498.         PushGlobal1(m_rL, L, "LoadLibrary");
  499.     } */
  500.  
  501.     void SetUpMum(lua_State *L) {
  502.         PushGlobal1(m_rL, L, "game");
  503.         PushGlobal1(m_rL, L, "Game");
  504.         PushGlobal1(m_rL, L, "workspace");
  505.         PushGlobal1(m_rL, L, "Workspace");
  506.         RegisterMT(L);
  507.         RegisterRF(L);
  508.         RegisterCF(L);
  509.         /* Add function... Like wtf! Explain to me*/
  510.         AddFunction(L, "MouseButton1Up", MouseButton1Up);
  511.         AddFunction(L, "MouseButton2Up", MouseButton2Up);
  512.         AddFunction(L, "MouseButton1Down", MouseButton1Down);
  513.         AddFunction(L, "MouseButton2Down", MouseButton2Down);
  514.     }
  515. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement