Beispiel #1
0
        private void SaveSavButton_Click(object sender, EventArgs e)
        {
            // time
            Sav.SavTime.Days.Value    = Convert.ToInt32(DaysTextBox.Text);
            Sav.SavTime.Hours.Value   = Convert.ToInt32(HoursTextBox.Text);
            Sav.SavTime.Minutes.Value = Convert.ToInt32(MinutesTextBox.Text);

            // instances
            string name;
            int    told;

            Sav.Instances.Items = new List <InstVar>();
            foreach (string s in InstancesTextBox.Lines)
            {
                if (!String.IsNullOrEmpty(s))
                {
                    name = Regex.Replace(s, "=.*", "");
                    told = Convert.ToInt32(Regex.Replace(s, ".*=", ""));
                    Sav.Instances.Items.Add(GothicGenerator.GenerateInstVar(name, told));
                }
            }

            Sav.Save(SavPathLabel.Text);
            MessageBox.Show("Saved");
        }
Beispiel #2
0
        public void Save(string FilePath)
        {
            MemoryStream sav_stream = new MemoryStream();
            BinaryWriter sav        = new BinaryWriter(sav_stream);
            int          index      = 0; // 0x00

            // prepare new symbols list
            SymData symbols = new SymData();

            // head
            sav.Write(this.SavHead);

            // post head ints
            sav.Write(this.PostHeadInts[0]);
            sav.Write(this.PostHeadInts[1]);
            int symbols_address = (int)sav_stream.Position;

            sav.Write((int)0);

            // time days
            int days_index = index++; // 0x00

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)days_index, 0, "day"));
            sav.Write(this.SavTime.Days.FirstByte);
            sav.Write(days_index);
            sav.Write(this.SavTime.Days.DelimeterByte);
            sav.Write(this.SavTime.Days.Value);
            // time hours
            int hours_index = index++; // 0x01

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)hours_index, 0, "hour"));
            sav.Write(this.SavTime.Hours.FirstByte);
            sav.Write(hours_index);
            sav.Write(this.SavTime.Hours.DelimeterByte);
            sav.Write(this.SavTime.Hours.Value);
            // time minutes
            int minutes_index = index++; // 0x02

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)minutes_index, 0, "min"));
            sav.Write(this.SavTime.Minutes.FirstByte);
            sav.Write(minutes_index);
            sav.Write(this.SavTime.Minutes.DelimeterByte);
            sav.Write(this.SavTime.Minutes.Value);

            // instances
            int num_of_entries_index = index++; // 0x03

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)num_of_entries_index, 0, "NumOfEntries"));
            sav.Write(this.Instances.InstancesCount.FirstByte);
            sav.Write(num_of_entries_index);
            sav.Write(this.Instances.InstancesCount.DelimeterByte);
            sav.Write(this.Instances.Items.Count);
            int told_index      = index++; // 0x04
            int inst_name_index = index++; // 0x05

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)told_index, 0, "Told"));
            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)inst_name_index, 0, "InstName"));
            foreach (InstVar inst_var in this.Instances.Items)
            {
                // told
                sav.Write(inst_var.Told.FirstByte);
                sav.Write(told_index);
                sav.Write(inst_var.Told.DelimeterByte);
                sav.Write(inst_var.Told.Value);
                // inst name
                sav.Write(inst_var.CaptionLength.FirstByte);
                sav.Write(inst_name_index);
                sav.Write(inst_var.CaptionLength.DelimeterByte);
                sav.Write((short)inst_var.CaptionLength.Value);
                // caption
                sav.Write(inst_var.CaptionBytes);
            }

            // journal
            int quests_count_index = index++; // 0x06

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)quests_count_index, 0, "LOGMANAGERTOPICCOUNT"));
            // journal entries var
            sav.Write(this.Journal.EntriesVar.FirstByte);
            sav.Write(num_of_entries_index);
            sav.Write(this.Journal.EntriesVar.DelimeterByte);
            sav.Write(this.Journal.EntriesVar.Value);
            // journal entries count
            sav.Write(this.Journal.QuestsCount.FirstByte);
            sav.Write(quests_count_index);
            sav.Write(this.Journal.QuestsCount.DelimeterByte);
            sav.Write(this.Journal.Quests.Count);
            // quests
            int quest_caption_index     = index++;      // 0x07
            int topic_description_index = index++;      // 0x08
            int topic_section_index     = index++;      // 0x09
            int topic_status_index      = index++;      // 0x0A
            int quest_notes_count_index = index++;      // 0x0B
            int quest_note_length_index = index++;      // 0x0C

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)quest_caption_index, 0, "TOPICDESCRIPTION"));
            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)topic_description_index, 0, "TOPICSECTION"));
            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)topic_section_index, 0, "TOPICSTATUS"));
            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)topic_status_index, 0, "LOGTOPICENTRYCOUNT"));
            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)quest_notes_count_index, 0, "LOGMANAGERENTRYCOUNT"));
            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)quest_note_length_index, 0, "ENTRYDESCRIPTION"));
            foreach (Quest quest in this.Journal.Quests)
            {
                // quest caption
                sav.Write(quest.CaptionLength.FirstByte);
                sav.Write(quest_caption_index);
                sav.Write(quest.CaptionLength.DelimeterByte);
                sav.Write((short)quest.CaptionLength.Value);
                sav.Write(quest.CaptionBytes);
                // quest topic description
                sav.Write(quest.TopicDecription.FirstByte);
                sav.Write(topic_description_index);
                sav.Write(quest.TopicDecription.DelimeterByte);
                sav.Write(quest.TopicDecription.Value);
                // quest topic section
                sav.Write(quest.TopicSection.FirstByte);
                sav.Write(topic_section_index);
                sav.Write(quest.TopicSection.DelimeterByte);
                sav.Write(quest.TopicSection.Value);
                // quest topic status
                sav.Write(quest.TopicStatus.FirstByte);
                sav.Write(topic_status_index);
                sav.Write(quest.TopicStatus.DelimeterByte);
                sav.Write(quest.TopicStatus.Value);
                // quest notes count
                sav.Write(quest.NotesCount.FirstByte);
                sav.Write(quest_notes_count_index);
                sav.Write(quest.NotesCount.DelimeterByte);
                sav.Write(quest.Notes.Count);
                // quest notes
                foreach (QuestNote quest_note in quest.Notes)
                {
                    // note length
                    sav.Write(quest_note.NoteLength.FirstByte);
                    sav.Write(quest_note_length_index);
                    sav.Write(quest_note.NoteLength.DelimeterByte);
                    sav.Write((short)quest_note.NoteLength.Value);
                    // note
                    sav.Write(quest_note.NoteBytes);
                }
            }

            // CCSManager
            int pool_count_index = index++; // 0x0D

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)pool_count_index, 0, "poolCount"));
            // CCSManager begin block
            sav.Write(this.CCSManagerBlock.BeginBlockLength.FirstByte);
            sav.Write(this.CCSManagerBlock.BeginBlockLength.Value);
            sav.Write(this.CCSManagerBlock.BeginBlockBytes);
            // CCSManager poll count
            sav.Write(this.CCSManagerBlock.PoolCount.FirstByte);
            sav.Write(pool_count_index);
            sav.Write(this.CCSManagerBlock.PoolCount.DelimeterByte);
            sav.Write(this.CCSManagerBlock.PoolCount.Value);
            // CCSManager end block
            sav.Write(this.CCSManagerBlock.EndBlockLength.FirstByte);
            sav.Write(this.CCSManagerBlock.EndBlockLength.Value);
            sav.Write(this.CCSManagerBlock.EndBlockBytes);

            // dialogs
            int num_symbols_index = index++; // 0x0E

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)num_symbols_index, 0, "numSymbols"));
            // dialogs count (numSymbols)
            sav.Write(this.Dialogs.DialogsCount.FirstByte);
            sav.Write(num_symbols_index);
            sav.Write(this.Dialogs.DialogsCount.DelimeterByte);
            sav.Write(this.Dialogs.Items.Count);
            foreach (VarStruct dialog in this.Dialogs.Items)
            {
                // dialog caption length
                sav.Write(dialog.CaptionLength.FirstByte);
                sav.Write(index++);
                sav.Write(dialog.CaptionLength.DelimeterByte);
                sav.Write((short)dialog.CaptionLength.Value);
                // dialog caption
                sav.Write(dialog.CaptionBytes);
                // dialog vars count
                sav.Write(dialog.VarValuesCount.FirstByte);
                sav.Write(index++);
                sav.Write(dialog.VarValuesCount.DelimeterByte);
                sav.Write(dialog.VarValues.Count);
                // dialog vars
                foreach (IntVar int_var in dialog.VarValues)
                {
                    sav.Write(int_var.FirstByte);
                    sav.Write(index++);
                    sav.Write(int_var.DelimeterByte);
                    sav.Write(int_var.Value);
                }
            }

            // guilds
            int guild_table_index = index++; // ~ 0x215A

            symbols.Items.Add(GothicGenerator.GenerateSymItem((short)guild_table_index, 0, "guildTable"));
            // guilds table cells count
            sav.Write(this.Guilds.CellsCount.FirstByte);
            sav.Write(guild_table_index);
            sav.Write(this.Guilds.CellsCount.DelimeterByte);
            sav.Write(this.Guilds.CellsCount.Value);
            // guilds table
            sav.Write(this.Guilds.ContentArray);
            int symbols_address_value = (int)sav_stream.Position;

            // symbols

            /* // write new items
             * sav.Write(symbols.Items.Count + Dialogs.SubItemsCount());
             * foreach (SymItem sym_item in symbols.Items)
             * {
             *  sav.Write(sym_item.CaptionLength);
             *  sav.Write(sym_item.VarLink);
             *  sav.Write((int)0);
             *  sav.Write(sym_item.CaptionBytes);
             * }
             * string symName;
             * string symNameCnt;
             * string symValue;
             * int symIndex = 0;
             * int symValueIndex = 0;
             * SymItem new_sym_item;
             * foreach (VarStruct dialog in Dialogs.Items)
             * {
             *  // symName0
             *  symName = "symName" + symIndex.ToString();
             *  new_sym_item = GothicGenerator.GenerateSymItem((short)dialog.CaptionLength.VarIndex, 0, symName);
             *  sav.Write(new_sym_item.CaptionLength);
             *  sav.Write(new_sym_item.VarLink);
             *  sav.Write((int)0);
             *  sav.Write(new_sym_item.CaptionBytes);
             *  // symName0cnt
             *  symNameCnt = symName + "cnt";
             *  new_sym_item = GothicGenerator.GenerateSymItem((short)dialog.VarValuesCount.VarIndex, 0, symNameCnt);
             *  sav.Write(new_sym_item.CaptionLength);
             *  sav.Write(new_sym_item.VarLink);
             *  sav.Write((int)0);
             *  sav.Write(new_sym_item.CaptionBytes);
             *  // symValue0_0
             *  symValueIndex = 0;
             *  foreach (IntVar dialog_var in dialog.VarValues)
             *  {
             *      symValue = "symValue" + symIndex.ToString() + "_" + symValueIndex.ToString();
             *      new_sym_item = GothicGenerator.GenerateSymItem((short)dialog_var.VarIndex, 0, symValue);
             *      sav.Write(new_sym_item.CaptionLength);
             *      sav.Write(new_sym_item.VarLink);
             *      sav.Write((int)0);
             *      sav.Write(new_sym_item.CaptionBytes);
             *      symValueIndex++;
             *  }
             *  symIndex++;
             * }
             */

            // write readed items
            //Symbols.Items.Sort((x, y) => x.VarLink.CompareTo(y.VarLink));
            sav.Write(Symbols.Count);
            foreach (SymItem symbols_item in Symbols.Items)
            {
                sav.Write(symbols_item.CaptionLength);
                sav.Write(symbols_item.VarLink);
                sav.Write(symbols_item.StrangeInt);
                sav.Write(symbols_item.CaptionBytes);
            }

            // save symbols array address
            sav.Seek(symbols_address, SeekOrigin.Begin);
            sav.Write(symbols_address_value);

            // save results to file
            File.WriteAllBytes(FilePath, sav_stream.ToArray());
        }