NorthstarLauncher icon indicating copy to clipboard operation
NorthstarLauncher copied to clipboard

Fix LSX error for good

Open p0358 opened this issue 1 year ago • 16 comments

  • fixes LSX error for good by adding EAConnectionId environment variable if it's missing, I confirmed this alone is enough to mitigate the LSX error, as I was lucky enough to have it occur 100% of the time when using NorthstarLauncher.exe :)
    • this method of checking environment variable existence is attested by Microsoft Docs, arguments to GetEnvironmentVariableA are nullptr and 0 as we aren't interested in the old value, these arguments are optional and thus can be set to these values
    • I didn't use getenv as the compiler would mutilate me for using "unsafe" function, and getenv_s requires taking output, so the method above is better
    • (void) cast is used on _putenv to explicitly discard the return value and avoid compiler warning
    • wsock and launcher proxy don't set this, as they're expected to be used with executable that's ran from within Origin and has always the environment variable pre-set, this only applies to NorthstarLauncher.exe
    • the actual value of EAConnectionId interestingly seems irrelevant, I could enter some random text in it and it would still mitigate the LSX error, it appears it just needs to exist and not be empty
  • ~~set current working directory to the exe path -- this is normally expected to be set to that, but under certain circumstances where you create a shortcut to NorthstarLauncher.exe or otherwise use non-direct method of launching it (3rd party game launchers etc), the working directory might have been wrong, causing issues like the log file being attempted to be written in another location, due to use of relative paths~~ --> moved to #275
  • ~~catch an error when log file cannot be created instead of silently crashing, which can happen if the path isn't writable and confuse the user (after the MessageBox is shown, the game will continue launching, as non-writable log file isn't a fatal issue)~~ --> moved to #274

After merging can consider https://github.com/R2Northstar/Northstar/issues/220 obsolete. Of course I tested all these changes and they behave as expected.

p0358 avatar Sep 15 '22 13:09 p0358

Uh, wait, I noticed some issues with the first change, don't merge it yet xd Perhaps I should have split them into two PRs ergh

p0358 avatar Sep 15 '22 14:09 p0358

NVM the fix is all good, the issue I had was on my PC only and was related to outdated DNS xD Free to merge

p0358 avatar Sep 15 '22 14:09 p0358

No more tickets on Discord!!!! (real)

x3Karma avatar Sep 15 '22 18:09 x3Karma

Also would like to note that the amount of detail given in this PR is great :)

ASpoonPlaysGames avatar Sep 15 '22 18:09 ASpoonPlaysGames

Well, definitely not due to my changes, as the code for LSX: connect() is called before my changes. Does this stuck always happen or only randomly now? Did it eventually get unstuck when Origin finished opening or not?

The socket connection being stuck on LSX port might be an Origin issue and require an unrelated refactor to the waiting function... As it stands, if it turns out to be buggy like here, one could consider using it only if EADesktop.exe is running and OriginClientService.exe is not, as according to the comments in code the latter running is enough to launch the game successfully...

p0358 avatar Sep 19 '22 00:09 p0358

Well, definitely not due to my changes, as the code for LSX: connect() is called before my changes. Does this stuck always happen or only randomly now? Did it eventually get unstuck when Origin finished opening or not?

Seems to be consistent. LSX: connect() is from this PR AFAIK #263

GeckoEidechse avatar Sep 19 '22 00:09 GeckoEidechse

Can you insert some extra log lines around those parts?

https://github.com/R2Northstar/NorthstarLauncher/blob/ebb4bd4ef099d77b0bf4dcbf63b0862fb58c29e8/NorthstarLauncher/main.cpp#L353-L361

For example:

	if (!noOriginStartup && !dedicated)
	{
		EnsureOriginStarted();
	}
	std::cout << "Before GetEnvironmentVariableA" << std::endl;
	// ensure no LSX error
	GetEnvironmentVariableA("EAConnectionId", nullptr, 0);
	std::cout << "Before GetLastError" << std::endl;
	if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
		std::cout << "Before _putenv" << std::endl;
		(void)_putenv("EAConnectionId=Origin.OFR.50.0001452");
		std::cout << "After everything" << std::endl;
}

p0358 avatar Sep 19 '22 00:09 p0358

Then if "Before GetEnvironmentVariableA" isn't printed, it would mean it's stuck on connecting and that it 100% wouldn't be related to my changes. And if that was the case, you'd need to temporarily comment out AwaitOriginStartup(); and then compare if my changes help against LSX error, nothing that AwaitOriginStartup in such case would need a refactor due to unrelated hang issue on connect.

In either case, AwaitOriginStartup has insufficient logging, you don't know if it's stuck on connect, on awaiting data, or finished successfully...

p0358 avatar Sep 19 '22 00:09 p0358

Then if "Before GetEnvironmentVariableA" isn't printed, it would mean it's stuck on connecting and that it 100% wouldn't be related to my changes.

Yup, it doesn't get printed.

And if that was the case, you'd need to temporarily comment out AwaitOriginStartup(); and then compare if my changes help against LSX error

Commenting out AwaitOriginStartup(); I'm back to LSX error again (:

screenshot

GeckoEidechse avatar Sep 20 '22 23:09 GeckoEidechse