The error is caused by your code running in a 64 bit context and returning a pointer address that lies outside the range addressable with 32 bits, so .ToInt32() throws.
Call Environment.Is64BitProcess to detect whether your process is running in 32 or 64 bit, and convert the address accordingly.
Note that I didn't regression-test this, nor did I find a test suite; it's up to the maintainer to test this out.
Fixes the issue mentioned here, encountered while exporting animations: https://github.com/lastbattle/Harepacker-resurrected/issues/78#issuecomment-853157170
Uses the fix mentioned here: https://stackoverflow.com/a/36480919
Note that I didn't regression-test this, nor did I find a test suite; it's up to the maintainer to test this out.