diff --git a/README.md b/README.md index 510701be9c..45adf3570f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ This is a fork of [emoose's Xenia build](https://github.com/emoose/xenia) as ori | Crackdown 2 | TU0/TU5 | | Saints Row 2 | TU3 | | Dark Messiah of Might and Magic | Singleplayer & Multiplayer | +| Just Cause | TU0 | | Red Dead Redemption | Original TU0/TU9, Undead Nightmare (Platinum Hits) TU4 & Game Of The Year Edition Disk 1/2 TU0| | Far Cry Instincts: Predator | TU0 | | Dead Rising 2 Case West | TU0 | diff --git a/bindings.ini b/bindings.ini index 9cbbc8538e..363d619917 100644 --- a/bindings.ini +++ b/bindings.ini @@ -328,6 +328,35 @@ Left = RS-Left Right = RS-Right CapsLock = A +[534307D5 Default - Just Cause] +CapsLock = Modifier +W = LS-Up +S = LS-Down +A = LS-Left +D = LS-Right +Space = B +F = Y +R = RB +E = A +Q = X +1 = Left +2 = Right +3 = Up +4 = Down +C = B +LClick = RT +RClick = LT +Enter = Start +Tab = Back +T = LB +C = LS +Shift = LS +V = RS +Up = Up +Down = Down +Left = Left +Right = Right + [545107FC Default - Saints Row 2] W = LS-Up S = LS-Down diff --git a/src/xenia/hid/winkey/hookables/JustCause.cc b/src/xenia/hid/winkey/hookables/JustCause.cc new file mode 100644 index 0000000000..0b403a73a5 --- /dev/null +++ b/src/xenia/hid/winkey/hookables/JustCause.cc @@ -0,0 +1,151 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2023 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#define _USE_MATH_DEFINES + +#include "xenia/hid/winkey/hookables/JustCause.h" + +#include "xenia/base/platform_win.h" +#include "xenia/cpu/processor.h" +#include "xenia/emulator.h" +#include "xenia/hid/hid_flags.h" +#include "xenia/hid/input_system.h" +#include "xenia/kernel/util/shim_utils.h" +#include "xenia/kernel/xmodule.h" +#include "xenia/kernel/xthread.h" +#include "xenia/xbox.h" + +using namespace xe::kernel; + +DECLARE_double(sensitivity); +DECLARE_bool(invert_y); +DECLARE_bool(invert_x); + +const uint32_t kTitleIdJustCause = 0x534307D5; + +namespace xe { +namespace hid { +namespace winkey { +struct GameBuildAddrs { + const char* title_version; + uint32_t cameracontroller_pointer_address; + uint32_t SteerAddYaw_offset; + uint32_t SteerAddPitch_offset; +}; + +std::map supported_builds{ + {JustCauseGame::GameBuild::JustCause1_TU0, + {"1.0", 0x46965100, 0x130, 0x12C}}}; + +JustCauseGame::~JustCauseGame() = default; + +bool JustCauseGame::IsGameSupported() { + if (kernel_state()->title_id() != kTitleIdJustCause) { + return false; + } + + const std::string current_version = + kernel_state()->emulator()->title_version(); + + for (auto& build : supported_builds) { + if (current_version == build.second.title_version) { + game_build_ = build.first; + return true; + } + } + + return false; +} + +/* float JustCauseGame::DegreetoRadians(float degree) { + return (float)(degree * (M_PI / 180)); +} + +float JustCauseGame::RadianstoDegree(float radians) { + return (float)(radians * (180 / M_PI)); +} +*/ + +bool JustCauseGame::DoHooks(uint32_t user_index, RawInputState& input_state, + X_INPUT_STATE* out_state) { + if (!IsGameSupported()) { + return false; + } + + if (supported_builds.count(game_build_) == 0) { + return false; + } + + XThread* current_thread = XThread::GetCurrentThread(); + + if (!current_thread) { + return false; + } + + /* +TODO: Vehicle Camera which is CMachineCamera +and Possibly turrets which is CMountedGunCamera + +Some addresses used are in radians, +Vehicle in-game camera is more closer to racing games cameras than a traditional +GTA-styled freecam. + +*/ + + xe::be* base_address = + kernel_memory()->TranslateVirtual*>( + supported_builds[game_build_].cameracontroller_pointer_address); + + if (!base_address || *base_address == NULL) { + // Not in game + return false; + } + + xe::be x_address = + *base_address + supported_builds[game_build_].SteerAddYaw_offset; + xe::be y_address = + *base_address + supported_builds[game_build_].SteerAddPitch_offset; + + xe::be* add_x = + kernel_memory()->TranslateVirtual*>(x_address); + + xe::be* add_y = + kernel_memory()->TranslateVirtual*>(y_address); + + float camx = *add_x; + float camy = *add_y; + // X-axis = 0 to 360 + if (!cvars::invert_x) { + camx += (input_state.mouse.x_delta / 5.f) * (float)cvars::sensitivity; + + } else { + camx -= (input_state.mouse.x_delta / 5.f) * (float)cvars::sensitivity; + } + *add_x = camx; + // Y-axis = -90 to 90 + if (!cvars::invert_y) { + camy += (input_state.mouse.y_delta / 5.f) * (float)cvars::sensitivity; + } else { + camy -= (input_state.mouse.y_delta / 5.f) * (float)cvars::sensitivity; + } + *add_y = camy; + + return true; +} + +std::string JustCauseGame::ChooseBinds() { return "Default"; } + +bool JustCauseGame::ModifierKeyHandler(uint32_t user_index, + RawInputState& input_state, + X_INPUT_STATE* out_state) { + return false; +} +} // namespace winkey +} // namespace hid +} // namespace xe \ No newline at end of file diff --git a/src/xenia/hid/winkey/hookables/JustCause.h b/src/xenia/hid/winkey/hookables/JustCause.h new file mode 100644 index 0000000000..d476d05dcb --- /dev/null +++ b/src/xenia/hid/winkey/hookables/JustCause.h @@ -0,0 +1,46 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2023 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_HID_WINKEY_JustCause_H_ +#define XENIA_HID_WINKEY_JustCause_H_ + +#include "xenia/hid/winkey/hookables/hookable_game.h" + +namespace xe { +namespace hid { +namespace winkey { + +class JustCauseGame : public HookableGame { + public: + enum class GameBuild { Unknown, JustCause1_TU0 }; + + ~JustCauseGame() override; + + bool IsGameSupported(); + /* + float RadianstoDegree(float radians); + float DegreetoRadians(float degree); + */ + bool DoHooks(uint32_t user_index, RawInputState& input_state, + X_INPUT_STATE* out_state); + + std::string ChooseBinds(); + + bool ModifierKeyHandler(uint32_t user_index, RawInputState& input_state, + X_INPUT_STATE* out_state); + + private: + GameBuild game_build_ = GameBuild::Unknown; +}; + +} // namespace winkey +} // namespace hid +} // namespace xe + +#endif // XENIA_HID_WINKEY_JustCause_H_ diff --git a/src/xenia/hid/winkey/winkey_input_driver.cc b/src/xenia/hid/winkey/winkey_input_driver.cc index fb1aae0472..fc58916355 100644 --- a/src/xenia/hid/winkey/winkey_input_driver.cc +++ b/src/xenia/hid/winkey/winkey_input_driver.cc @@ -23,6 +23,7 @@ #include "xenia/hid/winkey/hookables/DeadRising.h" #include "xenia/hid/winkey/hookables/Farcry.h" #include "xenia/hid/winkey/hookables/GearsOfWars.h" +#include "xenia/hid/winkey/hookables/JustCause.h" #include "xenia/hid/winkey/hookables/RDR.h" #include "xenia/hid/winkey/hookables/SaintsRow.h" #include "xenia/hid/winkey/hookables/SourceEngine.h" @@ -438,6 +439,7 @@ WinKeyInputDriver::WinKeyInputDriver(xe::ui::Window* window, hookable_games_.push_back(std::move(std::make_unique())); hookable_games_.push_back(std::move(std::make_unique())); hookable_games_.push_back(std::move(std::make_unique())); + hookable_games_.push_back(std::move(std::make_unique())); hookable_games_.push_back( std::move(std::make_unique())); hookable_games_.push_back(std::move(std::make_unique()));