Ejemplo n.º 1
0
        private void CullingPlaneOffsetTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (selectedLight == null)
            {
                return;
            }
            float v = FloatUtil.Parse(CullingPlaneOffsetTextBox.Text);

            if (selectedLight.CullingPlaneOffset != v)
            {
                selectedLight.CullingPlaneOffset = v;
                UpdateLightParams();
            }
        }
Ejemplo n.º 2
0
        private void FalloffExponentTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (selectedLight == null)
            {
                return;
            }
            float v = FloatUtil.Parse(FalloffExponentTextBox.Text);

            if (selectedLight.FalloffExponent != v)
            {
                selectedLight.FalloffExponent = v;
                UpdateLightParams();
            }
        }
Ejemplo n.º 3
0
        private void ShadowNearClipTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (selectedLight == null)
            {
                return;
            }
            float v = FloatUtil.Parse(ShadowNearClipTextBox.Text);

            if (selectedLight.ShadowNearClip != v)
            {
                selectedLight.ShadowNearClip = v;
                UpdateLightParams();
            }
        }
Ejemplo n.º 4
0
        private void CoronaZBiasTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (selectedLight == null)
            {
                return;
            }
            float v = FloatUtil.Parse(CoronaZBiasTextBox.Text);

            if (selectedLight.CoronaZBias != v)
            {
                selectedLight.CoronaZBias = v;
                UpdateLightParams();
            }
        }
Ejemplo n.º 5
0
        private void IntensityTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (selectedLight == null)
            {
                return;
            }
            float v = FloatUtil.Parse(IntensityTextBox.Text);

            if (selectedLight.Intensity != v)
            {
                selectedLight.Intensity = v;
                UpdateLightParams();
            }
        }
Ejemplo n.º 6
0
        private void OuterAngleTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (selectedLight == null)
            {
                return;
            }
            float v = FloatUtil.Parse(OuterAngleTextBox.Text);

            if (selectedLight.ConeOuterAngle != v)
            {
                selectedLight.ConeOuterAngle = v;
                UpdateLightParams();
            }
        }
Ejemplo n.º 7
0
        public void Init(string iplline)
        {
            var parts = iplline.Split(',');

            if (parts.Length >= 9)
            {
                ID = parts[0].Trim();
                BoundingBox b = new BoundingBox();
                b.Minimum.X = FloatUtil.Parse(parts[1].Trim());
                b.Minimum.Y = FloatUtil.Parse(parts[2].Trim());
                b.Minimum.Z = FloatUtil.Parse(parts[3].Trim());
                b.Maximum.X = FloatUtil.Parse(parts[4].Trim());
                b.Maximum.Y = FloatUtil.Parse(parts[5].Trim());
                b.Maximum.Z = FloatUtil.Parse(parts[6].Trim());
                Box         = b;
                NameLabel   = parts[7].Trim();
                UnkVal      = FloatUtil.Parse(parts[8].Trim());
            }
        }
Ejemplo n.º 8
0
        private void ExtParamsTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentZone?.AudioZone == null)
            {
                return;
            }

            var paramstrs = ExtParamsTextBox.Text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            if (paramstrs?.Length > 0)
            {
                var paramlist = new List <Dat151AmbientZone.ExtParam>();
                foreach (var paramstr in paramstrs)
                {
                    var paramvals = paramstr.Split(',');
                    if (paramvals?.Length == 2)
                    {
                        var  param   = new Dat151AmbientZone.ExtParam();
                        var  hashstr = paramvals[0].Trim();
                        var  valstr  = paramvals[1].Trim();
                        uint hash    = 0;
                        if (!uint.TryParse(hashstr, out hash))//don't re-hash hashes
                        {
                            hash = JenkHash.GenHash(hashstr);
                            JenkIndex.Ensure(hashstr);
                        }
                        param.Hash  = hash;
                        param.Value = FloatUtil.Parse(valstr);
                        paramlist.Add(param);
                    }
                }

                CurrentZone.AudioZone.ExtParams      = paramlist.ToArray();
                CurrentZone.AudioZone.ExtParamsCount = (uint)paramlist.Count;

                ProjectItemChanged();
            }
        }
Ejemplo n.º 9
0
        private void Unk01TextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentEmitter?.AudioEmitter == null)
            {
                return;
            }

            float unk = FloatUtil.Parse(Unk01TextBox.Text);

            if (CurrentEmitter.AudioEmitter.Unk01 != unk)
            {
                CurrentEmitter.AudioEmitter.Unk01 = unk;

                ProjectItemChanged();
            }
        }
Ejemplo n.º 10
0
        private void OuterRadTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentEmitter?.AudioEmitter == null)
            {
                return;
            }

            float rad = FloatUtil.Parse(OuterRadTextBox.Text);

            if (CurrentEmitter.AudioEmitter.OuterRad != rad)
            {
                CurrentEmitter.AudioEmitter.OuterRad = rad;

                ProjectItemChanged();
            }
        }
Ejemplo n.º 11
0
        private static float[] TraverseFloatArrayRaw(XmlNode node)
        {
            var data = new List <float>();

            if (node.InnerText != "")
            {
                var split = Regex.Split(node.InnerText, @"[\s\r\n\t]");

                for (int i = 0; i < split.Length; i++)
                {
                    if (!string.IsNullOrEmpty(split[i]))
                    {
                        var val = FloatUtil.Parse(split[i]);
                        data.Add(MetaTypes.SwapBytes(val));
                    }
                }
            }

            return(data.ToArray());
        }
Ejemplo n.º 12
0
        private void TriAreaTextBox_TextChanged(object sender, EventArgs e)
        {
            if (CollisionTriangle == null)
            {
                return;
            }
            if (populatingui)
            {
                return;
            }
            var v = FloatUtil.Parse(TriAreaTextBox.Text);

            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CollisionTriangle.triArea != v)
                {
                    CollisionTriangle.triArea = v;
                    ProjectForm.SetYbnHasChanged(true);
                }
            }
        }
Ejemplo n.º 13
0
        private void UnkFloat2TextBox_TextChanged(object sender, EventArgs e)
        {
            if (CollisionGeom == null)
            {
                return;
            }
            if (populatingui)
            {
                return;
            }
            var v = FloatUtil.Parse(UnkFloat2TextBox.Text);

            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CollisionGeom.Unknown_ACh != v)
                {
                    CollisionGeom.Unknown_ACh = v;
                    ProjectForm.SetYbnHasChanged(true);
                }
            }
        }
Ejemplo n.º 14
0
        private static Array_float TraverseRawFloatArray(XmlNode node, MetaBuilder mb)
        {
            var data = new List <float>();

            if (node.InnerText != "")
            {
                var split = Regex.Split(node.InnerText, @"[\s\r\n\t]");

                for (int i = 0; i < split.Length; i++)
                {
                    var ts = split[i]?.Trim();
                    if (!string.IsNullOrEmpty(ts))
                    {
                        var val = FloatUtil.Parse(ts);// Convert.ToSingle(split[i]);
                        data.Add(val);
                    }
                }
            }

            return(mb.AddFloatArrayPtr(data.ToArray()));
        }
Ejemplo n.º 15
0
        private static Array_Vector3 TraverseRawVector3Array(XmlNode node, MetaBuilder mb)
        {
            var items = new List <Vector4>();

            foreach (XmlNode cnode in node.ChildNodes)
            {
                var split = Regex.Split(node.InnerText, @",\s");

                float x = FloatUtil.Parse(split[0]);
                float y = FloatUtil.Parse(split[1]);
                float z = FloatUtil.Parse(split[2]);
                float w = 0f;

                var val = new Vector4(x, y, z, w);

                items.Add(val);
                break;
            }

            return(mb.AddPaddedVector3ArrayPtr(items.ToArray()));
        }
Ejemplo n.º 16
0
        private void VolumeTextBox_TextChanged(object sender, EventArgs e)
        {
            if (CollisionBounds == null)
            {
                return;
            }
            if (populatingui)
            {
                return;
            }
            var v = FloatUtil.Parse(VolumeTextBox.Text);

            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CollisionBounds.Volume != v)
                {
                    CollisionBounds.Volume = v;
                    ProjectForm.SetYbnHasChanged(true);
                }
            }
        }
Ejemplo n.º 17
0
        private void CylRadiusTextBox_TextChanged(object sender, EventArgs e)
        {
            if (CollisionCylinder == null)
            {
                return;
            }
            if (populatingui)
            {
                return;
            }
            var v = FloatUtil.Parse(CylRadiusTextBox.Text);

            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CollisionCylinder.cylinderRadius != v)
                {
                    CollisionCylinder.cylinderRadius = v;
                    ProjectForm.SetYbnHasChanged(true);
                }
            }
        }
Ejemplo n.º 18
0
        private void FalloffExponentTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentLodLight == null)
            {
                return;
            }
            float v = FloatUtil.Parse(FalloffExponentTextBox.Text);

            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CurrentLodLight.FalloffExponent != v)
                {
                    CurrentLodLight.FalloffExponent = v;
                    ProjectItemChanged();
                    UpdateGraphics();
                }
            }
        }
Ejemplo n.º 19
0
        private void CarPerpendicularLengthTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentCarGen == null)
            {
                return;
            }
            float len = FloatUtil.Parse(CarPerpendicularLengthTextBox.Text);

            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CurrentCarGen._CCarGen.perpendicularLength != len)
                {
                    CurrentCarGen.SetLength(len);
                    ProjectForm.SetYmapHasChanged(true);
                    ProjectForm.WorldForm?.SetWidgetScale(new Vector3(len));
                }
            }
        }
Ejemplo n.º 20
0
        private void CarOrientYTextBox_TextChanged(object sender, EventArgs e)
        {
            if (populatingui)
            {
                return;
            }
            if (CurrentCarGen == null)
            {
                return;
            }
            float oy = FloatUtil.Parse(CarOrientYTextBox.Text);

            lock (ProjectForm.ProjectSyncRoot)
            {
                if (CurrentCarGen._CCarGen.orientY != oy)
                {
                    CurrentCarGen._CCarGen.orientY = oy;
                    CurrentCarGen.CalcOrientation();
                    ProjectForm.SetYmapHasChanged(true);
                    ProjectForm.WorldForm?.SetWidgetRotation(CurrentCarGen.Orientation);
                }
            }
        }
Ejemplo n.º 21
0
        private static byte[] Traverse(XmlNode node, PsoBuilder pb, MetaName type = 0, bool isRoot = false)
        {
            if (type == 0)
            {
                type = (MetaName)(uint)GetHash(node.Name);
            }

            var infos = PsoTypes.GetStructureInfo(type);

            if (infos != null)
            {
                byte[] data         = new byte[infos.StructureLength];
                var    arrayResults = new PsoArrayResults();

                arrayResults.Structures        = new Dictionary <int, Array_Structure>();
                arrayResults.StructurePointers = new Dictionary <int, Array_StructurePointer>();
                arrayResults.UInts             = new Dictionary <int, Array_uint>();
                arrayResults.UShorts           = new Dictionary <int, Array_ushort>();
                arrayResults.UBytes            = new Dictionary <int, Array_byte>();
                arrayResults.Floats            = new Dictionary <int, Array_float>();
                arrayResults.Float_XYZs        = new Dictionary <int, Array_Vector3>();
                arrayResults.Hashes            = new Dictionary <int, Array_uint>();

                Array.Clear(data, 0, infos.StructureLength); //shouldn't really be necessary...

                PsoStructureEntryInfo arrEntry = null;


                //if (isRoot)
                //{
                //    pb.EnsureBlock(type);
                //}

                for (int i = 0; i < infos.Entries.Length; i++)
                {
                    var entry = infos.Entries[i];
                    var cnode = GetEntryNode(node.ChildNodes, entry.EntryNameHash);

                    if (entry.EntryNameHash == (MetaName)MetaTypeName.ARRAYINFO)
                    {
                        arrEntry = entry;
                        continue;
                    }

                    if (cnode == null)
                    {
                        //warning: node not found in XML for this entry!
                        continue;
                    }

                    switch (entry.Type)
                    {
                    case PsoDataType.Array:
                    {
                        TraverseArray(cnode, pb, entry, arrEntry, arrayResults, data, infos);
                        break;
                    }

                    case PsoDataType.Structure:
                    {
                        var stype = (MetaName)entry.ReferenceKey;
                        if (stype == 0)
                        {
                            var stypestr = Xml.GetStringAttribute(cnode, "type");
                            if (!string.IsNullOrEmpty(stypestr))
                            {
                                stype = (MetaName)(uint)GetHash(stypestr);
                            }
                        }
                        var struc = Traverse(cnode, pb, stype);
                        if (struc != null)
                        {
                            switch (entry.Unk_5h)
                            {
                            default:
                                //ErrorXml(sb, cind, ename + ": Unexpected Structure subtype: " + entry.Unk_5h.ToString());
                                break;

                            case 0:             //default structure

                                Buffer.BlockCopy(struc, 0, data, entry.DataOffset, struc.Length);

                                break;

                            case 3:             //structure pointer...
                            case 4:             //also pointer? what's the difference?

                                var bptr = pb.AddItem(stype, struc);
                                var ptr  = new PsoPOINTER(bptr.BlockID, bptr.Offset);
                                ptr.SwapEnd();
                                var ptrb = MetaTypes.ConvertToBytes(ptr);

                                Buffer.BlockCopy(ptrb, 0, data, entry.DataOffset, ptrb.Length);

                                break;
                            }
                        }
                        else
                        {
                        }
                        break;
                    }

                    case PsoDataType.Map:
                    {
                        TraverseMap(cnode, pb, entry, infos, data, arrayResults);

                        break;
                    }

                    case PsoDataType.Bool:
                    {
                        byte val = (cnode.Attributes["value"].Value == "false") ? (byte)0 : (byte)1;
                        data[entry.DataOffset] = val;
                        break;
                    }

                    case PsoDataType.SByte:
                    {
                        var val = Convert.ToSByte(cnode.Attributes["value"].Value);
                        data[entry.DataOffset] = (byte)val;
                        break;
                    }

                    case PsoDataType.UByte:
                    {
                        var val = Convert.ToByte(cnode.Attributes["value"].Value);
                        data[entry.DataOffset] = val;
                        break;
                    }

                    case PsoDataType.SShort:
                    {
                        var val = Convert.ToInt16(cnode.Attributes["value"].Value);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    case PsoDataType.UShort:
                    {
                        var val = Convert.ToUInt16(cnode.Attributes["value"].Value);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    case PsoDataType.SInt:
                    {
                        var val = Convert.ToInt32(cnode.Attributes["value"].Value);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    case PsoDataType.UInt:
                    {
                        switch (entry.Unk_5h)
                        {
                        default:
                            //ErrorXml(sb, cind, ename + ": Unexpected Integer subtype: " + entry.Unk_5h.ToString());
                            break;

                        case 0:             //signed int (? flags?)
                            var sval = Convert.ToInt32(cnode.Attributes["value"].Value);
                            Write(sval, data, entry.DataOffset);
                            break;

                        case 1:             //unsigned int
                            var  ustr = cnode.Attributes["value"].Value;
                            uint uval = 0;
                            if (ustr.StartsWith("0x"))
                            {
                                ustr = ustr.Substring(2);
                                uval = Convert.ToUInt32(ustr, 16);
                            }
                            else
                            {
                                uval = Convert.ToUInt32(ustr);
                            }
                            Write(uval, data, entry.DataOffset);
                            break;
                        }

                        break;
                    }

                    case PsoDataType.Float:
                    {
                        float val = FloatUtil.Parse(cnode.Attributes["value"].Value);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    case PsoDataType.Float2:
                    {
                        float x = FloatUtil.Parse(cnode.Attributes["x"].Value);
                        float y = FloatUtil.Parse(cnode.Attributes["y"].Value);
                        Write(x, data, entry.DataOffset);
                        Write(y, data, entry.DataOffset + sizeof(float));
                        break;
                    }

                    case PsoDataType.Float3:
                    {
                        float x = FloatUtil.Parse(cnode.Attributes["x"].Value);
                        float y = FloatUtil.Parse(cnode.Attributes["y"].Value);
                        float z = FloatUtil.Parse(cnode.Attributes["z"].Value);
                        Write(x, data, entry.DataOffset);
                        Write(y, data, entry.DataOffset + sizeof(float));
                        Write(z, data, entry.DataOffset + sizeof(float) * 2);
                        break;
                    }

                    case PsoDataType.Float4:
                    {
                        float x = FloatUtil.Parse(cnode.Attributes["x"].Value);
                        float y = FloatUtil.Parse(cnode.Attributes["y"].Value);
                        float z = FloatUtil.Parse(cnode.Attributes["z"].Value);
                        float w = FloatUtil.Parse(cnode.Attributes["w"].Value);
                        Write(x, data, entry.DataOffset);
                        Write(y, data, entry.DataOffset + sizeof(float));
                        Write(z, data, entry.DataOffset + sizeof(float) * 2);
                        Write(w, data, entry.DataOffset + sizeof(float) * 3);
                        break;
                    }

                    case PsoDataType.String:
                    {
                        TraverseString(cnode, pb, entry, data);
                        break;
                    }

                    case PsoDataType.Enum:
                    {
                        pb.AddEnumInfo((MetaName)entry.ReferenceKey);
                        switch (entry.Unk_5h)
                        {
                        default:
                            //ErrorXml(sb, cind, ename + ": Unexpected Enum subtype: " + entry.Unk_5h.ToString());
                            break;

                        case 0:             //int enum
                            int ival = GetEnumInt((MetaName)entry.ReferenceKey, cnode.InnerText, entry.Type);
                            Write(ival, data, entry.DataOffset);
                            break;

                        case 1:             //short enum?
                            short sval = (short)GetEnumInt((MetaName)entry.ReferenceKey, cnode.InnerText, entry.Type);
                            Write(sval, data, entry.DataOffset);
                            break;

                        case 2:             //byte enum
                            byte bval = (byte)GetEnumInt((MetaName)entry.ReferenceKey, cnode.InnerText, entry.Type);
                            data[entry.DataOffset] = bval;
                            break;
                        }
                        break;
                    }

                    case PsoDataType.Flags:
                    {
                        //uint fCount = (entry.ReferenceKey >> 16) & 0x0000FFFF;
                        uint        fEntry    = (entry.ReferenceKey & 0xFFF);
                        var         fEnt      = (fEntry != 0xFFF) ? infos.GetEntry((int)fEntry) : null;
                        PsoEnumInfo flagsInfo = null;
                        MetaName    fEnum     = (MetaName)(fEnt?.ReferenceKey ?? 0);
                        if ((fEnt != null) && (fEnt.EntryNameHash == (MetaName)MetaTypeName.ARRAYINFO))
                        {
                            flagsInfo = PsoTypes.GetEnumInfo(fEnum);
                        }
                        if (flagsInfo == null)
                        {
                            if (fEntry != 0xFFF)
                            {
                            }
                            //flagsInfo = PsoTypes.GetEnumInfo(entry.EntryNameHash);
                        }
                        if (flagsInfo != null)
                        {
                            pb.AddEnumInfo(flagsInfo.IndexInfo.NameHash);
                        }
                        else
                        {
                        }          //error?

                        switch (entry.Unk_5h)
                        {
                        default:
                            //ErrorXml(sb, cind, ename + ": Unexpected Flags subtype: " + entry.Unk_5h.ToString());
                            break;

                        case 0:             //int flags
                            int ival = GetEnumInt(fEnum, cnode.InnerText, entry.Type);
                            Write(ival, data, entry.DataOffset);
                            break;

                        case 1:             //short flags
                            short sval = (short)GetEnumInt(fEnum, cnode.InnerText, entry.Type);
                            Write(sval, data, entry.DataOffset);
                            break;

                        case 2:             //byte flags
                            byte bval = (byte)GetEnumInt(fEnum, cnode.InnerText, entry.Type);
                            data[entry.DataOffset] = bval;
                            break;
                        }
                        break;
                    }

                    case PsoDataType.Float3a:
                    {
                        float x = FloatUtil.Parse(cnode.Attributes["x"].Value);
                        float y = FloatUtil.Parse(cnode.Attributes["y"].Value);
                        float z = FloatUtil.Parse(cnode.Attributes["z"].Value);
                        Write(x, data, entry.DataOffset);
                        Write(y, data, entry.DataOffset + sizeof(float));
                        Write(z, data, entry.DataOffset + sizeof(float) * 2);
                        break;
                    }

                    case PsoDataType.Float4a:
                    {
                        float x = FloatUtil.Parse(cnode.Attributes["x"].Value);
                        float y = FloatUtil.Parse(cnode.Attributes["y"].Value);
                        float z = FloatUtil.Parse(cnode.Attributes["z"].Value);
                        //float w = FloatUtil.Parse(cnode.Attributes["w"].Value);
                        Write(x, data, entry.DataOffset);
                        Write(y, data, entry.DataOffset + sizeof(float));
                        Write(z, data, entry.DataOffset + sizeof(float) * 2);
                        //Write(w, data, entry.DataOffset + sizeof(float) * 3);
                        break;
                    }

                    case PsoDataType.HFloat:
                    {
                        var val = Convert.ToInt16(cnode.Attributes["value"].Value);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    case PsoDataType.Long:
                    {
                        var uval = Convert.ToUInt64(cnode.Attributes["value"].Value);
                        Write(uval, data, entry.DataOffset);
                        break;
                    }


                    default:
                        break;
                    }
                }


                arrayResults.WriteArrays(data);

                pb.AddStructureInfo(infos.IndexInfo.NameHash);

                if (isRoot)
                {
                    pb.RootPointer = pb.AddItem(type, data);
                }

                return(data);
            }
            else
            {
            }  //info not found

            return(null);
        }
Ejemplo n.º 22
0
        private static void GetParsedArrayOfBytes(XmlNode node, byte[] data, MetaStructureEntryInfo_s entry, MetaStructureEntryInfo_s arrEntry)
        {
            int offset = entry.DataOffset;

            string[] split;

            switch (arrEntry.DataType)
            {
            default:
                split = Split(node.InnerText, 2);
                for (int j = 0; j < split.Length; j++)
                {
                    byte val = Convert.ToByte(split[j], 16);
                    data[offset] = val;
                    offset      += sizeof(byte);
                }
                break;

            case MetaStructureEntryDataType.SignedByte:
                split = node.InnerText.Split();     //split = Split(node.InnerText, 2); to read as unsplitted HEX
                for (int j = 0; j < split.Length; j++)
                {
                    sbyte val = Convert.ToSByte(split[j], 10);
                    data[offset] = (byte)val;
                    offset      += sizeof(sbyte);
                }
                break;

            case MetaStructureEntryDataType.UnsignedByte:
                split = node.InnerText.Split();
                for (int j = 0; j < split.Length; j++)
                {
                    byte val = Convert.ToByte(split[j], 10);
                    data[offset] = val;
                    offset      += sizeof(byte);
                }
                break;

            case MetaStructureEntryDataType.SignedShort:
                split = node.InnerText.Split();
                for (int j = 0; j < split.Length; j++)
                {
                    short val = Convert.ToInt16(split[j], 10);
                    Write(val, data, offset);
                    offset += sizeof(short);
                }
                break;

            case MetaStructureEntryDataType.UnsignedShort:
                split = node.InnerText.Split();
                for (int j = 0; j < split.Length; j++)
                {
                    ushort val = Convert.ToUInt16(split[j], 10);
                    Write(val, data, offset);
                    offset += sizeof(ushort);
                }
                break;

            case MetaStructureEntryDataType.SignedInt:
                split = node.InnerText.Split();
                for (int j = 0; j < split.Length; j++)
                {
                    int val = Convert.ToInt32(split[j], 10);
                    Write(val, data, offset);
                    offset += sizeof(int);
                }
                break;

            case MetaStructureEntryDataType.UnsignedInt:
                split = node.InnerText.Split();
                for (int j = 0; j < split.Length; j++)
                {
                    uint val = Convert.ToUInt32(split[j], 10);
                    Write(val, data, offset);
                    offset += sizeof(uint);
                }
                break;

            case MetaStructureEntryDataType.Float:
                split = node.InnerText.Split();
                for (int j = 0; j < split.Length; j++)
                {
                    float val = FloatUtil.Parse(split[j]);
                    Write(val, data, offset);
                    offset += sizeof(float);
                }
                break;
            }
        }
Ejemplo n.º 23
0
        private static byte[] Traverse(XmlNode node, MetaBuilder mb, MetaName type = 0, bool isRoot = false)
        {
            if (type == 0)
            {
                type = (MetaName)(uint)GetHash(node.Name);
            }

            var infos = MetaTypes.GetStructureInfo(type);

            if (infos != null)
            {
                byte[] data         = new byte[infos.StructureSize];
                var    arrayResults = new ArrayResults();

                arrayResults.Structures        = new Dictionary <int, Array_Structure>();
                arrayResults.StructurePointers = new Dictionary <int, Array_StructurePointer>();
                arrayResults.UInts             = new Dictionary <int, Array_uint>();
                arrayResults.UShorts           = new Dictionary <int, Array_ushort>();
                arrayResults.UBytes            = new Dictionary <int, Array_byte>();
                arrayResults.Floats            = new Dictionary <int, Array_float>();
                arrayResults.Float_XYZs        = new Dictionary <int, Array_Vector3>();
                arrayResults.Hashes            = new Dictionary <int, Array_uint>();

                Array.Clear(data, 0, infos.StructureSize);

                MetaStructureEntryInfo_s arrEntry = new MetaStructureEntryInfo_s();

                if (isRoot)
                {
                    mb.EnsureBlock(type);
                }

                for (int i = 0; i < infos.Entries.Length; i++)
                {
                    var entry = infos.Entries[i];

                    var cnode = GetEntryNode(node.ChildNodes, entry);

                    if (entry.EntryNameHash == MetaName.ARRAYINFO)
                    {
                        arrEntry = entry;
                        continue;
                    }

                    if (cnode == null)
                    {
                        continue;
                    }

                    switch (entry.DataType)
                    {
                    case MetaStructureEntryDataType.Array:
                    {
                        TraverseArray(cnode, mb, arrEntry, entry.DataOffset, arrayResults);
                        break;
                    }

                    case MetaStructureEntryDataType.ArrayOfBytes:
                    {
                        GetParsedArrayOfBytes(cnode, data, entry, arrEntry);
                        break;
                    }

                    case MetaStructureEntryDataType.ArrayOfChars:
                    {
                        int offset = entry.DataOffset;
                        var split  = Split(cnode.InnerText, 2);

                        for (int j = 0; j < split.Length; j++)
                        {
                            byte val = Convert.ToByte(split[j], 16);
                            data[offset] = val;
                            offset      += sizeof(byte);
                        }

                        break;
                    }

                    case MetaStructureEntryDataType.Boolean:
                    {
                        byte val = (cnode.Attributes["value"].Value == "false") ? (byte)0 : (byte)1;
                        data[entry.DataOffset] = val;
                        break;
                    }

                    case MetaStructureEntryDataType.ByteEnum:
                    {
                        byte val = Convert.ToByte(cnode.Attributes["value"].Value);
                        data[entry.DataOffset] = val;
                        break;
                    }


                    case MetaStructureEntryDataType.CharPointer:
                    {
                        if (!string.IsNullOrEmpty(cnode.InnerText))
                        {
                            var ptr = mb.AddStringPtr(cnode.InnerText);
                            var val = MetaTypes.ConvertToBytes(ptr);

                            Buffer.BlockCopy(val, 0, data, entry.DataOffset, val.Length);
                        }

                        break;
                    }

                    case MetaStructureEntryDataType.DataBlockPointer:
                    {
                        // TODO
                        break;
                    }

                    case MetaStructureEntryDataType.Float:
                    {
                        float val = FloatUtil.Parse(cnode.Attributes["value"].Value);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    case MetaStructureEntryDataType.Float_XYZ:
                    {
                        float x = FloatUtil.Parse(cnode.Attributes["x"].Value);
                        float y = FloatUtil.Parse(cnode.Attributes["y"].Value);
                        float z = FloatUtil.Parse(cnode.Attributes["z"].Value);

                        Write(x, data, entry.DataOffset);
                        Write(y, data, entry.DataOffset + sizeof(float));
                        Write(z, data, entry.DataOffset + sizeof(float) * 2);

                        break;
                    }


                    case MetaStructureEntryDataType.Float_XYZW:
                    {
                        float x = FloatUtil.Parse(cnode.Attributes["x"].Value);
                        float y = FloatUtil.Parse(cnode.Attributes["y"].Value);
                        float z = FloatUtil.Parse(cnode.Attributes["z"].Value);
                        float w = FloatUtil.Parse(cnode.Attributes["w"].Value);

                        Write(x, data, entry.DataOffset);
                        Write(y, data, entry.DataOffset + sizeof(float));
                        Write(z, data, entry.DataOffset + sizeof(float) * 2);
                        Write(w, data, entry.DataOffset + sizeof(float) * 3);

                        break;
                    }

                    case MetaStructureEntryDataType.Hash:
                    {
                        var hash = GetHash(cnode.InnerText);
                        Write(hash, data, entry.DataOffset);
                        break;
                    }

                    case MetaStructureEntryDataType.IntEnum:
                    case MetaStructureEntryDataType.IntFlags1:
                    case MetaStructureEntryDataType.IntFlags2:
                    {
                        var _infos = MetaTypes.GetEnumInfo(entry.ReferenceKey);

                        mb.AddEnumInfo(_infos.EnumNameHash);

                        int val = GetEnumInt(entry.ReferenceKey, cnode.InnerText);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    case MetaStructureEntryDataType.ShortFlags:
                    {
                        var _infos = MetaTypes.GetEnumInfo(entry.ReferenceKey);

                        mb.AddEnumInfo(_infos.EnumNameHash);

                        int val = GetEnumInt(entry.ReferenceKey, cnode.InnerText);
                        Write((short)val, data, entry.DataOffset);
                        break;
                    }

                    case MetaStructureEntryDataType.SignedByte:
                    {
                        var val = Convert.ToSByte(cnode.Attributes["value"].Value);
                        data[entry.DataOffset] = (byte)val;
                        break;
                    }

                    case MetaStructureEntryDataType.SignedInt:
                    {
                        var val = Convert.ToInt32(cnode.Attributes["value"].Value);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    case MetaStructureEntryDataType.SignedShort:
                    {
                        var val = Convert.ToInt16(cnode.Attributes["value"].Value);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    case MetaStructureEntryDataType.Structure:
                    {
                        var struc = Traverse(cnode, mb, entry.ReferenceKey);

                        if (struc != null)
                        {
                            Buffer.BlockCopy(struc, 0, data, entry.DataOffset, struc.Length);
                        }

                        break;
                    }

                    case MetaStructureEntryDataType.StructurePointer:
                    {
                        // TODO
                        break;
                    }

                    case MetaStructureEntryDataType.UnsignedByte:
                    {
                        var val = Convert.ToByte(cnode.Attributes["value"].Value);
                        data[entry.DataOffset] = val;
                        break;
                    }

                    case MetaStructureEntryDataType.UnsignedInt:
                    {
                        switch (entry.EntryNameHash)
                        {
                        case MetaName.color:
                        {
                            var val = Convert.ToUInt32(cnode.Attributes["value"].Value, 16);
                            Write(val, data, entry.DataOffset);
                            break;
                        }

                        default:
                        {
                            var val = Convert.ToUInt32(cnode.Attributes["value"].Value);
                            Write(val, data, entry.DataOffset);
                            break;
                        }
                        }

                        break;
                    }

                    case MetaStructureEntryDataType.UnsignedShort:
                    {
                        var val = Convert.ToUInt16(cnode.Attributes["value"].Value);
                        Write(val, data, entry.DataOffset);
                        break;
                    }

                    default: break;
                    }
                }

                arrayResults.WriteArrays(data);

                mb.AddStructureInfo(infos.StructureNameHash);

                if (isRoot)
                {
                    mb.AddItem(type, data);
                }

                return(data);
            }

            return(null);
        }
Ejemplo n.º 24
0
 public static float TryParseFloat(string s)
 {
     return(FloatUtil.Parse(s));
 }
Ejemplo n.º 25
0
        private static Array_Vector3 TraverseRawVector3Array(XmlNode node, MetaBuilder mb)
        {
            var items = new List <Vector4>();

            float x = 0f;
            float y = 0f;
            float z = 0f;
            float w = 0f;

            var cnodes = node.SelectNodes("Item");

            if (cnodes.Count > 0)
            {
                foreach (XmlNode cnode in cnodes)
                {
                    var str  = cnode.InnerText;
                    var strs = str.Split(',');
                    if (strs.Length >= 3)
                    {
                        x = FloatUtil.Parse(strs[0].Trim());
                        y = FloatUtil.Parse(strs[1].Trim());
                        z = FloatUtil.Parse(strs[2].Trim());
                        if (strs.Length >= 4)
                        {
                            w = FloatUtil.Parse(strs[3].Trim());
                        }
                        var val = new Vector4(x, y, z, w);
                        items.Add(val);
                    }
                }
            }
            else
            {
                var split = node.InnerText.Split('\n');// Regex.Split(node.InnerText, @"[\s\r\n\t]");

                for (int i = 0; i < split.Length; i++)
                {
                    var s = split[i]?.Trim();
                    if (string.IsNullOrEmpty(s))
                    {
                        continue;
                    }
                    var split2 = Regex.Split(s, @"[\s\t]");
                    int c      = 0;
                    x = 0f; y = 0f; z = 0f;
                    for (int n = 0; n < split2.Length; n++)
                    {
                        var ts = split2[n]?.Trim();
                        if (string.IsNullOrEmpty(ts))
                        {
                            continue;
                        }
                        var f = FloatUtil.Parse(ts);
                        switch (c)
                        {
                        case 0: x = f; break;

                        case 1: y = f; break;

                        case 2: z = f; break;
                        }
                        c++;
                    }
                    if (c >= 3)
                    {
                        var val = new Vector4(x, y, z, w);
                        items.Add(val);
                    }
                }
            }


            return(mb.AddPaddedVector3ArrayPtr(items.ToArray()));
        }