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

Force _WIN32_WINNT variable #770

Merged
merged 14 commits into from
Oct 1, 2024

Conversation

Gazyi
Copy link
Contributor

@Gazyi Gazyi commented Aug 22, 2024

Fixes #612.
Compiled on Win 10, launches and works fine on Win 7.

CMakeLists.txt Outdated Show resolved Hide resolved
@GeckoEidechse GeckoEidechse added needs testing Changes from the PR still need to be tested needs code review Changes from PR still need to be reviewed in code labels Aug 23, 2024
@p0358
Copy link
Contributor

p0358 commented Aug 23, 2024

This should be fine tbh probably, as long as it doesn't break newer Windowses (also shouldn't).

Although ngl a cleaner solution would probably to define a shim for CreateFile2 that'd in turn call CreateFileW instead with the right params, as chances are this might be the only cause and place it breaks. Then our own CreateFile2 replacement would be used instead of linking it from Windows... This would be simpler and less risky of potential unknown breakage somewhere else.

@p0358
Copy link
Contributor

p0358 commented Aug 23, 2024

Also also also also: zlib-ng/minizip-ng@9829913

You should create an issue in the original repo mentioning that since they don't do a check for WinRT API anymore at all, they should just junk that check before CreateFile2 and simply just use CreateFileW, there's ZERO reason for them to use CreateFile2 now to begin with (apart from old limited WinRT API that isn't checked for anymore?), especially that they DON'T use the last LPCREATEFILE2_EXTENDED_PARAMETERS pCreateExParams param of CreateFile2, passing NULL there, meaning they literally could just use CreateFileW...

@p0358
Copy link
Contributor

p0358 commented Aug 23, 2024

As for the shim func, just do this:

HANDLE CreateFile2(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, LPCREATEFILE2_EXTENDED_PARAMETERS pCreateExParams)
{
    return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, NULL, NULL);
}

@p0358
Copy link
Contributor

p0358 commented Aug 23, 2024

And actually, if we go this way (of this PR), it would be preferred to have this define set only when compiling the actual files of minizip library itself, instead of applying it to main project and all children...

@Gazyi
Copy link
Contributor Author

Gazyi commented Aug 23, 2024

I found a way to define variable only for Minizip lib.

As for the shim func, just do this:

HANDLE CreateFile2(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, LPCREATEFILE2_EXTENDED_PARAMETERS pCreateExParams)
{
    return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, NULL, NULL);
}

I'm not sure where to do that. Should it be a WinAPI hook or something else?

@p0358
Copy link
Contributor

p0358 commented Aug 24, 2024

I'm not sure where to do that. Should it be a WinAPI hook or something else?

Technically in any file that's getting compiled in, and that should then cause it to be linked (I'm hoping the linker won't complain about symbol duplication though...). As for particular place, perhaps a new file under /primedev/windows/?

Copy link
Contributor

@ASpoonPlaysGames ASpoonPlaysGames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine as far as I'm aware. I'm no expert on this topic though.

@ASpoonPlaysGames ASpoonPlaysGames added almost ready to merge Apart from any small remaining other issues addressed by other labels, this would be ready to merge and removed needs code review Changes from PR still need to be reviewed in code labels Sep 7, 2024
Copy link
Contributor

@p0358 p0358 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine imo with this method, where the variable is limited just to the dependent library and thus limits possible impact of side effects its definition might had otherwise imposed in main project. I assume that the PR author checked that it still works on Win7 with the latter changes xd

@Gazyi
Copy link
Contributor Author

Gazyi commented Sep 8, 2024

This is fine imo with this method, where the variable is limited just to the dependent library and thus limits possible impact of side effects its definition might had otherwise imposed in main project. I assume that the PR author checked that it still works on Win7 with the latter changes xd

Current main branch build is working fine.

@GeckoEidechse
Copy link
Member

For testing, I assume just join a server that requires a mod through MAD and make sure it extracts correctly, right?

@p0358
Copy link
Contributor

p0358 commented Sep 9, 2024

Yeah you might do that. But original issue was with linking and bailing out on missing symbol. So just ensuring the game still starts up to begin with on Win10 is enough. If you don't test on actual Win7, then check with some tool like Detect-It-Easy or whatever else (PE Explorer etc) whether in Imports section from iirc kernel32.dll whether there's just CreateFile and not CreateFile2. For extra scrutiny you can confirm that CreateFile2 import is there on DLL before this PR is applied

@GeckoEidechse GeckoEidechse changed the title Force _WIN32_WINNT variable. Force _WIN32_WINNT variable Sep 30, 2024
@Alystrasz
Copy link
Contributor

Alystrasz commented Oct 1, 2024

For testing, I assume just join a server that requires a mod through MAD and make sure it extracts correctly, right?

Btw, I tested joining a server with mad and this PR, and everything went fine.

@GeckoEidechse
Copy link
Member

Aight given that this appears to have no effect on newer Windows versions then, I'm fine with merging this even if we don't support older Windows version.

The suggested solution for issues with older Windows versions is of course to switch to Linux update to a supported Windows version, however I also don't see a need to actively oppose a community contribution, given that it has no (negative) effect on supported platforms.

@GeckoEidechse GeckoEidechse changed the title Force _WIN32_WINNT variable Force _WIN32_WINNT variable Oct 1, 2024
@GeckoEidechse GeckoEidechse removed needs testing Changes from the PR still need to be tested almost ready to merge Apart from any small remaining other issues addressed by other labels, this would be ready to merge labels Oct 1, 2024
@GeckoEidechse GeckoEidechse merged commit 71349f0 into R2Northstar:main Oct 1, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
5 participants