I’m diving into modding a closed-source game that uses Havok 2015, and I’m rewriting the netcode and game state management to implement GGPO. It’s a pretty ambitious project, but I’ve hit a significant snag with the save/load operations related to their Havok integration.
So, here’s the crux of the issue: when I try to load a saved game state and then step to the next frame, I frequently encounter crashes. They seem to stem from some function that’s trying to work with a Havok struct. Right now, I’m just ignoring those Havok structs and saving/restoring pointers, but this not only leads to inaccuracies in the game state but also contributes to making the crash problem worse.
I’ve seen that Havok has a WorldSnapshot and a WorldSnapshot_Load feature, but from what I understand, it doesn’t save or restore the HkpWorld in a way that preserves everything in place. This means I’d have to go through the painstaking process of reconnecting all the pointers to the Havok structures, which feels nearly impossible given the complexity involved.
I’m really curious about how other games using Havok manage rollback netcode without messing up their internal state, especially during save/load operations. Do they actually save and restore the entire HkpWorld? Is there a better way in modern Havok to handle saving and loading specific parts of its state? When they roll back, do they just recreate those Havok structures from the game state, or is there some nuanced process they follow to ensure everything stays in sync?
Any insights or shared experiences would be super helpful! It feels like there’s something fundamental I’m missing, and I could really use some guidance from others who’ve tackled similar issues with Havok in their games. Thanks!
You’re encountering crashes because simply saving and restoring raw pointers or partially ignoring Havok’s internal structures leads to broken internal references; Havok’s memory layout and object relationships are too complex to handle this way. Most games implementing rollback netcode alongside Havok physics don’t directly save and restore the entire
hkpWorld
struct. Instead, they serialize only essential gameplay state—positions, velocities, orientations, and any other necessary metadata—and when rolling back, they carefully reconstruct the Havok world from this authoritative, simplified representation. Typically, this involves using Havok’s dedicated serialization mechanisms or even manually respawning/reconstructing physics objects to avoid corrupted internal pointers.Leveraging Havok’s built-in snapshot system (like
WorldSnapshot
andWorldSnapshot_Load
) may seem appealing initially, but it generally isn’t designed with rollback functionality in mind; it won’t restore complex internal states seamlessly. As a robust solution, consider crafting a deterministic, minimal state snapshot that captures only essential parameters. Then, use this snapshot to recreate the entire Havok representation consistently each time you rollback. This method ensures that state sync remains accurate and internal Havok objects stay valid, ultimately eliminating pointer corruption and associated crashes.Wow, that sounds like a huge undertaking! I can imagine how tricky it must be to deal with all the Havok stuff, especially since it’s closed-source and you can’t just dig into it directly.
From what I know (which isn’t a lot), the WorldSnapshot feature is supposed to help with saving and loading, but it sounds like it’s not really doing the job for you. If it doesn’t save the HkpWorld properly, then you’re right about having to reconnect pointers, which seems like a nightmare. I’ve heard that some games that use Havok do indeed try to save the whole world state, but they often have custom solutions to handle the complexities of everything.
One approach that might be worth looking into is whether you can create a sort of “template” for your Havok structures. That way, instead of saving the entire HkpWorld state, you could save certain parameters that allow you to reconstruct the structures more easily when loading. Some games might do something similar, where they save essential information and recreate the world state from that.
As for rollback netcode, it seems like some devs rely on a combination of saving the game state and using a deterministic simulation method to recreate the necessary Havok states when rolling back. So, they might not be literally saving everything, but instead keeping track of events or changes that can be replayed.
It’s definitely a complex issue, and it might be helpful to check out forums or communities dedicated to game development with Havok. Sometimes, seeing snippets of code from others or discussing it with fellow devs can lead to a breakthrough. Hang in there!