Is there a way to save map data in game?

I'm changing tile data in game using the script call $game_map.data[x,y,0..2]=value (ex. $game_map.data[0,0,0]=1555 would coerce the ground at coordinates 0,0 to snow at the A Layer on when used on a map whose tileset is the default exterior tileset). By looping this function with preset data I've created a dungeon generator, but wish to save the changed map data to the editor (similar to just editing the map by hand in the editor & hitting save) while in game. From my research it seems map data is stored in 2 places, MapID.rvdata2 & MapInfos.rvdata2, but anything I've thought of to attempt to write data to them either has either done nothing or corrupted said file.

EDIT:
Solved the problem. For anyone that may find it useful here's my solution:

module EL
def self.start
autogen = load_data(sprintf("Data/Map%03d.rvdata2", 999))
x = -1
y = 0
loop do
x += 1
y += x == $game_map.width ? 1 : 0
x += x == $game_map.width ? -x : 0
if y == $game_map.height
break
end
autogen.data[x,y,0] = $game_map.data[x,y,0]
autogen.data[x,y,1] = $game_map.data[x,y,1]
autogen.data[x,y,2] = $game_map.data[x,y,2]
end
save_data(autogen,sprintf("Data/Map%03d.rvdata2", 999))
maplist = load_data("Data/MapInfos.rvdata2")
mapinfo = RPG::MapInfo.new
mapinfo.name = sprintf("Auto-Generated")
mapinfo.parent_id = 0
mapinfo.order = 999
mapinfo.expanded = true
mapinfo.scroll_x = 0
mapinfo.scroll_y = 0
maplist[999]=mapinfo
save_data(maplist,"Data/MapInfos.rvdata2")
end
end

(This will overwrite Map999 & only copies tile data from the current active map. It also modifies MapInfos which contains data on game maps. Use at your own risk. The script call is EL.start)
I love you.
LOL.

yoshine, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-way-to-save-map-data-in-game.152628/