protected override void OnWrite(VoidPtr address)
        {
            _rebuildAddr = address;

            *(buint*)address = v1._data;
            *(buint*)(address + 4) = v2._data;
        }
        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);
            }
        }
        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;
            }
        }
Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #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);
 }
        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);
        }
 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++];
 }
 public DataSource(FileMap map, CompressionType compression)
 {
     Address = map.Address;
     Length = map.Length;
     Map = map;
     Compression = compression;
 }
 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; }
     }
 }
Beispiel #16
0
        private LZ77()
        {
            _dataAddr = Marshal.AllocHGlobal((0x1000 + 0x10000 + 0x10000) * 2);

            _Next = (ushort*)_dataAddr;
            _First = _Next + WindowLength;
            _Last = _First + 0x10000;
        }
Beispiel #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++];
 }
 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;
        }
 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);
     }
 }
 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]) ;
 }
 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);
     }
 }
Beispiel #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]) ;
 }
 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);
        }
        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++));
        }
Beispiel #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));
 }
Beispiel #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;
        }
Beispiel #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;
        }
Beispiel #31
0
 public static extern VoidPtr MapViewOfFileEx(VoidPtr hFileMappingObject, _FileMapAccess dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, uint dwNumberOfBytesToMap, VoidPtr lpBaseAddress);
Beispiel #32
0
 public static extern bool FlushViewOfFile(VoidPtr lpBaseAddress, uint dwNumberOfBytesToFlush);
Beispiel #33
0
 public static extern VoidPtr CreateFileMapping(VoidPtr hFile, VoidPtr lpAttributes, _FileMapProtect flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
Beispiel #34
0
 public static extern void FillMemory(VoidPtr dest, uint length, byte value);
Beispiel #35
0
 public SafeHandle(VoidPtr handle)
 {
     this._handle = handle;
 }
Beispiel #36
0
 public static extern bool DuplicateHandle(VoidPtr hSourceProcessHandle, VoidPtr hSourceHandle, VoidPtr hTargetProcessHandle, out VoidPtr lpTargetHandle, uint dwDesiredAccess, bool bInheritHandle, uint dwOptions);
Beispiel #37
0
 public static extern bool CloseHandle(VoidPtr hObject);
Beispiel #38
0
 public SafeHandle(VoidPtr handle)
 {
     _handle = handle;
 }
Beispiel #39
0
 public static extern bool UnmapViewOfFile(VoidPtr lpBaseAddress);
 public UnsafeBuffer(int size)
 {
     _data = Marshal.AllocHGlobal(size); _length = size;
 }
Beispiel #41
0
 public static extern VoidPtr GetDC(VoidPtr hWnd);
Beispiel #42
0
 public static extern void MoveMemory(VoidPtr dest, VoidPtr src, uint size);
Beispiel #43
0
 public static extern int ReleaseDC(VoidPtr hWnd, VoidPtr hDC);