Exemple #1
0
 internal BFFile(BFCodeLabel[] procedures, BFCodeLabel[] jumpLabels, List<BFOpcode> opcodes, BMDFile messageFile = null)
 {
     _procedures = procedures;
     _jumpLabels = jumpLabels;
     _opcodes = opcodes;
     _messageFile = messageFile;
 }
Exemple #2
0
        public static BMDFile CompileScript(string path)
        {
            BMDFile bmd = new BMDFile();

            List<BMDMessage> msgs = new List<BMDMessage>();
            using (reader = new StreamReader(path))
            {
                while (!reader.EndOfStream)
                {
                    ReadLine();

                    string[] tokens = curLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    if (tokens.Length == 0)
                        continue;

                    if (tokens[0] == "messagebox" || tokens[0] == "selection")
                        msgs.Add(ParseMsg());
                }
            }

            bmd.ActorNames = actorNameList.ToArray();
            bmd.Messages = msgs.ToArray();

            return bmd;
        }
Exemple #3
0
 public static void Decompile(BMDFile bmd, string path)
 {
     using (StreamWriter writer = new StreamWriter(path))
     {
         foreach (BMDMessage dlg in bmd.Messages)
         {
             DecompileMessage(writer, dlg);
         }
     }
 }
Exemple #4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("No input specified.");
                Console.WriteLine("Usage:");
                Console.WriteLine(" Enter path to BMD file to convert BMD file to XML.");
                Console.WriteLine(" Enter path to XML file to convert XML file to BMD.");
                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
                return;
            }

            if (args[0].EndsWith(".BMD", StringComparison.InvariantCultureIgnoreCase))
            {
                BMDFile msg = new BMDFile(args[0]);

                if (msg == null)
                {
                    Console.WriteLine("Could not read BMD.");
                    Console.ReadKey();
                    return;
                }

                //msg.SaveXml(args[0] + ".XML");
            }
            else if (args[0].EndsWith(".XML", StringComparison.InvariantCultureIgnoreCase))
            {
                BMDFile msg;
                try
                {
                    msg = new BMDFile(args[0]);
                }
                catch (InvalidDataException)
                {
                    Console.WriteLine("Xml header element name mismatch.\nAre you sure the xml was exported by this tool?");
                    Console.ReadKey();
                    return;
                }

                msg.Save(args[0].Replace(".XML", ".BMD"));
            }
        }
Exemple #5
0
        private void InternalRead(BinaryReader reader)
        {
            long posFileStart = reader.GetPosition();
            short flag = reader.ReadInt16();
            short userID = reader.ReadInt16();
            int length = reader.ReadInt32();
            string tag = reader.ReadCString(4);
            int unused = reader.ReadInt32();

            if (tag != TAG)
            {
                throw new InvalidDataException("Identifier mismatch.");
            }

            int numTypeTableEntries = reader.ReadInt32();
            int numUnknown = reader.ReadInt32();

            reader.AlignPosition(16);

            TypeTableEntry[] typeTable = new TypeTableEntry[numTypeTableEntries];
            for (int i = 0; i < numTypeTableEntries; i++)
            {
                typeTable[i] = new TypeTableEntry(reader);
            }

            System.Diagnostics.Debug.Assert(typeTable[(int)TypeTableType.Strings].elementCount == 0xF0);

            for (int i = 0; i < numTypeTableEntries; i++)
            {
                reader.Seek(posFileStart + typeTable[i].dataOffset, SeekOrigin.Begin);

                switch ((TypeTableType)typeTable[i].type)
                {
                    case TypeTableType.Procedures:
                        ReadCodeLabels(reader, ref _procedures, typeTable[i].elementCount, out _requireSortProcedures);
                        break;
                    case TypeTableType.JumpLabels:
                        ReadCodeLabels(reader, ref _jumpLabels, typeTable[i].elementCount, out _requireSortJumps);
                        break;
                    case TypeTableType.Opcodes:
                        {
                            bool hasExtendedOpcodes;
                            _opcodes = BFDisassembler.ParseCodeblock(reader.ReadUInt32Array(typeTable[i].elementCount), out hasExtendedOpcodes);

                            if (hasExtendedOpcodes) // only fix up the opcode indices if they have to be
                                FixupOpcodeIndices(); // this function is kinda 2*O(n^2)
                        }
                        break;
                    case TypeTableType.Messages:
                        if (typeTable[i].elementCount > 0)
                            _messageFile = new BMDFile(StreamHelper.ReadStream(reader, typeTable[i].elementCount), false);
                        break;
                    case TypeTableType.Strings:
                        // TODO: Implement this
                        break;
                }
            }
        }
Exemple #6
0
 public static BFFile AssembleFromBFASM(string path, BMDFile messageDialog = null)
 {
     BFFile bf = BFAssembler.AssembleFromASMText(path);
     bf._messageFile = messageDialog;
     return bf;
 }