/// <summary> /// Unloads the map data from the memory. /// </summary> public static void Unload() { if (_usePlugin) { MapAndreasInternal.Instance.Unload(); _usePlugin = false; _mode = MapAndreasMode.None; return; } switch (_mode) { case MapAndreasMode.NoBuffer: _fileStream.Dispose(); break; default: _data = null; break; } _data = null; _mode = MapAndreasMode.None; }
/// <summary> /// Loads the map data into the memory. /// </summary> /// <param name="mode"> /// The <see cref="MapAndreasMode" /> to load with. /// </param> /// <exception cref="FileLoadException"> /// Thrown if the file couldn't be /// loaded. /// </exception> public static void Load(MapAndreasMode mode) { if (_mode != MapAndreasMode.None) { return; } _mode = mode; if (IsPluginLoaded()) { MapAndreasInternal.Instance.Init((int)mode, string.Empty, 1); _usePlugin = true; return; } switch (mode) { case MapAndreasMode.Full: try { using (var memstream = new FileStream(FullFile, FileMode.Open)) { _data = new ushort[memstream.Length / 2]; var buffer = new byte[2]; var loc = 0; while ((memstream.Read(buffer, 0, 2)) == 2) { _data[loc++] = BitConverter.ToUInt16(buffer, 0); } } } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + FullFile, e); } break; case MapAndreasMode.Minimal: try { using (var memstream = new FileStream(MinimalFile, FileMode.Open)) { _data = new ushort[memstream.Length / 2]; var buffer = new byte[2]; var loc = 0; while ((memstream.Read(buffer, 0, 2)) == 2) { _data[loc++] = BitConverter.ToUInt16(buffer, 0); } } } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + MinimalFile, e); } break; case MapAndreasMode.NoBuffer: try { _fileStream = new FileStream(FullFile, FileMode.Open); } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + MinimalFile, e); } break; } }
/// <summary> /// Loads the map data into the memory. /// </summary> /// <param name="mode"> /// The <see cref="MapAndreasMode" /> to load with. /// </param> /// <exception cref="FileLoadException"> /// Thrown if the file couldn't be /// loaded. /// </exception> public static void Load(MapAndreasMode mode) { if (_mode != MapAndreasMode.None) return; _mode = mode; if (IsPluginLoaded()) { Internal.Init((int) mode, string.Empty, 1); _usePlugin = true; return; } switch (mode) { case MapAndreasMode.Full: try { using (var memstream = new FileStream(FullFile, FileMode.Open)) { _data = new ushort[memstream.Length/2]; var buffer = new byte[2]; var loc = 0; while ((memstream.Read(buffer, 0, 2)) == 2) _data[loc++] = BitConverter.ToUInt16(buffer, 0); } } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + FullFile, e); } break; case MapAndreasMode.Minimal: try { using (var memstream = new FileStream(MinimalFile, FileMode.Open)) { _data = new ushort[memstream.Length/2]; var buffer = new byte[2]; var loc = 0; while ((memstream.Read(buffer, 0, 2)) == 2) _data[loc++] = BitConverter.ToUInt16(buffer, 0); } } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + MinimalFile, e); } break; case MapAndreasMode.NoBuffer: try { _fileStream = new FileStream(FullFile, FileMode.Open); } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + MinimalFile, e); } break; } }
/// <summary> /// Unloads the map data from the memory. /// </summary> public static void Unload() { if (_usePlugin) { Internal.Unload(); _usePlugin = false; _mode = MapAndreasMode.None; return; } switch (_mode) { case MapAndreasMode.NoBuffer: _fileStream.Dispose(); break; default: _data = null; break; } _data = null; _mode = MapAndreasMode.None; }
/// <summary> /// Loads the map data into the memory. /// </summary> /// <param name="mode"> /// The <see cref="MapAndreasMode" /> to load with. /// </param> /// <exception cref="FileLoadException"> /// Thrown if the file couldn't be /// loaded. /// </exception> public static void Load(MapAndreasMode mode) { if (_mode != MapAndreasMode.None) { return; } _mode = mode; if (IsPluginLoaded()) { _nativeInit = new NativeFunction("MapAndreas_Init", typeof(int), typeof(string), typeof(int)); _nativeUnload = new NativeFunction("MapAndreas_Unload"); _nativeFindZ = new NativeFunction("MapAndreas_FindZ_For2DCoord", typeof(float), typeof(float), typeof(float).MakeByRefType()); _nativeFindAvgZ = new NativeFunction("MapAndreas_FindAverageZ", typeof(float), typeof(float), typeof(float).MakeByRefType()); _nativeSetZ = new NativeFunction("MapAndreas_SetZ_For2DCoord", typeof(float), typeof(float), typeof(float)); _native_SaveCurrentHMap = new NativeFunction("MapAndreas_SaveCurrentHMap", typeof(string)); _nativeInit.Invoke((int)mode, string.Empty, 1); _usePlugin = true; return; } switch (mode) { case MapAndreasMode.Full: try { using (var memstream = new FileStream(FullFile, FileMode.Open)) { _data = new ushort[memstream.Length / 2]; var buffer = new byte[2]; int loc = 0; while ((memstream.Read(buffer, 0, 2)) == 2) { _data[loc++] = BitConverter.ToUInt16(buffer, 0); } } } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + FullFile, e); } break; case MapAndreasMode.Minimal: try { using (var memstream = new FileStream(MinimalFile, FileMode.Open)) { _data = new ushort[memstream.Length / 2]; var buffer = new byte[2]; int loc = 0; while ((memstream.Read(buffer, 0, 2)) == 2) { _data[loc++] = BitConverter.ToUInt16(buffer, 0); } } } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + MinimalFile, e); } break; case MapAndreasMode.NoBuffer: try { _fileStream = new FileStream(FullFile, FileMode.Open); } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + MinimalFile, e); } break; } }
/// <summary> /// Loads the map data into the memory. /// </summary> /// <param name="mode"> /// The <see cref="MapAndreasMode" /> to load with. /// </param> /// <exception cref="FileLoadException"> /// Thrown if the file couldn't be /// loaded. /// </exception> public static void Load(MapAndreasMode mode) { if (_mode != MapAndreasMode.None) return; _mode = mode; if (IsPluginLoaded()) { _nativeInit = new NativeFunction("MapAndreas_Init", typeof(int), typeof(string), typeof(int)); _nativeUnload = new NativeFunction("MapAndreas_Unload"); _nativeFindZ = new NativeFunction("MapAndreas_FindZ_For2DCoord", typeof(float), typeof(float), typeof(float).MakeByRefType()); _nativeFindAvgZ = new NativeFunction("MapAndreas_FindAverageZ", typeof(float), typeof(float), typeof(float).MakeByRefType()); _nativeSetZ = new NativeFunction("MapAndreas_SetZ_For2DCoord", typeof(float), typeof(float), typeof(float)); _native_SaveCurrentHMap = new NativeFunction("MapAndreas_SaveCurrentHMap", typeof(string)); _nativeInit.Invoke((int) mode, string.Empty, 1); _usePlugin = true; return; } switch (mode) { case MapAndreasMode.Full: try { using (var memstream = new FileStream(FullFile, FileMode.Open)) { _data = new ushort[memstream.Length/2]; var buffer = new byte[2]; int loc = 0; while ((memstream.Read(buffer, 0, 2)) == 2) _data[loc++] = BitConverter.ToUInt16(buffer, 0); } } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + FullFile, e); } break; case MapAndreasMode.Minimal: try { using (var memstream = new FileStream(MinimalFile, FileMode.Open)) { _data = new ushort[memstream.Length/2]; var buffer = new byte[2]; int loc = 0; while ((memstream.Read(buffer, 0, 2)) == 2) _data[loc++] = BitConverter.ToUInt16(buffer, 0); } } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + MinimalFile, e); } break; case MapAndreasMode.NoBuffer: try { _fileStream = new FileStream(FullFile, FileMode.Open); } catch (Exception e) { _mode = MapAndreasMode.None; throw new FileLoadException("Couldn't load " + MinimalFile, e); } break; } }