Exemple #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     res               = new ME3BioConversation.EntryListReplyListStruct();
     res.Paraphrase    = textBox1.Text;
     res.refParaphrase = Int32.Parse(textBox2.Text);
     res.CategoryType  = pcc.FindNameOrAdd("EReplyCategory");
     res.CategoryValue = pcc.FindNameOrAdd(comboBox1.Text);
     res.Index         = Int32.Parse(textBox4.Text);
     state             = 1;
 }
        public byte[] ToArray()
        {
            MemoryStream buffer = new MemoryStream();

            buffer.WriteValueU32(firstVal);
            buffer.WriteValueS32(pccRef.findName("None"));
            buffer.Seek(16, SeekOrigin.Begin);
            buffer.WriteValueU32(otherVal);
            buffer.WriteValueS32(enumTextureGroups.Count);
            foreach (ByteProp byteProp in enumTextureGroups)
            {
                buffer.WriteValueS32(pccRef.FindNameOrAdd(byteProp.name));
                buffer.WriteValueS32(byteProp.value);
            }

            return(buffer.ToArray());
        }
        public static void ImportImmutableProperty(ME3Package pcc, ME3Package importpcc, Property p, string className, MemoryStream m, bool inStruct = false)
        {
            string name    = importpcc.getNameEntry(p.Name);
            int    idxname = pcc.FindNameOrAdd(name);

            if (name == "None")
            {
                return;
            }
            string          type    = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 8));
            int             idxtype = pcc.FindNameOrAdd(type);
            string          name2;
            int             idxname2;
            int             size, count, pos;
            List <Property> Props;

            switch (type)
            {
            case "IntProperty":
            case "FloatProperty":
            case "ObjectProperty":
            case "StringRefProperty":
                m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4);
                break;

            case "NameProperty":
                m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.getNameEntry(p.Value.IntValue))), 0, 4);
                //preserve index or whatever the second part of a namereference is
                m.Write(p.raw, 28, 4);
                break;

            case "BoolProperty":
                m.WriteByte((byte)p.Value.IntValue);
                break;

            case "BioMask4Property":
                m.WriteByte((byte)p.Value.IntValue);
                break;

            case "ByteProperty":
                name2    = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 24));
                idxname2 = pcc.FindNameOrAdd(name2);
                if (p.Size == 8)
                {
                    m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.getNameEntry(p.Value.IntValue))), 0, 4);
                    m.Write(new byte[4], 0, 4);
                }
                else
                {
                    m.WriteByte(p.raw[32]);
                }
                break;

            case "StrProperty":
                name2 = p.Value.StringValue;
                if (name2.Length > 0)
                {
                    name2 += '\0';
                }
                m.Write(BitConverter.GetBytes(-name2.Length), 0, 4);
                foreach (char c in name2)
                {
                    m.WriteByte((byte)c);
                    m.WriteByte(0);
                }
                break;

            case "StructProperty":
                size     = BitConverter.ToInt32(p.raw, 16);
                name2    = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 24));
                idxname2 = pcc.FindNameOrAdd(name2);
                pos      = 32;
                Props    = new List <Property>();
                try
                {
                    Props = ReadProp(importpcc, p.raw, pos);
                }
                catch (Exception)
                {
                }
                if (Props.Count == 0 || Props[0].TypeVal == PropertyType.Unknown)
                {
                    for (int i = 0; i < size; i++)
                    {
                        m.WriteByte(p.raw[32 + i]);
                    }
                }
                else
                {
                    foreach (Property pp in Props)
                    {
                        ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                }
                break;

            case "ArrayProperty":
                size  = BitConverter.ToInt32(p.raw, 16);
                count = BitConverter.ToInt32(p.raw, 24);
                ArrayType arrayType = ME3UnrealObjectInfo.getArrayType(className, importpcc.getNameEntry(p.Name));
                pos = 28;
                List <Property> AllProps = new List <Property>();

                if (arrayType == ArrayType.Struct)
                {
                    for (int i = 0; i < count; i++)
                    {
                        Props = new List <Property>();
                        try
                        {
                            Props = ReadProp(importpcc, p.raw, pos);
                        }
                        catch (Exception)
                        {
                        }
                        AllProps.AddRange(Props);
                        if (Props.Count != 0)
                        {
                            pos = Props[Props.Count - 1].offend;
                        }
                    }
                }
                m.Write(BitConverter.GetBytes(count), 0, 4);
                if (AllProps.Count != 0)
                {
                    foreach (Property pp in AllProps)
                    {
                        ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                }
                else if (arrayType == ArrayType.Name)
                {
                    for (int i = 0; i < count; i++)
                    {
                        string s = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 28 + i * 8));
                        m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(s)), 0, 4);
                        //preserve index or whatever the second part of a namereference is
                        m.Write(p.raw, 32 + i * 8, 4);
                    }
                }
                else
                {
                    m.Write(p.raw, 28, size - 4);
                }
                break;

            default:
            case "DelegateProperty":
                throw new NotImplementedException(type);
            }
        }
        public static void ImportImmutableProperty(ME3Package pcc, ME3Package importpcc, Property p, string className, MemoryStream m, bool inStruct = false)
        {
            string name = importpcc.getNameEntry(p.Name);
            int idxname = pcc.FindNameOrAdd(name);
            if (name == "None")
                return;
            string type = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 8));
            int idxtype = pcc.FindNameOrAdd(type);
            string name2;
            int idxname2;
            int size, count, pos;
            List<Property> Props;
            switch (type)
            {
                case "IntProperty":
                case "FloatProperty":
                case "ObjectProperty":
                case "StringRefProperty":
                    m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4);
                    break;
                case "NameProperty":
                    m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.getNameEntry(p.Value.IntValue))), 0, 4);
                    //preserve index or whatever the second part of a namereference is
                    m.Write(p.raw, 28, 4);
                    break;
                case "BoolProperty":
                    m.WriteByte((byte)p.Value.IntValue);
                    break;
                case "BioMask4Property":
                    m.WriteByte((byte)p.Value.IntValue);
                    break;
                case "ByteProperty":
                    name2 = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 24));
                    idxname2 = pcc.FindNameOrAdd(name2);
                    if (p.Size == 8)
                    {
                        m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.getNameEntry(p.Value.IntValue))), 0, 4);
                        m.Write(new byte[4], 0, 4);
                    }
                    else
                    {
                        m.WriteByte(p.raw[32]);
                    }
                    break;
                case "StrProperty":
                    name2 = p.Value.StringValue + '\0';
                    m.Write(BitConverter.GetBytes(-name2.Length), 0, 4);
                    foreach (char c in name2)
                    {
                        m.WriteByte((byte)c);
                        m.WriteByte(0);
                    }
                    break;
                case "StructProperty":
                    size = BitConverter.ToInt32(p.raw, 16);
                    name2 = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 24));
                    idxname2 = pcc.FindNameOrAdd(name2);
                    pos = 32;
                    Props = new List<Property>();
                    try
                    {
                        Props = ReadProp(importpcc, p.raw, pos);
                    }
                    catch (Exception)
                    {
                    }
                    if (Props.Count == 0 || Props[0].TypeVal == PropertyType.Unknown)
                    {
                        for (int i = 0; i < size; i++)
                            m.WriteByte(p.raw[32 + i]);
                    }
                    else
                    {
                        foreach (Property pp in Props)
                            ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                    break;
                case "ArrayProperty":
                    size = BitConverter.ToInt32(p.raw, 16);
                    count = BitConverter.ToInt32(p.raw, 24);
                    ArrayType arrayType = ME3UnrealObjectInfo.getArrayType(className, importpcc.getNameEntry(p.Name), inStruct);
                    pos = 28;
                    List<Property> AllProps = new List<Property>();

                    if (arrayType == ArrayType.Struct)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            Props = new List<Property>();
                            try
                            {
                                Props = ReadProp(importpcc, p.raw, pos);
                            }
                            catch (Exception)
                            {
                            }
                            AllProps.AddRange(Props);
                            if (Props.Count != 0)
                            {
                                pos = Props[Props.Count - 1].offend;
                            }
                        }
                    }
                    m.Write(BitConverter.GetBytes(count), 0, 4);
                    if (AllProps.Count != 0)
                    {
                        foreach (Property pp in AllProps)
                            ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                    else if (arrayType == ArrayType.Name)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            string s = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 28 + i * 8));
                            m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(s)), 0, 4);
                            //preserve index or whatever the second part of a namereference is
                            m.Write(p.raw, 32 + i * 8, 4);
                        }
                    }
                    else
                    {
                        m.Write(p.raw, 28, size - 4);
                    }
                    break;
                default:
                case "DelegateProperty":
                    throw new NotImplementedException(type);
            }
        }
        public void OneImageToRuleThemAll(string imageFileName, string archiveDir, out string newTextureGroup)
        {
            newTextureGroup = null;
            ImageMipMapHandler imgMipMap = new ImageMipMapHandler(imageFileName, null);

            // starts from the smaller image
            for (int i = imgMipMap.imageList.Count - 1; i >= 0; i--)
            {
                ImageFile newImageFile = imgMipMap.imageList[i];

                // insert images only with size > 64
                if (newImageFile.imgSize.width < 64 && newImageFile.imgSize.height < 64)
                {
                    continue;
                }

                // write the new image into a file (I know that's crappy solution, I'll find another one later...)
                using (FileStream newImageStream = File.Create(newImageFile.fileName))
                {
                    byte[] buffer = newImageFile.ToArray();
                    newImageStream.Write(buffer, 0, buffer.Length);
                }

                // if the image size exists inside the texture2d image list then we have to replace it
                if (imgList.Exists(img => img.imgSize == newImageFile.imgSize))
                {
                    // ...but at least for now I can reuse my replaceImage function... ;)
                    replaceImage(newImageFile.imgSize.ToString(), newImageFile.fileName, archiveDir);
                }
                else // if the image doesn't exists then we have to add it
                {
                    // ...and use my addBiggerImage function! :P
                    addBiggerImage(newImageFile.fileName, archiveDir);
                }

                File.Delete(newImageFile.fileName);
            }


            // check that Texture2D has a TextureGroup
            if (!properties.ContainsKey("LODGroup"))
            {
                return;
            }

            // extracting values from LODGroup Property
            PropertyReader.Property LODGroup = properties["LODGroup"];
            string textureGroupName          = pccRef.Names[LODGroup.Value.IntValue];

            string newTextureGroupName = "TEXTUREGROUP_Shadowmap";

            textureGroupName = newTextureGroupName;
            int nameIndex = pccRef.FindNameOrAdd(newTextureGroupName);

            using (MemoryStream rawStream = new MemoryStream(LODGroup.raw))
            {
                rawStream.Seek(32, SeekOrigin.Begin);
                rawStream.WriteValueS32(nameIndex);
                //rawStream.Seek(32, SeekOrigin.Begin);
                rawStream.WriteValueS32(0);
                properties["LODGroup"].raw = rawStream.ToArray();
            }
            //LODGroup.Value.IntValue = pccRef.Names.FindIndex(name => name == newTextureGroupName);

            /*MessageBox.Show("Texturegroup Name: " + textureGroupName);
             * ImageSize maxImageSize = imgList.Max(image => image.imgSize);
             * int textureGroupValue = (int)Math.Max(maxImageSize.width, maxImageSize.height) + 1;
             *
             * // open Engine.pcc file and edit TextureGroup enumerator
             * {
             *  PCCObject pccEngine = new PCCObject(ME3Directory.cookedPath + "Engine.pcc");
             *  int idxTexGroups = pccEngine.Exports.FindIndex(export => export.ObjectName == "TextureGroup");
             *
             *  TextureGroup texGroup = new TextureGroup(pccEngine, pccEngine.Exports[idxTexGroups].Data);
             *  if (texGroup.ExistsTextureGroup(textureGroupName, textureGroupValue))
             *      return;
             *  else
             *  {
             *      if (!pccEngine.Names.Exists(name => name == newTextureGroupName))
             *          pccEngine.Names.Add(newTextureGroupName);
             *
             *      newTextureGroup = textureGroupName + "_" + (textureGroupValue - 1);
             *
             *      texGroup.Add(textureGroupName, textureGroupValue);
             *      MessageBox.Show("Now editing texgroup enum");
             *      pccEngine.Exports[idxTexGroups].Data = texGroup.ToArray();
             *      MessageBox.Show("Now saving engine.pcc");
             *      pccEngine.saveToFile(true, ME3Directory.cookedPath + "Engine.pcc");
             *      MessageBox.Show("Saved engine.pcc");
             *
             *
             *  }
             * }*/
        }
Exemple #6
0
        public void Save()
        {
            int tmp1, tmp2, size;

            if (pcc == null)
            {
                return;
            }
            MemoryStream m = new MemoryStream();

            m.Write(BitConverter.GetBytes(Unk1), 0, 4);
            foreach (PropertyReader.Property p in Props)
            {
                switch (pcc.getNameEntry(p.Name))
                {
                case "m_StartingList":
                    m.Write(p.raw, 0, 0x10);
                    m.Write(BitConverter.GetBytes(StartingList.Count * 4 + 4), 0, 4);
                    m.Write(BitConverter.GetBytes(0), 0, 4);
                    m.Write(BitConverter.GetBytes(StartingList.Count), 0, 4);
                    foreach (int i in StartingList)
                    {
                        m.Write(BitConverter.GetBytes(i), 0, 4);
                    }
                    break;

                case "m_EntryList":
                    tmp1 = (int)m.Position;
                    m.Write(p.raw, 0, 0x10);
                    m.Write(new byte[8], 0, 8);
                    m.Write(BitConverter.GetBytes(EntryList.Count), 0, 4);
                    size = 4;
                    foreach (EntryListStuct el in EntryList)
                    {
                        size += WriteEntryList(m, el);
                    }
                    tmp2 = (int)m.Position;
                    m.Seek(tmp1 + 0x10, 0);
                    m.Write(BitConverter.GetBytes(size), 0, 4);
                    m.Seek(tmp2, 0);
                    break;

                case "m_ReplyList":
                    tmp1 = (int)m.Position;
                    m.Write(p.raw, 0, 0x10);
                    m.Write(new byte[8], 0, 8);
                    m.Write(BitConverter.GetBytes(ReplyList.Count), 0, 4);
                    size = 4;
                    foreach (ReplyListStruct rp in ReplyList)
                    {
                        size += WriteReplyList(m, rp);
                    }
                    tmp2 = (int)m.Position;
                    m.Seek(tmp1 + 0x10, 0);
                    m.Write(BitConverter.GetBytes(size), 0, 4);
                    m.Seek(tmp2, 0);
                    break;

                case "m_aSpeakerList":
                    m.Write(p.raw, 0, 0x10);
                    m.Write(BitConverter.GetBytes(SpeakerList.Count * 8 + 4), 0, 4);
                    m.Write(BitConverter.GetBytes(0), 0, 4);
                    m.Write(BitConverter.GetBytes(SpeakerList.Count), 0, 4);
                    foreach (NameReference name in SpeakerList)
                    {
                        m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(name.Name)), 0, 4);
                        m.Write(BitConverter.GetBytes(name.Number), 0, 4);
                    }

                    break;

                case "m_aFemaleFaceSets":
                    m.Write(p.raw, 0, 0x10);
                    m.Write(BitConverter.GetBytes(FemaleFaceSets.Count * 4 + 4), 0, 4);
                    m.Write(BitConverter.GetBytes(0), 0, 4);
                    m.Write(BitConverter.GetBytes(FemaleFaceSets.Count), 0, 4);
                    foreach (int i in FemaleFaceSets)
                    {
                        m.Write(BitConverter.GetBytes(i), 0, 4);
                    }
                    break;

                case "m_aMaleFaceSets":
                    m.Write(p.raw, 0, 0x10);
                    m.Write(BitConverter.GetBytes(MaleFaceSets.Count * 4 + 4), 0, 4);
                    m.Write(BitConverter.GetBytes(0), 0, 4);
                    m.Write(BitConverter.GetBytes(MaleFaceSets.Count), 0, 4);
                    foreach (int i in MaleFaceSets)
                    {
                        m.Write(BitConverter.GetBytes(i), 0, 4);
                    }
                    break;

                case "m_aStageDirections":
                    tmp1 = (int)m.Position;
                    m.Write(p.raw, 0, 0x10);
                    m.Write(new byte[8], 0, 8);
                    m.Write(BitConverter.GetBytes(StageDirections.Count), 0, 4);
                    size = 4;
                    foreach (StageDirectionStruct sd in StageDirections)
                    {
                        size += WriteStageDirection(m, sd);
                    }
                    tmp2 = (int)m.Position;
                    m.Seek(tmp1 + 0x10, 0);
                    m.Write(BitConverter.GetBytes(size), 0, 4);
                    m.Seek(tmp2, 0);
                    break;

                default:
                    m.Write(p.raw, 0, p.raw.Length);
                    break;
                }
            }
            m.Write(BitConverter.GetBytes(0), 0, 4);
            export.Data = m.ToArray();
        }