Beispiel #1
0
        public bool SetMOTD(string data, string language, string password)
        {
            if (password != PassPhrase)
            {
                return(false);
            }

            WAD.TWADFile WADFile = new WAD.TWADFile(Convert.FromBase64String(data), "motd-mp-" + language + ".txt");

            DWStorage.FlushPublisherFiles();

            return(WAD.Manager.AddFileToWAD(WADFile, language));
        }
Beispiel #2
0
        public string GetMOTD(string language, string password)
        {
            if (password != PassPhrase)
            {
                return("Invalid Password");
            }

            var WADFile = "data/pub/online_tu12_mp_" + language + ".wad";

            if (!File.Exists(WADFile))
            {
                return("Error");
            }

            WAD.TWADFile ReqFile = WAD.Manager.GetFileFromWAD("motd-mp-" + language + ".txt", language);

            if (ReqFile.FileName == "error")
            {
                return("Error");
            }

            return(Convert.ToBase64String(ReqFile.Content));
        }
Beispiel #3
0
        public static bool AddFileToWAD(TWADFile InFile, string Language = "english")
        {
            try
            {
                MemoryStream TWADMStream = new MemoryStream(File.ReadAllBytes("data/pub/online_tu12_mp_" + Language + ".wad"));
                BinaryReader TWADReader  = new BinaryReader(TWADMStream);

                TWADReader.ReadUInt32(true);
                TWADReader.ReadUInt32();
                UInt32 FileCount = TWADReader.ReadUInt32();
                TWADReader.ReadUInt32();

                List <TWADFile> TWADFiles = new List <TWADFile>();

                for (int i = 0; i < FileCount; i++)
                {
                    string NewFileName      = TWADReader.ReadString(32);
                    UInt32 CompressedLength = TWADReader.ReadUInt32(true);
                    UInt32 Length           = TWADReader.ReadUInt32(true);
                    UInt32 Offset           = TWADReader.ReadUInt32(true);
                    TWADFiles.Add(new TWADFile(NewFileName, CompressedLength, Length, Offset));
                }

                bool FoundFile = false;

                foreach (TWADFile FileEntry in TWADFiles)
                {
                    if (FileEntry.FileName == InFile.FileName)
                    {
                        FileEntry.Content    = InFile.Content;
                        FileEntry.Compressed = InFile.Compressed;
                        FoundFile            = true;
                    }
                    else
                    {
                        TWADMStream.Position = FileEntry.Offset;
                        FileEntry.Compressed = TWADReader.ReadBytes((Int32)FileEntry.CompressedLength);
                        FileEntry.Content    = FileEntry.GetData();
                    }
                }

                if (!FoundFile)
                {
                    TWADFiles.Add(InFile);
                }

                TWADReader.Close();
                TWADMStream.Close();

                // Recompress the WAD

                TWADMStream = new MemoryStream();
                BinaryWriter TWADWriter = new BinaryWriter(TWADMStream);

                TWADWriter.Write((UInt32)0xAB773354, true);

                TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
                TWADWriter.Write((UInt32)ts.TotalSeconds);
                TWADWriter.Write((UInt32)TWADFiles.Count);

                TWADWriter.Write((UInt32)0);

                int CurrentOffset = 16 + (44 * TWADFiles.Count);

                foreach (TWADFile WFile in TWADFiles)
                {
                    // Construct our directory
                    TWADWriter.Write(WFile.FileName, 32);
                    TWADWriter.Write((UInt32)WFile.Compressed.Length, true);
                    TWADWriter.Write((UInt32)WFile.Content.Length, true);
                    TWADWriter.Write((UInt32)CurrentOffset, true);
                    CurrentOffset += WFile.Compressed.Length;
                }

                // Add the file data
                foreach (TWADFile WFile in TWADFiles)
                {
                    TWADWriter.Write(WFile.Compressed);
                }

                // Write our file
                File.WriteAllBytes("data/pub/online_tu12_mp_" + Language + ".wad", TWADMStream.ToArray());

                // Close the streams
                TWADWriter.Close();
                TWADMStream.Close();

                return(true);
            }
            catch
            {
                return(false);
            }
        }