private static unsafe void LoadColors() { Debug.TimeBlock("Initializing Radar"); GRadar.m_Colors = new short[81920]; byte[] buffer = new byte[163840]; Stream stream = Engine.FileManager.OpenMUL("RadarCol.mul"); UnsafeMethods.ReadFile((FileStream)stream, buffer, 0, buffer.Length); stream.Close(); fixed(byte *numPtr1 = buffer) fixed(short *numPtr2 = GRadar.m_Colors) { ushort *numPtr3 = (ushort *)numPtr1; ushort *numPtr4 = (ushort *)numPtr2; int num = 0; while (num++ < 81920) { *numPtr4++ = (ushort)((uint)*numPtr3++ | 32768U); } foreach (GraphicTranslation graphicTranslation in GraphicTranslators.Art.Table.Values) { if (graphicTranslation.UpdatedId < 16384 && graphicTranslation.FallbackId < 16384) { numPtr2[graphicTranslation.UpdatedId] = numPtr2[graphicTranslation.FallbackId]; } } } Debug.EndBlock(); }
public unsafe TextureArt() { this.m_Lookup = new int[16384]; Stream stream = Engine.FileManager.OpenMUL(Files.TexIdx); byte[] buffer = new byte[196608]; UnsafeMethods.ReadFile((FileStream)stream, buffer, 0, buffer.Length); stream.Close(); fixed(byte *numPtr = buffer) { int index = 0; do { var localPtr = numPtr; m_Lookup[index] = *(int *)localPtr | ((int *)localPtr)[2] << 31; *(int *)localPtr += 3; }while (++index < 16384); } foreach (GraphicTranslation graphicTranslation in GraphicTranslators.Textures.Table.Values) { if (graphicTranslation.FallbackId < 16384 && graphicTranslation.UpdatedId < 16384) { this.m_Lookup[graphicTranslation.UpdatedId] = this.m_Lookup[graphicTranslation.FallbackId]; } } this.m_Stream = Engine.FileManager.OpenMUL(Files.TexMul); }
public static unsafe void LoadSpeechTable() { string path = Engine.FileManager.ResolveMUL("Speech.mul"); if (!File.Exists(path)) { Speech.m_Speech = new SpeechEntry[0]; Debug.Trace("File '{0}' not found, speech will not be encoded.", (object)path); } else { fixed(byte *numPtr = new byte[1024]) { ArrayList arrayList = new ArrayList(); FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); while (UnsafeMethods.ReadFile(file, (void *)numPtr, 4) > 0) { int idKeyword = (int)numPtr[1] | (int)numPtr[0] << 8; int num = (int)numPtr[3] | (int)numPtr[2] << 8; if (num > 0) { UnsafeMethods.ReadFile(file, (void *)numPtr, num); arrayList.Add((object)new SpeechEntry(idKeyword, new string((sbyte *)numPtr, 0, num))); } } file.Close(); Speech.m_Speech = (SpeechEntry[])arrayList.ToArray(typeof(SpeechEntry)); } } }
public unsafe LightReader() { this.index = new Entry3D[100]; fixed(Entry3D *entry3DPtr = this.index) { using (FileStream file = (FileStream)Engine.FileManager.OpenMUL(Files.LightIdx)) UnsafeMethods.ReadFile(file, (void *)entry3DPtr, 1200); } this.dataStream = Engine.FileManager.OpenMUL(Files.LightMul); }
protected override unsafe void CoreProcessImage(int width, int height, int stride, ushort *pLine, ushort *pLineEnd, ushort *pImageEnd, int lineDelta, int lineEndDelta) { int num = this.m_Textures.m_Lookup[this.m_TextureID]; if (num == -1) { return; } int size = width * height * 2; this.m_Textures.m_Stream.Seek((long)(num & int.MaxValue), SeekOrigin.Begin); UnsafeMethods.ReadFile((FileStream)this.m_Textures.m_Stream, this.m_Buffer, 0, size); fixed(byte *numPtr = this.m_Buffer) this.m_Hue.CopyPixels((void *)numPtr, (void *)pLine, width * height); }
public unsafe UnicodeFont(int FontID) { this.m_FileName = string.Format("UniFont{0}.mul", FontID != 0 ? (object)FontID.ToString() : (object)""); this.m_FontID = FontID; this.m_Stream = Engine.FileManager.OpenMUL(this.m_FileName); this.m_Lookup = new int[65536]; fixed(int *numPtr = this.m_Lookup) UnsafeMethods.ReadFile((FileStream)this.m_Stream, (void *)numPtr, 262144); this.m_4Bytes = new byte[4]; this.m_Factories = new UnicodeFont.UnicodeFontFactory[16]; this.m_Cache = new FontCache[this.m_Factories.Length]; for (int flags = 0; flags < this.m_Factories.Length; ++flags) { this.m_Factories[flags] = new UnicodeFont.UnicodeFontFactory(this, flags); this.m_Cache[flags] = new FontCache((IFontFactory)this.m_Factories[flags]); } }
private unsafe ArrayList ReadFromDisk(int multiID) { BinaryReader binaryReader = new BinaryReader(Engine.FileManager.OpenMUL(Files.MultiIdx)); binaryReader.BaseStream.Seek((long)(multiID * 12), SeekOrigin.Begin); int num = binaryReader.ReadInt32(); int length1 = binaryReader.ReadInt32(); binaryReader.Close(); if (num == -1) { return(new ArrayList()); } Stream stream = Engine.FileManager.OpenMUL(Files.MultiMul); stream.Seek((long)num, SeekOrigin.Begin); byte[] buffer = new byte[length1]; UnsafeMethods.ReadFile((FileStream)stream, buffer, 0, buffer.Length); stream.Close(); int length2 = length1 / sizeof(MultiItem); MultiItem[] multiItemArray = new MultiItem[length2]; fixed(byte *numPtr = buffer) { MultiItem *multiItemPtr1 = (MultiItem *)numPtr; MultiItem *multiItemPtr2 = multiItemPtr1 + length2; fixed(MultiItem *multiItemPtr3 = multiItemArray) { MultiItem *multiItemPtr4 = multiItemPtr3; while (multiItemPtr1 < multiItemPtr2) { *multiItemPtr4++ = *multiItemPtr1++; } } } return(new ArrayList((ICollection)multiItemArray)); }
private unsafe HuedTile[][][] ReadStaticBlock(int x, int y) { BinaryReader binaryReader = this.m_IndexReader; Stream stream = this.m_Statics; if (binaryReader == null || stream == null) { return(this.m_EmptyStaticBlock); } binaryReader.BaseStream.Seek((long)((x * this.m_BlockHeight + y) * 12), SeekOrigin.Begin); int num = binaryReader.ReadInt32(); int size = binaryReader.ReadInt32(); if (num < 0 || size <= 0) { return(this.m_EmptyStaticBlock); } int count = size / 7; FileStream file = stream as FileStream; if (file != null) { fixed(StaticTile *staticTiles = new StaticTile[count]) { stream.Seek((long)num, SeekOrigin.Begin); UnsafeMethods.ReadFile(file, (void *)staticTiles, size); return(this.GetTilesFromBlock(staticTiles, count)); } } else { MemoryStream memoryStream = stream as MemoryStream; if (memoryStream == null) throw new NotSupportedException(); fixed(byte *numPtr = memoryStream.GetBuffer()) return(this.GetTilesFromBlock((StaticTile *)(numPtr + num), count)); } }
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(); }
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]; } } }
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)); }