public void ExportOBJ(string path) { using (StreamWriter writer = new StreamWriter(path)) using (StreamWriter mtlWriter = new StreamWriter(Path.ChangeExtension(path, ".mtl"))) { writer.WriteLine("mtllib " + Path.GetFileNameWithoutExtension(path) + ".mtl"); // Vertices List <Vector3> points = null; List <Vector2> uvs = null; Dictionary <int, int> LODVertexOffsets = new Dictionary <int, int>(); // offset into the OBJ vertices that each buffer starts at points = new List <Vector3>(); uvs = new List <Vector2>(); int index = 0; int lodIndex = 0; foreach (var lod in LODModels) { LODVertexOffsets.Add(lodIndex, index); foreach (var gpuVertex in lod.VertexBufferGPUSkin.Vertices) { points.Add(gpuVertex.Position); uvs.Add(new Vector2(HalfToFloat(gpuVertex.U), HalfToFloat(gpuVertex.V))); } foreach (var mat in MatInsts) { mtlWriter.WriteLine("newmtl " + Owner.getObjectName(mat.index)); } lodIndex++; index += lod.NumVertices; } for (int i = 0; i < points.Count; i++) { Vector3 v = points[i]; writer.WriteLine("v " + v.X.ToString(CultureInfo.InvariantCulture) + " " + v.Z.ToString(CultureInfo.InvariantCulture) + " " + v.Y.ToString(CultureInfo.InvariantCulture)); writer.WriteLine("vt " + uvs[i].X.ToString(CultureInfo.InvariantCulture) + " " + uvs[i].Y.ToString(CultureInfo.InvariantCulture)); } // Triangles lodIndex = 0; foreach (var lod in LODModels) { int lodStart = LODVertexOffsets[lodIndex]; foreach (var section in lod.Sections) { writer.WriteLine("usemtl " + Owner.getObjectName(MatInsts[section.MaterialIndex].index)); writer.WriteLine("g LOD" + lodIndex + "-" + Owner.getObjectName(MatInsts[section.MaterialIndex].index)); for (int i = section.BaseIndex; i < section.BaseIndex + section.NumTriangles * 3; i += 3) { writer.WriteLine("f " + (lodStart + lod.IndexBuffer.Indexes[i] + 1).ToString(CultureInfo.InvariantCulture) + "/" + (lodStart + lod.IndexBuffer.Indexes[i] + 1).ToString(CultureInfo.InvariantCulture) + " " + (lodStart + lod.IndexBuffer.Indexes[i + 1] + 1).ToString(CultureInfo.InvariantCulture) + "/" + (lodStart + lod.IndexBuffer.Indexes[i + 1] + 1).ToString(CultureInfo.InvariantCulture) + " " + (lodStart + lod.IndexBuffer.Indexes[i + 2] + 1).ToString(CultureInfo.InvariantCulture) + "/" + (lodStart + lod.IndexBuffer.Indexes[i + 2] + 1).ToString(CultureInfo.InvariantCulture)); } } lodIndex++; } } }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { IMEPackage pcc = values[1] as IMEPackage; if (values[0] is int && pcc != null) { int uIndex = (int)values[0]; return($"({pcc.getObjectName(uIndex)})"); } return("()"); }
public TreeNode ToTree() { TreeNode res = new TreeNode("#" + index + " \"" + pcc.Exports[index].ObjectName + "\""); for (int i = 0; i < Textures.Count(); i++) { string s = Textures[i].Desc + " = #" + (Textures[i].TexIndex - 1); s += " \"" + pcc.getObjectName(Textures[i].TexIndex) + "\""; res.Nodes.Add(s); } TreeNode propsnode = new TreeNode("Properties"); res.Nodes.Add(propsnode); props = PropertyReader.getPropList(pcc.Exports[index]); for (int i = 0; i < props.Count(); i++) // Loop through props of export { string name = pcc.getNameEntry(props[i].Name); TreeNode propnode = new TreeNode(name + " | " + props[i].TypeVal.ToString()); propsnode.Nodes.Add(propnode); } return(res); }
public static CustomProperty PropertyToGrid(Property p, IMEPackage pcc) { string cat = p.TypeVal.ToString(); CustomProperty pg; NameProp pp; switch (p.TypeVal) { case PropertyType.BoolProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, (p.Value.IntValue == 1), typeof(bool), false, true); break; case PropertyType.FloatProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, p.Value.FloatValue, typeof(float), false, true); break; case PropertyType.ByteProperty: if (p.Size != 8) { pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, (byte)p.Value.IntValue, typeof(byte), false, true); } else { pp = new NameProp(); pp.name = pcc.getNameEntry(p.Value.IntValue); pp.nameindex = p.Value.IntValue; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, pp, typeof(NameProp), false, true); } break; case PropertyType.NameProperty: pp = new NameProp(); pp.name = pcc.getNameEntry(p.Value.IntValue); pp.nameindex = p.Value.IntValue; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, pp, typeof(NameProp), false, true); break; case PropertyType.ObjectProperty: ObjectProp ppo = new ObjectProp(); ppo.objectName = pcc.getObjectName(p.Value.IntValue); ppo.index = p.Value.IntValue; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, ppo, typeof(ObjectProp), false, true); break; case PropertyType.StrProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, p.Value.StringValue, typeof(string), false, true); break; case PropertyType.ArrayProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, BitConverter.ToInt32(p.raw, 24) + " elements", typeof(string), false, true); break; case PropertyType.StructProperty: string structType = pcc.getNameEntry(p.Value.IntValue); switch (structType) { case "Color": System.Drawing.Color color = System.Drawing.Color.FromArgb(BitConverter.ToInt32(p.raw, 32)); ColorProp cp = new ColorProp { name = structType, nameindex = p.Value.IntValue, Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B }; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, cp, typeof(ColorProp), false, true); break; case "Vector": VectorProp vp = new VectorProp { name = structType, nameindex = p.Value.IntValue, X = BitConverter.ToSingle(p.raw, 32), Y = BitConverter.ToSingle(p.raw, 36), Z = BitConverter.ToSingle(p.raw, 40) }; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, vp, typeof(VectorProp), false, true); break; case "Rotator": RotatorProp rp = new RotatorProp { name = structType, nameindex = p.Value.IntValue, Pitch = BitConverter.ToInt32(p.raw, 32).ToDegrees(), Yaw = BitConverter.ToInt32(p.raw, 36).ToDegrees(), Roll = BitConverter.ToInt32(p.raw, 40).ToDegrees() }; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, rp, typeof(RotatorProp), false, true); break; case "LinearColor": LinearColorProp lcp = new LinearColorProp { name = structType, nameindex = p.Value.IntValue, Red = BitConverter.ToSingle(p.raw, 32), Green = BitConverter.ToSingle(p.raw, 36), Blue = BitConverter.ToSingle(p.raw, 40), Alpha = BitConverter.ToSingle(p.raw, 44) }; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, lcp, typeof(VectorProp), false, true); break; default: byte[] buf = new byte[p.Value.Array.Count()]; for (int i = 0; i < p.Value.Array.Count(); i++) { buf[i] = (byte)p.Value.Array[i].IntValue; } List <int> buf2 = new List <int>(); for (int i = 0; i < p.Value.Array.Count() / 4; i++) { buf2.Add(BitConverter.ToInt32(buf, i * 4)); } StructProp ppp = new StructProp { name = structType, nameindex = p.Value.IntValue, data = buf2.ToArray() }; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, ppp, typeof(StructProp), false, true); break; } break; default: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, p.Value.IntValue, typeof(int), false, true); break; } return(pg); }
private BytecodeToken ReadNextInternal() { int readerpos = (int)_reader.BaseStream.Position; ME1OpCodes b = (ME1OpCodes)_reader.ReadByte(); switch (b) { case ME1OpCodes.EX_LocalVariable: case ME1OpCodes.EX_InstanceVariable: case ME1OpCodes.EX_NativeParm: return(ReadRef(r => r.ObjectName.Instanced)); case ME1OpCodes.EX_DefaultVariable: return(ReadRef(r => $"Default.{r.ObjectName.Instanced}")); case ME1OpCodes.EX_Return: { BytecodeToken returnValue = ReadNext(); return(new ReturnToken(returnValue, readerpos)); } case ME1OpCodes.EX_Assert: { _reader.ReadInt16(); _reader.ReadByte(); return(WrapNextBytecode(c => new BytecodeToken($"assert({c})", readerpos))); } case ME1OpCodes.EX_Switch: { byte b1 = _reader.ReadByte(); BytecodeToken switchExpr = ReadNext(); return(new SwitchToken(switchExpr.ToString(), switchExpr, readerpos)); } case ME1OpCodes.EX_Case: { short offset = _reader.ReadInt16(); if (offset == -1) { return(new DefaultToken(readerpos)); } BytecodeToken caseExpr = ReadNext(); return(new CaseToken(caseExpr.ToString(), readerpos)); } case ME1OpCodes.EX_Jump: { int offset = _reader.ReadInt16(); return(new UncondJumpToken(offset, readerpos)); } case ME1OpCodes.EX_JumpIfNot: { short offset = _reader.ReadInt16(); BytecodeToken condition = ReadNext(); if (IsInvalid(condition)) { return(WrapErrToken("if (!" + condition, condition)); } return(new JumpIfNotToken(offset, condition, readerpos)); } case ME1OpCodes.EX_LabelTable: { var token = new LabelTableToken(readerpos); while (true) { string labelName = ReadName(); if (labelName == "None") { break; } int offset = _reader.ReadInt32(); token.AddLabel(labelName, offset); } return(token); } case ME1OpCodes.EX_GotoLabel: return(WrapNextBytecode(op => Token("goto " + op, readerpos))); case ME1OpCodes.EX_Self: return(Token("self", readerpos)); case ME1OpCodes.EX_Skip: _reader.ReadInt16(); //Returning readnext causes a new token to be read return(ReadNext()); case ME1OpCodes.EX_EatReturnValue: _reader.ReadInt32(); return(ReadNext()); case ME1OpCodes.EX_Nothing: return(new NothingToken(readerpos)); case ME1OpCodes.EX_Stop: _reader.ReadInt16(); return(new NothingToken(readerpos)); case ME1OpCodes.EX_IntZero: return(Token("0", readerpos)); case ME1OpCodes.EX_IntOne: return(Token("1", readerpos)); case ME1OpCodes.EX_True: return(Token("true", readerpos)); case ME1OpCodes.EX_False: return(Token("false", readerpos)); case ME1OpCodes.EX_NoObject: case ME1OpCodes.EX_EmptyDelegate: return(Token("None", readerpos)); case ME1OpCodes.EX_Let: case ME1OpCodes.EX_LetBool: case ME1OpCodes.EX_LetDelegate: BytecodeToken lhs = ReadNext(); if (IsInvalid(lhs)) { return(lhs); } BytecodeToken rhs = ReadNext(); if (IsInvalid(rhs)) { return(WrapErrToken(lhs + " = " + rhs, rhs)); } return(Token(lhs + " = " + rhs, readerpos)); case ME1OpCodes.EX_IntConst: return(Token(_reader.ReadInt32().ToString(), readerpos)); case ME1OpCodes.EX_FloatConst: return(Token(_reader.ReadSingle().ToString(), readerpos)); case ME1OpCodes.EX_StringConst: { var s = ReadAsciiz().Replace("\n", "\\n").Replace("\t", "\\t"); return(Token($"\"{s}\"", readerpos)); } case ME1OpCodes.EX_ByteConst: case ME1OpCodes.EX_IntConstByte: return(Token(_reader.ReadByte().ToString(), readerpos)); case ME1OpCodes.EX_ObjectConst: { int objectIndex = _reader.ReadInt32(); var item = _package.GetEntry(objectIndex); if (item == null) { return(ErrToken("Unresolved class item " + objectIndex)); } return(Token($"{item.ClassName}'{item.ObjectName.Instanced}'", readerpos)); } case ME1OpCodes.EX_NameConst: return(Token($"'{ReadName()}'", readerpos)); case ME1OpCodes.EX_EndFunctionParms: return(new EndParmsToken(")", readerpos)); case ME1OpCodes.EX_ClassContext: case ME1OpCodes.EX_Context: { var context = ReadNext(); if (IsInvalid(context)) { return(context); } int exprSize = _reader.ReadInt16(); int bSize = _reader.ReadByte(); var value = ReadNext(); if (IsInvalid(value)) { return(WrapErrToken($"{context}.{value}", value)); } return(Token($"{context}.{value}", readerpos)); } case ME1OpCodes.EX_InterfaceContext: return(ReadNext()); case ME1OpCodes.EX_FinalFunction: { int functionIndex = _reader.ReadInt32(); var item = _package.GetEntry(functionIndex); if (item == null) { return(ErrToken("Unresolved function item " + item)); } string functionName = item.ObjectName.Instanced; return(ReadCall(functionName)); } case ME1OpCodes.EX_PrimitiveCast: { var prefix = _reader.ReadByte(); var v = ReadNext(); return(v); } case ME1OpCodes.EX_VirtualFunction: return(ReadCall(ReadName())); case ME1OpCodes.EX_GlobalFunction: return(ReadCall("Global." + ReadName())); case ME1OpCodes.EX_BoolVariable: return(ReadNext()); case ME1OpCodes.EX_ByteToInt: int objectRefIdx = _reader.ReadInt32(); if (_package.IsEntry(objectRefIdx)) { return(Token($"ByteToInt({_package.getObjectName(objectRefIdx)})", readerpos)); } else { return(Token($"ByteToInt(Unknown reference {objectRefIdx})", readerpos)); } case ME1OpCodes.EX_DynamicCast: { int typeIndex = _reader.ReadInt32(); var item = _package.GetEntry(typeIndex); return(WrapNextBytecode(op => Token($"{item.ObjectName.Instanced}({op})", readerpos))); } case ME1OpCodes.EX_Metacast: { int typeIndex = _reader.ReadInt32(); var item = _package.GetEntry(typeIndex); if (item == null) { return(ErrToken("Unresolved class item " + typeIndex)); } return(WrapNextBytecode(op => Token($"Class<{item.ObjectName.Instanced}>({op})", readerpos))); } case ME1OpCodes.EX_StructMember: { var field = ReadRef(); var structType = ReadRef(); int wSkip = _reader.ReadInt16(); var token = ReadNext(); if (IsInvalid(token)) { return(token); } return(Token($"{token}.{field.ObjectName.Instanced}", readerpos)); } case ME1OpCodes.EX_ArrayElement: case ME1OpCodes.EX_DynArrayElement: { var index = ReadNext(); if (IsInvalid(index)) { return(index); } var array = ReadNext(); if (IsInvalid(array)) { return(array); } return(Token($"{array}[{index}]", readerpos)); } case ME1OpCodes.EX_DynArrayLength: return(WrapNextBytecode(op => Token($"{op}.Length", readerpos))); case ME1OpCodes.EX_StructCmpEq: return(CompareStructs("==")); case ME1OpCodes.EX_StructCmpNe: return(CompareStructs("!=")); case ME1OpCodes.EX_EndOfScript: return(new EndOfScriptToken(readerpos)); case ME1OpCodes.EX_EmptyParmValue: case ME1OpCodes.EX_GoW_DefaultValue: return(new DefaultValueToken("", readerpos)); case ME1OpCodes.EX_DefaultParmValue: { var size = _reader.ReadInt16(); var offset = _reader.BaseStream.Position; var defaultValueExpr = ReadNext(); _reader.BaseStream.Position = offset + size; return(new DefaultParamValueToken(defaultValueExpr.ToString(), readerpos)); } case ME1OpCodes.EX_LocalOutVariable: int valueIndex = _reader.ReadInt32(); var packageItem = _package.GetEntry(valueIndex); if (packageItem == null) { return(ErrToken("Unresolved package item " + packageItem)); } return(Token(packageItem.ObjectName.Instanced, readerpos)); case ME1OpCodes.EX_Iterator: var expr = ReadNext(); int loopEnd = _reader.ReadInt16(); if (IsInvalid(expr)) { return(WrapErrToken("foreach " + expr, expr)); } return(new ForeachToken(loopEnd, expr, readerpos)); case ME1OpCodes.EX_IteratorPop: return(new IteratorPopToken(readerpos)); case ME1OpCodes.EX_IteratorNext: return(new IteratorNextToken(readerpos)); case ME1OpCodes.EX_New: var outer = ReadNext(); if (IsInvalid(outer)) { return(outer); } var name = ReadNext(); if (IsInvalid(name)) { return(name); } var flags = ReadNext(); if (IsInvalid(flags)) { return(flags); } var cls = ReadNext(); if (IsInvalid(cls)) { return(cls); } return(Token($"new({JoinTokens(outer, name, flags, cls)})", readerpos)); case ME1OpCodes.EX_VectorConst: var f1 = _reader.ReadSingle(); var f2 = _reader.ReadSingle(); var f3 = _reader.ReadSingle(); return(Token($"vect({f1},{f2},{f3})", readerpos)); case ME1OpCodes.EX_RotationConst: var i1 = _reader.ReadInt32(); var i2 = _reader.ReadInt32(); var i3 = _reader.ReadInt32(); return(Token($"rot({i1},{i2},{i3})", readerpos)); case ME1OpCodes.EX_InterfaceCast: { var interfaceName = ReadRef(); return(WrapNextBytecode(op => Token($"{interfaceName.ObjectName.Instanced}({op})", readerpos))); } case ME1OpCodes.EX_Conditional: { var condition = ReadNext(); if (IsInvalid(condition)) { return(condition); } var trueSize = _reader.ReadInt16(); var pos = _reader.BaseStream.Position; var truePart = ReadNext(); if (IsInvalid(truePart)) { return(WrapErrToken($"{condition} ? {truePart}", truePart)); } if (_reader.BaseStream.Position != pos + trueSize) { return(ErrToken("conditional true part size mismatch")); } var falseSize = _reader.ReadInt16(); pos = _reader.BaseStream.Position; var falsePart = ReadNext(); if (IsInvalid(truePart)) { return(WrapErrToken($"{condition} ? {truePart} : {falsePart}", falsePart)); } Debug.Assert(_reader.BaseStream.Position == pos + falseSize); return(Token($"{condition} ? {truePart} : {falsePart}", readerpos)); } case ME1OpCodes.EX_DynArrayFind: return(ReadDynArray1ArgMethod("Find")); case ME1OpCodes.EX_DynArrayFindStruct: return(ReadDynArray2ArgMethod("Find", true)); case ME1OpCodes.EX_DynArrayRemove: return(ReadDynArray2ArgMethod("Remove", false)); case ME1OpCodes.EX_DynArrayInsert: return(ReadDynArray2ArgMethod("Insert", false)); case ME1OpCodes.EX_DynArrayAddItem: return(ReadDynArray1ArgMethod("AddItem")); case ME1OpCodes.EX_DynArrayRemoveItem: return(ReadDynArray1ArgMethod("RemoveItem")); case ME1OpCodes.EX_DynArrayInsertItem: return(ReadDynArray2ArgMethod("InsertItem", true)); case ME1OpCodes.EX_DynArrayIterator: { var array = ReadNext(); if (IsInvalid(array)) { return(array); } var iteratorVar = ReadNext(); if (IsInvalid(iteratorVar)) { return(iteratorVar); } _reader.ReadInt16(); var endOffset = _reader.ReadInt16(); return(new ForeachToken(endOffset, array, iteratorVar, readerpos)); } case ME1OpCodes.EX_DelegateProperty: case ME1OpCodes.EX_InstanceDelegate: return(Token(ReadName(), readerpos)); case ME1OpCodes.EX_DelegateFunction: { var receiver = ReadNext(); if (IsInvalid(receiver)) { return(receiver); } var methodName = ReadName(); if (receiver.ToString().StartsWith("__") && receiver.ToString().EndsWith("__Delegate")) { return(ReadCall(methodName)); } return(ReadCall(receiver + "." + methodName)); } case ME1OpCodes.EX_EqualEqual_DelDel: case ME1OpCodes.EX_EqualEqual_DelFunc: return(CompareDelegates("==")); case ME1OpCodes.EX_NotEqual_DelDel: return(CompareDelegates("!=")); default: if ((int)b >= 0x60) { return(ReadNativeCall((byte)b)); } return(ErrToken("// unknown bytecode " + ((byte)b).ToString("X2"), (int)b)); } }
private static PropertyInfo getProperty(ExportEntry entry) { IMEPackage pcc = entry.FileRef; string reference = null; PropertyType type; switch (entry.ClassName) { case "IntProperty": type = PropertyType.IntProperty; break; case "StringRefProperty": type = PropertyType.StringRefProperty; break; case "FloatProperty": type = PropertyType.FloatProperty; break; case "BoolProperty": type = PropertyType.BoolProperty; break; case "StrProperty": type = PropertyType.StrProperty; break; case "NameProperty": type = PropertyType.NameProperty; break; case "DelegateProperty": type = PropertyType.DelegateProperty; break; case "ClassProperty": case "ObjectProperty": case "ComponentProperty": type = PropertyType.ObjectProperty; reference = pcc.getObjectName(BitConverter.ToInt32(entry.Data, entry.Data.Length - 4)); break; case "StructProperty": type = PropertyType.StructProperty; reference = pcc.getObjectName(BitConverter.ToInt32(entry.Data, entry.Data.Length - 4)); break; case "BioMask4Property": case "ByteProperty": type = PropertyType.ByteProperty; reference = pcc.getObjectName(BitConverter.ToInt32(entry.Data, entry.Data.Length - 4)); break; case "ArrayProperty": type = PropertyType.ArrayProperty; PropertyInfo arrayTypeProp = getProperty(pcc.getUExport(BitConverter.ToInt32(entry.Data, 44))); if (arrayTypeProp != null) { switch (arrayTypeProp.Type) { case PropertyType.ObjectProperty: case PropertyType.StructProperty: case PropertyType.ArrayProperty: reference = arrayTypeProp.Reference; break; case PropertyType.ByteProperty: //if (arrayTypeProp.reference == "") if (arrayTypeProp.Reference == "Class") { reference = arrayTypeProp.Type.ToString(); } else { reference = arrayTypeProp.Reference; } break; case PropertyType.IntProperty: case PropertyType.FloatProperty: case PropertyType.NameProperty: case PropertyType.BoolProperty: case PropertyType.StrProperty: case PropertyType.StringRefProperty: case PropertyType.DelegateProperty: reference = arrayTypeProp.Type.ToString(); break; case PropertyType.None: case PropertyType.Unknown: default: Debugger.Break(); return(null); } } else { return(null); } break; case "InterfaceProperty": default: return(null); } bool transient = ((UnrealFlags.EPropertyFlags)BitConverter.ToUInt64(entry.Data, 24)).HasFlag(UnrealFlags.EPropertyFlags.Transient); return(new PropertyInfo(type, reference, transient)); }
public static CustomProperty PropertyToGrid(Property p, IMEPackage pcc) { string cat = p.TypeVal.ToString(); CustomProperty pg; NameProp pp; switch (p.TypeVal) { case PropertyType.BoolProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, (p.Value.IntValue == 1), typeof(bool), false, true); break; case PropertyType.FloatProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, p.Value.FloatValue, typeof(float), false, true); break; case PropertyType.ByteProperty: if (p.Size != 8) { pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, (byte)p.Value.IntValue, typeof(byte), false, true); } else { pp = new NameProp(); pp.name = pcc.getNameEntry(p.Value.IntValue); pp.nameindex = p.Value.IntValue; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, pp, typeof(NameProp), false, true); } break; case PropertyType.NameProperty: pp = new NameProp(); pp.name = pcc.getNameEntry(p.Value.IntValue); pp.nameindex = p.Value.IntValue; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, pp, typeof(NameProp), false, true); break; case PropertyType.ObjectProperty: ObjectProp ppo = new ObjectProp(); ppo.objectName = pcc.getObjectName(p.Value.IntValue); ppo.index = p.Value.IntValue; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, ppo, typeof(ObjectProp), false, true); break; case PropertyType.StrProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, p.Value.StringValue, typeof(string), false, true); break; case PropertyType.ArrayProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, BitConverter.ToInt32(p.raw, 24) + " elements", typeof(string), false, true); break; case PropertyType.StructProperty: string structType = pcc.getNameEntry(p.Value.IntValue); if (structType == "Color") { ColorProp cp = new ColorProp(); cp.name = structType; cp.nameindex = p.Value.IntValue; System.Drawing.Color color = System.Drawing.Color.FromArgb(BitConverter.ToInt32(p.raw, 32)); cp.Alpha = color.A; cp.Red = color.R; cp.Green = color.G; cp.Blue = color.B; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, cp, typeof(ColorProp), false, true); } else if (structType == "Vector") { VectorProp vp = new VectorProp(); vp.name = structType; vp.nameindex = p.Value.IntValue; vp.X = BitConverter.ToSingle(p.raw, 32); vp.Y = BitConverter.ToSingle(p.raw, 36); vp.Z = BitConverter.ToSingle(p.raw, 40); pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, vp, typeof(VectorProp), false, true); } else if (structType == "Rotator") { RotatorProp rp = new RotatorProp(); rp.name = structType; rp.nameindex = p.Value.IntValue; rp.Pitch = BitConverter.ToInt32(p.raw, 32) * 360f / 65536f; rp.Yaw = BitConverter.ToInt32(p.raw, 36) * 360f / 65536f; rp.Roll = BitConverter.ToInt32(p.raw, 40) * 360f / 65536f; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, rp, typeof(RotatorProp), false, true); } else if (structType == "LinearColor") { LinearColorProp lcp = new LinearColorProp(); lcp.name = structType; lcp.nameindex = p.Value.IntValue; lcp.Red = BitConverter.ToSingle(p.raw, 32); lcp.Green = BitConverter.ToSingle(p.raw, 36); lcp.Blue = BitConverter.ToSingle(p.raw, 40); lcp.Alpha = BitConverter.ToSingle(p.raw, 44); pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, lcp, typeof(VectorProp), false, true); } else { StructProp ppp = new StructProp(); ppp.name = structType; ppp.nameindex = p.Value.IntValue; byte[] buf = new byte[p.Value.Array.Count()]; for (int i = 0; i < p.Value.Array.Count(); i++) { buf[i] = (byte)p.Value.Array[i].IntValue; } List <int> buf2 = new List <int>(); for (int i = 0; i < p.Value.Array.Count() / 4; i++) { buf2.Add(BitConverter.ToInt32(buf, i * 4)); } ppp.data = buf2.ToArray(); pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, ppp, typeof(StructProp), false, true); } break; default: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, p.Value.IntValue, typeof(int), false, true); break; } return(pg); }
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; }
public static CustomProperty PropertyToGrid(Property p, IMEPackage pcc) { string cat = p.TypeVal.ToString(); CustomProperty pg; NameProp pp; switch (p.TypeVal) { case PropertyType.BoolProperty : pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, (p.Value.IntValue == 1), typeof(bool), false, true); break; case PropertyType.FloatProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, p.Value.FloatValue, typeof(float), false, true); break; case PropertyType.ByteProperty: if (p.Size != 8) { pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, (byte)p.Value.IntValue, typeof(byte), false, true); } else { pp = new NameProp(); pp.name = pcc.getNameEntry(p.Value.IntValue); pp.nameindex = p.Value.IntValue; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, pp, typeof(NameProp), false, true); } break; case PropertyType.NameProperty: pp = new NameProp(); pp.name = pcc.getNameEntry(p.Value.IntValue); pp.nameindex = p.Value.IntValue; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, pp, typeof(NameProp), false, true); break; case PropertyType.ObjectProperty: ObjectProp ppo = new ObjectProp(); ppo.objectName = pcc.getObjectName(p.Value.IntValue); ppo.index = p.Value.IntValue; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, ppo, typeof(ObjectProp), false, true); break; case PropertyType.StrProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, p.Value.StringValue, typeof(string), false, true); break; case PropertyType.ArrayProperty: pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, BitConverter.ToInt32(p.raw,24) + " elements", typeof(string), false, true); break; case PropertyType.StructProperty: string structType = pcc.getNameEntry(p.Value.IntValue); if(structType == "Color") { ColorProp cp = new ColorProp(); cp.name = structType; cp.nameindex = p.Value.IntValue; System.Drawing.Color color = System.Drawing.Color.FromArgb(BitConverter.ToInt32(p.raw, 32)); cp.Alpha = color.A; cp.Red = color.R; cp.Green = color.G; cp.Blue = color.B; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, cp, typeof(ColorProp), false, true); } else if (structType == "Vector") { VectorProp vp = new VectorProp(); vp.name = structType; vp.nameindex = p.Value.IntValue; vp.X = BitConverter.ToSingle(p.raw, 32); vp.Y = BitConverter.ToSingle(p.raw, 36); vp.Z = BitConverter.ToSingle(p.raw, 40); pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, vp, typeof(VectorProp), false, true); } else if (structType == "Rotator") { RotatorProp rp = new RotatorProp(); rp.name = structType; rp.nameindex = p.Value.IntValue; rp.Pitch = BitConverter.ToInt32(p.raw, 32) * 360f / 65536f; rp.Yaw = BitConverter.ToInt32(p.raw, 36) * 360f / 65536f; rp.Roll = BitConverter.ToInt32(p.raw, 40) * 360f / 65536f; pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, rp, typeof(RotatorProp), false, true); } else if (structType == "LinearColor") { LinearColorProp lcp = new LinearColorProp(); lcp.name = structType; lcp.nameindex = p.Value.IntValue; lcp.Red = BitConverter.ToSingle(p.raw, 32); lcp.Green = BitConverter.ToSingle(p.raw, 36); lcp.Blue = BitConverter.ToSingle(p.raw, 40); lcp.Alpha = BitConverter.ToSingle(p.raw, 44); pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, lcp, typeof(VectorProp), false, true); } else { StructProp ppp = new StructProp(); ppp.name = structType; ppp.nameindex = p.Value.IntValue; byte[] buf = new byte[p.Value.Array.Count()]; for (int i = 0; i < p.Value.Array.Count(); i++) buf[i] = (byte)p.Value.Array[i].IntValue; List<int> buf2 = new List<int>(); for (int i = 0; i < p.Value.Array.Count() / 4; i++) buf2.Add(BitConverter.ToInt32(buf ,i * 4)); ppp.data = buf2.ToArray(); pg = new CustomProperty(pcc.getNameEntry(p.Name), cat, ppp, typeof(StructProp), false, true); } break; default: pg = new CustomProperty(pcc.getNameEntry(p.Name),cat,p.Value.IntValue,typeof(int),false,true); break; } return pg; }