コード例 #1
0
ファイル: Pointer.cs プロジェクト: Zax37/raymap
        public static Pointer GetPointerAtOffset(Pointer pointer)
        {
            MapLoader l   = MapLoader.Loader;
            Pointer   ptr = null;

            if (pointer.file.pointers.ContainsKey(pointer.offset))
            {
                ptr = pointer.file.pointers[pointer.offset];
                if (ptr.offset == 0)
                {
                    return(null);
                }
                return(ptr);
            }
            else if (pointer.file.allowUnsafePointers)
            {
                Reader reader = pointer.file.reader;
                Pointer.DoAt(ref reader, pointer, () => {
                    uint current_off      = (uint)(reader.BaseStream.Position);
                    uint value            = reader.ReadUInt32();
                    FileWithPointers file = pointer.file;
                    uint fileOff          = (uint)(current_off - file.baseOffset);

                    if (file.pointers.ContainsKey(fileOff))
                    {
                        ptr = file.pointers[fileOff];
                    }
                    else
                    {
                        if (value == 0 || value == 0xFFFFFFFF)
                        {
                            ptr = null;
                        }
                        else
                        {
                            ptr = file.GetUnsafePointer(value);
                        }
                    }
                });
                return(ptr);
            }
            return(null);
        }
コード例 #2
0
ファイル: Pointer.cs プロジェクト: icup321/raymap
        public static Pointer Read(Reader reader, bool allowMinusOne = false)
        {
            MapLoader        l           = MapLoader.Loader;
            uint             current_off = (uint)(reader.BaseStream.Position);
            Pointer          readFrom    = Pointer.Current(reader);
            uint             value       = reader.ReadUInt32();
            FileWithPointers file        = l.GetFileByReader(reader);

            if (file == null)
            {
                throw new PointerException("Reader wasn't recognized.", "Pointer.Read");
            }
            uint fileOff = (uint)(current_off - file.baseOffset);

            if (!file.pointers.ContainsKey(fileOff))
            {
                if (value == 0 || (allowMinusOne && value == 0xFFFFFFFF))
                {
                    return(null);
                }
                if (!l.allowDeadPointers && !file.allowUnsafePointers)
                {
                    throw new PointerException("Not a valid pointer at " + (Pointer.Current(reader) - 4) + ": " + value, "Pointer.Read");
                }
                if (file.allowUnsafePointers)
                {
                    Pointer ptr = file.GetUnsafePointer(value);
                    if (ptr == null)
                    {
                        throw new PointerException("Not a valid pointer at " + (Pointer.Current(reader) - 4) + ": " + value, "Pointer.Read");
                    }
                    return(LogPointer(ptr, readFrom, l));
                }
                return(null);
            }
            // Hack for R3GC US
            if (l.allowDeadPointers && file.name == "test" && file.pointers[fileOff].file.name == "fix")
            {
                return(null);
            }
            return(LogPointer(file.pointers[fileOff], readFrom, l));
        }