Skip to content

Commit

Permalink
feat: Added File::OpenFor::ReadWrite
Browse files Browse the repository at this point in the history
fix: Fixed std::span returned by memory_map being improperly sized

This fixes a problem with FileHandle::memory_map where it was impossible to successfully memory map a file if it was opened using File::open with any value other than OpenFor::Reading.
  • Loading branch information
UE4SS authored and Buckminsterfullerene02 committed May 19, 2024
1 parent c82f9bc commit d8189f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions assets/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Failing to do so will cause a crash when you try to render something with imgui.

BREAKING: Changed `FTransform` constructor to be identical to unreal.

Added `OpenFor::ReadWrite`, to be used when calling `File::open`.
This can be used when calling `FileHandle::memory_map`, unlike `OpenFor::Writing`. ([UE4SS #507](https://github.com/UE4SS-RE/RE-UE4SS/pull/507))

### BPModLoader

### Experimental
Expand Down Expand Up @@ -96,6 +99,8 @@ Fixed crash when calling UFunctions that take one or more 'out' params of type T
### C++ API
Fixed a crash caused by a race condition enabled by C++ mods using `UE4SS_ENABLE_IMGUI` in their constructor ([UE4SS #481](https://github.com/UE4SS-RE/RE-UE4SS/pull/481))

Fixed the `std::span` returned by `FileHandle::memory_map` being improperly sized. ([UE4SS #507](https://github.com/UE4SS-RE/RE-UE4SS/pull/507))

### BPModLoader
Fixed "bad conversion" errors ([UE4SS #398](https://github.com/UE4SS-RE/RE-UE4SS/pull/398))

Expand Down
1 change: 1 addition & 0 deletions deps/first/File/include/File/Enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace RC::File
Writing,
Appending,
Reading,
ReadWrite,
};

enum class OverwriteExistingFile
Expand Down
8 changes: 6 additions & 2 deletions deps/first/File/src/FileType/WinFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ namespace RC::File
{
case OpenFor::Writing:
case OpenFor::Appending:
case OpenFor::ReadWrite:
handle_desired_access = PAGE_READWRITE;
mapping_desired_access = FILE_MAP_WRITE;
break;
Expand All @@ -516,8 +517,8 @@ namespace RC::File
}

MEMORY_BASIC_INFORMATION buffer{};
auto size = VirtualQuery(m_memory_map, &buffer, sizeof(decltype(buffer)));
return std::span(m_memory_map, size);
VirtualQuery(m_memory_map, &buffer, sizeof(decltype(buffer)));
return std::span(m_memory_map, buffer.RegionSize);
}

auto WinFile::open_file(const std::filesystem::path& file_name_and_path, const OpenProperties& open_properties) -> WinFile
Expand All @@ -543,6 +544,9 @@ namespace RC::File
case OpenFor::Reading:
desired_access = GENERIC_READ;
break;
case OpenFor::ReadWrite:
desired_access = GENERIC_READ | GENERIC_WRITE;
break;
default:
THROW_INTERNAL_FILE_ERROR("[WinFile::open_file] Tried to open file but received invalid data for the 'OpenFor' parameter.")
}
Expand Down

0 comments on commit d8189f3

Please sign in to comment.