libER 0.1.4.2
ELDEN RING API library
Loading...
Searching...
No Matches
Files & Resources Examples

Loading and processing a .gparam file:

// Request a gparam file to be loaded and get a gparam resource
#include "../example_base.hpp"
// For the file and resource requests
// For wait_for_system:
// For Sleep
#include <detail/windows.inl>
// Request a gparam with from::resource_request
void get_gparam_resource() {
// Request the gparam resource "m12_01_0000" from the gparam repository,
// loading it from the m12_01_0000.gparam file in the "gparam:/" virtual
// game directory (if loading from disk, you should provide the path
// instead)
from::resource_request gparam_request{
from::CS::CSResourceRepository::CSGparamRepository, L"m12_01_0000",
L"gparam:/m12_01_0000.gparam"
};
// Wait for the gparam_request with a locking call to
// from::resource_request::get. Alternatively, you can poll
// for the result with from::resource_request::ready and
// from::resource_request::check - example below this function!
auto gparam = gparam_request.get();
std::cout << "Got m12_01_0000: " << std::boolalpha << gparam.has_reference()
<< '\n';
}
// Request a gparam file to be loaded, making
// its resources available to the game with from::file_request
void load_gparam_resource() {
// Request the gparam file "m12_01_0000.gparam" from the "gparam:/" virtual
// game directory (if loading from disk, you should provide the path
// instead) The file_request types are:
// - LOAD = load the file if it hasn't been loaded yet
// - RELOAD = load the file or reload an existing one, replacing it
// - UNLOAD = unload the file if it is loaded
from::file_request gparam_file_request{ L"gparam:/m10_00_0000.gparam",
from::file_request::LOAD };
// Poll for the gparam request, this can be done in a separate thread,
// or a task. ALWAYS prefer to poll when loading files and resources
// inside a task, by checking if the request is ready ONCE whenever the
// task is ran.
while (!gparam_file_request.ready()) {
std::cout << "Waiting for m10_00_0000.gparam...\n";
Sleep(100);
}
// from::file_request::check is a non-locking version of
// from::file_request::get
auto gparam_file = gparam_file_request.check();
std::cout << "Got m10_00_0000.gparam: " << std::boolalpha
<< gparam_file.has_reference() << '\n';
}
// Will be called from DllMain
void example_base() {
// Allocate console, don't enable manual flushing
con_allocate(false);
// It's necessary to wait for the game systems to be initialized.
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!\n";
return;
}
// Wait a bit longer, since the game doesn't
// expect to be loading gparams right on boot.
Sleep(10'000);
get_gparam_resource();
load_gparam_resource();
}
Asynchronous file loading using the file capsule system.
Definition file.hpp:90
Asynchronous resource loading using the resource capsule system.
Definition file.hpp:258
liber::optref< FD4::FD4ResCap > get() const noexcept
Block until the resource request is ready and get the result.
Definition file.hpp:332
Namespace CS file and resource loading.
Dantelion2 system properties.

Loading a Wwise bank and playing a sound:

// Load a Wwise sound bank and play a sound from it
#include "../example_base.hpp"
// For the file and resource requests
// For sound playback
// For wait_for_system:
// Will be called from DllMain
void example_base() {
// Allocate console, don't enable manual flushing
con_allocate(false);
// It's necessary to wait for the game systems to be initialized.
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!\n";
return;
}
// Request a wwise bank containing our sound file to be loaded
from::file_request request{ L"sd:/vc201.bnk", from::file_request::LOAD };
// Wait for the request to be ready and get the result, see load_gparam.cpp
// for more details on file and resource loading.
auto bank = request.get();
if (!bank) {
std::cout << "Failed to load sd:/vc201.bnk!\n";
return;
}
// Play v020240300 (from vc201.bnk we loaded earlier)
}
static LIBERAPI DLUT::DLReferenceCountPtr< CSFD4SoundIns > play_system_sound(char sound_type, int sound_id)
Play a 2d system wwise sound.
Namespace CS sound playback.