public bool Save(string Filename, int MapFileVersion) { if (!string.IsNullOrEmpty(Filename) & Filename != this.Filename) { this.Filename = Filename; } else { Filename = this.Filename; } if (MapFileVersion <= 0) { MapFileVersion = VersionMinor; } if (MapFileVersion <= 0) { MapFileVersion = 56; } if (MapFileVersion != VersionMinor) { VersionMinor = MapFileVersion; } Debug.Log("Save file version: " + VersionMinor); System.IO.FileStream fs = new System.IO.FileStream(Filename, System.IO.FileMode.Create, System.IO.FileAccess.Write); BinaryWriter Stream = new BinaryWriter(fs); var _with2 = Stream; //# Header Section # _with2.Write(MAP_MAGIC); _with2.Write(MAP_VERSION); _with2.Write(Unknown10); //? always EDFE EFBE _with2.Write(Unknown11); //? always 2 _with2.Write((float)Width); //Map Width (in float) _with2.Write((float)Height); //Map Height (in float) _with2.Write(Unknown12); //? always 0 _with2.Write(Unknown13); //? always 0 //byte[] SaveData = new byte[0]; //SaveData = PreviewTex.GetRawTextureData(); //_with2.Write(SaveData.Length); //_with2.Write(SaveData); //Debug.Log(PreviewTex.GetRawTextureData().Length); TextureLoader.GetHeaderBGRA(PreviewTex, ref PreviewTextHeader); SaveTexture(_with2, TextureLoader.ConvertToBGRA(PreviewTex), PreviewTextHeader); //_with2.Write(PreviewImageLength); //_with2.Write(PreviewData); //Debug.Log( _with2.BaseStream.Length ); //# Heightmap Section # _with2.Write(MapFileVersion); _with2.Write(Width); _with2.Write(Height); _with2.Write(HeightScale); //Height Scale, usually 1/128 //_with2.Write(HeightmapData); for (int i = 0; i < HeightmapData.Length; i++) { _with2.Write(HeightmapData[i]); } if (MapFileVersion >= 56) { //_with2.Write(Convert.ToByte(0)); _with2.Write(Unknown15); } //Always 0? //# Texture Definition Section # _with2.Write(TerrainShader, true); //usually "TTerrain" _with2.Write(TexPathBackground, true); _with2.Write(TexPathSkyCubemap, true); if (VersionMinor >= 56) { _with2.Write(EnvCubemapsName.Length); for (int i = 0; i < EnvCubemapsName.Length; i++) { _with2.Write(EnvCubemapsName[i], true); _with2.Write(EnvCubemapsFile[i], true); } } else { if (EnvCubemapsFile.Length >= 1) { _with2.Write(EnvCubemapsFile[0], true); } else { _with2.Write(Convert.ToByte(0)); } } _with2.Write(LightingMultiplier); _with2.Write(SunDirection); _with2.Write(SunAmbience); _with2.Write(SunColor); _with2.Write(ShadowFillColor); _with2.Write(SpecularColor); _with2.Write(Bloom); _with2.Write(FogColor); _with2.Write(FogStart); _with2.Write(FogEnd); Water.Save(_with2); _with2.Write(WaveGenerators.Count); for (int i = 0; i < WaveGenerators.Count; i++) { WaveGenerators[i].Save(_with2); } if (VersionMinor < 56) { _with2.Write("No Tileset", true); _with2.Write(6); for (int i = 0; i <= 4; i++) { Layers[i].Save(_with2); } Layers[Layers.Count - 1].Save(_with2); } else { _with2.Write(MinimapContourInterval); int color = 0; color |= MinimapDeepWaterColor.a << 24; color |= MinimapDeepWaterColor.r << 16; color |= MinimapDeepWaterColor.g << 8; color |= MinimapDeepWaterColor.b; _with2.Write(color); int color2 = 0; color2 |= MinimapContourColor.a << 24; color2 |= MinimapContourColor.r << 16; color2 |= MinimapContourColor.g << 8; color2 |= MinimapContourColor.b; _with2.Write(color2); int color3 = 0; color3 |= MinimapShoreColor.a << 24; color3 |= MinimapShoreColor.r << 16; color3 |= MinimapShoreColor.g << 8; color3 |= MinimapShoreColor.b; _with2.Write(color3); int color4 = 0; color4 |= MinimapLandStartColor.a << 24; color4 |= MinimapLandStartColor.r << 16; color4 |= MinimapLandStartColor.g << 8; color4 |= MinimapLandStartColor.b; _with2.Write(color4); int color5 = 0; color5 |= MinimapLandEndColor.a << 24; color5 |= MinimapLandEndColor.r << 16; color5 |= MinimapLandEndColor.g << 8; color5 |= MinimapLandEndColor.b; _with2.Write(color5); if (VersionMinor > 56) { _with2.Write(Unknown14); } for (int i = 0; i < Layers.Count; i++) { Layers[i].SaveAlbedo(_with2); } for (int i = 0; i < Layers.Count - 1; i++) { Layers[i].SaveNormal(_with2); } } _with2.Write(Unknown7); //? _with2.Write(Unknown8); //? Decals = DecalsControler.GetAllDecals(); _with2.Write(Decals.Count); for (int i = 0; i < Decals.Count; i++) { Decals[i].Save(_with2, i); } _with2.Write(DecalGroups.Count); for (int i = 0; i < DecalGroups.Count; i++) { DecalGroups[i].Save(_with2); } _with2.Write(Width); //Width again _with2.Write(Height); //Height again _with2.Write(1); TextureLoader.GetHeaderDxt5(NormalmapTex, ref NormalmapHeader); SaveTexture(_with2, NormalmapTex, NormalmapHeader); //Format.Dxt5 if (VersionMinor < 56) { _with2.Write(1); } TextureLoader.GetHeaderBGRA(TexturemapTex, ref TextureMapHeader); SaveTexture(_with2, TextureLoader.ConvertToBGRA(TexturemapTex), TextureMapHeader); if (VersionMinor >= 56) { TextureLoader.GetHeaderBGRA(TexturemapTex2, ref TextureMap2Header); SaveTexture(_with2, TextureLoader.ConvertToBGRA(TexturemapTex2), TextureMap2Header); } _with2.Write(1); TextureLoader.GetHeaderDxt5(WatermapTex, ref WatermapHeader); SaveTexture(_with2, WatermapTex, WatermapHeader); _with2.Write(WaterFoamMask); _with2.Write(WaterFlatnessMask); _with2.Write(WaterDepthBiasMask); _with2.Write(TerrainTypeData.ToArray()); if (MapFileVersion <= 52) { _with2.Write(Convert.ToInt16(0)); } if (VersionMinor >= 60) { AdditionalSkyboxData.Save(_with2); } _with2.Write(Props.Count); for (int i = 0; i <= Props.Count - 1; i++) { Props[i].Save(_with2); } _with2.Close(); fs.Close(); fs.Dispose(); return(true); }