induktio / thinker

Improved game engine features for SMACX.
https://discord.gg/XdFuwWzzku
GNU General Public License v2.0
75 stars 10 forks source link

thinker.exe launcher doesn't work reliably on Windows 10/11 #38

Closed ghost closed 1 year ago

ghost commented 2 years ago

The game intermittently fails to start when using the launcher app. When it does start, it will not always respect flags (tested with the -smac flag), too. I've tested this on a Windows 10 and 11 PC and both have the issue.

Somewhat of a fix is to set Windows XP compatibility mode on terranx.exe. The game will reliably start every time, but it will sometimes start in 1024x768 resolution instead of native resolution, even with DirectDraw=0 set. Compatibility mode doesn't fix the flag issue.

induktio commented 2 years ago

Thanks for noting this issue. There's been some reports of startup problems when using the launcher in Windows 10/11. In the future I'll add some mention of the compatiblity mode fix in the readme too. Another possible workaround for now is to use terranx_mod.exe from earlier releases and combine it with the newest thinker.dll version. They are still compatible, but this is not guaranteed to be the case in the future.

It's possible that the compatibility mode "forces" the resolution to 1024x768 and the game isn't supplied the actual native resolution provided by the system in this case. There might some way to work around this, but I'm not sure now.

ghost commented 2 years ago

After more testing, I think the problem is related to the DirectDraw setting that you've added to thinker.ini. I added DirectDraw=0 manually to Alpha Centauri.ini and has no more incorrect resolution starts. I then removed compatibility mode from terranx and the game started correctly every time about 10 times in a row. Circumstantially, the times that terranx in XP compatibility mode would start with the wrong resolution felt like the same frequency that the game wouldn't start at all without compatibility mode.

induktio commented 2 years ago

So that's where the 1024x768 resolution came from then? The custom resolution setting in thinker.ini wont be used unless you set windowed=1. But it's possible this is also the same value than in some Windows XP compatibility mode implementation.

Also the default setting in thinker.ini should be DirectDraw=0. I have to emphasize this setting overrides any value in Alpha Centauri.ini. You need to comment out or remove this line from thinker.ini if you want to use the value in Alpha Centauri.ini. By default the mod should start in native desktop resolution instead of that DirectX mode.

ghost commented 2 years ago

To clarify, all of my testing for the game not starting/resolution issue has been done on a fresh install of SMACX with Thinker 3.1 applied. I've made no changes whatsoever to the defaults.

So that's where the 1024x768 resolution came from then? The custom resolution setting in thinker.ini wont be used unless you set windowed=1. But it's possible this is also the same value than in some Windows XP compatibility mode implementation.

Do you mean the resolution settings for windowed mode? I thought of this, too, so I changed those values to my screen's native resolution just to be sure. The game would still occasionally start in 1024x768. Needless to say, I didn't enable windowed mode.

Also the default setting in thinker.ini should be DirectDraw=0. I have to emphasize this setting overrides any value in Alpha Centauri.ini. You need to comment out or remove this line from thinker.ini if you want to use the value in Alpha Centauri.ini. By default the mod should start in native desktop resolution instead of that DirectX mode.

Just to repeat from above, the bug is on a completely unaltered install with Thinker applied. I'm not saying I want to use Alpha Centauri.ini, I'm saying that adding DirectDraw=0 to it completely resolves the issue. That is why I suspect something about the DirectDraw setting in thinker.ini is the problem. Here are the various combinations I've tried and their results:

I did further testing today that also indicates some issue with DirectDraw in thinker.ini:

All tests were done on both Windows 10 and 11. Let me know if there are any specifics you need to know about my installs that might help.

induktio commented 2 years ago

The wording is a little bit confusing when you say "adding DirectDraw=0" when that should be the default in the config, e.g. it's already there. That was my point. The other behaviour you described with those default settings (DirectDraw=0) have been confirmed in some other player reports too. It's just a little difficult to figure out the actual issue when I currently don't have that version of Windows installed.

ghost commented 2 years ago

Oh yeah, I'm not talking about adding DirectDraw=0 to thinker.ini. It never appears on its own in Alpha Centauri.ini, though. Is it supposed to?

Darrheadjones commented 2 years ago

I just wanted to say that I was running into a similar issue in Windows 10 (~50% or more of the time the game would launch in 1024x768 rather than native). Writing in "DirectDraw=0" in the Alpha Centauri.ini and running it without compatibility mode solved it for me.

induktio commented 2 years ago

As a workaround you can try to use the older launcher version to see if it works better on Win 10. It's the same binary that was present in the older releases. You just need to copy terranx_mod.exe from the zip and use it with the newest thinker.dll and related config files. Unless you have specific problems with the startup, this older launcher should not be needed anymore. This is just a temporary solution, but I don't have any other fix at this time.

induktio commented 2 years ago

Okay, revisiting issue once again since I tested the game with Windows 10. Downloaded Windows 10 Pro build 21H2 from Microsoft website and installed it on VirtualBox. Note that if you want to download the Windows ISO, you need to visit that site with a browser that has a non-Windows UserAgent. I didn't adjust Windows settings meaningfully from the default values when I did this test except installing VirtualBox guest additions.

Using Thinker v3.1 and v3.0 seemed to work flawlessly when I started the mod from a desktop shortcut for thinker.exe. I didn't notice any issues when double clicking the launcher icon and I didn't manually activate any Windows XP compatibility mode either. As of now it seems I can't replicate the error condition that was described here. If you can provide some additional information on what actually triggers the issues on Win 10, that would be helpful.

S-W-N commented 1 year ago

Can confirm the issue on Win10 21H2 19044.2251 + fresh gog install. Using smac option in ini.

thinker.exe run result is random each program start and the possibilities are:

  1. SMACX menu in low res. alt+T does not work. After starting game, ctrl+F4 says thinker mod.
  2. SMACX menu in high res. alt+T works.
  3. SMAC menu in high res. alt+T works.

If you can log early enough I don't mind testing with such option. You probably should not instruct people to use ctrl+F4 check, and stick with alt+T test only.

Edit: So most likely a timing or threading issue. Sprinkling some well placed sleeps might help for both.

induktio commented 1 year ago

Okay, I don't have any other information on how the issue might relate to threading. This is probably not related to the earlier cpu fix patch added in Thinker, but we could check for it. Try to start the mod with config parameter cpu_idle_fix=0 and see if anything changes?

Also if some of you have Windows Defender enabled, you might try disabling it before starting the mod. It's possible some of its heuristics or background checks might interfere with binaries that are not signed. It might be related to the startup issue.

S-W-N commented 1 year ago

Disabling cpu fix does not change this issue. Note though that cpu fix seems to get applied in all cases, at least based on a rough task manager check. Would it be possible to add a 100ms sleep or so between patching and main game execution..?

Tested adding all game files to windows virus exception list or whatever, but it changes nothing. Would be a bit odd if such had a random effect though.

induktio commented 1 year ago

Hmm, cpu fix patch seems to be unrelated as expected. It's certainly possible to modify the launcher program to add a small delay before the game executable is launched. It might be possible the current implementation creates some race condition in the patching process where it might not work reliably, although I tried to check the behaviour from MS documents, but the wording there was slightly ambigious related to some API calls. If you have the compiler environment ready, it's enough to add one line Sleep(50); in launch.cpp before it calls ResumeThread which begins game execution. Was this the thing you meant? I could also add that change to the next develop build.

S-W-N commented 1 year ago

Yep, that's the spot that I was thinking, although I'm not really familiar with these particularities.

Yeah, I could test the development build if you make that change. Dev environment setups are a bit of a pain usually.

induktio commented 1 year ago

I added the extra calls in thinker.exe in the latest build. The filename is Thinker-dev-20221127.zip. Let us know if the launcher works any differently. As an unrelated change, the mod also now displays the remaining infiltration turns when the probe team action window opens. SMAC in SMACX mod help files were also updated in many places.

S-W-N commented 1 year ago

I just took the new launcher exe from the zip. Simply put, this fixed the issue.

induktio commented 1 year ago

Hopefully this simple fix is enough for this problem. Looks like some Windows versions had different API call implementations there. If there are other users with Windows 10/11 who previously had this issue, would be interesting to know if the issue is now fixed in all Windows versions.

Mjnd commented 1 year ago

Windows 10 Enterprise LTSC user here. The first launch was still affected by the unreliable behavior, but any subsequent launch worked reliably. I guess in the first launch, the loading delay has introduced a lag that reestablished the race condition. Anyway for me the issue is fixed too.

induktio commented 1 year ago

Hmm, the issue where the launcher doesn't work reliably on the first try was reported earlier by users before this recent fix. So I doubt the patch actually caused that. It is probably caused by some unrelated factor and/or the patch didn't change it. But if you say the launcher works reliably on the second try, that's probably good enough for now. Minor inconvenienve and does not prevent from playing the game. Currently the docs also mention using XP compatiblity mode in case of problems, but this might be obsolete advice. I wonder did anybody actually need the XP mode to run the game?

Mjnd commented 1 year ago

I agree the last patch has nothing to do with the first launch issue; I reported it because I failed to read about this specific behaviour. I have never needed XP compatibility mode, the only change I applied is that the shortcut has to be set to be executed as administrator (which caused me a little trouble the first time I tried Thinker Mod, because the game failed to start but the error message was not helpful; it could be because I installed Alpha Centauri in "C:\Program Files (x86)\Sid Meier's Alpha Centauri" and maybe special permissions for that directory are required).

S-W-N commented 1 year ago

Had a single start with corrupted patching (certainly due to timing). It is of course hard to say if there have been partially patched starts that just don't produce easily visible issues.

induktio commented 1 year ago

In what way do you think it's caused by timing? What kind of issue did it cause? DLL initialization should be serialized so I'm not sure how it could happen there. It might also be some other process or setting in Windows 10 interfering with loading. These kind of issues would have to be reproducible to be able to do something on it.

induktio commented 1 year ago

There's one issue that is confirmed however. If you install the game on a folder that requires admin rights to modify (usually those under C: drive), you must start thinker.exe as an administrator or else the startup will fail. This can be modified from thinker.exe Properties > Compatibility > Run this program as an administrator. You probably don't have to do this if the game is installed on some other drive. The error message could be changed to something more descriptive though. I guess the game installer by default assumes terranx.exe will be started with elevated privileges, so it might not be possible to avoid that in all cases.

S-W-N commented 1 year ago

Oh I simply mean getting the SMACX starting screen in low resolution once. Given that the sleep greatly reduces the probability of this happening and that it is random by nature, it's obvious that at least for my system the patching and execution happen simultaneously. Which in turn could mean the exe may be partially patched when executed. Could the changes made in one thread not always (yet) be visible in the execution thread? I dunno. But I know you can't quite trust microsoft code to work correctly.

induktio commented 1 year ago

Uploaded a new build with some useful changes.