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

Version 0.1.4.0 #32

Merged
merged 57 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
a4d3ffa
play_system_sound, play_character_sound
Dasaav-dsv May 1, 2024
c87dbc7
Rename back to make_system_sound
Dasaav-dsv May 1, 2024
4a89c0e
Restructure, use play_ instead of make_ and add character sound playback
Dasaav-dsv May 1, 2024
185dc8c
Simplify example
Dasaav-dsv May 1, 2024
85b198d
Add auto-generated paramdef headers
ThomasJClark Apr 30, 2024
b7f4160
Add SoloParamRepositoryImp class
ThomasJClark Apr 30, 2024
ed5ac2d
Add graphics/draw
Dasaav-dsv May 6, 2024
f766f33
Add draw symbols
Dasaav-dsv May 6, 2024
8fa6fb0
Rename structures
Dasaav-dsv May 6, 2024
f4a88cb
Doxygen documentation
Dasaav-dsv May 6, 2024
bcfe1ab
Correct scene name (HDRScene as used by the game)
Dasaav-dsv May 7, 2024
6dfb1d8
Skip outside typedefs for forward declarations
Dasaav-dsv May 7, 2024
e28016b
Add DirectX 12 sample triangle example
Dasaav-dsv May 7, 2024
778de1f
Update version
Dasaav-dsv May 7, 2024
dda8b21
Update documentation
Dasaav-dsv May 7, 2024
1e3a7b5
Small doxygen fix
Dasaav-dsv May 7, 2024
95ec188
Merge pull request #30 from Dasaav-dsv:graphics-impl
Dasaav-dsv May 7, 2024
fb94fcd
Merge branch 'dev' into SoloParamRepositoryImp
Dasaav-dsv May 7, 2024
8249033
Merge pull request #29 from ThomasJClark/SoloParamRepositoryImp
Dasaav-dsv May 7, 2024
f2e3201
Begin restructuring param impl
Dasaav-dsv May 8, 2024
de75ef0
Move row info into fd4_param.hpp
Dasaav-dsv May 8, 2024
131fca4
FD4-specific param structures
Dasaav-dsv May 8, 2024
8cf8813
Begin separate param impl
Dasaav-dsv May 8, 2024
37054b8
Move paramdefs into param/paramdef
Dasaav-dsv May 8, 2024
f362f30
Begin restructuring
Dasaav-dsv May 10, 2024
9a3d833
Continue param restructuring
Dasaav-dsv May 10, 2024
51e2ea0
Rename paramdefs namespace
Dasaav-dsv May 10, 2024
90d248f
Move paramdef header
Dasaav-dsv May 10, 2024
75395da
param_index
Dasaav-dsv May 10, 2024
04a3560
Param list implementation
Dasaav-dsv May 10, 2024
fbbf7d9
Add param.cpp
Dasaav-dsv May 10, 2024
07717eb
Add initial param tables
Dasaav-dsv May 10, 2024
6126967
Begin implementing iterator for params
Dasaav-dsv May 10, 2024
44edbcf
Initial param manipulation (WIP)
Dasaav-dsv May 11, 2024
5c684c9
Update source files
Dasaav-dsv May 11, 2024
9ebca73
Update CS:: param interface
Dasaav-dsv May 11, 2024
40d5d4c
Remove param file layout
Dasaav-dsv May 11, 2024
bbc3867
Move param file layout to separate file
Dasaav-dsv May 11, 2024
1f19be1
Add param type enum and constants
Dasaav-dsv May 11, 2024
47efe6e
Individual param table impl
Dasaav-dsv May 11, 2024
f5fc89c
Add main param header
Dasaav-dsv May 11, 2024
ea05c9a
Add translated paramdef docs from nord's repo
ThomasJClark May 11, 2024
be2bf44
Add "f" suffix to floats
ThomasJClark May 12, 2024
bed402e
Merge pull request #31 from ThomasJClark/paramdefdocs
Dasaav-dsv May 12, 2024
846637c
Remove old impl
Dasaav-dsv May 12, 2024
e79d6f3
Merge branch 'dev' of https://github.com/Dasaav-dsv/libER into dev
Dasaav-dsv May 12, 2024
d21d553
Update param tables to no longer use statics (186 statics is too many)
Dasaav-dsv May 12, 2024
a045b5d
Add back param_const_iterator support
Dasaav-dsv May 12, 2024
693ce05
Remove get_param_res_cap_address (unused)
Dasaav-dsv May 12, 2024
27b34cf
Add doxygen documentation for param manipulation
Dasaav-dsv May 12, 2024
47ed190
Update paramdef documentation
Dasaav-dsv May 12, 2024
433e7a6
Patch a use after free bug in CS::GaitemDialog related classes
Dasaav-dsv May 13, 2024
fdebe02
Add a runtime param editing example
Dasaav-dsv May 13, 2024
145f30e
Update version to 0.1.4.0
Dasaav-dsv May 13, 2024
6b93ea5
Update Doxygen documentation
Dasaav-dsv May 13, 2024
6f10bb6
Template shadowing fix
Dasaav-dsv May 13, 2024
2561577
Fix subobject initialization
Dasaav-dsv May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.15.0)
project(libER VERSION 0.1.2.1 LANGUAGES C CXX)
project(libER VERSION 0.1.4.0 LANGUAGES C CXX)

# Must build with C++20 or newer
set(CMAKE_CXX_STANDARD 20)
Expand Down Expand Up @@ -106,12 +106,23 @@ target_sources("objlibER" PUBLIC

# Namespace CS source files
target_sources("objlibER" PUBLIC
"source/coresystem/cs_param.cpp"
"source/coresystem/task.cpp"
"source/coresystem/window.cpp"
"source/coresystem/file.cpp"
"source/coresystem/sound.cpp"
)

# Namespace GX source files
target_sources("objlibER" PUBLIC
"source/graphics/draw.cpp"
)

# Param manipulation source files
# target_sources("objlibER" PUBLIC
# "source/param/param.cpp"
# )

# Target libER[d].dll
add_library("libER" SHARED $<TARGET_OBJECTS:objlibER> $<TARGET_OBJECTS:mimalloc-obj>)
target_include_directories("libER" PUBLIC "include")
Expand Down
4 changes: 2 additions & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "libER"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.1.2.1
PROJECT_NUMBER = 0.1.4.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down Expand Up @@ -1082,7 +1082,7 @@ EXCLUDE_PATTERNS = */include/detail/* */include/version/detail/* */build/*
# wildcard * is used, a substring. Examples: ANamespace, AClass,
# ANamespace::AClass, ANamespace::*Test

EXCLUDE_SYMBOLS = liber_* LIBER_* FD4_RUNTIME_CLASS FD4_SINGLETON_CLASS
EXCLUDE_SYMBOLS = liber_* LIBER_* FD4_RUNTIME_CLASS FD4_SINGLETON_CLASS unk* pad* reserve* Unk* Pad* Reserve*

# The EXAMPLE_PATH tag can be used to specify one or more files or directories
# that contain example code fragments that are included (see the \include
Expand Down
13 changes: 13 additions & 0 deletions docs/Changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@
* ## Version 0.1.2.1:
* - Add @link from::CS::CSWindowImp CSWindowImp @endlink documentation by <a href="https://github.com/ThomasJClark">ThomasJClark</a>
*
* ## Version 0.1.3.0:
* - Add graphics directory for GX* namespaces
* - Add graphics/draw with a DirectX 12 drawing helper task abstract class
* - Add a sample D3D12 triangle example under examples/d3d12/sample_triangle.cpp
* - play_system_sound and play_character_sound, restructure sound playback
* - Simplify sound playback example
*
* ## Version 0.1.4.0:
* - Add runtime param manipulation based on a pull request by <a href="https://github.com/ThomasJClark">ThomasJClark</a>
* - Add 186 param tables with iterator support
* - Autogenerate paramdef headers with ParamStructGenerator by <a href="https://github.com/tremwil">tremwil</a> and <a href="https://github.com/Nordgaren">Nordgaren</a>
* - Add paramdef Doxygen documentation based on Nordgaren's translations
*
*/
16 changes: 16 additions & 0 deletions docs/MainPage.dox
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@
* @see **EXAMPLES**: @ref example_resources_page
* @see file.hpp
*
* - @link draw.hpp DirectX 12 3D graphics @endlink: accessing **ELDEN RING**'s D3D12
* resources and dispatching draw tasks via its task system (described above). The
* provided abstract draw task exposes both the game world render target and the UI render target,
* allowing to draw on either.
* None of the DirectX resources are acquired via hooking.
* @see **EXAMPLES**: @ref example_d3d12_page
* @see draw.hpp
*
* - @link param.hpp Runtime Param Management @endlink: read/write access to all
* param tables used by **ELDEN RING**, with full iterator support, paramdef layouts,
* type safety and field documentation (thanks ThomasJClark and Nordgaren!).
* @see **EXAMPLES**: @ref example_param_page
* @see param.hpp
* @see cs_param.hpp
*
* - @link from_allocator.hpp Memory Allocation@endlink: **libER** documents the
* **ELDEN RING** allocation implementation, and replaces it with a modern <a
* href="https://github.com/microsoft/mimalloc/">mimalloc</a> implementation
Expand Down Expand Up @@ -81,5 +96,6 @@
* - @link include/fd4 FD4@endlink - internal **ELDEN RING** implementation
* details
* - @link include/memory from::* containers and memory@endlink
* - @link include/graphics GX* namespace(s)@endlink ELDEN RING graphics
*
*/
8 changes: 8 additions & 0 deletions docs/examples/D3D12.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @page example_d3d12_page D3D12 Examples
*
* ## Draw a sample triangle over the UI of ELDEN RING:
*
* @include sample_triangle.cpp
*
*/
8 changes: 8 additions & 0 deletions docs/examples/Param.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @page example_param_page Param Examples
*
* ## Modify PostureControlParam at runtime:
*
* @include posture_param.cpp
*
*/
8 changes: 7 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ add_library("libER_gparam_resource_example" SHARED "resources/load_gparam.cpp")
target_link_libraries("libER_gparam_resource_example" PUBLIC "libER")

add_library("libER_play_bank_sound_example" SHARED "resources/play_bank_sound.cpp")
target_link_libraries("libER_play_bank_sound_example" PUBLIC "libER")
target_link_libraries("libER_play_bank_sound_example" PUBLIC "libER")

add_library("libER_posture_param_example" SHARED "params/posture_param.cpp")
target_link_libraries("libER_posture_param_example" PUBLIC "libER")

add_library("libER_d3d12_triangle_example" SHARED "d3d12/sample_triangle.cpp")
target_link_libraries("libER_d3d12_triangle_example" PUBLIC "libER" "dxgi.lib" "d3dcompiler.lib" "d3d12.lib")
197 changes: 197 additions & 0 deletions examples/d3d12/sample_triangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
// Draw a DirectX 12 sample triangle
// Sample code based on D3D12 Hello World samples by Microsoft

#include "../example_base.hpp"

// For D3D12 draw tasks inside the game's render pipeline:
#include <graphics/draw.hpp>
// For wait_for_system:
#include <dantelion2/system.hpp>
// For memory management:
#include <memory/from_unique_ptr.hpp>

// DirectX 12 dependencies:
#include <D3Dcompiler.h>
#include <d3d12.h>

// DirectX Windows dependencies:
#include <detail/windows.inl>
#include <wrl/client.h>

class draw_sample : public from::GXBS::GXDrawTask {
public:
void draw() override {
// Get the device from the task context,
// all context getters are guaranteed to return
// initialized resources
ID3D12Device* device = &this->get_device();
if (this->needs_init) {
// This method has ran for the first time
// so our D3D12 resources need to be initialized
this->init_pipeline_state();
this->init_command_list();
this->init_vertex_buffer();
this->needs_init = false;
}
this->command_allocator->Reset();
this->command_list->Reset(this->command_allocator.Get(),
this->pipeline_state.Get());
this->command_list->SetGraphicsRootSignature(
&this->get_root_signature());
this->command_list->RSSetViewports(1, &this->get_viewport());
this->command_list->RSSetScissorRects(1, &this->get_scissor_rect());
this->command_list->OMSetRenderTargets(1,
&this->get_render_target_view(), FALSE, nullptr);
this->command_list->IASetPrimitiveTopology(
D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
this->command_list->IASetVertexBuffers(0, 1, &vertex_buffer_view);
this->command_list->DrawInstanced(3, 1, 0, 0);
this->command_list->Close();
ID3D12CommandList* command_list = this->command_list.Get();
this->get_command_queue().ExecuteCommandLists(1, &command_list);
}

private:
// Create a pipeline state for our resource
void init_pipeline_state() {
Microsoft::WRL::ComPtr<ID3DBlob> vertex_shader_buffer;
Microsoft::WRL::ComPtr<ID3DBlob> pixel_shader_buffer;
D3DCompileFromFile(L"shaders.hlsl", nullptr, nullptr, "VSMain",
"vs_5_0", 0, 0, &vertex_shader_buffer, nullptr);
D3DCompileFromFile(L"shaders.hlsl", nullptr, nullptr, "PSMain",
"ps_5_0", 0, 0, &pixel_shader_buffer, nullptr);
D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc{};
D3D12_INPUT_ELEMENT_DESC input_desc[2] = {
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }
};
pso_desc.InputLayout = { input_desc, 2 };
pso_desc.pRootSignature = &this->get_root_signature();
pso_desc.VS = { vertex_shader_buffer->GetBufferPointer(),
vertex_shader_buffer->GetBufferSize() };
pso_desc.PS = { pixel_shader_buffer->GetBufferPointer(),
pixel_shader_buffer->GetBufferSize() };
D3D12_RASTERIZER_DESC& rasterizer_desc = pso_desc.RasterizerState;
rasterizer_desc.FillMode = D3D12_FILL_MODE_SOLID;
rasterizer_desc.CullMode = D3D12_CULL_MODE_BACK;
rasterizer_desc.FrontCounterClockwise = FALSE;
rasterizer_desc.DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
rasterizer_desc.DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
rasterizer_desc.SlopeScaledDepthBias =
D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
rasterizer_desc.DepthClipEnable = TRUE;
rasterizer_desc.MultisampleEnable = FALSE;
rasterizer_desc.AntialiasedLineEnable = FALSE;
rasterizer_desc.ForcedSampleCount = 0;
rasterizer_desc.ConservativeRaster =
D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
D3D12_BLEND_DESC& blend_desc = pso_desc.BlendState;
blend_desc.AlphaToCoverageEnable = FALSE;
blend_desc.IndependentBlendEnable = FALSE;
for (auto& rt_blend_desc : blend_desc.RenderTarget) {
rt_blend_desc.BlendEnable = FALSE;
rt_blend_desc.LogicOpEnable = FALSE;
rt_blend_desc.SrcBlend = D3D12_BLEND_ONE;
rt_blend_desc.DestBlend = D3D12_BLEND_ZERO;
rt_blend_desc.BlendOp = D3D12_BLEND_OP_ADD;
rt_blend_desc.SrcBlendAlpha = D3D12_BLEND_ONE;
rt_blend_desc.DestBlendAlpha = D3D12_BLEND_ZERO;
rt_blend_desc.BlendOpAlpha = D3D12_BLEND_OP_ADD;
rt_blend_desc.LogicOp = D3D12_LOGIC_OP_NOOP;
rt_blend_desc.RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
}
pso_desc.DepthStencilState.DepthEnable = FALSE;
pso_desc.DepthStencilState.StencilEnable = FALSE;
pso_desc.SampleMask = UINT_MAX;
pso_desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
pso_desc.NumRenderTargets = 1;
pso_desc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
pso_desc.SampleDesc.Count = 1;
this->get_device().CreateGraphicsPipelineState(&pso_desc,
IID_PPV_ARGS(&this->pipeline_state));
}

// Create the command list to be executed whenever draw_sample::draw is
// called by the game
void init_command_list() {
ID3D12Device& device = this->get_device();
device.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
IID_PPV_ARGS(&this->command_allocator));
device.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
this->command_allocator.Get(), this->pipeline_state.Get(),
IID_PPV_ARGS(&this->command_list));
this->command_list->Close();
}

// Initialize the vertex buffer to be drawn
void init_vertex_buffer() {
ID3D12Device& device = this->get_device();
// XYZRGBA
using vertex_data = float[7];
float triangle_point =
0.25f * this->get_viewport().Width / this->get_viewport().Height;
// clang-format off
vertex_data vertices[3] = {
{ 0.0f, triangle_point, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.25f, -triangle_point, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
{ -0.25f, -triangle_point, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }
};
// clang-format on
D3D12_HEAP_PROPERTIES heap_properties{ D3D12_HEAP_TYPE_UPLOAD,
D3D12_CPU_PAGE_PROPERTY_UNKNOWN, D3D12_MEMORY_POOL_UNKNOWN, 1, 1 };
D3D12_RESOURCE_DESC resource_desc{ D3D12_RESOURCE_DIMENSION_BUFFER, 0,
sizeof(vertices), 1, 1, 1, DXGI_FORMAT_UNKNOWN, { 1, 0 },
D3D12_TEXTURE_LAYOUT_ROW_MAJOR, D3D12_RESOURCE_FLAG_NONE };
device.CreateCommittedResource(&heap_properties, D3D12_HEAP_FLAG_NONE,
&resource_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS(&this->vertex_buffer));
void* vertex_data_buf;
D3D12_RANGE range{ 0, 0 };
vertex_buffer->Map(0, &range, &vertex_data_buf);
std::memcpy((void*)vertex_data_buf, (void*)vertices, sizeof(vertices));
vertex_buffer->Unmap(0, nullptr);
vertex_buffer_view.BufferLocation =
vertex_buffer->GetGPUVirtualAddress();
vertex_buffer_view.StrideInBytes = sizeof(vertices[0]);
vertex_buffer_view.SizeInBytes = sizeof(vertices);
}

bool needs_init = true;
Microsoft::WRL::ComPtr<ID3D12PipelineState> pipeline_state;
Microsoft::WRL::ComPtr<ID3D12CommandAllocator> command_allocator;
Microsoft::WRL::ComPtr<ID3D12GraphicsCommandList> command_list;
Microsoft::WRL::ComPtr<ID3D12Resource> vertex_buffer;
D3D12_VERTEX_BUFFER_VIEW vertex_buffer_view;
};

void example_base() {
// Allocate console
con_allocate(false);
// It's necessary to wait for the task system to be initialized
// before registering tasks. We can use wait_for_system
// with a timeout of 5000ms to ensure ELDEN RING has initialized it
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!\n";
return;
}
// Create the draw task with a smart pointer
// that has a delay deleter. This is important for the
// task to be properly unregistered on destruction
auto task = from::make_unique<draw_sample>();
// Set the render target/layer on which to draw
// UI_SCENE (called UIScene by ELDEN RING) is the HUD and menu
// HDR_SCENE (called HDRScene by ELDEN RING) is the game world,
// overlayed by the UIScene in the final composite.
// This means that to draw under the HUD, HDR_SCENE must be chosen,
// and to draw above the HUD, UI_SCENE must be chosen instead.
// Keep in mind that the game world scene is actually using
// an HDR colorspace like it says in the name
task->set_scene(from::GXBS::GXDrawTask::UI_SCENE);
// Call for the draw task to be registered and executed
task->register_task();
// Sleep before letting the task unique_ptr go out of scope
// and cease rendering as it gets destroyed
Sleep(20'000);
}
Loading