Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. bool retro_serialize(void *data, size_t size)
  2. {
  3. /* it seems that mednafen can realloc pointers sent to it?
  4. since we don't know the disposition of void* data (is it safe to realloc?) we have to manage a new buffer here */
  5. StateMem st;
  6. memset(&st, 0, sizeof(st));
  7. st.data = (uint8_t*)malloc(size);
  8. st.malloced = size;
  9.  
  10. bool ret = MDFNSS_SaveSM(&st, 0, 0, NULL, NULL, NULL);
  11.  
  12. /* there are still some errors with the save states, the size seems to change on some games for now just log when this happens */
  13. if (st.len != size)
  14. log_cb(RETRO_LOG_WARN, "warning, save state size has changed\n");
  15.  
  16. if( st.len > size) {
  17. log_cb(RETRO_LOG_ERROR, "ERROR: save state size inflated. This is forbidden. Can't serialize.\n");
  18. return false;
  19. }
  20.  
  21. memcpy(data,st.data,size);
  22. free(st.data);
  23. return ret;
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement