Exemplo n.º 1
0
        public static void CookRoomDefinitionFiles(IEnumerable <String> levelRulesFiles)
        {
            foreach (String filePath in levelRulesFiles)
            {
                try
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(filePath);

                    RoomDefinitionFile roomDefinitionFile = new RoomDefinitionFile(filePath);
                    roomDefinitionFile.ParseXmlDocument(xmlDocument);
                    byte[] fileBytes = roomDefinitionFile.ToByteArray();

                    File.WriteAllBytes(filePath.Replace(RoomDefinitionFile.ExtensionDeserialised, RoomDefinitionFile.Extension), fileBytes);
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                    Console.WriteLine(String.Format("Error: Failed to serialize file {0}", filePath));
                }
            }
        }
Exemplo n.º 2
0
        public static void LoadAllRooms()
        {
            const String root = @"D:\Games\Hellgate London\data\background\";
            List<String> roomFiles = new List<String>(Directory.GetFiles(root, "*.rom", SearchOption.AllDirectories));

            foreach (String roomFilePath in roomFiles)
            {
                String path = roomFilePath;
                //path = @"D:\Games\Hellgate London\data\background\city\charactercreate.rom";
                //path = "D:\\Games\\Hellgate London\\data\\background\\props\\vehicles\\ambulance_a.rom";

                byte[] roomFileBytes = File.ReadAllBytes(path);
                RoomDefinitionFile roomDefinitionFile = new RoomDefinitionFile(path, null, null);

                String fileName = path.Replace(@"D:\Games\Hellgate London\data\background\", "");
                String xmlPath = path.Replace(RoomDefinitionFile.Extension, RoomDefinitionFile.ExtensionDeserialised);
                Console.WriteLine("Loading: " + fileName);
                try
                {
                    roomDefinitionFile.ParseFileBytes(roomFileBytes);
                    byte[] xmlBytes = roomDefinitionFile.ExportAsDocument();
                    File.WriteAllBytes(xmlPath, xmlBytes);

                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(xmlPath);
                    RoomDefinitionFile roomDefinitionFile2 = new RoomDefinitionFile(xmlPath);
                    roomDefinitionFile2.ParseXmlDocument(xmlDocument);
                    byte[] bytes = roomDefinitionFile2.ToByteArray();

                    if (!roomFileBytes.SequenceEqual(bytes))
                    {
                        File.WriteAllBytes(path + "2", bytes);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to load file!\n" + e);
                    continue;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// User-friendly uncooking of Tree Node list.
        /// </summary>
        /// <param name="progressForm">A progress form to update.</param>
        /// <param name="param">The Tree Node List.</param>
        private void _DoUnooking(ProgressForm progressForm, Object param)
        {
            List<TreeNode> uncookingNodes = (List<TreeNode>)param;
            const int progressUpdateFreq = 20;
            if (progressForm != null)
            {
                progressForm.ConfigBar(1, uncookingNodes.Count, progressUpdateFreq);
            }

            int i = 0;
            foreach (TreeNode treeNode in uncookingNodes)
            {
                NodeObject nodeObject = (NodeObject)treeNode.Tag;
                PackFileEntry fileEntry = nodeObject.FileEntry;

                // update progress if applicable
                if (i % progressUpdateFreq == 0 && progressForm != null)
                {
                    progressForm.SetCurrentItemText(fileEntry.Path);
                }
                i++;

                // get the file bytes
                String relativePath = fileEntry.Path;
                byte[] fileBytes;
                try
                {
                    fileBytes = _fileManager.GetFileBytes(fileEntry, true);
                    if (fileBytes == null) continue;
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                    continue;
                }

                // determine file type
                HellgateFile hellgateFile;
                if (relativePath.EndsWith(XmlCookedFile.Extension))
                {
                    hellgateFile = new XmlCookedFile(_fileManager);
                }
                else if (relativePath.EndsWith(RoomDefinitionFile.Extension))
                {
                    hellgateFile = new RoomDefinitionFile(relativePath);
                }
                else if (relativePath.EndsWith(MLIFile.Extension))
                {
                    hellgateFile = new MLIFile();
                }
                else
                {
                    Debug.Assert(false, "wtf");
                    continue;
                }

                // deserialise file
                DialogResult dr = DialogResult.Retry;
                bool uncooked = false;
                while (dr == DialogResult.Retry && !uncooked)
                {
                    try
                    {
                        hellgateFile.ParseFileBytes(fileBytes);
                        uncooked = true;
                    }
                    catch (Exception e)
                    {
                        ExceptionLogger.LogException(e, true);

                        String errorMsg = String.Format("Failed to uncooked file!\n{0}\n\n{1}", relativePath, e);
                        dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
                        if (dr == DialogResult.Abort) return;
                        if (dr == DialogResult.Ignore) break;
                    }
                }
                if (!uncooked) continue;

                // save file
                String relativeSavePath = relativePath.Replace(HellgateFile.Extension, HellgateFile.ExtensionDeserialised);
                String savePath = Path.Combine(Config.HglDir, relativeSavePath);

                dr = DialogResult.Retry;
                bool saved = false;
                byte[] documentBytes = null;
                while (dr == DialogResult.Retry && !saved)
                {
                    try
                    {
                        if (documentBytes == null) documentBytes = hellgateFile.ExportAsDocument();
                        File.WriteAllBytes(savePath, documentBytes);
                        saved = true;
                    }
                    catch (Exception e)
                    {
                        ExceptionLogger.LogException(e, true);

                        String errorMsg = String.Format("Failed to save file!\n{0}\n\n{1}", relativePath, e);
                        dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
                        if (dr == DialogResult.Abort) return;
                        if (dr == DialogResult.Ignore) break;
                    }
                }

                // update tree view
                TreeNode newTreeNode = new TreeNode();
                NodeObject newNodeObject = new NodeObject
                {
                    CanEdit = true,
                    IsUncookedVersion = true
                };
                newTreeNode.Tag = newNodeObject;
                treeNode.Nodes.Add(newTreeNode);
            }
        }
Exemplo n.º 4
0
        private void _PaintRooms(Graphics g, IEnumerable <LevelRulesFile.Room> rooms, PointF offset, Color color, PaintType paintType)
        {
            int i = 0;

            foreach (LevelRulesFile.Room room in rooms)
            {
                float yPos = room.X * _graphicsScale + offset.X + _graphicsOffsetX;
                float xPos = room.Y * _graphicsScale + offset.Y + _graphicsOffsetY;
                if (_flipXYOffsets)
                {
                    yPos = room.Y * _graphicsScale + offset.X + _graphicsOffsetX;
                    xPos = room.X * _graphicsScale + offset.Y + _graphicsOffsetY;
                }

                String             roomPathName   = _GetRoomPathName(room.RoomDesc);
                RoomDefinitionFile roomDefinition = _roomDefinitions[roomPathName];
                float roomWidth  = roomDefinition.RoomDefinition.FileHeader.UnknownFloat1 * _graphicsScale;
                float roomHeight = roomDefinition.RoomDefinition.FileHeader.MinX * _graphicsScale;
                if (_flipWidthHeight)
                {
                    roomWidth  = roomDefinition.RoomDefinition.FileHeader.MinX * _graphicsScale;
                    roomHeight = roomDefinition.RoomDefinition.FileHeader.UnknownFloat1 * _graphicsScale;
                }

                Matrix myMatrix  = new Matrix();
                float  rotateDeg = -room.Rotation * 180.0f / (float)Math.PI;
                if (_reverseRotation)
                {
                    rotateDeg *= -1;
                }


                if (roomWidth < 0)
                {
                    roomWidth *= -1;
                    if (!_disableWidthOffset)
                    {
                        if (_flipWidthHeightOffset)
                        {
                            xPos -= roomWidth;
                        }
                        else
                        {
                            yPos -= roomWidth;
                        }
                    }
                }
                if (roomHeight < 0)
                {
                    roomHeight *= -1;
                    if (!_disableWidthOffset)
                    {
                        if (_flipWidthHeightOffset)
                        {
                            xPos -= roomHeight;
                        }
                        else
                        {
                            yPos -= roomHeight;
                        }
                    }
                }

                myMatrix.RotateAt(rotateDeg, new PointF(xPos, yPos));
                g.Transform = myMatrix;

                if (paintType == PaintType.Block)
                {
                    g.FillRectangle(new SolidBrush(color), xPos, yPos, roomWidth, roomHeight);

                    // g.Transform = new Matrix();

                    //g.FillRectangle(new SolidBrush(Color.MistyRose), xPos, yPos, roomWidth, roomHeight);
                    //g.DrawString(rotateDeg.ToString(), _font, new SolidBrush(Color.Black), xPos, yPos);
                }
                if (paintType == PaintType.Outline)
                {
                    g.DrawRectangle(new Pen(Color.Black), xPos, yPos, roomWidth, roomHeight);
                }
                if (paintType == PaintType.DashedOutline)
                {
                    Pen pen = new Pen(Color.Black)
                    {
                        DashStyle  = DashStyle.DashDot,
                        DashOffset = 20
                    };
                    g.DrawRectangle(pen, xPos, yPos, roomWidth, roomHeight);
                }

                float strX = xPos;
                float strY = yPos;
                //if (i % 2 == 0)
                //{
                //    strY += roomHeight;
                //}
                //else
                //{
                //    strY -= (_font.Size + 6);
                //}

                //g.Transform = new Matrix();
                if (paintType == PaintType.Text && !_disableRoomNames)
                {
                    g.DrawString(room.RoomDesc, _font, new SolidBrush(Color.Black), strX, strY);
                }
                i++;
            }
        }
Exemplo n.º 5
0
        private void _LoadRooms(IEnumerable <LevelRulesFile.Room> rooms, String rootDir)
        {
            foreach (LevelRulesFile.Room room in rooms)
            {
                String roomPathName = _GetRoomPathName(room.RoomDesc);
                if (_roomDefinitions.ContainsKey(roomPathName))
                {
                    continue;
                }


                // do we need to change our directory?
                int codeDot = room.RoomDesc.IndexOf('.');
                if (codeDot > 0)
                {
                    // debug check
                    Debug.Assert(codeDot == room.RoomDesc.Length - 5);

                    String excelError = "The level rule loaded has rooms that require a directory change.\n" +
                                        "This act requires access to an initialised FileManager instance with loaded Excel files.\n" +
                                        "The room \"" + room.RoomDesc + "\" cannot be loaded.";
                    if (_fileManager == null)
                    {
                        MessageBox.Show(excelError, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        continue;
                    }

                    String codeString = room.RoomDesc.Substring(codeDot + 1);
                    int    code       = codeString[3] << 24 | codeString[2] << 16 | codeString[1] << 8 | codeString [0];

                    // get data table
                    DataTable levelFilePathsTable = _fileManager.GetDataTable("LEVEL_FILE_PATHS");
                    if (levelFilePathsTable == null)
                    {
                        MessageBox.Show(excelError, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        continue;
                    }

                    DataRow[] dataRows = levelFilePathsTable.Select(String.Format("code = {0}", code));
                    if (dataRows.Length == 0)
                    {
                        throw new Exceptions.UnknownExcelCodeException(code);
                    }

                    rootDir = @"data\" + dataRows[0][3].ToString().ToLower();
                }

                // read file
                byte[]             fileBytes;
                RoomDefinitionFile roomDefinitionFile;
                if (_fileManager != null)
                {
                    String relativeDirectory = Path.GetDirectoryName(rootDir);
                    Debug.Assert(relativeDirectory != null);
                    String relativePath = Path.Combine(relativeDirectory, roomPathName + RoomDefinitionFile.Extension);
                    fileBytes          = _fileManager.GetFileBytes(relativePath);
                    roomDefinitionFile = new RoomDefinitionFile(relativePath);
                }
                else
                {
                    String roomPath = Path.Combine(rootDir, roomPathName + RoomDefinitionFile.Extension);
                    fileBytes          = File.ReadAllBytes(roomPath);
                    roomDefinitionFile = new RoomDefinitionFile(roomPath);
                }

                roomDefinitionFile.ParseFileBytes(fileBytes);
                _roomDefinitions.Add(roomPathName, roomDefinitionFile);
            }
        }
Exemplo n.º 6
0
        public static void CookRoomDefinitionFiles(IEnumerable<String> levelRulesFiles)
        {
            foreach (String filePath in levelRulesFiles)
            {
                try
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(filePath);

                    RoomDefinitionFile roomDefinitionFile = new RoomDefinitionFile(filePath);
                    roomDefinitionFile.ParseXmlDocument(xmlDocument);
                    byte[] fileBytes = roomDefinitionFile.ToByteArray();

                    File.WriteAllBytes(filePath.Replace(RoomDefinitionFile.ExtensionDeserialised, RoomDefinitionFile.Extension), fileBytes);
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                    Console.WriteLine(String.Format("Error: Failed to serialize file {0}", filePath));
                }
            }
        }
Exemplo n.º 7
0
        private void _LoadRooms(IEnumerable<LevelRulesFile.Room> rooms, String rootDir)
        {
            foreach (LevelRulesFile.Room room in rooms)
            {
                String roomPathName = _GetRoomPathName(room.RoomDesc);
                if (_roomDefinitions.ContainsKey(roomPathName)) continue;

                // do we need to change our directory?
                int codeDot = room.RoomDesc.IndexOf('.');
                if (codeDot > 0)
                {
                    // debug check
                    Debug.Assert(codeDot == room.RoomDesc.Length - 5);

                    String excelError = "The level rule loaded has rooms that require a directory change.\n" +
                                        "This act requires access to an initialised FileManager instance with loaded Excel files.\n" +
                                        "The room \"" + room.RoomDesc + "\" cannot be loaded.";
                    if (_fileManager == null)
                    {
                        MessageBox.Show(excelError, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        continue;
                    }

                    String codeString = room.RoomDesc.Substring(codeDot + 1);
                    int code = codeString[3] << 24 | codeString[2] << 16 | codeString[1] << 8 | codeString [0];

                    // get data table
                    DataTable levelFilePathsTable = _fileManager.GetDataTable("LEVEL_FILE_PATHS");
                    if (levelFilePathsTable == null)
                    {
                        MessageBox.Show(excelError, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        continue;
                    }

                    DataRow[] dataRows = levelFilePathsTable.Select(String.Format("code = {0}", code));
                    if (dataRows.Length == 0) throw new Exceptions.UnknownExcelCodeException(code);

                    rootDir = @"data\" + dataRows[0][3].ToString().ToLower();
                }

                // read file
                byte[] fileBytes;
                RoomDefinitionFile roomDefinitionFile;
                if (_fileManager != null)
                {
                    String relativeDirectory = Path.GetDirectoryName(rootDir);
                    Debug.Assert(relativeDirectory != null);
                    String relativePath = Path.Combine(relativeDirectory, roomPathName + RoomDefinitionFile.Extension);
                    fileBytes = _fileManager.GetFileBytes(relativePath);
                    roomDefinitionFile = new RoomDefinitionFile(relativePath);
                }
                else
                {
                    String roomPath = Path.Combine(rootDir, roomPathName + RoomDefinitionFile.Extension);
                    fileBytes = File.ReadAllBytes(roomPath);
                    roomDefinitionFile = new RoomDefinitionFile(roomPath);
                }

                roomDefinitionFile.ParseFileBytes(fileBytes);
                _roomDefinitions.Add(roomPathName, roomDefinitionFile);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// User-friendly uncooking of Tree Node list.
        /// </summary>
        /// <param name="progressForm">A progress form to update.</param>
        /// <param name="param">The Tree Node List.</param>
        private void _DoUnooking(ProgressForm progressForm, Object param)
        {
            List <TreeNode> uncookingNodes     = (List <TreeNode>)param;
            const int       progressUpdateFreq = 20;

            if (progressForm != null)
            {
                progressForm.ConfigBar(1, uncookingNodes.Count, progressUpdateFreq);
            }

            int i = 0;

            foreach (TreeNode treeNode in uncookingNodes)
            {
                NodeObject    nodeObject = (NodeObject)treeNode.Tag;
                PackFileEntry fileEntry  = nodeObject.FileEntry;


                // update progress if applicable
                if (i % progressUpdateFreq == 0 && progressForm != null)
                {
                    progressForm.SetCurrentItemText(fileEntry.Path);
                }
                i++;


                // get the file bytes
                String relativePath = fileEntry.Path;
                byte[] fileBytes;
                try
                {
                    fileBytes = _fileManager.GetFileBytes(fileEntry, true);
                    if (fileBytes == null)
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                    continue;
                }


                // determine file type
                HellgateFile hellgateFile;
                if (relativePath.EndsWith(XmlCookedFile.Extension))
                {
                    hellgateFile = new XmlCookedFile(_fileManager);
                }
                else if (relativePath.EndsWith(RoomDefinitionFile.Extension))
                {
                    hellgateFile = new RoomDefinitionFile(relativePath);
                }
                else if (relativePath.EndsWith(MLIFile.Extension))
                {
                    hellgateFile = new MLIFile();
                }
                else
                {
                    Debug.Assert(false, "wtf");
                    continue;
                }


                // deserialise file
                DialogResult dr       = DialogResult.Retry;
                bool         uncooked = false;
                while (dr == DialogResult.Retry && !uncooked)
                {
                    try
                    {
                        hellgateFile.ParseFileBytes(fileBytes);
                        uncooked = true;
                    }
                    catch (Exception e)
                    {
                        ExceptionLogger.LogException(e, true);

                        String errorMsg = String.Format("Failed to uncooked file!\n{0}\n\n{1}", relativePath, e);
                        dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
                        if (dr == DialogResult.Abort)
                        {
                            return;
                        }
                        if (dr == DialogResult.Ignore)
                        {
                            break;
                        }
                    }
                }
                if (!uncooked)
                {
                    continue;
                }


                // save file
                String relativeSavePath = relativePath.Replace(HellgateFile.Extension, HellgateFile.ExtensionDeserialised);
                String savePath         = Path.Combine(Config.HglDir, relativeSavePath);

                dr = DialogResult.Retry;
                bool   saved         = false;
                byte[] documentBytes = null;
                while (dr == DialogResult.Retry && !saved)
                {
                    try
                    {
                        if (documentBytes == null)
                        {
                            documentBytes = hellgateFile.ExportAsDocument();
                        }
                        File.WriteAllBytes(savePath, documentBytes);
                        saved = true;
                    }
                    catch (Exception e)
                    {
                        ExceptionLogger.LogException(e, true);

                        String errorMsg = String.Format("Failed to save file!\n{0}\n\n{1}", relativePath, e);
                        dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
                        if (dr == DialogResult.Abort)
                        {
                            return;
                        }
                        if (dr == DialogResult.Ignore)
                        {
                            break;
                        }
                    }
                }


                // update tree view
                TreeNode   newTreeNode   = new TreeNode();
                NodeObject newNodeObject = new NodeObject
                {
                    CanEdit           = true,
                    IsUncookedVersion = true
                };
                newTreeNode.Tag = newNodeObject;
                treeNode.Nodes.Add(newTreeNode);
            }
        }