RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

BodyConverter

I Cheat

Wanderer
BodyConverter

Code:
using System;
using System.Collections.Generic;
using System.IO;

namespace Client
{
    class BodyConverter
    {
        private static List<List<int>> m_Values;

        static BodyConverter()
        {
            using (StreamReader streamReader = new StreamReader(FileManager.GetFilePath("bodyconv.def")))
            {
                string currentLine;

                while ((currentLine = streamReader.ReadLine()) != null)
                {
                    if (currentLine.IndexOf("#") >= 0)
                        currentLine = currentLine.Remove(currentLine.IndexOf("#"));

                    if (currentLine.IndexOf('"') >= 0)
                        currentLine = currentLine.Remove(currentLine.IndexOf('"'));

                    currentLine = currentLine.Trim();

                    if (currentLine.Length == 0)
                        continue;

                    string[] splitLine = currentLine.Split('\t');

                    if (m_Values == null)
                    {
                        m_Values = new List<List<int>>();

                        for (int i = 0; i < splitLine.Length; i++)
                            m_Values.Add(new List<int>());
                    }

                    for (int i = 0; i < m_Values.Count; i++)
                    {
                        if (splitLine.Length < m_Values.Count)
                            m_Values[i].Add(-1);
                        else
                        {
                            splitLine[i] = splitLine[i].Trim();

                            m_Values[i].Add(Int32.Parse(splitLine[i]));
                        }
                    }
                }
            }
        }

        public static int Convert(int value, out int fileIndex)
        {
            int index = GetIndex(value);

            if (index >= 0)
            {
                for (int i = 1; i < m_Values.Count; i++)
                {
                    if (m_Values[i][index] != -1)
                    {
                        fileIndex = i + 1;

                        return m_Values[i][index];
                    }
                }
            }

            fileIndex = 1;

            return value;
        }

        private static int GetIndex(int value)
        {
            for (int i = 0; i < m_Values[0].Count; i++)
            {
                if (m_Values[0][i] == value)
                    return i;
            }

            return -1;
        }
    }
}
Code:
// fileIndex:
// 1 = anim.mul
// 2 = anim2.mul
// 3 = anim3.mul
// 4 = anim4.mul
// 5 = anim5.mul

int bodyID = 917;
int fileIndex;

bodyID = BodyConverter.Convert(bodyID, out fileIndex);

// Result: bodyID = 637 & fileIndex = 5
 
Top