Example #1
0
 public ItemStruct(ref FileStruct.TSAreaItem tsAreaItem)
 {
     this.resItem    = Utils.CharsToString(tsAreaItem.resItem).ToUpper();
     this.itemExpiry = tsAreaItem.itemExpiry;
     this.priCount   = tsAreaItem.priCount;
     this.secCount   = tsAreaItem.secCount;
     this.terCount   = tsAreaItem.terCount;
     this.flags      = tsAreaItem.flags;
 }
Example #2
0
        public static ResourceClass.IResource ReadQAREResourceFile(bool headerOnly,
                                                                   ChitinKey ckey, FileStream fileStream, int fileOffset, int fileSize)
        {
            ResourceClass.QAREFile areFile = new ResourceClass.QAREFile(ckey.name);

            #region Check file header

            buff = new byte[FileStruct.TSAreaHeaderSize];
            fileStream.Position = fileOffset;

            FileStruct.TSAreaHeader areHead =
                (FileStruct.TSAreaHeader)ReadBuffer <FileStruct.TSAreaHeader>
                    (fileStream, buff, FileStruct.TSAreaHeaderSize);

            if (GlobalDefs.RES_QARE_SIGNATURE != Utils.CharsToString(areHead.signature))
            {
                throw new ArgumentException("Warning: Invalid signature in *.are file.");
            }

            areFile.SetHeader(ref areHead);

            #endregion Check file header

            #region Load base area stuff

            // looks neat enough, but can consider writing subroutines for each arraylist

            // --- actor list --- //

            buff = new byte[FileStruct.TSAreaActorSize];
            fileStream.Position = areHead.actorsOffset + fileOffset;

            areFile.actorList = new ResourceClass.QAREFile.ActorStruct[areHead.actorsCount];
            for (int c = 0; c < areHead.actorsCount; c++)
            {
                FileStruct.TSAreaActor tsAreaActor =
                    (FileStruct.TSAreaActor)ReadBuffer <FileStruct.TSAreaActor>
                        (fileStream, buff, FileStruct.TSAreaActorSize);

                areFile.actorList[c] = ResourceClass.QAREFile.CreateActorStruct(ref tsAreaActor);
            }

            // --- infopt list --- //

            buff = new byte[FileStruct.TSAreaInfoptSize];
            fileStream.Position = areHead.infoptsOffset + fileOffset;

            areFile.infoptList = new ResourceClass.QAREFile.InfoptStruct[areHead.infoptsCount];
            for (int c = 0; c < areHead.infoptsCount; c++)
            {
                FileStruct.TSAreaInfopt tsAreaInfopt =
                    (FileStruct.TSAreaInfopt)ReadBuffer <FileStruct.TSAreaInfopt>
                        (fileStream, buff, FileStruct.TSAreaInfoptSize);

                areFile.infoptList[c] = ResourceClass.QAREFile.CreateInfoptStruct(ref tsAreaInfopt);
            }

            // --- spawn list --- //

            buff = new byte[FileStruct.TSAreaSpawnSize];
            fileStream.Position = areHead.spawnsOffset + fileOffset;

            areFile.spawnList = new ResourceClass.QAREFile.SpawnStruct[areHead.spawnsCount];
            for (int c = 0; c < areHead.spawnsCount; c++)
            {
                FileStruct.TSAreaSpawn tsAreaSpawn =
                    (FileStruct.TSAreaSpawn)ReadBuffer <FileStruct.TSAreaSpawn>
                        (fileStream, buff, FileStruct.TSAreaSpawnSize);

                areFile.spawnList[c] = ResourceClass.QAREFile.CreateSpawnStruct(ref tsAreaSpawn);
            }

            // --- entrance list --- //

            buff = new byte[FileStruct.TSAreaEntranceSize];
            fileStream.Position = areHead.entrancesOffset + fileOffset;

            areFile.entranceList = new ResourceClass.QAREFile.EntranceStruct[areHead.entrancesCount];
            for (int c = 0; c < areHead.entrancesCount; c++)
            {
                FileStruct.TSAreaEntrance tsAreaEntrance =
                    (FileStruct.TSAreaEntrance)ReadBuffer <FileStruct.TSAreaEntrance>
                        (fileStream, buff, FileStruct.TSAreaEntranceSize);

                areFile.entranceList[c] = ResourceClass.QAREFile.CreateEntranceStruct(ref tsAreaEntrance);
            }

            // --- item list --- //

            buff = new byte[FileStruct.TSAreaItemSize];
            fileStream.Position = areHead.itemsOffset + fileOffset;

            ResourceClass.QAREFile.ItemStruct[] itemList =
                new ResourceClass.QAREFile.ItemStruct[areHead.itemsCount];
            for (int c = 0; c < areHead.itemsCount; c++)
            {
                FileStruct.TSAreaItem tsAreaItem =
                    (FileStruct.TSAreaItem)ReadBuffer <FileStruct.TSAreaItem>
                        (fileStream, buff, FileStruct.TSAreaItemSize);

                itemList[c] = new ResourceClass.QAREFile.ItemStruct(ref tsAreaItem);
            }

            // --- container list --- //

            buff = new byte[FileStruct.TSAreaContainerSize];
            fileStream.Position = areHead.containersOffset + fileOffset;

            areFile.containerList = new ResourceClass.QAREFile.ContainerStruct[areHead.containersCount];
            for (int c = 0; c < areHead.containersCount; c++)
            {
                FileStruct.TSAreaContainer tsAreaContainer =
                    (FileStruct.TSAreaContainer)ReadBuffer <FileStruct.TSAreaContainer>
                        (fileStream, buff, FileStruct.TSAreaContainerSize);

                areFile.containerList[c] = ResourceClass.QAREFile.
                                           CreateContainerStruct(ref tsAreaContainer, ref itemList);
            }

            // --- vertex list --- //

            buff = new byte[FileStruct.TSAreaVerticeSize];
            fileStream.Position = areHead.verticesOffset + fileOffset;

            areFile.vertices = new XPoint[areHead.verticesCount];
            for (int c = 0; c < areHead.verticesCount; c++)
            {
                FileStruct.TSAreaVertice tsAreaVertice =
                    (FileStruct.TSAreaVertice)ReadBuffer <FileStruct.TSAreaVertice>
                        (fileStream, buff, FileStruct.TSAreaVerticeSize);

                areFile.vertices[c] = tsAreaVertice.vertex;
            }

            // --- ambient list --- //

            buff = new byte[FileStruct.TSAreaAmbientSize];
            fileStream.Position = areHead.ambientsOffset + fileOffset;

            areFile.ambientList = new ResourceClass.QAREFile.AmbientStruct[areHead.ambientsCount];
            for (int c = 0; c < areHead.ambientsCount; c++)
            {
                FileStruct.TSAreaAmbient tsAreaAmbient =
                    (FileStruct.TSAreaAmbient)ReadBuffer <FileStruct.TSAreaAmbient>
                        (fileStream, buff, FileStruct.TSAreaAmbientSize);

                areFile.ambientList[c] = ResourceClass.QAREFile.CreateAmbientStruct(ref tsAreaAmbient);
            }

            // --- variables list --- //

            buff = new byte[FileStruct.TSAreaVariableSize];
            fileStream.Position = areHead.variablesOffset + fileOffset;

            areFile.varList = new ResourceClass.QAREFile.VariableStruct[areHead.variablesCount];
            for (int c = 0; c < areHead.variablesCount; c++)
            {
                FileStruct.TSAreaVariable tsAreaVariable =
                    (FileStruct.TSAreaVariable)ReadBuffer <FileStruct.TSAreaVariable>
                        (fileStream, buff, FileStruct.TSAreaVariableSize);

                areFile.varList[c] = ResourceClass.QAREFile.CreateVariableStruct(ref tsAreaVariable);
            }

            // --- door list --- //

            buff = new byte[FileStruct.TSAreaDoorSize];
            fileStream.Position = areHead.doorsOffset + fileOffset;

            areFile.doorList = new ResourceClass.QAREFile.DoorStruct[areHead.doorsCount];
            for (int c = 0; c < areHead.doorsCount; c++)
            {
                FileStruct.TSAreaDoor tsAreaDoor =
                    (FileStruct.TSAreaDoor)ReadBuffer <FileStruct.TSAreaDoor>
                        (fileStream, buff, FileStruct.TSAreaDoorSize);

                areFile.doorList[c] = ResourceClass.QAREFile.CreateDoorStruct(ref tsAreaDoor);
            }

            // --- animation list --- //

            buff = new byte[FileStruct.TSAreaAnimationSize];
            fileStream.Position = areHead.animOffset + fileOffset;

            areFile.animList = new ResourceClass.QAREFile.AnimStruct[areHead.animCount];
            for (int c = 0; c < areHead.animCount; c++)
            {
                FileStruct.TSAreaAnimation tsAreaAnimation =
                    (FileStruct.TSAreaAnimation)ReadBuffer <FileStruct.TSAreaAnimation>
                        (fileStream, buff, FileStruct.TSAreaAnimationSize);

                areFile.animList[c] = ResourceClass.QAREFile.CreateAnimStruct(ref tsAreaAnimation);
            }

            // --- automap list --- //

            buff = new byte[FileStruct.TSAreaMapNoteSize];
            fileStream.Position = areHead.amapNotesOffset + fileOffset;

            areFile.mapNoteList = new ResourceClass.QAREFile.MapNoteStruct[areHead.amapNotesCount];
            for (int c = 0; c < areHead.amapNotesCount; c++)
            {
                FileStruct.TSAreaMapNote tsAreaMapNote =
                    (FileStruct.TSAreaMapNote)ReadBuffer <FileStruct.TSAreaMapNote>
                        (fileStream, buff, FileStruct.TSAreaMapNoteSize);

                areFile.mapNoteList[c] = ResourceClass.QAREFile.CreateMapNoteStruct(ref tsAreaMapNote);
            }

            // --- tiled list --- //

            buff = new byte[FileStruct.TSAreaTileSize];
            fileStream.Position = areHead.tileObjOffset + fileOffset;

            areFile.tileList = new ResourceClass.QAREFile.TileStruct[areHead.tileObjCount];
            for (int c = 0; c < areHead.tileObjCount; c++)
            {
                FileStruct.TSAreaTile tsAreaTile =
                    (FileStruct.TSAreaTile)ReadBuffer <FileStruct.TSAreaTile>
                        (fileStream, buff, FileStruct.TSAreaTileSize);

                areFile.tileList[c] = ResourceClass.QAREFile.CreateTileStruct(ref tsAreaTile);
            }

            // --- projectiles list --- //

            buff = new byte[FileStruct.TSAreaProjectileSize];
            fileStream.Position = areHead.projectilesOffset + fileOffset;

            areFile.projectileList = new ResourceClass.QAREFile.ProjectileStruct[areHead.projectilesCount];
            for (int c = 0; c < areHead.projectilesCount; c++)
            {
                FileStruct.TSAreaProjectile tsAreaProjectile =
                    (FileStruct.TSAreaProjectile)ReadBuffer <FileStruct.TSAreaProjectile>
                        (fileStream, buff, FileStruct.TSAreaProjectileSize);

                areFile.projectileList[c] = ResourceClass.QAREFile.CreateProjectileStruct(ref tsAreaProjectile);
            }

            #endregion Load single sections

            #region Load single sections

            buff = new byte[FileStruct.TSAreaSongSize];
            fileStream.Position = areHead.songOffset + fileOffset;

            FileStruct.TSAreaSong tsAreaSong =
                (FileStruct.TSAreaSong)ReadBuffer <FileStruct.TSAreaSong>
                    (fileStream, buff, FileStruct.TSAreaSongSize);

            areFile.song = ResourceClass.QAREFile.CreateSongStruct(ref tsAreaSong);

            buff = new byte[FileStruct.TSAreaAwakenSize];
            fileStream.Position = areHead.awakenOffset + fileOffset;

            FileStruct.TSAreaAwaken tsAreaAwaken =
                (FileStruct.TSAreaAwaken)ReadBuffer <FileStruct.TSAreaAwaken>
                    (fileStream, buff, FileStruct.TSAreaAwakenSize);

            areFile.awaken = ResourceClass.QAREFile.CreateAwakenStruct(ref tsAreaAwaken);

            #endregion

            fileStream.Close();

            return(areFile);
        }