The 1 3 4 3 Method Rewrite Post
While I was taking my Uber back from the Postmodern Jukebox concert, I figured out how I was going to "fix" Terraria and allow myself to release an update for RomTerraria at the same time: Im going to rewrite the method that is introducing the issue.
Ive patched bugs in the base game before. For the longest time, if you didnt have a My Games/Terraria folder in your Documents folder, the game would crash when trying to create the settings file. I patched that with the original releases of RomTerraria.
Fortunately, Ive got a good place to handle injecting my replacement method. LiquidRenderer.PrepareDraw just calls the internal method.
Im going to do this patch in two phases.
Phase two will take significantly longer. Im going to rewrite LiquidRenderer.InternalPrepareDraw. Its a bit over 400 lines of, well, not good code. I mean, its dereferencing to memory before a pointer. If I was going to be a total dick, I could craft a world file that could potentially turn into a native code exploit. Fortunately, Im not a total dick. This will take me a lot longer to do and may end up moot if they fix the issue before my rewrite is done.
Ive only got this weekend to do this, so here goes nothing.
Update 11/24/2016, 11:57am: Well, its not going to happen this morning, but I am working on it...
Update 11/24/2016, 12:20pm: Ive gotten the replacement class building as a standalone DLL. Ive got to do IL-patches to replace 14 instances of the class in six methods in two classes. Im going to try to get that done before I have to leave for my afternoon social obligation.
Update 11/24/2016, 4:38pm: Im back from my social obligation and am resuming my coding. Ive almost got the replacement working.
Update 11/24/2016, 9:57pm: Stopping for the night. Ive got my replacement class patched in and am working on debugging, but Im exhausted. That said, making PrepareDraw a no-op has other side effects and isnt a good solution, so Im dropping that part of the plan.
Update 11/25/2016, 12:18pm: Taking a lunch break. Since Im afraid Im going to have to do this kind of thing again in the future, Ive created a general purpose class replacement system. Will resume testing once I am fed.
Update 11/25/2016, 1:03pm: Im now able to reproduce the crash inside my custom class inside the debugger. Should help me fix it.
Update 11/25/2016, 1:09pm: Well, its good that I made the class replacement system generic, because the crash is NOT caused by the code I suspected. It appears that something else is running amok around memory. Give me a bit of time to figure out the appropriate memory layout so I can figure out which object is immediately before this one in the heap.
Update 11/25/2016, 1:30pm: Ive got a 1.2GB memory dump that Im manually going through. Id be going faster, but the .NET memory tools require a minimum .NET version of 4.5 and Terraria is compiled to 4.0.
Update 11/25/2016, 2:25pm: Good news: managed to stop the game from crashing. Bad news: filled blocks of water arent rendering. Still going.

Update 11/25/2016, 3:53pm: Ive checked my current code into Github. Still trying to figure out why full blocks dont render. Note that this doesnt truly fix the memory overwrite, but it leaves the old 160KB object around as a "safety buffer." Im going to try for another hour, then call it a day. Ive still got work to do around the house.
Update 11/25/2016, 5:51pm: Part of the problem is that the version of Telerik JustDecompile that Im using doesnt properly decompile unsafe code evidently. Testing a fix now.
Update 11/25/2016 6:00pm: Adding padding around the wave bank let me run with water effects for almost ten seconds before the game crashed in a spectacular fashion. Looks like something is hardcoded with a max resolution and when you go above that resolution, it starts walking over memory it shouldnt. Dinner shortly, then more research
Update 11/25/2016 6:09pm: Heres a test version. This is not guaranteed to work, but appears to be working in my limited testing. Please let me know if it crashes for you.
Update 12/6/2016 1:13pm: v1.3.4.4 was just released. The test version was compiled and tested against v1.3.4.3, and may not work with v1.3.4.4. Im at work for several more hours. Let me know if I need to address anything after the fix.
Update 12/19/2016 9:35pm: Added LAA support code. Trying to fix an issue with rendering water that surfaced at certain resolutions for v1.3.4.4 before releasing an update.
Update 12/25/2016 3:58pm: Build for v1.3.4.4 here. Youll have to set up your settings again.