Skip to content

Commit e018d73

Browse files
authored
Merge branch 'praydog:master' into master
2 parents c9c3c65 + 6cd87ef commit e018d73

12 files changed

Lines changed: 542 additions & 30 deletions

shared/sdk/MurmurHash.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ uint32_t calc32(std::wstring_view str) {
2020
uint32_t calc32(std::string_view str) {
2121
return calc32(utility::widen(str));
2222
}
23+
24+
uint32_t calc32_as_utf8(std::string_view str) {
25+
static auto calc_method = type()->get_method("calc32AsUTF8");
26+
27+
return calc_method->call<uint32_t>(sdk::get_thread_context(), sdk::VM::create_managed_string(utility::widen(str)), str.length());
28+
}
2329
}

shared/sdk/MurmurHash.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ namespace murmur_hash {
1111
sdk::RETypeDefinition* type();
1212
uint32_t calc32(std::wstring_view str);
1313
uint32_t calc32(std::string_view str);
14+
uint32_t calc32_as_utf8(std::string_view str);
1415
}
1516
}

shared/sdk/REComponent.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ namespace utility::re_component {
4242
return nullptr;
4343
}
4444

45+
template<typename T = ::REComponent>
46+
static T** find_replaceable(::REComponent* comp, REType* t) {
47+
for (auto* child = &comp->childComponent; *child != nullptr && *child != comp; child = &(*child)->childComponent) {
48+
if (utility::re_managed_object::is_a(*child, t)) {
49+
return (T**)child;
50+
}
51+
}
52+
53+
return nullptr;
54+
}
55+
4556
// Find a component using the getComponent method
4657
/*template <typename T = ::REComponent>
4758
static T *find_using_method(::REComponent *comp, std::string_view name) {

shared/sdk/intrusive_ptr.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class intrusive_ptr {
6161
return m_ptr != nullptr;
6262
}
6363

64+
void reset() {
65+
if (m_ptr != nullptr) {
66+
m_ptr->release();
67+
m_ptr = nullptr;
68+
}
69+
}
70+
6471
private:
6572
T* m_ptr{nullptr};
6673
};

src/Mods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Mods::Mods() {
4444

4545
// All games!!!!
4646
m_mods.emplace_back(std::make_unique<Camera>());
47-
m_mods.emplace_back(std::make_unique<Graphics>());
47+
m_mods.emplace_back(Graphics::get());
4848

4949
#if defined(RE2) || defined(RE3) || defined(RE8)
5050
m_mods.emplace_back(std::make_unique<ManualFlashlight>());

src/REFramework.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class REFramework {
4545
Address get_module() const { return m_game_module; }
4646

4747
bool is_ready() const { return m_initialized && m_game_data_initialized; }
48+
bool is_ui_focused() const { return m_is_ui_focused; }
4849

4950
void run_imgui_frame(bool from_present);
5051

src/mods/FreeCam.cpp

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ void FreeCam::on_update_transform(RETransform* transform) {
123123
return;
124124
}
125125

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

168167
m_first_time = false;
169168

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

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

214214
// Controller support
215215
if (pad != nullptr) {
216+
static const auto gamepad_device_t = sdk::find_type_definition("via.hid.GamePadDevice");
217+
static const auto is_down = gamepad_device_t != nullptr ? gamepad_device_t->get_method("isDown(via.hid.GamePadButton)") : nullptr;
218+
216219
// Move direction
217220
// It's not a Vector2f because via.vec2 is not actually 8 bytes, we don't want stack corruption to occur.
218221
const auto axis_l = *re_managed_object::get_field<Vector3f*>(pad, "AxisL");
219222
const auto axis_r = *re_managed_object::get_field<Vector3f*>(pad, "AxisR");
220223

221-
m_custom_angles[0] += axis_r.y * rotation_speed * delta * timescale_mult;
222-
m_custom_angles[1] -= axis_r.x * rotation_speed * delta * timescale_mult;
223-
m_custom_angles[2] = 0.0f;
224+
bool is_using_up_down_modifier = false;
225+
bool is_using_twist_modifier = false;
226+
227+
if (is_down != nullptr) {
228+
const auto dpad_up_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LUp);
229+
const auto dpad_down_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LDown);
230+
231+
if (dpad_up_is_down) {
232+
dir.y = 1.0f;
233+
} else if (dpad_down_is_down) {
234+
dir.y = -1.0f;
235+
}
236+
237+
const auto dpad_left_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LLeft);
238+
const auto dpad_right_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LRight);
239+
240+
if (dpad_left_is_down) {
241+
dir.x -= 1.0f;
242+
} else if (dpad_right_is_down) {
243+
dir.x += 1.0f;
244+
}
245+
246+
const auto l_trigger_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::LTrigBottom);
247+
248+
if (l_trigger_is_down) {
249+
if (glm::length(axis_r) > 0.0f) {
250+
dir += Vector4f{ 0.0, axis_r.y, 0.0, 0.0f };
251+
is_using_up_down_modifier = true;
252+
}
253+
}
254+
255+
const auto r_trigger_is_down = is_down->call_safe<bool>(sdk::get_thread_context(), pad, via::hid::GamePadButton::RTrigBottom);
256+
257+
if (r_trigger_is_down) {
258+
if (glm::length(axis_r) > 0.0f) {
259+
m_custom_angles[2] -= axis_r.x * rotation_speed * delta * timescale_mult;
260+
is_using_twist_modifier = true;
261+
}
262+
}
263+
}
264+
265+
if (!is_using_up_down_modifier && !is_using_twist_modifier) {
266+
m_custom_angles[0] += axis_r.y * rotation_speed * delta * timescale_mult;
267+
m_custom_angles[1] -= axis_r.x * rotation_speed * delta * timescale_mult;
268+
//m_custom_angles[2] = 0.0f;
269+
}
224270

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

@@ -252,19 +298,28 @@ void FreeCam::on_update_transform(RETransform* transform) {
252298
dir_speed *= dir_speed_mod_slow;
253299
}
254300

255-
const auto& mouse_delta = g_framework->get_mouse_delta();
301+
if (!g_framework->is_ui_focused()) {
302+
const auto& mouse_delta = g_framework->get_mouse_delta();
256303

257-
m_custom_angles[0] -= mouse_delta[1] * rotation_speed_kbm * delta * timescale_mult;
258-
m_custom_angles[1] -= mouse_delta[0] * rotation_speed_kbm * delta * timescale_mult;
259-
m_custom_angles[2] = 0.0f;
304+
if (keyboard_state[VK_RBUTTON]) {
305+
m_custom_angles[2] -= mouse_delta[0] * rotation_speed_kbm * delta * timescale_mult;
306+
} else {
307+
m_custom_angles[0] -= mouse_delta[1] * rotation_speed_kbm * delta * timescale_mult;
308+
m_custom_angles[1] -= mouse_delta[0] * rotation_speed_kbm * delta * timescale_mult;
309+
}
310+
}
260311

261312
math::fix_angles(m_custom_angles);
262313

263-
const auto new_rotation = Matrix4x4f{ glm::quat{ m_custom_angles } };
264-
const auto new_pos = m_last_camera_matrix[3] + new_rotation * dir * (dir_speed * delta * timescale_mult);
314+
if (glm::length(m_custom_angles) > 0.0f) {
315+
m_custom_rotation *= glm::quat{ m_custom_angles };
316+
m_custom_angles = {};
317+
}
318+
319+
const auto new_pos = m_last_camera_matrix[3] + m_custom_rotation * dir * (dir_speed * delta * timescale_mult);
265320

266321
// Keep track of the rotation if we want to lock the camera
267-
m_last_camera_matrix = new_rotation;
322+
m_last_camera_matrix = glm::mat4{m_custom_rotation};
268323
m_last_camera_matrix[3] = new_pos;
269324
}
270325

src/mods/FreeCam.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FreeCam : public Mod {
3636
const ModSlider::Ptr m_speed{ ModSlider::create(generate_name("Speed"), 0.0f, 1.0f, 0.1f) };
3737
const ModSlider::Ptr m_speed_modifier{ ModSlider::create(generate_name("SpeedModifier"), 1.f, 50.f, 4.f) };
3838

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

4141
ValueList m_options{
4242
*m_enabled,
@@ -71,6 +71,7 @@ class FreeCam : public Mod {
7171
bool m_was_disabled{ false };
7272

7373
Vector3f m_custom_angles{};
74+
glm::quat m_custom_rotation{};
7475

7576
RECamera* m_camera{nullptr};
7677

0 commit comments

Comments
 (0)