Esempio n. 1
0
        void LoadBanks(string fileName)
        {
            StreamReader reader = new StreamReader(fileName);

            try
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    line = line.Trim();
                    BankDescription newBank = BankDescription.Parse(line);
                    if (newBank != null)
                    {
                        banks.Add(newBank);
                    }
                }
            }
            catch (Exception ex)
            {
                EmulationState.messages.AppendMessage("Failed to level name file!\nException was:\n" + ex.ToString(), "Error");
            }
            finally
            {
                reader.Close();
            }
        }
Esempio n. 2
0
 static bool LOAD_BANK(byte[] commandBytes)
 {
     if (current != null)
     {
         current.loadedBanks.Add(BankDescription.Parse(commandBytes));
     }
     return(true);
 }
Esempio n. 3
0
        public static BankDescription Parse(byte[] commandBytes)
        {
            if (commandBytes.Length < 0xC || commandBytes.Length != commandBytes[1])
            {
                throw new ArgumentException("Invalid command bytes!");
            }
            BankDescription output = new BankDescription();

            output.compressed = commandBytes[0] != 0x17;
            output.arg        = commandBytes[2];
            output.ID         = commandBytes[3];
            output.ROM_Start  = cvt.uint32(commandBytes, 4);
            output.ROM_End    = cvt.uint32(commandBytes, 8);
            return(Editor.projectSettings.UpdateBank(output));
        }
Esempio n. 4
0
 public BankDescription UpdateBank(BankDescription bankDescription)
 {
     foreach (BankDescription bank in banks)
     {
         if (bank.ROM_Start == bankDescription.ROM_Start)
         {
             bank.ROM_End    = bankDescription.ROM_End;
             bank.ID         = bankDescription.ID;
             bank.arg        = bankDescription.arg;
             bank.compressed = bankDescription.compressed;
             return(bank);
         }
     }
     bankDescription.name = "<Unknown>";
     banks.Add(bankDescription);
     return(bankDescription);
 }
Esempio n. 5
0
        void WriteLevelData()
        {
            foreach (LevelBankDescription bank in new LevelBankDescription[] { bank0x5, bank0x6, bank0x9 })
            {
                if (bank == null)
                {
                    continue;
                }
                byte[][] cmd17;
                if (bank.commandBytes.TryGetValue("cmd17", out cmd17))
                {
                    foreach (byte[] cmd in cmd17)
                    {
                        BankDescription newDescription = BankDescription.Parse(cmd);
                        foreach (BankDescription desc in new List <BankDescription>(Editor.currentLevel.loadedBanks))
                        {
                            if (desc.ID == newDescription.ID)
                            {
                                Editor.currentLevel.loadedBanks.Remove(desc);
                            }
                        }
                        Editor.currentLevel.loadedBanks.Add(newDescription);
                        SM64RAM.EmulationState.instance.banks[newDescription.ID] = new SM64RAM.EmulationState.RAMBank(newDescription.ID, (int)newDescription.ROM_Start, (int)newDescription.ROM_End, cmd[0] != 0x17);
                    }
                }
                byte[][] cmd1A;
                if (bank.commandBytes.TryGetValue("cmd1a", out cmd1A))
                {
                    foreach (byte[] cmd in cmd1A)
                    {
                        BankDescription newDescription = BankDescription.Parse(cmd);
                        foreach (BankDescription desc in new List <BankDescription>(Editor.currentLevel.loadedBanks))
                        {
                            if (desc.ID == newDescription.ID)
                            {
                                Editor.currentLevel.loadedBanks.Remove(desc);
                            }
                        }
                        Editor.currentLevel.loadedBanks.Add(newDescription);
                        SM64RAM.EmulationState.instance.banks[newDescription.ID] = new SM64RAM.EmulationState.RAMBank(newDescription.ID, (int)newDescription.ROM_Start, (int)newDescription.ROM_End, true);
                    }
                }
                byte[][] cmd22;
                if (bank.commandBytes.TryGetValue("cmd22", out cmd22))
                {
                    foreach (byte[] cmd in cmd22)
                    {
                        Editor.currentLevel.AddLevelGeo(cmd[3], Level.modelIDs[cmd[3]] = GeoLayout.LoadSegmented(SM64RAM.cvt.int32(cmd, 4)));
                    }
                }

                byte[][] cmd06;
                if (bank.commandBytes.TryGetValue("cmd06", out cmd06))
                {
                    foreach (byte[] cmd in bank.commandBytes["cmd06"])
                    {
                        Editor.currentLevel.ReadJump(cmd);
                    }
                }
                Editor.currentLevel.CleanLevelGeos();
            }
        }
Esempio n. 6
0
        public static BankDescription Parse(string str)
        {
            BankDescription output = new BankDescription();

            string[] split = str.Split(new string[] { ":=" }, StringSplitOptions.None);
            if (split.Length != 2)
            {
                return(null);
            }
            string[] rangeSplit = split[1].Split('-');
            if (rangeSplit.Length != 2)
            {
                return(null);
            }
            string[] typeSplit = rangeSplit[1].Split('(');
            if (typeSplit.Length == 2)
            {
                string argString = typeSplit[1].Trim();
                if (argString.EndsWith(")"))
                {
                    argString = argString.Substring(0, argString.Length - 1);
                    string[] args = argString.Split(',');
                    if (args.Length != 2)
                    {
                        return(null);
                    }
                    string typeString = args[0].Trim().ToLower();
                    if (typeString.StartsWith("0x"))
                    {
                        if (!byte.TryParse(typeString.Substring(2), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out output.ID))
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        object enumEntry = Enum.Parse(typeof(BankType), typeString, true);
                        if (enumEntry == null)
                        {
                            return(null);
                        }
                        else
                        {
                            output.ID = (byte)enumEntry;
                        }
                    }
                    string compString = args[1].Trim().ToLower();
                    if (compString == "compressed")
                    {
                        output.compressed = true;
                    }
                    else if (compString == "uncompressed")
                    {
                        output.compressed = false;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            if (!uint.TryParse(typeSplit[0].Trim().Substring(2), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out output.ROM_End))
            {
                return(null);
            }
            if (!uint.TryParse(rangeSplit[0].Trim().Substring(2), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out output.ROM_Start))
            {
                return(null);
            }
            output.name = split[0];
            return(output);
        }
Esempio n. 7
0
 public BankWrapper(BankDescription bank)
 {
     this.bank = bank;
 }