String problem

10/03/2011 12:57 BaussHacker#1
Is not much of a conquer problem, but more a programming problem, but it's related to Conquer as it's for an ani editor.

So the problem is, when I'm reading the ids of the files, then the result is something like this:
Code:
561359
1
I have tried split with \n and check if the current char was alpha only, but it still does it :/

And when I copy it from the .ani file itself, then it would be:
Code:
5613591
So what could I do to make the itemid being normal? It's really bugging me ><

And this is how I get the item id:
Code:
            for (int i = 0; i < Values.Length; i++)
            {
                if (Values[i].StartsWith("["))
                {
                    ItemIDs.Add((Values[i] + 1).Replace("[Item", "").Replace("]", ""));
                }
            }
ItemIDs is a List<string>.

How I call it:
Code:
            foreach (string id in ItemIDs)
            {
                string select = comboBox1.SelectedItem.ToString();
                if (select == id)
                {
                    textBox1.Text = "Item" + id;
10/03/2011 13:41 pro4never#2
Two options...

#1: To get item ids that end in 0 (not equipment generally...)


itemID = itemID / 10 * 10;

#2: To get item ids that end in 5 (normal quality for equipment... non damaged non special versions)

if(itemID % 10 < 5)
itemID += 5 - newID % 10;

What this says in english (although I know you know what it does) is....

Take my id, divide it by 10 (gives me the LAST digit) and check if it's less than 5 (damaged or 'less than normal')

Now boost the ID by 5 - whatever it currently is (think about it... 1005 + 5-5 = 1005.... 1004 +5 - 4 = 1005. Simple logic)

Now you have to deal with other situations which are more likely


#3: You want to 'downgrade' all id's to a normal ID (IE: getting the base of a weapon maybe?)

itemID = itemID / 10 * 10 + 5;

That's the simplest way I can think of it. Just sets the last digit to 5 in this case (or whatever you want it to be really... set it to super if you wanted.


</sleepy post that probably completely bypasses the point of the thread>
10/03/2011 14:18 nTL3fTy#3
Quote:
Originally Posted by BaussHacker View Post
I have tried split with \n and check if the current char was alpha only, but it still does it :/
Environment.NewLine:
Code:
/*===================================NewLine==================================== 
        **Action: A property which returns the appropriate newline string for the given
        **        platform. 
        **Returns: \r\n on Win32. 
        **Arguments: None.
        **Exceptions: None. 
        ==============================================================================*/
        public static String NewLine {
            get {
                Contract.Ensures(Contract.Result<String>() != null); 
#if !PLATFORM_UNIX
                return "\r\n"; 
#else 
                return "\n";
#endif // !PLATFORM_UNIX 
            }
        }
Quote:
Originally Posted by BaussHacker View Post
And this is how I get the item id:
Code:
            for (int i = 0; i < Values.Length; i++)
            {
                if (Values[i].StartsWith("["))
                {
                    ItemIDs.Add((Values[i] + 1).Replace("[Item", "").Replace("]", ""));
                }
            }
You could use Substring:
Code:
var lines = new[] { "[ItemDefault]", "[Item50000]", "[Item3111000]" };
foreach (var line in lines)
{
    var sub = line.Substring(5, line.Length - 6);
    Console.WriteLine(sub);
}
Output:
Code:
Default
50000
3111000
10/03/2011 14:51 BaussHacker#4
Like I said already tried newline.

Quote:
Originally Posted by pro4never View Post
Two options...

#1: To get item ids that end in 0 (not equipment generally...)


itemID = itemID / 10 * 10;

#2: To get item ids that end in 5 (normal quality for equipment... non damaged non special versions)

if(itemID % 10 < 5)
itemID += 5 - newID % 10;

What this says in english (although I know you know what it does) is....

Take my id, divide it by 10 (gives me the LAST digit) and check if it's less than 5 (damaged or 'less than normal')

Now boost the ID by 5 - whatever it currently is (think about it... 1005 + 5-5 = 1005.... 1004 +5 - 4 = 1005. Simple logic)

Now you have to deal with other situations which are more likely


#3: You want to 'downgrade' all id's to a normal ID (IE: getting the base of a weapon maybe?)

itemID = itemID / 10 * 10 + 5;

That's the simplest way I can think of it. Just sets the last digit to 5 in this case (or whatever you want it to be really... set it to super if you wanted.


</sleepy post that probably completely bypasses the point of the thread>
ID is from MapItemIco.ani and ItemMinIco.ani
10/03/2011 15:03 Korvacs#5
Can you paste some example text your trying to read? I never had this problem when i was reading from ani files.
10/03/2011 15:10 BaussHacker#6
Quote:
Originally Posted by Korvacs View Post
Can you paste some example text your trying to read? I never had this problem when i was reading from ani files.
Code:
            ItemIDs = new List<string>();
            string[] Values;
            FileStream fs = new FileStream(Environment.CurrentDirectory + "\\ani\\" + comboBox2.SelectedItem.ToString() + ".ani", FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            Values = sr.ReadToEnd().Split('\n');
            sr.Close();
            fs.Close();

            for (int i = 0; i < Values.Length; i++)
            {
                if (Values[i].StartsWith("["))
                {
                    ItemIDs.Add((Values[i] + 1).Replace("[Item", "").Replace("]", ""));
                }
            }
            foreach (string itemid in ItemIDs)
                comboBox1.Items.Add(itemid);
10/03/2011 15:44 Korvacs#7
That wasnt quite what i meant, but its like this for any ani file?
10/03/2011 15:48 BaussHacker#8
Quote:
Originally Posted by Korvacs View Post
That wasnt quite what i meant, but its like this for any ani file?
Haven't tried others. I will try and look, but I don't think it's the file as I can copy it from the file and it's all normal ><
10/03/2011 15:50 Korvacs#9
Which file is it specifically.

Well either way, my advice would be to ditch your "Values = sr.ReadToEnd().Split('\n');" and instead go with:

Code:
while ((CurrentLine = Reader.ReadLine()) != null)
And then for every line perform your filtering to get item ids and add them to the list.

For example, this is how i handle .ani files in my .wdf extractor, i realise that its not identical to what your trying to do, but you could do something similar certainly.

Code:
foreach (string _File in Directory.GetFiles(ConquerFolder + "\\ani"))
                {
                    FileStream InputFile = new FileStream(_File, FileMode.Open);
                    TextReader Reader = new StreamReader(InputFile);

                    string CurrentLine = string.Empty;
                    string Path = string.Empty;
                    uint Key = 0;

                    while ((CurrentLine = Reader.ReadLine()) != null)
                    {
                        if (!CurrentLine.StartsWith("Frame") || CurrentLine.StartsWith("FrameAmount"))
                            continue;

                        string[] Data = CurrentLine.Split('=');

                        if (Data.Length < 2)
                            continue;

                        Path = Data[1];

                        Key = Shared.CalculateStringHash(Path);
                        if (!_HashList.ContainsKey(Key))
                            _HashList.Add(Key, Path);
                    }
                }
10/03/2011 16:15 BaussHacker#10
It's ItemMinIco.ani and I will try that thank you.

Thanks Korvacs, yours example worked.