Skip to content

Commit

Permalink
Merge branch 'praydog:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyhodge authored May 4, 2024
2 parents c9c3c65 + 6cd87ef commit e018d73
Show file tree
Hide file tree
Showing 12 changed files with 542 additions and 30 deletions.
6 changes: 6 additions & 0 deletions shared/sdk/MurmurHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ uint32_t calc32(std::wstring_view str) {
uint32_t calc32(std::string_view str) {
return calc32(utility::widen(str));
}

uint32_t calc32_as_utf8(std::string_view str) {
static auto calc_method = type()->get_method("calc32AsUTF8");

return calc_method->call<uint32_t>(sdk::get_thread_context(), sdk::VM::create_managed_string(utility::widen(str)), str.length());
}
}
1 change: 1 addition & 0 deletions shared/sdk/MurmurHash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ namespace murmur_hash {
sdk::RETypeDefinition* type();
uint32_t calc32(std::wstring_view str);
uint32_t calc32(std::string_view str);
uint32_t calc32_as_utf8(std::string_view str);
}
}
11 changes: 11 additions & 0 deletions shared/sdk/REComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ namespace utility::re_component {
return nullptr;
}

template<typename T = ::REComponent>
static T** find_replaceable(::REComponent* comp, REType* t) {
for (auto* child = &comp->childComponent; *child != nullptr && *child != comp; child = &(*child)->childComponent) {
if (utility::re_managed_object::is_a(*child, t)) {
return (T**)child;
}
}

return nullptr;
}

// Find a component using the getComponent method
/*template <typename T = ::REComponent>
static T *find_using_method(::REComponent *comp, std::string_view name) {
Expand Down
7 changes: 7 additions & 0 deletions shared/sdk/intrusive_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class intrusive_ptr {
return m_ptr != nullptr;
}

void reset() {
if (m_ptr != nullptr) {
m_ptr->release();
m_ptr = nullptr;
}
}

private:
T* m_ptr{nullptr};
};
Expand Down
2 changes: 1 addition & 1 deletion src/Mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Mods::Mods() {

// All games!!!!
m_mods.emplace_back(std::make_unique<Camera>());
m_mods.emplace_back(std::make_unique<Graphics>());
m_mods.emplace_back(Graphics::get());

#if defined(RE2) || defined(RE3) || defined(RE8)
m_mods.emplace_back(std::make_unique<ManualFlashlight>());
Expand Down
1 change: 1 addition & 0 deletions src/REFramework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class REFramework {
Address get_module() const { return m_game_module; }

bool is_ready() const { return m_initialized && m_game_data_initialized; }
bool is_ui_focused() const { return m_is_ui_focused; }

void run_imgui_frame(bool from_present);

Expand Down
81 changes: 68 additions & 13 deletions src/mods/FreeCam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ void FreeCam::on_update_transform(RETransform* transform) {
return;
}


#if defined(RE2) || defined(RE3)
static auto get_player_condition_method = sdk::find_method_definition(game_namespace("SurvivorManager"), "get_Player");
static auto get_action_orderer_method = sdk::find_method_definition(game_namespace("survivor.SurvivorCondition"), "get_ActionOrderer");
Expand Down Expand Up @@ -167,7 +166,8 @@ void FreeCam::on_update_transform(RETransform* transform) {

m_first_time = false;

m_custom_angles = math::euler_angles(glm::extractMatrixRotation(m_last_camera_matrix));
m_custom_rotation = glm::extractMatrixRotation(m_last_camera_matrix);
m_custom_angles = {}; // per-frame rotation gets reset.
//m_custom_angles[1] *= -1.0f;
//m_custom_angles[1] += glm::radians(180.0f);

Expand Down Expand Up @@ -213,17 +213,63 @@ void FreeCam::on_update_transform(RETransform* transform) {

// Controller support
if (pad != nullptr) {
static const auto gamepad_device_t = sdk::find_type_definition("via.hid.GamePadDevice");
static const auto is_down = gamepad_device_t != nullptr ? gamepad_device_t->get_method("isDown(via.hid.GamePadButton)") : nullptr;

// Move direction
// It's not a Vector2f because via.vec2 is not actually 8 bytes, we don't want stack corruption to occur.
const auto axis_l = *re_managed_object::get_field<Vector3f*>(pad, "AxisL");
const auto axis_r = *re_managed_object::get_field<Vector3f*>(pad, "AxisR");

m_custom_angles[0] += axis_r.y * rotation_speed * delta * timescale_mult;
m_custom_angles[1] -= axis_r.x * rotation_speed * delta * timescale_mult;
m_custom_angles[2] = 0.0f;
bool is_using_up_down_modifier = false;
bool is_using_twist_modifier = false;

if (is_down != nullptr) {
const auto dpad_up_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LUp);
const auto dpad_down_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LDown);

if (dpad_up_is_down) {
dir.y = 1.0f;
} else if (dpad_down_is_down) {
dir.y = -1.0f;
}

const auto dpad_left_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LLeft);
const auto dpad_right_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LRight);

if (dpad_left_is_down) {
dir.x -= 1.0f;
} else if (dpad_right_is_down) {
dir.x += 1.0f;
}

const auto l_trigger_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LTrigBottom);

if (l_trigger_is_down) {
if (glm::length(axis_r) > 0.0f) {
dir += Vector4f{ 0.0, axis_r.y, 0.0, 0.0f };
is_using_up_down_modifier = true;
}
}

const auto r_trigger_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::RTrigBottom);

if (r_trigger_is_down) {
if (glm::length(axis_r) > 0.0f) {
m_custom_angles[2] -= axis_r.x * rotation_speed * delta * timescale_mult;
is_using_twist_modifier = true;
}
}
}

if (!is_using_up_down_modifier && !is_using_twist_modifier) {
m_custom_angles[0] += axis_r.y * rotation_speed * delta * timescale_mult;
m_custom_angles[1] -= axis_r.x * rotation_speed * delta * timescale_mult;
//m_custom_angles[2] = 0.0f;
}

if (glm::length(axis_l) > 0.0f) {
dir = Vector4f{ axis_l.x, 0.0f, axis_l.y * -1.0f, 0.0f };
dir += Vector4f{ axis_l.x, 0.0f, axis_l.y * -1.0f, 0.0f };
}
}

Expand Down Expand Up @@ -252,19 +298,28 @@ void FreeCam::on_update_transform(RETransform* transform) {
dir_speed *= dir_speed_mod_slow;
}

const auto& mouse_delta = g_framework->get_mouse_delta();
if (!g_framework->is_ui_focused()) {
const auto& mouse_delta = g_framework->get_mouse_delta();

m_custom_angles[0] -= mouse_delta[1] * rotation_speed_kbm * delta * timescale_mult;
m_custom_angles[1] -= mouse_delta[0] * rotation_speed_kbm * delta * timescale_mult;
m_custom_angles[2] = 0.0f;
if (keyboard_state[VK_RBUTTON]) {
m_custom_angles[2] -= mouse_delta[0] * rotation_speed_kbm * delta * timescale_mult;
} else {
m_custom_angles[0] -= mouse_delta[1] * rotation_speed_kbm * delta * timescale_mult;
m_custom_angles[1] -= mouse_delta[0] * rotation_speed_kbm * delta * timescale_mult;
}
}

math::fix_angles(m_custom_angles);

const auto new_rotation = Matrix4x4f{ glm::quat{ m_custom_angles } };
const auto new_pos = m_last_camera_matrix[3] + new_rotation * dir * (dir_speed * delta * timescale_mult);
if (glm::length(m_custom_angles) > 0.0f) {
m_custom_rotation *= glm::quat{ m_custom_angles };
m_custom_angles = {};
}

const auto new_pos = m_last_camera_matrix[3] + m_custom_rotation * dir * (dir_speed * delta * timescale_mult);

// Keep track of the rotation if we want to lock the camera
m_last_camera_matrix = new_rotation;
m_last_camera_matrix = glm::mat4{m_custom_rotation};
m_last_camera_matrix[3] = new_pos;
}

Expand Down
3 changes: 2 additions & 1 deletion src/mods/FreeCam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FreeCam : public Mod {
const ModSlider::Ptr m_speed{ ModSlider::create(generate_name("Speed"), 0.0f, 1.0f, 0.1f) };
const ModSlider::Ptr m_speed_modifier{ ModSlider::create(generate_name("SpeedModifier"), 1.f, 50.f, 4.f) };

const ModSlider::Ptr m_rotation_speed{ ModSlider::create(generate_name("RotationSpeed"), 0.0f, 1.0f, 1.0f) };
const ModSlider::Ptr m_rotation_speed{ ModSlider::create(generate_name("RotationSpeed"), 0.0f, 1.0f, 0.1f) };

ValueList m_options{
*m_enabled,
Expand Down Expand Up @@ -71,6 +71,7 @@ class FreeCam : public Mod {
bool m_was_disabled{ false };

Vector3f m_custom_angles{};
glm::quat m_custom_rotation{};

RECamera* m_camera{nullptr};

Expand Down
Loading

0 comments on commit e018d73

Please sign in to comment.