Skip to content

Snippets

Some code snippets that utilizes DKUtil::Config.

NoEnchantmentRestrictionRemake

cpp
#pragma once
#include "DKUtil/Config.hpp"

namespace Config
{
	using namespace DKUtil::Alias;

	extern Boolean EnableDE;
	extern Boolean EnableUE;
	extern Integer UEMax;
	extern String Exclusion;

	void Load();
}
cpp
#include "Config.h"

namespace Config
{
	Boolean EnableDE{ "EnableDisenchantEverything" };
	Boolean EnableUE{ "EnableUnlimitedEnchantment" };
	Integer UEMax{ "EnchantmentMaxSlots" };
	String Exclusion{ "ExcludedEnchantments" };

	void Load()
	{
		auto mainConfig = COMPILE_PROXY("NoEnchantmentRestrictionRemake.toml"sv);

		mainConfig.Bind(EnableDE, true);
		mainConfig.Bind(EnableUE, true);
		mainConfig.Bind(UEMax, 3);
		mainConfig.Bind(Exclusion, "0|Example.esp");

		mainConfig.Load();

		INFO("Config Loaded"sv);
	}
}
cpp
DKUtil::Hook::WriteImm(_Hook_UES->TramPtr, static_cast<Imm32>(*Config::UEMax));

void Validator::ResolveExclusion()
{
    auto* dataHandler = RE::TESDataHandler::GetSingleton();

    for (auto& ex : Config::Exclusion.get_collection()) {
        auto list = dku::string::split(ex, "|"sv);
        if (list.size() < 2) {
            continue;
        }
    }
}

YouCanSleepRemake

cpp
#pragma once
#include "DKUtil/Config.hpp"

namespace Config
{
	using namespace DKUtil::Alias;

	extern Boolean EnableSleepWait[8];

	void Load();
}
cpp
#include "Config.h"

namespace Config
{
	Boolean EnableSleepWait[8] = {
		{ "InAir" },
		{ "Trespassing" },
		{ "AskedToLeave" },
		{ "GuardsPursuing" },
		{ "EnemiesNearby" },
		{ "TakingHealthDamage" },
		{ "Owned" },
		{ "InUse" },
	};

	void Load()
	{
		auto main = COMPILE_PROXY("YouCanSleepRemake.toml"sv);

		for (auto index = 0; index < std::extent_v<decltype(EnableSleepWait)>; ++index) {
			main.Bind(EnableSleepWait[index], true);
		}

		main.Load();

		INFO("Config Loaded"sv);
	}
}
cpp
std::ptrdiff_t OffsetTbl[8] = {
    0x2E,                        // You cannot sleep in the air.
    0x89,                        // You cannot sleep while trespassing.
    0xB1,                        // You cannot sleep while being asked to leave.
    0xF6,                        // You cannot sleep while guards are pursuing you.
    0x11F,                       // You cannot sleep when enemies are nearby.
    0x146,                       // You cannot sleep while taking health damage.
    0x1BB,                       // This object is already in use by someone else.
    REL::Relocate(0x3BC, 0x3C0)  // You cannot sleep in an owned bed.
};

const auto funcAddr = DKUtil::Hook::IDToAbs(AE_FuncID, SE_FuncID);

for (auto index = 0; index < std::extent_v<decltype(Config::EnableSleepWait)>; ++index) {
    if (*Config::EnableSleepWait[index]) {
        DKUtil::Hook::WriteImm(funcAddr + OffsetTbl[index], JmpShort);
        INFO("Enabled SleepWait {} at 0x{:X}", Config::EnableSleepWait[index].get_key(), OffsetTbl[index]);
    }
}

// loop check for in air position
if (*Config::EnableSleepWait[0]) {
    DKUtil::Hook::WriteData(funcAddr + InAirLoopOffset, &InAirHookNop, sizeof(InAirHookNop));
}

INFO("Hooks installed"sv);

SF_NativeAutoHDR

cpp
#pragma once
#include "DKUtil/Config.hpp"

namespace Settings
{
    using namespace DKUtil::Alias;

    class Main : public DKUtil::model::Singleton<Main>
    {
    public:
		Integer ImageSpaceBufferFormat{ "ImageSpaceBufferFormat", "Main" };
		Boolean UpgradeUIRenderTarget{ "UpgradeUIRenderTarget", "Main" };
		Integer UpgradeRenderTargets{ "UpgradeRenderTargets", "Main" };

		Integer FrameBufferFormat{ "FrameBufferFormat", "HDR" };

		String RenderTargetsToUpgrade{ "RenderTargetsToUpgrade", "RenderTargets" };

        void Load() noexcept;

    private:
		TomlConfig config = COMPILE_PROXY("NativeAutoHDR.toml"sv);
    };
}
cpp
#include "Settings.h"

namespace Settings
{
	void Main::Load() noexcept
	{
		static std::once_flag ConfigInit;
		std::call_once(ConfigInit, [&]() {
			config.Bind(ImageSpaceBufferFormat, 0);
			config.Bind(UpgradeUIRenderTarget, true);
			config.Bind(UpgradeRenderTargets, 2);
			config.Bind(FrameBufferFormat, 0);
			config.Bind(RenderTargetsToUpgrade, "SF_ColorBuffer", "HDRImagespaceBuffer", "ImageSpaceHalfResBuffer", "ImageProcessColorTarget", "ImageSpaceBufferB10G11R11", "ImageSpaceBufferE5B9G9R9", "TAA_idTech7HistoryColorTarget", "EnvBRDF", "ImageSpaceBufferR10G10B10A2");
		});

		config.Load();

		INFO("Config loaded"sv)
	}
}
cpp
const auto settings = Settings::Main::GetSingleton();

if (*settings->FrameBufferFormat == 2) {
	SetBufferFormat(RE::Buffers::FrameBuffer, RE::BS_DXGI_FORMAT::BS_DXGI_FORMAT_R16G16B16A16_FLOAT);
} else {
	SetBufferFormat(RE::Buffers::FrameBuffer, RE::BS_DXGI_FORMAT::BS_DXGI_FORMAT_R10G10B10A2_UNORM);
}

switch (*settings->ImageSpaceBufferFormat) {
case 1:
	SetBufferFormat(RE::Buffers::ImageSpaceBuffer, RE::BS_DXGI_FORMAT::BS_DXGI_FORMAT_R10G10B10A2_UNORM);
	break;
case 2:
	SetBufferFormat(RE::Buffers::ImageSpaceBuffer, RE::BS_DXGI_FORMAT::BS_DXGI_FORMAT_R16G16B16A16_FLOAT);
	break;
}

if (*settings->UpgradeUIRenderTarget) {
	SetBufferFormat(RE::Buffers::ScaleformCompositeBuffer, RE::BS_DXGI_FORMAT::BS_DXGI_FORMAT_R16G16B16A16_FLOAT);
}

Released under the MIT License