-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
056af96
commit a1b1727
Showing
40 changed files
with
4,396 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.vs | ||
/Build | ||
*.vcxproj.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include "DynamicSun.hpp" | ||
|
||
#include "GameInstanceData.hpp" | ||
|
||
#include "Utils/Console.hpp" | ||
|
||
DirectX::XMVECTOR DynamicSun::ComputeQuatFromAngle(float angle) | ||
{ | ||
DirectX::FXMMATRIX v_rot_matrix = DirectX::XMMatrixRotationRollPitchYaw(0.0f, angle, ms_fSunAngle); | ||
return DirectX::XMQuaternionRotationMatrix(v_rot_matrix); | ||
} | ||
|
||
DirectX::XMFLOAT3& DynamicSun::GetLightDirection() | ||
{ | ||
return *Memory::Read<DirectX::XMFLOAT3>(0x11D32C0); | ||
} | ||
|
||
inline static float lerp_float(float a, float b, float f) | ||
{ | ||
return a + f * (b - a); | ||
} | ||
|
||
const float GetLightIntensity(float time_of_day) | ||
{ | ||
constexpr float c_fSunriseTime = 0.3f; | ||
constexpr float c_fSunsetTime = 0.75f; | ||
constexpr float c_fSunsetTimeReversed = 1.0f - c_fSunsetTime; | ||
constexpr float c_fSunriseOffset = 0.27f; | ||
constexpr float c_fSunsetOffset = 0.23f; | ||
|
||
if (time_of_day <= c_fSunriseTime) | ||
{ | ||
return std::max<float>(time_of_day - c_fSunriseOffset, 0.0f) / (c_fSunriseTime - c_fSunriseOffset); | ||
} | ||
else if (time_of_day >= c_fSunsetTime) | ||
{ | ||
const float v_time_reversed = std::max<float>((1.0f - time_of_day) - c_fSunsetOffset, 0.0f); | ||
return v_time_reversed / (c_fSunsetTimeReversed - c_fSunsetOffset); | ||
} | ||
else | ||
{ | ||
return 1.0f; | ||
} | ||
} | ||
|
||
DirectX::XMVECTOR DynamicSun::GetRotationQuat(float time_of_day) | ||
{ | ||
float v_lerp_factor; | ||
if (time_of_day <= 0.5f) | ||
{ | ||
const float v_range_start = std::fmaxf(0.0f, time_of_day - 0.27f); | ||
const float v_range_end = 0.5f - 0.27f; | ||
|
||
const float v_distance = 1.0f - std::fmaxf((v_range_end - v_range_start) / v_range_end, 0.0f); | ||
v_lerp_factor = v_distance / 2.0f; | ||
} | ||
else | ||
{ | ||
const float v_range_start = time_of_day - 0.5f; | ||
const float v_range_end = 1.0f - 0.77f; | ||
|
||
const float v_distance = 1.0f - std::fmaxf((v_range_end - v_range_start) / v_range_end, 0.0f); | ||
v_lerp_factor = 0.5f + (v_distance / 2.0f); | ||
} | ||
|
||
//0.27 -> v_lerp_factor = 0.0 sun appears | ||
//0.73 -> v_lerp_factor = 1.0 sun disappears | ||
|
||
const float v_rotation_radians = lerp_float(0.0f, DirectX::XM_PI, v_lerp_factor); | ||
return ComputeQuatFromAngle(v_rotation_radians); | ||
} | ||
|
||
__int64 DynamicSun::Update(void* device) | ||
{ | ||
const float delta_time = ms_deltaTimeTimer.Update(); | ||
|
||
DirectX::XMFLOAT3& v_curLightDir = DynamicSun::GetLightDirection(); | ||
|
||
GameInstanceData* v_game_instance = GameInstanceData::GetInstance(); | ||
if (v_game_instance) | ||
{ | ||
const float v_light_intensity = GetLightIntensity(v_game_instance->time_of_day); | ||
|
||
DirectX::FXMVECTOR v_rot_quat = GetRotationQuat(v_game_instance->time_of_day); | ||
DirectX::FXMVECTOR v_shadow_dir = DirectX::XMVectorScale( | ||
DirectX::XMVector3Normalize( | ||
DirectX::XMVector3Rotate({ 1.0f, 0.0f, 0.0f, 0.0f }, v_rot_quat) | ||
), v_light_intensity); | ||
|
||
DirectX::XMStoreFloat3(&v_curLightDir, v_shadow_dir); | ||
} | ||
|
||
return DynamicSun::o_PresentFunction(device); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "Utils/Memory.hpp" | ||
#include "Utils/Timer.hpp" | ||
|
||
class DynamicSun | ||
{ | ||
public: | ||
using PresentFunction = __int64 (*)(void*); | ||
inline static PresentFunction o_PresentFunction = nullptr; | ||
|
||
static DirectX::XMVECTOR ComputeQuatFromAngle(float angle); | ||
static DirectX::XMFLOAT3& GetLightDirection(); | ||
|
||
static DirectX::XMVECTOR GetRotationQuat(float time_of_day); | ||
static __int64 Update(void* device); | ||
|
||
inline static float ms_fSunAngle = 0.32f; | ||
|
||
private: | ||
inline static Timer ms_deltaTimeTimer; | ||
inline static float ms_fLightIntensity = 0.0f; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "Utils/Memory.hpp" | ||
|
||
struct GameInstanceData | ||
{ | ||
float time_of_day; | ||
|
||
inline static GameInstanceData* GetInstance() | ||
{ | ||
return *Memory::Read<GameInstanceData*>(0x128D790); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include "Utils/Memory.hpp" | ||
|
||
#include <unordered_map> | ||
#include <string> | ||
|
||
struct GameSettings | ||
{ | ||
/* 0x0000 */ std::unordered_map<std::string, int> int_settings; | ||
/* 0x0040 */ std::unordered_map<std::string, float> float_settings; | ||
/* 0x0080 */ std::unordered_map<std::string, std::string> string_settings; | ||
/* 0x00C0 */ char pad_0xC0[0x8]; | ||
|
||
inline static void UpdateFloatSetting(const std::string& name, float value) | ||
{ | ||
GameSettings* v_instance = GameSettings::GetInstance(); | ||
if (!v_instance) return; | ||
|
||
auto v_iter = v_instance->float_settings.find(name); | ||
if (v_iter == v_instance->float_settings.end()) | ||
{ | ||
v_instance->float_settings.emplace(name, value); | ||
return; | ||
} | ||
|
||
v_iter->second = value; | ||
} | ||
|
||
inline static GameSettings* GetInstance() | ||
{ | ||
return *Memory::Read<GameSettings*>(0x128D830); | ||
} | ||
}; // Size: 0xC8 | ||
|
||
static_assert(sizeof(GameSettings) == 0xC8, "GameSettings: Incorrect Size"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "GraphicsOptionsMenu.hpp" | ||
|
||
#include "OptionsItemSlider.hpp" | ||
#include "GameSettings.hpp" | ||
#include "DynamicSun.hpp" | ||
|
||
|
||
#include "Utils/Console.hpp" | ||
#include "Utils/Memory.hpp" | ||
|
||
MyGUI::Widget* Options::createNewOption() | ||
{ | ||
using NewOptionConstructor = MyGUI::Widget* (*)(Options*); | ||
|
||
NewOptionConstructor v_constructor = Memory::GetGlobal<NewOptionConstructor>(0x536A90); | ||
return v_constructor(this); | ||
} | ||
|
||
void GraphicsOptionsMenu::RegisterOptionItem(OptionsItemBase* item) | ||
{ | ||
auto v_iter = ms_customItems.find(this); | ||
if (v_iter == ms_customItems.end()) | ||
{ | ||
ms_customItems.emplace(this, std::vector<OptionsItemBase*>{ item }); | ||
return; | ||
} | ||
|
||
v_iter->second.push_back(item); | ||
} | ||
|
||
void GraphicsOptionsMenu::DestroyOptionItems() | ||
{ | ||
auto v_iter = ms_customItems.find(this); | ||
if (v_iter == ms_customItems.end()) | ||
return; | ||
|
||
for (auto v_item_ptr : v_iter->second) | ||
v_item_ptr->~OptionsItemBase(); | ||
|
||
ms_customItems.erase(v_iter); | ||
} | ||
|
||
__int64 GraphicsOptionsMenu::h_CreateWidgets(GraphicsOptionsMenu* self) | ||
{ | ||
if (Memory::ToLocalOffset(*reinterpret_cast<void**>(self)) == 0xF65600) | ||
{ | ||
DebugOutL(__FUNCTION__, " -> Injected custom game settings"); | ||
|
||
constexpr float v_min_sun_angle = DirectX::XMConvertToRadians(-70.0f); | ||
constexpr float v_max_sun_angle = DirectX::XMConvertToRadians(70.0f); | ||
|
||
GameSettings::UpdateFloatSetting("SunAngle", DynamicSun::ms_fSunAngle); | ||
|
||
MyGUI::Widget* v_new_option = self->options2.createNewOption(); | ||
OptionsItemSlider* v_new_slider = new OptionsItemSlider( | ||
v_new_option, "Sun Angle", "SunAngle", v_min_sun_angle, v_max_sun_angle, 20, | ||
[](std::size_t value) -> void { | ||
DynamicSun::ms_fSunAngle = *reinterpret_cast<float*>(&value); | ||
} | ||
); | ||
|
||
self->RegisterOptionItem(v_new_slider); | ||
v_new_slider->Update(); | ||
} | ||
|
||
return GraphicsOptionsMenu::o_CreateWidgets(self); | ||
} | ||
|
||
void GraphicsOptionsMenu::h_Destructor(GraphicsOptionsMenu* self, char flag) | ||
{ | ||
//Cleanup custom options | ||
self->DestroyOptionItems(); | ||
o_Destructor(self, flag); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#pragma once | ||
|
||
#include "OptionsItemDropDown.hpp" | ||
|
||
#include <unordered_map> | ||
#include <vector> | ||
#include <string> | ||
#include <memory> | ||
|
||
struct Options | ||
{ | ||
/* 0x0000 */ char pad_0x0[0x8]; | ||
/* 0x0008 */ std::string skin; | ||
/* 0x0028 */ char pad_0x28[0x38]; | ||
/* 0x0060 */ std::vector<MyGUI::Widget*> widgets; | ||
/* 0x0078 */ MyGUI::Colour color; | ||
|
||
MyGUI::Widget* createNewOption(); | ||
}; // Size: 0x88 | ||
|
||
struct OptionsSubMenuBase | ||
{ | ||
/* 0x0000 */ char pad_0x0[0x30]; | ||
/* 0x0030 */ Options options1; | ||
/* 0x00B8 */ Options options2; | ||
/* 0x0140 */ char pad_0x140[0x28]; | ||
}; // Size: 0x168 | ||
|
||
static_assert(sizeof(OptionsSubMenuBase) == 0x168, "OptionsSubMenuBase: Incorrect Size"); | ||
|
||
struct GraphicsOptionsMenu; | ||
|
||
template<typename T> | ||
struct CustomHasher | ||
{ | ||
inline std::size_t operator()(const T* ptr) const noexcept | ||
{ | ||
return reinterpret_cast<std::size_t>(ptr); | ||
} | ||
}; | ||
|
||
struct GraphicsOptionsMenu : public OptionsSubMenuBase | ||
{ | ||
using CreateWidgetsSig = __int64 (*)(GraphicsOptionsMenu*); | ||
using Destructor = void (*)(GraphicsOptionsMenu*, char); | ||
|
||
inline static std::unordered_map<const GraphicsOptionsMenu*, | ||
std::vector<OptionsItemBase*>, CustomHasher<void>> ms_customItems = {}; | ||
|
||
/* 0x0168 */ MyGUI::Button* some_button; | ||
/* 0x0170 */ std::shared_ptr<OptionsItemDropDown> shader_quality_dropdown; | ||
/* 0x0180 */ std::shared_ptr<OptionsItemDropDown> reflection_quality_dropdown; | ||
/* 0x0190 */ std::shared_ptr<OptionsItemDropDown> shadow_resolution_dropdown; | ||
/* 0x01A0 */ std::shared_ptr<OptionsItemDropDown> shadow_quality_dropdown; | ||
/* 0x01B0 */ std::shared_ptr<OptionsItemDropDown> ssao_dropdown; | ||
/* 0x01C0 */ std::shared_ptr<OptionsItemDropDown> foliage_dropdown; | ||
/* 0x01D0 */ std::shared_ptr<OptionsItemDropDown> texture_quality_dropdown; | ||
/* 0x01E0 */ std::shared_ptr<OptionsItemDropDown> draw_distance_dropdown; | ||
/* 0x01F0 */ std::shared_ptr<OptionsItemDropDown> tex_filtering_dropdown; | ||
/* 0x0200 */ std::shared_ptr<OptionsItemDropDown> particle_quality_dropdown; | ||
/* 0x0210 */ std::vector<std::string> quality_level_labels; | ||
/* 0x0228 */ char pad_0x228[0x20]; | ||
|
||
void RegisterOptionItem(OptionsItemBase* item); | ||
void DestroyOptionItems(); | ||
|
||
inline static CreateWidgetsSig o_CreateWidgets = nullptr; | ||
inline static Destructor o_Destructor = nullptr; | ||
|
||
static __int64 h_CreateWidgets(GraphicsOptionsMenu* self); | ||
static void h_Destructor(GraphicsOptionsMenu* self, char flag); | ||
}; // Size: 0x248 | ||
|
||
static_assert(sizeof(GraphicsOptionsMenu) == 0x248, "GraphicsOptionsMenu: Incorrect Size"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "MyGUIAny.hpp" | ||
|
||
#include "Utils/Console.hpp" | ||
#include "Utils/Memory.hpp" | ||
|
||
namespace MyGUI | ||
{ | ||
Any::HolderSizeT::HolderSizeT(std::size_t value) | ||
{ | ||
this->vftable = Memory::GetGlobal<void*>(0xF5CCC8); | ||
this->value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
namespace MyGUI | ||
{ | ||
struct Any | ||
{ | ||
struct Holder {}; | ||
|
||
struct HolderSizeT : Holder | ||
{ | ||
void* vftable; | ||
std::size_t value; | ||
|
||
HolderSizeT(std::size_t value); | ||
}; | ||
|
||
template<typename T> | ||
Any(const T& value) | ||
{ | ||
if constexpr (std::is_same_v<T, std::size_t>) | ||
{ | ||
this->holder = new HolderSizeT(value); | ||
} | ||
else | ||
{ | ||
this->holder = nullptr; | ||
} | ||
} | ||
|
||
~Any() = default; | ||
|
||
template<typename T> | ||
inline T GetValue() const | ||
{ | ||
return *reinterpret_cast<T*>(reinterpret_cast<char*>(holder) + 8); | ||
} | ||
|
||
Holder* holder; | ||
}; | ||
} |
Oops, something went wrong.