I wrote those two functions: (language is BlitzBasic)
LoadMap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Function LoadMap(path$) ; Loads map (overwrites existing variables) 	Local File = ReadFile(path) 	If File > 0 Then 		If ReadLine(File) = "Unreal Software's Counter-Strike 2D Map File (max)" Then ;True CS2D format 			; Byte settings 			Setting_ScrollLikeTiles# = ReadByte(File) Print Setting_ScrollLikeTiles ;-- 			Setting_UseModifiers# = ReadByte(File) Print Setting_UseModifiers ;-- 			For I = 1 To 8 				ReadByte(File) 			Next 			 			; Int settings 			Setting_UpTime# = ReadInt(File) Print Setting_UpTime ;-- 			Setting_UsgnMapAuthor# = ReadInt(File) 			If Setting_UsgnMapAuthor > 0 Then 				Setting_UsgnMapAuthor# = Setting_UsgnMapAuthor - 51 			End If 			Print Setting_UsgnMapAuthor ;-- 			For I = 1 To 8 				ReadInt(File) 			Next 			 			; String settings 			Setting_AuthorName$ = ReadLine(File) Print Setting_AuthorName ;-- 			For I = 1 To 9 				ReadLine(File) 			Next 			 			; More map settings 			Print ReadLine(File) ;-- 			Setting_TilesetFileName$ = ReadLine(File) 			Setting_TileCount# = ReadByte(File) 			Setting_MapWidth# = ReadInt(File) 			Setting_MapHeight# = ReadInt(File) 			Setting_BackgroundFileName$ = ReadLine(File) 			Setting_ScrollSpeedX# = ReadInt(File) 			Setting_ScrollSpeedY# = ReadInt(File) 			Setting_BackGroundRed# = ReadByte(File) 			Setting_BackGroundGreen# = ReadByte(File) 			Setting_BackGroundBlue# = ReadByte(File) 			Print ReadLine(File) ;-- 			 			; Tile types 			Dim Setting_TileType#(Setting_TileCount) 			For I = 0 To Setting_TileCount 				Setting_TileType(I) = ReadByte(File) Print(Setting_TileType(I)) 			Next 			 			; Map tiles 			Dim Map_Tile(Setting_MapWidth+1,Setting_MapHeight+1) 			For X = 0 To Setting_MapWidth 				For Y = 0 To Setting_MapHeight 					Map_Tile(X,Y) = ReadByte(File) 				Next 			Next 			 			; Map modifiers 			Dim Map_MapModifier#(Setting_MapWidth+1,Setting_MapHeight+1) 			If Setting_UseModifiers = 1 Then 				For X = 0 To Setting_MapWidth 					For Y = 0 To Setting_MapHeight 						Map_MapModifier(X,Y) = ReadByte(File) 						If Map_MapModifier(X,Y) <> 0 Then 							Print("MOD: " + Map_MapModifier(X,Y)) 						End If 						Dim Map_Data_TileFrame#(Setting_MapWidth+1,Setting_MapHeight+1) 						Dim Map_Data_TileR#(Setting_MapWidth+1,Setting_MapHeight+1) 						Dim Map_Data_TileG#(Setting_MapWidth+1,Setting_MapHeight+1) 						Dim Map_Data_TileB#(Setting_MapWidth+1,Setting_MapHeight+1) 						Dim Map_Data_TileOverlay#(Setting_MapWidth+1,Setting_MapHeight+1) 						If (Map_MapModifier(X,Y) And (64 + 128)) > 0 Then 							If (Map_MapModifier(X,Y) And (64+128)) = 192 Then 								ReadLine(File) 								Print("if") 							Else If (Map_MapModifier(X,Y) And (64+128)) = 64 Then 								Map_Data_TileFrame(X,Y) = ReadByte(File) 								Print(Map_MapModifier(X,Y))	 							Else 								Map_Data_TileR(X,Y) = ReadByte(File) 								Map_Data_TileG(X,Y) = ReadByte(File) 								Map_Data_TileB(X,Y) = ReadByte(File) 								Map_Data_TileOverlay(X,Y) = ReadByte(File) 								Print("else") 							End If 						End If 					Next 				Next 			End If 						 			; Entities 			Setting_EntityCount# = ReadInt(File) Print(Setting_EntityCount) 			Dim Map_Entity_Name$(Setting_EntityCount) 			Dim Map_Entity_Type#(Setting_EntityCount) 			Dim Map_Entity_X#(Setting_EntityCount) 			Dim Map_Entity_Y#(Setting_EntityCount) 			Dim Map_Entity_Trigger$(Setting_EntityCount) 			Dim Map_Entity_Int#(Setting_EntityCount,10) 			Dim Map_Entity_String$(Setting_EntityCount,10) 			For I = 1 To Setting_EntityCount 				Map_Entity_Name(I) = ReadLine(File) 				Map_Entity_Type(I) = ReadByte(File) 				Map_Entity_X(I) = ReadInt(FIle) 				Map_Entity_Y(I) = ReadInt(File) 				Map_Entity_Trigger(I) = ReadLine(File) 				For II = 1 To 10 					Map_Entity_Int(I, II) = ReadInt(File) 					Map_Entity_String(I, II) = ReadLine(File) 				Next 			Next 		End If 		CloseFile(File) 	End If End Function
SaveMap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Function SaveMap(path$) ; Saves map 	Local File = WriteFile(path) 	If File > 0 Then 		WriteLine(File, "Unreal Software's Counter-Strike 2D Map File (max)") 		 		; Byte settings 		WriteByte(File, Setting_ScrollLikeTiles) 		WriteByte(File, Setting_UseModifiers) 		For I = 1 To 8 			WriteByte(File, 0) 		Next 		 		; Int settings 		WriteInt(File, Setting_UpTime) 		WriteInt(File, Setting_UsgnMapAuthor) 		For I = 1 To 8 			WriteInt(File, 0) 		Next 		 		; String settings 		WriteLine(File, Setting_AuthorName) 		For I = 1 To 9 			WriteLine(File, "") 		Next 		 		; More map settings 		WriteLine(File, Setting_MapWidth * Setting_MapHeight + "x" + Setting_TileCount + "$" + Replace(CurrentTime(), ":", "") + "%" + MilliSecs()) 		WriteLine(File, Setting_TilesetFileName) 		WriteByte(File, Setting_TileCount) 		WriteInt(File, Setting_MapWidth) 		WriteInt(File, Setting_MapHeight) 		WriteLine(File, Setting_BackgroundFileName) 		WriteInt(File, Setting_ScrollSpeedX) 		WriteInt(File, Setting_ScrollSpeedY) 		WriteByte(File, Setting_BackgroundRed) 		WriteByte(File, Setting_BackgroundGreen) 		WriteByte(File, Setting_BackgroundBlue) 		 		; Test 		WriteLine(File, "ed.erawtfoslaernu") 		 		; Tile modes 		Print(Setting_TileCount) 		For I = 0 To Setting_TileCount 			WriteByte(File, Setting_TileType(I)) 		Next 		 		; Saving map 		Print(Setting_MapWidth) 		For X = 0 To Setting_MapWidth 			For Y = 0 To Setting_MapHeight 				WriteByte(File, Map_Tile(X,Y)) 			Next 		Next 		 		; Save modifiers 		If Setting_UseModifiers = 1 Then 			For X = 0 To Setting_MapWidth 				For Y = 0 To Setting_MapHeight 					WriteByte(File, Map_MapModifier(X,Y)) 					If (Map_MapModifier(X,Y) And (64+128)) > 0 Then 						If (Map_MapModifier(X,Y) And (64+128)) = 192 Then 							WriteLine(File, "") 						Else If (Map_MapModifier(X,Y) And (64+128)) = 64 Then 							If Map_Data_TileFrame(X,Y) Then 								WriteByte(File, Map_Data_TileFrame(X,Y)) 							Else 								WriteByte(File, 0) 							End If 						Else 							If Map_Data_TileR(X,Y) Then 								WriteByte(File, Map_Data_TileR(X,Y)) 								WriteByte(File, Map_Data_TileG(X,Y)) 								WriteByte(File, Map_Data_TileB(X,Y)) 								WriteByte(File, Map_Data_TileOverlay(X,Y)) 							Else 								WriteByte(File, 255) 								WriteByte(File, 255) 								WriteByte(File, 255) 								WriteByte(File, 0) 							End If 						End If 					End If 				Next 			Next 		End If 		 		; Entities 		WriteInt(File, Setting_EntityCount) 		 		For I = 1 To Setting_EntityCount 			WriteLine(File, Map_Entity_Name(I)) 			WriteByte(File, Map_Entity_Type(I)) 			WriteInt(File, Map_Entity_X(I)) 			WriteInt(File, Map_Entity_Y(I)) 			WriteLine(File, Map_Entity_Trigger(I)) 			For II = 1 To 10 				WriteInt(File, Map_Entity_Int(I,II)) 				WriteLine(File, Map_Entity_String(I,II)) 			Next 		Next 		Print("Map Saved!") 		CloseFile(File) 	End If End Function
The problem is that when I load (using LoadMap function) one map without any tile blending (let's say de_dust2) and then save it using SaveMap function I get perfect copy.
But if I use map which uses tile blending then all the tile blends get messed up.
I checked size of original and the copy, and the copied map has a little bit more size than the original one.
I was trying to solve this problem for hours now and can't do it.
If you have any idea why does it happen, then please reply.