Player Index / Handle Each Controller

This commit is contained in:
SirMangler 2021-04-08 22:44:39 +01:00
parent 35cf0def0b
commit dc832a5c85
8 changed files with 170 additions and 166 deletions

View File

@ -212,50 +212,50 @@ void ChangeUIPrimeHack(int number, bool useMetroidUI)
wiimote->GetNunchuk()->ChangeUIPrimeHack(useMetroidUI); wiimote->GetNunchuk()->ChangeUIPrimeHack(useMetroidUI);
} }
bool CheckVisor(int visorcount) bool CheckVisor(int visorcount, int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->CheckVisorCtrl(visorcount); return wiimote->CheckVisorCtrl(visorcount);
} }
bool CheckBeam(int beamcount) bool CheckBeam(int beamcount, int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->CheckBeamCtrl(beamcount); return wiimote->CheckBeamCtrl(beamcount);
} }
bool CheckForward() { bool CheckForward(int player_index) {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->GetNunchukGroup(WiimoteEmu::NunchukGroup::Stick)-> return wiimote->GetNunchukGroup(WiimoteEmu::NunchukGroup::Stick)->
controls[0].get()->control_ref->State() > 0.5; controls[0].get()->control_ref->State() > 0.5;
} }
bool CheckBack() { bool CheckBack(int player_index) {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->GetNunchukGroup(WiimoteEmu::NunchukGroup::Stick)-> return wiimote->GetNunchukGroup(WiimoteEmu::NunchukGroup::Stick)->
controls[1].get()->control_ref->State() > 0.5; controls[1].get()->control_ref->State() > 0.5;
} }
bool CheckLeft() { bool CheckLeft(int player_index) {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->GetNunchukGroup(WiimoteEmu::NunchukGroup::Stick)-> return wiimote->GetNunchukGroup(WiimoteEmu::NunchukGroup::Stick)->
controls[2].get()->control_ref->State() > 0.5; controls[2].get()->control_ref->State() > 0.5;
} }
bool CheckRight() { bool CheckRight(int player_index) {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->GetNunchukGroup(WiimoteEmu::NunchukGroup::Stick)-> return wiimote->GetNunchukGroup(WiimoteEmu::NunchukGroup::Stick)->
controls[3].get()->control_ref->State() > 0.5; controls[3].get()->control_ref->State() > 0.5;
} }
bool CheckJump() { bool CheckJump(int player_index) {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->groups[0].get()->controls[1]->control_ref->State() > 0.5; return wiimote->groups[0].get()->controls[1]->control_ref->State() > 0.5;
} }
@ -278,16 +278,16 @@ bool GrappleCtlBound() {
return wiimote->IsGrappleBinded(); return wiimote->IsGrappleBinded();
} }
bool CheckSpringBall() bool CheckSpringBall(int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->CheckSpringBallCtrl(); return wiimote->CheckSpringBallCtrl();
} }
std::tuple<bool, bool> GetBVMenuOptions() std::tuple<bool, bool> GetBVMenuOptions(int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->GetBVMenuOptions(); return wiimote->GetBVMenuOptions();
} }
@ -299,44 +299,44 @@ bool CheckImprovedMotions()
return wiimote->CheckImprovedMotions(); return wiimote->CheckImprovedMotions();
} }
bool CheckVisorScroll(bool direction) bool CheckVisorScroll(bool direction, int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0));
return wiimote->CheckVisorScrollCtrl(direction); return wiimote->CheckVisorScrollCtrl(direction);
} }
bool CheckBeamScroll(bool direction) bool CheckBeamScroll(bool direction, int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0));
return wiimote->CheckBeamScrollCtrl(direction); return wiimote->CheckBeamScrollCtrl(direction);
} }
bool PrimeUseController() bool PrimeUseController(int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->PrimeControllerMode(); return wiimote->PrimeControllerMode();
} }
std::tuple<double, double> GetPrimeStickXY() std::tuple<double, double> GetPrimeStickXY(int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->GetPrimeStickXY(); return wiimote->GetPrimeStickXY();
} }
std::tuple<double, double, bool, bool, bool, bool> PrimeSettings() std::tuple<double, double, bool, bool, bool, bool> PrimeSettings(int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->GetPrimeSettings(); return wiimote->GetPrimeSettings();
} }
bool CheckPitchRecentre() bool CheckPitchRecentre(int player_index)
{ {
WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(0)); WiimoteEmu::Wiimote* wiimote = static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(player_index));
return wiimote->CheckPitchRecentre(); return wiimote->CheckPitchRecentre();
} }

View File

@ -102,30 +102,29 @@ ControllerEmu::ControlGroup* GetTaTaConGroup(int number, WiimoteEmu::TaTaConGrou
void ChangeUIPrimeHack(int number, bool useMetroidUI); void ChangeUIPrimeHack(int number, bool useMetroidUI);
bool CheckVisor(int visor_count); bool CheckVisor(int visor_count, int player_index = 0);
bool CheckBeam(int beam_count); bool CheckBeam(int beam_count, int player_index = 0);
bool CheckBeamScroll(bool direction); bool CheckBeamScroll(bool direction, int player_index = 0);
bool CheckVisorScroll(bool direction); bool CheckVisorScroll(bool direction, int player_index = 0);
bool CheckSpringBall(); bool CheckSpringBall(int player_index = 0);
bool CheckImprovedMotions(); bool CheckImprovedMotions();
bool CheckForward(); bool CheckForward(int player_index = 0);
bool CheckBack(); bool CheckBack(int player_index = 0);
bool CheckLeft(); bool CheckLeft(int player_index = 0);
bool CheckRight(); bool CheckRight(int player_index = 0);
bool CheckJump(); bool CheckJump(int player_index = 0);
bool CheckGrapple(); bool CheckGrapple();
bool UseGrappleTapping(); bool UseGrappleTapping();
bool GrappleCtlBound(); bool GrappleCtlBound();
bool PrimeUseController(); bool PrimeUseController(int player_index = 0);
bool PrimeUseController(); bool CheckPitchRecentre(int player_index = 0);
bool CheckPitchRecentre();
std::tuple<double, double> GetPrimeStickXY(); std::tuple<double, double> GetPrimeStickXY(int player_index = 0);
std::tuple<bool, bool> GetBVMenuOptions(); std::tuple<bool, bool> GetBVMenuOptions(int player_index = 0);
std::tuple<double, double, bool, bool, bool, bool> PrimeSettings(); std::tuple<double, double, bool, bool, bool, bool> PrimeSettings(int player_index = 0);
bool NetPlay_GetButtonPress(int wiimote, bool pressed); bool NetPlay_GetButtonPress(int wiimote, bool pressed);

View File

@ -31,24 +31,26 @@
#include "Core/Config/GraphicsSettings.h" #include "Core/Config/GraphicsSettings.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/InputConfig.h"
#include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoConfig.h"
#include "Core\HW\GCPadEmu.h"
namespace prime { namespace prime {
namespace { namespace {
float sensitivity; std::array<float, 4> sensitivity;
float cursor_sensitivity; std::array<float, 4> cursor_sensitivity;
float camera_fov; std::array<float, 4> camera_fov;
bool inverted_x = false; std::array<bool, 4> inverted_x = {false, false, false, false};
bool inverted_y = false; std::array<bool, 4> inverted_y = {false, false, false, false};
bool scale_cursor_sens = false; std::array<bool, 4> scale_cursor_sens = {false, false, false, false};
HackManager hack_mgr; HackManager hack_mgr;
AddressDB addr_db; AddressDB addr_db;
EmuVariableManager var_mgr; EmuVariableManager var_mgr;
bool is_running = false; bool is_running = false;
CameraLock lock_camera = CameraLock::Unlocked; CameraLock lock_camera = CameraLock::Unlocked;
bool reticle_lock = false; std::array<bool, 4> reticle_lock = {false, false, false, false};
std::string pending_modfile = ""; std::string pending_modfile = "";
bool mod_suspended = false; bool mod_suspended = false;
@ -91,47 +93,47 @@ void InitializeHack() {
hack_mgr.enable_mod("elf_mod_loader"); hack_mgr.enable_mod("elf_mod_loader");
} }
bool CheckBeamCtl(int beam_num) { bool CheckBeamCtl(int beam_num, int player_index) {
return Wiimote::CheckBeam(beam_num); return Wiimote::CheckBeam(beam_num);
} }
bool CheckVisorCtl(int visor_num) { bool CheckVisorCtl(int visor_num, int player_index) {
return Wiimote::CheckVisor(visor_num); return Wiimote::CheckVisor(visor_num);
} }
bool CheckVisorScrollCtl(bool direction) { bool CheckVisorScrollCtl(bool direction, int player_index) {
return Wiimote::CheckVisorScroll(direction); return Wiimote::CheckVisorScroll(direction);
} }
bool CheckBeamScrollCtl(bool direction) { bool CheckBeamScrollCtl(bool direction, int player_index) {
return Wiimote::CheckBeamScroll(direction); return Wiimote::CheckBeamScroll(direction);
} }
bool CheckSpringBallCtl() { bool CheckSpringBallCtl(int player_index) {
return Wiimote::CheckSpringBall(); return Wiimote::CheckSpringBall(player_index);
} }
bool ImprovedMotionControls() { bool ImprovedMotionControls() {
return Wiimote::CheckImprovedMotions(); return Wiimote::CheckImprovedMotions();
} }
bool CheckForward() { bool CheckForward(int player_index) {
return Wiimote::CheckForward(); return Wiimote::CheckForward();
} }
bool CheckBack() { bool CheckBack(int player_index) {
return Wiimote::CheckBack(); return Wiimote::CheckBack();
} }
bool CheckLeft() { bool CheckLeft(int player_index) {
return Wiimote::CheckLeft(); return Wiimote::CheckLeft();
} }
bool CheckRight() { bool CheckRight(int player_index) {
return Wiimote::CheckRight(); return Wiimote::CheckRight();
} }
bool CheckJump() { bool CheckJump(int player_index) {
return Wiimote::CheckJump(); return Wiimote::CheckJump();
} }
@ -211,113 +213,114 @@ std::tuple<float, float, float> GetArmXYZ() {
return std::make_tuple(x, y, z); return std::make_tuple(x, y, z);
} }
void UpdateHackSettings() { void UpdateHackSettings(int player_index) {
double camera, cursor; double camera, cursor;
bool invertx, inverty, scale_sens = false, lock = false; bool invertx, inverty, scale_sens = false, lock = false;
if (hack_mgr.get_active_game() >= Game::PRIME_1_GCN) if (hack_mgr.get_active_game() >= Game::PRIME_1_GCN) {
std::tie<double, double, bool, bool>(camera, cursor, invertx, inverty) = std::tie(camera, cursor, invertx, inverty) =
Pad::PrimeSettings(); static_cast<GCPad*>(Pad::GetConfig()->GetController(player_index))->GetPrimeSettings();
else } else {
std::tie<double, double, bool, bool, bool>(camera, cursor, invertx, inverty, scale_sens, lock) = std::tie(camera, cursor, invertx, inverty, scale_sens, lock) =
Wiimote::PrimeSettings(); static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(player_index))->GetPrimeSettings();
}
SetSensitivity((float)camera); SetSensitivity((float)camera, player_index);
SetCursorSensitivity((float)cursor); SetCursorSensitivity((float)cursor, player_index);
SetInvertedX(invertx); SetInvertedX(invertx, player_index);
SetInvertedY(inverty); SetInvertedY(inverty, player_index);
SetScaleCursorSensitivity(scale_sens); SetScaleCursorSensitivity(scale_sens, player_index);
SetReticleLock(lock); SetReticleLock(lock, player_index);
} }
float GetSensitivity() { float GetSensitivity(int player_index) {
return sensitivity; return sensitivity[player_index];
} }
void SetSensitivity(float sens) { void SetSensitivity(float sens, int player_index) {
sensitivity = sens; sensitivity[player_index] = sens;
} }
bool HandleReticleLockOn() bool HandleReticleLockOn(int player_index)
{ {
return reticle_lock; return reticle_lock[player_index];
} }
void SetReticleLock(bool lock) void SetReticleLock(bool lock, int player_index)
{ {
reticle_lock = lock; reticle_lock[player_index] = lock;
} }
float GetCursorSensitivity() { float GetCursorSensitivity(int player_index) {
return cursor_sensitivity; return cursor_sensitivity[player_index];
} }
void SetCursorSensitivity(float sens) { void SetCursorSensitivity(float sens, int player_index) {
cursor_sensitivity = sens; cursor_sensitivity[player_index] = sens;
} }
float GetFov() { float GetFov() {
return Config::Get(Config::FOV); return Config::Get(Config::FOV);
} }
bool InvertedY() { bool InvertedY(int player_index) {
return inverted_y; return inverted_y[player_index];
} }
void SetInvertedY(bool inverted) { void SetInvertedY(bool inverted, int player_index) {
inverted_y = inverted; inverted_y[player_index] = inverted;
} }
bool InvertedX() { bool InvertedX(int player_index) {
return inverted_x; return inverted_x[player_index];
} }
void SetInvertedX(bool inverted) { void SetInvertedX(bool inverted, int player_index) {
inverted_x = inverted; inverted_x[player_index] = inverted;
} }
bool ScaleCursorSensitivity() { bool ScaleCursorSensitivity(int player_index) {
return scale_cursor_sens; return scale_cursor_sens[player_index];
} }
void SetScaleCursorSensitivity(bool scale) { void SetScaleCursorSensitivity(bool scale, int player_index) {
scale_cursor_sens = scale; scale_cursor_sens[player_index] = scale;
} }
bool CheckPitchRecentre() { bool CheckPitchRecentre(int player_index) {
if (hack_mgr.get_active_game() >= Game::PRIME_1_GCN) { if (hack_mgr.get_active_game() >= Game::PRIME_1_GCN) {
if (Pad::PrimeUseController()) { if (Pad::PrimeUseController()) {
return Pad::CheckPitchRecentre(); return Pad::CheckPitchRecentre();
} }
} }
else if (Wiimote::PrimeUseController()) { else if (Wiimote::PrimeUseController()) {
return Wiimote::CheckPitchRecentre(); return Wiimote::CheckPitchRecentre(player_index);
} }
return false; return false;
} }
double GetHorizontalAxis() { double GetHorizontalAxis(int player_index) {
if (hack_mgr.get_active_game() >= Game::PRIME_1_GCN) { if (hack_mgr.get_active_game() >= Game::PRIME_1_GCN) {
if (Pad::PrimeUseController()) { if (Pad::PrimeUseController()) {
return std::get<0>(Pad::GetPrimeStickXY()); return std::get<0>(Pad::GetPrimeStickXY());
} }
} }
else if (Wiimote::PrimeUseController()) { else if (Wiimote::PrimeUseController()) {
return std::get<0>(Wiimote::GetPrimeStickXY()); return std::get<0>(Wiimote::GetPrimeStickXY(player_index));
} }
return static_cast<double>(g_mouse_input->GetDeltaHorizontalAxis()); return static_cast<double>(g_mouse_input->GetDeltaHorizontalAxis());
} }
double GetVerticalAxis() { double GetVerticalAxis(int player_index) {
if (hack_mgr.get_active_game() >= Game::PRIME_1_GCN) { if (hack_mgr.get_active_game() >= Game::PRIME_1_GCN) {
if (Pad::PrimeUseController()) { if (Pad::PrimeUseController()) {
return std::get<1>(Pad::GetPrimeStickXY()); return std::get<1>(Pad::GetPrimeStickXY());
} }
} }
else if (Wiimote::PrimeUseController()) { else if (Wiimote::PrimeUseController()) {
return std::get<1>(Wiimote::GetPrimeStickXY()); return std::get<1>(Wiimote::GetPrimeStickXY(player_index));
} }
return static_cast<double>(g_mouse_input->GetDeltaVerticalAxis()); return static_cast<double>(g_mouse_input->GetDeltaVerticalAxis());

View File

@ -13,17 +13,17 @@
namespace prime { namespace prime {
void InitializeHack(); void InitializeHack();
bool CheckBeamCtl(int beam_num); bool CheckBeamCtl(int beam_num, int player_index = 0);
bool CheckVisorCtl(int visor_num); bool CheckVisorCtl(int visor_num, int player_index = 0);
bool CheckBeamScrollCtl(bool direction); bool CheckBeamScrollCtl(bool direction, int player_index = 0);
bool CheckVisorScrollCtl(bool direction); bool CheckVisorScrollCtl(bool direction, int player_index = 0);
bool CheckSpringBallCtl(); bool CheckSpringBallCtl(int player_index = 0);
bool ImprovedMotionControls(); bool ImprovedMotionControls();
bool CheckForward(); bool CheckForward(int player_index = 0);
bool CheckBack(); bool CheckBack(int player_index = 0);
bool CheckLeft(); bool CheckLeft(int player_index = 0);
bool CheckRight(); bool CheckRight(int player_index = 0);
bool CheckJump(); bool CheckJump(int player_index = 0);
bool CheckGrappleCtl(); bool CheckGrappleCtl();
bool GrappleTappingMode(); bool GrappleTappingMode();
@ -48,33 +48,33 @@ bool GetAutoArmAdjust();
bool GetToggleArmAdjust(); bool GetToggleArmAdjust();
std::tuple<float, float, float> GetArmXYZ(); std::tuple<float, float, float> GetArmXYZ();
void UpdateHackSettings(); void UpdateHackSettings(int player_index = 0);
float GetSensitivity(); float GetSensitivity(int player_index = 0);
void SetSensitivity(float sensitivity); void SetSensitivity(float sensitivity, int player_index = 0);
float GetCursorSensitivity(); float GetCursorSensitivity(int player_index = 0);
void SetCursorSensitivity(float sensitivity); void SetCursorSensitivity(float sensitivity, int player_index = 0);
bool ScaleCursorSensitivity(); bool ScaleCursorSensitivity(int player_index = 0);
void SetScaleCursorSensitivity(bool scale); void SetScaleCursorSensitivity(bool scale, int player_index = 0);
float GetFov(); float GetFov();
bool InvertedY(); bool InvertedY(int player_index = 0);
void SetInvertedY(bool inverted); void SetInvertedY(bool inverted, int player_index = 0);
bool InvertedX(); bool InvertedX(int player_index = 0);
void SetInvertedX(bool inverted); void SetInvertedX(bool inverted, int player_index = 0);
bool GetCulling(); bool GetCulling();
bool HandleReticleLockOn(); bool HandleReticleLockOn(int player_index = 0);
void SetReticleLock(bool lock); void SetReticleLock(bool lock, int player_index = 0);
enum CameraLock { Centre, Angle45, Unlocked }; enum CameraLock { Centre, Angle45, Unlocked };
void SetLockCamera(CameraLock lock); void SetLockCamera(CameraLock lock);
CameraLock GetLockCamera(); CameraLock GetLockCamera();
bool CheckPitchRecentre(); bool CheckPitchRecentre(int player_index = 0);
double GetHorizontalAxis(); double GetHorizontalAxis(int player_index = 0);
double GetVerticalAxis(); double GetVerticalAxis(int player_index = 0);
std::tuple<bool, bool> GetMenuOptions(); std::tuple<bool, bool> GetMenuOptions();

View File

@ -169,7 +169,7 @@ float FpsControls::calculate_yaw_vel() {
} }
void FpsControls::handle_beam_visor_switch(std::array<int, 4> const &beams, void FpsControls::handle_beam_visor_switch(std::array<int, 4> const &beams,
std::array<std::tuple<int, int>, 4> const &visors) { std::array<std::tuple<int, int>, 4> const &visors, int player_index) {
// Global array of all powerups (measured in "ammunition" // Global array of all powerups (measured in "ammunition"
// even for things like visors/beams) // even for things like visors/beams)
LOOKUP_DYN(powerups_array); LOOKUP_DYN(powerups_array);
@ -192,7 +192,7 @@ void FpsControls::handle_beam_visor_switch(std::array<int, 4> const &beams,
} }
if (has_beams) { if (has_beams) {
const int beam_id = get_beam_switch(beams); const int beam_id = get_beam_switch(beams, player_index);
if (beam_id != -1) { if (beam_id != -1) {
prime::GetVariableManager()->set_variable("new_beam", static_cast<u32>(beam_id)); prime::GetVariableManager()->set_variable("new_beam", static_cast<u32>(beam_id));
prime::GetVariableManager()->set_variable("beamchange_flag", u32{1}); prime::GetVariableManager()->set_variable("beamchange_flag", u32{1});
@ -202,7 +202,7 @@ void FpsControls::handle_beam_visor_switch(std::array<int, 4> const &beams,
LOOKUP_DYN(active_visor); LOOKUP_DYN(active_visor);
int visor_id, visor_off; int visor_id, visor_off;
std::tie(visor_id, visor_off) = get_visor_switch(visors, std::tie(visor_id, visor_off) = get_visor_switch(visors,
read32(active_visor) == 0); read32(active_visor) == 0, player_index);
if (visor_id != -1) { if (visor_id != -1) {
if (read32(powerups_array + (visor_off * powerups_size) + powerups_offset)) { if (read32(powerups_array + (visor_off * powerups_size) + powerups_offset)) {
@ -367,6 +367,8 @@ void FpsControls::run_mod_mp2(Region region) {
// VERY similar to mp1, this time CPlayer isn't TOneStatic (presumably because // VERY similar to mp1, this time CPlayer isn't TOneStatic (presumably because
// of multiplayer mode in the GCN version?) // of multiplayer mode in the GCN version?)
int player_index = 0;
LOOKUP_DYN(player); LOOKUP_DYN(player);
if (player == 0) { if (player == 0) {
return; return;
@ -378,7 +380,7 @@ void FpsControls::run_mod_mp2(Region region) {
return; return;
} }
handle_beam_visor_switch(prime_two_beams, prime_two_visors); handle_beam_visor_switch(prime_two_beams, prime_two_visors, player_index);
// Is beam/visor menu showing on screen // Is beam/visor menu showing on screen
LOOKUP_DYN(beamvisor_menu_state); LOOKUP_DYN(beamvisor_menu_state);

View File

@ -28,7 +28,7 @@ private:
void calculate_pitch_to_target(float target_pitch); void calculate_pitch_to_target(float target_pitch);
float calculate_yaw_vel(); float calculate_yaw_vel();
void handle_beam_visor_switch(std::array<int, 4> const &beams, void handle_beam_visor_switch(std::array<int, 4> const &beams,
std::array<std::tuple<int, int>, 4> const& visors); std::array<std::tuple<int, int>, 4> const& visors, int player_index = 0);
void mp3_handle_lasso(u32 grapple_state_addr); void mp3_handle_lasso(u32 grapple_state_addr);
void run_mod_menu(Game game, Region region); void run_mod_menu(Game game, Region region);

View File

@ -25,8 +25,8 @@ namespace prime
*/ */
static float cursor_x = 0, cursor_y = 0; static float cursor_x = 0, cursor_y = 0;
static int current_beam = 0; static std::array<int, 4> current_beam = {0, 0, 0, 0};
static int current_visor = 0; static std::array<int, 4> current_visor = {0, 0, 0, 0};
static std::array<bool, 4> beam_owned = {false, false, false, false}; static std::array<bool, 4> beam_owned = {false, false, false, false};
static std::array<bool, 4> visor_owned = {false, false, false, false}; static std::array<bool, 4> visor_owned = {false, false, false, false};
static bool noclip_enabled = false; static bool noclip_enabled = false;
@ -103,9 +103,9 @@ void write_invalidate(u32 address, u32 value) {
PowerPC::ScheduleInvalidateCacheThreadSafe(address); PowerPC::ScheduleInvalidateCacheThreadSafe(address);
} }
std::tuple<int, int> get_visor_switch(std::array<std::tuple<int, int>, 4> const& visors, bool combat_visor) { std::tuple<int, int> get_visor_switch(std::array<std::tuple<int, int>, 4> const& visors, bool combat_visor, int player_index) {
static bool pressing_button = false; static bool pressing_button = false;
if (CheckVisorCtl(0)) { if (CheckVisorCtl(0, player_index)) {
if (!combat_visor) { if (!combat_visor) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
@ -116,40 +116,40 @@ std::tuple<int, int> get_visor_switch(std::array<std::tuple<int, int>, 4> const&
} }
} }
} }
if (CheckVisorCtl(1)) { if (CheckVisorCtl(1, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
return visors[1]; return visors[1];
} }
} }
else if (CheckVisorCtl(2)) { else if (CheckVisorCtl(2, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
return visors[2]; return visors[2];
} }
} }
else if (CheckVisorCtl(3)) { else if (CheckVisorCtl(3, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
return visors[3]; return visors[3];
} }
} }
else if (CheckVisorScrollCtl(true)) { else if (CheckVisorScrollCtl(true, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (visor_owned[current_visor = (current_visor + 1) % 4]) break; if (visor_owned[current_visor[player_index] = (current_visor[player_index] + 1) % 4]) break;
} }
return visors[current_visor]; return visors[current_visor[player_index]];
} }
} }
else if (CheckVisorScrollCtl(false)) { else if (CheckVisorScrollCtl(false, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (visor_owned[current_visor = (current_visor + 3) % 4]) break; if (visor_owned[current_visor[player_index] = (current_visor[player_index] + 3) % 4]) break;
} }
return visors[current_visor]; return visors[current_visor[player_index]];
} }
} }
else { else {
@ -158,48 +158,48 @@ std::tuple<int, int> get_visor_switch(std::array<std::tuple<int, int>, 4> const&
return std::make_tuple(-1, 0); return std::make_tuple(-1, 0);
} }
int get_beam_switch(std::array<int, 4> const& beams) { int get_beam_switch(std::array<int, 4> const& beams, int player_index) {
static bool pressing_button = false; static bool pressing_button = false;
if (CheckBeamCtl(0)) { if (CheckBeamCtl(0, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
return current_beam = beams[0]; return current_beam[player_index] = beams[0];
} }
} }
else if (CheckBeamCtl(1)) { else if (CheckBeamCtl(1, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
return current_beam = beams[1]; return current_beam[player_index] = beams[1];
} }
} }
else if (CheckBeamCtl(2)) { else if (CheckBeamCtl(2, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
return current_beam = beams[2]; return current_beam[player_index] = beams[2];
} }
} }
else if (CheckBeamCtl(3)) { else if (CheckBeamCtl(3, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
return current_beam = beams[3]; return current_beam[player_index] = beams[3];
} }
} }
else if (CheckBeamScrollCtl(true)) { else if (CheckBeamScrollCtl(true, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (beam_owned[current_beam = (current_beam + 1) % 4]) break; if (beam_owned[current_beam[player_index] = (current_beam[player_index] + 1) % 4]) break;
} }
return beams[current_beam]; return beams[current_beam[player_index]];
} }
} }
else if (CheckBeamScrollCtl(false)) { else if (CheckBeamScrollCtl(false, player_index)) {
if (!pressing_button) { if (!pressing_button) {
pressing_button = true; pressing_button = true;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (beam_owned[current_beam = (current_beam + 3) % 4]) break; if (beam_owned[current_beam[player_index] = (current_beam[player_index] + 3) % 4]) break;
} }
return beams[current_beam]; return beams[current_beam[player_index]];
} }
} }
else { else {

View File

@ -49,8 +49,8 @@ constexpr u32 gen_vmcall(const u32 call_idx, const u32 param) {
constexpr float kTurnrateRatio = 0.00498665500569808449206349206349f; constexpr float kTurnrateRatio = 0.00498665500569808449206349206349f;
int get_beam_switch(std::array<int, 4> const& beams); int get_beam_switch(std::array<int, 4> const& beams, int player_index = 0);
std::tuple<int, int> get_visor_switch(std::array<std::tuple<int, int>, 4> const& visors, bool combat_visor); std::tuple<int, int> get_visor_switch(std::array<std::tuple<int, int>, 4> const& visors, bool combat_visor, int player_index = 0);
void handle_cursor(u32 x_address, u32 y_address, Region region); void handle_cursor(u32 x_address, u32 y_address, Region region);
void handle_reticle(u32 x_address, u32 y_address, Region region, float fov); void handle_reticle(u32 x_address, u32 y_address, Region region, float fov);