Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# map parse help.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Mon Oct 26, 2009 12:14 pm    Post subject: C# map parse help. Reply with quote

Hello,

I need to parse a .map file which is being used by a game to draw the map.
The BinaryReader class doesn't provide what I need, i need a function to read every byte and store them into a string until it encounters 0x0D 0x0A
Which marks an end of line.
The ReadString function of BinaryReader doesn't stop reading the bytes there, it just reads them as \r\n.. But I want it to stop reading there..
Is there a way to do it?

Or is there another way how i can easily parse a data file in c# or c++?

I hope I'm clear enough,

blackmorpeus.
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Mon Oct 26, 2009 1:41 pm    Post subject: Reply with quote

In c++ you can use the function getline like this:
Code:

char Inputline[128]; //Depends on how big the lines in the file are
ifstream file("myfile.map");
if( file.is_open() ){
   while( file.eof() == false ){
      file.getline(Inputline, sizeof(Inputline));
      //Process the line
   }
   file.close();
}
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Tue Oct 27, 2009 5:48 am    Post subject: Reply with quote

Regular expressions are good for this:
Code:

using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
...........
 using (TextReader fileReader = new StreamReader(filename ))
{
    string line = "";
    MatchCollection file = Regex.Matches(fileReader.ReadToEnd(),@"(?<=^).+(?=$)",RegexOptions.Multiline);
    foreach(Match lineMatch in file)
    {
        line = lineMatch.Value;
    }
}

_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Tue Oct 27, 2009 10:38 am    Post subject: Reply with quote

Thanks all, I solved it:

Code:

public class MapReader : BinaryReader
    {
        private BinaryReader reader;
        Stream mapStream;


        public MapReader(Stream file) : base(file)
        {
            this.mapStream = file;
        }

        public override String ReadString()
        {
            int currentPosition = (int)mapStream.Position;
            int enterPlace = 0;
            for (int i = 0; i < 100; i++)
            {
                if (this.ReadChar() == 0x0A)
                {
                    enterPlace = i;
                    break;
                }
            }
            string line = "";
            mapStream.Position = currentPosition;
            line = new string(this.ReadChars(enterPlace - 1));
            this.ReadByte();
            this.ReadByte();
            return line;
        }
    }
[/code]
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Wed Oct 28, 2009 10:34 am    Post subject: Reply with quote

See the binary reader works just fine..
_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Thu Oct 29, 2009 1:50 pm    Post subject: Reply with quote

Yeah it worked fine, but it didn't do what i wanted it to do.
What i wanted was a ReadString() function that stopped when there was a 0x0D 0x0A byte found Wink
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Thu Oct 29, 2009 3:24 pm    Post subject: Reply with quote

blackmorpheus wrote:
Yeah it worked fine, but it didn't do what i wanted it to do.
What i wanted was a ReadString() function that stopped when there was a 0x0D 0x0A byte found Wink

Then wouldn't you need a different class than Binaryreader? Since Binaryreader is meant to read binary files which usually don't use 0x0D 0x0A as seperation.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites