void save_dat_map_file()
{
	
	var i = ent_status(newterrain, 0);
	
	int dimen_1 = 1;int dimen_2 = 1;int counter = 1;
	
	for (; i>0; i--)
	{
		var vertexh;
		CONTACT* c = ent_getvertex(newterrain,NULL,i);
		map_array[dimen_1][dimen_2] = c.v.y;
		dimen_1 +=1;
		if(dimen_1 > 257){dimen_1  =1;dimen_2 +=1;}
	}
	
	dimen_1 = 257; dimen_2 = 1; var harray = 0;
	
	while(dimen_1 > 0)
	{
		hmData[harray].vertex_high = map_array[dimen_1][dimen_2];
		counter +=1;
		dimen_2 +=1;
		harray += 1;
		if(dimen_2 > 257){dimen_2 =1;dimen_1 -=1;}
	}
	
	dat_save = fopen(filepfad,"w+b");
	if(dat_save == NULL){error("Fehler DAT Write");}
	fwrite(hData, sizeof(DAT_STRUC_HEADER), 1, dat_save);
	fwrite(hmData, sizeof(DAT_STRUC_HIGHMAP),  hData.hmap_block_count, dat_save);
	fwrite(waData, sizeof(DAT_STRUC_WATERMAP), hData.wmap_block_count, dat_save);
	var reslut = fwrite(objData, sizeof(DAT_STRUC_MAPOBJECTS), hData.object_block_count, dat_save);
	if (reslut != hData.object_block_count) {error("Reading error"); sys_exit (NULL);printf("Block Count = %i reslut = %i",hData.object_block_count,reslut);}
	reslut = fwrite(effData_1, sizeof(DAT_STRUC_EFFECT_1), 2, dat_save);
	if (reslut != 2) {error("Reading error"); sys_exit (NULL);printf("Block Count = %i reslut = %i",2,reslut);}
	fclose(dat_save);
	error("Done!");
	
}

void save_file_all()
{
	if(aas_window){LBG_destroy_window (aas_window);}
	if(startwindow){LBG_destroy_window (startwindow);}
	if(Change_Map_Object){LBG_destroy_window (Change_Map_Object);}
	
	var i = ent_status(newterrain, 0);
	
	int dimen_1 = 1;int dimen_2 = 1;int counter = 1;
	
	for (; i>0; i--)
	{
		var vertexh;
		CONTACT* c = ent_getvertex(newterrain,NULL,i);
		map_array[dimen_1][dimen_2] = c.v.y;
		dimen_1 +=1;
		if(dimen_1 > 257){dimen_1  =1;dimen_2 +=1;}
	}
	
	dimen_1 = 257; dimen_2 = 1; var harray = 0;
	
	while(dimen_1 > 0)
	{
		hmData[harray].vertex_high = map_array[dimen_1][dimen_2];
		counter +=1;
		dimen_2 +=1;
		harray += 1;
		if(dimen_2 > 257){dimen_2 =1;dimen_1 -=1;}
	}
	
	dat_save = fopen(filepfad,"w+b");
	if(dat_save == NULL){error("Fehler DAT Write!");}
	fwrite(hData, sizeof(DAT_STRUC_HEADER), 1, dat_save);
	fwrite(hmData, sizeof(DAT_STRUC_HIGHMAP),  hData.hmap_block_count, dat_save);
	fwrite(waData, sizeof(DAT_STRUC_WATERMAP), hData.wmap_block_count, dat_save);
	var reslut = fwrite(objData, sizeof(DAT_STRUC_MAPOBJECTS), hData.object_block_count, dat_save);
	if (reslut != hData.object_block_count) {error("Reading error"); sys_exit (NULL);printf("Block Count = %i reslut = %i",hData.object_block_count,reslut);}
	reslut = fwrite(effData_1, sizeof(DAT_STRUC_EFFECT_1), 2, dat_save);
	if (reslut != 2) {error("Reading error"); sys_exit (NULL);printf("Block Count = %i reslut = %i",2,reslut);}
	fclose(dat_save);
	
	
	sma_save = fopen(_chr(file_sma),"w+b");
	if(sma_save == NULL){error("Error SMA Write!");}
	fwrite(hsmadata, sizeof(SMA_STRUC_HEADER), 1, sma_save);
	fwrite(sma_data2, sizeof(SMA_STRUC_DATEN),  65536, sma_save);
	fwrite(smamb, sizeof(SMA_MONSTER_BLOCK_COUNT),  1, sma_save);
	fwrite(monster_data, sizeof(SMA_MONSTER_DATEN),  smamb.monster_block_count, sma_save);
	fclose(sma_save);
	
	
	error("Done!");
}