Ejemplo n.º 1
0
        protected override void OnWrite(VoidPtr address)
        {
            _rebuildAddr = address;

            *(buint*)address = v1._data;
            *(buint*)(address + 4) = v2._data;
        }
Ejemplo n.º 2
0
        public override void OnRebuild(VoidPtr address, int length, bool force)
        {
            RWAR* header = (RWAR*)address;
            header->_header._version = 0x100;
            header->_header._tag = RWAR.Tag;
            header->_header.Endian = Endian.Big;
            header->_header._length = length;
            header->_header._firstOffset = 0x20;
            header->_header._numEntries = 2;
            header->_tableOffset = 0x20;

            RWARTableBlock* tabl = (RWARTableBlock*)(address + 0x20);
            tabl->_header._tag = RWARTableBlock.Tag;
            tabl->_header._length = (12 + Children.Count * 12).Align(0x20);
            tabl->_entryCount = (uint)Children.Count;

            header->_tableLength = tabl->_header._length;
            header->_dataOffset = 0x20 + header->_tableLength;

            RWARDataBlock* data = (RWARDataBlock*)(address + 0x20 + tabl->_header._length);
            data->_header._tag = RWARDataBlock.Tag;

            VoidPtr addr = (VoidPtr)data + 0x20;
            foreach (RWAVNode n in Children)
            {
                tabl->Entries[n.Index].waveFileRef = (uint)(addr - (VoidPtr)data);
                //Memory.Move(addr, n.WorkingSource.Address, (uint)n.WorkingSource.Length);
                n.MoveRaw(addr, n.WorkingUncompressed.Length);
                addr += (tabl->Entries[n.Index].waveFileSize = (uint)n.WorkingUncompressed.Length);
            }
            data->_header._length = (int)(addr - (VoidPtr)data);
            header->_dataLength = data->_header._length;
        }
 public DataSource(VoidPtr addr, int len, CompressionType compression)
 {
     Address = addr;
     Length = len;
     Map = null;
     Compression = compression;
 }
        public static void Expand(CompressionHeader* header, VoidPtr dstAddress, int dstLen)
        {
            uint total = 0;
            VoidPtr ceil = dstAddress + dstLen;

            if (header->Parameter != 1)
            {
                byte* pSrc = (byte*)header->Data;
                byte* pDst = (byte*)dstAddress;
                do
                {
                    total += *pSrc++;
                    *pDst++ = (byte)total;
                }
                while (pSrc < ceil);
            }
            else
            {
                bushort* pSrc = (bushort*)header->Data;
                bushort* pDst = (bushort*)dstAddress;
                do
                {
                    total += *pSrc++;
                    *pDst++ = (ushort)total;
                }
                while (pSrc < ceil);
            }
        }
Ejemplo n.º 5
0
        public static bool IsDataCompressed(VoidPtr addr, int length)
        {
            if (*(uint*)addr == YAZ0.Tag)
                return true;
            else
            {
                CompressionHeader* cmpr = (CompressionHeader*)addr;

                if (cmpr->ExpandedSize < length)
                    return false;

                if (!cmpr->HasLegitCompression())
                    return false;

                char[] chars = characters.ToCharArray();

                //Check to make sure we're not reading a tag
                byte* c = (byte*)addr;
                byte[] tag = { c[0], c[1], c[2], c[3] };
                if ((Array.IndexOf(chars, (char)tag[0]) >= 0) &&
                    (Array.IndexOf(chars, (char)tag[1]) >= 0) &&
                    (Array.IndexOf(chars, (char)tag[2]) >= 0) &&
                    (Array.IndexOf(chars, (char)tag[3]) >= 0))
                    return false;

                return true;
            }
        }
Ejemplo n.º 6
0
 protected override void DecodeBlock(VoidPtr blockAddr, ARGBPixel* dPtr, int width)
 {
     byte* sPtr = (byte*)blockAddr;
     byte b;
     if (_workingPalette != null)
     {
         for (int y = 0; y < BlockHeight; y++, dPtr += width)
             for (int x = 0; x < BlockWidth; )
             {
                 b = *sPtr++;
                 dPtr[x++] = (ARGBPixel)_workingPalette.Entries[b >> 4];
                 dPtr[x++] = (ARGBPixel)_workingPalette.Entries[b & 0xF];
             }
     }
     else
     {
         for (int y = 0; y < BlockHeight; y++, dPtr += width)
             for (int x = 0; x < BlockWidth; )
             {
                 b = *sPtr++;
                 dPtr[x++] = new ARGBPixel((byte)(b & 0xF0));
                 dPtr[x++] = new ARGBPixel((byte)(b << 4));
             }
     }
 }
 public static void DecodeFrames(KeyframeArray kf, VoidPtr offset, int flags, int fixedBit)
 {
     if ((flags & fixedBit) != 0)
         kf[0] = *(bfloat*)offset;
     else
         DecodeFrames(kf, offset + *(bint*)offset);
 }
 public void Close()
 {
     if (Map != null) { Map.Dispose(); Map = null; }
     Address = null;
     Length = 0;
     Compression = CompressionType.None;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Copies data from memory at a specific address into an array
 /// </summary>
 /// <param name="source"></param>
 /// <param name="sourceOffset"></param>
 /// <param name="target"></param>
 /// <param name="targetOffset"></param>
 /// <param name="Length"></param>
 public static byte[] GetArrayFromAddress(VoidPtr Address, int length)
 {
     byte[] arr = new byte[length];
     for (int i = 0; i < length; i++)
         arr[i] = *(byte*)(Address + i);
     return arr;
 }
 public static void DecodeFrames(KeyframeArray kf, VoidPtr dataAddr)
 {
     SCN0KeyframesHeader* header = (SCN0KeyframesHeader*)dataAddr;
     SCN0KeyframeStruct* entry = header->Data;
     for (int i = 0; i < header->_numFrames; i++, entry++)
         kf.SetFrameValue((int)entry->_index, entry->_value)._tangent = entry->_tangent;
 }
Ejemplo n.º 11
0
 internal static unsafe SafeHandle Duplicate(VoidPtr hFile)
 {
     VoidPtr hProc = Process.GetCurrentProcess().Handle;
     if (!DuplicateHandle(hProc, hFile, hProc, out hFile, 0, false, 2))
         Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
     return new SafeHandle(hFile);
 }
Ejemplo n.º 12
0
        public override void Parse(VoidPtr address)
        {
            MoveDefLookupOffsetNode o;
            bint* addr = First;
            VoidPtr current = BaseAddress + *addr++;
            VoidPtr next = BaseAddress + *addr++;
            int size = 0;
            for (int i = 1; i < Count; i++)
            {
                size = (int)next - (int)current;
                (o = new MoveDefLookupOffsetNode()).Initialize(this, current, size);
                if (_root._lookupSizes.ContainsKey(o.DataOffset))
                    if (_root._lookupSizes[o.DataOffset].DataSize < o.DataSize)
                        _root._lookupSizes[o.DataOffset] = o;
                    else { }
                else
                    _root._lookupSizes.Add(o.DataOffset, o);
                current = next;
                next = BaseAddress + *addr++;
            }
            size = ((int)_offset - (int)(current - BaseAddress));
            (o = new MoveDefLookupOffsetNode()).Initialize(this, current, size);

            if (!_root._lookupSizes.ContainsKey(o.DataOffset))
                _root._lookupSizes.Add(o.DataOffset, o);

            //Sorting by data offset will allow us to get the exact size of every entry!
            Children.Sort(MoveDefLookupOffsetNode.LookupCompare);
        }
Ejemplo n.º 13
0
 protected override void EncodeBlock(ARGBPixel* sPtr, VoidPtr blockAddr, int width)
 {
     wRGB5A3Pixel* dPtr = (wRGB5A3Pixel*)blockAddr;
     for (int y = 0; y < BlockHeight; y++, sPtr += width)
         for (int x = 0; x < BlockWidth; )
             *dPtr++ = (wRGB5A3Pixel)sPtr[x++];
 }
Ejemplo n.º 14
0
 public DataSource(FileMap map, CompressionType compression)
 {
     Address = map.Address;
     Length = map.Length;
     Map = map;
     Compression = compression;
 }
Ejemplo n.º 15
0
 internal static unsafe void Fill(VoidPtr dest, uint length, byte value)
 {
     switch (Environment.OSVersion.Platform)
     {
         case PlatformID.Win32NT: { Win32.FillMemory(dest, length, value); break; }
         case PlatformID.Unix: { Linux.memset(dest, value, length); break; }
     }
 }
Ejemplo n.º 16
0
        private LZ77()
        {
            _dataAddr = Marshal.AllocHGlobal((0x1000 + 0x10000 + 0x10000) * 2);

            _Next = (ushort*)_dataAddr;
            _First = _Next + WindowLength;
            _Last = _First + 0x10000;
        }
Ejemplo n.º 17
0
 protected override void EncodeBlock(ARGBPixel* sPtr, VoidPtr blockAddr, int width)
 {
     byte* stPtr = (byte*)sPtr;
     byte* dPtr = (byte*)blockAddr;
     for (int y = 0; y < BlockHeight; y++, stPtr += width)
         for (int x = 0; x < BlockWidth; )
             *dPtr++ = stPtr[x++];
 }
Ejemplo n.º 18
0
 protected override void DecodeBlock(VoidPtr blockAddr, ARGBPixel* dPtr, int width)
 {
     wRGB5A3Pixel* sPtr = (wRGB5A3Pixel*)blockAddr;
     //ARGBPixel* dPtr = (ARGBPixel*)destAddr;
     for (int y = 0; y < BlockHeight; y++, dPtr += width)
         for (int x = 0; x < BlockWidth; )
             dPtr[x++] = (ARGBPixel)(*sPtr++);
 }
        protected override void OnWrite(VoidPtr address)
        {
            VoidPtr addr = address;
            foreach (ArticleEntry b in Children)
            {
                b._buildHeader = false;
                b.Rebuild(addr, b._childLength, true);
                addr += b._childLength;
            }

            VoidPtr start = addr;
            foreach (ArticleEntry b in Children)
            {
                b._rebuildAddr = addr;

                Article* article = (Article*)addr;

                article->_id = b.id;
                article->_boneID = b.charBone;
                article->_arcGroup = b.articleBone;

                article->_actionsStart = b.aStart;
                article->_actionFlagsStart = b.aFlags;
                article->_subactionFlagsStart = b.sFlags;
                article->_subactionMainStart = b.sMStart;
                article->_subactionGFXStart = b.sGStart;
                article->_subactionSFXStart = b.sSStart;
                article->_modelVisibility = b.visStart;
                article->_collisionData = b.off1;
                article->_unknownD2 = b.off2;
                article->_unknownD3 = b.off3;

                bint* ext = (bint*)((VoidPtr)article + 52);
                ext[0] = (b._subActions == null ? 0 : b._subActions.Children.Count);

                //Add all header offsets
                bint* off = (bint*)(addr + 12);
                for (int i = 0; i < 10 + b._extraOffsets.Count; i++)
                    if (off[i] > 1480 && off[i] < _root.dataSize)
                        b._lookupOffsets.Add(&off[i]);

                _lookupOffsets.AddRange(b._lookupOffsets);

                addr += b._entryLength;
            }

            FDefListOffset* header = (FDefListOffset*)addr;

            _rebuildAddr = header;

            if (Children.Count > 0)
            {
                header->_startOffset = (int)start - (int)RebuildBase;
                _lookupOffsets.Add(header->_startOffset.Address);
            }

            header->_listCount = Children.Count;
        }
Ejemplo n.º 20
0
 public static unsafe void Compact(CompressionType type, VoidPtr srcAddr, int srcLen, Stream outStream, ResourceNode r)
 {
     switch (type)
     {
         case CompressionType.LZ77: { LZ77.Compact(srcAddr, srcLen, outStream, r, false); break; }
         case CompressionType.ExtendedLZ77: { LZ77.Compact(srcAddr, srcLen, outStream, r, true); break; }
         case CompressionType.RunLength: { RunLength.Compact(srcAddr, srcLen, outStream, r); break; }
     }
 }
 public override void Parse(VoidPtr address)
 {
     VoidPtr addr = BaseAddress + DataOffset;
     for (int i = 0; i < Count; i++)
     {
         ArticleEntry d = new ArticleEntry() { Static = true };
         d.Initialize(this, addr + i * 56, 56);
     }
 }
Ejemplo n.º 22
0
 public static void Expand(VoidPtr srcAddress, VoidPtr dstAddress, int dstLen)
 {
     for (byte* srcPtr = (byte*)srcAddress, dstPtr = (byte*)dstAddress, ceiling = dstPtr + dstLen; dstPtr < ceiling; )
         for (byte control = *srcPtr++, bit = 8; (bit-- != 0) && (dstPtr != ceiling); )
             if ((control & (1 << bit)) != 0)
                 *dstPtr++ = *srcPtr++;
             else
                 for (int b1 = *srcPtr++, b2 = *srcPtr++, offset = ((b1 & 0xF) << 8 | b2) + 2, temp = (b1 >> 4) & 0xF, num = temp == 0 ? *srcPtr++ + 0x12 : temp + 2; num-- > 0 && dstPtr != ceiling; *dstPtr++ = dstPtr[-offset]) ;
 }
Ejemplo n.º 23
0
 public static void BuildData2(MoveDefDataNode node, MovesetHeader* header, VoidPtr address, int length, bool force)
 {
     VoidPtr addr = address;
     foreach (MoveDefEntryNode e in MoveDefNode.nodeDictionary.Values)
     {
         if (e.External && !(e._extNode is MoveDefReferenceEntryNode)) continue;
         e.Rebuild(addr, e._calcSize, true);
     }
 }
Ejemplo n.º 24
0
 public static void Expand(VoidPtr data, VoidPtr dstAddress, int dstLen, bool extFmt)
 {
     for (byte* srcPtr = (byte*)data, dstPtr = (byte*)dstAddress, ceiling = dstPtr + dstLen; dstPtr < ceiling; )
         for (byte control = *srcPtr++, bit = 8; (bit-- != 0) && (dstPtr != ceiling); )
             if ((control & (1 << bit)) == 0)
                 *dstPtr++ = *srcPtr++;
             else
                 for (int temp = (*srcPtr >> 4), num = !extFmt ? temp + 3 : temp == 1 ? (((*srcPtr++ & 0x0F) << 12) | ((*srcPtr++) << 4) | (*srcPtr >> 4)) + 0xFF + 0xF + 3 : temp == 0 ? (((*srcPtr++ & 0x0F) << 4) | (*srcPtr >> 4)) + 0xF + 2 : temp + 1, offset = (((*srcPtr++ & 0xF) << 8) | *srcPtr++) + 2; dstPtr != ceiling && num-- > 0; *dstPtr++ = dstPtr[-offset]) ;
 }
Ejemplo n.º 25
0
 public void Dispose()
 {
     if (_data)
     {
         Marshal.FreeHGlobal(_data);
         _data = null;
         GC.SuppressFinalize(this);
     }
 }
        public static void Write(this Stream stream, VoidPtr srcAddr, int length)
        {
            byte[] arr = new byte[length];

            fixed (byte* ptr = arr)
                System.Memory.Move(ptr, srcAddr, (uint)length);

            stream.Write(arr, 0, length);
        }
Ejemplo n.º 27
0
        public override void Parse(VoidPtr address)
        {
            base.Parse(address);

            _indices = new List<IndexValue>();
            bint* entry = (bint*)(BaseAddress + DataOffset);
            for (int i = 0; i < Count; i++)
                _indices.Add(Parse<IndexValue>(entry++));
        }
Ejemplo n.º 28
0
 protected override void EncodeBlock(ARGBPixel* sPtr, VoidPtr blockAddr, int width)
 {
     byte* stPtr = (byte*)sPtr;
     byte* dPtr = (byte*)blockAddr;
     for (int y = 0; y < BlockHeight; y++, stPtr += width / 2)
         for (int x = 0; x < BlockWidth / 2; )
             *dPtr++ = stPtr[x++];
             //*dPtr++ = (byte)((_workingPalette.FindMatch(sPtr[x++]) << 4) | (_workingPalette.FindMatch(sPtr[x++]) & 0x0F));
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Retrieves an 32 bit integer from the specified address.
        /// </summary>
        /// <param name="Address"></param>
        /// <param name="endian"></param>
        /// <returns></returns>
        public static int GetWordUnsafe(VoidPtr Address, Endianness endian)
        {
            if (Address % 4 != 0)
                return 0;

            if (endian == Endianness.Big)
                return *(bint*)Address;
            else
                return *(int*)Address;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Gets a floating point value from a specified adress.
        /// </summary>
        /// <param name="Address"></param>
        /// <param name="endian"></param>
        /// <returns></returns>
        public static float GetFloatUnsafe(VoidPtr Address, Endianness endian)
        {
            if (Address % 4 != 0)
                return 0;

            if (endian == Endianness.Big)
                return *(bfloat*)Address;
            else
                return *(float*)Address;
        }
Ejemplo n.º 31
0
 public static extern VoidPtr MapViewOfFileEx(VoidPtr hFileMappingObject, _FileMapAccess dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, uint dwNumberOfBytesToMap, VoidPtr lpBaseAddress);
Ejemplo n.º 32
0
 public static extern bool FlushViewOfFile(VoidPtr lpBaseAddress, uint dwNumberOfBytesToFlush);
Ejemplo n.º 33
0
 public static extern VoidPtr CreateFileMapping(VoidPtr hFile, VoidPtr lpAttributes, _FileMapProtect flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
Ejemplo n.º 34
0
 public static extern void FillMemory(VoidPtr dest, uint length, byte value);
Ejemplo n.º 35
0
 public SafeHandle(VoidPtr handle)
 {
     this._handle = handle;
 }
Ejemplo n.º 36
0
 public static extern bool DuplicateHandle(VoidPtr hSourceProcessHandle, VoidPtr hSourceHandle, VoidPtr hTargetProcessHandle, out VoidPtr lpTargetHandle, uint dwDesiredAccess, bool bInheritHandle, uint dwOptions);
Ejemplo n.º 37
0
 public static extern bool CloseHandle(VoidPtr hObject);
Ejemplo n.º 38
0
 public SafeHandle(VoidPtr handle)
 {
     _handle = handle;
 }
Ejemplo n.º 39
0
 public static extern bool UnmapViewOfFile(VoidPtr lpBaseAddress);
Ejemplo n.º 40
0
 public UnsafeBuffer(int size)
 {
     _data = Marshal.AllocHGlobal(size); _length = size;
 }
Ejemplo n.º 41
0
 public static extern VoidPtr GetDC(VoidPtr hWnd);
Ejemplo n.º 42
0
 public static extern void MoveMemory(VoidPtr dest, VoidPtr src, uint size);
Ejemplo n.º 43
0
 public static extern int ReleaseDC(VoidPtr hWnd, VoidPtr hDC);