예제 #1
0
        public static void read_templates()
        {
            if (doOnce)
            {
                return;
            }

            doOnce = true;
            TES5.ESM esm = TES5.ESM.read_from_file(Config.Paths.Templates.characters);

            foreach (TES5.Record r in esm.find_TOP_group_OR_FAIL("NPC_").records)
            {
                TES5.Field FULL = r.try_find_field("FULL");
                TES5.Field EDID = r.find_field_OR_FAIL("EDID", "NPC encountered with no editor id, FORMID=" + Text.toHex(r.id));

                if (FULL == null)
                {
                    Log.confirm(EDID.readString() + " : FaceGen Template NPC does not have a NAME. Un-named NPCs are ignored and not used as facegen templates.");
                    continue;
                }

                string name_full = FULL.readString().ToLower();
                body_templates.Add(name_full, r);
            }
        }
예제 #2
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);
            }
        }
        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);
                }
            }
        }
        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);
                }
            }
        }
예제 #5
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);
        }