#include <Windows.h>
#include <iostream>
#include <string>
#include <sstream>

// Function to inject Lua script into Roblox process
void injectLuaScript(DWORD processId, const std::string& script) {
    // Open the target process
    HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
    if (processHandle == NULL) {
        std::cerr << "Failed to open process. Error code: " << GetLastError() << std::endl;
        return;
    }

    // Allocate memory for the Lua script in target process
    LPVOID scriptAddress = VirtualAllocEx(processHandle, NULL, script.size() + 1, MEM_COMMIT, PAGE_READWRITE);
    if (scriptAddress == NULL) {
        std::cerr << "Failed to allocate memory in target process. Error code: " << GetLastError() << std::endl;
        CloseHandle(processHandle);
        return;
    }

    // Write the Lua script to allocated memory
    if (!WriteProcessMemory(processHandle, scriptAddress, script.c_str(), script.size() + 1, NULL)) {
        std::cerr << "Failed to write Lua script to target process. Error code: " << GetLastError() << std::endl;
        VirtualFreeEx(processHandle, scriptAddress, 0, MEM_RELEASE);
        CloseHandle(processHandle);
        return;
    }

    // Get the address of the Roblox Lua state
    HMODULE robloxModule = GetModuleHandleA("RobloxPlayerBeta.exe");
    if (robloxModule == NULL) {
        std::cerr << "Failed to get Roblox module handle. Error code: " << GetLastError() << std::endl;
        VirtualFreeEx(processHandle, scriptAddress, 0, MEM_RELEASE);
        CloseHandle(processHandle);
        return;
    }

    // Get the address of the Lua state
    uintptr_t luaStateAddress = reinterpret_cast<uintptr_t>(robloxModule) + 0x023F0EB0;

    // Create remote thread to execute Lua script
    HANDLE remoteThread = CreateRemoteThread(processHandle, NULL, 0, 
        reinterpret_cast<LPTHREAD_START_ROUTINE>(luaStateAddress), scriptAddress, 0, NULL);
    if (remoteThread == NULL) {
        std::cerr << "Failed to create remote thread. Error code: " << GetLastError() << std::endl;
        VirtualFreeEx(processHandle, scriptAddress, 0, MEM_RELEASE);
        CloseHandle(processHandle);
        return;
    }

    // Wait for the remote thread to finish
    WaitForSingleObject(remoteThread, INFINITE);

    // Clean up
    CloseHandle(remoteThread);
    VirtualFreeEx(processHandle, scriptAddress, 0, MEM_RELEASE);
    CloseHandle(processHandle);

    std::cout << "Lua script injected and executed successfully." << std::endl;
}

// Window procedure function
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    static HWND hEdit;

    switch (uMsg) {
        case WM_CREATE: {
            // Create "Inject" button
            CreateWindowW(L"Button", L"Inject", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
                          10, 10, 100, 30, hwnd, (HMENU)1, NULL, NULL);

            // Create text box for Lua code input
            hEdit = CreateWindowW(L"Edit", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_VSCROLL,
                                  10, 50, 260, 100, hwnd, (HMENU)2, NULL, NULL);
            break;
        }
        case WM_COMMAND: {
            if (LOWORD(wParam) == 1) {
                // Get Lua code from text box
                int textLength = GetWindowTextLength(hEdit);
                std::wstring scriptBuffer;
                scriptBuffer.resize(textLength + 1);
                GetWindowText(hEdit, &scriptBuffer[0], textLength + 1);
                std::string script(scriptBuffer.begin(), scriptBuffer.end());

                // Get process ID of Roblox
                DWORD processId; // You need to implement this part to get the process ID of Roblox

                // Inject Lua script into Roblox process
                injectLuaScript(processId, script);
            }
            break;
        }
        case WM_DESTROY: {
            // Close the window and exit the application
            PostQuitMessage(0);
            break;
        }
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}

// Entry point of the program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    // Register window class
    WNDCLASS wc = {};
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.lpszClassName = L"InjectorWindowClass";

    RegisterClass(&wc);

    // Create the window
    HWND hwnd = CreateWindowEx(0, L"InjectorWindowClass", L"Roblox Lua Script Injector",
                               WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
                               300, 200, NULL, NULL, hInstance, NULL);

    if (hwnd == NULL) {
        return 0;
    }

    // Show the window
    ShowWindow(hwnd, nCmdShow);

    // Run the message loop
    MSG msg = {};
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}
 
by

C++ Online Compiler

Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!

Read inputs from stdin

OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string name;
    cout << "Enter name:";
    getline (cin, name);
    cout << "Hello " << name;
    return 0;
}

About C++

C++ is a widely used middle-level programming language.

  • Supports different platforms like Windows, various Linux flavours, MacOS etc
  • C++ supports OOPS concepts like Inheritance, Polymorphism, Encapsulation and Abstraction.
  • Case-sensitive
  • C++ is a compiler based language
  • C++ supports structured programming language
  • C++ provides alot of inbuilt functions and also supports dynamic memory allocation.
  • Like C, C++ also allows you to play with memory using Pointers.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition If-Else is used.

if(conditional-expression) {
   //code
}
else {
   //code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression){    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
......    
    
default:     
 code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  //code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
// code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
 // code 
} while (condition); 

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.

How to declare a Function:

return_type function_name(parameters);

How to call a Function:

function_name (parameters)

How to define a Function:

return_type function_name(parameters) {  
 // code
}