/// <summary>
        /// return a list all tagRefs mentioned in the meta and the extended meta
        /// </summary>
        /// <returns></returns>
        public List <tagRef> Get_all_tag_refs()
        {
            List <tagRef> ret = new List <tagRef>();

            //first i add all my the tagRefs in the concerned meta
            foreach (int temp_off in ref_tags)
            {
                string type       = DATA_READ.ReadTAG_TYPE(temp_off, data);
                int    temp_datum = DATA_READ.ReadINT_LE(temp_off + 4, data);

                //i only list them if they are valid
                if (temp_datum != -1)
                {
                    tagRef temp_tagref = new tagRef();
                    temp_tagref.type        = type;
                    temp_tagref.datum_index = temp_datum;

                    ret.Add(temp_tagref);
                }
            }
            //list_extended object is only created when we are reading from a map
            if (list_extended != null)
            {
                //then we add the extended_meta dependencies
                List <int> key_list = list_extended.Keys.ToList <int>();
                foreach (int temp_key in key_list)
                {
                    extended_meta temp_meta = list_extended[temp_key];
                    ret.AddRange(temp_meta.Get_all_tag_refs());
                }
            }
            //listing the WCtagRefs
            //we can only do this when we are reading from a map
            if (map_stream != null)
            {
                //some meta reading prologue
                int table_off   = DATA_READ.ReadINT_LE(0x10, map_stream);
                int table_start = table_off + 0xC * DATA_READ.ReadINT_LE(table_off + 4, map_stream) + 0x20;

                foreach (int temp_off in ref_WCtags)
                {
                    int temp_datum = DATA_READ.ReadINT_LE(temp_off, data);//we read it from meta data
                    if (temp_datum != -1)
                    {
                        string type = DATA_READ.ReadTAG_TYPE(table_start + (0xFFFF & temp_datum) * 0x10, map_stream);//we read this from map stream

                        tagRef temp_WCtagref = new tagRef();
                        temp_WCtagref.datum_index = temp_datum;
                        temp_WCtagref.type        = type;

                        ret.Add(temp_WCtagref);
                    }
                }
            }

            return(ret);
        }
        /// <summary>
        /// use to rebase current meta data to a newer memory address(affects reflexive,extended and data ref fields only)
        /// </summary>
        /// <param name="new_base">the new memory address to which the meta has to rebased</param>
        public void Rebase_meta(int new_base)
        {
            //first rebase reflexive fields
            foreach (int off in ref_reflexive)
            {
                int old_mem_addr = DATA_READ.ReadINT_LE(off + 4, data);
                int new_mem_addr = new_base + (old_mem_addr - mem_off);

                DATA_READ.WriteINT_LE(new_mem_addr, off + 4, data);
            }
            //then we rebase all the dataref fields
            foreach (int off in ref_data)
            {
                int old_mem_addr = DATA_READ.ReadINT_LE(off + 4, data);
                int new_mem_addr = new_base + (old_mem_addr - mem_off);

                DATA_READ.WriteINT_LE(new_mem_addr, off + 4, data);
            }
            //we venture in extended meta if it is even concerned
            if (list_extended != null)
            {
                //for extended meta stuff we are gonna first rebase the extended meta(s) first and set the offsets accordingly
                //well extende meta are gonna follow meta one by one
                int extended_new_base = new_base + size;

                List <int> key_mems = list_extended.Keys.ToList <int>();
                //Rebase extended meta
                foreach (int temp_key in key_mems)
                {
                    extended_meta temp_meta = list_extended[temp_key];
                    temp_meta.Rebase_meta(extended_new_base);

                    extended_new_base += temp_meta.Get_Total_size();
                }
                //now lets update the offsets with the newer values
                List <int> extend_off = ref_extended.Keys.ToList <int>();
                foreach (int temp_off in extend_off)
                {
                    int           extend_mem_addr = ref_extended[temp_off];
                    extended_meta temp_ext        = list_extended[extend_mem_addr];

                    int new_mem_addr = temp_ext.Get_mem_addr();

                    DATA_READ.WriteINT_LE(new_mem_addr, temp_off + 4, data);
                }
            }

            //update the base to which meta has been compiled
            mem_off = new_base;
        }
        /// <summary>
        /// returns the total size of the meta along with all extended meta sizes
        /// </summary>
        /// <returns></returns>
        public int Get_Total_size()
        {
            int Tsize = size;
            //lets add the extended meta sizes
            List <int> key_mems = list_extended.Keys.ToList <int>();

            foreach (int temp_key in key_mems)
            {
                extended_meta temp_meta = list_extended[temp_key];
                Tsize += temp_meta.Get_Total_size();
            }

            return(Tsize);
        }
        /// <summary>
        /// used to null all the stringId in theconcerned meta and extended meta
        /// </summary>
        public void Null_StringID()
        {
            //first null all my string ids
            foreach (int temp_off in ref_stringID)
            {
                DATA_READ.WriteINT_LE(0x0, temp_off, data);
            }
            //we then proceed for extended meta
            List <int> keys = list_extended.Keys.ToList <int>();

            foreach (int temp_key in keys)
            {
                extended_meta temp_meta = list_extended[temp_key];
                temp_meta.Null_StringID();
            }
        }
        /// <summary>
        /// Generates a full self dependent meta file(except tag refs)
        /// </summary>
        /// <returns></returns>
        public byte[] Generate_meta_file()
        {
            byte[] ret = new byte[this.Get_Total_size()];

            //we first copy the root meta data into it
            DATA_READ.ArrayCpy(ret, data, 0x0, size);

            //now we go for extended meta
            List <int> extend_keys = list_extended.Keys.ToList <int>();

            //here we go
            foreach (int temp_key in extend_keys)
            {
                extended_meta temp_meta = list_extended[temp_key];
                int           start_off = temp_meta.Get_mem_addr() - mem_off;
                DATA_READ.ArrayCpy(ret, temp_meta.Generate_meta_file(), start_off, temp_meta.Get_Total_size());
            }

            return(ret);
        }
        /// <summary>
        /// a function to fill in all the Lists and Dictionaries
        /// </summary>
        /// <param name="off">the starting offset where the stuff is being read</param>
        /// <param name="fields">the concerned field(s) in that section</param>
        void List_deps(int off, plugins_field fields)
        {
            List <int> temp = fields.Get_tag_ref_list();

            //first we look for tag_refs and add them
            foreach (int i in temp)
            {
                int Toff = off + i;//it contains type
                //we add this off to the list if it doesnt contain the off already
                if (!ref_tags.Contains(Toff))
                {
                    ref_tags.Add(Toff);
                }
            }
            //then we look for data_refs and add them
            temp = fields.Get_data_ref_list();
            foreach (int i in temp)
            {
                int Toff = off + i;
                //we add this off to the list if it doesnt contain the off already
                if (!ref_data.Contains(Toff))
                {
                    ref_data.Add(Toff);
                }
            }
            //then we look for stringId refs and add them
            temp = fields.Get_stringID_ref_list();
            foreach (int i in temp)
            {
                int Toff = off + i;
                //we add this off to the list if it doesnt contain the off already
                if (!ref_stringID.Contains(Toff))
                {
                    ref_stringID.Add(Toff);
                }
            }
            //now we look into reflexive fields and extended meta and add them accordingly
            List <plugins_field> Ptemp = fields.Get_reflexive_list();

            foreach (plugins_field i_Pfield in Ptemp)
            {
                int Toff = off + i_Pfield.Get_offset();//field table off contains count

                int count         = DATA_READ.ReadINT_LE(Toff, data);
                int field_memaddr = DATA_READ.ReadINT_LE(Toff + 4, data);
                int entry_size    = i_Pfield.Get_entry_size(); //entry_size

                int field_off = field_memaddr - mem_off;       //its the offset of the field from the starting of the meta data

                if (count > 0)
                {
                    //now we check whether its inside meta or a case of extended meta
                    if ((field_memaddr >= mem_off) && (field_off < size))
                    {
                        //inside meta
                        //we add this off which contains reflexive table to the list if it doesnt contain the off already
                        if (!ref_reflexive.Contains(Toff))
                        {
                            ref_reflexive.Add(Toff);
                            //after adding it to the list we look into them,recursively
                            for (int j = 0; j < count; j++)
                            {
                                List_deps(field_off + j * entry_size, i_Pfield);
                            }
                        }
                    }
                    else
                    {
                        //extended meta(IN SUCCESSFULL RUN ,EXTENDED META ONLY APPEARS ONLY WHEN WE READ FROM A MAP)

                        //but first we check whether we are reading meta from a map,or an exracted file,its rather easy
                        if (list_extended != null)
                        {
                            //we add this off to the list if it doesnt contain the off already
                            if (!ref_extended.ContainsKey(Toff))
                            {
                                ref_extended.Add(Toff, field_memaddr);
                                //now we create and add extended_meta to the list if it isnt already there
                                if (!list_extended.ContainsKey(field_memaddr))
                                {
                                    extended_meta temp_extend = new extended_meta(field_memaddr, entry_size * count, count, i_Pfield, map_stream);
                                    list_extended.Add(field_memaddr, temp_extend);
                                }
                                //we dont need to look into them as extended meta does it for us
                            }
                        }
                        else
                        {
                            //the program will only reach here when u try to use an extended meta on meta file.
                            //any meta which i extract from a map file have all issues of extended_meta fixed.
                            throw new Exception("Meta file " + path + "." + type + " is broken.\nEither debug the extraction proceedure or fix the meta file");
                        }
                    }
                }
            }
            //now we go for withClass attribute tagRefs,they are a bit different as they only contain the datum index of the refered tag
            temp = fields.Get_WCtag_ref_list();
            foreach (int i in temp)
            {
                int Toff = off + i;
                //we add this off to the list if it doesnt contain the off already
                if (!ref_WCtags.Contains(Toff))
                {
                    ref_WCtags.Add(Toff);
                }
            }
        }
        /// <summary>
        /// a function to fill in all the Lists and Dictionaries
        /// </summary>
        /// <param name="off">the starting offset where the stuff is being read</param>
        /// <param name="fields">the concerned field(s) in that section</param>
        void List_deps(int off, plugins_field fields)
        {
            List <int> temp = fields.Get_tag_ref_list();

            //first we look for tag_refs and add them
            foreach (int i in temp)
            {
                int Toff = off + i;//it contains type
                //we add this off to the list if it doesnt contain the off already
                if (!ref_tags.Contains(Toff))
                {
                    ref_tags.Add(Toff);
                }
            }
            //then we look for data_refs and add them
            temp = fields.Get_data_ref_list();
            foreach (int i in temp)
            {
                int Toff = off + i;
                //we add this off to the list if it doesnt contain the off already
                if (!ref_data.Contains(Toff))
                {
                    ref_data.Add(Toff);
                }
            }
            //then we look for stringId refs and add them
            temp = fields.Get_stringID_ref_list();
            foreach (int i in temp)
            {
                int Toff = off + i;
                //we add this off to the list if it doesnt contain the off already
                if (!ref_stringID.Contains(Toff))
                {
                    ref_stringID.Add(Toff);
                }
            }
            //now we look into reflexive fields and extended meta and add them accordingly
            List <plugins_field> Ptemp = fields.Get_reflexive_list();

            foreach (plugins_field i_Pfield in Ptemp)
            {
                int Toff = off + i_Pfield.Get_offset();//field table off contains count

                int count         = DATA_READ.ReadINT_LE(Toff, data);
                int field_memaddr = DATA_READ.ReadINT_LE(Toff + 4, data);
                int entry_size    = i_Pfield.Get_entry_size(); //entry_size

                int field_off = field_memaddr - mem_off;       //its the offset of the field from the starting of the meta data

                if (count > 0)
                {
                    //now we check whether its inside meta or a case of extended meta
                    if ((field_memaddr >= mem_off) && (field_off < size))
                    {
                        //inside meta
                        //we add this off which contains reflexive table to the list if it doesnt contain the off already
                        if (!ref_reflexive.Contains(Toff))
                        {
                            ref_reflexive.Add(Toff);
                            //after adding it to the list we look into them,recursively
                            for (int j = 0; j < count; j++)
                            {
                                List_deps(field_off + j * entry_size, i_Pfield);
                            }
                        }
                    }
                    else
                    {
                        //extended meta
                        //we add this off to the list if it doesnt contain the off already
                        if (!ref_extended.ContainsKey(Toff))
                        {
                            ref_extended.Add(Toff, field_memaddr);
                            //now we create and add extended_meta to the list if it isnt already there
                            if (!list_extended.ContainsKey(field_memaddr))
                            {
                                extended_meta temp_extend = new extended_meta(field_memaddr, entry_size * count, count, i_Pfield, map_stream);
                                list_extended.Add(field_memaddr, temp_extend);
                            }
                            //we dont need to look into them as extended meta does it for us
                        }
                    }
                }
            }
            //now we go for withClass attribute tagRefs,they are a bit different as they only contain the datum index of the refered tag
            temp = fields.Get_WCtag_ref_list();
            foreach (int i in temp)
            {
                int Toff = off + i;
                //we add this off to the list if it doesnt contain the off already
                if (!ref_WCtags.Contains(Toff))
                {
                    ref_WCtags.Add(Toff);
                }
            }
        }