コード例 #1
0
ファイル: JassInjector.cs プロジェクト: Arathi/War3MapTools
        public bool ParseMapJass()
        {
            try
            {
                string    jPath      = @"scripts\war3map.j";
                MpqStream jassStream = MapFile.OpenFile(jPath);

                StreamReader   streader = new StreamReader(jassStream);
                IList <string> lines    = new List <string>();
                while (!streader.EndOfStream)
                {
                    lines.Add(streader.ReadLine());
                }
                logger.Info($"读取jass文件{lines.Count}行");

                JassFile = new JassFile(lines);
                JassFile.Parse();
                logger.Info($"解析jass完成,共计{JassFile.Globals.Variables.Count}个全局变量,{JassFile.Functions.Count}个函数");

                return(true);
            }
            catch (FileNotFoundException ex)
            {
                logger.Error("未找到jass文件:" + ex.Message);
            }
            return(false);
        }
コード例 #2
0
ファイル: MPQEditor.cs プロジェクト: Stannnnn/War3NetMPQApi
        public void ExtractAll(string listFile, string dirOut)
        {
            if (originalMpqArchive != null)
            {
                var files = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                files.AddRange(File.ReadAllLines(listFile));

                if (originalMpqArchive.FileExists("(listfile)"))
                {
                    using (MpqStream fileStreamIn = originalMpqArchive.OpenFile("(listfile)"))
                    {
                        files.AddRange(ReadLines(() => fileStreamIn));
                    }
                }

                foreach (var file in files)
                {
                    if (originalMpqArchive.FileExists(file))
                    {
                        Extract(file, dirOut + Path.DirectorySeparatorChar + file);
                    }
                }
            }
        }
コード例 #3
0
        public byte[] read(string fileName)
        {
            MpqStream    input  = this._mpqArchive.OpenFile(fileName);
            BinaryReader reader = new BinaryReader(input);

            byte[] buffer = new byte[reader.BaseStream.Length];
            reader.Read(buffer, 0, buffer.Length);
            reader.Close();
            input.Close();
            return(buffer);
        }
コード例 #4
0
 public string readFile(string fileName)
 {
     if (this._fileContentsType != fileName)
     {
         MpqStream    input  = this._mpqArchive.OpenFile(fileName);
         BinaryReader reader = new BinaryReader(input);
         char[]       buffer = new char[reader.BaseStream.Length];
         reader.Read(buffer, 0, buffer.Length);
         reader.Close();
         input.Close();
         this._fileContents     = new string(buffer);
         this._fileContentsType = fileName;
     }
     return(this._fileContents);
 }
コード例 #5
0
ファイル: MPQEditor.cs プロジェクト: Stannnnn/War3NetMPQApi
        public void Extract(string fileName, string fileOut)
        {
            if (originalMpqArchive != null)
            {
                try
                {
                    var mpqEntries = originalMpqArchive.GetMpqEntries(fileName);

                    if (mpqEntries.Count() > 1)
                    {
                        foreach (var mpqEntry in mpqEntries)
                        {
                            System.Console.WriteLine(mpqEntry.FileName + " " + mpqEntry.FilePosition + " " + mpqEntry.FileSize);
                        }
                    }

                    if (mpqEntries.Count() >= 1)
                    {
                        using (MpqStream fileStreamIn = originalMpqArchive.OpenFile(mpqEntries.Last()))
                        {
                            using (FileStream fileStreamOut = CreateOrOpenFileAndFolder(fileOut))
                            {
                                fileStreamIn.CopyTo(fileStreamOut);
                            }
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                }
                catch (MpqParserException)
                {
                    System.Console.WriteLine("Exception for: " + fileName);
                    throw;
                }
            }
        }
コード例 #6
0
        public Map(string filename)
        {
            MapPath = filename;
            using (FileStream fs = new FileStream(filename, FileMode.Open)) {
                byte[] d = new byte[fs.Length];
                fs.Read(d, 0, d.Length);
                fs.Seek(0, SeekOrigin.Begin);

                this.MapSize = BitConverter.GetBytes((int)fs.Length);
                this.MapInfo = new CRC32().ComputeHash(d, 0, d.Length);

                using (MpqArchive a = new MpqArchive(fs, true))
                {
                    uint CRCVal = 0;

                    SHA1Managed sha = new SHA1Managed();

                    byte[] commonJData, blizzardJData;
                    if (a.FileExists("Scripts\\common.j"))
                    {
                        using (var commonOverload = a.OpenFile("Scripts\\common.j")){
                            var ms = new MemoryStream();
                            commonOverload.CopyTo(ms);
                            commonJData = ms.ToArray();
                            ms.Dispose();
                        }
                    }
                    else
                    {
                        commonJData = File.ReadAllBytes("dep/common.j");
                    }
                    if (a.FileExists("Scripts\\blizzard.j"))
                    {
                        using (var blizzardOverload = a.OpenFile("Scripts\\blizzard.j")){
                            var ms = new MemoryStream();
                            blizzardOverload.CopyTo(ms);
                            blizzardJData = ms.ToArray();
                            ms.Dispose();
                        }
                    }
                    else
                    {
                        blizzardJData = File.ReadAllBytes("dep/blizzard.j");
                    }

                    CRCVal = CRCVal ^ XORRotateLeft(commonJData);
                    CRCVal = CRCVal ^ XORRotateLeft(blizzardJData);

                    sha.TransformBlock(commonJData, 0, commonJData.Length, commonJData, 0);
                    sha.TransformBlock(blizzardJData, 0, blizzardJData.Length, blizzardJData, 0);

                    var  magicBytes = new byte[] { 0x9e, 0x37, 0xf1, 0x03 };
                    uint magicInt   = 0x03F1379E;

                    CRCVal = ROTL(CRCVal, 3);
                    CRCVal = ROTL(CRCVal ^ magicInt, 3);

                    sha.TransformBlock(magicBytes, 0, magicBytes.Length, magicBytes, 0);

                    string[] filenames   = { "war3map.j", "scripts\\war3map.j", "war3map.w3e", "war3map.wpm", "war3map.doo", "war3map.w3u", "war3map.w3b", "war3map.w3d", "war3map.w3a", "war3map.w3q" };
                    var      foundScript = false;

                    foreach (string fn in filenames)
                    {
                        if (foundScript && fn == filenames[2])
                        {
                            continue;
                        }

                        if (!a.FileExists(fn))
                        {
                            continue;
                        }

                        using (MpqStream s = a.OpenFile(fn)){
                            var ms = new MemoryStream();
                            s.CopyTo(ms);
                            var fdata = ms.ToArray();
                            ms.Dispose();

                            CRCVal = ROTL(CRCVal ^ XORRotateLeft(fdata), 3);
                            sha.TransformBlock(fdata, 0, fdata.Length, fdata, 0);
                        }
                    }

                    MapCRC = BitConverter.GetBytes(CRCVal);

                    sha.TransformFinalBlock(new byte[] {}, 0, 0);
                    MapSha = sha.Hash;
                    //loading actual map shit now

                    int MapFlags;

                    using (MpqStream m = a.OpenFile("war3map.w3i")){
                        BinaryReader br         = new BinaryReader(m);
                        var          FileFormat = br.ReadInt32();
                        if (FileFormat != 18 && FileFormat != 25)
                        {
                            throw new Exception("Unknown w3i file format " + FileFormat);
                        }

                        //most of these are practically garbage, but still fun to have :)
                        int    g_NumSaves              = br.ReadInt32();
                        int    g_EditorVer             = br.ReadInt32();
                        string g_MapName               = ConvertUtils.parseStringZ(br);
                        string g_MapAuthor             = ConvertUtils.parseStringZ(br);
                        string g_MapDesc               = ConvertUtils.parseStringZ(br);
                        string g_MapReccomendedPlayers = ConvertUtils.parseStringZ(br);
                        byte[] g_CameraBounds          = br.ReadBytes(32);
                        byte[] g_CameraBoundsExt       = br.ReadBytes(16);
                        int    g_MapWidth              = MapWidth = br.ReadInt32();
                        int    g_MapHeight             = MapHeight = br.ReadInt32();
                        int    g_MapFlags              = MapFlags = br.ReadInt32();
                        byte   g_MapGroundType         = br.ReadByte();

                        bool   g_TFTLoading = FileFormat == 25;
                        int    g_LoadingScreenId;
                        string g_LoadingScreenPath = "";
                        if (!g_TFTLoading)
                        {
                            g_LoadingScreenId = br.ReadInt32();
                        }
                        else
                        {
                            g_LoadingScreenId   = br.ReadInt32();
                            g_LoadingScreenPath = ConvertUtils.parseStringZ(br);
                        }

                        string g_LoadingText     = ConvertUtils.parseStringZ(br);
                        string g_LoadingTitle    = ConvertUtils.parseStringZ(br);
                        string g_LoadingSubTitle = ConvertUtils.parseStringZ(br);

                        int    g_PrologueScreenId;
                        string g_PrologueScreenPath = "";
                        if (!g_TFTLoading)
                        {
                            g_PrologueScreenId = br.ReadInt32();
                        }
                        else
                        {
                            g_PrologueScreenId   = br.ReadInt32();
                            g_PrologueScreenPath = ConvertUtils.parseStringZ(br);
                        }

                        string g_PrologueText     = ConvertUtils.parseStringZ(br);
                        string g_PrologueTitle    = ConvertUtils.parseStringZ(br);
                        string g_PrologueSubTitle = ConvertUtils.parseStringZ(br);

                        if (FileFormat == 25)
                        {
                            br.ReadBytes(4 + 4 + 4 + 4 + 1 + 1 + 1 + 1 + 4); // int fog, int fog startz, int fog endz, int fogdensity, byte fogRED, byte ffogGREEN, byte fogBLUE, byte fogALPHA, int globalWeatherId

                            ConvertUtils.parseStringZ(br);                   // custom sound environment

                            br.ReadBytes(5);                                 // bytes[5] {tilesetid, waterTintRED, waterTintGREEN, waterTintBLUE, waterTintALPHA}
                        }

                        int g_NumPlayers = MapNumPlayers = br.ReadInt32();
                        int ClosedSlots  = 0;

                        for (int i = 0; i < MapNumPlayers; i++)
                        {
                            Slot s = new Slot();

                            s.color = (byte)br.ReadInt32();
                            int status = br.ReadInt32();

                            if (status == 1)
                            {
                                s.slotStatus = (byte)SlotStatus.OPEN;
                            }
                            else if (status == 2)
                            {
                                s.slotStatus   = (byte)SlotStatus.OCCUPIED;
                                s.computer     = 1;
                                s.computertype = (byte)SlotCompType.NORMAL;
                            }
                            else
                            {
                                s.slotStatus = (byte)SlotStatus.CLOSED;
                                ClosedSlots++;
                            }

                            switch (br.ReadInt32())
                            {
                            case 1: s.race = (byte)SlotRace.HUMAN; break;

                            case 2: s.race = (byte)SlotRace.ORC; break;

                            case 3: s.race = (byte)SlotRace.UNDEAD; break;

                            case 4: s.race = (byte)SlotRace.NIGHTELF; break;

                            default: s.race = (byte)SlotRace.RANDOM; break;
                            }

                            br.ReadBytes(4);               // fixedstart
                            ConvertUtils.parseStringZ(br); //playername (could be interesting)
                            br.ReadBytes(16);              // startx, starty, allylow, allyhigh

                            if (s.slotStatus != (byte)SlotStatus.CLOSED)
                            {
                                Slots.Add(s);
                            }
                        }
                        MapNumPlayers -= ClosedSlots;

                        int g_NumTeams = MapNumTeams = br.ReadInt32();

                        for (int i = 0; i < MapNumTeams; i++)
                        {
                            int Flags      = br.ReadInt32();
                            int PlayerMask = br.ReadInt32();

                            for (int si = 0; si < MAX_SLOTS; si++)
                            {
                                if ((PlayerMask & 1) == 1)
                                {
                                    foreach (Slot s in Slots)
                                    {
                                        if (s.color == si)
                                        {
                                            s.team = (byte)i;
                                        }
                                    }
                                }

                                PlayerMask >>= 1;
                            }

                            ConvertUtils.parseStringZ(br); //Team Name
                        }
                    }

                    MapOptions    = MapFlags & ((int)MAPOPTIONS.MELEE | (int)MAPOPTIONS.FIXEDPLAYERSETTINGS | (int)MAPOPTIONS.CUSTOMFORCES);
                    MapFilterType = (int)MAPFILTERTYPE.SCENARIO;

                    if ((MapOptions & (int)MAPOPTIONS.MELEE) == (int)MAPOPTIONS.MELEE)
                    {
                        byte team = 0;
                        foreach (Slot s in Slots)
                        {
                            s.team = team++;
                            s.race = (byte)SlotRace.RANDOM;
                        }
                        MapFilterType = (int)MAPFILTERTYPE.MELEE;
                    }

                    if ((MapOptions & (int)MAPOPTIONS.FIXEDPLAYERSETTINGS) != (int)MAPOPTIONS.FIXEDPLAYERSETTINGS)
                    {
                        foreach (Slot s in Slots)
                        {
                            s.race = (byte)(s.race | (byte)SlotRace.SELECTABLE);
                        }
                    }
                }
            }

            LoadGameVariables();

            if ((MapFlags & (int)MAPFLAGS.RANDOMRACES) == (int)MAPFLAGS.RANDOMRACES)
            {
                foreach (Slot s in Slots)
                {
                    s.race = (byte)SlotRace.RANDOM;
                }
            }

            if ((MapObservers & (int)MAPOBSERVERS.ALLOWED) == (int)MAPOBSERVERS.ALLOWED || (MapObservers & (int)MAPOBSERVERS.REFEREES) == (int)MAPOBSERVERS.REFEREES)
            {
                var observercount = MAX_SLOTS;
                if ((MapOptions & (int)MAPOPTIONS.MELEE) == (int)MAPOPTIONS.MELEE)
                {
                    observercount = 12;
                }
                while (Slots.Count < observercount)
                {
                    Slots.Add(new Slot(0, 255, (byte)SlotStatus.OPEN, 0, MAX_SLOTS, MAX_SLOTS, (byte)SlotRace.RANDOM | (byte)SlotRace.SELECTABLE));
                }
            }

            // System.Console.WriteLine(BitConverter.ToString(MapInfo).Replace("-",""));
            // System.Console.WriteLine(BitConverter.ToString(MapCRC).Replace("-",""));
            // System.Console.WriteLine(BitConverter.ToString(MapSha).Replace("-",""));
        }
コード例 #7
0
ファイル: MpqKnownFile.cs プロジェクト: yungshing/War3Net
 /// <summary>
 /// Initializes a new instance of the <see cref="MpqKnownFile"/> class.
 /// </summary>
 internal MpqKnownFile(string fileName, MpqStream mpqStream, MpqFileFlags flags, MpqLocale locale, bool leaveOpen = false)
     : base(MpqHash.GetHashedFileName(fileName), mpqStream, flags, locale, leaveOpen)
 {
     _fileName = fileName;
 }