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

AttachConsole over AllocConsole #11

Open
JustArion opened this issue Jul 10, 2024 · 0 comments
Open

AttachConsole over AllocConsole #11

JustArion opened this issue Jul 10, 2024 · 0 comments

Comments

@JustArion
Copy link

Hi, in ModLoader.cpp#L135 BOOL AllocConsole is called.

An alternate proposal is to call BOOL AttachConsole first, then if that fails call AllocConsole.

The reasoning behind this is that you can launch the game from the CLI and the Console Data will be sent to the Console who started the game (if any) instead of making a new console on launch.

You can attach to the parent process by calling AttachConsole(ATTACH_PARENT_PROCESS);
The function returns true on success, and false if there's no parent console (eg. the user double-clicked the program and launched it)

The proposed change can be made like this:

void ModLoader::OpenTerminal()
{
    if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
    {
        freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
        SetWindowText(GetConsoleWindow(), "Elden Mod Loader");
    }
}
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

1 participant