Esempio n. 1
0
        public static Pointer Read(Reader reader, bool allowMinusOne = false)
        {
            MapLoader        l           = MapLoader.Loader;
            uint             current_off = (uint)(reader.BaseStream.Position);
            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(ptr);
                }
                return(null);
            }
            // enable for R3GC_US: if (file.name == "test" && file.pointers[fileOff].file.name == "fix") return null;
            return(file.pointers[fileOff]);
        }
Esempio n. 2
0
        public static Matrix Read(Reader reader, Pointer offset)
        {
            MapLoader l = MapLoader.Loader;
            //l.print("MATRIX " + offset);
            UInt32 type = Settings.s.game != Settings.Game.R2Revolution ? reader.ReadUInt32() : 0; // 0x02: always at the start of a transformation matrix
            Matrix mat  = new Matrix(offset, type, new Matrix4x4(), null);

            if (Settings.s.engineVersion < Settings.EngineVersion.R3 && Settings.s.game != Settings.Game.R2Revolution)
            {
                Vector3 pos = Vector3.zero;

                if (Settings.s.platform != Settings.Platform.DC)
                {
                    pos = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                }
                mat.m.SetColumn(0, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), 0f));
                mat.m.SetColumn(1, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), 0f));
                mat.m.SetColumn(2, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), 0f));
                Matrix4x4 sclMatrix = new Matrix4x4();
                sclMatrix.SetColumn(0, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), Settings.s.platform == Settings.Platform.DC ? reader.ReadSingle() : 0f));
                sclMatrix.SetColumn(1, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), Settings.s.platform == Settings.Platform.DC ? reader.ReadSingle() : 0f));
                sclMatrix.SetColumn(2, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), Settings.s.platform == Settings.Platform.DC ? reader.ReadSingle() : 0f));
                if (Settings.s.platform == Settings.Platform.DC)
                {
                    pos = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                }

                mat.m.SetColumn(3, new Vector4(pos.x, pos.y, pos.z, 1f));
                sclMatrix.SetColumn(3, new Vector4(0, 0, 0, 1f));
                mat.SetScaleMatrix(sclMatrix);

                /*if (type != 4) {
                 *  transMatrix.SetColumn(0, rotColX);
                 *  transMatrix.SetColumn(1, rotColY);
                 *  transMatrix.SetColumn(2, rotColZ);
                 * } else {
                 *  transMatrix.SetColumn(0, sclColX);
                 *  transMatrix.SetColumn(1, sclColY);
                 *  transMatrix.SetColumn(2, sclColZ);
                 * }*/
            }
            else
            {
                if (Settings.s.platform == Settings.Platform.PS2 && Settings.s.game != Settings.Game.R2Revolution)
                {
                    Vector3 v = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                }
                mat.m.SetColumn(0, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
                mat.m.SetColumn(1, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
                mat.m.SetColumn(2, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
                mat.m.SetColumn(3, new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
                mat.v = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                /*mat.SetScaleMatrix(new Matrix4x4(
                 *      new Vector4(v.x, 0, 0, 0),
                 *      new Vector4(0,v.y, 0, 0),
                 *      new Vector4(0, 0, v.z, 0),
                 *      new Vector4(0, 0, 0, v.w)));*/
            }
            if (Settings.s.game == Settings.Game.R2Revolution)
            {
                mat.type = reader.ReadUInt32();
                // There's 0x8c more?
            }
            return(mat);
        }