diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroApi.cs b/BizHawk.Emulation.Cores/Libretro/LibretroApi.cs index 975d09deb7..5e81a13b93 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroApi.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroApi.cs @@ -150,6 +150,7 @@ namespace BizHawk.Emulation.Cores.Libretro { public retro_system_info retro_system_info; public retro_system_av_info retro_system_av_info; + public uint retro_serialize_size_initial; //size_t :( public uint retro_serialize_size; //size_t :( public uint retro_region; public uint retro_api_version; diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroApi_CMD.cs b/BizHawk.Emulation.Cores/Libretro/LibretroApi_CMD.cs index 076950a988..9bb5b6540c 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroApi_CMD.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroApi_CMD.cs @@ -58,6 +58,13 @@ namespace BizHawk.Emulation.Cores.Libretro return true; } + public uint CMD_UpdateSerializeSize() + { + Message(eMessage.CMD_UpdateSerializeSize); + WaitForCMD(); + return comm->env.retro_serialize_size; + } + public bool CMD_Serialize(byte[] data) { bool ret = false; diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroApi_Enums.cs b/BizHawk.Emulation.Cores/Libretro/LibretroApi_Enums.cs index ce44cadfe5..232189f0fd 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroApi_Enums.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroApi_Enums.cs @@ -24,6 +24,7 @@ namespace BizHawk.Emulation.Cores.Libretro CMD_Deinit, CMD_Reset, CMD_Run, + CMD_UpdateSerializeSize, CMD_Serialize, CMD_Unserialize, CMD_LAST, diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs index 8f821c13e8..068b6214da 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs @@ -374,6 +374,7 @@ namespace BizHawk.Emulation.Cores.Libretro public void SaveStateBinary(System.IO.BinaryWriter writer) { + api.CMD_UpdateSerializeSize(); if (savebuff == null || savebuff.Length != api.comm->env.retro_serialize_size) { savebuff = new byte[api.comm->env.retro_serialize_size]; @@ -404,6 +405,7 @@ namespace BizHawk.Emulation.Cores.Libretro public byte[] SaveStateBinary() { + api.CMD_UpdateSerializeSize(); if (savebuff == null || savebuff.Length != api.comm->env.retro_serialize_size) { savebuff = new byte[api.comm->env.retro_serialize_size]; diff --git a/LibretroBridge/vs2015/LibretroBridge.cpp b/LibretroBridge/vs2015/LibretroBridge.cpp index 09baef543e..addc698708 100644 --- a/LibretroBridge/vs2015/LibretroBridge.cpp +++ b/LibretroBridge/vs2015/LibretroBridge.cpp @@ -89,6 +89,7 @@ enum eMessage : s32 CMD_Deinit, CMD_Reset, CMD_Run, + CMD_UpdateSerializeSize, CMD_Serialize, CMD_Unserialize, CMD_LAST, @@ -140,6 +141,7 @@ struct CommStruct //set by the core retro_system_info retro_system_info; retro_system_av_info retro_system_av_info; + size_t retro_serialize_size_initial; size_t retro_serialize_size; u32 retro_region; u32 retro_api_version; @@ -694,7 +696,7 @@ static void LoadHandler(eMessage msg) //Between calls to retro_load_game() and retro_unload_game(), the returned size is never allowed to be larger than a previous returned //value, to ensure that the frontend can allocate a save state buffer once. - comm.env.retro_serialize_size = comm.funs.retro_serialize_size(); + comm.env.retro_serialize_size_initial = comm.env.retro_serialize_size = comm.funs.retro_serialize_size(); //not sure when this can be called, but it's surely safe here comm.env.retro_region = comm.funs.retro_get_region(); @@ -722,6 +724,11 @@ void cmd_Run() comm.funs.retro_run(); } +void cmd_UpdateSerializeSize() +{ + comm.env.retro_serialize_size = comm.funs.retro_serialize_size(); +} + void cmd_Serialize() { comm.value = !!comm.funs.retro_serialize(comm.buf[BufId::Param0], comm.buf_size[BufId::Param0]); @@ -765,6 +772,7 @@ const Action kHandlers_CMD[] = { cmd_Deinit, cmd_Reset, cmd_Run, + cmd_UpdateSerializeSize, cmd_Serialize, cmd_Unserialize, }; diff --git a/output/dll/LibretroBridge.dll b/output/dll/LibretroBridge.dll index c685e1f9a3..3e94b57a67 100644 Binary files a/output/dll/LibretroBridge.dll and b/output/dll/LibretroBridge.dll differ