Beispiel #1
0
        public static void read_gene_mapping(string src)
        {
            _GENE_NAME = new List <string>();
            _GENE_ID   = new List <uint>();

            string       line;
            StringReader file = new StringReader(src);

            while ((line = file.ReadLine()) != null)
            {
                if (line.Length == 0)
                {
                    continue;
                }

                string[] eachline = line.Split('\t');
                if (eachline.Length != 2)
                {
                    BugCheck.bug_check(BugCheck.ErrorCode.MON_GENE_MAPPING_CORRUPTED,
                                       "Invalid gene mapping file line:\n" + line);
                }

                _GENE_ID.Add(uint.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber));
                _GENE_NAME.Add(eachline[1]);
            }
            _GENE_NAME.Add("Custom");

            file.Close();
        }
Beispiel #2
0
        private static void read_item_mappings(string src)
        {
            _OFFSET_ID_MAPPING   = new Dictionary <uint, uint>();
            _OFFSET_NAME_MAPPING = new Dictionary <uint, string>();

            string       line;
            StringReader file = new StringReader(src);

            while ((line = file.ReadLine()) != null)
            {
                if (line.Length == 0)
                {
                    continue;
                }

                string[] eachline = line.Split('\t');
                if (eachline.Length != 3)
                {
                    BugCheck.bug_check(BugCheck.ErrorCode.ITEM_MAPPING_CORRUPTED, "Invalid mapping file line:\n" + line);
                }

                _OFFSET_ID_MAPPING.Add(uint.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber), uint.Parse(eachline[1], System.Globalization.NumberStyles.HexNumber));
                _OFFSET_NAME_MAPPING.Add(uint.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber), eachline[2]);
            }

            file.Close();
        }
Beispiel #3
0
 public Model(byte[] save_file)
 {
     if (save_file.Length != SAVE_FILE_SIZE)
     {
         BugCheck.bug_check(BugCheck.ErrorCode.MODEL_INVALID_FILE_SIZE, "Invalid file size.\nExpected: " + SAVE_FILE_SIZE + " Got: " + save_file.Length);
     }
     _save_file = save_file;
 }
Beispiel #4
0
 private uint extract_gene(uint gene_idx)
 {
     if (gene_idx >= 9)
     {
         BugCheck.bug_check(BugCheck.ErrorCode.MON_GENE_IDX_OVERFLOW, "Invalid gene index: " + gene_idx);
     }
     return(Helper.byte_to_uint16_le(_data, _obj_offset + gene_idx * _gene_size));
 }
Beispiel #5
0
 public static uint byte_to_uint16_le(byte[] arr, uint offset)
 {
     if (arr.Length < offset + 2)
     {
         BugCheck.bug_check(BugCheck.ErrorCode.MODEL_READ_UINT16_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " Offset " + offset);
     }
     return(byte_to_uint(arr[offset]) | (byte_to_uint(arr[offset + 1]) << 8));
 }
Beispiel #6
0
        //
        // Genes
        //

        private uint extract_gene(uint gene_idx)
        {
            if (gene_idx >= 9)
            {
                BugCheck.bug_check(BugCheck.ErrorCode.MON_GENE_IDX_OVERFLOW, "Invalid gene index: " + gene_idx);
            }
            return(Model.byte_to_uint16_le(_model.save_file, _offset + OFFSETR_MONSTER_GENE + gene_idx * SIZE_MONSTER_GENE));
        }
Beispiel #7
0
 public static void write_uint16_le(byte[] arr, uint offset, uint val)
 {
     if (arr.Length < offset + 2)
     {
         BugCheck.bug_check(BugCheck.ErrorCode.MODEL_WRITE_UINT16_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " Offset " + offset);
     }
     arr[offset]     = (byte)(val & 0xFF);
     arr[offset + 1] = (byte)((val >> 8) & 0xFF);
 }
Beispiel #8
0
 public static void write_byte(byte[] arr, uint offset, uint val)
 {
     if (offset < arr.Length)
     {
         arr[offset] = (byte)(val & 0xFF);
     }
     else
     {
         BugCheck.bug_check(BugCheck.ErrorCode.MODEL_WRITE_BYTE_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " Offset " + offset);
     }
 }
Beispiel #9
0
 public virtual void setByteArray(byte[] data)
 {
     if (data.Length != _obj_size)
     {
         BugCheck.bug_check(BugCheck.ErrorCode.MODEL_INVALID_FILE_SIZE, "Invalid data size in setByteArray.");
     }
     else
     {
         Array.Copy(data, 0, _data, _obj_offset, _obj_size);
         OnPropertyChanged(null);
     }
 }
Beispiel #10
0
        public static void write_unicode_string(byte[] arr, uint offset, string str, uint length)
        {
            if (length < str.Length || arr.Length < offset + length)
            {
                BugCheck.bug_check(BugCheck.ErrorCode.MODEL_WRITE_UNICODE_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " Offset " + offset);
            }

            Array.Clear(arr, (int)offset, (int)length * 2);
            for (uint i = 0; i < str.Length; i++)
            {
                write_uint16_le(arr, offset + i * 2, str.ElementAt((int)i));
            }
            return;
        }
Beispiel #11
0
 public void init(byte[] save)
 {
     if (save == null)
     {
         BugCheck.bug_check(BugCheck.ErrorCode.VIEWMODEL_NULL_SAVE, "The save file reference is NULL.");
     }
     _model         = save;
     _character     = new Character(_model);
     _items         = Item.read_all_items(_model);
     _monsters      = new ObservableCollection <Monster>(Monster.read_all_monsters(_model));
     _egg_fragments = EggFragment.read_all_egg_fragments(_model);
     _talismans     = Talisman.read_all_talismans(_model);
     _weapons       = Weapon.read_all_weapons(_model);
     _armors        = Armor.read_all_armors(_model);
     _eggs          = Egg.read_all_eggs(_model);
 }
Beispiel #12
0
 private void set_gene(uint gene_idx, uint val)
 {
     if (gene_idx >= 9)
     {
         BugCheck.bug_check(BugCheck.ErrorCode.MON_GENE_IDX_OVERFLOW, "Invalid gene index: " + gene_idx);
     }
     if (val <= 0xFFFF)
     {
         Helper.write_uint16_le(_data, _obj_offset + gene_idx * _gene_size,
                                val);
     }
     else
     {
         MessageBox.Show("Malformed gene value - must be 0x0 to 0xFFFF.", "Error", MessageBoxButton.OK,
                         MessageBoxImage.Error);
     }
 }
Beispiel #13
0
 private void set_gene(uint gene_idx, uint val)
 {
     if (gene_idx >= 9)
     {
         BugCheck.bug_check(BugCheck.ErrorCode.MON_GENE_IDX_OVERFLOW, "Invalid gene index: " + gene_idx);
     }
     if (val <= 0xFFFF)
     {
         Model.write_uint16_le(_model.save_file, _offset + OFFSETR_MONSTER_GENE + gene_idx * SIZE_MONSTER_GENE,
                               val);
     }
     else
     {
         MessageBox.Show("Malformed gene value - must be 0x0 to 0xFFFF.", "Error", MessageBoxButton.OK,
                         MessageBoxImage.Error);
     }
 }
Beispiel #14
0
        public static void read_item_mappings()
        {
            string       line;
            StringReader file = new StringReader(Properties.Resources.idmap);

            while ((line = file.ReadLine()) != null)
            {
                if (line.Length == 0)
                {
                    continue;
                }

                string[] eachline = line.Split('\t');
                if (eachline.Length != 3)
                {
                    BugCheck.bug_check(BugCheck.ErrorCode.ITEM_MAPPING_CORRUPTED, "Invalid mapping file line:\n" + line);
                }

                OFFSET_ID_MAPPING.Add(uint.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber), uint.Parse(eachline[1], System.Globalization.NumberStyles.HexNumber));
                OFFSET_NAME_MAPPING.Add(uint.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber), eachline[2]);
            }

            file.Close();
        }