ReplaceFile() public method

public ReplaceFile ( string qbFilename, QbFile withQbFile ) : void
qbFilename string
withQbFile QbFile
return void
Beispiel #1
0
        public void ResetBonusArt(PakEditor qbPak)
        {
            string storeQb = @"scripts\guitar\store_data.qb.ngc";
            if (_project.GameInfo.Game == Game.GH3_Wii)
                storeQb = storeQb.Substring(1);  //remove first char

            QbFile qbStore = qbPak.ReadQbFile(storeQb);

            this.ResetBonusArt(qbStore);

            qbPak.ReplaceFile(storeQb, qbStore);
        }
Beispiel #2
0
        /// <summary>
        /// Edits tiers using the files in Partition folder
        /// </summary>
        /// <param name="removeBossBattles"></param>
        /// <param name="bonusSongs"></param>
        /// <param name="songCounts"></param>
        public void EditTiers(PakEditor pak, bool removeBossBattles, int setTierCount, int bonusSongs, int[] songCounts, bool unlockTiers)
        {
            QbKey[] nonCareerSongs = new QbKey[0];

            string progQb = @"scripts\guitar\guitar_progression.qb.ngc";
            string coopQb = @"scripts\guitar\guitar_coop.qb.ngc";
            string storeDataQb = @"scripts\guitar\store_data.qb.ngc";
            string songlistQb = @"scripts\guitar\songlist.qb.ngc";
            if (_project.GameInfo.Game == Game.GH3_Wii)
            {
                progQb = progQb.Substring(1);  //remove first char
                coopQb = coopQb.Substring(1);  //remove first char
                storeDataQb = storeDataQb.Substring(1);  //remove first char
                songlistQb = songlistQb.Substring(1);  //remove first char
            }

            if (_project.GameInfo.Game == Game.GH3_Wii || _project.GameInfo.Game == Game.GHA_Wii)
            {
                //add song to song list
                QbFile qbProg = pak.ReadQbFile(progQb);
                QbFile qbCoop = _project.GameInfo.Game == Game.GH3_Wii ? pak.ReadQbFile(coopQb) : null;
                QbFile qbStore = pak.ReadQbFile(storeDataQb);
                QbFile qbSonglist = pak.ReadQbFile(songlistQb);

                this.EditTiers(qbProg, qbStore, qbSonglist, qbCoop, removeBossBattles, setTierCount, bonusSongs, songCounts, unlockTiers);

                pak.ReplaceFile(progQb, qbProg);
                pak.ReplaceFile(storeDataQb, qbStore);
                if (qbCoop != null)
                    pak.ReplaceFile(coopQb, qbCoop);
                pak.ReplaceFile(songlistQb, qbSonglist);
            }
        }
Beispiel #3
0
        public void RemoveIntroVids(PakEditor qbPak)
        {
            string bootupQb = @"scripts\guitar\menu\bootup_menu_flow.qb.ngc";
            if (_project.GameInfo.Game == Game.GH3_Wii)
                bootupQb = bootupQb.Substring(1);  //remove first char

            QbFile qb = qbPak.ReadQbFile(bootupQb);

            this.RemoveIntroVids(qb);

            qbPak.ReplaceFile(bootupQb, qb);
        }
Beispiel #4
0
        /// <summary>
        /// Add new songs to GH3, this method requires that the partition 2 files are on the local disc
        /// </summary>
        public void AddSongs(DirectoryInfo rootPartitionPath, int adjustBy, string sourceSong, bool addNonCareerSongs, DirectoryInfo workingPath)
        {
            PakFormat pf = new PakFormat(string.Format(@"{0}\pak\{1}", rootPartitionPath.FullName, _project.FileManager.PakFormat.PakFilename), string.Empty, string.Empty, PakFormatType.Wii, false);
            PakEditor pe = new PakEditor(pf, false);

            string songlistQb = @"scripts\guitar\songlist.qb.ngc";
            string storeDataQb = @"scripts\guitar\store_data.qb.ngc";
            string guitProgQb = @"scripts\guitar\guitar_progression.qb.ngc";

            if (_project.GameInfo.Game == Game.GH3_Wii)
            {
                songlistQb = songlistQb.Substring(1);  //remove first char
                storeDataQb = storeDataQb.Substring(1);  //remove first char
                guitProgQb = guitProgQb.Substring(1);  //remove first char
            }

            if (_project.GameInfo.Game == Game.GH3_Wii || _project.GameInfo.Game == Game.GHA_Wii)
            {
                //add song to song list
                QbFile qb = pe.ReadQbFile(songlistQb);
                QbFile qbStore = pe.ReadQbFile(storeDataQb);
                QbFile qbGuitProg = pe.ReadQbFile(guitProgQb);

                string silentXbox = createBlankSourceAudio(workingPath);

                QbItemArray songsList = qb.FindItem(QbKey.Create("gh3_songlist"), false) as QbItemArray;

                List<QbKey> careerSongs = getAllCareerSongs(qbGuitProg);
                List<QbKey> bonusSongs = getAllBonusSongs(qbStore);
                List<QbKey> allSongs = new List<QbKey>(careerSongs);
                allSongs.AddRange(bonusSongs);

                //remove the boss battles. If we pick new files from the career then they will be removed anyway
                //QbKey[] bossSongs = new QbKey[] { QbKey.Create("bosstom"), QbKey.Create("bossslash"), QbKey.Create("bossdevil"), QbKey.Create("bossjoe") };
                //foreach (QbKey qk in bossSongs)
                //    careerSongs.Remove(qk);

                //insert the special songs on the end (that aren't in the career)
                List<QbKey> specialSongs = new List<QbKey>();
                foreach (QbKey k in _specialSongs)
                {
                    if (!careerSongs.Contains(k))
                        specialSongs.Add(k);
                }

                if (adjustBy > 0)
                {
                    //Calculate extras
                    int add = adjustBy + (addNonCareerSongs ? _nonCareerSongs.Count : 0);

                    foreach (QbKey k in specialSongs)
                    {
                        if (!bonusSongs.Contains(k))
                        {
                            if (_project.GameInfo.Game == Game.GH3_Wii)
                                add--; //if bonus songs currently doesn't contian this special track then add one less song
                            else
                                add++; //GHA k&qcred will be added from not existing
                        }
                    }
                    add = Math.Max(0, add);

                    List<QbKey> newBonusList = new List<QbKey>();

                    //add the special songs on the end - DO THIS FIRST
                    foreach (QbKey k in specialSongs)
                    {
                        if (!careerSongs.Contains(k))
                            newBonusList.Add(k);
                    }

                    int specialAdded = newBonusList.Count;

                    //find the last _restoresong (a regular-song list in the correct order) in the career
                    int start = -1;
                    for (int i = careerSongs.Count - 1; i >= 0; i--)
                    {
                        start = _restoreSongs.IndexOf(careerSongs[i]);
                        if (start >= 0)
                            break;
                    }

                    if (start != -1)
                    {
                        start++; //move to the next item

                        for (int i = start; i < _restoreSongs.Count; i++)
                        {
                            if (newBonusList.Count >= add + bonusSongs.Count) //add + existing bonussongs = correct count
                                break;

                            if (!careerSongs.Contains(_restoreSongs[i]))
                                newBonusList.Insert(newBonusList.Count - specialAdded, _restoreSongs[i]);
                        }
                    }

                    //nonCareer songs (only on GH3)
                    if (addNonCareerSongs)
                    {
                        for (int i = 0; i < _nonCareerSongs.Count; i++)
                        {
                            if (newBonusList.Count >= add + bonusSongs.Count)
                                break;

                            if (!careerSongs.Contains(_nonCareerSongs[i]))
                                newBonusList.Insert(newBonusList.Count - specialAdded, _nonCareerSongs[i]);
                        }
                    }

                    //add ghost songs
                    int num = 1;
                    while (newBonusList.Count < add + bonusSongs.Count)
                    {
                        QbKey qk = QbKey.Create(string.Format("theghost{0}", (num++).ToString().PadLeft(3, '0')));

                        if (!careerSongs.Contains(qk))
                            newBonusList.Insert(newBonusList.Count - specialAdded, qk);
                    }

                    //remove any bonus songs not in our list
                    foreach (QbKey k in bonusSongs)
                    {
                        if (!newBonusList.Contains(k))
                        {
                            if (!careerSongs.Contains(k))
                                this.BonusSongRemoveFromGame(qbStore, qb, k); //remove from set list also
                            else
                                removeBonusSong(qbStore, k);
                        }
                    }

                    //add all the missing items to the bonus lists
                    foreach (QbKey k in newBonusList)
                    {
                        if (!bonusSongs.Contains(k))
                        {
                            this.BonusSongAddToGame(qbStore, qb, k.Clone(), false);
                            addBonusSongNotes(rootPartitionPath, QbKey.Create(sourceSong), k.Clone(), pe);
                            createBonusSongAudio(rootPartitionPath, silentXbox, k);
                        }
                    }

                    //set the correct order in the store list
                    //find bonus song list
                    QbItemArray qbBonusSongs = qbStore.FindItem(QbKey.Create("songs"), true) as QbItemArray;

                    //add bonus song to list
                    if (qbBonusSongs != null)
                        (qbBonusSongs.Items[0] as QbItemQbKey).Values = newBonusList.ToArray();

                    qbStore.AlignPointers();
                    qbStore.IsValid();
                    qb.AlignPointers();
                    qb.IsValid();

                }
                else if (adjustBy < 0)
                {
                    if (addNonCareerSongs) //adds kings and queens credits if required
                        this.AddBonusSongsFromNonCareer(qbStore, qb, qbGuitProg);

                    bonusSongs = getAllBonusSongs(qbStore);

                    //remove bonus songs that aren't required. keep any required
                    int offset = 0;
                    while (adjustBy != 0 && bonusSongs.Count > 0 && bonusSongs.Count - offset > 0)
                    {
                        int idx = (bonusSongs.Count - offset) - 1;

                        if (bonusSongs[idx].Crc == QbKey.Create("kingsandqueenscredits").Crc
                         || bonusSongs[idx].Crc == QbKey.Create("kingsandqueens").Crc
                         || bonusSongs[idx].Crc == QbKey.Create("thrufireandflames").Crc)
                        {
                            offset++;
                            continue;
                        }

                        if (!careerSongs.Contains(bonusSongs[idx]))
                            this.BonusSongRemoveFromGame(qbStore, qb, bonusSongs[idx]); //remove from set list also
                        else
                            removeBonusSong(qbStore, bonusSongs[idx]);
                        bonusSongs.RemoveAt(idx);
                        adjustBy++;
                    }
                }
                else if (adjustBy == 0 && addNonCareerSongs)
                {
                    this.AddBonusSongsFromNonCareer(qbStore, qb, qbGuitProg);
                }

                qb.AlignPointers();
                qb.IsValid();
                qbStore.AlignPointers();
                qbStore.IsValid();

                FileHelper.Delete(silentXbox);
                pe.ReplaceFile(songlistQb, qb);
                pe.ReplaceFile(storeDataQb, qbStore);
            }
        }
Beispiel #5
0
        private void addBonusSongNotes(DirectoryInfo rootPath, QbKey source, QbKey dest, PakEditor qbPak)
        {
            string srcFolder = string.Format(@"{0}\songs", rootPath.FullName.TrimEnd('\\'));
            string srcMask = string.Format(@"{0}*.pak.ngc", source.Text);

            string[] srcFi = Directory.GetFiles(srcFolder, srcMask, SearchOption.TopDirectoryOnly);

            if (_project.GameInfo.Game == Game.GHA_Wii)
            {
                //GHA holds the section text in the main qb.pak file
                string destNotes = string.Format(@"songs\{0}.mid_text.qb.ngc", dest.Text);
                if (!qbPak.Headers.ContainsKey(destNotes.ToLower()))
                {
                    QbFile qbNotes = qbPak.ReadQbFile(string.Format(@"songs\{0}.mid_text.qb.ngc", source.Text));
                    //copy notes section qb file to new file in qb.pak.ngc
                    qbPak.AddFile(qbNotes, destNotes, QbKey.Create(".qb"), true);
                }
            }

            foreach (string src in srcFi)
            {
                FileInfo srcF = new FileInfo(src);
                string dst = string.Format(@"{0}\{1}{2}", srcF.Directory.FullName.TrimEnd('\\'), dest.Text, srcF.Name.Substring(source.Text.Length));

                //skip if exists
                if (File.Exists(dst) || !Regex.IsMatch(src, string.Format(@"{0}(|_.)\.pak\.ngc$", source.Text))) //only allow "" or _<fgis>
                    continue;

                File.Copy(src, dst, true);

                PakFormat pf = new PakFormat(dst, string.Empty, string.Empty, PakFormatType.Wii, false);
                PakEditor pe = new PakEditor(pf, false);
                string qbDst;
                QbFile qb;
                Dictionary<uint, string> srcQk;
                string dstS;
                foreach (string qbSrc in pe.QbFilenames)
                {
                    qbDst = qbSrc.ToLower().Replace(source.Text.ToLower(), dest.Text.ToLower());
                    pe.RenameFile(qbSrc, qbDst, QbKey.Create(".mqb"));

                    if (!qbSrc.Contains(".mid_text."))
                    {
                        //map the section QbKeys
                        qb = pe.ReadQbFile(qbDst);

                        srcQk = getMidItems(source.Text);
                        foreach (QbItemBase qib in qb.Items)
                        {
                            if (qib.ItemQbKey != null)
                            {
                                if (srcQk.ContainsKey(qib.ItemQbKey.Crc))
                                {
                                    dstS = string.Format("{0}{1}", dest.Text, srcQk[qib.ItemQbKey.Crc].Substring(source.Text.Length));
                                    qib.ItemQbKey = QbKey.Create(dstS);
                                }
                                //else
                                //    throw new ApplicationException("Item QBKey not recognised");
                            }
                        }
                        pe.ReplaceFile(qbDst, qb);
                    }

                }
            }
        }
Beispiel #6
0
        public void UnlockSetlists(PakEditor qbPak, bool unlockAllTiers, bool completeTier1Song)
        {
            string progQb = @"scripts\guitar\guitar_progression.qb.ngc";
            string progCoopQb = @"scripts\guitar\guitar_coop.qb.ngc";

            if (_project.GameInfo.Game == Game.GH3_Wii)
                progQb = progQb.Substring(1);  //remove first char

            if (_project.GameInfo.Game == Game.GH3_Wii)
                progCoopQb = progCoopQb.Substring(1);  //remove first char

            QbFile qb = qbPak.ReadQbFile(progQb);
            QbFile qbCoop = _project.GameInfo.Game == Game.GH3_Wii ? qbPak.ReadQbFile(progCoopQb) : null;
            this.UnlockSetlists(qb, qbCoop, unlockAllTiers, completeTier1Song);

            qbPak.ReplaceFile(progQb, qb);
            if (qbCoop != null)
                qbPak.ReplaceFile(progCoopQb, qbCoop);
        }
Beispiel #7
0
        public void SetCheats(PakEditor qbPak)
        {
            string cheatQb = @"scripts\guitar\menu\menu_cheats.qb.ngc";
            if (_project.GameInfo.Game == Game.GH3_Wii)
                cheatQb = cheatQb.Substring(1);  //remove first char

            QbFile qb = qbPak.ReadQbFile(cheatQb);

            this.SetCheats(qb);

            qbPak.ReplaceFile(cheatQb, qb);
        }
Beispiel #8
0
        private int replaceNotesItems()
        {
            int notesLength = 0; //position of final notes item (last fret)
            QbKey song = this.SongQb.Id;
            string songName = song.Text;

            GameFile gf = _project.FileManager.File(_project.GameInfo.GetNotesFilename(song));

            if (gf == null)
                return notesLength; //return 0, this prevents exceptions in the ISO tool which doesn't replace notes

            string notesPak = gf.LocalName;

            PakFormat pf = new PakFormat(notesPak, "", "", _project.GameInfo.PakFormatType);
            PakEditor pak = new PakEditor(pf);
            QbFile qb = pak.ReadQbFile(_project.GameInfo.GetNotesQbFilename(song));

            //modify the mid file
            //clearAllQbItems(qb, this.Notes.GhItems,
            //    QbKey.Create(string.Format("{0}_TimeSig", songName)),
            //    QbKey.Create(string.Format("{0}_FretBars", songName)),
            //    QbKey.Create(string.Format("{0}_Markers", songName)));

            QbFile qbText;
            if (!_project.GameInfo.MidTextInQbPak)
                qbText = pak.ReadQbFile(_project.GameInfo.GetNotesTextQbFilename(song));
            else
            {
                qbText = _project.FileManager.QbPakEditor.ReadQbFile(_project.GameInfo.GetNotesTextQbFilename(song));
            }

            QbItemArray ar;

            int[] ints;
            int offset;

            //calculate ms to add to wav to ensure notes don't start before the given time (in seconds)
            if (this.Notes.MinNoteOffsetSynced < this.MinMsBeforeNotesStart)
                _startPaddingMs = this.MinMsBeforeNotesStart - this.Notes.MinNoteOffsetSynced;

            this.Length = this.Audio.AudioLength + _startPaddingMs;

            offset = this.Notes.BaseFile.NonNoteSyncOffset + _startPaddingMs;

            int[] frets = (int[])this.Notes.BaseFile.Frets.Clone(); //clone in case class is holding reference
            for (int i = 0; i < frets.Length; i++)
                frets[i] += offset;

            //this function sets _fretPadding, another padding value.  It adds padding to allow a properly spaced fret to be at position 0
            frets = adjustFrets(frets);
            notesLength = frets[frets.Length - 1];

            //set the track length to the notes length if it's longer
            if (this.Length < notesLength)
                this.Length = notesLength;
            else
                this.Length += _fretPadding;

            offset += _fretPadding;

            int[] timeSig = (int[])this.Notes.BaseFile.Parser.GetTimeSig().Clone(); //clone in case class is holding reference

            if (timeSig.Length == 0)
                timeSig = new int[] { 0, 4, 4 };

            for (int i = 0; i < timeSig.Length; i += 3)
                timeSig[i] = (int)findNearestFret((uint)(timeSig[i] + offset), frets);

            timeSig[0] = 0; //if the first item is not 0 the song won't load??.

            NotesMarker[] markers = (NotesMarker[])this.Notes.BaseFile.Parser.GetNotesMarkers().Clone(); //clone in case class is holding reference
            for (int i = 0; i < markers.Length; i += 3)
                markers[i] = new NotesMarker(markers[i].Title, markers[i].Offset + offset); //perform deep clone

            int oldSustainTrigger;
            int sustainTrigger;
            int nextNote;
            int[] faceOffP1Ints = new int[0];
            int[] faceOffP2Ints = new int[0];
            GhNotesItem faceOffItem = null;

            //we have a face off item for each mapping, GH3 only has one per song,  find the one with the hardest difficulty (They're always the same anyway)
            foreach (GhNotesItem ghi in this.Notes.GhItems)
            {
                if (ghi.IsMapped && ghi.MappedFileItem.FaceOffP1Count != 0 && ghi.MappedFileItem.FaceOffP2Count != 0)
                {
                    //non generated overrides generated
                    if (faceOffItem == null || faceOffItem.MappedFileItem.HasGeneratedFaceOff || (ghi.MappedFileItem.HasGeneratedFaceOff == faceOffItem.MappedFileItem.HasGeneratedFaceOff))
                    {
                        if (faceOffItem == null || ((int)faceOffItem.Difficulty < (int)ghi.Difficulty && ghi.Type == NotesType.Guitar)) //guitar is more reliable
                            faceOffItem = ghi;
                    }
                }
            }

            if (faceOffItem != null)
            {
                offset = faceOffItem.MappedFileItem.SyncOffset + _startPaddingMs + _fretPadding;

                faceOffP1Ints = (int[])faceOffItem.MappedFileItem.FaceOffP1.Clone();
                for (int i = 0; i < faceOffP1Ints.Length; i += 2)
                    faceOffP1Ints[i] += offset;

                faceOffP2Ints = (int[])faceOffItem.MappedFileItem.FaceOffP2.Clone();
                for (int i = 0; i < faceOffP2Ints.Length; i += 2)
                    faceOffP2Ints[i] += offset;
            }

            foreach (GhNotesItem ghi in this.Notes.GhItems)
            {
                if (ghi.IsMapped)
                {
                    oldSustainTrigger = ghi.MappedFileItem.SustainTrigger;
                    sustainTrigger = (int)((float)(frets[1] - frets[0]) / 2F);
                    ghi.MappedFileItem.SustainTrigger = sustainTrigger;

                    //Offset notes
                    offset = ghi.MappedFileItem.SyncOffset + _startPaddingMs + _fretPadding;

                    ints = (int[])ghi.MappedFileItem.Notes.Clone(); //don't modify original notes
                    int startFret = 0;
                    for (int i = 0; i < ints.Length; i += 3)
                    {
                        ints[i] += offset;
                        if (i + 3 < ints.Length)
                            nextNote = ints[i + 3] + offset;
                        else
                            nextNote = 0;

                        //loop to find fret length note is in to calculate if note is sustained
                        int fpos;
                        int fretLen = 0;
                        bool isSustained = false;
                        for (int c = startFret; c < frets.Length; c++)
                        {
                            if ((fpos = frets[c]) > ints[i] && c > 0) //careful fpos is assigned here
                            {
                                startFret = c; //next time start from here
                                fretLen = fpos - frets[c - 1];
                                isSustained = ints[i + 1] > ((fretLen / 192.0) * (double)(192 >> 2));  //(fretLen / 192.0 == bpmUnit
                                break;
                            }
                        }
                        //clip sustained notes to GH3 mode
                        if (isSustained)
                            ints[i + 1] = setSustain(ints[i], ints[i + 1], nextNote, oldSustainTrigger / 2, sustainTrigger / 2, this.Notes.Gh3SustainClipping);
                    }
                    int[] notes = ints;

                    //if this is a boss battle then remove notes that are not within the face off sections
                    if (this.IsBoss && faceOffItem != null)
                        ints = convertBossNotesToFaceOff(ints, ghi.Type == NotesType.Guitar ? faceOffP1Ints : faceOffP2Ints);
                    ints = adjustNotes(ints); //merge any notes that are really close together

                    //replace track notes
                    ar = (QbItemArray)qb.FindItem(ghi.SongNotesQbKey, false);
                    replaceQbItems(ar, ints, false);
                    setLength(ar, this.Length, 3, frets, false);

                    //Offset star power
                    ints = (int[])ghi.MappedFileItem.StarPower.Clone(); //don't modify original starpower
                    for (int i = 0; i < ints.Length; i += 3)
                        ints[i] += offset;
                    //if (faceOffItem != null)
                    //    alignBattleStarPowerToFaceOff(ints, ghi.Type == NotesType.Guitar ? faceOffP1Ints : faceOffP2Ints);
                    ints = adjustBattleStarPower(ints, notes);

                    //replace star power
                    ar = (QbItemArray)qb.FindItem(ghi.SongStarPowerQbKey, false);
                    replaceQbItems(ar, this.Notes.ForceNoStarPower ? new int[0] : ints, true); //optionally set to no star power
                    setLength(ar, this.Length, 3, frets, false);

                    int[] sp = ints;

                    //Offset star battle mode
                    ints = (int[])ghi.MappedFileItem.BattlePower.Clone();
                    for (int i = 0; i < ints.Length; i += 3)
                        ints[i] += offset;
                    //if (faceOffItem != null)
                    //    alignBattleStarPowerToFaceOff(ints, ghi.Type == NotesType.Guitar ? faceOffP1Ints : faceOffP2Ints);
                    ints = adjustBattleStarPower(ints, notes);

                    if (ints.Length == 0) //if no ints then use star power
                        ints = (int[])sp.Clone(); //just to ensure there's no issue with 2 references pointing at the same array

                    //replace star battle notes
                    ar = (QbItemArray)qb.FindItem(ghi.SongStarPowerBattleQbKey, false);
                    replaceQbItems(ar, ints, true);
                    setLength(ar, this.Length, 3, frets, false);

                }
                else
                {
                    ar = (QbItemArray)qb.FindItem(ghi.SongNotesQbKey, false);
                    clearQbItems(ar);
                    ar = (QbItemArray)qb.FindItem(ghi.SongStarPowerQbKey, false);
                    clearQbItems(ar);
                    ar = (QbItemArray)qb.FindItem(ghi.SongStarPowerBattleQbKey, false);
                    clearQbItems(ar);
                }
            }

            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Song_GuitarCoop_{1}", songName, NotesDifficulty.Easy.ToString())), false);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Song_GuitarCoop_{1}", songName, NotesDifficulty.Medium.ToString())), false);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Song_GuitarCoop_{1}", songName, NotesDifficulty.Hard.ToString())), false);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Song_GuitarCoop_{1}", songName, NotesDifficulty.Expert.ToString())), false);
            clearQbItems(ar);

            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Song_RhythmCoop_{1}", songName, NotesDifficulty.Easy.ToString())), false);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Song_RhythmCoop_{1}", songName, NotesDifficulty.Medium.ToString())), false);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Song_RhythmCoop_{1}", songName, NotesDifficulty.Hard.ToString())), false);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Song_RhythmCoop_{1}", songName, NotesDifficulty.Expert.ToString())), false);
            clearQbItems(ar);

            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_BossBattleP1", songName)), false);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_BossBattleP2", songName)), false);
            clearQbItems(ar);

            //start with expert guitar and work down the difficulties to find a GHItem with Face off, copy in to BOss Battle also

            if (faceOffItem != null)
            {
                QbItemArray fo1 = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_FaceOffP1", songName)), false);
                QbItemArray fo2 = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_FaceOffP2", songName)), false);
                if (faceOffItem.IsMapped && faceOffItem.MappedFileItem != null && faceOffItem.MappedFileItem.FaceOffP1Count + faceOffItem.MappedFileItem.FaceOffP2Count != 0)
                {
                    faceOffP1Ints = adjustFaceOff(faceOffP1Ints);
                    replaceQbItems(fo1, faceOffP1Ints, true, 2);

                    //ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_BossBattleP1", songName)), false);
                    //replaceQbItems(ar, faceOffP1Ints, true, 2);

                    faceOffP2Ints = adjustFaceOff(faceOffP2Ints);
                    replaceQbItems(fo2, faceOffP2Ints, true, 2);

                    //ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_BossBattleP2", songName)), false);
                    //replaceQbItems(ar, faceOffP2Ints, true, 2);
                }
                else
                {
                    clearQbItems(fo1);
                    clearQbItems(fo2);
                }

            }

            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_TimeSig", songName)), false);
            replaceQbItems(ar, timeSig, true);
            setLength(ar, this.Length, 3, frets, false);

            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_FretBars", songName)), false);
            replaceQbItems(ar, frets, false);

            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Markers", songName)), false);
            if (markers.Length != 0)
                setMarkers(frets, ar, qbText, markers);
            else
                calculateMarkers(frets, ar, qbText);

            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Scripts_Notes", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Anim_Notes", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Triggers_Notes", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Cameras_Notes", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Lightshow_Notes", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Crowd_Notes", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Drums_Notes", songName)), false);
            ////setLength(ar, this.Length, 3, frets, true);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Performance_Notes", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);

            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Scripts", songName)), false);
            if (this.SongQb.IsBoss) //set the death drain marker to the correct location
                setDeathDrain(ar, markers);
            else
                setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Anim", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Triggers", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Cameras", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Lightshow", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Crowd", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Drums", songName)), false);
            ////setLength(ar, this.Length, 3, frets, true);
            clearQbItems(ar);
            ar = (QbItemArray)qb.FindItem(QbKey.Create(string.Format("{0}_Performance", songName)), false);
            setLength(ar, this.Length, 3, frets, true);
            //clearQbItems(ar);

            qb.AlignPointers();
            qb.IsValid();
            qbText.AlignPointers();
            qbText.IsValid();

            long origPakLen = pak.FileLength;
            string tmpPak = string.Format("{0}_{1}", notesPak, Guid.NewGuid().ToString("N"));
            File.Copy(notesPak, tmpPak);

            if (_project.GameInfo.MidTextInQbPak)
            {
                //save markers to qbPak
                _project.FileManager.QbPakEditor.ReplaceFile(_project.GameInfo.GetNotesTextQbFilename(song), qbText);
            }
            else //save markers to mid pak
            {
                pak.ReplaceFile(_project.GameInfo.GetNotesTextQbFilename(song), qbText);
            }

            //replace notes to mid pak
            pak.ReplaceFile(_project.GameInfo.GetNotesQbFilename(song), qb);

            //pad notes pak with original file
            //add padding to ensure song works - This took over a month of testing to find!!
            //////////using (FileStream fs = new FileStream(notesPak, FileMode.Open, FileAccess.ReadWrite))
            //////////{

            //////////    using (FileStream fsI = new FileStream(tmpPak, FileMode.Open, FileAccess.Read))
            //////////    {
            //////////        fs.Seek(0, SeekOrigin.End);

            //////////        string tag = " -=> NANOOK <=-  PADDING BELOW  ";
            //////////        if (fs.Position + tag.Length < fsI.Length)
            //////////            fs.Write(Encoding.Default.GetBytes(tag), 0, tag.Length);

            //////////        if (fs.Position < fsI.Length)
            //////////        {
            //////////            fsI.Seek(fs.Position, SeekOrigin.Begin);
            //////////            copy(fsI, fs, fsI.Length - fsI.Position);
            //////////        }

            //////////    }
            //////////}

            FileHelper.Delete(tmpPak);

            return notesLength;
        }