Ejemplo n.º 1
0
        public static TES5.Group[] convert(string file)
        {
            List <mw_ltex> mw_textures = get_mw_land_textures(file);

            TES5.Group grup_txst = new TES5.Group("TXST");
            TES5.Group grup_ltex = new TES5.Group("LTEX");

            foreach (mw_ltex t in mw_textures)
            {
                TES5.Record txst = make_txst(t.editor_id, t.texture_path);
                TES5.Record ltex = make_ltex(txst.id, t.editor_id);

                LAND.add_texture(t.index, t.editor_id, t.texture_path, ltex.id);

                grup_txst.addRecord(txst);
                grup_ltex.addRecord(ltex);
            }

            TES5.Group[] grps = new TES5.Group[2];
            grps[0] = grup_txst;
            grps[1] = grup_ltex;

            done = true;

            return(grps);
        }
Ejemplo n.º 2
0
        protected TES5.Group convert(string file)
        {
            List <OBJ_STRUCT> lst = get_lst(file);

            TES5.Group grup = new TES5.Group(TYPE);

            foreach (OBJ_STRUCT obj in lst)
            {
                TES5.Record r = new TES5.Record(TYPE, obj.editor_id);

                if (obj.editor_id != null)
                {
                    r.addField(new TES5.Field("EDID", Text.editor_id(obj.editor_id)));
                }
                if (obj.game_name != null)
                {
                    r.addField(new TES5.Field("FULL", Text.zstring(obj.game_name)));
                }
                if (obj.model_path != null)
                {
                    r.addField(new TES5.Field("MODL", Text.model_path(obj.model_path)));
                }

                grup.addRecord(r);
            }

            return(grup);
        }
Ejemplo n.º 3
0
        static TES5.Group make_tes5_doors(List <door_> lst)
        {
            TES5.Group grup = new TES5.Group("DOOR");

            TES5.Record marker = new TES5.Record("DOOR");
            marker.addField(new TES5.Field("EDID", Text.editor_id("teleport_marker")));

            marker_id = marker.id;
            grup.addRecord(marker);

            foreach (door_ d in lst)
            {
                // Make Normal version
                TES5.Record r = new TES5.Record("DOOR", d.id);
                r.addField(new TES5.Field("EDID", Text.editor_id(d.id)));
                r.addField(new TES5.Field("FULL", Text.zstring(d.full_name)));
                r.addField(new TES5.Field("MODL", Text.model_path(d.model_path)));

                // Make Portal version
                TES5.Record r_load = new TES5.Record("DOOR", d.id + "_zload");
                r_load.addField(new TES5.Field("EDID", Text.editor_id(d.id + "_zload")));
                r_load.addField(new TES5.Field("FULL", Text.zstring(d.full_name)));
                r_load.addField(new TES5.Field("MODL", Text.model_path(d.model_path.ToLower().Replace(".nif", "_zload.nif"))));

                grup.addRecord(r);
                grup.addRecord(r_load);

                ModelConverter.convert(d.model_path, "door_load", true);
                ModelConverter.convert(d.model_path, "door_anim", true);
            }

            return(grup);
        }
Ejemplo n.º 4
0
        static void search_record(TES5.Record record)
        {
            if (mode == 1)
            {
                TES5.Field ATXT = null;

                foreach (TES5.Field field in record.fields)
                {
                    if (field.isType("BTXT"))
                    {
                        helper.update(x, y, field);
                    }

                    if (field.isType("ATXT"))
                    {
                        ATXT = field;
                    }

                    if (field.isType("VTXT"))
                    {
                        helper.update(x, y, ATXT, field);
                        ATXT = null;
                    }
                }
            }

            if (mode == 2)
            {
                helper.clean(record);
                helper.reconstruct(record, x, y);
            }
        }
Ejemplo n.º 5
0
        public static TES5.Group convert()
        {
            if (furn != null)
            {
                return(furn);
            }

            furn = new TES5.Group("FURN");

            TES5.ESM esm = TES5.ESM.read_from_file(Config.Paths.Templates.furniture);

            TES5.Group furn_g = esm.find_TOP_group_OR_FAIL("FURN");

            chair      = furn_g.find_record("mw_chair_marker");
            bed        = furn_g.find_record("mw_bed_marker");
            bench      = furn_g.find_record("mw_bench_marker");
            bed_double = furn_g.find_record("mw_doublebed_marker");

            if (chair == null || bed == null || bench == null || bed_double == null)
            {
                Log.error("FURN some Furniture marker were not assigned. Possibly bad furn.esp template");
            }

            chair.reset_formid("mw_chair_marker");
            bed.reset_formid("mw_bed_marker");
            bench.reset_formid("mw_bench_marker");
            bed_double.reset_formid("mw_doublebed_marker");

            furn.addRecord(chair);
            furn.addRecord(bed);
            furn.addRecord(bench);
            furn.addRecord(bed_double);

            return(furn);
        }
Ejemplo n.º 6
0
        public TES5.Group convert(string file, bool ignoreFurniture = false)
        {
            List <OBJ_STRUCT> lst = get_lst(file);

            TES5.Group grup = new TES5.Group(TYPE);

            foreach (OBJ_STRUCT obj in lst)
            {
                TES5.Record r = new TES5.Record(TYPE, obj.editor_id);

                bool isFurn = false;
                if (!ignoreFurniture)
                {
                    isFurn = FURN.consider(obj.model_path, r);
                }

                r.addField(new TES5.Field("EDID", Text.editor_id(obj.editor_id)));
                if (obj.game_name != null && !isFurn)
                {
                    r.addField(new TES5.Field("FULL", Text.zstring(obj.game_name)));
                }
                if (obj.model_path != null)
                {
                    r.addField(new TES5.Field("MODL", Text.model_path(obj.model_path)));
                }

                grup.addRecord(r);
                ModelConverter.convert(obj.model_path, "stat", true);
            }

            return(grup);
        }
Ejemplo n.º 7
0
        public static bool consider(string model_path, TES5.Record stat_rec)
        {
            convert();
            read_placement_config();

            bool taken = false;

            model_path = Text.model_path_string(model_path);

            if (model_path.Contains("chair") || model_path.Contains("stool") || model_path.Contains("bench") || model_path.Contains("bed") || model_path.Contains("hammock"))
            {
                taken = true;

                if (!dict.ContainsKey(model_path))
                {
                    Log.error("No FURN marker defined for potential furniture model: " + model_path);
                }

                Tuple <TES5.Record, TES5.REFR.Placement> marker_data = dict[model_path];

                TES5.REFR.Placement pos        = marker_data.Item2;
                TES5.Record         addon_base = marker_data.Item1;

                Convert.REFERENCE.Addon_Rules.add_rule(stat_rec, addon_base.id, /*pos.x*/ 0, pos.y, pos.z, pos.xR, pos.yR, pos.zR);
            }

            return(taken);
        }
        private void search_group(TES5.Group grup)
        {
            if (grup.isType(TES5.Group.TYPE.TEMP_REFR))
            {
                UInt32 cell_form_id = Binary.toUInt32(grup.label);

                if (!formid_index.ContainsKey(cell_form_id))
                {
                    Log.error("Cell with formid: " + cell_form_id + " was not encountered");
                }

                Tuple <int, int> cell_grid_info = formid_index[cell_form_id];

                int x = cell_grid_info.Item1;
                int y = cell_grid_info.Item2;

                put(x, y, grup);

                return;
            }

            Queue <TES5.Group>  grps = new Queue <TES5.Group>(grup.subGroups);
            Queue <TES5.Record> recs = new Queue <TES5.Record>(grup.records);

            foreach (int t in grup.turn)
            {
                if (t == 1)
                {
                    TES5.Record r = recs.Dequeue();

                    #region if (r.isType("CELL"))

                    if (r.isType("CELL"))
                    {
                        TES5.Field xclc = r.try_find_field("XCLC");

                        if (xclc != null)
                        {
                            BinaryReader reader = xclc.getData();
                            int          x      = reader.ReadInt32();
                            int          y      = reader.ReadInt32();

                            formid_index.Add(r.id, new Tuple <int, int>(x, y));
                        }
                    }
                    #endregion
                }

                if (t == 2)
                {
                    TES5.Group g = grps.Dequeue();
                    search_group(g);
                }
            }
        }
Ejemplo n.º 9
0
        private static void read_placement_config()
        {
            if (dict != null)
            {
                return;
            }

            dict = new Dictionary <string, Tuple <TES5.Record, TES5.REFR.Placement> >();

            if (!File.Exists(Config.Paths.furniture_marker_config))
            {
                Log.confirm("Furniture Placement Config File was not found. \n Please generate it through FurnitureWorkshop.");
                return;
            }

            TextReader config = File.OpenText(Config.Paths.furniture_marker_config);


            while (config.Peek() != -1)
            {
                string line = config.ReadLine().Trim();

                if (line.StartsWith("#"))
                {
                    continue;
                }

                string[] parsed = line.Split(',');

                string model     = parsed[0];
                string editor_id = parsed[1];

                float x = float.Parse(parsed[2]);
                float y = float.Parse(parsed[3]);
                float z = float.Parse(parsed[4]);

                float xR = float.Parse(parsed[5]);
                float yR = float.Parse(parsed[6]);
                float zR = float.Parse(parsed[7]);


                TES5.Record         associated_marker = furn.find_record(editor_id);
                TES5.REFR.Placement pos = new TES5.REFR.Placement(x, y, z, xR, yR, zR);

                if (associated_marker == null)
                {
                    Log.error(editor_id + " was not found in FURN group. Ensure that conversion has run");
                }

                Tuple <TES5.Record, TES5.REFR.Placement> value = new Tuple <TES5.Record, TES5.REFR.Placement>(associated_marker, pos);

                dict.Add(model, value);
            }
        }
Ejemplo n.º 10
0
        public static TES5.Group convert(string file)
        {
            TES5.Group fact = new TES5.Group("FACT");

            TES3.ESM.open(file);

            while (TES3.ESM.find("FACT"))
            {
                TES3.Record f3 = new TES3.Record();
                f3.read();

                string editor_id = f3.find_first("NAME").readString();
                string full_name = f3.find_first("NAME") != null?f3.find_first("NAME").readString() : null;

                TES5.Record f5 = new TES5.Record("FACT", editor_id);

                if (full_name != null)
                {
                    f5.addField(new TES5.Field("FULL", Text.zstring(full_name)));
                }

                List <TES3.SubRecord> ANAMs = f3.find_all("ANAM", true);
                List <TES3.SubRecord> INTVs = f3.find_all("INTV", true);

                foreach (TES3.SubRecord intv in INTVs)
                {
                    int reaction = intv.getData().ReadInt32();
                    if (reaction <= -3) // make hostile
                    {
                        reaction = 1;
                    }
                    else if (reaction > -3 && reaction <= 1)
                    {
                        reaction = 0;
                    }
                    else if (reaction >= 2)
                    {
                        reaction = 2;
                    }
                }

                uint flags = 0;
                flags = BinaryFlag.set(flags, 0x8000);
                f5.addField(new TES5.Field("DATA", Binary.toBin(flags)));
                fact.addRecord(f5);
            }


            TES3.ESM.close();

            return(fact);
        }
Ejemplo n.º 11
0
        static TES5.Record make_ltex(uint formid, string editor_id)
        {
            TES5.Record ltex = new TES5.Record("LTEX");
            ltex.addField(new TES5.Field("EDID", Text.editor_id("LAND_" + editor_id)));
            ltex.addField(new TES5.Field("TNAM", Binary.toBin(formid)));
            ltex.addField(new TES5.Field("HNAM", new byte[2] {
                2, 0
            }));
            ltex.addField(new TES5.Field("SNAM", new byte[1] {
                30
            }));

            return(ltex);
        }
Ejemplo n.º 12
0
        public static void make_formID_index(TES5.Group furn)
        {
            chair      = furn.find_record("mw_chair_marker");
            bed        = furn.find_record("mw_bed_marker");
            bench      = furn.find_record("mw_bench_marker");
            bed_double = furn.find_record("mw_doublebed_marker");

            TextWriter f2 = File.CreateText(Config.Paths.Temporary.furn_formid_index);

            f2.WriteLine("# !AUTO-GENERATED! Do NOT edit this file. It contains formid index for FURN markers.");

            f2.WriteLine("mw_chair_marker=" + chair.id);
            f2.WriteLine("mw_bench_marker=" + bench.id);
            f2.WriteLine("mw_bed_marker=" + bed.id);
            f2.WriteLine("mw_doublebed_marker=" + bed_double.id);

            f2.Close();
        }
Ejemplo n.º 13
0
        static TES5.Record make_txst(string editor_id, string texture)
        {
            texture = texture.Replace(".tga", ".dds");

            string path = "morrowind\\";

            TES5.Record txset = new TES5.Record("TXST");
            txset.addField(new TES5.Field("EDID", Text.editor_id(editor_id)));
            txset.addField(new TES5.Field("OBND", new byte[12]));
            txset.addField(new TES5.Field("TX00", Text.zstring(path + texture)));
            txset.addField(new TES5.Field("TX01", Text.zstring(path + texture.Replace(".dds", "_n.dds"))));

            ushort flag = (ushort)BinaryFlag.set(0, 0x01);

            txset.addField(new TES5.Field("DNAM", Binary.toBin(flag)));

            return(txset);
        }
Ejemplo n.º 14
0
        static void search_group(TES5.Group group)
        {
            Queue <TES5.Record> q_rec  = new Queue <TES5.Record>(group.records);
            Queue <TES5.Group>  q_sgrp = new Queue <TES5.Group>(group.subGroups);

            foreach (int t in group.turn)
            {
                if (t == 2)
                {
                    search_group(q_sgrp.Dequeue());
                }

                if (t == 1)
                {
                    TES5.Record r = q_rec.Dequeue();
                    if (r.isType("CELL"))
                    {
                        foreach (TES5.Field fld in r.fields)
                        {
                            if (fld.isType("XCLC"))
                            {
                                BinaryReader br = fld.getData();
                                x = br.ReadInt32();
                                y = br.ReadInt32();
                                Log.info(x + "," + y);
                            }
                        }
                    }

                    if (r.isType("LAND"))
                    {
                        search_record(r);
                        x = 0;
                        y = 0;
                    }
                }
            }
        }
Ejemplo n.º 15
0
        private static void read_templates()
        {
            has_read = true;

            TES5.ESM   esm       = TES5.ESM.read_from_file(Config.Paths.light_templates);
            TES5.Group LGTM_GRUP = esm.find_TOP_group_OR_FAIL("LGTM", "No LGTM Group in Template File");


            default_ = LGTM_GRUP.find_record("mw_ltmp_default");
            daedric  = LGTM_GRUP.find_record("mw_ltmp_daedric");
            fort     = LGTM_GRUP.find_record("mw_ltmp_fort");
            dwemer   = LGTM_GRUP.find_record("mw_ltmp_dwemer");
            tomb     = velothi = LGTM_GRUP.find_record("mw_ltmp_tomb");
            hlaalu   = LGTM_GRUP.find_record("mw_ltmp_hlaalu");
            redoran  = LGTM_GRUP.find_record("mw_ltmp_redoran");
            telvanni = LGTM_GRUP.find_record("mw_ltmp_telvanni");
            cave     = mine = LGTM_GRUP.find_record("mw_ltmp_mine");
            imperial = LGTM_GRUP.find_record("mw_ltmp_imperial");

            if (default_ == null || hlaalu == null || fort == null || imperial == null || redoran == null || telvanni == null || dwemer == null || daedric == null || cave == null || tomb == null)
            {
                Log.error("TES5:LTMP Not all Lighting templates were assigned");
            }


            default_.reset_formid("mw_ltmp_default");
            daedric.reset_formid("mw_ltmp_daedric");
            fort.reset_formid("mw_ltmp_fort");
            dwemer.reset_formid("mw_ltmp_dwemer");
            tomb.reset_formid("mw_ltmp_tomb");
            hlaalu.reset_formid("mw_ltmp_hlaalu");
            redoran.reset_formid("mw_ltmp_redoran");
            telvanni.reset_formid("mw_ltmp_telvanni");
            cave.reset_formid("mw_ltmp_mine");
            imperial.reset_formid("mw_ltmp_imperial");
        }
Ejemplo n.º 16
0
        public static TES5.Group convert(string file_path, bool ignoreFurniture = false)
        {
            TES3.ESM.open(file_path);

            List <STRUCT_STAT> list_stat = new List <STRUCT_STAT>();

            while (TES3.ESM.find("STAT"))
            {
                TES3.Record stat = new TES3.Record();
                stat.read();

                STRUCT_STAT stat_ = new STRUCT_STAT();

                foreach (TES3.SubRecord srec in stat.subRecords)
                {
                    if (srec.isType("MODL"))
                    {
                        stat_.model_path = Text.trim(new string(srec.getData().ReadChars(srec.size)));
                        //stat_.model_path = stat_.model_path.Split('\\')[stat_.model_path.Split('\\').Length - 1];
                        //stat_.model_path = "morrowind\\" + stat_.model_path;
                        Log.info(stat_.model_path);
                    }

                    if (srec.isType("NAME"))
                    {
                        stat_.editor_id = Text.trim(new string(srec.getData().ReadChars(srec.size)));
                    }
                }



                list_stat.Add(stat_);
            }

            TES3.ESM.close();

            // Make TES5


            TES5.Group stat_grup = new TES5.Group("STAT");

            foreach (STRUCT_STAT stat in list_stat)
            {
                TES5.Record stat_tes5 = new TES5.Record("STAT", stat.editor_id, 0);
                stat_tes5.addField(new TES5.Field("EDID", Text.editor_id(stat.editor_id)));
                //stat_tes5.addField(new TES5.Field("OBND", new byte[12]));
                stat_tes5.addField(new TES5.Field("MODL", Text.model_path(stat.model_path)));

                MemoryStream mstream = new MemoryStream();
                BinaryWriter bw      = new BinaryWriter(mstream);
                bw.Write(90f);
                bw.Write(0);

                stat_tes5.addField(new TES5.Field("DNAM", mstream.ToArray()));

                if (!ignoreFurniture)
                {
                    Convert.FURN.consider(stat.model_path, stat_tes5);
                }
                stat_grup.addRecord(stat_tes5);


                ModelConverter.convert(stat.model_path, "stat", true);
            }


            return(stat_grup);
        }
        private void search_group(TES5.Group grup)
        {
            if (grup.isType(TES5.Group.TYPE.TEMP_REFR))
            {
                UInt32 cell_form_id = Binary.toUInt32(grup.label);

                if (!formid_index.ContainsKey(cell_form_id))
                {
                    Log.error("Cell with formid: " + cell_form_id + " was not encountered");
                }

                string cell_id = formid_index[cell_form_id];

                put(cell_id, grup);

                return;
            }

            Queue <TES5.Group>  grps = new Queue <TES5.Group>(grup.subGroups);
            Queue <TES5.Record> recs = new Queue <TES5.Record>(grup.records);

            foreach (int t in grup.turn)
            {
                if (t == 1)
                {
                    TES5.Record r = recs.Dequeue();

                    #region if (r.isType("CELL"))

                    if (r.isType("CELL"))
                    {
                        TES5.Field DATA = r.try_find_field("DATA");

                        if (DATA == null)
                        {
                            continue;
                        }

                        if (DATA.data_size() < 2)
                        {
                            continue;
                        }

                        UInt16 flags = DATA.getData().ReadUInt16();

                        if (!BinaryFlag.isSet((UInt16)flags, (UInt16)0x0001))
                        {
                            continue;
                        }

                        TES5.Field EDID = r.try_find_field("EDID");

                        if (EDID != null)
                        {
                            BinaryReader reader  = EDID.getData();
                            string       cell_id = Text.trim(new string (reader.ReadChars(EDID.data_size())));
                            formid_index.Add(r.id, cell_id);
                        }
                    }
                    #endregion
                }

                if (t == 2)
                {
                    TES5.Group g = grps.Dequeue();
                    search_group(g);
                }
            }
        }
Ejemplo n.º 18
0
        public static void presets()
        {
            string[] races = { "Breton",
                               "Dark Elf",
                               "High Elf",
                               "Imperial",
                               "Redguard",
                               "Wood Elf",
                               "Nord",
                               "Khajiit",
                               "Argonian",
                               "Orc" };

            string[] sexes = { "Female", "Male" };

            Dictionary <string, Dictionary <string, Queue <string> > > dict = new Dictionary <string, Dictionary <string, Queue <string> > >();

            foreach (string r in races)
            {
                Dictionary <string, Queue <string> > d = new Dictionary <string, Queue <string> >();

                dict.Add(r.Replace(" ", ""), d);

                foreach (string s in sexes)
                {
                    d.Add(s, new Queue <string>());
                }
            }

            TextReader fin = File.OpenText("tmp\\faces.csv");

            while (fin.Peek() != -1)
            {
                string   line   = fin.ReadLine();
                string[] parsed = line.Split(',');

                string race  = parsed[0];
                string sex   = parsed[1];
                string model = parsed[2].ToLower();

                dict[race.Replace(" ", "")][sex].Enqueue(model);
            }

            BinaryReader bw = new BinaryReader(new FileStream("tmp\\Skyrim.esm", FileMode.Open));

            TES5.Record head = new TES5.Record("TES4");

            head.read(bw);

            TES5.Group g = new TES5.Group();
            g.read(bw);

            while (!g.hasLabel("NPC_"))
            {
                Log.info("Reading: ");
                g.read(bw);
            }

            TES5.ESM esm = new TES5.ESM("faces.esp");
            esm.add_masters("Skyrim.esm");

            TES5.Group g_out = new TES5.Group("NPC_");

            foreach (TES5.Record r in g.records)
            {
                if (!r.isType("NPC_"))
                {
                    continue;
                }

                TES5.Field f = r.find_field_OR_FAIL("ACBS", "ACBS not found");

                UInt32 flagers = f.getData().ReadUInt32();

                if (BinaryFlag.isSet(flagers, 0x04))
                {
                    string edid = r.find_field_OR_FAIL("EDID", "").readString();
                    string sex  = "";
                    if (edid.Contains("Female"))
                    {
                        sex = "Female";
                    }
                    else if (edid.Contains("Male"))
                    {
                        sex = "Male";
                    }
                    else
                    {
                        Log.error("Can't be");
                    }

                    string race = edid.Split(new string[] { sex }, StringSplitOptions.None).First();

                    if (dict[race][sex].Count == 0)
                    {
                        continue;
                    }

                    string model = dict[race][sex].Dequeue();

                    Log.info(race);
                    Log.info(sex);
                    Log.info(r.find_field_OR_FAIL("EDID", "").readString());

                    TES5.Field full = r.try_find_field("FULL");

                    if (full == null)
                    {
                        full = new TES5.Field("FULL", Text.zstring(model));
                        r.fields.Insert(11, full);
                    }
                    else
                    {
                        full.replaceData(Text.zstring(model));
                    }

                    r.find_field_OR_FAIL("EDID", "").replaceData(Text.zstring(model));

                    TES5.Record new_rec = new TES5.Record("NPC_");
                    new_rec.clone(r, model);
                    new_rec.find_field_OR_FAIL("EDID", "").replaceData(Text.zstring(model));
                    g_out.addRecord(new_rec);
                }
            }


            esm.add_group(g_out);
            esm.write_to_file(Config.Paths.Templates.characters);
        }
Ejemplo n.º 19
0
        public static void add_rule(TES5.Record obj, UInt32 addon_id, float x, float y, float z, float xR, float yR, float zR)
        {
            Addon relative_placement = new Addon(addon_id, x, y, z, xR, yR, zR);

            dict.Add(obj.id, relative_placement);
        }