this is the c# code. maybe someone can transer it to java?
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Data;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Collections;
using System.ComponentModel;
using LSE.LoginServer.Logger;
using LSE.LoginServer.UI;
namespace LSE.LoginServer
{
public class linMap
{
public int mapId;
public int LocX;
public int EndX;
public int LocY;
public int EndY;
public int[][] MapData;
}
public class MapFiles
{
public string dir;
public string filename;
}
public class Map
{
public enum map_area
{
CELL_NORMAL = 0,
CELL_BLOCK = 1,
CELL_UNK1 = 2,
CELL_SAFETY = 4,
CELL_COMBAT = 8,
CELL_UNK2 = 16,
CELL_UNK3 = 32,
CELL_UNK4 = 64,
CELL_UNK5 = 128,
CELL_UNK6 = 256,
CELL_OBJECT = 512,
CELL_DOOR = 1024,
}
public int files;
public int amountfound;
public int skipped;
public int highX;
public int lowX;
public int highY;
public int lowY;
string[] szDirs;
string[] szFiles;
public int totalbytes;
string homeDir = null;
private bool isdone = true;
public static List<linMap> LinMap = new List<linMap>();
public static List<MapFiles> mapLoc = new List<MapFiles>();
MapFiles mapfile;
private static FileStream fs;
public Map()
{
files = 0;
amountfound = 0;
skipped = 0;
totalbytes = 0;
}
public void InitMaps()
{
Logger.Logger.Log(true, "Loading map data from client,
location: "+ConfigReader.LinLocation+".");
Form1.AddLogText(Form1.SERVER, "Loading map data from
client, location: " + ConfigReader.LinLocation + ".");
homeDir = Directory.GetCurrentDirectory();
LinMap = new List<linMap>();
mapLoc = new List<MapFiles>();
szDirs =
Directory.GetDirectories(ConfigReader.LinLocation);
LoadS32();
LoadSeg();
Form1.AddMapsLoaded(mapLoc.Count.ToString());
Form1.AddMapsSkipped(skipped.ToString());
LinMap = new List<linMap>();
Maploader frm = new Maploader();
frm.ShowDialog();
Logger.Logger.Log(true, "Map files loaded : " +
amountfound + ", skipped : " + skipped);
Logger.Logger.Log(true, "Map data stored in memory : " +
LinMap.Count);
}
#region LoadMaps S32
public void LoadS32()
{
for (int i = 0; i < szDirs.Length; i++)
{
LoadMap32(szDirs[i]);
}
}
public void LoadMap32(string dir)
{
szFiles = null;
szFiles = Directory.GetFiles(dir, "*.s32");
if (szFiles.Length > 0)
{
for (int i = 0; i < szFiles.Length; i++)
{
string filename = szFiles[i].Substring(dir.Length
+1);
if (!filename.ToLower().Equals("tempseg.s32"))
{
int loc = dir.Length;
int locX = FromString(filename.Substring(0,
4));
int locY = FromString(filename.Substring(4,
4));
string mapID =
dir.Substring(ConfigReader.LinLocation.Length+1);
int mapid = Convert.ToInt32(mapID);
linMap map = new linMap();
map.mapId = mapid;
map.LocX = locX;
map.LocY = locY;
LinMap.Add(map);
mapfile = new MapFiles();
mapfile.dir = dir;
mapfile.filename = filename;
mapLoc.Add(mapfile);
}
}
}
}
#endregion
#region LoadMaps SEG
public void LoadSeg()
{
for (int i = 0; i < szDirs.Length; i++)
{
LoadMapSeg(szDirs[i]);
}
}
public void LoadMapSeg(string dir)
{
szFiles = null;
szFiles = Directory.GetFiles(dir, "*.seg");
if (szFiles.Length > 0)
{
for (int i = 0; i < szFiles.Length; i++)
{
string filename = szFiles[i].Substring(dir.Length
+ 1);
if (!filename.ToLower().Equals("tempseg.seg"))
{
int loc = dir.Length;
int locX = FromString(filename.Substring(0,
4));
int locY = FromString(filename.Substring(4,
4));
string mapID =
dir.Substring(ConfigReader.LinLocation.Length + 1);
int mapid = Convert.ToInt32(mapID);
if (!CheckFile(locX, locY, mapid))
{
mapfile = new MapFiles();
mapfile.dir = dir;
mapfile.filename = filename;
mapLoc.Add(mapfile);
}
else
{
skipped ++;
}
}
}
}
}
#endregion
#region Load Data into buffer, hard part :)
public static void LoadData(string dir, string filename)
{
Maploader.Loaded++;
string file = dir + "\\" + filename;
fs = new FileStream(@file, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
// add common data to list
string mapID =
dir.Substring(ConfigReader.LinLocation.Length + 1);
int mapid = Convert.ToInt32(mapID);
// get map locx, locy from filename
int locX = FromString(filename.Substring(0, 4));
int locY = FromString(filename.Substring(4, 4));
string filetype = filename.Substring(9);
if (mapid == 1)
{
//******
// LOAD
//******
if (filetype.Equals("s32"))
{
//Logger.Logger.Log(true, "Loading "+filename);
int xdif = (32767 - locX) *64;
int ydif = (32767 - locY) *64;
//Logger.Logger.Log(true, "X Diff " + xdif + "
ydiff "+ ydif);
//*LOAD S32 MAP
DATA**********************************************
// MAP SIZE 128x128
//
// skip intro bytes
fs.Seek(32768, SeekOrigin.Begin);
// skip gfx part
ushort gfxLen = br.ReadUInt16();
long len = gfxLen * 6;
fs.Seek(len + 32768 + 2, SeekOrigin.Begin);
for (int x = 0; x < 64; x++)
for (int y = 0; y < 64; y++)
{
linMap map = new linMap();
map.LocX = xdif + x;
map.LocY = ydif + y;
map.mapId = mapid;
ushort idx = br.ReadUInt16();
ushort idy = br.ReadUInt16();
//Logger.Logger.Log(true, "Map = x: " +
map.LocX + " (data " + idx.ToString() + ") y: " + map.LocY + " (data "
+ idy.ToString()+")");
LinMap.Add(map);
}
//
****************************************************************
}
if (filetype.Equals("seg"))
{
Logger.Logger.Log(true, "Loading " + filename);
//*LOAD SEG MAP
DATA**********************************************
//
// skip intro bytes
fs.Seek(16384, SeekOrigin.Begin);
// skip gfx part
ushort gfxLen = br.ReadUInt16();
long len = gfxLen * 4;
fs.Seek(len + 16384, SeekOrigin.Begin);
// HERE DATA BEGINS!!!!
for (int i = 0; i < 4096; i++)
{
byte idx = br.ReadByte();
byte idy = br.ReadByte();
Logger.Logger.Log(true, "id = x: " +
idx.ToString() + " y: " + idy.ToString());
}
//
****************************************************************
}
}
// close all file things
fs.Close();
fs.Dispose();
br.Close();
br = null;
}
#endregion
#region Utilites
public bool CheckFile(int locx, int locy, int mapid)
{
foreach (linMap map in LinMap)
{
if (map.LocX == locx && map.LocY == locy &&
map.mapId.Equals(mapid))
{
return true;
}
}
return false;
}
// convert hex value to integer.
public static Int32 FromString(string id)
{
int num = int.Parse(id,
System.Globalization.NumberStyles.HexNumber);
return num;
}
#endregion