Skip to content

Commit 0329e63

Browse files
Clippy95Clippy95marinesciencedude
committed
Far Cry support (#28)
* Far Cry: Instincts Predator support * lint * Bindings for FC: Instincts Predator * Update README.md --------- Co-authored-by: Clippy95 <[email protected]> Co-authored-by: Marine Biologist <[email protected]>
1 parent 2000919 commit 0329e63

File tree

5 files changed

+207
-0
lines changed

5 files changed

+207
-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+
| Far Cry Instincts: Predator | TU0 |
5960
| Dead Rising 2 Case West | TU0 |
6061
| Dead Rising 2 Case Zero | TU0 |
6162
| Call Of Duty 3 | Singleplayer & Multiplayer TU0/TU3 |

bindings.ini

+27
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,33 @@ Down = Down
2222
Left = Left
2323
Right = Right
2424

25+
[555307DC Default - Far Cry Instincts Predator]
26+
CapsLock = Modifier
27+
W = LS-Up
28+
S = LS-Down
29+
A = LS-Left
30+
D = LS-Right
31+
Space = A
32+
R = X
33+
E = X
34+
Shift = Y
35+
1 = RB
36+
2 = LB
37+
3 = Up
38+
4 = Left
39+
5 = Right
40+
6 = Down
41+
V = B
42+
LClick = RT
43+
RClick = LT
44+
Mouse4 = Y
45+
Enter = Start
46+
Tab = Back
47+
4 = LB
48+
G = RB
49+
C = LS
50+
B = RS
51+
2552
[58410A8D Default - Dead Rising 2 Case Zero]
2653
CapsLock = Modifier
2754
W = LS-Up
+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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/Farcry.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 kTitleIdFarCry = 0x555307DC;
31+
32+
namespace xe {
33+
namespace hid {
34+
namespace winkey {
35+
struct GameBuildAddrs {
36+
const char* title_version;
37+
uint32_t base_address;
38+
uint32_t x_offset;
39+
uint32_t y_offset;
40+
};
41+
42+
std::map<FarCryGame::GameBuild, GameBuildAddrs> supported_builds{
43+
{FarCryGame::GameBuild::FarCry_TU0, {"1.0", 0x829138B8, 0x3AC, 0x3A4}}};
44+
45+
FarCryGame::~FarCryGame() = default;
46+
47+
bool FarCryGame::IsGameSupported() {
48+
if (kernel_state()->title_id() != kTitleIdFarCry) {
49+
return false;
50+
}
51+
52+
const std::string current_version =
53+
kernel_state()->emulator()->title_version();
54+
55+
for (auto& build : supported_builds) {
56+
if (current_version == build.second.title_version) {
57+
game_build_ = build.first;
58+
return true;
59+
}
60+
}
61+
62+
return false;
63+
}
64+
65+
bool FarCryGame::DoHooks(uint32_t user_index, RawInputState& input_state,
66+
X_INPUT_STATE* out_state) {
67+
if (!IsGameSupported()) {
68+
return false;
69+
}
70+
71+
if (supported_builds.count(game_build_) == 0) {
72+
return false;
73+
}
74+
75+
XThread* current_thread = XThread::GetCurrentThread();
76+
77+
if (!current_thread) {
78+
return false;
79+
}
80+
81+
xe::be<uint32_t>* base_address =
82+
kernel_memory()->TranslateVirtual<xe::be<uint32_t>*>(
83+
supported_builds[game_build_].base_address);
84+
85+
if (!base_address || *base_address == NULL) {
86+
// Not in game
87+
return false;
88+
}
89+
90+
xe::be<uint32_t> x_address =
91+
*base_address + supported_builds[game_build_].x_offset;
92+
xe::be<uint32_t> y_address =
93+
*base_address + supported_builds[game_build_].y_offset;
94+
95+
xe::be<float>* degree_x =
96+
kernel_memory()->TranslateVirtual<xe::be<float>*>(x_address);
97+
98+
xe::be<float>* degree_y =
99+
kernel_memory()->TranslateVirtual<xe::be<float>*>(y_address);
100+
101+
float new_degree_x = *degree_x;
102+
float new_degree_y = *degree_y;
103+
104+
if (!cvars::invert_x) {
105+
new_degree_x -=
106+
(input_state.mouse.x_delta / 7.5f) * (float)cvars::sensitivity;
107+
} else {
108+
new_degree_x +=
109+
(input_state.mouse.x_delta / 7.5f) * (float)cvars::sensitivity;
110+
}
111+
*degree_x = new_degree_x;
112+
113+
if (!cvars::invert_y) {
114+
new_degree_y +=
115+
(input_state.mouse.y_delta / 7.5f) * (float)cvars::sensitivity;
116+
} else {
117+
new_degree_y -=
118+
(input_state.mouse.y_delta / 7.5f) * (float)cvars::sensitivity;
119+
}
120+
*degree_y = new_degree_y;
121+
122+
return true;
123+
}
124+
125+
std::string FarCryGame::ChooseBinds() { return "Default"; }
126+
127+
bool FarCryGame::ModifierKeyHandler(uint32_t user_index,
128+
RawInputState& input_state,
129+
X_INPUT_STATE* out_state) {
130+
return false;
131+
}
132+
} // namespace winkey
133+
} // namespace hid
134+
} // namespace xe
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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_FarCry_H_
11+
#define XENIA_HID_WINKEY_FarCry_H_
12+
13+
#include "xenia/hid/winkey/hookables/hookable_game.h"
14+
15+
namespace xe {
16+
namespace hid {
17+
namespace winkey {
18+
19+
class FarCryGame : public HookableGame {
20+
public:
21+
enum class GameBuild { Unknown, FarCry_TU0 };
22+
23+
~FarCryGame() override;
24+
25+
bool IsGameSupported();
26+
27+
bool DoHooks(uint32_t user_index, RawInputState& input_state,
28+
X_INPUT_STATE* out_state);
29+
30+
std::string ChooseBinds();
31+
32+
bool ModifierKeyHandler(uint32_t user_index, RawInputState& input_state,
33+
X_INPUT_STATE* out_state);
34+
35+
private:
36+
GameBuild game_build_ = GameBuild::Unknown;
37+
};
38+
39+
} // namespace winkey
40+
} // namespace hid
41+
} // namespace xe
42+
43+
#endif // XENIA_HID_WINKEY_FarCry_H_

src/xenia/hid/winkey/winkey_input_driver.cc

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "xenia/hid/winkey/hookables/CallOfDuty.h"
2222
#include "xenia/hid/winkey/hookables/Crackdown2.h"
2323
#include "xenia/hid/winkey/hookables/DeadRising.h"
24+
#include "xenia/hid/winkey/hookables/Farcry.h"
2425
#include "xenia/hid/winkey/hookables/GearsOfWars.h"
2526
#include "xenia/hid/winkey/hookables/SaintsRow.h"
2627
#include "xenia/hid/winkey/hookables/SourceEngine.h"
@@ -451,6 +452,7 @@ WinKeyInputDriver::WinKeyInputDriver(xe::ui::Window* window,
451452
hookable_games_.push_back(std::move(std::make_unique<SourceEngine>()));
452453
hookable_games_.push_back(std::move(std::make_unique<Crackdown2Game>()));
453454
hookable_games_.push_back(std::move(std::make_unique<SaintsRowGame>()));
455+
hookable_games_.push_back(std::move(std::make_unique<FarCryGame>()));
454456
hookable_games_.push_back(std::move(std::make_unique<GearsOfWarsGame>()));
455457
hookable_games_.push_back(std::move(std::make_unique<DeadRisingGame>()));
456458
hookable_games_.push_back(std::move(std::make_unique<CallOfDutyGame>()));

0 commit comments

Comments
 (0)