mirror of https://github.com/PCSX2/pcsx2.git
onepad: support load/save state for the plugin
close #205 close #1375 close #1465 v2: don't bump PCSX2 savestate version
This commit is contained in:
parent
62aff1f2a1
commit
48c4d54a6c
|
@ -49,6 +49,7 @@ bool toggleAutoRepeat = false;
|
|||
const u32 version = PS2E_PAD_VERSION;
|
||||
const u32 revision = 1;
|
||||
const u32 build = 3; // increase that with each version
|
||||
#define PAD_SAVE_STATE_VERSION ((revision << 8) | (build << 0))
|
||||
|
||||
FILE *padLog = NULL;
|
||||
|
||||
|
@ -242,6 +243,73 @@ EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot)
|
|||
return 1;
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) PADfreeze(int mode, freezeData *data)
|
||||
{
|
||||
if (!data)
|
||||
return -1;
|
||||
|
||||
if (mode == FREEZE_SIZE) {
|
||||
data->size = sizeof(PadPluginFreezeData);
|
||||
|
||||
} else if (mode == FREEZE_LOAD) {
|
||||
PadPluginFreezeData* pdata = (PadPluginFreezeData*)(data->data);
|
||||
|
||||
Pad::stop_vibrate_all();
|
||||
|
||||
if (data->size != sizeof(PadPluginFreezeData) || pdata->version != PAD_SAVE_STATE_VERSION ||
|
||||
strncmp(pdata->format, "OnePad", sizeof(pdata->format)))
|
||||
return 0;
|
||||
|
||||
query = pdata->query;
|
||||
if (pdata->query.slot < 4) {
|
||||
query = pdata->query;
|
||||
}
|
||||
|
||||
// Tales of the Abyss - pad fix
|
||||
// - restore data for both ports
|
||||
for (int port=0; port<2; port++) {
|
||||
for (int slot=0; slot<4; slot++) {
|
||||
u8 mode = pdata->padData[port][slot].mode;
|
||||
|
||||
if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE) {
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(&pads[port][slot], &pdata->padData[port][slot], sizeof(PadFreezeData));
|
||||
}
|
||||
|
||||
if (pdata->slot[port] < 4)
|
||||
slots[port] = pdata->slot[port];
|
||||
}
|
||||
|
||||
} else if (mode == FREEZE_SAVE) {
|
||||
if (data->size != sizeof(PadPluginFreezeData)) return 0;
|
||||
|
||||
PadPluginFreezeData* pdata = (PadPluginFreezeData*)(data->data);
|
||||
|
||||
// Tales of the Abyss - pad fix
|
||||
// - PCSX2 only saves port0 (save #1), then port1 (save #2)
|
||||
|
||||
memset(pdata, 0, data->size);
|
||||
strncpy(pdata->format, "OnePad", sizeof(pdata->format));
|
||||
pdata->version = PAD_SAVE_STATE_VERSION;
|
||||
pdata->query = query;
|
||||
|
||||
for (int port=0; port<2; port++) {
|
||||
for (int slot=0; slot<4; slot++) {
|
||||
pdata->padData[port][slot] = pads[port][slot];
|
||||
}
|
||||
|
||||
pdata->slot[port] = slots[port];
|
||||
}
|
||||
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_C_(u8) PADstartPoll(int pad)
|
||||
{
|
||||
return pad_start_poll(pad);
|
||||
|
|
Loading…
Reference in New Issue