Better Map Sizes Fix — VEF Compatibility Patch
Fixes the [b]System.OverflowException[/b] crash that occurs when using [url=https://steamcommunity.com/workshop/filedetails/?id=2099101052]Better Map Sizes[/url] with some mods depending on [url=https://steamcommunity.com/workshop/filedetails/?id=2023507013]Vanilla Expanded Framework[/url] and editing the map structure such as [url=https://steamcommunity.com/workshop/filedetails/?id=3656316229]Vanilla Landmarks Expanded[/url] or [url=https://steamcommunity.com/workshop/filedetails/?id=1841354677]Alpha Biomes[/url].
The Problem
If you use Better Map Sizes (BMS) alongside VEF mods, generating a map at any custom size crashes with an overflow error in [i]HaulDestinationManager[/i] during [i]Map.ConstructComponents()[/i]. Even sizes that should be perfectly fine (250x250, 325x325) will crash. The game never reaches biome or landmark generation; it dies immediately during map setup.
What Causes It
BMS rewrites the IL bytecode of [i]Game.InitNewGame[/i] using a Harmony Transpiler. VEF does the same thing to the same method with its own Transpiler ([i]TweakMapSizes[/i]). When both Transpilers rewrite the same method, the instruction layout shifts and BMS ends up reading the wrong local variable, producing garbage values for the map dimensions. The crash was never about the map being too large. It was corrupted data from two Transpilers colliding.
What This Mod Does
[list]
[*] Removes BMS's broken Transpiler from [i]Game.InitNewGame[/i]
[*] Replaces it with a safe Prefix that reads BMS's custom size settings via reflection
[*] Sets [i]Find.GameInitData.mapSize[/i] before the method runs
[*] Handles non-square maps by also prefixing [i]MapGenerator.GenerateMap[/i]
[*] Leaves BMS's UI patches completely untouched
[/list]
Important: Setting Custom Map Size
Set your custom map size through BMS's Mod Settings page or Options → Mod Options → Custom Map Sizes for best results. The world creation screen input fields sometimes do not pick up the custom size properly, so you may end up with something else other than the 600x600 you wanted.
Load Order
Load this [b]after[/b] all of the following:
[list]
[*] Harmony
[*] Vanilla Expanded Framework
[/list]
Requirements
[list]
[*] [url=https://steamcommunity.com/workshop/filedetails/?id=2009463077]Harmony[/url]
[*] [url=https://steamcommunity.com/workshop/filedetails/?id=2023507013]Vanilla Expanded Framework[/url]
[*] [url=https://steamcommunity.com/workshop/filedetails/?id=2099101052]Better Map Sizes[/url] (no point in the fix if you are not using this)
[/list]
Tested With
395 mods active, VLE + Alpha Biomes both loaded, 500x500 custom map. No crash.
Source Code
Full C# source and build instructions are included in the mod folder. Licensed under WTFPL (same as BMS).
Coding Disclaimer
Problem diagnosed and fixed with Claude, it works and that's all that matters to me. If this doesn't sit well with you, please don't use it.