Esempio n. 1
0
        public static void analyze2(string record)
        {
            ESM.open(Config.Paths.mw_esm);
            Log lg = new Log("explore.txt");

            while (ESM.find(record))
            {
                TES3.Record rec = new TES3.Record();
                rec.read();

                byte[] flgs = rec.find_first("BYDT").getData().ReadBytes(4);

                if (flgs[0] == 0 && flgs[3] == 0)
                {
                    string edid = rec.find_first("NAME").readString();
                    string rnam = rec.find_first("FNAM").readString();
                    string sex  = "";

                    if (BinaryFlag.isSet((int)flgs[2], (int)0x01))
                    {
                        sex = "Female";
                    }
                    else
                    {
                        sex = "Male";
                    }



                    lg.log(rnam + "," + sex + "," + edid);
                }
            }

            lg.show();
        }
Esempio n. 2
0
        public void write(BinaryWriter output)
        {
            Log.info("Writing RECORD: " + new string(type));

            // handle if compression set
            if (BinaryFlag.isSet(flags, 0x00040000))
            {
                MemoryStream mstream = new MemoryStream();
                BinaryWriter out2    = new BinaryWriter(mstream);


                for (int i = 0; i < fields.Count; i++)
                {
                    fields[i].write(out2);
                }

                mstream.Position = 0;

                byte[] uncompressed      = mstream.ToArray();
                int    uncompressed_size = uncompressed.Length;

                byte[] compressed_     = Ionic.Zlib.ZlibStream.CompressBuffer(uncompressed);
                int    compressed_size = compressed_.Length;

                dataSize = (uint)compressed_size + 4;

                output.Write(type);
                output.Write(dataSize);
                output.Write(flags);
                output.Write(id);
                output.Write(revision);
                output.Write(version);
                output.Write(unknown);

                output.Write(uncompressed_size);
                output.Write(compressed_);
                return;
            }



            // Non-Compressed case
            recalculate_size();

            output.Write(type);
            output.Write(dataSize);
            output.Write(flags);
            output.Write(id);
            output.Write(revision);
            output.Write(version);
            output.Write(unknown);

            for (int i = 0; i < fields.Count; i++)
            {
                fields[i].write(output);
            }
        }
Esempio n. 3
0
 private void read_flags()
 {
     Dynamic      = BinaryFlag.isSet(flags, (ushort)0x0001);
     Can_Carry    = BinaryFlag.isSet(flags, (ushort)0x0002);
     Negative     = BinaryFlag.isSet(flags, (ushort)0x0004);
     Flicker      = BinaryFlag.isSet(flags, (ushort)0x0008);
     Fire         = BinaryFlag.isSet(flags, (ushort)0x0010);
     Off_Default  = BinaryFlag.isSet(flags, (ushort)0x0020);
     Flicker_Slow = BinaryFlag.isSet(flags, (ushort)0x0040);
     Pulse        = BinaryFlag.isSet(flags, (ushort)0x0080);
     Pulse_Slow   = BinaryFlag.isSet(flags, (ushort)0x0100);
 }
Esempio n. 4
0
 private void pack_flags()
 {
     data_flags = 0;
     if (Interior)
     {
         data_flags = BinaryFlag.set((ushort)data_flags, (ushort)FLAGS_CELL.Interior);
     }
     if (HasWater)
     {
         data_flags = BinaryFlag.set((ushort)data_flags, (ushort)FLAGS_CELL.HasWater);
     }
 }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public void read()
        {
            base.read();
            editor_id = find_first("NAME").readString().ToLower();
            game_name = find_first("FNAM").readString();
            race      = find_first("RNAM").readString();
            head      = find_first("BNAM").readString().ToLower();
            hair      = find_first("KNAM").readString().ToLower();

            faction = find_first("ANAM").readString();

            isFemale = BinaryFlag.isSet(find_first("FLAG").getData().ReadUInt32(), 0x0001);
            autoCalc = BinaryFlag.isSet(find_first("FLAG").getData().ReadUInt32(), 0x0010);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public Record(string type, bool compressed = false)
        {
            if (type == null)
            {
                return;
            }

            this.type = type.ToCharArray(0, 4);
            //this.flags = flags;
            if (compressed)
            {
                this.compressed = compressed;
                this.flags      = BinaryFlag.set((uint)0, (uint)FLAGS.compressed);
            }
            this.id       = FormID.getNew();
            this.revision = 5906;
            this.version  = 43;
            this.unknown  = 0;
        }
Esempio n. 9
0
            public XCLL()
            {
                Ambient       = new byte[4];
                Directional   = new byte[4];
                FogNear       = new byte[4];
                AmbientX_plus = new byte[4] {
                    255, 255, 255, 0
                };
                AmbientX_minus = new byte[4] {
                    255, 255, 255, 0
                };
                AmbientY_plus = new byte[4] {
                    255, 255, 255, 0
                };
                AmbientY_minus = new byte[4] {
                    255, 255, 255, 0
                };
                AmbientZ_plus = new byte[4] {
                    255, 255, 255, 0
                };
                AmbientZ_minus = new byte[4] {
                    255, 255, 255, 0
                };
                SpecularColor = new byte[4];
                FogFar2       = new byte[4];

                Inheritflags_minuscontrols = (uint)BinaryFlag.set(0, 0x0001);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0002);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0004);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0008);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0010);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0020);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0040);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0080);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0100);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0200);
                Inheritflags_minuscontrols = (uint)BinaryFlag.set(Inheritflags_minuscontrols, 0x0400);

                FogPow       = 1.0f;
                FresnelPower = 1.0f;
                FogMax       = 1.0f;
            }
Esempio n. 10
0
        //long temp_store;

        public void read(BinaryReader input, bool unpack = true)
        {
            type     = input.ReadChars(4);
            dataSize = input.ReadUInt32();
            flags    = input.ReadUInt32();
            id       = input.ReadUInt32();
            revision = input.ReadUInt32();
            version  = input.ReadUInt16();
            unknown  = input.ReadUInt16();

            long reading_size = dataSize;

            if (Config.GeneralSettings.verbose)
            {
                Log.info("     Reading Record: " + new string(type) + " " + id.ToString("X") + " >>> " + uint.MaxValue.ToString("X"));
            }

            // If compressed flag is set then uncompress the data
            if (BinaryFlag.isSet(flags, 0x00040000))
            {
                this.compressed = true;
                UInt32 decompressed_size = input.ReadUInt32();
                byte[] compressed_data   = input.ReadBytes((int)dataSize - 4);

                //Log.infoX(compressed_data[0] + " " + compressed_data[1]);

                byte[] uncompressed_data = (Ionic.Zlib.ZlibStream.UncompressBuffer(compressed_data));

                //      temp_store = (int)dataSize;

                if (uncompressed_data.Length != decompressed_size)
                {
                    Log.error("Uncompressed Data was not of expected size: in Record.read()");
                }

                MemoryStream mstream = new MemoryStream();
                mstream.Write(uncompressed_data, 0, uncompressed_data.Length);
                mstream.Position = 0;

                //dataSize = (uint)uncompressed_data.Length;

                input = new BinaryReader(mstream);

                reading_size = uncompressed_data.Length;
            }



            if (!unpack)
            {
                Log.error("Not Implemented !unpack at Record.read()");
            }

            uint read_data = 0;

            while (read_data < reading_size)
            {
                Field field = new Field();
                field.read(input);
                fields.Add(field);

                if (field.isBig)
                {
                    read_data = read_data + (uint)field.data_size() + 6 + /*XXX size*/ +10;
                }
                else
                {
                    read_data = read_data + (uint)field.data_size() + 6;
                }
            }
        }
Esempio n. 11
0
        //byte[] compressed_data;
        // END Data



        public void setFlag(uint option)
        {
            flags = BinaryFlag.set(flags, option);
        }
        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);
                }
            }
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        public new void read(bool skip = false)
        {
            Name    = ESM.input.ReadChars(4);
            Size    = ESM.input.ReadInt32();
            Header1 = ESM.input.ReadInt32();
            Flags   = ESM.input.ReadInt32();

            if (!"CELL".Equals(new string(Name)))
            {
                Log.error("Error reading CELL, mismatch name");
            }

            int read_size = 0;

            while (read_size < Size)
            {
                SubRecord subrec = new SubRecord();
                subrec.read();
                read_size = read_size + subrec.size + 8;

                // Skipping over cell reference data for now
                if (subrec.isType("FRMR"))
                {
                    //Log.info("FRMR found");
                    REFR refr = new REFR();
                    read_size = read_size + refr.read(Size - read_size);
                    references.Add(refr);

                    continue;
                }

                subRecords.Add(subrec);
            }


            for (int i = 0; i < subRecords.Count; i++)
            {
                SubRecord    srec      = subRecords[i];
                BinaryReader srec_data = srec.getData();
                switch (new string(srec.name))
                {
                case ("NAME"):
                    if (srec.size > 1)
                    {
                        cell_name = new string(srec_data.ReadChars(srec.size));
                        cell_name = Text.trim(cell_name);
                    }
                    break;

                case ("RGNN"):
                    if (String.IsNullOrWhiteSpace(cell_name) || String.IsNullOrEmpty(cell_name.Trim()))
                    {
                        cell_name = new string(srec_data.ReadChars(srec.size));
                    }
                    break;

                case ("INTV"):
                    // water height is stored as a signed int, but the value
                    // corresponds to the float z-axis position of the water plane in the
                    // cell world
                    water_height = (float)srec_data.ReadInt32();

                    break;

                case ("AMBI"):
                    amb_col = srec_data.ReadBytes(4);
                    sun_col = srec_data.ReadBytes(4);
                    break;

                case ("DATA"):
                    data_flags = srec_data.ReadInt32();
                    grid_x     = srec_data.ReadInt32();
                    grid_y     = srec_data.ReadInt32();

                    interior = BinaryFlag.isSet(data_flags, (int)CELL_FLAGS.Interior);
                    HasWater = BinaryFlag.isSet(data_flags, (int)CELL_FLAGS.Water);
                    NoSleep  = BinaryFlag.isSet(data_flags, (int)CELL_FLAGS.NoSleep);

                    break;
                }
            }
        }
Esempio n. 15
0
 public bool flagSet(uint option)
 {
     return(BinaryFlag.isSet(flags, option));
 }
Esempio n. 16
0
 public void make_persistent()
 {
     this.flags = BinaryFlag.set(this.flags, 0x400);
 }
Esempio n. 17
0
        public void pack()
        {
            addField(new Field("EDID", Text.editor_id(editor_id)));

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

            if (model != null)
            {
                addField(new Field("MODL", Text.model_path(model)));
            }

            if (icon != null)
            {
                addField(new Field("ICON", Text.zstring(icon)));
            }

            // FIELD -> DATA
            {
                MemoryStream ms = new MemoryStream();
                BinaryWriter bw = new BinaryWriter(ms);

                bw.Write((UInt32)Time);
                bw.Write((UInt32)Radius);

                bw.Write((byte)r);
                bw.Write((byte)g);
                bw.Write((byte)b);
                bw.Write((byte)0);

                UInt32 flags = 0;

                if (Dynamic)
                {
                    flags = BinaryFlag.set(flags, (UInt32)0x0001);
                }
                if (carried)
                {
                    flags = BinaryFlag.set(flags, (UInt32)0x0002);
                }
                if (Flicker)
                {
                    flags = BinaryFlag.set(flags, (UInt32)0x0008);
                }
                if (Off)
                {
                    flags = BinaryFlag.set(flags, (UInt32)0x0020);
                }
                if (FlickerSlow)
                {
                    flags = BinaryFlag.set(flags, (UInt32)0x0040);
                }
                if (Pulse)
                {
                    flags = BinaryFlag.set(flags, (UInt32)0x0080);
                }
                if (Spotlight)
                {
                    flags = BinaryFlag.set(flags, (UInt32)0x0400);
                }
                if (Hemisphere)
                {
                    flags = BinaryFlag.set(flags, (UInt32)0x0800);
                }
                if (Omnidirectional)
                {
                    flags = BinaryFlag.set(flags, (UInt32)0x1000);
                }

                bw.Write((UInt32)flags);
                bw.Write((float)Falloff_Exponent);
                bw.Write((float)FOV);
                bw.Write((float)Near_Clip);
                bw.Write((float)Period);
                bw.Write((float)Intensity_Amplitude);
                bw.Write((float)Movement_Amplitude);
                bw.Write((UInt32)Value);
                bw.Write((float)Weight);

                if (ms.Length != 48)
                {
                    Log.error("LIGH:DATA must be 48 bytes");
                }

                addField(new Field("DATA", ms.ToArray()));
            }
        }