Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ build
src/bin/_empty.cpp
src/bin/_empty.h
.vscode/settings.json
dist
*log*
11 changes: 11 additions & 0 deletions src/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ namespace util
using SKSE::stl::report_and_fail;
}

#define INFO(...) logger::info(__VA_ARGS__)
#define WARN(...) logger::warn(__VA_ARGS__)
#define ERROR(...) logger::error(__VA_ARGS__)
#define CRITICAL(...) logger::critical(__VA_ARGS__)
#ifndef NDEBUG
#include <cassert>
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif

namespace std
{
template <class T>
Expand Down
2 changes: 1 addition & 1 deletion src/bin/Rendering/Drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void Drawer::draw_texture(ID3D11ShaderResourceView* a_texture,

Utils::Color::MultAlpha(a_color, a_drawArgs.alphaMult);
ImGui::GetWindowDrawList()
->AddImageQuad(a_texture, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], a_color);
->AddImageQuad((ImTextureID)a_texture, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], a_color);
}

void Drawer::draw_arc(ImVec2 center,
Expand Down
28 changes: 17 additions & 11 deletions src/bin/Rendering/RenderManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "RenderManager.h"
#include <RE/R/Renderer.h>
#include "FontLoader.h"

#include <d3d11.h>
Expand Down Expand Up @@ -47,35 +48,40 @@ void RenderManager::D3DInitHook::thunk()
func();

INFO("RenderManager: Initializing...");
auto render_manager = RE::BSRenderManager::GetSingleton();
if (!render_manager) {
ERROR("Cannot find render manager. Initialization failed!");
auto renderer = RE::BSGraphics::Renderer::GetSingleton();
if (!renderer) {
ERROR("Cannot find renderer. Initialization failed!");
return;
}

auto render_data = render_manager->GetRuntimeData();
auto render_data = renderer->GetRendererData();
if (!render_data) {
ERROR("Cannot find render data. Initialization failed!");
return;
}

INFO("Getting swapchain...");
auto swapchain = render_data.swapChain;
auto window = renderer->GetCurrentRenderWindow();
auto swapchain = window->swapChain;
if (!swapchain) {
ERROR("Cannot find swapchain. Initialization failed!");
return;
}

INFO("Getting swapchain desc...");
DXGI_SWAP_CHAIN_DESC sd{};
if (swapchain->GetDesc(std::addressof(sd)) < 0) {
REX::W32::DXGI_SWAP_CHAIN_DESC sd{};
if (swapchain->GetDesc(&sd) < 0) {
ERROR("IDXGISwapChain::GetDesc failed.");
return;
}

device = render_data.forwarder;
device = reinterpret_cast<ID3D11Device*>(render_data->forwarder);
Texture::device_ = device;
context = render_data.context;
context = reinterpret_cast<ID3D11DeviceContext*>(render_data->context);

INFO("Initializing ImGui...");
ImGui::CreateContext();
if (!ImGui_ImplWin32_Init(sd.OutputWindow)) {
if (!ImGui_ImplWin32_Init(sd.outputWindow)) {
ERROR("ImGui initialization failed (Win32)");
return;
}
Expand All @@ -90,7 +96,7 @@ void RenderManager::D3DInitHook::thunk()

WndProcHook::func = reinterpret_cast<WNDPROC>(
SetWindowLongPtrA(
sd.OutputWindow,
sd.outputWindow,
GWLP_WNDPROC,
reinterpret_cast<LONG_PTR>(WndProcHook::thunk)));
if (!WndProcHook::func)
Expand Down
16 changes: 10 additions & 6 deletions src/bin/Rendering/TextureManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "TextureManager.h"
#include <RE/R/Renderer.h>
#define NANOSVG_IMPLEMENTATION
#define NANOSVG_ALL_COLOR_KEYWORDS
#include "include/lib/nanosvg.h"
Expand Down Expand Up @@ -40,14 +41,14 @@ Texture::Image Texture::GetIconImage(icon_image_type a_imageType, RE::TESForm* a
bool Texture::load_texture_from_file(const char* filename, ID3D11ShaderResourceView** out_srv, int& out_width, int& out_height)
{
ASSERT(device_ != nullptr);
auto* render_manager = RE::BSRenderManager::GetSingleton();
if (!render_manager) {
logger::error("Cannot find render manager. Initialization failed."sv);
auto* renderer = RE::BSGraphics::Renderer::GetSingleton();
if (!renderer) {
logger::error("Cannot find renderer. Initialization failed."sv);
return false;
}

auto [forwarder, context, unk58, unk60, unk68, swapChain, unk78, unk80, renderView, resourceView] =
render_manager->GetRuntimeData();
auto render_data = renderer->GetRendererData();
auto forwarder = render_data->forwarder;

// Load from disk into a raw RGBA buffer
auto* svg = nsvgParseFromFile(filename, "px", 96.0f);
Expand Down Expand Up @@ -89,7 +90,10 @@ bool Texture::load_texture_from_file(const char* filename, ID3D11ShaderResourceV
srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srv_desc.Texture2D.MipLevels = desc.MipLevels;
srv_desc.Texture2D.MostDetailedMip = 0;
forwarder->CreateShaderResourceView(p_texture, &srv_desc, out_srv);
forwarder->CreateShaderResourceView(
reinterpret_cast<REX::W32::ID3D11Resource*>(p_texture),
reinterpret_cast<const REX::W32::D3D11_SHADER_RESOURCE_VIEW_DESC*>(&srv_desc),
reinterpret_cast<REX::W32::ID3D11ShaderResourceView**>(out_srv));
p_texture->Release();

free(image_data);
Expand Down
6 changes: 5 additions & 1 deletion src/bin/Utilities/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ namespace Utils
if (!aem) {
return;
}
auto* dummy = RE::TESForm::LookupByID<RE::TESForm>(0x00020163)->As<RE::TESObjectWEAP>();
// Use Iron Dagger as dummy weapon to clear slot
auto* dummy = RE::TESForm::LookupByID<RE::TESForm>(0x0001397E)->As<RE::TESObjectWEAP>();
if (!dummy) {
return;
}
//sound false, queue false, force true
aem->EquipObject(a_pc, dummy, nullptr, 1, a_slot, false, true, false);
aem->UnequipObject(a_pc, dummy, nullptr, 1, a_slot, false, true, false);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ extern "C" DLLEXPORT constinit auto SKSEPlugin_Version = []() {

extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Load(const SKSE::LoadInterface* a_skse)
{
REL::Module::reset(); // Clib-NG bug workaround
// REL::Module::reset(); // Clib-NG bug workaround
//std::this_thread::sleep_for(std::chrono::milliseconds(10000));
InitializeLog();
logger::info("{} v{}"sv, Plugin::NAME, Plugin::VERSION.string());
Expand Down
12 changes: 6 additions & 6 deletions src/include/lib/imgui_freetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ struct ImFontBuildDstDataFT

bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, unsigned int extra_flags)
{
IM_ASSERT(atlas->ConfigData.Size > 0);
IM_ASSERT(atlas->Sources.Size > 0);

ImFontAtlasBuildInit(atlas);

Expand All @@ -413,16 +413,16 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u
bool src_load_color = false;
ImVector<ImFontBuildSrcDataFT> src_tmp_array;
ImVector<ImFontBuildDstDataFT> dst_tmp_array;
src_tmp_array.resize(atlas->ConfigData.Size);
src_tmp_array.resize(atlas->Sources.Size);
dst_tmp_array.resize(atlas->Fonts.Size);
memset((void*)src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
memset((void*)dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());

// 1. Initialize font loading structure, check font data validity
for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)
for (int src_i = 0; src_i < atlas->Sources.Size; src_i++)
{
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
ImFontConfig& cfg = atlas->ConfigData[src_i];
ImFontConfig& cfg = atlas->Sources[src_i];
FreeTypeFont& font_face = src_tmp.Font;
IM_ASSERT(cfg.DstFont && (!cfg.DstFont->IsLoaded() || cfg.DstFont->ContainerAtlas == atlas));

Expand Down Expand Up @@ -530,7 +530,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
{
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
ImFontConfig& cfg = atlas->ConfigData[src_i];
ImFontConfig& cfg = atlas->Sources[src_i];
if (src_tmp.GlyphsCount == 0)
continue;

Expand Down Expand Up @@ -642,7 +642,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u
// When merging fonts with MergeMode=true:
// - We can have multiple input fonts writing into a same destination font.
// - dst_font->ConfigData is != from cfg which is our source configuration.
ImFontConfig& cfg = atlas->ConfigData[src_i];
ImFontConfig& cfg = atlas->Sources[src_i];
ImFont* dst_font = cfg.DstFont;

const float ascent = src_tmp.Font.Info.Ascender;
Expand Down
13 changes: 7 additions & 6 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"rapidcsv",
"nlohmann-json",
"freetype",
"directxtk",
{
"name": "imgui",
"features": [
"dx11-binding",
"win32-binding"
]
"name": "imgui",
"features": [
"dx11-binding",
"win32-binding"
]
}
]
}
}