Exemple #1
0
 public FATEntry GetEntry(FATEntry.Type type, ushort index)
 {
     if (!entriesDict.ContainsKey(type) || !entriesDict[type].ContainsKey(index))
     {
         return(null);
     }
     return(entriesDict[type][index]);
 }
Exemple #2
0
 private void AddEntryToDict(FATEntry entry)
 {
     FATEntry.Type entryType = entry.EntryType;
     if (!entriesDict.ContainsKey(entryType))
     {
         entriesDict[entryType] = new Dictionary <ushort, FATEntry>();
     }
     entriesDict[entryType][entry.index] = entry;
 }
Exemple #3
0
        public Pointer GetStructPtr(FATEntry.Type type, ushort index, bool global = false)
        {
            FATEntry entry = GetEntry(type, index, global: global);

            if (entry != null)
            {
                return(new Pointer(entry.off_data, files_array[SMem.Data]));
            }
            else
            {
                return(null);
            }
        }
Exemple #4
0
        public T GetOrRead <T>(Reader reader, ushort index, Action <T> onPreRead = null) where T : ROMStruct, new()
        {
            T rs = Get <T>(index);

            if (rs == null)
            {
                if (index != 0xFFFF)
                {
                    FATEntry.Type type   = FATEntry.types[typeof(T)];
                    Pointer       offset = null;
                    // For some reason, this type receives special treatment
                    if (type == FATEntry.Type.EntryAction &&
                        ((index & (ushort)FATEntry.Flag.Fix) != (ushort)FATEntry.Flag.Fix))
                    {
                        ushort fixIndex = (ushort)(index | (ushort)FATEntry.Flag.Fix);
                        offset = GetStructPtr(type, fixIndex);
                        if (offset != null)
                        {
                            index = fixIndex;
                        }
                    }
                    if (offset == null)
                    {
                        offset = GetStructPtr(type, index);
                    }
                    if (offset != null)
                    {
                        if (!romStructs.ContainsKey(type))
                        {
                            romStructs[type] = new Dictionary <ushort, ROMStruct>();
                        }
                        if (!romStructs[type].ContainsKey(index))
                        {
                            rs = new T();
                            rs.Init(offset, index);
                            romStructs[type][index] = rs;
                            onPreRead?.Invoke(rs);
                            rs.Read(reader);
                        }
                        else
                        {
                            Debug.LogWarning("Duplicate index " + index + " for type " + type);
                        }
                    }
                }
            }
            return(rs);
        }
Exemple #5
0
 public T Get <T>(ushort index) where T : ROMStruct
 {
     FATEntry.Type type = FATEntry.types[typeof(T)];
     // Special treatment for EntryActions
     if (type == FATEntry.Type.EntryAction &&
         ((index & (ushort)FATEntry.Flag.Fix) != (ushort)FATEntry.Flag.Fix))
     {
         ushort ind = (ushort)(index | (ushort)FATEntry.Flag.Fix);
         if (romStructs.ContainsKey(type) && romStructs[type].ContainsKey(ind))
         {
             return(romStructs[type][ind] as T);
         }
     }
     if (!romStructs.ContainsKey(type) || !romStructs[type].ContainsKey(index))
     {
         return(null);
     }
     return(romStructs[type][index] as T);
 }
Exemple #6
0
        public Type Resolve(Reader reader)
        {
            if (this.type == 0xFFFF)
            {
                return(null);
            }
            R2ROMLoader l = MapLoader.Loader as R2ROMLoader;

            FATEntry.Type entryType = FATEntry.GetEntryType(this.type);
            System.Type   type      = null;
            foreach (KeyValuePair <System.Type, FATEntry.Type> typePair in FATEntry.types)
            {
                if (typePair.Value == entryType)
                {
                    type = typePair.Key;
                    break;
                }
            }
            ushort index = forceFix ? (ushort)(this.index | (ushort)FATEntry.Flag.Fix) : this.index;

            switch (entryType)
            {
            case FATEntry.Type.GeometricElementTriangles:
                Value = l.GetOrRead <GeometricObjectElementTriangles>(reader, index);
                break;

            case FATEntry.Type.GeometricElementSprites:
                Value = l.GetOrRead <GeometricObjectElementSprites>(reader, index);
                break;

            case FATEntry.Type.VisualMaterial:
                Value = l.GetOrRead <VisualMaterial>(reader, index);
                break;

            case FATEntry.Type.GeometricElementCollideTriangles:
                Value = l.GetOrRead <GeometricObjectElementCollideTriangles>(reader, index);
                break;

            case FATEntry.Type.GeometricElementCollideAlignedBoxes:
                Value = l.GetOrRead <GeometricObjectElementCollideAlignedBoxes>(reader, index);
                break;

            case FATEntry.Type.GeometricElementCollideSpheres:
                Value = l.GetOrRead <GeometricObjectElementCollideSpheres>(reader, index);
                break;

            case FATEntry.Type.GameMaterial:
                Value = l.GetOrRead <GameMaterial>(reader, index);
                break;

            case FATEntry.Type.PhysicalObject:
                Value = l.GetOrRead <PhysicalObject>(reader, index);
                break;

            case FATEntry.Type.Sector:
                Value = l.GetOrRead <Sector>(reader, index);
                break;

            default:
                UnityEngine.Debug.LogWarning("GenericReference: Unsupported struct with type " + entryType + "(" + this.type + ")");
                break;
            }
            return(type);
        }
Exemple #7
0
        public FATEntry GetEntry(FATEntry.Type type, ushort index, bool global = false)
        {
            bool   isFix = (index & (ushort)FATEntry.Flag.Fix) == (ushort)FATEntry.Flag.Fix;
            ushort ind   = (ushort)(index & 0x7FFF);

            if (!global)
            {
                if (!isFix)
                {
                    FATEntry levelEntry = fatTables[CurrentLevel + 2].GetEntry(type, ind);
                    if (levelEntry != null)
                    {
                        return(levelEntry);
                    }

                    FATEntry fix2Entry = fatTables[1].GetEntry(type, ind);
                    if (fix2Entry != null)
                    {
                        return(fix2Entry);
                    }
                }
                else
                {
                    FATEntry fixEntry = fatTables[0].GetEntry(type, ind);
                    if (fixEntry != null)
                    {
                        return(fixEntry);
                    }
                }
            }
            else
            {
                FATEntry levelEntry = fatTables[CurrentLevel + 2].GetEntry(type, ind);
                if (levelEntry != null)
                {
                    return(levelEntry);
                }

                FATEntry fix2Entry = fatTables[1].GetEntry(type, ind);
                if (fix2Entry != null)
                {
                    return(fix2Entry);
                }

                FATEntry fixEntry = fatTables[0].GetEntry(type, ind);
                if (fixEntry != null)
                {
                    return(fixEntry);
                }

                for (int i = 2; i < fatTables.Length; i++)
                {
                    if (i == CurrentLevel + 2)
                    {
                        continue;
                    }
                    FATEntry entry = fatTables[i].GetEntry(type, ind);
                    if (entry != null)
                    {
                        return(entry);
                    }
                }
            }

            return(null);
        }