Пример #1
0
        public unsafe Font(int fid)
        {
            this.m_FontID = fid;
            this.m_Cache  = new FontCache((IFontFactory)this);
            this.m_Images = new FontImage[224];
            string cachePath = Font.GetCachePath();

            if (!File.Exists(cachePath))
            {
                string str = Engine.FileManager.BasePath("data/ultima/cache/fonts.uoi");
                if (File.Exists(str))
                {
                    try
                    {
                        File.Move(str, cachePath);
                    }
                    catch
                    {
                        File.Copy(str, cachePath, false);
                    }
                }
                else
                {
                    Font.Reformat();
                }
            }
            FileStream   file         = new FileStream(cachePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader binaryReader = new BinaryReader((Stream)file);

            if (DateTime.FromFileTime(binaryReader.ReadInt64()) != new FileInfo(Engine.FileManager.ResolveMUL(Files.Fonts)).LastWriteTime)
            {
                binaryReader.Close();
                Font.Reformat();
                file         = new FileStream(cachePath, FileMode.Open, FileAccess.Read, FileShare.None);
                binaryReader = new BinaryReader((Stream)file);
            }
            file.Seek((long)(12 + fid * 8), SeekOrigin.Begin);
            int num1 = binaryReader.ReadInt32();
            int size = binaryReader.ReadInt32();

            file.Seek((long)num1, SeekOrigin.Begin);
            if (Font.m_Buffer == null || size > Font.m_Buffer.Length)
            {
                Font.m_Buffer = new byte[size];
                fixed(byte *numPtr1 = Font.m_Buffer)
                {
                    UnsafeMethods.ReadFile(file, (void *)numPtr1, size);
                    byte *numPtr2 = numPtr1;

                    for (int index = 0; index < 224; ++index)
                    {
                        int xWidth  = (int)*numPtr2;
                        int yHeight = (int)numPtr2[1];
                        numPtr2 += 3;
                        FontImage fontImage = new FontImage(xWidth, yHeight);
                        int       num2      = fontImage.xDelta;
                        fixed(byte *numPtr3 = fontImage.xyPixels)
                        {
                            IntPtr localPtr = (IntPtr)numPtr3;
                            int    num3     = 0;

                            while (num3 < yHeight)
                            {
                                int   num4    = 0;
                                byte *numPtr4 = (byte *)localPtr;
                                for (; num4 < xWidth; ++num4)
                                {
                                    *numPtr4++ = *numPtr2++;
                                }
                                ++num3;
                                localPtr += num2;
                            }
                        }

                        this.m_Images[index] = fontImage;
                    }
                    int    length  = *(int *)numPtr2;
                    short *numPtr5 = (short *)(numPtr2 + 4);

                    this.m_Palette = new short[length];
                    for (int index = 0; index < length; ++index)
                    {
                        this.m_Palette[index] = *numPtr5++;
                    }
                }

                binaryReader.Close();
        }
Пример #2
0
            protected override unsafe void CoreProcessImage(int width, int height, int stride, ushort *pLine, ushort *pLineEnd, ushort *pImageEnd, int lineDelta, int lineEndDelta)
            {
                string str        = this.m_String;
                int    num1       = 0;
                int    num2       = 0;
                int    spaceWidth = this.m_Font.SpaceWidth;
                bool   flag1      = false;
                int    size       = width * height;

                byte[] numArray = UnicodeFont.UnicodeFontFactory.m_Buffer;
                if (numArray == null || size > numArray.Length)
                {
                    UnicodeFont.UnicodeFontFactory.m_Buffer = numArray = new byte[size];
                }
                bool flag2 = (this.m_Flags & 8) != 0;

                fixed(byte *buffer = numArray)
                {
                    UnsafeMethods.ZeroMemory(buffer, size);
                    for (int index1 = 0; index1 < str.Length; ++index1)
                    {
                        char c = str[index1];
                        switch (c)
                        {
                        case '\t':
                            flag1 = false;
                            num1 += 24;
                            break;

                        case '\n':
                        case '\r':
                            if (!flag1)
                            {
                                num1  = 0;
                                num2 += 18;
                                flag1 = true;
                                break;
                            }
                            break;

                        case ' ':
                            flag1 = false;
                            num1 += spaceWidth;
                            break;

                        default:
                            flag1 = false;
                            UnicodeFont.UnicodeFontFactory.CharacterBits character = this.GetCharacter(c, true);
                            if (num1 > 0)
                            {
                                ++num1;
                            }
                            int num3 = num1 + character.m_xOffset;
                            fixed(byte *numPtr1 = character.m_Bits)
                            {
                                IntPtr localPtr = (IntPtr)numPtr1;
                                byte * numPtr2  = buffer + ((num2 + 1 + character.m_yOffset) * width) + (num3 + 1 + character.m_xWidth - 1);
                                int    num4     = 32 - character.m_xWidth;
                                int    num5     = character.m_xWidth + 7 >> 3;
                                int    num6     = (num2 + 1 + character.m_yOffset) * width + (num3 + 1 + character.m_xWidth - 1);
                                int    num7     = 0;

                                while (num7 < character.m_yHeight)
                                {
                                    uint  num8    = *(uint *)localPtr;
                                    uint  num9    = (uint)(((int)num8 & (int)byte.MaxValue) << 24 | ((int)num8 & 65280) << 8 | (int)((num8 & 16711680U) >> 8) | (int)(num8 >> 24) & (int)byte.MaxValue) >> num4;
                                    byte *numPtr3 = numPtr2;
                                    int   index2  = num6;
                                    int   num10   = num3 + 1 + character.m_xWidth - 1;
                                    int   num11   = num2 + 1 + character.m_yOffset + num7;
                                    if (num11 > 0 && num11 + 1 < height)
                                    {
                                        if (flag2)
                                        {
                                            if (num10 + 1 < width)
                                            {
                                                while ((int)num9 != 0 && num10 > 0)
                                                {
                                                    if (((int)num9 & 1) != 0)
                                                    {
                                                        IntPtr num12 = (IntPtr)(numPtr3 - width);
                                                        int    num13 = (int)(byte)((uint)*(byte *)num12 | 128U);
                                                        *(sbyte *)num12 = (sbyte)num13;
                                                        IntPtr num14 = (IntPtr)(numPtr3 - 1);
                                                        int    num15 = (int)(byte)((uint)*(byte *)num14 | 128U);
                                                        *(sbyte *)num14 = (sbyte)num15;
                                                        *      numPtr3 = (byte)2;
                                                        IntPtr num16   = (IntPtr)(numPtr3 + 1);
                                                        int    num17   = (int)(byte)((uint)*(byte *)num16 | 128U);
                                                        *(sbyte *)num16 = (sbyte)num17;
                                                        IntPtr num18 = (IntPtr)(numPtr3 + width);
                                                        int    num19 = (int)(byte)((uint)*(byte *)num18 | 128U);
                                                        *(sbyte *)num18           = (sbyte)num19;
                                                        numArray[index2 - width] |= (byte)128;
                                                        numArray[index2 - 1]     |= (byte)128;
                                                        numArray[index2]          = (byte)2;
                                                        numArray[index2 + 1]     |= (byte)128;
                                                        numArray[index2 + width] |= (byte)128;
                                                    }
                                                    --numPtr3;
                                                    --index2;
                                                    --num10;
                                                    num9 >>= 1;
                                                }
                                            }
                                        }
                                        else if (num10 + 1 < width)
                                        {
                                            while ((int)num9 != 0 && num10 > 0)
                                            {
                                                if (((int)num9 & 1) != 0)
                                                {
                                                    *numPtr3 = (byte)2;
                                                    numArray[index2] = (byte)2;
                                                }
                                                --numPtr3;
                                                --index2;
                                                --num10;
                                                num9 >>= 1;
                                            }
                                        }
                                    }
                                    ++num7;
                                    numPtr2  += width;
                                    num6     += width;
                                    localPtr += num5;
                                }
                            }

                            num1 = num3 + character.m_xWidth;
                            break;
                        }
                    }
                    int   num20   = width;
                    int   num21   = height;
                    int   num22   = 0;
                    int   num23   = 0;
                    bool  flag3   = (this.m_Flags & 1) != 0;
                    byte *numPtr4 = buffer;

                    fixed(short *numPtr1 = UnicodeFont.m_Colors)
                    fixed(short *numPtr2 = UnicodeFont.m_HuedColors)
                    {
                        Hues.Default.CopyPixels((void *)(numPtr1 + 1), (void *)((ushort *)numPtr2 + 1), 32);
                        Hues.Default.CopyPixels((void *)(numPtr1 + 129), (void *)((ushort *)numPtr2 + 129), 32);
                        for (int index1 = 0; index1 < height; ++index1)
                        {
                            for (int index2 = 0; index2 < width; ++index2)
                            {
                                if ((int)*numPtr4 != 0)
                                {
                                    if (index2 < num20)
                                    {
                                        num20 = index2;
                                    }
                                    if (index2 > num22)
                                    {
                                        num22 = index2;
                                    }
                                    if (index1 < num21)
                                    {
                                        num21 = index1;
                                    }
                                    if (index1 > num23)
                                    {
                                        num23 = index1;
                                    }
                                }
                                if (flag3 && index1 % 18 == 15)
                                {
                                    *numPtr4 = (byte)16;
                                }
                                *pLine++ = ((ushort *)numPtr2)[*numPtr4++];
                            }
                            pLine += lineDelta;
                        }
                    }
                    this.m_xMin = num20;
                    this.m_yMin = num21;
                    this.m_xMax = num22;
                    this.m_yMax = num23;
                }
            }
Пример #3
0
        public unsafe Skills()
        {
            byte[] buffer1 = new byte[3072];
            Stream stream1 = Engine.FileManager.OpenMUL(Files.SkillIdx);

            UnsafeMethods.ReadFile((FileStream)stream1, buffer1, 0, 3072);
            stream1.Close();
            Stream stream2 = Engine.FileManager.OpenMUL(Files.SkillMul);

            byte[] buffer2 = new byte[stream2.Length];
            UnsafeMethods.ReadFile((FileStream)stream2, buffer2, 0, buffer2.Length);
            stream2.Close();
            fixed(byte *numPtr1 = buffer1)
            fixed(byte *numPtr2 = buffer2)
            {
                this.m_Skills = new Skill[256];
                int    id       = 0;
                IntPtr localPtr = new IntPtr(*(int *)numPtr1);

                while (id < 256)
                {
                    int num1 = localPtr.ToInt32();
                    if (num1 < 0)
                    {
                        localPtr += 3;
                        ++id;
                    }
                    else
                    {
                        byte *numPtr3 = numPtr2 + num1;
                        int   num2    = ((int *)localPtr)[1];
                        if (num2 < 1)
                        {
                            localPtr += 3;
                            ++id;
                        }
                        else
                        {
                            byte *        numPtr4 = numPtr3;
                            IntPtr        num3    = new IntPtr(1);
                            byte *        numPtr5 = numPtr4 + num3.ToInt64();
                            bool          action  = (int)*numPtr4 != 0;
                            StringBuilder stringBuilder;
                            if (num2 < 1)
                            {
                                stringBuilder = new StringBuilder();
                            }
                            else
                            {
                                int capacity = num2 - 1;
                                stringBuilder = new StringBuilder(capacity);
                                for (int index = 0; index < capacity && (int)numPtr5[index] != 0; ++index)
                                {
                                    stringBuilder.Append((char)numPtr5[index]);
                                }
                            }
                            this.m_Skills[id] = new Skill(id, action, stringBuilder.ToString());
                            localPtr         += 3;
                            ++id;
                        }
                    }
                }
            }
            string path = Engine.FileManager.ResolveMUL("SkillGrp.mul");

            if (File.Exists(path))
            {
                FileStream   fileStream   = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                BinaryReader binaryReader = new BinaryReader((Stream)fileStream);
                int          length       = binaryReader.ReadInt32();
                bool         flag         = false;
                if (length == -1)
                {
                    flag   = true;
                    length = binaryReader.ReadInt32();
                }
                this.m_Groups    = new SkillGroup[length];
                this.m_Groups[0] = new SkillGroup("Miscellaneous", 0);
                for (int groupID = 1; groupID < length; ++groupID)
                {
                    fileStream.Seek((long)((flag ? 8 : 4) + (groupID - 1) * (flag ? 34 : 17)), SeekOrigin.Begin);
                    StringBuilder stringBuilder = new StringBuilder(18);
                    if (flag)
                    {
                        int num;
                        while ((num = (int)binaryReader.ReadInt16()) != 0)
                        {
                            stringBuilder.Append((char)num);
                        }
                    }
                    else
                    {
                        int num;
                        while ((num = (int)binaryReader.ReadByte()) != 0)
                        {
                            stringBuilder.Append((char)num);
                        }
                    }
                    this.m_Groups[groupID] = new SkillGroup(stringBuilder.ToString(), groupID);
                }
                fileStream.Seek((long)((flag ? 8 : 4) + (length - 1) * (flag ? 34 : 17)), SeekOrigin.Begin);
                for (int index1 = 0; index1 < 256; ++index1)
                {
                    Skill skill = this.m_Skills[index1];
                    if (skill != null)
                    {
                        try
                        {
                            int index2 = binaryReader.ReadInt32();
                            skill.Group = this.m_Groups[index2];
                            skill.Group.Skills.Add((object)skill);
                        }
                        catch
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                binaryReader.Close();
            }
            else
            {
                this.m_Groups    = new SkillGroup[1];
                this.m_Groups[0] = new SkillGroup("Skills", 0);
                for (int index = 0; index < 256; ++index)
                {
                    this.m_Skills[index].Group = this.m_Groups[0];
                }
            }
        }
Пример #4
0
 public static unsafe int ReadFile(FileStream file, byte[] buffer, int offset, int size)
 {
     fixed(byte *numPtr = buffer)
     return(UnsafeMethods.ReadFile(file, (void *)(numPtr + offset), size));
 }