Skip to content

Commit 52f6b80

Browse files
committed
Make fixed chance ignore plugin load order
1 parent c29b177 commit 52f6b80

6 files changed

Lines changed: 33 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.20)
22
set(NAME "po3_BaseObjectSwapper" CACHE STRING "")
3-
set(VERSION 3.3.1 CACHE STRING "")
3+
set(VERSION 3.4.0 CACHE STRING "")
44
set(VR_VERSION 1)
55
set(AE_VERSION 1)
66

@@ -134,6 +134,7 @@ else ()
134134
endif()
135135

136136
find_package(unordered_dense CONFIG REQUIRED)
137+
find_package(boost_container_hash CONFIG REQUIRED)
137138

138139
find_path(SRELL_INCLUDE_DIRS "srell.hpp")
139140
find_path(MERGEMAPPER_INCLUDE_DIRS "MergeMapperPluginAPI.h")
@@ -200,6 +201,7 @@ target_link_libraries(
200201
PRIVATE
201202
${CommonLibName}::${CommonLibName}
202203
unordered_dense::unordered_dense
204+
Boost::container_hash
203205
)
204206

205207
target_precompile_headers(

extern/CommonLibSSE

src/PCH.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <ankerl/unordered_dense.h>
1515
#include <spdlog/sinks/basic_file_sink.h>
1616
#include <srell.hpp>
17+
#include <boost/container_hash/hash.hpp>
1718

1819
#include <CLibUtil/distribution.hpp>
1920
#include <CLibUtil/hash.hpp>

src/RNG.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
#include "RNG.h"
22

3+
std::uint64_t BOS_RNG::get_form_seed(const RE::TESForm* a_form)
4+
{
5+
if (a_form->IsDynamicForm()) {
6+
return a_form->GetFormID();
7+
}
8+
9+
std::uint64_t result = 0;
10+
boost::hash_combine(result, a_form->GetLocalFormID());
11+
boost::hash_combine(result, a_form->GetFile(0)->GetFilename());
12+
return result;
13+
}
14+
315
BOS_RNG::BOS_RNG(const Chance& a_chance, const RE::TESObjectREFR* a_ref) :
416
type(a_chance.chanceType)
517
{
618
switch (type) {
719
case CHANCE_TYPE::kRefHash:
8-
seed = a_ref->GetFormID();
20+
seed = get_form_seed(a_ref);
921
break;
1022
case CHANCE_TYPE::kLocationHash:
1123
{
12-
auto baseID = a_ref->GetBaseObject()->GetFormID();
13-
auto location = a_ref->GetCurrentLocation();
24+
auto base = a_ref->GetBaseObject();
25+
auto location = a_ref->GetEditorLocation();
1426
auto cell = a_ref->GetSaveParentCell();
1527

1628
if (!location && !cell) {
17-
seed = a_ref->GetFormID();
29+
seed = get_form_seed(a_ref);
1830
} else {
19-
RE::FormID locID = 0;
31+
RE::TESForm* cellOrLoc = nullptr;
2032
if (location) {
21-
locID = location->GetFormID();
33+
cellOrLoc = location;
2234
} else if (cell) {
23-
locID = cell->GetFormID();
35+
cellOrLoc = cell;
2436
}
2537
// generate hash based on location + baseID
26-
seed = hash::szudzik_pair(locID, baseID);
38+
std::uint64_t result = 0;
39+
boost::hash_combine(result, get_form_seed(cellOrLoc));
40+
boost::hash_combine(result, get_form_seed(base));
41+
seed = result;
2742
}
2843
}
2944
break;

src/RNG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ struct BOS_RNG
4040
// members
4141
CHANCE_TYPE type;
4242
std::uint64_t seed{ 0 };
43+
44+
private:
45+
std::uint64_t get_form_seed(const RE::TESForm* a_form);
4346
};

vcpkg.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "base-object-swapper",
3-
"version-string": "3.3.1",
3+
"version-string": "3.4.0",
44
"description": "Base Object Swapper",
55
"homepage": "",
66
"license": "MIT",
77
"dependencies": [
8+
"boost-container-hash",
89
"clib-util",
910
"mergemapper",
1011
"rsm-binary-io",

0 commit comments

Comments
 (0)