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

Handle dwCreationDisposition in CreateFileA to fix PSYLINK #60

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

nocato
Copy link
Contributor

@nocato nocato commented Oct 26, 2023

Before this change, dwCreationDisposition parameter of CreateFileA was ignored by wibo. However, it turns out that PSYLINK.EXE in PsyQ 4.4 sometimes depends on correct handling of that parameter.

When building overlays with PSYLINK.EXE, it sometimes opens the resulting overlay file the second time, with OPEN_EXISTING creation disposition (as opposed to TRUNCATE_EXISTING). Before the change, wibo opened that file with fopen(..., "wb+") which truncated the file even though OPEN_EXISTING (non-truncating) was requested. This affected mgs_reversing, where one of the overlays (camera.bin) was built incorrectly when using wibo (worked correctly on Windows or with wine).

This PR adds proper handling of dwCreationDisposition parameter. The file now can be opened in truncating or non-truncating mode. Additionally, the implementation now reacts correctly to file existing/non-existing as specified by the requested creation disposition parameter. For example, if CreateFileA is called with OPEN_EXISTING and the file does not exist it will set an error and not create a new file (the previous behavior). If the file exists, it's opened in non-truncating mode, as TRUNCATE_EXISTING or CREATE_ALWAYS is required for truncation.

After the fix you can correctly build the whole mgs_reversing project with wibo - tools running under wibo: ASMPSX, ASPSX, CC1PSX 4.0 & 4.4, PSYLINK. I have NOT tested other executables apart from those.

Before this change, dwCreationDisposition parameter of CreateFileA was
ignored by wibo. However, it turns out that PSYLINK.EXE in PsyQ 4.4
sometimes depends on correct handling of that parameter.

When building overlays with PSYLINK.EXE, it sometimes opens the
resulting overlay file the second time, with OPEN_EXISTING creation
disposition (as opposed to TRUNCATE_EXISTING). Before the change,
wibo opened that file with fopen(..., "wb+") which truncated the file
even though OPEN_EXISTING (non-truncating) was requested. This affected
https://github.com/foxdieteam/mgs_reversing, where one of the overlays
(camera.bin) was built incorrectly when using wibo (worked correctly
on Windows or with wine).

This commit adds proper handling of dwCreationDisposition parameter.
The file now can be opened in truncating or non-truncating mode.
Additionally, the implementation now reacts correctly to file
existing/non-existing as specified by the requested creation disposition
mode. For example, if CreateFileA is called with OPEN_EXISTING and the
file does not exist it will set an error and not create a new file
(the previous behavior). If the file exists, it's opened in
non-truncating mode, as TRUNCATE_EXISTING or CREATE_ALWAYS is required
for truncation.

After the fix you can correctly build the whole mgs_reversing project
with wibo - tools running under wibo: ASMPSX, ASPSX, CC1PSX 4.0 & 4.4,
PSYLINK. I have NOT tested other executables apart from those.
@ethteck ethteck merged commit c6fa592 into decompals:main Oct 27, 2023
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants