TexlzAye

Untitled

Jul 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. int CopyString(lua_State *Ls) {
  2. const char* str = lua_tostring(Ls, -1);
  3.  
  4. int len = strlen(str);
  5. HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len + 1);
  6. void *mem_ptr = GlobalLock(hMem);
  7. memcpy(mem_ptr, str, len + 1);
  8. GlobalUnlock(hMem);
  9. OpenClipboard(NULL);
  10. EmptyClipboard();
  11. SetClipboardData(CF_TEXT, hMem);
  12. CloseClipboard();
  13. return 0;
  14. }
  15.  
  16. void GetFile(const char* dllName, const char* fileName, char* buffer, int bfSize) {
  17. GetModuleFileName(GetModuleHandle(dllName), buffer, bfSize);
  18. if (strlen(fileName) + strlen(buffer) < MAX_PATH) {
  19. char* pathEnd = strrchr(buffer, '\\');
  20. strcpy(pathEnd + 1, fileName);
  21. }
  22. else {
  23. *buffer = 0;
  24. }
  25. }
  26.  
  27. int luawritefile(lua_State* r_lua_State) {
  28. const char * nameoffile = lua_tostring(r_lua_State, -1);
  29. const char * contentsoffile = lua_tostring(r_lua_State, -2);
  30.  
  31. char path[MAX_PATH];
  32. GetFile("Chaosity.dll", "", path, MAX_PATH);
  33.  
  34. std::string Lean;
  35. Lean += path;
  36. Lean += "Scripts\\";
  37. Lean += contentsoffile;
  38.  
  39. std::ofstream o(Lean.c_str());
  40.  
  41. return 1;
  42. }
  43.  
  44. int custom_readfile(lua_State* r_lua_State) {
  45. const char * nameoffile = lua_tostring(r_lua_State, -1);
  46.  
  47. char path[MAX_PATH];
  48. GetFile("Chaosity.dll", "", path, MAX_PATH);
  49.  
  50. std::string file;
  51. file += path;
  52. file += "Workspace\\";
  53. file += nameoffile;
  54.  
  55. printf(file.c_str());
  56.  
  57. string line;
  58. ifstream myfile(file);
  59. if (myfile.is_open())
  60. {
  61. while (getline(myfile, line))
  62. {
  63. lua_pushstring(r_lua_State, line.c_str());
  64. }
  65. myfile.close();
  66. }
  67.  
  68. return 1;
  69. }
  70.  
  71. static int custom_runfile(lua_State *lua_State) {
  72. const char * name = r_lua_tolstring(m_rL, -1, 0);
  73.  
  74. char path[MAX_PATH];
  75. GetFile("Chaosity.dll", "", path, MAX_PATH);
  76.  
  77. std::string file;
  78. file += path;
  79. file += "Workspace//";
  80. file += name;
  81.  
  82. std::ifstream swfile(file);
  83. std::string line;
  84.  
  85. if (swfile.is_open())
  86. {
  87. while (getline(swfile, line))
  88. {
  89. Wrapped(line);
  90. }
  91. swfile.close();
  92. }
  93.  
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment