예제 #1
0
        public MapChr Clone()
        {
            MapChr mc = new MapChr();

            if (bImageAvailable)
            {
                // copy actual chr data
                mc.bImageAvailable = this.bImageAvailable;
                mc.FrameWidth      = this.FrameWidth;
                mc.FrameHeight     = this.FrameHeight;
                mc.HotspotX        = this.HotspotX;
                mc.HotspotY        = this.HotspotY;
                mc.HotspotWidth    = this.HotspotWidth;
                mc.HotspotHeight   = this.HotspotHeight;
                mc.FrameCount      = this.FrameCount;
                mc.ImageData       = (byte[])this.ImageData.Clone();
                mc.IdleFrameDown   = this.IdleFrameDown;
                mc.IdleFrameLeft   = this.IdleFrameLeft;
                mc.IdleFrameUp     = this.IdleFrameUp;
                mc.IdleFrameRight  = this.IdleFrameRight;
                for (int i = 0; i < 4; i++)
                {
                    mc.MoveScripts[i] = string.Copy(this.MoveScripts[i]);
                }
            }
            // copy map relevant info
            //mc.ID = this.ID;
            //mc.Name = this.Name;
            return(mc);
        }
예제 #2
0
        /// <summary>
        /// loads the data from 'fi' into 'chr'.
        /// </summary>
        /// <returns>-1 on failure, 0 on success</returns>
        public static int ReadCHR(FileInfo fi, MapChr chr)
        {
            if (!fi.Exists) return -1;

            FileStream fs = fi.OpenRead();
            BinaryReader br = new BinaryReader(fs);

            // pump the file into a memory stream
            int length = (int)fs.Length;

            MemoryStream ms = new MemoryStream(br.ReadBytes(length));

            br.Close();
            br = new BinaryReader(ms);

            byte version = br.ReadByte();

            if (version != 2)
            {
                Errors.Error("ReadChr", "INPUTOUTPUT::READCHR(): INCORRECT FILE VERSION");
                return -1;
            }

            chr.FrameWidth = (int)br.ReadInt16();
            chr.FrameHeight = (int)br.ReadInt16();

            chr.HotspotX = (int)br.ReadInt16();
            chr.HotspotY = (int)br.ReadInt16();

            chr.HotspotWidth = (int)br.ReadInt16();
            chr.HotspotHeight = (int)br.ReadInt16();

            chr.FrameCount = (int)br.ReadInt16();

            int CompressedLength = br.ReadInt32();
            chr.ImageData = DecompressData8(br.ReadBytes(CompressedLength));

            chr.IdleFrameLeft = (int)br.ReadInt32();
            chr.IdleFrameRight = (int)br.ReadInt32();
            chr.IdleFrameUp = (int)br.ReadInt32();
            chr.IdleFrameDown = (int)br.ReadInt32();

            for (int i = 0; i < 4; i++)
            {
                int msLength = br.ReadInt32();
                chr.MoveScripts[i] = Helper.BytesToString(br.ReadBytes(msLength));
            }

            br.Close();
            return 0;
        }
예제 #3
0
        public static Map ReadMap2(FileInfo fi)
        {
            FileStream fs = fi.OpenRead();
            BinaryReader br = new BinaryReader(fs);

            byte[] Buffer = br.ReadBytes((int)fi.Length);

            br.Close();

            Map map = new Map();

            map.FileOnDisk = fi;

            MemoryStream ms = new MemoryStream(Buffer);
            br = new BinaryReader(ms);

            if (Buffer[0] != 77 || Buffer[1] != 65 || Buffer[2] != 80 || Buffer[3] != 249 || Buffer[4] != 53 || Buffer[5] != 0)
            {
                Errors.Error("InputOutput", "File is not a VERGE2 Map");
                return null;
            }

            // 6 bytes signature
            // 4 bytes unknown??
            // ---
            // advance 10 bytes
            br.ReadBytes(10);

            // 60 bytes VSP FileName
            FileInfo vspfile = new FileInfo(Helper.BytesToString(br.ReadBytes(60)));
            if (!vspfile.Exists)
            {
                // TODO:  give the option to create a vsp in this case
                Errors.Error("InputOutput", "VSP was not found. New VSP created.");
                map.vsp = new Vsp24();
            }
            else
            {
                map.vsp = ReadVsp(vspfile.FullName);
            }

            // 60 bytes music filename
            map.MusicFileName = Helper.BytesToString(br.ReadBytes(60));

            // 20 bytes render string
            string dontcare = Helper.BytesToString(br.ReadBytes(20));

            // 4 bytes, start position
            map.PlayerStartX = (int)br.ReadInt16();
            map.PlayerStartY = (int)br.ReadInt16();

            // 51 bytes, unknown
            br.ReadBytes(51);

            // 1 byte, number of layers
            int layerCount = (int)br.ReadByte();

            for (int i = 0; i < layerCount; i++)
            {
                // 12 bytes per layer discriptor
                MapLayer ml = new MapLayer(map);
                ml.type = LayerType.Tile;
                ml.name = "Layer " + i.ToString();

                int mx, dx, my, dy;
                mx = (int)br.ReadByte();
                dx = (int)br.ReadByte();
                my = (int)br.ReadByte();
                dy = (int)br.ReadByte();

                double dmx, dmy;

                dmx = 1.0 * mx / dx;
                dmy = 1.0 * my / dy;
                ml.parallaxInfo.MultipleX = dmx;
                ml.parallaxInfo.MultipleY = dmy;
                /*
                                                                                ml.parallaxInfo.MultiplyX = (int)br.ReadByte();
                                                                                ml.parallaxInfo.DivideX = (int)br.ReadByte();
                                                                                ml.parallaxInfo.MultiplyY = (int)br.ReadByte();
                                                                                ml.parallaxInfo.DivideY = (int)br.ReadByte(); */

                int w = (int)br.ReadInt16();
                int h = (int)br.ReadInt16();
                ml.size(w, h);

                ml.Translucency = (int)br.ReadByte();
                ml.HLine = (int)br.ReadByte();

                // padding
                br.ReadInt16();

                map.Layers.Add(ml);
            }

            for (int i = 0; i < layerCount; i++)
            {
                int rleLength = br.ReadInt32();

                ushort[] layerdata = InputOutput.DecompressData16(Helper.BytesToWords(br.ReadBytes(rleLength)));
                MapLayer ml = (MapLayer)map.Layers[i];
                ml.Data = new short[ml.Width * ml.Height];
                for (int j = 0; j < ml.Width * ml.Height; j++)
                    ml.Data[j] = (short)layerdata[j];

            }

            int obsDataLength = br.ReadInt32();
            byte[] obsdata = InputOutput.DecompressData8(br.ReadBytes(obsDataLength));
            map.ObsLayer = new MapLayer(map);
            map.ObsLayer.type = LayerType.Obs;
            map.ObsLayer.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height);
            map.ObsLayer.name = "Obstructions";
            map.ObsLayer.Data = new short[map.ObsLayer.Width * map.ObsLayer.Height];
            for (int i = 0; i < map.ObsLayer.Width * map.ObsLayer.Height; i++)
                map.ObsLayer.Data[i] = obsdata[i];

            int zoneDataLength = br.ReadInt32();
            byte[] zonedata = InputOutput.DecompressData8(br.ReadBytes(zoneDataLength));
            map.ZoneLayer = new MapLayer(map);
            map.ZoneLayer.type = LayerType.Zone;
            map.ZoneLayer.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height);
            map.ZoneLayer.name = "Zones";
            map.ZoneLayer.Data = new short[map.ZoneLayer.Width * map.ZoneLayer.Height];
            for (int i = 0; i < map.ZoneLayer.Width * map.ZoneLayer.Height; i++)
                map.ZoneLayer.Data[i] = zonedata[i];

            MapLayer el = new MapLayer(map);
            el.type = LayerType.Entity;
            el.name = "Entities";
            map.Layers.Add(el);
            map.EntLayer = el;

            MapLayerSpecial rl = new MapLayerSpecial(map);
            rl.type = LayerType.Special_Retrace;

            map.Layers.Add(rl);
            map.Layers.Add(map.ObsLayer);
            map.Layers.Add(map.ZoneLayer);
            int zoneCount = br.ReadInt32();

            // 50 bytes per zone
            for (int i = 0; i < zoneCount; i++)
            {
                MapZone mz = new MapZone();

                mz.ID = i;

                mz.Name = Helper.CharsToString(br.ReadChars(40));
                //Errors.Error(mz.Name);

                mz.PlayerScript = "";
                br.ReadInt16();
                mz.Rate = (int)br.ReadInt16();
                mz.Delay = (int)br.ReadInt16();

                mz.Flags = (int)br.ReadInt16();
                mz.EntityScript = "";
                br.ReadInt16();

                map.Zones.Add(mz);
            }
            if (zoneCount == 0)
            {
                MapZone mz = new MapZone();
                mz.ID = 0;
                mz.Name = "NULL_ZONE";
                map.Zones.Add(mz);
            }

            int chrCount = (int)br.ReadByte();
            ArrayList al_chrs = new ArrayList();

            for (int i = 0; i < chrCount; i++)
            {
                MapChr mc = new MapChr();

                try
                {
                    mc.Name = Helper.BytesToFileString(br.ReadBytes(60));
                }
                catch (Exception e)
                {
                    mc.Name = "";

                    /// there's no error log in maped3 yet.  I'll discuss this with the boys.  For now, ANNOYING MESSAGE BOX!
                    /// -gru

                    Errors.Error("I/O", "Bad filename for MapChr(" + i + "): " + e.Message + "\nDefaulting to empty string for file name.");
                }

                mc.ID = i;

                if (mc.Name.Length > 0)
                {
                    FileInfo mcfi = new FileInfo(mc.Name);
                    if (ReadCHR(mcfi, mc) == 0) mc.bImageAvailable = true;
                }
                al_chrs.Add(mc);
            }

            int entCount = (int)br.ReadByte();
            //Errors.Error(entCount.ToString() + ", "+br.BaseStream.Position.ToString());

            for (int i = 0; i < entCount; i++)
            {
                MapEntity me = new MapEntity();

                me.TileX = (int)br.ReadInt32();
                me.TileY = (int)br.ReadInt32();

                int xx = (int)br.ReadInt16();
                int xy = (int)br.ReadInt16();

                //Errors.Error(""+ me.TileX+","+me.TileY+":"+xx+","+xy);
                // ignore
                //br.ReadBytes(4);

                me.Facing = (int)br.ReadByte();
                if (me.Facing == 0)
                    me.Facing = 2;
                me.Moving = (int)br.ReadByte();

                // ignore
                br.ReadByte();

                me.BottomLineFrame = (int)br.ReadByte();
                me.SpecialFrameSet = (int)br.ReadByte();
                int cidx = (int)br.ReadByte();
                // assign chr
                // dont do this
                //me.Chr = ((MapChr)al_chrs[cidx]).Clone();
                me.ChrName = string.Copy(((MapChr)al_chrs[cidx]).Name);

                me.Reset = (int)br.ReadByte();
                me.ObeyObstruction = (int)br.ReadByte();
                me.IsObstruction = (int)br.ReadByte();
                me.Speed = (int)br.ReadByte();
                switch (me.Speed)
                {
                    case 1: me.Speed = 25; break;
                    case 2: me.Speed = 33; break;
                    case 3: me.Speed = 50; break;
                    case 4: me.Speed = 100; break;
                    case 5: me.Speed = 200; break;
                    case 6: me.Speed = 300; break;
                    case 7: me.Speed = 400; break;
                }

                // ignore
                br.ReadBytes(10); // entspeedcnt(1), anim frame delay(1), anim script(4), move script(4)

                //32

                me.AutoFace = (int)br.ReadByte();
                me.ActivationMode = (int)br.ReadByte();
                me.MoveType = (int)br.ReadByte();
                if (me.MoveType > 1) me.MoveType--;
                me.__movescript = (int)br.ReadByte();

                // ignore
                br.ReadBytes(2); // subtile move ctr, mode flag

                me.WanderSteps = (int)br.ReadInt16();
                me.WanderDelay = (int)br.ReadInt16();

                // ignore
                br.ReadBytes(4); // step ctr, delay ctr

                me.ID = i;

                br.ReadBytes(2); // WTF IS THIS!!

                for (int j = 0; j < 6; j++)
                {
                    me.UserData[j] = br.ReadInt16();
                }

                me.WanderRectangle.x0 = me.UserData[1];
                me.WanderRectangle.y0 = me.UserData[2];
                me.WanderRectangle.x1 = me.UserData[4];
                me.WanderRectangle.y1 = me.UserData[5];

                // ignore
                br.ReadBytes(20); // a lot of shiznit

                me.Description = Helper.BytesToString(br.ReadBytes(20));

                //Errors.Error(me.Description);

                //br.ReadBytes(2); // WTF IS THIS!!

                me.ID = i;
                map.Entities.Add(me);
            }

            int movescriptCount = (int)br.ReadByte();
            int movescriptBuffersize = (int)br.ReadInt32();

            ArrayList al_scripts = new ArrayList();
            // ignore
            br.ReadBytes(4 * movescriptCount);

            string script = "";
            while (movescriptBuffersize > 0)
            {
                char c = br.ReadChar();

                if (c == (char)0)
                {
                    al_scripts.Add(string.Copy(script));
                    script = "";
                }
                else script += c;
                movescriptBuffersize--;
            }
            // add all the scripts to their respective entities and trash the movescript array

            foreach (MapEntity me in map.Entities)
            {
                me.MoveScript = (string)al_scripts[me.__movescript];
            }

            br.Close();

            string rs2 = "";
            foreach (char c in dontcare)
            {
                if (rs2.Length != 0)
                    rs2 += ",";
                rs2 += c;
            }
            map.RenderString = rs2;
            return map;
        }
예제 #4
0
파일: Map.cs 프로젝트: zeromus/maped3
 public MapChr Clone()
 {
     MapChr mc = new MapChr();
     if (bImageAvailable)
     {
         // copy actual chr data
         mc.bImageAvailable = this.bImageAvailable;
         mc.FrameWidth = this.FrameWidth;
         mc.FrameHeight = this.FrameHeight;
         mc.HotspotX = this.HotspotX;
         mc.HotspotY = this.HotspotY;
         mc.HotspotWidth = this.HotspotWidth;
         mc.HotspotHeight = this.HotspotHeight;
         mc.FrameCount = this.FrameCount;
         mc.ImageData = (byte[])this.ImageData.Clone();
         mc.IdleFrameDown = this.IdleFrameDown;
         mc.IdleFrameLeft = this.IdleFrameLeft;
         mc.IdleFrameUp = this.IdleFrameUp;
         mc.IdleFrameRight = this.IdleFrameRight;
         for (int i = 0; i < 4; i++)
             mc.MoveScripts[i] = string.Copy(this.MoveScripts[i]);
     }
     // copy map relevant info
     //mc.ID = this.ID;
     //mc.Name = this.Name;
     return mc;
 }