-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMap.cs
190 lines (175 loc) · 7.08 KB
/
DMap.cs
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
//using DMapLoader;
namespace Server
{
public class DMaps
{
public static ArrayList MapsNeeded = new ArrayList() { 1026, 1025, 1013, 1700, 600, 700, 1005, 1038, 1000, 1001, 1010, 1002, 1036, 1950, 1038, 1039, 1037, 1039, 1011, 1015, 1020, 2021, 2022, 2023, 2024, 1028, 1785, 1786, 1787, 1351, 1352, 1353, 1354, 1010, 6000, 6001, 6002, 5000, 1707, 1068, 9995, 9996, 9997, 1099, 1098, 9998, 1996 };
public static ArrayList DengunMaps1 = new ArrayList() { (ushort)1996, (ushort)1785, (ushort)0, (ushort)1, (ushort)2 };
public static ArrayList DimMaps = new ArrayList() { (ushort)1996, (ushort)1707, (ushort)1068, (ushort)0, (ushort)1, (ushort)2 };
public static ArrayList NoPKMaps = new ArrayList() { (ushort)1036, (ushort)1950, (ushort)1039, (ushort)1002, (ushort)700, (ushort)1004 };
public static ArrayList FreePKMaps = new ArrayList() { (ushort)6000, (ushort)1081, (ushort)6001, (ushort)1038, (ushort)1005, (ushort)1068, (ushort)1090, (ushort)1707, (ushort)5000 };
public static Hashtable DynamicMapsOwner = new Hashtable();
public static Hashtable H_Maps = new Hashtable();
public static Hashtable H_DynamicMaps = new Hashtable();
public static bool Loaded = false;
public static void LoadMaps()
{
if (Directory.Exists(Program.ConquerPath))
{
FileStream FS = new FileStream(Program.ConquerPath + @"GameMap.dat", FileMode.Open);
BinaryReader BR = new BinaryReader(FS);
int count = 0;
uint MapCount = BR.ReadUInt32();
for (uint i = 0; i < MapCount; i++)
{
ushort MapID = (ushort)BR.ReadUInt32();
string Path = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadInt32()));
count++;
if (MapsNeeded.Contains((int)MapID) || DengunMaps1.Contains((int)MapID))
if (!H_Maps.ContainsKey(MapID))
{
DMap D = new DMap(MapID, Path);
H_Maps.Add(MapID, D);
}
BR.ReadInt32();
}
BR.Close();
FS.Close();
Loaded = true;
Console.WriteLine("Maps Loaded " + count);
}
else
Program.WriteMessage("The specified Conquer Online folder doesn't exist. DMaps couldn't be loaded.");
}
public static bool CreateDynamicMap(ushort mapadd, ushort mapneed, uint ownerid)
{
bool addedmap = false;
if (DMaps.DynamicMapsOwner.Contains(Convert.ToInt32(ownerid)))
return false;
while (DMaps.H_Maps.Contains(mapadd))
{
mapadd++;
}
FileStream FS = new FileStream(Program.ConquerPath + @"GameMap.dat", FileMode.Open);
BinaryReader BR = new BinaryReader(FS);
uint MapCount = BR.ReadUInt32();
for (uint i = 0; i < MapCount; i++)
{
ushort MapID = (ushort)BR.ReadUInt32();
string Path = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadInt32()));
if (mapneed == MapID)
{
ushort NewMapID = mapadd;
DMap D = new DMap(NewMapID, Path);
H_Maps.Add(NewMapID, D);
H_DynamicMaps.Add(NewMapID, mapneed);
DynamicMapsOwner.Add(Convert.ToInt32(ownerid), NewMapID);
addedmap = true;
break;
}
BR.ReadInt32();
}
BR.Close();
FS.Close();
return addedmap;
}
public static bool DeleteDynamicMap(ushort mapadd, uint ownerid)
{
bool deletedmap = false;
if (!DMaps.DynamicMapsOwner.Contains(Convert.ToInt32(ownerid)))
return false;
ushort NewMapID = mapadd;
H_Maps.Remove(NewMapID);
H_DynamicMaps.Remove(NewMapID);
DynamicMapsOwner.Remove(Convert.ToInt32(ownerid));
deletedmap = true;
return deletedmap;
}
}
public struct DMapCell
{
public Boolean High;
private Boolean _noAccess;
public Boolean NoAccess
{
get
{
return _noAccess;
}
internal set
{
_noAccess = value;
}
}
public DMapCell(Boolean noAccess)
{
_noAccess = noAccess;
High = false;
}
}
public class DMap
{
private Int32 Width;
private Int32 Height;
private DMapCell[,] Cells;
public DMap(ushort MapID, string Path)
{
if (File.Exists(Program.ConquerPath + Path))
{
FileStream FS = new FileStream(Program.ConquerPath + Path, FileMode.Open);
BinaryReader BR = new BinaryReader(FS);
BR.ReadBytes(268);
Width = BR.ReadInt32();
Height = BR.ReadInt32();
Cells = new DMapCell[Width, Height];
byte[] cell_data = BR.ReadBytes(((6 * Width) + 4) * Height);
int offset = 0;
for (int y = 0; y < Width; y++)
{
for (int x = 0; x < Height; x++)
{
Boolean noAccess = BitConverter.ToBoolean(cell_data, offset) != false;
//Console.WriteLine(y);
if (MapID == 5000)
{
if (x >= 24 && x <= 29)
if (y >= 67 && y <= 72)
noAccess = true;
}
if (MapID == 1002)
{
if (x >= 606 && x <= 641)
if (y >= 674 && y <= 680)
noAccess = false;
if (x >= 148 && x <= 194)
if (y >= 541 && y <= 546)
noAccess = false;
}
Cells[x, y] = new DMapCell(noAccess);
if (MapID == 1038)
{
if (x <= 119)
Cells[x, y].High = true;
if (x >= 120 && x <= 216 && y <= 210)
Cells[x, y].High = true;
}
offset += 6;
}
offset += 4;
}
BR.Close();
FS.Close();
}
}
public DMapCell GetCell(ushort X, ushort Y)
{
return Cells[X, Y];
}
}
}