Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with IClientUser::SpawnProcess #13

Open
devilExE3 opened this issue Dec 29, 2023 · 2 comments
Open

Help with IClientUser::SpawnProcess #13

devilExE3 opened this issue Dec 29, 2023 · 2 comments

Comments

@devilExE3
Copy link

Hello, I would like to start by saying nice fork, thanks for keeping it up to date.

The issue i'm currently facing is that i can't get IClientUser::SpawnProcess to work for the life of me.

If anyone can please look at my code and tell my what I did wrong, or what I'm missing, please tell me.

    IClientShortcuts* clientShortcuts = m_clientEngine->GetIClientShortcuts(hSteamUser, hSteamPipe);
    uint32_t appId = clientShortcuts->GetUniqueLocalAppId();
    uint32_t parentAppId = 243750;
    uint64_t gameId = 0xD8A9994402000000 | parentAppId; // 'cfx' crc32 + shortcut
    std::cout << "[parent] " << appId << ' ' << parentAppId << ' ' << gameId << std::endl;

    IClientApps* clientApps = m_clientEngine->GetIClientApps(hSteamUser, hSteamPipe);
    KeyValuesBuilder builder;
    builder.PackString("name", "Muck.NET");
    builder.PackUint64("gameid", gameId);
    builder.PackString("installed", "1");
    builder.PackString("gamedir", "cfx");
    builder.PackString("serverbrowsername", "lovely!");
    builder.PackEnd();

    std::string str = builder.GetString();
    bool ok = clientApps->SetLocalAppConfig(appId, (uint8_t*)str.c_str(), str.size());
    if (ok)
    {
        std::cout << "[parent] " << "Config Set OK" << std::endl;
        IClientUtils* clientUtils = m_clientEngine->GetIClientUtils(hSteamPipe);

        // set pipe appid
        clientUtils->SetAppIDForCurrentPipe(parentAppId, false);
        std::cout << "[parent] " << "AppId set for current pipe" << std::endl;

        IClientUser* clientUser = m_clientEngine->GetIClientUser(hSteamUser, hSteamPipe);

        wchar_t directory[MAX_PATH];
        GetCurrentDirectoryW(sizeof(directory), directory);
        std::wstring process(directory);
        process.append(L"\\Test Platform.exe");
        std::wstringstream cmdwss;
        cmdwss << '"' << process << "\" child " << parent_parentPID;
        std::wstring cmd = cmdwss.str();
        
        std::wcout << "[parent] " << directory << std::endl;
        std::wcout << "[parent] " << process.c_str() << std::endl;
        std::wcout << "[parent] " << cmd.c_str() << std::endl;

        std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;

        if(clientUser->SpawnProcess(converter.to_bytes(process).c_str(), converter.to_bytes(cmd).c_str(), converter.to_bytes(directory).c_str(), &gameId, "Muck.NET", 0, 0, 0))
            std::cout << "[parent] " << "Process Spawned" << std::endl;
        else {
            std::cout << "[parent] " << "SpawnProcess returned false" << std::endl;
        }
    }

This code is mostly copied from the FiveM repository, here

Thanks to anyone reading and trying to help me.

@m4dEngi
Copy link
Owner

m4dEngi commented Dec 29, 2023

This fork is a bit out of date atm, maybe that's the reason why it doesn't work as expected...

@devilExE3
Copy link
Author

I've managed to get it working by implementing method lookup via name, as the cfx.re team did in their repo.
Also to be noted when i call it with the current signature it returns false, it works when calling with

([thisPtr,] converter.to_bytes(process).c_str(), converter.to_bytes(cmd).c_str(), 0, converter.to_bytes(directory).c_str(), gameId, "Muck.NET", 0, 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants