Contains translation tables used for mapping body values to file subsets. Animations
Example #1
0
        /// <summary>
        /// Returns Filename body is in
        /// </summary>
        /// <param name="body"></param>
        /// <returns>anim{0}.mul</returns>
        public static string GetFileName(int body)
        {
            Translate(ref body);
            int fileType = BodyConverter.Convert(ref body);

            return(fileType == 1 ? "anim.mul" : $"anim{fileType}.mul");
        }
Example #2
0
        public static bool IsAnimDefinied(int body)
        {
            var _body = body;

            Translate(ref _body);
            int fileType = BodyConverter.Convert(ref _body);

            return(IsAnimDefinied(_body, fileType));
        }
Example #3
0
        /// <summary>
        ///     Rereads AnimX files and bodyconv, body.def
        /// </summary>
        public static void Reload()
        {
            m_FileIndex  = new FileIndex("Anim.idx", "Anim.mul", 0x40000, 6);
            m_FileIndex2 = new FileIndex("Anim2.idx", "Anim2.mul", 0x10000, -1);
            m_FileIndex3 = new FileIndex("Anim3.idx", "Anim3.mul", 0x20000, -1);
            m_FileIndex4 = new FileIndex("Anim4.idx", "Anim4.mul", 0x20000, -1);
            m_FileIndex5 = new FileIndex("Anim5.idx", "Anim5.mul", 0x20000, -1);

            BodyConverter.Initialize();
            BodyTable.Initialize();
        }
Example #4
0
        /// <summary>
        /// Is Body with action and direction defined
        /// </summary>
        /// <param name="body"></param>
        /// <param name="action"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public static bool IsActionDefined(int body, int action, int direction)
        {
            Translate(ref body);
            int fileType = BodyConverter.Convert(ref body);

            GetFileIndex(body, action, direction, fileType, out FileIndex fileIndex, out int index);

            bool valid = fileIndex.Valid(index, out int length, out int _, out bool _);

            return(valid && (length >= 1));
        }
Example #5
0
        /// <summary>
        ///     Returns Filename body is in
        /// </summary>
        /// <param name="body"></param>
        /// <returns>anim{0}.mul</returns>
        public static string GetFileName(int body)
        {
            Translate(ref body);
            var fileType = BodyConverter.Convert(ref body);

            if (fileType == 1)
            {
                return("anim.mul");
            }
            return(String.Format("anim{0}.mul", fileType));
        }
Example #6
0
        /// <summary>
        /// Returns Filename body is in
        /// </summary>
        /// <param name="body"></param>
        /// <returns>anim{0}.mul</returns>
        public static string GetFileName(int body)
        {
            Translate(ref body);
            int fileType = BodyConverter.Convert(ref body);

            if (fileType == 1)
            {
                return("anim.mul");
            }
            else
            {
                return($"anim{fileType}.mul");
            }
        }
Example #7
0
        /// <summary>
        /// Inizializza una nuova istanza della classe <see cref="T:System.Object"/>.
        /// </summary>
        public Animations(Verdata verdata, Hues hues, Files files)
        {
            _files       = files;
            m_FileIndex  = new FileIndex("Anim.idx", "Anim.mul", 0x40000, 6, verdata, _files);
            m_FileIndex2 = new FileIndex("Anim2.idx", "Anim2.mul", 0x10000, -1, verdata, files);
            m_FileIndex3 = new FileIndex("Anim3.idx", "Anim3.mul", 0x20000, -1, verdata, files);
            m_FileIndex4 = new FileIndex("Anim4.idx", "Anim4.mul", 0x20000, -1, verdata, files);
            m_FileIndex5 = new FileIndex("Anim5.idx", "Anim5.mul", 0x20000, -1, verdata, files);

            _BodyConverter = new BodyConverter(_files);
            BodyTable      = new BodyTable(_files);
            _hues          = hues;
            LoadTable();
        }
Example #8
0
        /// <summary>
        /// Is Body with action and direction definied
        /// </summary>
        /// <param name="body"></param>
        /// <param name="action"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public static bool IsActionDefined(int body, int action, int direction)
        {
            Translate(ref body);
            var fileType = BodyConverter.Convert(ref body);

            GetFileIndex(body, action, direction, fileType, out var fileIndex, out var index);

            var valid = fileIndex.Valid(index, out var length, out var extra, out var patched);

            if ((!valid) || (length < 1))
            {
                return(false);
            }

            return(true);
        }
        private static void LoadTable()
        {
            int length = 400 + (Animations.m_FileIndex.Index.Length - 35000) / 175;

            Animations.m_Table = new int[length];
            for (int body = 0; body < length; ++body)
            {
                object obj = BodyTable.m_Entries[(object)body];
                if (obj == null || BodyConverter.Contains(body))
                {
                    Animations.m_Table[body] = body;
                }
                else
                {
                    BodyTableEntry bodyTableEntry = (BodyTableEntry)obj;
                    Animations.m_Table[body] = bodyTableEntry.m_OldID | int.MinValue | ((bodyTableEntry.m_NewHue ^ 32768) & (int)ushort.MaxValue) << 15;
                }
            }
        }
Example #10
0
        private static void LoadTable()
        {
            int count = 400 + ((_fileIndex.Index.Length - 35000) / 175);

            _table = new int[count];

            for (int i = 0; i < count; ++i)
            {
                var bodyTableEntryExist = BodyTable.Entries.TryGetValue(i, out BodyTableEntry bodyTableEntry);
                if (!bodyTableEntryExist || BodyConverter.Contains(i))
                {
                    _table[i] = i;
                }
                else
                {
                    _table[i] = bodyTableEntry.OldId | (1 << 31) | ((bodyTableEntry.NewHue & 0xFFFF) << 15);
                }
            }
        }
        private static void LoadTable()
        {
            int length = 400 + ((int)Animations.m_FileIndex.Index.Length - 35000) / 175;

            Animations.m_Table = new int[length];
            for (int i = 0; i < length; i++)
            {
                object item = BodyTable.m_Entries[i];
                if (item == null || BodyConverter.Contains(i))
                {
                    Animations.m_Table[i] = i;
                }
                else
                {
                    BodyTableEntry bodyTableEntry = (BodyTableEntry)item;
                    Animations.m_Table[i] = bodyTableEntry.m_OldID | -2147483648 | ((bodyTableEntry.m_NewHue ^ 32768) & 65535) << 15;
                }
            }
        }
Example #12
0
        /// <summary>
        ///     Is Body with action and direction definied
        /// </summary>
        /// <param name="body"></param>
        /// <param name="action"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public static bool IsActionDefined(int body, int action, int direction)
        {
            Translate(ref body);
            int       fileType = BodyConverter.Convert(ref body);
            FileIndex fileIndex;
            int       index;

            GetFileIndex(body, action, direction, fileType, out fileIndex, out index);

            int  length, extra;
            bool patched;
            bool valid = fileIndex.Valid(index, out length, out extra, out patched);

            if ((!valid) || (length < 1))
            {
                return(false);
            }
            return(true);
        }
Example #13
0
        private static void LoadTable()
        {
            // TODO: check why it was fixed at max 1697. Probably old code for anim.mul?
            //int count = 400 + ((_fileIndex.Index.Length - 35000) / 175);

            _table = new int[_maxAnimationValue + 1];

            for (int i = 0; i < _table.Length; ++i)
            {
                var bodyTableEntryExist = BodyTable.Entries.TryGetValue(i, out BodyTableEntry bodyTableEntry);
                if (!bodyTableEntryExist || BodyConverter.Contains(i))
                {
                    _table[i] = i;
                }
                else
                {
                    _table[i] = bodyTableEntry.OldId | (1 << 31) | ((bodyTableEntry.NewHue & 0xFFFF) << 15);
                }
            }
        }
Example #14
0
        private static void LoadTable()
        {
            int count = 400 + ((m_FileIndex.Index.Length - 35000) / 175);

            m_Table = new int[count];

            for (int i = 0; i < count; ++i)
            {
                object o = BodyTable.m_Entries[i];

                if (o == null || BodyConverter.Contains(i))
                {
                    m_Table[i] = i;
                }
                else
                {
                    var bte = (BodyTableEntry)o;

                    m_Table[i] = bte.OldID | (1 << 31) | ((bte.NewHue & 0xFFFF) << 15);
                }
            }
        }
Example #15
0
        public static Frame[] GetAnimation(int body, int action, int direction, int hue, bool preserveHue)
        {
            if (preserveHue)
            {
                Translate(ref body);
            }
            else
            {
                Translate(ref body, ref hue);
            }

            int       fileType = BodyConverter.Convert(ref body);
            FileIndex fileIndex;

            int index;

            switch (fileType)
            {
            default:
            case 1:
            {
                fileIndex = m_FileIndex;

                if (body < 200)
                {
                    index = body * 110;
                }
                else if (body < 400)
                {
                    index = 22000 + ((body - 200) * 65);
                }
                else
                {
                    index = 35000 + ((body - 400) * 175);
                }

                break;
            }

            case 2:
            {
                fileIndex = m_FileIndex2;

                if (body < 200)
                {
                    index = body * 110;
                }
                else
                {
                    index = 22000 + ((body - 200) * 65);
                }

                break;
            }

            case 3:
            {
                fileIndex = m_FileIndex3;

                if (body < 300)
                {
                    index = body * 65;
                }
                else if (body < 400)
                {
                    index = 33000 + ((body - 300) * 110);
                }
                else
                {
                    index = 35000 + ((body - 400) * 175);
                }

                break;
            }
            }

            index += action * 5;

            if (direction <= 4)
            {
                index += direction;
            }
            else
            {
                index += direction - (direction - 4) * 2;
            }

            int    length, extra;
            bool   patched;
            Stream stream = fileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }

            bool flip = (direction > 4);

            BinaryReader bin = new BinaryReader(stream);

            ushort[] palette = new ushort[0x100];

            for (int i = 0; i < 0x100; ++i)
            {
                palette[i] = (ushort)(bin.ReadUInt16() ^ 0x8000);
            }

            int start      = (int)bin.BaseStream.Position;
            int frameCount = bin.ReadInt32();

            int[] lookups = new int[frameCount];

            for (int i = 0; i < frameCount; ++i)
            {
                lookups[i] = start + bin.ReadInt32();
            }

            bool onlyHueGrayPixels = ((hue & 0x8000) == 0);

            hue = (hue & 0x3FFF) - 1;

            Hue hueObject = null;

            if (hue >= 0 && hue < Hues.List.Length)
            {
                hueObject = Hues.List[hue];
            }

            Frame[] frames = new Frame[frameCount];

            for (int i = 0; i < frameCount; ++i)
            {
                bin.BaseStream.Seek(lookups[i], SeekOrigin.Begin);
                frames[i] = new Frame(palette, bin, flip);

                if (hueObject != null)
                {
                    hueObject.ApplyTo(frames[i].Bitmap, onlyHueGrayPixels);
                }
            }

            return(frames);
        }
Example #16
0
        /// <summary>
        ///     Returns Framelist
        /// </summary>
        /// <param name="body"></param>
        /// <param name="action"></param>
        /// <param name="direction"></param>
        /// <param name="hue"></param>
        /// <param name="preserveHue">
        ///     No Hue override <see cref="bodydev" />
        /// </param>
        /// <param name="FirstFrame"></param>
        /// <returns></returns>
        public static Frame[] GetAnimation(
            int body, int action, int direction, ref int hue, bool preserveHue, bool FirstFrame)
        {
            if (preserveHue)
            {
                Translate(ref body);
            }
            else
            {
                Translate(ref body, ref hue);
            }

            int fileType = BodyConverter.Convert(ref body);

            FileIndex fileIndex;
            int       index;

            GetFileIndex(body, action, direction, fileType, out fileIndex, out index);

            int    length, extra;
            bool   patched;
            Stream stream = fileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }
            if (m_StreamBuffer == null || m_StreamBuffer.Length < length)
            {
                m_StreamBuffer = new byte[length];
            }
            stream.Read(m_StreamBuffer, 0, length);
            m_MemoryStream = new MemoryStream(m_StreamBuffer, false);

            bool flip = direction > 4;

            Frame[] frames;
            using (var bin = new BinaryReader(m_MemoryStream))
            {
                var palette = new ushort[0x100];

                for (int i = 0; i < 0x100; ++i)
                {
                    palette[i] = (ushort)(bin.ReadUInt16() ^ 0x8000);
                }

                var start      = (int)bin.BaseStream.Position;
                int frameCount = bin.ReadInt32();

                var lookups = new int[frameCount];

                for (int i = 0; i < frameCount; ++i)
                {
                    lookups[i] = start + bin.ReadInt32();
                }

                bool onlyHueGrayPixels = (hue & 0x8000) != 0;

                hue = (hue & 0x3FFF) - 1;

                Hue hueObject;

                if (hue >= 0 && hue < Hues.List.Length)
                {
                    hueObject = Hues.List[hue];
                }
                else
                {
                    hueObject = null;
                }

                if (FirstFrame)
                {
                    frameCount = 1;
                }
                frames = new Frame[frameCount];

                for (int i = 0; i < frameCount; ++i)
                {
                    bin.BaseStream.Seek(lookups[i], SeekOrigin.Begin);
                    frames[i] = new Frame(palette, bin, flip);

                    if (hueObject != null)
                    {
                        if (frames[i] != null)
                        {
                            if (frames[i].Bitmap != null)
                            {
                                hueObject.ApplyTo(frames[i].Bitmap, onlyHueGrayPixels);
                            }
                        }
                    }
                }
                bin.Close();
            }
            m_MemoryStream.Close();
            return(frames);
        }
        public static Frame[] GetAnimation(int body, int action, int direction, int hue, bool preserveHue)
        {
            if (preserveHue)
            {
                Animations.Translate(ref body);
            }
            else
            {
                Animations.Translate(ref body, ref hue);
            }
            FileIndex fileIndex;
            int       num1;

            switch (BodyConverter.Convert(ref body))
            {
            case 2:
                fileIndex = Animations.m_FileIndex2;
                num1      = body >= 200 ? 22000 + (body - 200) * 65 : body * 110;
                break;

            case 3:
                fileIndex = Animations.m_FileIndex3;
                num1      = body >= 300 ? (body >= 400 ? 35000 + (body - 400) * 175 : 33000 + (body - 300) * 110) : body * 65;
                break;

            default:
                fileIndex = Animations.m_FileIndex;
                num1      = body >= 200 ? (body >= 400 ? 35000 + (body - 400) * 175 : 22000 + (body - 200) * 65) : body * 110;
                break;
            }
            int    num2   = num1 + action * 5;
            int    index1 = direction > 4 ? num2 + (direction - (direction - 4) * 2) : num2 + direction;
            int    length1;
            int    extra;
            bool   patched;
            Stream input = fileIndex.Seek(index1, out length1, out extra, out patched);

            if (input == null)
            {
                return((Frame[])null);
            }
            bool         flip = direction > 4;
            BinaryReader bin  = new BinaryReader(input);

            ushort[] palette = new ushort[256];
            for (int index2 = 0; index2 < 256; ++index2)
            {
                palette[index2] = (ushort)((uint)bin.ReadUInt16() ^ 32768U);
            }
            int num3    = (int)bin.BaseStream.Position;
            int length2 = bin.ReadInt32();

            int[] numArray = new int[length2];
            for (int index2 = 0; index2 < length2; ++index2)
            {
                numArray[index2] = num3 + bin.ReadInt32();
            }
            bool onlyHueGrayPixels = (hue & 32768) == 0;

            hue = (hue & 16383) - 1;
            Hue hue1 = (Hue)null;

            if (hue >= 0 && hue < Hues.List.Length)
            {
                hue1 = Hues.List[hue];
            }
            Frame[] frameArray = new Frame[length2];
            for (int index2 = 0; index2 < length2; ++index2)
            {
                bin.BaseStream.Seek((long)numArray[index2], SeekOrigin.Begin);
                frameArray[index2] = new Frame(palette, bin, flip);
                if (hue1 != null)
                {
                    hue1.ApplyTo(frameArray[index2].Bitmap, onlyHueGrayPixels);
                }
            }
            return(frameArray);
        }
        public static Frame[] GetAnimation(int body, int action, int direction, int hue, bool preserveHue)
        {
            Ultima.FileIndex mFileIndex2;
            int  num;
            int  num1;
            int  num2;
            bool flag;

            if (!preserveHue)
            {
                Animations.Translate(ref body, ref hue);
            }
            else
            {
                Animations.Translate(ref body);
            }
            switch (BodyConverter.Convert(ref body))
            {
            case 2:
            {
                mFileIndex2 = Animations.m_FileIndex2;
                if (body >= 200)
                {
                    num = 22000 + (body - 200) * 65;
                    break;
                }
                else
                {
                    num = body * 110;
                    break;
                }
            }

            case 3:
            {
                mFileIndex2 = Animations.m_FileIndex3;
                if (body < 300)
                {
                    num = body * 65;
                    break;
                }
                else if (body >= 400)
                {
                    num = 35000 + (body - 400) * 175;
                    break;
                }
                else
                {
                    num = 33000 + (body - 300) * 110;
                    break;
                }
            }

            default:
            {
                mFileIndex2 = Animations.m_FileIndex;
                if (body < 200)
                {
                    num = body * 110;
                    break;
                }
                else if (body >= 400)
                {
                    num = 35000 + (body - 400) * 175;
                    break;
                }
                else
                {
                    num = 22000 + (body - 200) * 65;
                    break;
                }
            }
            }
            num = num + action * 5;
            num = (direction > 4 ? num + (direction - (direction - 4) * 2) : num + direction);
            Stream stream = mFileIndex2.Seek(num, out num1, out num2, out flag);

            if (stream == null)
            {
                return(null);
            }
            bool         flag1        = direction > 4;
            BinaryReader binaryReader = new BinaryReader(stream);

            ushort[] numArray = new ushort[256];
            for (int i = 0; i < 256; i++)
            {
                numArray[i] = (ushort)(binaryReader.ReadUInt16() ^ 32768);
            }
            int position = (int)binaryReader.BaseStream.Position;
            int num3     = binaryReader.ReadInt32();

            int[] numArray1 = new int[num3];
            for (int j = 0; j < num3; j++)
            {
                numArray1[j] = position + binaryReader.ReadInt32();
            }
            bool flag2 = (hue & 32768) == 0;

            hue = (hue & 16383) - 1;
            Hue list = null;

            if (hue >= 0 && hue < (int)Hues.List.Length)
            {
                list = Hues.List[hue];
            }
            Frame[] frame = new Frame[num3];
            for (int k = 0; k < num3; k++)
            {
                binaryReader.BaseStream.Seek((long)numArray1[k], SeekOrigin.Begin);
                frame[k] = new Frame(numArray, binaryReader, flag1);
                if (list != null)
                {
                    list.ApplyTo(frame[k].Bitmap, flag2);
                }
            }
            return(frame);
        }