Skip to content
Draft
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = external/CommonLibSSE-NG
url = https://github.com/alandtse/CommonLibVR.git
branch = ng
[submodule "external/rpmalloc"]
path = external/rpmalloc
url = https://github.com/mjansson/rpmalloc.git
branch = main
32 changes: 23 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
cmake_minimum_required(VERSION 3.21)
cmake_minimum_required(VERSION 3.30)

if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()

macro(set_from_environment VARIABLE)
if (NOT DEFINED ${VARIABLE} AND DEFINED ENV{${VARIABLE}})
Expand All @@ -11,7 +15,7 @@ include(cmake/version.cmake)
project(
EngineFixes
VERSION ${VERSION}
LANGUAGES CXX
LANGUAGES C CXX
)

add_compile_definitions(SKYRIM)
Expand Down Expand Up @@ -45,12 +49,7 @@ add_subdirectory(${CommonLibPath} ${CommonLibName} EXCLUDE_FROM_ALL)

find_package(spdlog CONFIG REQUIRED)
find_package(AutoTOML REQUIRED CONFIG)
find_package(Boost
MODULE
REQUIRED
COMPONENTS
regex
)
find_package(boost_regex CONFIG REQUIRED)
find_package(TBB
REQUIRED
CONFIG
Expand All @@ -77,13 +76,17 @@ add_library(
${PROJECT_NAME}
SHARED
${SOURCES}
external/rpmalloc/rpmalloc/rpmalloc.c
${CMAKE_CURRENT_BINARY_DIR}/include/Version.h
${CMAKE_CURRENT_BINARY_DIR}/version.rc
${PROJECT_NAME}.toml
.clang-format
.editorconfig
)

# TODO: flags
set_source_files_properties( external/rpmalloc/rpmalloc/rpmalloc.c PROPERTIES COMPILE_FLAGS "/D \"_UNICODE\" /D \"UNICODE\" /std:c17 /Zi /Oi /Oy- /GS- /Qpar- /fp:fast /fp:except- /Zc:forScope /Zc:wchar_t /GR- /openmp- /W4 /WX /wd4201 /wd4100 /Gm- /Ob2 /Ot /GT /GL /GF /O2 /D\"BUILD_RELEASE=1\"")

target_compile_features(
${PROJECT_NAME}
PRIVATE
Expand All @@ -95,6 +98,7 @@ target_include_directories(
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
"external/rpmalloc/rpmalloc"
)

target_link_libraries(
Expand All @@ -106,6 +110,16 @@ target_link_libraries(
TBB::tbb
TBB::tbbmalloc
xbyak::xbyak
# ${CMAKE_CURRENT_SOURCE_DIR}/external/rpmalloc/lib/windows/release/x86-64/rpmalloc.lib
)
target_compile_definitions(
${PROJECT_NAME}
PRIVATE
ENABLE_PRELOAD
ENABLE_VALIDATE_ARGS
ENABLE_ASSERTS
ENABLE_THREAD_CACHE=1
# ENABLE_STATISTICS
)

if (MSVC)
Expand All @@ -120,7 +134,7 @@ endif()
target_precompile_headers(
${PROJECT_NAME}
PRIVATE
src/PCH.h
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/src/PCH.h>"
)

option(COPY_BUILD "whether we should copy the outputs to the skyrim dir" OFF)
Expand Down
6 changes: 3 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
}
},
{
"environment": {
"CXXFLAGS": "/MP /W4 /WX /external:anglebrackets /external:W0 $penv{CXXFLAGS}"
},
"environment": {
"CXXFLAGS": "/MP /W4 /WX /external:anglebrackets /external:W0 $penv{CXXFLAGS}"
},
"generator": "Visual Studio 17 2022",
"hidden": true,
"name": "vs2022"
Expand Down
1 change: 1 addition & 0 deletions external/rpmalloc
Submodule rpmalloc added at 935176
1 change: 0 additions & 1 deletion src/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@

#include <boost/regex.hpp>
#include <tbb/concurrent_hash_map.h>
#include <tbb/scalable_allocator.h>
#include <xbyak/xbyak.h>

#ifndef NDEBUG
Expand Down
20 changes: 20 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "utils.h"
#include "version.h"
#include "warnings.h"
#include <stdio.h>

inline constexpr REL::Version RUNTIME_1_6_1170(1, 6, 1170, 0);

Expand Down Expand Up @@ -39,6 +40,25 @@ void MessageHandler(SKSE::MessagingInterface::Message* a_msg)
if (*config::warnRefHandleLimit)
warnings::WarnActiveRefrHandleCount(static_cast<std::uint32_t>(*config::warnRefrLoadedGameLimit));

break;
case SKSE::MessagingInterface::kSaveGame:
if (*config::patchMemoryManager) {
/*
FILE* fout;
auto path = logger::log_directory();
if (!path)
stl::report_and_fail("failed to get standard log path"sv);

*path /= "EngineFixes_rpmalloc_stats.log"sv;
if ((fout = fopen(path->string().c_str(), "w")) != NULL)
{
rpmalloc_dump_statistics(fout);
fclose(fout);
}
*/
patches::WriteMemoryManagerStats();
}

break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions src/patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace patches
bool PatchWaterflowAnimation();

bool PatchMemoryManager();
void WriteMemoryManagerStats();
bool PatchSafeExit();
bool PatchSaveGameMaxSize();
bool PatchScaleformAllocator();
Expand Down
24 changes: 22 additions & 2 deletions src/patches/formcaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ namespace patches
if (globalFormCacheMap[masterId].find(accessor, baseId))
{
formPointer = accessor->second;
if (masterId == 0xFF)
{
RE::TESForm* formPointerGlobalTable = nullptr;
GlobalFormTableLock->LockForRead();

if (*GlobalFormTable)
{
auto iter = (*GlobalFormTable)->find(FormId);
formPointerGlobalTable = (iter != (*GlobalFormTable)->end()) ? iter->second : nullptr;
}

GlobalFormTableLock->UnlockForRead();

if (formPointerGlobalTable == nullptr)
{
logger::trace("debug hk_GetFormByID from cache for {:08X} is {}, but in globalTable is {}"sv, FormId, (formPointer == nullptr) ? "nullptr" : "Form", (formPointerGlobalTable == nullptr) ? "nullptr" : "Form");
//UpdateFormCache(FormId, formPointerGlobalTable, true);
return formPointerGlobalTable;
}
}
return formPointer;
}
}
Expand Down Expand Up @@ -201,8 +221,8 @@ namespace patches
origFunc2HookAddr.address(),
reinterpret_cast<std::uintptr_t>(UnknownFormFunction2));
}

logger::trace("done"sv);
bool isTbbScalableAllocator = (globalFormCacheMap[0].get_allocator().allocator_type() == globalFormCacheMap[0].get_allocator().scalable) ? true : false;
logger::trace("done. isTbbScalableAllocator: {}"sv, isTbbScalableAllocator);

logger::trace("success"sv);

Expand Down
Loading