REPENTOGON icon indicating copy to clipboard operation
REPENTOGON copied to clipboard

Fix socket in --luadebug mode.

Open elliottcarlson opened this issue 6 months ago • 12 comments

Currently, when launching with --luadebug and using require("socket") will cause Repentogon to crash. This is due to the scripts/socket/core.dll being built for the base TBOI, and it will not work with Lua 5.4.

The fix for this is to build a new luasocket linked to Lua 5.4, however, there are some nuances to this approach.

Since scripts/socket.lua ships with TBOI, and it directly references scripts/socket/core.dll, we can not cleanly override when socket is being required. As I don't think there should be any permanent changes to the default files (which would get reset on a Steam integrity check anyhow), we have to hack around this slightly.

The route I have taken is to add luasocket as a new libs submodule. I have created a patch for src/luasocket.c which will rename the entry point to repentogon_socket.core. A new folder is added under resources/scripts called repentogon_socket which includes the same base files from the socket folder, but gets the new core.dll that is built during the standard build process.

The one hacky element to this approach, which I am not really happy about, but don't see a solid way of working around (definitely open to suggestions), is the interception of require("socket") inside of main_ex.lua. I took advantage of the fact that require is already being caught and re-addressed to oldrequire, and add a check for if the modname is socket.core then it should load in the repentogon_socket.core instance instead. While I am not happy about this, it allows luasocket to be loaded without altering any of the base files in Isaac.

I have tested this extensively with Repentogon, as well as via -repentogonoff, and performing an uninstall of Repentogon to ensure it continues to work as expected.

No changes in the build process; in the cleanup process there would be the additional removal of the repentogon_socket folder within scripts, however it has no side effects if not removed either.

elliottcarlson avatar Aug 07 '24 17:08 elliottcarlson