Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            string strSQL = "";

            if (CName.Text != "" && CNIC.Text != "")
            {
                strSQL = "INSERT INTO Customer(CustomerName,CNIC,Phone) VALUES ('" + CName.Text + "','" + CNIC.Text + "','" + Phone.Text + "')";

                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    OleDbCommand command = new OleDbCommand(strSQL, connection);
                    try
                    {
                        connection.Open();
                        command.ExecuteReader();
                        connection.Close();
                        MessageBox.Show("New Renter Added");
                        CName.Clear();
                        CNIC.Clear();
                        Phone.Clear();
                        DataRecordBind("Select * from Customer");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
Example #2
0
        private string getScript()
        {
            string ret          = "";
            CName  functionName = (CName)Chunk.GetVariableByName("functionName");

            ret += functionName + "(";
            CArray parameters = (CArray)Chunk.GetVariableByName("parameters");

            CVector last = (CVector)parameters.Last();

            foreach (CVector parameter in parameters)
            {
                CName    name    = (CName)parameter.GetVariableByType("CName");
                CVariant variant = (CVariant)parameter.GetVariableByType("CVariant");
                ret += name + ":" + variant;
                if (parameter != last)
                {
                    ret += ", ";
                }
            }

            ret += ")";

            return(ret);
        }
Example #3
0
 public object ReadEnumerator(Type enumType)
 {
     if (!enumType.IsEnum)
     {
         throw new ArgumentException();
     }
     if (enumType.IsDefined(typeof(FlagsAttribute), false))
     {
         var flags = new HashSet <CName>();
         while (true)
         {
             var flag = ReadCName();
             if (CName.IsNullOrEmpty(flag))
             {
                 break;
             }
             flags.Add(flag);
         }
         return(EnumExtensions.ConvertToEnum(enumType, flags));
     }
     else
     {
         var name = ReadCName();
         return(Enum.Parse(enumType, name));
     }
 }
        internal void Encode(AsnWriter writer, Asn1Tag tag)
        {
            writer.PushSequence(tag);

            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.WriteInteger(Nonce);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 0));

            if (Asn1Extension.HasValue(CName))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
                CName?.Encode(writer);
                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            }
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
            writer.WriteCharacterString(UniversalTagNumber.GeneralString, Realm);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 2));

            if (Asn1Extension.HasValue(SubjectCertificate))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
                writer.WriteOctetString(SubjectCertificate.Value.Span);
                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            }
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            writer.WriteBitString(Options.AsReadOnlySpan());
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            writer.PopSequence(tag);
        }
Example #5
0
        private static Control GetEditor(this CName @this)
        {
            var editor = new TextBox();

            editor.DataBindings.Add("Text", @this, nameof(@this.Value));
            return(editor);
        }
Example #6
0
        private string getScript()
        {
            string ret = "";

            if (Chunk.data is CQuestScriptBlock block)
            {
                CName functionName = block.FunctionName;

                ret += functionName.Value + "(";
                CArray <QuestScriptParam> parameters = block.Parameters;

                QuestScriptParam last = parameters.LastOrDefault();

                foreach (var parameter in parameters)
                {
                    CName    name    = parameter.Name;
                    CVariant variant = parameter.Value;
                    ret += name + ":" + variant;
                    if (parameter != last)
                    {
                        ret += ", ";
                    }
                }

                ret += ")";
            }



            return(ret);
        }
Example #7
0
 public CompoundField(string name, uint number) : base(name)
 {
     _fields     = new List <ACompilerInfoField>();
     this.Number = number;
     string[] x = CName.Split('.');
     _cTypeName  = x[x.Length - 1];
     _cTypeName += "_t";
 }
        internal void Encode(AsnWriter writer, Asn1Tag tag)
        {
            writer.PushSequence(tag);

            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.WriteInteger(AuthenticatorVersionNumber);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            writer.WriteCharacterString(UniversalTagNumber.GeneralString, Realm);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
            CName?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 2));

            if (Asn1Extension.HasValue(Checksum))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
                Checksum?.Encode(writer);
                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            }
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            writer.WriteInteger(CuSec);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 5));
            writer.WriteGeneralizedTime(CTime);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 5));

            if (Asn1Extension.HasValue(Subkey))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 6));
                Subkey?.Encode(writer);
                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 6));
            }

            if (Asn1Extension.HasValue(SequenceNumber))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 7));
                writer.WriteInteger(SequenceNumber.Value);
                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 7));
            }

            if (Asn1Extension.HasValue(AuthorizationData))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 8));
                writer.PushSequence();

                for (int i = 0; i < AuthorizationData.Length; i++)
                {
                    AuthorizationData[i]?.Encode(writer);
                }

                writer.PopSequence();

                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 8));
            }

            writer.PopSequence(tag);
        }
Example #9
0
        public void Load(string filename)
        {
            using (StreamReader r = new StreamReader(filename))
            {
                string        json     = r.ReadToEnd();
                ReadCSkeleton skeleton = JsonConvert.DeserializeObject <ReadCSkeleton>(json);
                byte[]        data;
                //data = File.ReadAllBytes(@"D:\w3.modding\animation\template.w2rig");
                data = new byte[] { 0x43, 0x52, 0x32, 0x57, 0xA3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD4, 0x03, 0x7E, 0x27, 0xDF, 0xE1, 0x03, 0x48, 0xC9, 0x12, 0x00, 0xF3, 0x07, 0x00, 0x00, 0xF3, 0x07, 0x00, 0x00, 0xAF, 0xE7, 0x43, 0x5A, 0x06, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x00, 0x00, 0xF8, 0x03, 0x00, 0x00, 0x9B, 0x95, 0xBE, 0x25, 0x98, 0x04, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x53, 0x1D, 0xB7, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x55, 0x4B, 0xBB, 0xEC, 0xC0, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xE6, 0x44, 0x44, 0x4B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x53, 0x6B, 0x65, 0x6C, 0x65, 0x74, 0x6F, 0x6E, 0x00, 0x62, 0x6F, 0x6E, 0x65, 0x73, 0x00, 0x61, 0x72, 0x72, 0x61, 0x79, 0x3A, 0x32, 0x2C, 0x30, 0x2C, 0x53, 0x53, 0x6B, 0x65, 0x6C, 0x65, 0x74, 0x6F, 0x6E, 0x42, 0x6F, 0x6E, 0x65, 0x00, 0x6E, 0x61, 0x6D, 0x65, 0x00, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x41, 0x6E, 0x73, 0x69, 0x00, 0x6E, 0x61, 0x6D, 0x65, 0x41, 0x73, 0x43, 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x43, 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x52, 0x6F, 0x6F, 0x74, 0x00, 0x54, 0x72, 0x61, 0x6A, 0x65, 0x63, 0x74, 0x6F, 0x72, 0x79, 0x00, 0x70, 0x65, 0x6C, 0x76, 0x69, 0x73, 0x00, 0x74, 0x6F, 0x72, 0x73, 0x6F, 0x00, 0x74, 0x6F, 0x72, 0x73, 0x6F, 0x32, 0x00, 0x74, 0x6F, 0x72, 0x73, 0x6F, 0x33, 0x00, 0x6E, 0x65, 0x63, 0x6B, 0x00, 0x68, 0x65, 0x61, 0x64, 0x00, 0x6C, 0x5F, 0x74, 0x68, 0x69, 0x67, 0x68, 0x00, 0x6C, 0x5F, 0x73, 0x68, 0x69, 0x6E, 0x00, 0x6C, 0x5F, 0x66, 0x6F, 0x6F, 0x74, 0x00, 0x72, 0x5F, 0x74, 0x68, 0x69, 0x67, 0x68, 0x00, 0x72, 0x5F, 0x73, 0x68, 0x69, 0x6E, 0x00, 0x72, 0x5F, 0x66, 0x6F, 0x6F, 0x74, 0x00, 0x6C, 0x5F, 0x73, 0x68, 0x6F, 0x75, 0x6C, 0x64, 0x65, 0x72, 0x00, 0x6C, 0x5F, 0x62, 0x69, 0x63, 0x65, 0x70, 0x00, 0x6C, 0x5F, 0x66, 0x6F, 0x72, 0x65, 0x61, 0x72, 0x6D, 0x00, 0x6C, 0x5F, 0x68, 0x61, 0x6E, 0x64, 0x00, 0x6C, 0x5F, 0x6D, 0x69, 0x64, 0x64, 0x6C, 0x65, 0x31, 0x00, 0x6C, 0x5F, 0x6D, 0x69, 0x64, 0x64, 0x6C, 0x65, 0x32, 0x00, 0x72, 0x5F, 0x73, 0x68, 0x6F, 0x75, 0x6C, 0x64, 0x65, 0x72, 0x00, 0x72, 0x5F, 0x62, 0x69, 0x63, 0x65, 0x70, 0x00, 0x72, 0x5F, 0x66, 0x6F, 0x72, 0x65, 0x61, 0x72, 0x6D, 0x00, 0x72, 0x5F, 0x68, 0x61, 0x6E, 0x64, 0x00, 0x72, 0x5F, 0x6D, 0x69, 0x64, 0x64, 0x6C, 0x65, 0x31, 0x00, 0x72, 0x5F, 0x6D, 0x69, 0x64, 0x64, 0x6C, 0x65, 0x32, 0x00, 0x72, 0x5F, 0x77, 0x65, 0x61, 0x70, 0x6F, 0x6E, 0x00, 0x6C, 0x5F, 0x77, 0x65, 0x61, 0x70, 0x6F, 0x6E, 0x00, 0x72, 0x5F, 0x62, 0x6F, 0x6F, 0x62, 0x00, 0x6C, 0x5F, 0x62, 0x6F, 0x6F, 0x62, 0x00, 0x6C, 0x5F, 0x74, 0x6F, 0x65, 0x00, 0x6C, 0x5F, 0x6C, 0x65, 0x67, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x6C, 0x5F, 0x6C, 0x65, 0x67, 0x52, 0x6F, 0x6C, 0x6C, 0x32, 0x00, 0x6C, 0x5F, 0x6B, 0x6E, 0x65, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x74, 0x6F, 0x65, 0x00, 0x72, 0x5F, 0x6C, 0x65, 0x67, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x6C, 0x65, 0x67, 0x52, 0x6F, 0x6C, 0x6C, 0x32, 0x00, 0x72, 0x5F, 0x6B, 0x6E, 0x65, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x6C, 0x5F, 0x62, 0x69, 0x63, 0x65, 0x70, 0x32, 0x00, 0x6C, 0x5F, 0x73, 0x68, 0x6F, 0x75, 0x6C, 0x64, 0x65, 0x72, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x6C, 0x5F, 0x65, 0x6C, 0x62, 0x6F, 0x77, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x6C, 0x5F, 0x66, 0x6F, 0x72, 0x65, 0x61, 0x72, 0x6D, 0x52, 0x6F, 0x6C, 0x6C, 0x31, 0x00, 0x6C, 0x5F, 0x66, 0x6F, 0x72, 0x65, 0x61, 0x72, 0x6D, 0x52, 0x6F, 0x6C, 0x6C, 0x32, 0x00, 0x6C, 0x5F, 0x68, 0x61, 0x6E, 0x64, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x62, 0x69, 0x63, 0x65, 0x70, 0x32, 0x00, 0x72, 0x5F, 0x65, 0x6C, 0x62, 0x6F, 0x77, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x66, 0x6F, 0x72, 0x65, 0x61, 0x72, 0x6D, 0x52, 0x6F, 0x6C, 0x6C, 0x31, 0x00, 0x72, 0x5F, 0x66, 0x6F, 0x72, 0x65, 0x61, 0x72, 0x6D, 0x52, 0x6F, 0x6C, 0x6C, 0x32, 0x00, 0x72, 0x5F, 0x68, 0x61, 0x6E, 0x64, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x73, 0x68, 0x6F, 0x75, 0x6C, 0x64, 0x65, 0x72, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x68, 0x72, 0x6F, 0x6C, 0x6C, 0x00, 0x6C, 0x5F, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x31, 0x00, 0x6C, 0x5F, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x32, 0x00, 0x6C, 0x5F, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x33, 0x00, 0x6C, 0x5F, 0x6D, 0x69, 0x64, 0x64, 0x6C, 0x65, 0x33, 0x00, 0x6C, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x30, 0x00, 0x6C, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x31, 0x00, 0x6C, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x32, 0x00, 0x6C, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x33, 0x00, 0x6C, 0x5F, 0x72, 0x69, 0x6E, 0x67, 0x31, 0x00, 0x6C, 0x5F, 0x72, 0x69, 0x6E, 0x67, 0x32, 0x00, 0x6C, 0x5F, 0x72, 0x69, 0x6E, 0x67, 0x33, 0x00, 0x6C, 0x5F, 0x74, 0x68, 0x75, 0x6D, 0x62, 0x31, 0x00, 0x6C, 0x5F, 0x74, 0x68, 0x75, 0x6D, 0x62, 0x32, 0x00, 0x6C, 0x5F, 0x74, 0x68, 0x75, 0x6D, 0x62, 0x33, 0x00, 0x72, 0x5F, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x31, 0x00, 0x72, 0x5F, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x32, 0x00, 0x72, 0x5F, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x33, 0x00, 0x72, 0x5F, 0x6D, 0x69, 0x64, 0x64, 0x6C, 0x65, 0x33, 0x00, 0x72, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x30, 0x00, 0x72, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x31, 0x00, 0x72, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x32, 0x00, 0x72, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x33, 0x00, 0x72, 0x5F, 0x72, 0x69, 0x6E, 0x67, 0x31, 0x00, 0x72, 0x5F, 0x72, 0x69, 0x6E, 0x67, 0x32, 0x00, 0x72, 0x5F, 0x72, 0x69, 0x6E, 0x67, 0x33, 0x00, 0x72, 0x5F, 0x74, 0x68, 0x75, 0x6D, 0x62, 0x31, 0x00, 0x72, 0x5F, 0x74, 0x68, 0x75, 0x6D, 0x62, 0x32, 0x00, 0x72, 0x5F, 0x74, 0x68, 0x75, 0x6D, 0x62, 0x33, 0x00, 0x6C, 0x5F, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x5F, 0x6B, 0x6E, 0x75, 0x63, 0x6B, 0x6C, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x6C, 0x5F, 0x6D, 0x69, 0x64, 0x64, 0x6C, 0x65, 0x5F, 0x6B, 0x6E, 0x75, 0x63, 0x6B, 0x6C, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x6C, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x5F, 0x6B, 0x6E, 0x75, 0x63, 0x6B, 0x6C, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x6C, 0x5F, 0x72, 0x69, 0x6E, 0x67, 0x5F, 0x6B, 0x6E, 0x75, 0x63, 0x6B, 0x6C, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x6C, 0x5F, 0x74, 0x68, 0x75, 0x6D, 0x62, 0x5F, 0x72, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x5F, 0x6B, 0x6E, 0x75, 0x63, 0x6B, 0x6C, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x6D, 0x69, 0x64, 0x64, 0x6C, 0x65, 0x5F, 0x6B, 0x6E, 0x75, 0x63, 0x6B, 0x6C, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x70, 0x69, 0x6E, 0x6B, 0x79, 0x5F, 0x6B, 0x6E, 0x75, 0x63, 0x6B, 0x6C, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x72, 0x69, 0x6E, 0x67, 0x5F, 0x6B, 0x6E, 0x75, 0x63, 0x6B, 0x6C, 0x65, 0x52, 0x6F, 0x6C, 0x6C, 0x00, 0x72, 0x5F, 0x74, 0x68, 0x75, 0x6D, 0x62, 0x5F, 0x72, 0x6F, 0x6C, 0x6C, 0x00, 0x70, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x49, 0x6E, 0x64, 0x69, 0x63, 0x65, 0x73, 0x00, 0x61, 0x72, 0x72, 0x61, 0x79, 0x3A, 0x32, 0x2C, 0x30, 0x2C, 0x49, 0x6E, 0x74, 0x31, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xA3, 0x3D, 0x4F, 0x72, 0x0B, 0x00, 0x00, 0x00, 0x5C, 0xC8, 0x16, 0x46, 0x11, 0x00, 0x00, 0x00, 0x12, 0x05, 0x4C, 0xD0, 0x29, 0x00, 0x00, 0x00, 0x12, 0xF1, 0xE5, 0x37, 0x2E, 0x00, 0x00, 0x00, 0x45, 0x91, 0x58, 0x83, 0x39, 0x00, 0x00, 0x00, 0x08, 0xF8, 0xB3, 0x89, 0x45, 0x00, 0x00, 0x00, 0xDB, 0x5B, 0x10, 0xF1, 0x4B, 0x00, 0x00, 0x00, 0xFF, 0x4C, 0x19, 0x19, 0x50, 0x00, 0x00, 0x00, 0x68, 0x17, 0x16, 0x22, 0x5B, 0x00, 0x00, 0x00, 0x58, 0xB4, 0xEA, 0xE4, 0x62, 0x00, 0x00, 0x00, 0x8C, 0x3D, 0xF7, 0x70, 0x68, 0x00, 0x00, 0x00, 0xE6, 0xCB, 0xB1, 0xCD, 0x6F, 0x00, 0x00, 0x00, 0x4F, 0x46, 0xB4, 0xF3, 0x76, 0x00, 0x00, 0x00, 0x56, 0x37, 0x87, 0xAB, 0x7B, 0x00, 0x00, 0x00, 0xF9, 0x43, 0xC2, 0x1E, 0x80, 0x00, 0x00, 0x00, 0x5C, 0x06, 0x02, 0x17, 0x88, 0x00, 0x00, 0x00, 0x7C, 0xD6, 0x63, 0xA7, 0x8F, 0x00, 0x00, 0x00, 0x80, 0x8A, 0x61, 0xDC, 0x96, 0x00, 0x00, 0x00, 0xFA, 0x3D, 0x98, 0x2E, 0x9E, 0x00, 0x00, 0x00, 0x12, 0x30, 0x83, 0x19, 0xA5, 0x00, 0x00, 0x00, 0x5A, 0x05, 0x0D, 0x97, 0xAC, 0x00, 0x00, 0x00, 0x34, 0xDB, 0x99, 0x55, 0xB7, 0x00, 0x00, 0x00, 0x99, 0xDE, 0x3E, 0x67, 0xBF, 0x00, 0x00, 0x00, 0x1C, 0x6B, 0xC0, 0x1F, 0xC9, 0x00, 0x00, 0x00, 0x67, 0x43, 0x5E, 0xB6, 0xD0, 0x00, 0x00, 0x00, 0x98, 0x4D, 0x0D, 0xD0, 0xDA, 0x00, 0x00, 0x00, 0xD3, 0xBC, 0x14, 0x42, 0xE4, 0x00, 0x00, 0x00, 0x4E, 0x5C, 0x7A, 0x07, 0xEF, 0x00, 0x00, 0x00, 0x93, 0x6E, 0x3D, 0x01, 0xF7, 0x00, 0x00, 0x00, 0x7E, 0xD8, 0x5B, 0x20, 0x01, 0x01, 0x00, 0x00, 0xB9, 0x77, 0xFF, 0x5C, 0x08, 0x01, 0x00, 0x00, 0xDA, 0x78, 0xB2, 0x29, 0x12, 0x01, 0x00, 0x00, 0x71, 0xFE, 0xAF, 0x03, 0x1C, 0x01, 0x00, 0x00, 0xAA, 0x2A, 0xBA, 0x51, 0x25, 0x01, 0x00, 0x00, 0xE0, 0x11, 0x62, 0x2C, 0x2E, 0x01, 0x00, 0x00, 0x68, 0xE6, 0x48, 0xDF, 0x35, 0x01, 0x00, 0x00, 0x92, 0xA9, 0x6D, 0x35, 0x3C, 0x01, 0x00, 0x00, 0x70, 0x3A, 0xFB, 0x34, 0x42, 0x01, 0x00, 0x00, 0x99, 0x1E, 0x77, 0x76, 0x4C, 0x01, 0x00, 0x00, 0x79, 0x8F, 0x58, 0x6A, 0x57, 0x01, 0x00, 0x00, 0xBC, 0x99, 0xE7, 0x41, 0x62, 0x01, 0x00, 0x00, 0xD6, 0xE4, 0x6D, 0x5D, 0x68, 0x01, 0x00, 0x00, 0x3F, 0x2C, 0x76, 0xD3, 0x72, 0x01, 0x00, 0x00, 0x6F, 0xF5, 0xE4, 0x0D, 0x7D, 0x01, 0x00, 0x00, 0xDA, 0x1C, 0xD7, 0x02, 0x88, 0x01, 0x00, 0x00, 0x79, 0xCF, 0xCB, 0x74, 0x91, 0x01, 0x00, 0x00, 0xAD, 0x93, 0xAC, 0x28, 0xA0, 0x01, 0x00, 0x00, 0x4C, 0x13, 0x93, 0x6E, 0xAC, 0x01, 0x00, 0x00, 0x86, 0x96, 0x0B, 0x8E, 0xBB, 0x01, 0x00, 0x00, 0x1D, 0x1C, 0x09, 0x68, 0xCA, 0x01, 0x00, 0x00, 0xD2, 0xD2, 0x51, 0x88, 0xD5, 0x01, 0x00, 0x00, 0xEB, 0xF9, 0x30, 0xF3, 0xDE, 0x01, 0x00, 0x00, 0x2A, 0x97, 0x99, 0x18, 0xEA, 0x01, 0x00, 0x00, 0x94, 0x96, 0xA1, 0x74, 0xF9, 0x01, 0x00, 0x00, 0xCF, 0x05, 0xA9, 0xE6, 0x08, 0x02, 0x00, 0x00, 0x74, 0xA2, 0xBA, 0x92, 0x13, 0x02, 0x00, 0x00, 0x8F, 0x35, 0x68, 0x4D, 0x22, 0x02, 0x00, 0x00, 0xB8, 0x70, 0xF1, 0x92, 0x28, 0x02, 0x00, 0x00, 0xD1, 0x34, 0x96, 0x93, 0x31, 0x02, 0x00, 0x00, 0x3A, 0xAF, 0x98, 0xB9, 0x3A, 0x02, 0x00, 0x00, 0xA3, 0x29, 0x9B, 0xDF, 0x43, 0x02, 0x00, 0x00, 0x6A, 0x42, 0x12, 0x1C, 0x4D, 0x02, 0x00, 0x00, 0x33, 0x2A, 0x09, 0x01, 0x56, 0x02, 0x00, 0x00, 0xCA, 0xAF, 0x06, 0xDB, 0x5F, 0x02, 0x00, 0x00, 0x61, 0x35, 0x04, 0xB5, 0x68, 0x02, 0x00, 0x00, 0xF8, 0xBA, 0x01, 0x8F, 0x71, 0x02, 0x00, 0x00, 0xDF, 0x39, 0x62, 0x28, 0x79, 0x02, 0x00, 0x00, 0xA4, 0xCA, 0x5A, 0xB6, 0x81, 0x02, 0x00, 0x00, 0x0D, 0x45, 0x5D, 0xDC, 0x89, 0x02, 0x00, 0x00, 0x35, 0x6F, 0x80, 0x4A, 0x92, 0x02, 0x00, 0x00, 0x9E, 0xE9, 0x82, 0x70, 0x9B, 0x02, 0x00, 0x00, 0x07, 0x64, 0x85, 0x96, 0xA4, 0x02, 0x00, 0x00, 0x8B, 0xB1, 0xC3, 0x06, 0xAD, 0x02, 0x00, 0x00, 0x50, 0x42, 0xBC, 0x94, 0xB6, 0x02, 0x00, 0x00, 0xB9, 0xBC, 0xBE, 0xBA, 0xBF, 0x02, 0x00, 0x00, 0x08, 0x84, 0xAD, 0xDD, 0xC9, 0x02, 0x00, 0x00, 0xD1, 0xA5, 0x23, 0x7D, 0xD2, 0x02, 0x00, 0x00, 0x68, 0x2B, 0x21, 0x57, 0xDB, 0x02, 0x00, 0x00, 0xA3, 0x9A, 0x28, 0xC9, 0xE4, 0x02, 0x00, 0x00, 0x3A, 0x20, 0x26, 0xA3, 0xED, 0x02, 0x00, 0x00, 0xCD, 0x55, 0x75, 0xEC, 0xF5, 0x02, 0x00, 0x00, 0x36, 0xD0, 0x77, 0x12, 0xFD, 0x02, 0x00, 0x00, 0x9F, 0x4A, 0x7A, 0x38, 0x05, 0x03, 0x00, 0x00, 0x07, 0x21, 0xFA, 0x1A, 0x0E, 0x03, 0x00, 0x00, 0xCC, 0xB1, 0xF2, 0xA8, 0x17, 0x03, 0x00, 0x00, 0x35, 0x2C, 0xF5, 0xCE, 0x20, 0x03, 0x00, 0x00, 0xC3, 0x5A, 0x68, 0xBE, 0x34, 0x03, 0x00, 0x00, 0xC8, 0x88, 0x77, 0xE7, 0x49, 0x03, 0x00, 0x00, 0xC2, 0x29, 0xBC, 0xF3, 0x5D, 0x03, 0x00, 0x00, 0x99, 0x21, 0x83, 0xC3, 0x70, 0x03, 0x00, 0x00, 0x1E, 0x14, 0x9D, 0x0A, 0x7D, 0x03, 0x00, 0x00, 0x6D, 0xE8, 0x69, 0xE3, 0x91, 0x03, 0x00, 0x00, 0xB2, 0xAD, 0x7F, 0xE1, 0xA6, 0x03, 0x00, 0x00, 0xF8, 0x21, 0x90, 0x38, 0xBA, 0x03, 0x00, 0x00, 0xA7, 0x0F, 0xB6, 0x12, 0xCD, 0x03, 0x00, 0x00, 0xE4, 0x1B, 0x18, 0x6E, 0xDA, 0x03, 0x00, 0x00, 0x7E, 0x22, 0x4E, 0x6E, 0xE8, 0x03, 0x00, 0x00, 0xA4, 0xBB, 0xE3, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0xD8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x65, 0xB5, 0xDE, 0x00, 0x02, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x00, 0x62, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                using (MemoryStream ms = new MemoryStream(data))
                    using (BinaryReader br = new BinaryReader(ms))
                    {
                        W2RigFile = new CR2WFile(br);
                        var chunk = W2RigFile.chunks[0];

                        CArray bonesorig = (chunk.GetVariableByName("bones") as CArray);
                        for (int i = 0; i < skeleton.names.Count; i++)
                        {
                            CVariable   newBone = new CVector(W2RigFile);
                            CStringAnsi newName = new CStringAnsi(W2RigFile).SetValue(skeleton.names[i] + "\0") as CStringAnsi;
                            newName.Name = "name";
                            newName.Type = "StringAnsi";
                            newBone.AddVariable(newName);
                            CName newCName = new CName(W2RigFile).SetValue(skeleton.names[i]) as CName;
                            newCName.Name = "nameAsCName";
                            newCName.Type = "CName";
                            newBone.AddVariable(newCName);
                            (chunk.GetVariableByName("bones") as CArray).AddVariable(newBone);
                            (chunk.GetVariableByName("parentIndices") as CArray).AddVariable(new CInt16(W2RigFile).SetValue(skeleton.parentIdx[i]));
                        }

                        using (var stream = new MemoryStream())
                        {
                            using (var bw = new BinaryWriter(stream))
                            {
                                for (int i = 0; i < skeleton.nbBones; i++)
                                {
                                    bw.Write(skeleton.positions[i].X);
                                    bw.Write(skeleton.positions[i].Y);
                                    bw.Write(skeleton.positions[i].Z);
                                    bw.Write(1f); // the w component
                                    bw.Write(-skeleton.rotations[i].X);
                                    bw.Write(-skeleton.rotations[i].Y);
                                    bw.Write(-skeleton.rotations[i].Z);
                                    bw.Write(skeleton.rotations[i].W);
                                    bw.Write(skeleton.scales[i].X);
                                    bw.Write(skeleton.scales[i].Y);
                                    bw.Write(skeleton.scales[i].Z);
                                    bw.Write(1f); // the w component
                                }
                            }
                            chunk.unknownBytes.SetValue(stream.ToArray());
                            //saveToFile();
                        }
                    }
            }
        }
Example #10
0
        public void SetNameTests(string name)
        {
            var cName = new CName
            {
                Name = name
            };

            cName.Name.Should().Be(name);
        }
Example #11
0
        public override List <CPtr> GetConnections()
        {
            var list = new List <CPtr>();

            if (Chunk != null)
            {
                var cachedConnections = Chunk.GetVariableByName("cachedConnections");
                if (cachedConnections != null && cachedConnections is CArray)
                {
                    var cachedConnectionsArray = ((CArray)cachedConnections);
                    foreach (CVariable conn in cachedConnectionsArray)
                    {
                        if (conn is CVector)
                        {
                            CVector connection = (CVector)conn;
                            CName   socketId   = (CName)connection.GetVariableByName("socketId");
                            CArray  blocks     = (CArray)connection.GetVariableByName("blocks");

                            if (blocks != null && blocks is CArray)
                            {
                                foreach (CVariable block in blocks)
                                {
                                    if (block is CVector)
                                    {
                                        foreach (CVariable blockVectorVariable in ((CVector)block).variables)
                                        {
                                            if (blockVectorVariable is CPtr)
                                            {
                                                var nextLinkElementPtr = ((CPtr)blockVectorVariable);
                                                if (nextLinkElementPtr.Reference != null)
                                                {
                                                    list.Add(nextLinkElementPtr);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                var nextLinkElementObj = Chunk.GetVariableByName("nextLinkElement");
                if (nextLinkElementObj != null && nextLinkElementObj is CPtr)
                {
                    var nextLinkElementPtr = ((CPtr)nextLinkElementObj);
                    if (nextLinkElementPtr.Reference != null)
                    {
                        list.Add(nextLinkElementPtr);
                    }
                }
            }

            return(list);
        }
Example #12
0
 public CR2WChunk(CR2WFile cr2w)
 {
     this.cr2w      = cr2w;
     parentPtr      = new CPtr(cr2w);
     parentPtr.Name = nameof(Parent);
     flags          = new CUInt16(cr2w);
     flags.Name     = nameof(Flags);
     typeName       = new CName(cr2w);
     typeName.Name  = nameof(Type);
     Flags          = 8192;
 }
Example #13
0
 public CEntityBufferType2(CR2WFile cr2w) : base(cr2w)
 {
     componentName = new CName(cr2w)
     {
         Name = "Name",
     };
     sizeofdata = new CUInt32(cr2w)
     {
         Name = "Size",
     };
     variables = new CBufferUInt32 <CVariableWrapper>(cr2w, _ => new CVariableWrapper(_));
 }
Example #14
0
 public W3TypeAttribute(string name)
 {
     if (String.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("[W3TypeAttribute] Name property cannot be NULL or empty.");
     }
     if (!CName.IsCName(name))
     {
         throw new InvalidOperationException("[W3TypeAttribute] Name property is not a CName");
     }
     Name = name;
 }
Example #15
0
 public SEntityBufferType1(CR2WFile cr2w, CVariable parent, string name) : base(cr2w, parent, name)
 {
     ComponentName = new CName(cr2w, this, nameof(ComponentName))
     {
         IsSerialized = true
     };
     Guid = new CGUID(cr2w, this, nameof(Guid))
     {
         IsSerialized = true
     };
     Buffer = new CByteArray2(cr2w, this, nameof(Buffer))
     {
         IsSerialized = true
     };
 }
Example #16
0
        private UInt16 AddName(CName value)
        {
            var index = m_names.FindIndex(n => n.hash == (uint)value.GetHashCode());

            if (index >= 0)
            {
                return(Convert.ToUInt16(index));
            }
            m_names.Add(new CR2WName
            {
                //value = m_strings.AddString(value, out var isNew),
                hash = (uint)value.GetHashCode(),
            });
            return(Convert.ToUInt16(m_names.Count - 1));
        }
Example #17
0
        public CR2WChunk(CR2WFile cr2w)
        {
            this.cr2w = cr2w;


            parentPtr      = new CPtr(cr2w);
            parentPtr.Name = "Parent";

            flags      = new CUInt16(cr2w);
            flags.Name = "Flags";

            typeName      = new CName(cr2w);
            typeName.Name = "Type";

            Flags = 8192;
        }
Example #18
0
        private void OnRecvName(IChannel channel, Message message)
        {
            Console.WriteLine(string.Format("Name send to backend start"));
            CName request = message as CName;
            //Player player = (Player)World.Instance.GetEntity(request.entityid);

            SName response = new SName();

            //response.entityid = request.entityid;
            //response.self = request.self;//不能传到后端

            //channel.Send(response);
            //player.Broadcast(response, true);
            World.Instance.Broundcast(response);
            Console.WriteLine(string.Format("send to backend sucess"));
        }
Example #19
0
        public void ParseObject(object instance, REDBinaryReader red)
        {
            // Each object is prefixed with a zero byte header.
            var b = red.ReadByte();

            if (b != 0)
            {
                throw new FormatException($"Invalid object null header: {b}");
            }

            // Keep looping until the 2 byte null termintator is reached.
            while (true)
            {
                var name = red.ReadCName();
                if (CName.IsNullOrEmpty(name))
                {
                    // 2 byte null terminator instead of the next name id indicates the end of the object.
                    break;
                }
                var type = red.ReadCName();

                var start = red.BaseStream.Position;
                var size  = red.ReadUInt32();
                // Size value includes the size of the uint size value itself (+ 4).
                if (size < sizeof(uint))
                {
                    throw new FormatException($"Invalid object size: {size}");
                }

                // Check to see if the current class contains a property with the name and type read.
                var field = REDReflection.GetREDField(instance.GetType(), name, type);
                if (field == null)
                {
                    throw new FormatException($"Property '{name}' : '{type}', not found in class {instance.GetType().Name}, Aborting!");
                }

                var value = ReadObject(field.FieldType, red);

                var diff = start.CompareTo(red.BaseStream.Position);
                if (diff != 0)
                {
                    throw new FormatException($"Property '{name}' : '{type}', read unknown size of bytes, aborting!");
                }

                field.SetValue(instance, value);
            }
        }
Example #20
0
        public override List <IPtrAccessor> GetConnections()
        {
            var list = new List <IPtrAccessor>();

            if (Chunk.data is CQuestGraphBlock graphBlock)
            {
                CArray <SCachedConnections> cachedConnections = graphBlock.CachedConnections;
                if (cachedConnections != null)
                {
                    foreach (SCachedConnections conn in cachedConnections.Elements)
                    {
                        CName socketId             = conn.SocketId;
                        CArray <SBlockDesc> blocks = conn.Blocks;

                        if (blocks != null)
                        {
                            foreach (SBlockDesc block in blocks.Elements)
                            {
                                CPtr <CQuestGraphBlock> graphpointer = block.Ock;
                                if (graphpointer.Reference != null)
                                {
                                    list.Add(graphpointer);
                                }
                            }
                        }
                    }
                }
            }
            else if (Chunk.data is CStorySceneLinkElement linkElement)
            {
                CPtr <CStorySceneLinkElement> nextLinkElementPtr = linkElement.NextLinkElement;
                if (nextLinkElementPtr != null)
                {
                    if (nextLinkElementPtr.Reference != null)
                    {
                        list.Add(nextLinkElementPtr);
                    }
                }
            }
            else
            {
            }


            return(list);
        }
Example #21
0
        internal void Encode(AsnWriter writer, Asn1Tag tag)
        {
            writer.PushSequence(tag);

            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.WriteGeneralizedTime(Timestamp);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            writer.WriteInteger(USec);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
            writer.WriteCharacterString(UniversalTagNumber.GeneralString, CRealm);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            CName?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            TicketChecksum?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            writer.PopSequence(tag);
        }
        internal void Encode(AsnWriter writer, Asn1Tag tag)
        {
            writer.PushSequence(tag);

            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.WriteInteger(ProtocolVersionNumber);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            writer.WriteInteger((long)MessageType);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 1));

            if (Asn1Extension.HasValue(PaData))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
                writer.PushSequence();

                for (int i = 0; i < PaData.Length; i++)
                {
                    PaData[i]?.Encode(writer);
                }

                writer.PopSequence();

                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
            }

            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            writer.WriteCharacterString(UniversalTagNumber.GeneralString, CRealm);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            CName?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 5));
            Ticket?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 5));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 6));
            EncPart?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 6));
            writer.PopSequence(tag);
        }
Example #23
0
        public CR2WExportWrapper(CR2WFile file)
        {
            this.cr2w = file;

            parentPtr = new CPtr(file)
            {
                Name = "Parent"
            };

            flags = new CUInt16(file)
            {
                Name = "Flags"
            };

            typeName = new CName(file)
            {
                Name = "Type"
            };

            Flags = 8192;
            _export.objectFlags = 8192;
        }
Example #24
0
        public CR2WExportWrapper(CR2WFile file, CR2WExport export)
        {
            this.cr2w = file;
            _export   = export;

            parentPtr = new CPtr(file)
            {
                Name = "Parent"
            };
            ParentChunkId = export.parentID;

            flags = new CUInt16(file)
            {
                Name = "Flags",
                val  = export.objectFlags
            };

            typeName = new CName(file)
            {
                Name = "Type",
                val  = export.className
            };
        }
Example #25
0
 public override void Write(CName value)
 {
     throw new NotImplementedException();
 }
Example #26
0
        private void ReadBytes(int bytestart, BinaryReader reader)
        {
            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CVector(File);
                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CVector";
            }
            catch
            {
            }

            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CUInt64(File);
                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CUInt64";
            }
            catch
            {
            }

            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CUInt32(File);
                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CUInt32";
            }
            catch
            {
            }


            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CUInt16(File);
                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CUInt16";
            }
            catch
            {
            }

            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CUInt8(File);

                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CUInt8";
            }
            catch
            {
            }

            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CDynamicInt(File);
                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CDynamicInt";
            }
            catch
            {
            }

            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CFloat(File);
                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CFloat";
            }
            catch
            {
            }

            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CName(File);

                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CName";

                var valueTest = v.Value;
            }
            catch
            {
            }

            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CHandle(File);

                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CHandle";

                var valueTest = v.Value;
            }
            catch
            {
            }

            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = new CSoft(File);

                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "CSoft";

                var valueTest = v.Value;
            }
            catch
            {
            }

            reader.BaseStream.Seek(bytestart, SeekOrigin.Begin);

            try
            {
                var obj = File.ReadVariable(reader);

                obj.Read(reader, (uint)(bytes.Length - bytestart));
                var v = CreatePropertyLayout(obj);
                v.Endpos   = (int)reader.BaseStream.Position;
                v.HexValue = bytes[bytestart].ToString("X2");
                v.Method   = "ReadVariable";
            }
            catch
            {
            }
        }
        internal void Encode(AsnWriter writer, Asn1Tag tag)
        {
            writer.PushSequence(tag);

            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.WriteBitString(Flags.AsReadOnlySpan());
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            Key?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
            writer.WriteCharacterString(UniversalTagNumber.GeneralString, CRealm);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            CName?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            Transited?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 5));
            writer.WriteGeneralizedTime(AuthTime);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 5));

            if (Asn1Extension.HasValue(StartTime))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 6));
                writer.WriteGeneralizedTime(StartTime.Value);
                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 6));
            }
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 7));
            writer.WriteGeneralizedTime(EndTime);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 7));

            if (Asn1Extension.HasValue(RenewTill))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 8));
                writer.WriteGeneralizedTime(RenewTill.Value);
                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 8));
            }

            if (Asn1Extension.HasValue(CAddr))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 9));
                writer.PushSequence();

                for (int i = 0; i < CAddr.Length; i++)
                {
                    CAddr[i]?.Encode(writer);
                }

                writer.PopSequence();

                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 9));
            }


            if (Asn1Extension.HasValue(AuthorizationData))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 10));
                writer.PushSequence();

                for (int i = 0; i < AuthorizationData.Length; i++)
                {
                    AuthorizationData[i]?.Encode(writer);
                }

                writer.PopSequence();

                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 10));
            }

            writer.PopSequence(tag);
        }
Example #28
0
        /// <summary>
        /// Read mesh chunk and buffer infos.
        /// </summary>
        public void LoadData(CR2WFile meshFile)
        {
            // IMPLEMENTED FROM jlouis' witcherconverter
            // http://jlouisb.users.sourceforge.net/
            // https://bitbucket.org/jlouis/witcherconverter

            SBufferInfos bufferInfos = new SBufferInfos();

            // *************** READ CHUNK INFOS ***************
            foreach (var chunk in meshFile.Chunks)
            {
                if (chunk.REDType == "CMesh" && chunk.data is CMesh cmesh)
                {
                    List <SVertexBufferInfos> vertexBufferInfos = new List <SVertexBufferInfos>();
                    SMeshCookedData           meshCookedData    = cmesh.CookedData;


                    var bytes = meshCookedData.RenderChunks.Bytes;
                    using (MemoryStream ms = new MemoryStream(bytes))
                        using (BinaryReader br = new BinaryReader(ms))
                        {
                            var nbBuffers = br.ReadByte();
                            for (uint i = 0; i < nbBuffers; i++)
                            {
                                SVertexBufferInfos buffInfo = new SVertexBufferInfos();

                                br.BaseStream.Position       += 1; // Unknown
                                buffInfo.verticesCoordsOffset = br.ReadUInt32();
                                buffInfo.uvOffset             = br.ReadUInt32();
                                buffInfo.normalsOffset        = br.ReadUInt32();

                                br.BaseStream.Position += 9; // Unknown
                                buffInfo.indicesOffset  = br.ReadUInt32();
                                br.BaseStream.Position += 1; // 0x1D

                                buffInfo.nbVertices     = br.ReadUInt16();
                                buffInfo.nbIndices      = br.ReadUInt32();
                                buffInfo.materialID     = br.ReadByte();
                                br.BaseStream.Position += 2;             // Unknown
                                buffInfo.lod            = br.ReadByte(); // lod ?

                                vertexBufferInfos.Add(buffInfo);
                            }
                        }

                    bufferInfos.indexBufferOffset = meshCookedData.IndexBufferOffset.val;
                    bufferInfos.indexBufferSize   = meshCookedData.IndexBufferSize.val;
                    //bufferInfos.vertexBufferOffset = meshCookedData.vertexBufferOffset.val; //FIXME
                    bufferInfos.vertexBufferSize     = meshCookedData.VertexBufferSize.val;
                    bufferInfos.quantizationOffset.X = meshCookedData.QuantizationOffset.X.val;
                    bufferInfos.quantizationOffset.Y = meshCookedData.QuantizationOffset.Y.val;
                    bufferInfos.quantizationOffset.Z = meshCookedData.QuantizationOffset.Z.val;
                    bufferInfos.quantizationScale.X  = meshCookedData.QuantizationScale.X.val;
                    bufferInfos.quantizationScale.Y  = meshCookedData.QuantizationScale.Y.val;
                    bufferInfos.quantizationScale.Z  = meshCookedData.QuantizationScale.Z.val;

                    if (meshCookedData.BonePositions != null)
                    {
                        foreach (var item in meshCookedData.BonePositions)
                        {
                            Vector3Df pos = new Vector3Df();
                            pos.X = item.X.val;
                            pos.Y = item.Y.val;
                            pos.Z = item.Z.val;
                            bonePositions.Add(pos);
                        }
                    }


                    bufferInfos.verticesBuffer = vertexBufferInfos;
                    CArray <SMeshChunkPacked> meshChunks = cmesh.Chunks;
                    foreach (SMeshChunkPacked meshChunk in meshChunks.Elements)
                    {
                        SMeshInfos meshInfo = new SMeshInfos();

                        meshInfo.numVertices       = meshChunk.NumVertices == null ? 0 : meshChunk.NumVertices.val;
                        meshInfo.numIndices        = meshChunk.NumIndices == null ? 0 : meshChunk.NumIndices.val;
                        meshInfo.numBonesPerVertex = meshChunk.NumBonesPerVertex == null ? (uint)0 : meshChunk.NumBonesPerVertex.val;
                        meshInfo.firstVertex       = meshChunk.FirstVertex == null ? 0 : meshChunk.FirstVertex.val;
                        meshInfo.firstIndex        = meshChunk.FirstIndex == null ? 0 : meshChunk.FirstIndex.val;
                        meshInfo.materialID        = meshChunk.MaterialID == null ? 0 : meshChunk.MaterialID.val;

                        if (meshChunk.VertexType != null)
                        {
                            if (meshChunk.VertexType.WrappedEnum == Enums.EMeshVertexType.MVT_StaticMesh)
                            {
                                meshInfo.vertexType = SMeshInfos.EMeshVertexType.EMVT_STATIC;
                            }
                            else if (meshChunk.VertexType.WrappedEnum == Enums.EMeshVertexType.MVT_SkinnedMesh)
                            {
                                meshInfo.vertexType = SMeshInfos.EMeshVertexType.EMVT_SKINNED;
                            }
                        }

                        CData.meshInfos.Add(meshInfo);
                    }

                    // bone names and matrices
                    CBufferVLQInt32 <CName>      boneNames    = cmesh.BoneNames;
                    CBufferVLQInt32 <CMatrix4x4> bonematrices = cmesh.Bonematrices;
                    CData.boneData.nbBones = (uint)boneNames.elements.Count;
                    for (int i = 0; i < CData.boneData.nbBones; i++)
                    {
                        CName name = boneNames.elements[i];
                        CData.boneData.jointNames.Add(name.Value);

                        CMatrix4x4 cmatrix = bonematrices.elements[i];
                        Matrix     matrix  = new Matrix();
                        for (int j = 0; j < 16; j++)
                        {
                            float value = (cmatrix.fields[j] as CFloat).val;
                            matrix.SetElement(j, value);
                        }
                        CData.boneData.boneMatrices.Add(matrix);
                    }
                }

                else if (chunk.REDType == "CMaterialInstance")
                {
                    CData.materialInstances.Add(chunk.data as CMaterialInstance);
                }
            }

            // *************** READ MESH BUFFER INFOS ***************
            foreach (var meshInfo in CData.meshInfos)
            {
                SVertexBufferInfos vBufferInf = new SVertexBufferInfos();
                uint nbVertices        = 0;
                uint firstVertexOffset = 0;
                uint nbIndices         = 0;
                uint firstIndiceOffset = 0;
                for (int i = 0; i < bufferInfos.verticesBuffer.Count; i++)
                {
                    nbVertices += bufferInfos.verticesBuffer[i].nbVertices;
                    if (nbVertices > meshInfo.firstVertex)
                    {
                        vBufferInf = bufferInfos.verticesBuffer[i];
                        // the index of the first vertex in the buffer
                        firstVertexOffset = meshInfo.firstVertex - (nbVertices - vBufferInf.nbVertices);
                        break;
                    }
                }
                for (int i = 0; i < bufferInfos.verticesBuffer.Count; i++)
                {
                    nbIndices += bufferInfos.verticesBuffer[i].nbIndices;
                    if (nbIndices > meshInfo.firstIndex)
                    {
                        vBufferInf        = bufferInfos.verticesBuffer[i];
                        firstIndiceOffset = meshInfo.firstIndex - (nbIndices - vBufferInf.nbIndices);
                        break;
                    }
                }

                // Load only best LOD
                if (vBufferInf.lod == 1)
                {
                    using (BinaryReader br = new BinaryReader(File.Open(meshFile.FileName + ".1.buffer", FileMode.Open)))
                    {
                        uint vertexSize = 8;
                        if (meshInfo.vertexType == SMeshInfos.EMeshVertexType.EMVT_SKINNED)
                        {
                            vertexSize += meshInfo.numBonesPerVertex * 2;
                        }

                        br.BaseStream.Seek(vBufferInf.verticesCoordsOffset + firstVertexOffset * vertexSize, SeekOrigin.Begin);

                        List <Vertex3D> vertex3DCoords = new List <Vertex3D>();
                        Color           defaultColor   = new Color(255, 255, 255, 255);
                        for (uint i = 0; i < meshInfo.numVertices; i++)
                        {
                            ushort x = br.ReadUInt16();
                            ushort y = br.ReadUInt16();
                            ushort z = br.ReadUInt16();
                            ushort w = br.ReadUInt16();

                            if (meshInfo.vertexType == SMeshInfos.EMeshVertexType.EMVT_SKINNED)
                            {
                                //sr.BaseStream.Seek(meshInfo.numBonesPerVertex * 2, SeekOrigin.Current);
                                byte[] skinningData = new byte[meshInfo.numBonesPerVertex * 2];
                                br.BaseStream.Read(skinningData, 0, (int)meshInfo.numBonesPerVertex * 2);

                                for (uint j = 0; j < meshInfo.numBonesPerVertex; ++j)
                                {
                                    uint  boneId  = skinningData[j];
                                    uint  weight  = skinningData[j + meshInfo.numBonesPerVertex];
                                    float fweight = weight / 255.0f;

                                    if (weight != 0)
                                    {
                                        var vertexSkinningEntry = new W3_DataCache.VertexSkinningEntry();
                                        vertexSkinningEntry.boneId       = boneId;
                                        vertexSkinningEntry.meshBufferId = 0;
                                        vertexSkinningEntry.vertexId     = i;
                                        vertexSkinningEntry.strength     = fweight;
                                        CData.w3_DataCache.vertices.Add(vertexSkinningEntry);
                                    }
                                }
                            }

                            Vertex3D vertex3DCoord = new Vertex3D();
                            vertex3DCoord.Position = new Vector3Df(x, y, z) / 65535f * bufferInfos.quantizationScale + bufferInfos.quantizationOffset;
                            vertex3DCoord.Color    = defaultColor;
                            vertex3DCoords.Add(vertex3DCoord);
                        }

                        br.BaseStream.Seek(vBufferInf.uvOffset + firstVertexOffset * 4, SeekOrigin.Begin);

                        for (int i = 0; i < meshInfo.numVertices; i++)
                        {
                            float uf = br.ReadHalfFloat();
                            float vf = br.ReadHalfFloat();

                            Vertex3D vertex3DCoord = vertex3DCoords[i];
                            vertex3DCoord.TCoords = new Vector2Df(uf, vf);
                            vertex3DCoords[i]     = vertex3DCoord;
                        }

                        // Indices -------------------------------------------------------------------
                        br.BaseStream.Seek(bufferInfos.indexBufferOffset + vBufferInf.indicesOffset + firstIndiceOffset * 2, SeekOrigin.Begin);

                        List <ushort> indices = new List <ushort>();
                        for (int i = 0; i < meshInfo.numIndices; i++)
                        {
                            indices.Add(0);
                        }

                        for (int i = 0; i < meshInfo.numIndices; i++)
                        {
                            ushort index = br.ReadUInt16();

                            // Indice need to be inversed for the normals
                            if (i % 3 == 0)
                            {
                                indices[i] = index;
                            }
                            else if (i % 3 == 1)
                            {
                                indices[i + 1] = index;
                            }
                            else if (i % 3 == 2)
                            {
                                indices[i - 1] = index;
                            }
                        }

                        MeshBuffer meshBuff = MeshBuffer.Create(VertexType.Standard, IndexType._16Bit);
                        meshBuff.Append(vertex3DCoords.ToArray(), indices.ToArray());
                        meshBuff.RecalculateBoundingBox();
                        CData.staticMesh.AddMeshBuffer(meshBuff);
                        meshBuff.Drop();
                    }
                }
            }
        }
Example #29
0
        /// <summary>
        /// Parses whatever comes until the specified stop symbol is reached.
        /// </summary>
        void ParseObject(CSequence sequence, CSymbol stop)
        {
            CSymbol symbol;

            while ((symbol = ScanNextToken()) != CSymbol.Eof)
            {
                if (symbol == stop)
                {
                    return;
                }

                CString   s;
                COperator op;
                switch (symbol)
                {
                case CSymbol.Comment:
                    // ignore comments
                    break;

                case CSymbol.Integer:
                    CInteger n = new CInteger();
                    n.Value = _lexer.TokenToInteger;
                    _operands.Add(n);
                    break;

                case CSymbol.Real:
                    CReal r = new CReal();
                    r.Value = _lexer.TokenToReal;
                    _operands.Add(r);
                    break;

                case CSymbol.String:
                case CSymbol.HexString:
                case CSymbol.UnicodeString:
                case CSymbol.UnicodeHexString:
                    s       = new CString();
                    s.Value = _lexer.Token;
                    _operands.Add(s);
                    break;

                case CSymbol.Dictionary:
                    s             = new CString();
                    s.Value       = _lexer.Token;
                    s.CStringType = CStringType.Dictionary;
                    _operands.Add(s);
                    op = CreateOperator(OpCodeName.Dictionary);
                    //_operands.Clear();
                    sequence.Add(op);

                    break;

                case CSymbol.Name:
                    CName name = new CName();
                    name.Name = _lexer.Token;
                    _operands.Add(name);
                    break;

                case CSymbol.Operator:
                    op = CreateOperator();
                    //_operands.Clear();
                    sequence.Add(op);
                    break;

                case CSymbol.BeginArray:
                    CArray array = new CArray();
                    if (_operands.Count != 0)
                    {
                        ContentReaderDiagnostics.ThrowContentReaderException("Array within array...");
                    }

                    ParseObject(array, CSymbol.EndArray);
                    array.Add(_operands);
                    _operands.Clear();
                    _operands.Add((CObject)array);
                    break;

                case CSymbol.EndArray:
                    ContentReaderDiagnostics.HandleUnexpectedCharacter(']');
                    break;

#if DEBUG
                default:
                    Debug.Assert(false);
                    break;
#endif
                }
            }
        }
Example #30
0
 public int GetRowIndexByKey(CName key)
 {
     throw new NotImplementedException();
 }