Skip to content

Commit e925723

Browse files
Clippy95Clippy95marinesciencedude
committed
Just Cause support. (#34)
* 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]>
1 parent c10213f commit e925723

File tree

5 files changed

+229
-0
lines changed

5 files changed

+229
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ This is a fork of [emoose's Xenia build](https://github.com/emoose/xenia) as ori
5656
| Crackdown 2 | TU0/TU5 |
5757
| Saints Row 2 | TU3 |
5858
| Dark Messiah of Might and Magic | Singleplayer & Multiplayer |
59+
| Just Cause | TU0 |
5960
| Red Dead Redemption | Original TU0/TU9, Undead Nightmare (Platinum Hits) TU4 & Game Of The Year Edition Disk 1/2 TU0|
6061
| Far Cry Instincts: Predator | TU0 |
6162
| Dead Rising 2 Case West | TU0 |

bindings.ini

+29
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,35 @@ Left = RS-Left
328328
Right = RS-Right
329329
CapsLock = A
330330

331+
[534307D5 Default - Just Cause]
332+
CapsLock = Modifier
333+
W = LS-Up
334+
S = LS-Down
335+
A = LS-Left
336+
D = LS-Right
337+
Space = B
338+
F = Y
339+
R = RB
340+
E = A
341+
Q = X
342+
1 = Left
343+
2 = Right
344+
3 = Up
345+
4 = Down
346+
C = B
347+
LClick = RT
348+
RClick = LT
349+
Enter = Start
350+
Tab = Back
351+
T = LB
352+
C = LS
353+
Shift = LS
354+
V = RS
355+
Up = Up
356+
Down = Down
357+
Left = Left
358+
Right = Right
359+
331360
[545107FC Default - Saints Row 2]
332361
W = LS-Up
333362
S = LS-Down
+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
******************************************************************************
3+
* Xenia : Xbox 360 Emulator Research Project *
4+
******************************************************************************
5+
* Copyright 2023 Ben Vanik. All rights reserved. *
6+
* Released under the BSD license - see LICENSE in the root for more details. *
7+
******************************************************************************
8+
*/
9+
10+
#define _USE_MATH_DEFINES
11+
12+
#include "xenia/hid/winkey/hookables/JustCause.h"
13+
14+
#include "xenia/base/platform_win.h"
15+
#include "xenia/cpu/processor.h"
16+
#include "xenia/emulator.h"
17+
#include "xenia/hid/hid_flags.h"
18+
#include "xenia/hid/input_system.h"
19+
#include "xenia/kernel/util/shim_utils.h"
20+
#include "xenia/kernel/xmodule.h"
21+
#include "xenia/kernel/xthread.h"
22+
#include "xenia/xbox.h"
23+
24+
using namespace xe::kernel;
25+
26+
DECLARE_double(sensitivity);
27+
DECLARE_bool(invert_y);
28+
DECLARE_bool(invert_x);
29+
30+
const uint32_t kTitleIdJustCause = 0x534307D5;
31+
32+
namespace xe {
33+
namespace hid {
34+
namespace winkey {
35+
struct GameBuildAddrs {
36+
const char* title_version;
37+
uint32_t cameracontroller_pointer_address;
38+
uint32_t SteerAddYaw_offset;
39+
uint32_t SteerAddPitch_offset;
40+
};
41+
42+
std::map<JustCauseGame::GameBuild, GameBuildAddrs> supported_builds{
43+
{JustCauseGame::GameBuild::JustCause1_TU0,
44+
{"1.0", 0x46965100, 0x130, 0x12C}}};
45+
46+
JustCauseGame::~JustCauseGame() = default;
47+
48+
bool JustCauseGame::IsGameSupported() {
49+
if (kernel_state()->title_id() != kTitleIdJustCause) {
50+
return false;
51+
}
52+
53+
const std::string current_version =
54+
kernel_state()->emulator()->title_version();
55+
56+
for (auto& build : supported_builds) {
57+
if (current_version == build.second.title_version) {
58+
game_build_ = build.first;
59+
return true;
60+
}
61+
}
62+
63+
return false;
64+
}
65+
66+
/* float JustCauseGame::DegreetoRadians(float degree) {
67+
return (float)(degree * (M_PI / 180));
68+
}
69+
70+
float JustCauseGame::RadianstoDegree(float radians) {
71+
return (float)(radians * (180 / M_PI));
72+
}
73+
*/
74+
75+
bool JustCauseGame::DoHooks(uint32_t user_index, RawInputState& input_state,
76+
X_INPUT_STATE* out_state) {
77+
if (!IsGameSupported()) {
78+
return false;
79+
}
80+
81+
if (supported_builds.count(game_build_) == 0) {
82+
return false;
83+
}
84+
85+
XThread* current_thread = XThread::GetCurrentThread();
86+
87+
if (!current_thread) {
88+
return false;
89+
}
90+
91+
/*
92+
TODO: Vehicle Camera which is CMachineCamera
93+
and Possibly turrets which is CMountedGunCamera
94+
95+
Some addresses used are in radians,
96+
Vehicle in-game camera is more closer to racing games cameras than a traditional
97+
GTA-styled freecam.
98+
99+
*/
100+
101+
xe::be<uint32_t>* base_address =
102+
kernel_memory()->TranslateVirtual<xe::be<uint32_t>*>(
103+
supported_builds[game_build_].cameracontroller_pointer_address);
104+
105+
if (!base_address || *base_address == NULL) {
106+
// Not in game
107+
return false;
108+
}
109+
110+
xe::be<uint32_t> x_address =
111+
*base_address + supported_builds[game_build_].SteerAddYaw_offset;
112+
xe::be<uint32_t> y_address =
113+
*base_address + supported_builds[game_build_].SteerAddPitch_offset;
114+
115+
xe::be<float>* add_x =
116+
kernel_memory()->TranslateVirtual<xe::be<float>*>(x_address);
117+
118+
xe::be<float>* add_y =
119+
kernel_memory()->TranslateVirtual<xe::be<float>*>(y_address);
120+
121+
float camx = *add_x;
122+
float camy = *add_y;
123+
// X-axis = 0 to 360
124+
if (!cvars::invert_x) {
125+
camx += (input_state.mouse.x_delta / 5.f) * (float)cvars::sensitivity;
126+
127+
} else {
128+
camx -= (input_state.mouse.x_delta / 5.f) * (float)cvars::sensitivity;
129+
}
130+
*add_x = camx;
131+
// Y-axis = -90 to 90
132+
if (!cvars::invert_y) {
133+
camy += (input_state.mouse.y_delta / 5.f) * (float)cvars::sensitivity;
134+
} else {
135+
camy -= (input_state.mouse.y_delta / 5.f) * (float)cvars::sensitivity;
136+
}
137+
*add_y = camy;
138+
139+
return true;
140+
}
141+
142+
std::string JustCauseGame::ChooseBinds() { return "Default"; }
143+
144+
bool JustCauseGame::ModifierKeyHandler(uint32_t user_index,
145+
RawInputState& input_state,
146+
X_INPUT_STATE* out_state) {
147+
return false;
148+
}
149+
} // namespace winkey
150+
} // namespace hid
151+
} // namespace xe
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
******************************************************************************
3+
* Xenia : Xbox 360 Emulator Research Project *
4+
******************************************************************************
5+
* Copyright 2023 Ben Vanik. All rights reserved. *
6+
* Released under the BSD license - see LICENSE in the root for more details. *
7+
******************************************************************************
8+
*/
9+
10+
#ifndef XENIA_HID_WINKEY_JustCause_H_
11+
#define XENIA_HID_WINKEY_JustCause_H_
12+
13+
#include "xenia/hid/winkey/hookables/hookable_game.h"
14+
15+
namespace xe {
16+
namespace hid {
17+
namespace winkey {
18+
19+
class JustCauseGame : public HookableGame {
20+
public:
21+
enum class GameBuild { Unknown, JustCause1_TU0 };
22+
23+
~JustCauseGame() override;
24+
25+
bool IsGameSupported();
26+
/*
27+
float RadianstoDegree(float radians);
28+
float DegreetoRadians(float degree);
29+
*/
30+
bool DoHooks(uint32_t user_index, RawInputState& input_state,
31+
X_INPUT_STATE* out_state);
32+
33+
std::string ChooseBinds();
34+
35+
bool ModifierKeyHandler(uint32_t user_index, RawInputState& input_state,
36+
X_INPUT_STATE* out_state);
37+
38+
private:
39+
GameBuild game_build_ = GameBuild::Unknown;
40+
};
41+
42+
} // namespace winkey
43+
} // namespace hid
44+
} // namespace xe
45+
46+
#endif // XENIA_HID_WINKEY_JustCause_H_

src/xenia/hid/winkey/winkey_input_driver.cc

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "xenia/hid/winkey/hookables/DeadRising.h"
2424
#include "xenia/hid/winkey/hookables/Farcry.h"
2525
#include "xenia/hid/winkey/hookables/GearsOfWars.h"
26+
#include "xenia/hid/winkey/hookables/JustCause.h"
2627
#include "xenia/hid/winkey/hookables/RDR.h"
2728
#include "xenia/hid/winkey/hookables/SaintsRow.h"
2829
#include "xenia/hid/winkey/hookables/SourceEngine.h"
@@ -462,6 +463,7 @@ WinKeyInputDriver::WinKeyInputDriver(xe::ui::Window* window,
462463
hookable_games_.push_back(std::move(std::make_unique<SourceEngine>()));
463464
hookable_games_.push_back(std::move(std::make_unique<Crackdown2Game>()));
464465
hookable_games_.push_back(std::move(std::make_unique<SaintsRowGame>()));
466+
hookable_games_.push_back(std::move(std::make_unique<JustCauseGame>()));
465467
hookable_games_.push_back(
466468
std::move(std::make_unique<RedDeadRedemptionGame>()));
467469
hookable_games_.push_back(std::move(std::make_unique<FarCryGame>()));

0 commit comments

Comments
 (0)