cellGem: ignore missing pad handler

This is a hacky way to fix cellGem savestates
This commit is contained in:
Megamouse 2025-01-20 22:55:21 +01:00
parent 23483a80c7
commit 74540844d2
14 changed files with 56 additions and 55 deletions

View File

@ -329,7 +329,8 @@ public:
connected_controllers = 0;
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread(true);
if (!handler) break;
for (u32 i = 0; i < CELL_GEM_MAX_NUM; i++)
{
@ -398,7 +399,7 @@ public:
if (g_cfg.io.move == move_handler::real)
{
std::lock_guard pad_lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (pad && pad->m_pad_handler == pad_handler::move)
{
@ -428,7 +429,7 @@ public:
if (g_cfg.io.move == move_handler::real)
{
std::lock_guard pad_lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (pad && pad->m_pad_handler == pad_handler::move)
{
@ -458,7 +459,7 @@ public:
{
connected_controllers = 0;
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
for (u32 i = 0; i < std::min<u32>(attribute.max_connect, CELL_GEM_MAX_NUM); i++)
{
const auto& pad = ::at32(handler->GetPads(), pad_num(i));
@ -479,7 +480,7 @@ public:
{
connected_controllers = 0;
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
for (u32 i = 0; i < std::min<u32>(attribute.max_connect, CELL_GEM_MAX_NUM); i++)
{
const auto& pad = ::at32(handler->GetPads(), pad_num(i));
@ -1482,7 +1483,7 @@ public:
// Update PS Move LED colors
{
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
auto& handlers = handler->get_handlers();
if (auto it = handlers.find(pad_handler::move); it != handlers.end() && it->second)
{
@ -1744,7 +1745,7 @@ static void ds3_input_to_pad(const u32 gem_num, be_t<u16>& digital_buttons, be_t
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
@ -1837,7 +1838,7 @@ static void ds3_pos_to_gem_state(u32 gem_num, gem_config::gem_controller& contro
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
@ -1868,7 +1869,7 @@ static void ps_move_pos_to_gem_state(u32 gem_num, gem_config::gem_controller& co
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (pad->m_pad_handler != pad_handler::move || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
@ -1913,7 +1914,7 @@ static void ds3_input_to_ext(u32 gem_num, gem_config::gem_controller& controller
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
@ -2373,7 +2374,7 @@ error_code cellGemEnableMagnetometer(u32 gem_num, u32 enable)
{
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (pad && pad->m_pad_handler == pad_handler::move)
@ -2421,7 +2422,7 @@ error_code cellGemEnableMagnetometer2(u32 gem_num, u32 enable)
{
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (pad && pad->m_pad_handler == pad_handler::move)
@ -2746,7 +2747,7 @@ error_code cellGemGetInertialState(u32 gem_num, u32 state_flag, u64 timestamp, v
{
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (pad && (pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
@ -3333,7 +3334,7 @@ error_code cellGemReadExternalPortDeviceInfo(u32 gem_num, vm::ptr<u32> ext_id, v
{
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (pad->m_pad_handler != pad_handler::move || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
@ -3417,7 +3418,7 @@ error_code cellGemSetRumble(u32 gem_num, u8 rumble)
if (g_cfg.io.move == move_handler::real)
{
std::lock_guard pad_lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
auto& handlers = handler->get_handlers();
if (auto it = handlers.find(pad_handler::move); it != handlers.end() && it->second)
{
@ -3647,7 +3648,7 @@ error_code cellGemWriteExternalPort(u32 gem_num, vm::ptr<u8[CELL_GEM_EXTERNAL_PO
{
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (pad->m_pad_handler != pad_handler::move || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))

View File

@ -196,7 +196,7 @@ bool cellPad_NotifyStateChange(usz index, u64 /*state*/, bool locked, bool is_bl
return true;
}
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[index];
@ -268,7 +268,7 @@ error_code cellPadInit(ppu_thread& ppu, u32 max_connect)
config.port_setting.fill(CELL_PAD_SETTING_PRESS_OFF | CELL_PAD_SETTING_SENSOR_OFF);
config.reported_info = {};
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
for (usz i = 0; i < config.get_max_connect(); ++i)
@ -336,7 +336,7 @@ error_code cellPadClearBuf(u32 port_no)
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -351,7 +351,7 @@ error_code cellPadClearBuf(u32 port_no)
void pad_get_data(u32 port_no, CellPadData* data, bool get_periph_data = false)
{
auto& config = g_fxo->get<pad_info>();
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = handler->GetPads()[port_no];
const PadInfo& rinfo = handler->GetInfo();
@ -709,7 +709,7 @@ error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -740,7 +740,7 @@ error_code cellPadPeriphGetInfo(vm::ptr<CellPadPeriphInfo> info)
if (!info)
return CELL_PAD_ERROR_INVALID_PARAMETER;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const PadInfo& rinfo = handler->GetInfo();
std::memset(info.get_ptr(), 0, sizeof(CellPadPeriphInfo));
@ -795,7 +795,7 @@ error_code cellPadPeriphGetData(u32 port_no, vm::ptr<CellPadPeriphData> data)
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -827,7 +827,7 @@ error_code cellPadGetRawData(u32 port_no, vm::ptr<CellPadData> data)
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -891,7 +891,7 @@ error_code cellPadSetActDirect(u32 port_no, vm::ptr<CellPadActParam> param)
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -923,7 +923,7 @@ error_code cellPadGetInfo(vm::ptr<CellPadInfo> info)
std::memset(info.get_ptr(), 0, sizeof(CellPadInfo));
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const PadInfo& rinfo = handler->GetInfo();
info->max_connect = config.max_connect;
info->system_info = rinfo.system_info;
@ -968,7 +968,7 @@ error_code cellPadGetInfo2(vm::ptr<CellPadInfo2> info)
std::memset(info.get_ptr(), 0, sizeof(CellPadInfo2));
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const PadInfo& rinfo = handler->GetInfo();
info->max_connect = config.get_max_connect(); // Here it is forcibly clamped
info->system_info = rinfo.system_info;
@ -1018,7 +1018,7 @@ error_code cellPadGetCapabilityInfo(u32 port_no, vm::ptr<CellPadCapabilityInfo>
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -1074,7 +1074,7 @@ error_code cellPadInfoPressMode(u32 port_no)
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -1101,7 +1101,7 @@ error_code cellPadInfoSensorMode(u32 port_no)
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -1129,7 +1129,7 @@ error_code cellPadSetPressMode(u32 port_no, u32 mode)
if (port_no >= CELL_PAD_MAX_PORT_NUM)
return CELL_OK;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -1163,7 +1163,7 @@ error_code cellPadSetSensorMode(u32 port_no, u32 mode)
if (port_no >= CELL_PAD_MAX_PORT_NUM)
return CELL_OK;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
@ -1190,7 +1190,7 @@ error_code cellPadLddRegisterController()
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const s32 handle = handler->AddLddPad();
@ -1215,7 +1215,7 @@ error_code cellPadLddDataInsert(s32 handle, vm::ptr<CellPadData> data)
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
auto& pads = handler->GetPads();
if (handle < 0 || static_cast<u32>(handle) >= pads.size() || !data) // data == NULL stalls on decr
@ -1240,7 +1240,7 @@ error_code cellPadLddGetPortNo(s32 handle)
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
auto& pads = handler->GetPads();
if (handle < 0 || static_cast<u32>(handle) >= pads.size())
@ -1264,7 +1264,7 @@ error_code cellPadLddUnregisterController(s32 handle)
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
if (handle < 0 || static_cast<u32>(handle) >= pads.size())

View File

@ -146,7 +146,7 @@ void usb_device_buzz::interrupt_transfer(u32 buf_size, u8* buf, u32 /*endpoint*/
}
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
ensure(pads.size() > m_last_controller);
ensure(g_cfg_buzz.players.size() > m_last_controller);

View File

@ -138,7 +138,7 @@ void usb_device_ghltar::interrupt_transfer(u32 buf_size, u8* buf, u32 /*endpoint
}
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pad = ::at32(handler->GetPads(), m_controller_index);
if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))

View File

@ -195,7 +195,7 @@ void usb_device_gametablet::interrupt_transfer(u32 buf_size, u8* buf, u32 /*endp
{
std::lock_guard lock(pad::g_pad_mutex);
const auto gamepad_handler = pad::get_current_handler();
const auto gamepad_handler = pad::get_pad_thread();
const auto& pads = gamepad_handler->GetPads();
const auto& pad = ::at32(pads, m_controller_index);
if (pad->m_port_status & CELL_PAD_STATUS_CONNECTED)

View File

@ -255,7 +255,7 @@ void usb_device_guncon3::interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint,
{
std::lock_guard lock(pad::g_pad_mutex);
const auto gamepad_handler = pad::get_current_handler();
const auto gamepad_handler = pad::get_pad_thread();
const auto& pads = gamepad_handler->GetPads();
const auto& pad = ::at32(pads, m_controller_index);
if (pad->m_port_status & CELL_PAD_STATUS_CONNECTED)

View File

@ -315,7 +315,7 @@ void usb_device_topshotelite::interrupt_transfer(u32 buf_size, u8* buf, u32 /*en
{
std::lock_guard lock(pad::g_pad_mutex);
const auto gamepad_handler = pad::get_current_handler();
const auto gamepad_handler = pad::get_pad_thread();
const auto& pads = gamepad_handler->GetPads();
const auto& pad = ::at32(pads, m_controller_index);
if (pad->m_port_status & CELL_PAD_STATUS_CONNECTED)

View File

@ -339,7 +339,7 @@ void usb_device_topshotfearmaster::interrupt_transfer(u32 buf_size, u8* buf, u32
{
std::lock_guard lock(pad::g_pad_mutex);
const auto gamepad_handler = pad::get_current_handler();
const auto gamepad_handler = pad::get_pad_thread();
const auto& pads = gamepad_handler->GetPads();
const auto& pad = ::at32(pads, m_controller_index);
if (pad->m_port_status & CELL_PAD_STATUS_CONNECTED)

View File

@ -151,7 +151,7 @@ void usb_device_turntable::interrupt_transfer(u32 buf_size, u8* buf, u32 /*endpo
// All other bufs are always 0x00
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const auto& pads = handler->GetPads();
const auto& pad = ::at32(pads, m_controller_index);

View File

@ -189,7 +189,7 @@ void usb_device_usio::save_backup()
void usb_device_usio::translate_input_taiko()
{
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
std::vector<u8> input_buf(0x60);
constexpr le_t<u16> c_hit = 0x1800;
@ -273,7 +273,7 @@ void usb_device_usio::translate_input_taiko()
void usb_device_usio::translate_input_tekken()
{
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
std::vector<u8> input_buf(0x180);
le_t<u64> digital_input[2]{};

View File

@ -193,7 +193,7 @@ namespace rsx
// Get gamepad input
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto handler = pad::get_pad_thread();
const PadInfo& rinfo = handler->GetInfo();
const bool ignore_gamepad_input = (!rinfo.now_connect || !input::g_pads_intercepted);

View File

@ -37,7 +37,7 @@ extern std::string g_input_config_override;
namespace pad
{
atomic_t<pad_thread*> g_current = nullptr;
atomic_t<pad_thread*> g_pad_thread = nullptr;
shared_mutex g_pad_mutex;
std::string g_title_id;
atomic_t<bool> g_started{false};
@ -62,13 +62,13 @@ struct pad_setting
pad_thread::pad_thread(void* curthread, void* curwindow, std::string_view title_id) : m_curthread(curthread), m_curwindow(curwindow)
{
pad::g_title_id = title_id;
pad::g_current = this;
pad::g_pad_thread = this;
pad::g_started = false;
}
pad_thread::~pad_thread()
{
pad::g_current = nullptr;
pad::g_pad_thread = nullptr;
}
void pad_thread::Init()

View File

@ -70,7 +70,7 @@ private:
namespace pad
{
extern atomic_t<pad_thread*> g_current;
extern atomic_t<pad_thread*> g_pad_thread;
extern shared_mutex g_pad_mutex;
extern std::string g_title_id;
extern atomic_t<bool> g_enabled;
@ -78,14 +78,14 @@ namespace pad
extern atomic_t<bool> g_started;
extern atomic_t<bool> g_home_menu_requested;
static inline class pad_thread* get_current_handler(bool relaxed = false)
static inline class pad_thread* get_pad_thread(bool relaxed = false)
{
if (relaxed)
{
return g_current.observe();
return g_pad_thread.observe();
}
return ensure(g_current.load());
return ensure(g_pad_thread.load());
}
static inline void set_enabled(bool enabled)
@ -102,7 +102,7 @@ namespace pad
static inline void SetIntercepted(bool intercepted)
{
std::lock_guard lock(g_pad_mutex);
const auto handler = get_current_handler();
const auto handler = get_pad_thread();
handler->SetIntercepted(intercepted);
}
}

View File

@ -2017,7 +2017,7 @@ bool pad_settings_dialog::GetIsLddPad(u32 index) const
if (!Emu.IsStopped() && (m_title_id.empty() || m_title_id == Emu.GetTitleID()))
{
std::lock_guard lock(pad::g_pad_mutex);
if (const auto handler = pad::get_current_handler(true))
if (const auto handler = pad::get_pad_thread(true))
{
ensure(index < handler->GetPads().size());