Ejemplo n.º 1
0
 protected ActorNode(int idx, IMEPackage p)
 {
     pcc              = p;
     index            = idx;
     export           = pcc.getExport(index);
     comment          = new SText(GetComment(), commentColor, false);
     comment.X        = 0;
     comment.Y        = 0 - comment.Height;
     comment.Pickable = false;
     this.AddChild(comment);
     this.Pickable = true;
 }
Ejemplo n.º 2
0
 protected SObj(int idx, IMEPackage p)
 {
     pcc = p;
     index = idx;
     export = pcc.getExport(index);
     comment = new SText(GetComment(), commentColor, false);
     comment.X = 0;
     comment.Y = 0 - comment.Height;
     comment.Pickable = false;
     this.AddChild(comment);
     this.Pickable = true;
 }
Ejemplo n.º 3
0
 protected SplineNode(int idx, IMEPackage p, PathingGraphEditor grapheditor)
 {
     Tag              = new ArrayList(); //outbound reachspec edges.
     pcc              = p;
     g                = grapheditor;
     index            = idx;
     export           = pcc.getExport(index);
     comment          = new SText(GetComment(), commentColor, false);
     comment.X        = 0;
     comment.Y        = 52 + comment.Height;
     comment.Pickable = false;
     this.AddChild(comment);
     this.Pickable = true;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to relink unreal binary data to object pointers if they are part of the clone tree.
        /// It's gonna be an ugly mess.
        /// </summary>
        /// <param name="importpcc">PCC being imported from</param>
        private List <string> relinkBinaryObjects(IMEPackage importpcc)
        {
            List <string> relinkFailedReport = new List <string>();

            foreach (KeyValuePair <int, int> entry in crossPCCObjectMap)
            {
                if (entry.Key > 0)
                {
                    IExportEntry exp        = pcc.getExport(entry.Value);
                    byte[]       binarydata = exp.getBinaryData();
                    if (binarydata.Length > 0)
                    {
                        //has binary data
                        //This is temporary until I find a more permanent style for relinking binary
                        try
                        {
                            switch (exp.ClassName)
                            {
                            case "WwiseEvent":
                            {
                                int count = BitConverter.ToInt32(binarydata, 0);
                                for (int i = 0; i < count; i++)
                                {
                                    int  originalValue    = BitConverter.ToInt32(binarydata, 4 + (i * 4));
                                    int  currentObjectRef = unrealIndexToME3ExpIndexing(originalValue);        //count + i * intsize
                                    int  mapped;
                                    bool isMapped = crossPCCObjectMap.TryGetValue(currentObjectRef, out mapped);
                                    if (isMapped)
                                    {
                                        mapped = me3ExpIndexingToUnreal(mapped, originalValue < 0);         //if the value is 0, it would have an error anyways.
                                        Debug.WriteLine("Binary relink hit for WwiseEvent Export " + exp.UIndex + " 0x" + (4 + (i * 4)).ToString("X6") + " " + originalValue + " -> " + (mapped + 1));
                                        WriteMem(4 + (i * 4), binarydata, BitConverter.GetBytes(mapped));
                                        int newValue = BitConverter.ToInt32(binarydata, 4 + (i * 4));
                                        Debug.WriteLine(originalValue + " -> " + newValue);
                                    }
                                    else
                                    {
                                        Debug.WriteLine("Binary relink missed WwiseEvent Export " + exp.UIndex + " 0x" + (4 + (i * 4)).ToString("X6") + " " + originalValue);
                                        relinkFailedReport.Add(exp.Index + " " + exp.GetFullPath + " binary relink error: WwiseEvent referenced WwiseStream " + originalValue + " is not in the mapping tree and could not be relinked");
                                    }
                                }
                                exp.setBinaryData(binarydata);
                            }
                            break;

                            case "Class":
                            {
                                if (exp.FileRef.Game != importpcc.Game)
                                {
                                    //Cannot relink against a different game.
                                    continue;
                                }
                                IExportEntry importingExp = importpcc.getExport(entry.Key);
                                if (importingExp.ClassName != "Class")
                                {
                                    continue;         //the class was not actually set, so this is not really class.
                                }

                                //This is going to be pretty ugly
                                try
                                {
                                    byte[] newdata = importpcc.Exports[entry.Key].Data;         //may need to rewrite first unreal header
                                    byte[] data    = importpcc.Exports[entry.Key].Data;

                                    int offset            = 0;
                                    int unrealExportIndex = BitConverter.ToInt32(data, offset);
                                    offset += 4;


                                    int superclassIndex = BitConverter.ToInt32(data, offset);
                                    if (superclassIndex < 0)
                                    {
                                        //its an import
                                        ImportEntry superclassImportEntry = importpcc.Imports[Math.Abs(unrealIndexToME3ExpIndexing(superclassIndex))];
                                        ImportEntry newSuperclassValue    = getOrAddCrossImport(superclassImportEntry.GetFullPath, importpcc, exp.FileRef);
                                        WriteMem(offset, newdata, BitConverter.GetBytes(newSuperclassValue.UIndex));
                                    }
                                    else
                                    {
                                        relinkFailedReport.Add(exp.Index + " " + exp.GetFullPath + " binary relink error: Superclass is an export in the source package and was not relinked.");
                                    }


                                    int unknown1 = BitConverter.ToInt32(data, offset);
                                    offset += 4;

                                    int classObjTree = BitConverter.ToInt32(data, offset);         //Don't know if I need to do this.
                                    offset += 4;


                                    //I am not sure what these mean. However if Pt1&2 are 33/25, the following bytes that follow are extended.
                                    int   headerUnknown1 = BitConverter.ToInt32(data, offset);
                                    Int64 ignoreMask     = BitConverter.ToInt64(data, offset);
                                    offset += 8;

                                    Int16 labelOffset = BitConverter.ToInt16(data, offset);
                                    offset += 2;
                                    int skipAmount = 0x6;
                                    //Find end of script block. Seems to be 10 FF's.
                                    while (offset + skipAmount + 10 < data.Length)
                                    {
                                        //Debug.WriteLine("Cheecking at 0x"+(offset + skipAmount + 10).ToString("X4"));
                                        bool isEnd = true;
                                        for (int i = 0; i < 10; i++)
                                        {
                                            byte b = data[offset + skipAmount + i];
                                            if (b != 0xFF)
                                            {
                                                isEnd = false;
                                                break;
                                            }
                                        }
                                        if (isEnd)
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            skipAmount++;
                                        }
                                    }

                                    int offsetEnd = offset + skipAmount + 10;
                                    offset += skipAmount + 10;         //heuristic to find end of script
                                    uint stateMask = BitConverter.ToUInt32(data, offset);
                                    offset += 4;

                                    int localFunctionsTableCount = BitConverter.ToInt32(data, offset);
                                    offset += 4;
                                    bool isMapped;
                                    for (int i = 0; i < localFunctionsTableCount; i++)
                                    {
                                        int           nameTableIndex = BitConverter.ToInt32(data, offset);
                                        int           nameIndex      = BitConverter.ToInt32(data, offset + 4);
                                        NameReference importingName  = importpcc.getNameEntry(nameTableIndex);
                                        int           newFuncName    = exp.FileRef.FindNameOrAdd(importingName);
                                        WriteMem(offset, newdata, BitConverter.GetBytes(newFuncName));
                                        offset += 8;

                                        int functionObjectIndex = unrealIndexToME3ExpIndexing(BitConverter.ToInt32(data, offset));
                                        int mapped;
                                        isMapped = crossPCCObjectMap.TryGetValue(functionObjectIndex, out mapped);
                                        if (isMapped)
                                        {
                                            mapped = me3ExpIndexingToUnreal(mapped, functionObjectIndex < 0);         //if the value is 0, it would have an error anyways.
                                            WriteMem(offset, newdata, BitConverter.GetBytes(mapped));
                                        }
                                        else
                                        {
                                            relinkFailedReport.Add(exp.Index + " " + exp.GetFullPath + " binary relink error: Local function[" + i + "] could not be remapped during porting: " + functionObjectIndex + " is not in the mapping tree and could not be relinked");
                                        }
                                        offset += 4;
                                    }

                                    int classMask = BitConverter.ToInt32(data, offset);
                                    offset += 4;
                                    if (importpcc.Game != MEGame.ME3)
                                    {
                                        offset += 1;         //seems to be a blank byte here
                                    }

                                    int coreReference = BitConverter.ToInt32(data, offset);
                                    if (coreReference < 0)
                                    {
                                        //its an import
                                        ImportEntry outerclassReferenceImport = importpcc.Imports[Math.Abs(unrealIndexToME3ExpIndexing(coreReference))];
                                        ImportEntry outerclassNewImport       = getOrAddCrossImport(outerclassReferenceImport.GetFullPath, importpcc, exp.FileRef);
                                        WriteMem(offset, newdata, BitConverter.GetBytes(outerclassNewImport.UIndex));
                                    }
                                    else
                                    {
                                        relinkFailedReport.Add(exp.Index + " " + exp.GetFullPath + " binary relink error: Outerclass is an export in the original package, not relinked.");
                                    }
                                    offset += 4;


                                    if (importpcc.Game == MEGame.ME3)
                                    {
                                        offset = ClassParser_RelinkComponentsTable(importpcc, exp, relinkFailedReport, ref newdata, offset);
                                        offset = ClassParser_ReadImplementsTable(importpcc, exp, relinkFailedReport, ref newdata, offset);
                                        int    postComponentsNoneNameIndex = BitConverter.ToInt32(data, offset);
                                        int    postComponentNoneIndex      = BitConverter.ToInt32(data, offset + 4);
                                        string postCompName = importpcc.getNameEntry(postComponentsNoneNameIndex);         //This appears to be unused in ME3, it is always None it seems.
                                        int    newFuncName  = exp.FileRef.FindNameOrAdd(postCompName);
                                        WriteMem(offset, newdata, BitConverter.GetBytes(newFuncName));
                                        offset += 8;

                                        int unknown4 = BitConverter.ToInt32(data, offset);
                                        offset += 4;
                                    }
                                    else
                                    {
                                        offset = ClassParser_ReadImplementsTable(importpcc, exp, relinkFailedReport, ref data, offset);
                                        offset = ClassParser_RelinkComponentsTable(importpcc, exp, relinkFailedReport, ref data, offset);

                                        int me12unknownend1 = BitConverter.ToInt32(data, offset);
                                        offset += 4;

                                        int me12unknownend2 = BitConverter.ToInt32(data, offset);
                                        offset += 4;
                                    }

                                    int defaultsClassLink = unrealIndexToME3ExpIndexing(BitConverter.ToInt32(data, offset));
                                    int defClassLink;
                                    isMapped = crossPCCObjectMap.TryGetValue(defaultsClassLink, out defClassLink);
                                    if (isMapped)
                                    {
                                        defClassLink = me3ExpIndexingToUnreal(defClassLink, defaultsClassLink < 0);         //if the value is 0, it would have an error anyways.
                                        WriteMem(offset, newdata, BitConverter.GetBytes(defClassLink));
                                    }
                                    else
                                    {
                                        relinkFailedReport.Add(exp.Index + " " + exp.GetFullPath + " binary relink error: DefaultsClassLink cannot be currently automatically relinked by Binary Relinker. Please manually set this in Binary Editor");
                                    }
                                    offset += 4;

                                    if (importpcc.Game == MEGame.ME3)
                                    {
                                        int functionsTableCount = BitConverter.ToInt32(data, offset);
                                        offset += 4;

                                        for (int i = 0; i < functionsTableCount; i++)
                                        {
                                            int functionsTableIndex = unrealIndexToME3ExpIndexing(BitConverter.ToInt32(data, offset));
                                            int mapped;
                                            isMapped = crossPCCObjectMap.TryGetValue(functionsTableIndex, out mapped);
                                            if (isMapped)
                                            {
                                                mapped = me3ExpIndexingToUnreal(mapped, functionsTableIndex < 0);         //if the value is 0, it would have an error anyways.
                                                WriteMem(offset, newdata, BitConverter.GetBytes(mapped));
                                            }
                                            else
                                            {
                                                if (functionsTableIndex < 0)
                                                {
                                                    ImportEntry functionObjIndex    = importpcc.Imports[Math.Abs(functionsTableIndex)];
                                                    ImportEntry newFunctionObjIndex = getOrAddCrossImport(functionObjIndex.GetFullPath, importpcc, exp.FileRef);
                                                    WriteMem(offset, newdata, BitConverter.GetBytes(newFunctionObjIndex.UIndex));
                                                }
                                                else
                                                {
                                                    relinkFailedReport.Add(exp.Index + " " + exp.GetFullPath + " binary relink error: Full Functions List function[" + i + "] could not be remapped during porting: " + functionsTableIndex + " is not in the mapping tree and could not be relinked");
                                                }
                                            }
                                            offset += 4;
                                        }
                                    }
                                    exp.Data = newdata;
                                }
                                catch (Exception ex)
                                {
                                    relinkFailedReport.Add(exp.Index + " " + exp.GetFullPath + " binary relink error: Exception relinking: " + ex.Message);
                                }
                            }
                            break;

                            default:
                                continue;
                            }
                        }
                        catch (Exception e)
                        {
                            relinkFailedReport.Add(exp.Index + " " + exp.GetFullPath + " binary relinking failed: " + e.Message);
                        }
                        //Run an interpreter pass over it - we will find objectleafnodes and attempt to update the same offset in the destination file.
                        //BinaryInterpreter binaryrelinkInterpreter = new ME3Explorer.BinaryInterpreter(importpcc, importpcc.Exports[entry.Key], pcc, pcc.Exports[entry.Value], crossPCCObjectMapping);
                    }
                }
            }
            return(relinkFailedReport);
        }
Ejemplo n.º 5
0
 public static void propGridPropertyValueChanged(PropertyValueChangedEventArgs e, int n, IMEPackage pcc)
 {
     string name = e.ChangedItem.Label;
     GridItem parent = e.ChangedItem.Parent;
     //if (parent != null) name = parent.Label;
     if (parent.Label == "data")
     {
         GridItem parent2 = parent.Parent;
         if (parent2 != null) name = parent2.Label;
     }
     Type parentVal = null;
     if (parent.Value != null)
     {
         parentVal = parent.Value.GetType();
     }
     if (name == "nameindex" || name == "index" || parentVal == typeof(ColorProp) || parentVal == typeof(VectorProp) || parentVal == typeof(Unreal.RotatorProp) || parentVal == typeof(Unreal.LinearColorProp))
     {
         name = parent.Label;
     }
     IExportEntry ent = pcc.getExport(n);
     byte[] data = ent.Data;
     List<PropertyReader.Property> p = PropertyReader.getPropList(ent);
     int m = -1;
     for (int i = 0; i < p.Count; i++)
         if (pcc.getNameEntry(p[i].Name) == name)
             m = i;
     if (m == -1)
         return;
     byte[] buff2;
     switch (p[m].TypeVal)
     {
         case PropertyType.BoolProperty:
             byte res = 0;
             if ((bool)e.ChangedItem.Value == true)
                 res = 1;
             data[p[m].offsetval] = res;
             break;
         case PropertyType.FloatProperty:
             buff2 = BitConverter.GetBytes((float)e.ChangedItem.Value);
             for (int i = 0; i < 4; i++)
                 data[p[m].offsetval + i] = buff2[i];
             break;
         case PropertyType.IntProperty:
         case PropertyType.StringRefProperty:
             int newv = Convert.ToInt32(e.ChangedItem.Value);
             int oldv = Convert.ToInt32(e.OldValue);
             buff2 = BitConverter.GetBytes(newv);
             for (int i = 0; i < 4; i++)
                 data[p[m].offsetval + i] = buff2[i];
             break;
         case PropertyType.StrProperty:
             string s = Convert.ToString(e.ChangedItem.Value);
             int stringMultiplier = 1;
             int oldLength = BitConverter.ToInt32(data, p[m].offsetval);
             if (oldLength < 0)
             {
                 stringMultiplier = 2;
                 oldLength *= -2;
             }
             int oldSize = 4 + oldLength;
             List<byte> stringBuff = new List<byte>(s.Length * stringMultiplier);
             if (stringMultiplier == 2)
             {
                 for (int j = 0; j < s.Length; j++)
                 {
                     stringBuff.AddRange(BitConverter.GetBytes(s[j]));
                 }
                 stringBuff.Add(0);
             }
             else
             {
                 for (int j = 0; j < s.Length; j++)
                 {
                     stringBuff.Add(BitConverter.GetBytes(s[j])[0]);
                 }
             }
             stringBuff.Add(0);
             buff2 = BitConverter.GetBytes((s.Length + 1) * stringMultiplier + 4);
             for (int j = 0; j < 4; j++)
                 data[p[m].offsetval - 8 + j] = buff2[j];
             buff2 = BitConverter.GetBytes((s.Length + 1) * stringMultiplier == 1 ? 1 : -1);
             for (int j = 0; j < 4; j++)
                 data[p[m].offsetval + j] = buff2[j];
             buff2 = new byte[data.Length - oldLength + stringBuff.Count];
             int startLength = p[m].offsetval + 4;
             int startLength2 = startLength + oldLength;
             for (int i = 0; i < startLength; i++)
             {
                 buff2[i] = data[i];
             }
             for (int i = 0; i < stringBuff.Count; i++)
             {
                 buff2[i + startLength] = stringBuff[i];
             }
             startLength += stringBuff.Count;
             for (int i = 0; i < data.Length - startLength2; i++)
             {
                 buff2[i + startLength] = data[i + startLength2];
             }
             data = buff2;
             break;
         case PropertyType.StructProperty:
             if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(ColorProp))
             {
                 switch (e.ChangedItem.Label)
                 {
                     case "Alpha":
                         data[p[m].offsetval + 11] = Convert.ToByte(e.ChangedItem.Value);
                         break;
                     case "Red":
                         data[p[m].offsetval + 10] = Convert.ToByte(e.ChangedItem.Value);
                         break;
                     case "Green":
                         data[p[m].offsetval + 9] = Convert.ToByte(e.ChangedItem.Value);
                         break;
                     case "Blue":
                         data[p[m].offsetval + 8] = Convert.ToByte(e.ChangedItem.Value);
                         break;
                     default:
                         break;
                 }
             }
             else if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(VectorProp))
             {
                 int offset = 0;
                 switch (e.ChangedItem.Label)
                 {
                     case "X":
                         offset = 8;
                         break;
                     case "Y":
                         offset = 12;
                         break;
                     case "Z":
                         offset = 16;
                         break;
                     default:
                         break;
                 }
                 if (offset != 0)
                 {
                     buff2 = BitConverter.GetBytes(Convert.ToSingle(e.ChangedItem.Value));
                     for (int i = 0; i < 4; i++)
                         data[p[m].offsetval + offset + i] = buff2[i];
                 }
             }
             else if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(Unreal.RotatorProp))
             {
                 int offset = 0;
                 switch (e.ChangedItem.Label)
                 {
                     case "Pitch":
                         offset = 8;
                         break;
                     case "Yaw":
                         offset = 12;
                         break;
                     case "Roll":
                         offset = 16;
                         break;
                     default:
                         break;
                 }
                 if (offset != 0)
                 {
                     int val = Convert.ToInt32(Convert.ToSingle(e.ChangedItem.Value) * 65536f / 360f);
                     buff2 = BitConverter.GetBytes(val);
                     for (int i = 0; i < 4; i++)
                         data[p[m].offsetval + offset + i] = buff2[i];
                 }
             }
             else if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(Unreal.LinearColorProp))
             {
                 int offset = 0;
                 switch (e.ChangedItem.Label)
                 {
                     case "Red":
                         offset = 8;
                         break;
                     case "Green":
                         offset = 12;
                         break;
                     case "Blue":
                         offset = 16;
                         break;
                     case "Alpha":
                         offset = 20;
                         break;
                     default:
                         break;
                 }
                 if (offset != 0)
                 {
                     buff2 = BitConverter.GetBytes(Convert.ToSingle(e.ChangedItem.Value));
                     for (int i = 0; i < 4; i++)
                         data[p[m].offsetval + offset + i] = buff2[i];
                 }
             }
             else if (e.ChangedItem.Value is int)
             {
                 int val = Convert.ToInt32(e.ChangedItem.Value);
                 if (e.ChangedItem.Label == "nameindex")
                 {
                     int val1 = Convert.ToInt32(e.ChangedItem.Value);
                     buff2 = BitConverter.GetBytes(val1);
                     for (int i = 0; i < 4; i++)
                         data[p[m].offsetval + i] = buff2[i];
                 }
                 else
                 {
                     string sidx = e.ChangedItem.Label.Replace("[", "");
                     sidx = sidx.Replace("]", "");
                     int index = Convert.ToInt32(sidx);
                     buff2 = BitConverter.GetBytes(val);
                     for (int i = 0; i < 4; i++)
                         data[p[m].offsetval + i + index * 4 + 8] = buff2[i];
                 }
             }
             break;
         case PropertyType.ByteProperty:
         case PropertyType.NameProperty:
             if (e.ChangedItem.Value is int)
             {
                 int val = Convert.ToInt32(e.ChangedItem.Value);
                 buff2 = BitConverter.GetBytes(val);
                 for (int i = 0; i < 4; i++)
                     data[p[m].offsetval + i] = buff2[i];
             }
             break;
         case PropertyType.ObjectProperty:
             if (e.ChangedItem.Value is int)
             {
                 int val = Convert.ToInt32(e.ChangedItem.Value);
                 buff2 = BitConverter.GetBytes(val);
                 for (int i = 0; i < 4; i++)
                     data[p[m].offsetval + i] = buff2[i];
             }
             break;
         default:
             return;
     }
     ent.Data = data;
 }
Ejemplo n.º 6
0
 public TreeNode FindSequences(IMEPackage pcc, int index, bool wantFullName = false)
 {
     TreeNode ret = new TreeNode("#" + index + ": " + (wantFullName ? pcc.getExport(index).GetFullPath : pcc.getExport(index).ObjectName));
     ret.Name = index.ToString();
     var seqObjs = pcc.getExport(index).GetProperty<ArrayProperty<ObjectProperty>>("SequenceObjects");
     if (seqObjs != null)
     {
         IExportEntry exportEntry;
         foreach (ObjectProperty seqObj in seqObjs)
         {
             exportEntry = pcc.getExport(seqObj.Value - 1);
             if (exportEntry.ClassName == "Sequence" || exportEntry.ClassName.StartsWith("PrefabSequence"))
             {
                 TreeNode t = FindSequences(pcc, seqObj.Value - 1, false);
                 ret.Nodes.Add(t);
             }
             else if (exportEntry.ClassName == "SequenceReference")
             {
                 var propSequenceReference = exportEntry.GetProperty<ObjectProperty>("oSequenceReference");
                 if (propSequenceReference != null)
                 {
                     TreeNode t = FindSequences(pcc, propSequenceReference.Value - 1, false);
                     ret.Nodes.Add(t);
                 }
             }
         }
     }
     return ret;
 }
Ejemplo n.º 7
0
 private bool importExport(IMEPackage importpcc, int n, int link)
 {
     IExportEntry ex = importpcc.getExport(n);
     IExportEntry nex = null;
     switch (pcc.Game)
     {
         case MEGame.ME1:
             nex = new ME1ExportEntry(pcc as ME1Package);
             break;
         case MEGame.ME2:
             nex = new ME2ExportEntry(pcc as ME2Package);
             break;
         case MEGame.ME3:
             nex = new ME3ExportEntry(pcc as ME3Package);
             break;
     }
     byte[] idata = ex.Data;
     PropertyCollection props = ex.GetProperties();
     int start = ex.GetPropertyStart();
     int end = props.endOffset;
     MemoryStream res = new MemoryStream();
     if ((importpcc.getExport(n).ObjectFlags & (ulong)UnrealFlags.EObjectFlags.HasStack) != 0)
     {
         byte[] stackdummy = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //Lets hope for the best :D
                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,};
         if (pcc.Game != MEGame.ME3)
         {
             stackdummy = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,};
         }
         res.Write(stackdummy, 0, stackdummy.Length);
     }
     else
     {
         res.Write(new byte[start], 0, start);
     }
     //store copy of names list in case something goes wrong
     List<string> names = pcc.Names.ToList();
     try
     {
         props.WriteTo(res, pcc);
     }
     catch (Exception exception)
     {
         //restore namelist
         pcc.setNames(names);
         MessageBox.Show("Error occured while trying to import " + ex.ObjectName + " : " + exception.Message);
         return false;
     }
     if (importpcc.Game == MEGame.ME3 && importpcc.getObjectName(ex.idxClass) == "SkeletalMesh")
     {
         SkeletalMesh skl = new SkeletalMesh(importpcc as ME3Package, n);
         SkeletalMesh.BoneStruct bone;
         for (int i = 0; i < skl.Bones.Count; i++)
         {
             bone = skl.Bones[i];
             string s = importpcc.getNameEntry(bone.Name);
             bone.Name = pcc.FindNameOrAdd(s);
             skl.Bones[i] = bone;
         }
         SkeletalMesh.TailNamesStruct tailName;
         for (int i = 0; i < skl.TailNames.Count; i++)
         {
             tailName = skl.TailNames[i];
             string s = importpcc.getNameEntry(tailName.Name);
             tailName.Name = pcc.FindNameOrAdd(s);
             skl.TailNames[i] = tailName;
         }
         SerializingContainer container = new SerializingContainer(res);
         container.isLoading = false;
         skl.Serialize(container);
     }
     else
     {
         res.Write(idata, end, idata.Length - end);
     }
     nex.setHeader((byte[])ex.header.Clone());
     nex.Data = res.ToArray();
     nex.idxObjectName = pcc.FindNameOrAdd(importpcc.getNameEntry(ex.idxObjectName));
     nex.idxLink = link;
     nex.idxArchtype = nex.idxClass = nex.idxClassParent = 0;
     pcc.addExport(nex);
     return true;
 }
Ejemplo n.º 8
0
        public static void propGridPropertyValueChanged(PropertyValueChangedEventArgs e, int n, IMEPackage pcc)
        {
            string   name   = e.ChangedItem.Label;
            GridItem parent = e.ChangedItem.Parent;

            //if (parent != null) name = parent.Label;
            if (parent.Label == "data")
            {
                GridItem parent2 = parent.Parent;
                if (parent2 != null)
                {
                    name = parent2.Label;
                }
            }
            Type parentVal = null;

            if (parent.Value != null)
            {
                parentVal = parent.Value.GetType();
            }
            if (name == "nameindex" || name == "index" || parentVal == typeof(ColorProp) || parentVal == typeof(VectorProp) || parentVal == typeof(Unreal.RotatorProp) || parentVal == typeof(Unreal.LinearColorProp))
            {
                name = parent.Label;
            }
            IExportEntry ent = pcc.getExport(n);

            byte[] data = ent.Data;
            List <PropertyReader.Property> p = PropertyReader.getPropList(ent);
            int m = -1;

            for (int i = 0; i < p.Count; i++)
            {
                if (pcc.getNameEntry(p[i].Name) == name)
                {
                    m = i;
                }
            }
            if (m == -1)
            {
                return;
            }
            byte[] buff2;
            switch (p[m].TypeVal)
            {
            case PropertyType.BoolProperty:
                byte res = 0;
                if ((bool)e.ChangedItem.Value == true)
                {
                    res = 1;
                }
                data[p[m].offsetval] = res;
                break;

            case PropertyType.FloatProperty:
                buff2 = BitConverter.GetBytes((float)e.ChangedItem.Value);
                for (int i = 0; i < 4; i++)
                {
                    data[p[m].offsetval + i] = buff2[i];
                }
                break;

            case PropertyType.IntProperty:
            case PropertyType.StringRefProperty:
                int newv = Convert.ToInt32(e.ChangedItem.Value);
                int oldv = Convert.ToInt32(e.OldValue);
                buff2 = BitConverter.GetBytes(newv);
                for (int i = 0; i < 4; i++)
                {
                    data[p[m].offsetval + i] = buff2[i];
                }
                break;

            case PropertyType.StrProperty:
                string s = Convert.ToString(e.ChangedItem.Value);
                int    stringMultiplier = 1;
                int    oldLength        = BitConverter.ToInt32(data, p[m].offsetval);
                if (oldLength < 0)
                {
                    stringMultiplier = 2;
                    oldLength       *= -2;
                }
                int         oldSize    = 4 + oldLength;
                List <byte> stringBuff = new List <byte>(s.Length * stringMultiplier);
                if (stringMultiplier == 2)
                {
                    for (int j = 0; j < s.Length; j++)
                    {
                        stringBuff.AddRange(BitConverter.GetBytes(s[j]));
                    }
                    stringBuff.Add(0);
                }
                else
                {
                    for (int j = 0; j < s.Length; j++)
                    {
                        stringBuff.Add(BitConverter.GetBytes(s[j])[0]);
                    }
                }
                stringBuff.Add(0);
                buff2 = BitConverter.GetBytes((s.Length + 1) * stringMultiplier + 4);
                for (int j = 0; j < 4; j++)
                {
                    data[p[m].offsetval - 8 + j] = buff2[j];
                }
                buff2 = BitConverter.GetBytes((s.Length + 1) * stringMultiplier == 1 ? 1 : -1);
                for (int j = 0; j < 4; j++)
                {
                    data[p[m].offsetval + j] = buff2[j];
                }
                buff2 = new byte[data.Length - oldLength + stringBuff.Count];
                int startLength  = p[m].offsetval + 4;
                int startLength2 = startLength + oldLength;
                for (int i = 0; i < startLength; i++)
                {
                    buff2[i] = data[i];
                }
                for (int i = 0; i < stringBuff.Count; i++)
                {
                    buff2[i + startLength] = stringBuff[i];
                }
                startLength += stringBuff.Count;
                for (int i = 0; i < data.Length - startLength2; i++)
                {
                    buff2[i + startLength] = data[i + startLength2];
                }
                data = buff2;
                break;

            case PropertyType.StructProperty:
                if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(ColorProp))
                {
                    switch (e.ChangedItem.Label)
                    {
                    case "Alpha":
                        data[p[m].offsetval + 11] = Convert.ToByte(e.ChangedItem.Value);
                        break;

                    case "Red":
                        data[p[m].offsetval + 10] = Convert.ToByte(e.ChangedItem.Value);
                        break;

                    case "Green":
                        data[p[m].offsetval + 9] = Convert.ToByte(e.ChangedItem.Value);
                        break;

                    case "Blue":
                        data[p[m].offsetval + 8] = Convert.ToByte(e.ChangedItem.Value);
                        break;

                    default:
                        break;
                    }
                }
                else if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(VectorProp))
                {
                    int offset = 0;
                    switch (e.ChangedItem.Label)
                    {
                    case "X":
                        offset = 8;
                        break;

                    case "Y":
                        offset = 12;
                        break;

                    case "Z":
                        offset = 16;
                        break;

                    default:
                        break;
                    }
                    if (offset != 0)
                    {
                        buff2 = BitConverter.GetBytes(Convert.ToSingle(e.ChangedItem.Value));
                        for (int i = 0; i < 4; i++)
                        {
                            data[p[m].offsetval + offset + i] = buff2[i];
                        }
                    }
                }
                else if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(Unreal.RotatorProp))
                {
                    int offset = 0;
                    switch (e.ChangedItem.Label)
                    {
                    case "Pitch":
                        offset = 8;
                        break;

                    case "Yaw":
                        offset = 12;
                        break;

                    case "Roll":
                        offset = 16;
                        break;

                    default:
                        break;
                    }
                    if (offset != 0)
                    {
                        int val = Convert.ToSingle(e.ChangedItem.Value).ToUnrealRotationUnits();
                        buff2 = BitConverter.GetBytes(val);
                        for (int i = 0; i < 4; i++)
                        {
                            data[p[m].offsetval + offset + i] = buff2[i];
                        }
                    }
                }
                else if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(Unreal.LinearColorProp))
                {
                    int offset = 0;
                    switch (e.ChangedItem.Label)
                    {
                    case "Red":
                        offset = 8;
                        break;

                    case "Green":
                        offset = 12;
                        break;

                    case "Blue":
                        offset = 16;
                        break;

                    case "Alpha":
                        offset = 20;
                        break;

                    default:
                        break;
                    }
                    if (offset != 0)
                    {
                        buff2 = BitConverter.GetBytes(Convert.ToSingle(e.ChangedItem.Value));
                        for (int i = 0; i < 4; i++)
                        {
                            data[p[m].offsetval + offset + i] = buff2[i];
                        }
                    }
                }
                else if (e.ChangedItem.Value is int)
                {
                    int val = Convert.ToInt32(e.ChangedItem.Value);
                    if (e.ChangedItem.Label == "nameindex")
                    {
                        int val1 = Convert.ToInt32(e.ChangedItem.Value);
                        buff2 = BitConverter.GetBytes(val1);
                        for (int i = 0; i < 4; i++)
                        {
                            data[p[m].offsetval + i] = buff2[i];
                        }
                    }
                    else
                    {
                        string sidx = e.ChangedItem.Label.Replace("[", "");
                        sidx = sidx.Replace("]", "");
                        int index = Convert.ToInt32(sidx);
                        buff2 = BitConverter.GetBytes(val);
                        for (int i = 0; i < 4; i++)
                        {
                            data[p[m].offsetval + i + index * 4 + 8] = buff2[i];
                        }
                    }
                }
                break;

            case PropertyType.ByteProperty:
            case PropertyType.NameProperty:
                if (e.ChangedItem.Value is int)
                {
                    int val = Convert.ToInt32(e.ChangedItem.Value);
                    buff2 = BitConverter.GetBytes(val);
                    for (int i = 0; i < 4; i++)
                    {
                        data[p[m].offsetval + i] = buff2[i];
                    }
                }
                break;

            case PropertyType.ObjectProperty:
                if (e.ChangedItem.Value is int)
                {
                    int val = Convert.ToInt32(e.ChangedItem.Value);
                    buff2 = BitConverter.GetBytes(val);
                    for (int i = 0; i < 4; i++)
                    {
                        data[p[m].offsetval + i] = buff2[i];
                    }
                }
                break;

            default:
                return;
            }
            ent.Data = data;
        }