UnleashedRecomp/UnleashedRecomp/kernel/memory.h
Skyth (Asilkan) a397a90551
Mod loader implementation. (#66)
* Initial mod loader implementation.

* Allow iterating in mod directories.

* Initial append archive implementation.

* Avoid calling function wrappers when loading append ARs.

For some reason they cause issues. Should investigate later.

* UMM merge archive support.

* Load merge archives without archive lists.

* Less thread locals.

I shouldn't worry about string allocations this much when the game itself spams them...

* Check for read-only UMM archives.

TODO: Skip merging as it's currently just doing duplicate loads.

* Skip loading merge archives if they are read-only.

* Merge only archives.

* Implement decompression.

* Fix append ARLs not loading.

* Initial save file redirection implementation.

* Slightly refactor resolved path usage.

* Implement save file redirection fallback.

* Set a default save file path if none is provided.

* Check for enabled option & replace backward slashes with forward ones in mod save file paths.

* Convert back slashes to forward ones when iterating directories.

* Make CSB limit dynamic.

* Cache append/merge archive lookups.

* Close stream after reading compressed ARL.

* Fix UMM/HMM ARL file path inconsistency.
2024-12-31 20:20:07 +03:00

45 lines
952 B
C++

#pragma once
#ifndef _WIN32
#define MEM_COMMIT 0x00001000
#define MEM_RESERVE 0x00002000
#endif
class Memory
{
public:
char* base{};
size_t size{};
size_t guestBase{};
Memory(void* address, size_t size);
void* Alloc(size_t offset, size_t size, uint32_t type);
void* Commit(size_t offset, size_t size);
void* Reserve(size_t offset, size_t size);
bool IsInMemoryRange(const void* host) const noexcept
{
return host >= base && host < (base + size);
}
void* Translate(size_t offset) const noexcept
{
if (offset)
assert(offset < 0x100000000ull);
return base + offset;
}
uint32_t MapVirtual(const void* host) const noexcept
{
if (host)
assert(IsInMemoryRange(host));
return static_cast<uint32_t>(static_cast<const char*>(host) - base);
}
};
extern "C" void* MmGetHostAddress(uint32_t ptr);
extern Memory g_memory;