GameMap Reading

02/26/2011 19:06 Iron~Man#1
Well, I'm having problems reading the decoded GameMap ... It keeps reading the first map , it Doesn't go down...

Code:
           IniFile I = new IniFile(ThePath+ @"ini\TheGameMap.txt");
            uint TotalMaps = 260;
 for (uint i = 0; i < TotalMaps; i++)
            {
                ushort MapID = I.ReadUInt16("AllMaps", "MapID");
                string Path = I.ReadString("AllMaps", "Path");
                    DMap D = new DMap(MapID, Path);
                    H_DMaps.Add(MapID, D);
            }
and there's an example how the gamemap looks

Quote:
[AllMaps]

MapID=1000
Path=map/map/desert.DMap
PuzzleSize=256// Keeps reading this map.. Doesn't go any further

MapID=1001
Path=map/map/d_antre01.DMap
PuzzleSize=256

MapID=1002
Path=map/map/newplain.DMap
PuzzleSize=256

MapID=1003
Path=map/map/mine01.DMap
PuzzleSize=256

MapID=1004
Path=map/map/forum.DMap
PuzzleSize=256

MapID=1005
Path=map/map/arena.DMap
PuzzleSize=256

MapID=1006
Path=map/map/horse.DMap
PuzzleSize=256

MapID=1100
Path=map/map/star01.DMap
PuzzleSize=256

Where am I wrong?
Thank you.
02/26/2011 20:17 CptSky#2
Your structure isn't a valid INI structure. You have the same key a lot of time.

Code:
[Section]
Key=Value
Something like this can work... You can use a loop.

Code:
[Header]
Count=2

[Map0]
MapId=1000
Path=map/map/desert.dmap
PuzzleSize=256

[Map1]
MapId=1000
Path=map/map/desert.dmap
PuzzleSize=256
02/26/2011 21:27 zath#3
sorry, cant help you im bad in 5165 servers. hope someone els can help you, goodluck
02/26/2011 22:47 Iron~Man#4
Quote:
Originally Posted by CptSky View Post
Your structure isn't a valid INI structure. You have the same key a lot of time.

Code:
[Section]
Key=Value
Something like this can work... You can use a loop.

Code:
[Header]
Count=2

[Map0]
MapId=1000
Path=map/map/desert.dmap
PuzzleSize=256

[Map1]
MapId=1000
Path=map/map/desert.dmap
PuzzleSize=256
Yeh Good Idea...

Quote:
Originally Posted by zath View Post
sorry, cant help you im bad in 5165 servers. hope someone els can help you, goodluck
You can't code Zath, So Please Don't even TRY to help me.
02/26/2011 23:41 Arco.#5
Quote:
Originally Posted by Iron~Man View Post
Yeh Good Idea...
You can't code Zath, So Please Don't even TRY to help me.
#Edit;
Why are you trying to make it read from an ini file? o.O
02/27/2011 09:22 Iron~Man#6
Quote:
Originally Posted by Yup Arco View Post
#Edit;
Why are you trying to make it read from an ini file? o.O
Because the very original GameMap.dat from the latest client has 2 maps under 1 MapID , so That It gives me error when debugging.
02/27/2011 12:51 Korvacs#7
Quote:
Originally Posted by Iron~Man View Post
Because the very original GameMap.dat from the latest client has 2 maps under 1 MapID , so That It gives me error when debugging.
You just skip one instead of trying to add it to the dictionary.
02/27/2011 13:11 Syst3m_W1z4rd#8
This
Code:
                    H_DMaps.Add(MapID, D);
To
Code:
                if (!H_DMaps.Contains(MapID))
                    H_DMaps.Add(MapID, D);
02/27/2011 14:18 Iron~Man#9
Quote:
Originally Posted by Syst3m_W1z4rd View Post
This
Code:
                    H_DMaps.Add(MapID, D);
To
Code:
                if (!H_DMaps.Contains(MapID))
                    H_DMaps.Add(MapID, D);
Tried that Already, Doesn't work.
02/27/2011 14:29 Syst3m_W1z4rd#10
What is the exactly error you're getting?
02/27/2011 14:36 Iron~Man#11
Quote:
Originally Posted by Syst3m_W1z4rd View Post
What is the exactly error you're getting?
When I do that, I get no error, It Only Reads The First Map, Then It Stops.
02/27/2011 16:25 Arco.#12
Quote:
Originally Posted by Iron~Man View Post
When I do that, I get no error, It Only Reads The First Map, Then It Stops.
Why don't you instead, create a program that decodes the gamemap.dat, change the mapid, then encode it again?

#Edit;
Made the program for you, I haven't tested it fully, so there MIGHT be bugs with it, but I tested it a few times and it worked. So try it.

Here's what it does;
It reads the game map.dat and for each map information read(Mapid, Puzzlesize, Path, Pathlength) it creates a new MapInfo(); and saves the map information read, to a new MapInfo();
It then adds the new information to a dictionary, so it can be used later on.
But if the dictionary already holds the information for a certain mapid, then it creates a "randomly" generated map id, then checks if the dictionary already holds that id, if it does hold the new ID, then it generates a new id. Once the program is fully done with that gamemap.dat, it creates a new gamemap.dat file and writes the TotalMaps, then foreach value in the dictionary, it writes the values' information, to the same structure of gamemap.dat.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace GameMap
{
    public class MapInfo
    {
        public uint MapID;
        public string Path;
        public int PathLength;
        public int PuzzleSize;
    }
    class Program
    {
        static String Path = @"C:\Users\Arco\Desktop\kkkkk\ini\GameMap.dat";
        static Dictionary<uint, MapInfo> Dict = new Dictionary<uint, MapInfo>();
        static Random Random = new Random();
        static String NewPath = @"C:\Users\Arco\Desktop\GameMap.dat";
        static void Main(string[] args)
        {

            Console.Title = "GameMap.dat";
            uint TotalMaps;
            using (BinaryReader Reader = new BinaryReader(new FileStream(Path, FileMode.Open)))
            {
                TotalMaps = Reader.ReadUInt32();
                Console.WriteLine("Writing....");
                for (int i = 0; i < TotalMaps; i++)
                {

                    uint Mapid = Reader.ReadUInt32();
                    int Length = Reader.ReadInt32();
                    string newPath = Encoding.ASCII.GetString(Reader.ReadBytes(Length));
                    int Puz = Reader.ReadInt32();

                    MapInfo Map = new MapInfo();
                    Map.MapID = Mapid;
                    Map.PathLength = Length;
                    Map.Path = newPath;
                    Map.PuzzleSize = Puz;

                    if (!Dict.ContainsKey(Mapid))
                    {
                        Dict.Add(Mapid, Map);
                    }
                    else
                    {
                    trythis:
                        uint newMap = (uint)Random.Next(1200, 2000);
                        if (!Dict.ContainsKey(newMap))
                        {
                            Map.MapID = newMap;
                            Dict.Add(newMap, Map);
                            Console.WriteLine("The map ID " + Mapid + " was a copy, so it was replaced with the new ID, " + newMap);
                        }
                        else
                        {
                            goto trythis;
                        }
                    }
                }
                Reader.Close();
            }
            Console.WriteLine("Done!");
            Console.WriteLine("Press enter to begin writing the data to a new GameMap.dat");
            Console.ReadLine();

            FileStream Fil = new FileStream(NewPath, FileMode.Create);
            BinaryWriter BW = new BinaryWriter(Fil);
            BW.Write(TotalMaps);
            foreach (MapInfo Info in Dict.Values)
            {
                BW.Write(Info.MapID);
                BW.Write(Info.PathLength);
                BW.Write(Info.Path);
                BW.Write(Info.PuzzleSize);
            }
            Console.WriteLine("Done!");
            Console.WriteLine("Finished writing a new GameMap.dat...");
            Console.WriteLine("Press enter to close the program...");
            Console.ReadLine();
        }
    }
}
02/27/2011 18:47 Iron~Man#13
Quote:
Originally Posted by Yup Arco View Post
Why don't you instead, create a program that decodes the gamemap.dat, change the mapid, then encode it again?

#Edit;
Made the program for you, I haven't tested it fully, so there MIGHT be bugs with it, but I tested it a few times and it worked. So try it.

Here's what it does;
It reads the game map.dat and for each map information read(Mapid, Puzzlesize, Path, Pathlength) it creates a new MapInfo(); and saves the map information read, to a new MapInfo();
It then adds the new information to a dictionary, so it can be used later on.
But if the dictionary already holds the information for a certain mapid, then it creates a "randomly" generated map id, then checks if the dictionary already holds that id, if it does hold the new ID, then it generates a new id. Once the program is fully done with that gamemap.dat, it creates a new gamemap.dat file and writes the TotalMaps, then foreach value in the dictionary, it writes the values' information, to the same structure of gamemap.dat.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace GameMap
{
    public class MapInfo
    {
        public uint MapID;
        public string Path;
        public int PathLength;
        public int PuzzleSize;
    }
    class Program
    {
        static String Path = @"C:\Users\Arco\Desktop\kkkkk\ini\GameMap.dat";
        static Dictionary<uint, MapInfo> Dict = new Dictionary<uint, MapInfo>();
        static Random Random = new Random();
        static String NewPath = @"C:\Users\Arco\Desktop\GameMap.dat";
        static void Main(string[] args)
        {

            Console.Title = "GameMap.dat";
            uint TotalMaps;
            using (BinaryReader Reader = new BinaryReader(new FileStream(Path, FileMode.Open)))
            {
                TotalMaps = Reader.ReadUInt32();
                Console.WriteLine("Writing....");
                for (int i = 0; i < TotalMaps; i++)
                {

                    uint Mapid = Reader.ReadUInt32();
                    int Length = Reader.ReadInt32();
                    string newPath = Encoding.ASCII.GetString(Reader.ReadBytes(Length));
                    int Puz = Reader.ReadInt32();

                    MapInfo Map = new MapInfo();
                    Map.MapID = Mapid;
                    Map.PathLength = Length;
                    Map.Path = newPath;
                    Map.PuzzleSize = Puz;

                    if (!Dict.ContainsKey(Mapid))
                    {
                        Dict.Add(Mapid, Map);
                    }
                    else
                    {
                    trythis:
                        uint newMap = (uint)Random.Next(1200, 2000);
                        if (!Dict.ContainsKey(newMap))
                        {
                            Map.MapID = newMap;
                            Dict.Add(newMap, Map);
                            Console.WriteLine("The map ID " + Mapid + " was a copy, so it was replaced with the new ID, " + newMap);
                        }
                        else
                        {
                            goto trythis;
                        }
                    }
                }
                Reader.Close();
            }
            Console.WriteLine("Done!");
            Console.WriteLine("Press enter to begin writing the data to a new GameMap.dat");
            Console.ReadLine();

            FileStream Fil = new FileStream(NewPath, FileMode.Create);
            BinaryWriter BW = new BinaryWriter(Fil);
            BW.Write(TotalMaps);
            foreach (MapInfo Info in Dict.Values)
            {
                BW.Write(Info.MapID);
                BW.Write(Info.PathLength);
                BW.Write(Info.Path);
                BW.Write(Info.PuzzleSize);
            }
            Console.WriteLine("Done!");
            Console.WriteLine("Finished writing a new GameMap.dat...");
            Console.WriteLine("Press enter to close the program...");
            Console.ReadLine();
        }
    }
}
Thankies.
02/28/2011 10:18 .Kinshi#14
Check out my TinyMap release ([Only registered and activated users can see links. Click Here To Register...])

It reads the GameMap.dat file to load and convert DMaps.
I'm pretty sure I added the source as well, so you can check it out.