Skip to content

Commit

Permalink
Just Cause support. (#34)
Browse files Browse the repository at this point in the history
* Update README.md

* Just Cause 1 basic support (broken vehicle camera)

* Just Cause readme

* Comments

* Bindings

---------

Co-authored-by: Clippy95 <[email protected]>
Co-authored-by: Marine Biologist <[email protected]>
  • Loading branch information
3 people committed Oct 22, 2024
1 parent 4c4e1c7 commit 04052b3
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
29 changes: 29 additions & 0 deletions bindings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
151 changes: 151 additions & 0 deletions src/xenia/hid/winkey/hookables/JustCause.cc
Original file line number Diff line number Diff line change
@@ -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<JustCauseGame::GameBuild, GameBuildAddrs> 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<uint32_t>* base_address =
kernel_memory()->TranslateVirtual<xe::be<uint32_t>*>(
supported_builds[game_build_].cameracontroller_pointer_address);

if (!base_address || *base_address == NULL) {
// Not in game
return false;
}

xe::be<uint32_t> x_address =
*base_address + supported_builds[game_build_].SteerAddYaw_offset;
xe::be<uint32_t> y_address =
*base_address + supported_builds[game_build_].SteerAddPitch_offset;

xe::be<float>* add_x =
kernel_memory()->TranslateVirtual<xe::be<float>*>(x_address);

xe::be<float>* add_y =
kernel_memory()->TranslateVirtual<xe::be<float>*>(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
46 changes: 46 additions & 0 deletions src/xenia/hid/winkey/hookables/JustCause.h
Original file line number Diff line number Diff line change
@@ -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_
2 changes: 2 additions & 0 deletions src/xenia/hid/winkey/winkey_input_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -438,6 +439,7 @@ WinKeyInputDriver::WinKeyInputDriver(xe::ui::Window* window,
hookable_games_.push_back(std::move(std::make_unique<SourceEngine>()));
hookable_games_.push_back(std::move(std::make_unique<Crackdown2Game>()));
hookable_games_.push_back(std::move(std::make_unique<SaintsRowGame>()));
hookable_games_.push_back(std::move(std::make_unique<JustCauseGame>()));
hookable_games_.push_back(
std::move(std::make_unique<RedDeadRedemptionGame>()));
hookable_games_.push_back(std::move(std::make_unique<FarCryGame>()));
Expand Down

0 comments on commit 04052b3

Please sign in to comment.