Auto-Tiling when setting $game_map.data[x, y, z]

I'm working on a script to generate a randomly-generated dungeon at runtime. (It's fun.)  I have pretty good results so far; I can generate a connected, decent-looking map similar to what the RPG Maker tool generates from Generate Dungeon.

The main issue I have is with auto-tiles. Check this screenshot out:

xtGGwT5.png


Notice the tiles for the wall are not auto-tiling; you can see what they should look like in the window on the right.

I looked at the script from this thread, but it seems depressingly complicated to manually calculate which of the 24-48 auto-tile values I have to set. Is that really the only way to do this?

I'm setting tile data directly by using $game_map.data[x, y, 0] = tile_id. (I require a pre-populated map with a single, stand-alone tile in the first tile location so I can get the ID.)
Tsukihime's tile swap script must do something like this. Take a look and see what her logic is. I do suspect you'd have to do some reasonably complicated testing of surrounding tiles to see what tile belongs (and to adjust the surrounding tiles accordingly)
I solved this by including KilloZappit's Auto Tile Update script: http://www.rpgmakervxace.net/blog/121/entry-454-autotile-update-script/
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/auto-tiling-when-setting-game_map-data-x-y-z.29989/