Fixing Save Game error BufferOverflow [B42.13]

Project Zomboid278 views11 favorites1 min readby MaDKoTUpdated 7 FebView on Steam ↗

The Core of the Problem

The issue is a buffer overflow (BufferOverflowException) when saving character data. The error occurs in the WriteStringUTF method when trying to write a string to a ByteBuffer that has a limited size.

When a character's inventory contains too many items (especially items with a lot of metadata, like literature), many learned recipes, read journals and books, the total size of the data to be saved exceeds the allocated 64KB buffer. For games with mods that add many crafting recipes, this is very limited.

Solution

Increasing the buffer size to fix character save errors on the server:

  1. Go to the game folder and open projectzomboid.jar using WinRAR (or any archiver).
    *for a dedicated server, the path is Project Zomboid Dedicated Server\java\projectzomboid.jar
  2. Look for the file ServerPlayerDB$NetworkCharacterData.class. It is located in \zombie\savefile\.
  3. Extract this file from the archive and open it using the Recaf program – a bytecode editor that
    allows us to edit the file without the hassle of decompilation, etc. You can download it from GitHub, and to run it you need Java (any version).
  4. Double-click on ServerPlayerDB$NetworkCharacterData on the left in the Workspace section (If it's not there, you haven't completed step 3). Right-click on ServerPlayerDB$NetworkCharacterData and click Edit class in assembler.
  5. Look for the lines:

ldc 65536 (The number here may be different)
invokestatic java/nio/ByteBuffer.allocate (I)Ljava/nio/ByteBuffer;

  1. Change ldc 65536 (64KB) to your own value, for example 1048576 (1MB). It should look like this:

ldc 1048576
invokestatic java/nio/ByteBuffer.allocate (I)Ljava/nio/ByteBuffer;

  1. Press CTRL+S to save the changes.
  2. Right-click on ServerPlayerDB$NetworkCharacterData on the left in the Workspace again and export the saved file to any folder.
  3. Replace the original file with the modified file.

You are magnificent!

*You don't need to do all this on the client side, just on the server side.

This guide was created by its original author on the Steam Community. Are you the author and want it removed? Request removal.