示例#1
0
 public override void FromString(string[] d, UAsset asset)
 {
     if (Guid.TryParse(d[0], out Guid res))
     {
         Value = res;
     }
 }
示例#2
0
        public void TestImproperNameMapHashes()
        {
            var tester = new UAsset(Path.Combine("TestImproperNameMapHashes", "OC_Gatling_DamageB_B.uasset"), UE4Version.VER_UE4_25);

            Assert.IsTrue(tester.VerifyBinaryEquality());

            Dictionary <string, bool> testingEntries = new Dictionary <string, bool>();

            testingEntries["/Game/WeaponsNTools/GatlingGun/Overclocks/OC_BonusesAndPenalties/OC_Bonus_MovmentBonus_150p"] = false;
            testingEntries["/Game/WeaponsNTools/GatlingGun/Overclocks/OC_BonusesAndPenalties/OC_Bonus_MovmentBonus_150p.OC_Bonus_MovmentBonus_150p"] = false;

            foreach (KeyValuePair <FString, uint> overrideHashes in tester.OverrideNameMapHashes)
            {
                if (testingEntries.ContainsKey(overrideHashes.Key.Value))
                {
                    Assert.IsTrue(overrideHashes.Value == 0);
                    testingEntries[overrideHashes.Key.Value] = true;
                }
            }

            foreach (KeyValuePair <string, bool> testingEntry in testingEntries)
            {
                Assert.IsTrue(testingEntry.Value);
            }
        }
示例#3
0
 public override void FromString(string[] d, UAsset asset)
 {
     float.TryParse(d[0], out float X);
     float.TryParse(d[1], out float Y);
     float.TryParse(d[2], out float Z);
     Value = new FVector(X, Y, Z);
 }
 public override void FromString(string[] d, UAsset asset)
 {
     Enum.TryParse(d[0], out InterpMode);
     Enum.TryParse(d[1], out TangentMode);
     Enum.TryParse(d[2], out TangentWeightMode);
     if (float.TryParse(d[3], out float res1))
     {
         Time = res1;
     }
     if (float.TryParse(d[4], out float res2))
     {
         Value = res2;
     }
     if (float.TryParse(d[5], out float res3))
     {
         ArriveTangent = res3;
     }
     if (float.TryParse(d[6], out float res4))
     {
         ArriveTangentWeight = res4;
     }
     if (float.TryParse(d[7], out float res5))
     {
         LeaveTangent = res5;
     }
     if (float.TryParse(d[8], out float res6))
     {
         LeaveTangentWeight = res6;
     }
 }
示例#5
0
        public void TestCustomSerializationStructsInMap()
        {
            var tester = new UAsset(Path.Combine("TestCustomSerializationStructsInMap", "wtf.uasset"), UE4Version.VER_UE4_25);

            Assert.IsTrue(tester.VerifyBinaryEquality());

            // Get the map property in export 2
            Export exportTwo = FPackageIndex.FromRawIndex(2).ToExport(tester);

            Assert.IsTrue(exportTwo is NormalExport);

            NormalExport exportTwoNormal = (NormalExport)exportTwo;

            var             mapPropertyName = FName.FromString("KekWait");
            MapPropertyData testMap         = exportTwoNormal[mapPropertyName] as MapPropertyData;

            Assert.IsNotNull(testMap);
            Assert.IsTrue(testMap == exportTwoNormal[mapPropertyName.Value.Value]);

            // Get the first entry of the map
            StructPropertyData entryKey   = testMap?.Value?.Keys?.ElementAt(0) as StructPropertyData;
            StructPropertyData entryValue = testMap?.Value?[0] as StructPropertyData;

            Assert.IsNotNull(entryKey?.Value?[0]);
            Assert.IsNotNull(entryValue?.Value?[0]);

            // Check that the properties are correct
            Assert.IsTrue(entryKey.Value[0] is VectorPropertyData);
            Assert.IsTrue(entryValue.Value[0] is LinearColorPropertyData);
        }
示例#6
0
        public void TestUnknownProperties()
        {
            var tester = new UAsset(Path.Combine("TestUnknownProperties", "BP_DetPack_Charge.uasset"), UE4Version.VER_UE4_25);

            Assert.IsTrue(tester.VerifyBinaryEquality());
            Assert.IsTrue(CheckAllExportsParsedCorrectly(tester));

            // Check that only the expected unknown properties are present
            Dictionary <string, bool> newUnknownProperties = new Dictionary <string, bool>();

            newUnknownProperties.Add("GarbagePropty", false);
            newUnknownProperties.Add("EvenMoreGarbageTestingPropertyy", false);

            foreach (Export testExport in tester.Exports)
            {
                if (testExport is NormalExport normalTestExport)
                {
                    foreach (PropertyData prop in normalTestExport.Data)
                    {
                        if (prop is UnknownPropertyData unknownProp)
                        {
                            string serializingType = unknownProp?.SerializingPropertyType?.Value?.Value;
                            Assert.AreNotEqual(serializingType, null);
                            Assert.IsTrue(newUnknownProperties.ContainsKey(serializingType));
                            newUnknownProperties[serializingType] = true;
                        }
                    }
                }
            }

            foreach (KeyValuePair <string, bool> entry in newUnknownProperties)
            {
                Assert.IsTrue(entry.Value);
            }
        }
示例#7
0
 public PrefabPool(Transform root, string assetPath, int capacity)
 {
     _root             = root;
     _capacity         = capacity;
     _asset            = ResourceManager.LoadAsset(assetPath, typeof(GameObject));
     _asset.completed += onAssetLoaded;
 }
示例#8
0
        public void TestCustomProperty()
        {
            var tester = new UAsset(Path.Combine("TestCustomProperty", "AlternateStartActor.uasset"), UE4Version.VER_UE4_23);

            Assert.IsTrue(tester.VerifyBinaryEquality());
            Assert.IsTrue(CheckAllExportsParsedCorrectly(tester));

            // Make sure that there are no unknown properties, and that there is at least one CoolProperty with a value of 72
            bool hasCoolProperty = false;

            foreach (Export testExport in tester.Exports)
            {
                if (testExport is NormalExport normalTestExport)
                {
                    foreach (PropertyData prop in normalTestExport.Data)
                    {
                        Assert.IsFalse(prop is UnknownPropertyData);
                        if (prop is CoolPropertyData coolProp)
                        {
                            hasCoolProperty = true;
                            Assert.IsTrue(coolProp.Value == 72);
                        }
                    }
                }
            }
            Assert.IsTrue(hasCoolProperty);
        }
示例#9
0
 public override void FromString(string[] d, UAsset asset)
 {
     if (int.TryParse(d[0], out int x))
     {
         Value = x;
     }
 }
示例#10
0
        private void onAssetLoaded(UAsset asset)
        {
            var prefab = asset.GetObject() as GameObject;

            if (prefab != null)
            {
                _localRotation = prefab.transform.localRotation;
                _localScale    = prefab.transform.localScale;
            }
            if (_callbacks == null)
            {
                return;
            }
            var shadows = _callbacks;
            var count   = shadows.Count;

            if (count > 0)
            {
                _callbacks = null;
                for (var i = 0; i < count; i++)
                {
                    var cb = shadows[i];
                    try
                    {
                        cb();
                    }
                    catch (Exception exception)
                    {
                        UnityEngine.Debug.LogErrorFormat("GameObjectPool({0}) Exception: {1}", _asset.assetPath, exception);
                    }
                }
            }
        }
示例#11
0
 public override void FromString(string[] d, UAsset asset)
 {
     if (d[4] != null)
     {
         ArrayType = FName.FromString(d[4]);
     }
 }
示例#12
0
        private void onAssetLoaded(UAsset asset)
        {
            if (_callbacks == null)
            {
                return;
            }
            var shadows = _callbacks;
            var count   = shadows.Count;

            if (count > 0)
            {
                _callbacks = null;
                for (var i = 0; i < count; i++)
                {
                    var cb = shadows[i];
                    try
                    {
                        cb();
                    }
                    catch (Exception exception)
                    {
                        UnityEngine.Debug.LogErrorFormat("GameObjectPool({0}) Exception: {1}", _asset.assetPath, exception);
                    }
                }
            }
        }
示例#13
0
        public void TestCDOModification()
        {
            var tester = new UAsset(Path.Combine("TestManyAssets", "Astroneer", "Augment_BroadBrush.uasset"), UE4Version.VER_UE4_23);

            Assert.IsTrue(tester.VerifyBinaryEquality());

            NormalExport cdoExport = null;

            foreach (Export testExport in tester.Exports)
            {
                if (testExport.ObjectFlags.HasFlag(EObjectFlags.RF_ClassDefaultObject))
                {
                    cdoExport = (NormalExport)testExport;
                    break;
                }
            }
            Assert.IsNotNull(cdoExport);

            cdoExport["PickupActor"] = new ObjectPropertyData()
            {
                Value = FPackageIndex.FromRawIndex(0)
            };

            Assert.IsTrue(cdoExport["PickupActor"] is ObjectPropertyData);
            Assert.IsTrue(((ObjectPropertyData)cdoExport["PickupActor"]).Value.Index == 0);
        }
示例#14
0
 public override void FromString(string[] d, UAsset asset)
 {
     float.TryParse(d[0], out float Pitch);
     float.TryParse(d[1], out float Yaw);
     float.TryParse(d[2], out float Roll);
     Value = new FRotator(Pitch, Yaw, Roll);
 }
示例#15
0
 public override void FromString(string[] d, UAsset asset)
 {
     Value = 0;
     if (ulong.TryParse(d[0], out ulong res))
     {
         Value = res;
     }
 }
示例#16
0
 public FString GetEnumBase(UAsset asset)
 {
     if (EnumType <= 0)
     {
         return(null);
     }
     return(asset.GetNameReference(EnumType));
 }
示例#17
0
 public FString GetEnumFull(UAsset asset)
 {
     if (Value <= 0)
     {
         return(null);
     }
     return(asset.GetNameReference(Value));
 }
示例#18
0
 public override void FromString(string[] d, UAsset asset)
 {
     Value = 0;
     if (sbyte.TryParse(d[0], out sbyte res))
     {
         Value = res;
     }
 }
示例#19
0
 public override void FromString(string[] d, UAsset asset)
 {
     if (int.TryParse(d[0], out int res))
     {
         Value = new FPackageIndex(res);
         return;
     }
 }
示例#20
0
 public override void FromString(string[] d, UAsset asset)
 {
     Value = 0;
     if (float.TryParse(d[0], out float res))
     {
         Value = res;
     }
 }
示例#21
0
 public void Read(AssetBinaryReader reader, UAsset asset)
 {
     RelativeStreamingDistance = reader.ReadInt32();
     Reserved0 = reader.ReadSingle();
     Reserved1 = reader.ReadSingle();
     Reserved2 = reader.ReadInt32();
     Reserved3 = reader.ReadInt32();
 }
示例#22
0
 public void Write(AssetBinaryWriter writer, UAsset asset)
 {
     writer.Write(RelativeStreamingDistance);
     writer.Write(Reserved0);
     writer.Write(Reserved1);
     writer.Write(Reserved2);
     writer.Write(Reserved3);
 }
示例#23
0
        private static void ProcessFile(string[] actions, string filepath)
        {
            Console.WriteLine(filepath);
            string text = Path.ChangeExtension(filepath, "uasset");

            if (!File.Exists(text))
            {
                Console.WriteLine("Unable to open " + text);
                return;
            }
            UAsset.Options = new UAParserOptions(actions.Contains("-verbose"), actions.Contains("-force"), actions.Contains("-instnums"), actions.Contains("-fullinst"), actions.Contains("-newentries"));
            using (FileStream uassetStream = File.OpenRead(text))
            {
                UAsset uAsset = new UAsset(uassetStream);
                for (int i = 0; i < actions.Length; i++)
                {
                    switch (actions[i])
                    {
                    case "-tojson":
                    {
                        Dictionary <string, object>[] array = (from x in uAsset.Summary.Exports.SelectMany((FObjectExport x) => x.Objects)
                                                               select x.ToDictionary()).ToArray();
                        File.WriteAllText(Path.ChangeExtension(filepath, "json"), JsonConvert.SerializeObject((array.Length >= 2) ? array : (uAsset.Summary.Exports.FirstOrDefault()?.Objects.FirstOrDefault()?.ObjectData?.Serialize() ?? array), Formatting.Indented, new JsonSerializerSettings
                            {
                                ContractResolver = new IgnoreDataBinding()
                            }));
                        break;
                    }

                    case "-dumpmeta":
                        DumpMeta(uAsset, filepath);
                        break;

                    case "-dumpnames":
                        File.WriteAllLines(Path.ChangeExtension(filepath, "names"), uAsset.Summary.Names.Select((FNameEntry x) => x.Name));
                        break;

                    case "-tobin":
                    {
                        if (uAsset.Summary.ExportCount > 1)
                        {
                            throw new NotImplementedException("Export Count > 1 is not supported!");
                        }
                        string text2 = Path.ChangeExtension(filepath, "json");
                        if (!File.Exists(text2))
                        {
                            Console.WriteLine("Unable to open " + text2);
                            break;
                        }
                        new UAParserOptions(actions.Contains("-verbose"), actions.Contains("-force"));
                        uAsset.UpdateFromJSON(File.ReadAllText(text2, Encoding.UTF8));
                        uAsset.SerializeToBinary(text2);
                        break;
                    }
                    }
                }
            }
        }
示例#24
0
        public void TestDataTables()
        {
            var tester = new UAsset(Path.Combine("TestDatatables", "PB_DT_RandomizerRoomCheck.uasset"), UE4Version.VER_UE4_18);

            Assert.IsTrue(tester.VerifyBinaryEquality());
            Assert.IsTrue(CheckAllExportsParsedCorrectly(tester));
            Assert.IsTrue(tester.Exports.Count == 1);

            var ourDataTableExport = tester.Exports[0] as DataTableExport;
            var ourTable           = ourDataTableExport?.Table;

            Assert.IsNotNull(ourTable);

            // Check out the first entry to make sure it's parsing alright, and flip all the flags for later testing
            StructPropertyData firstEntry = ourTable.Data[0];

            bool didFindTestName = false;

            for (int i = 0; i < firstEntry.Value.Count; i++)
            {
                var propData = firstEntry.Value[i];
                Debug.WriteLine(i + ": " + propData.Name + ", " + propData.PropertyType);
                if (propData.Name == new FName("AcceleratorANDDoubleJump"))
                {
                    didFindTestName = true;
                }
                if (propData is BoolPropertyData boolProp)
                {
                    boolProp.Value = !boolProp.Value;
                }
            }
            Assert.IsTrue(didFindTestName);

            // Save the modified table
            tester.Write(Path.Combine("TestDatatables", "MODIFIED.uasset"));

            // Load the modified table back in and make sure we're good
            var tester2 = new UAsset(Path.Combine("TestDatatables", "MODIFIED.uasset"), UE4Version.VER_UE4_18);

            Assert.IsTrue(tester2.VerifyBinaryEquality());
            Assert.IsTrue(CheckAllExportsParsedCorrectly(tester2));
            Assert.IsTrue(tester2.Exports.Count == 1);

            // Flip the flags back to what they originally were
            firstEntry = (tester2.Exports[0] as DataTableExport)?.Table?.Data?[0];
            Assert.IsNotNull(firstEntry);
            for (int i = 0; i < firstEntry.Value.Count; i++)
            {
                if (firstEntry.Value[i] is BoolPropertyData boolProp)
                {
                    boolProp.Value = !boolProp.Value;
                }
            }

            // Save and check that it's binary equal to what we originally had
            tester2.Write(tester2.FilePath);
            Assert.IsTrue(File.ReadAllBytes(Path.Combine("TestDatatables", "PB_DT_RandomizerRoomCheck.uasset")).SequenceEqual(File.ReadAllBytes(Path.Combine("TestDatatables", "MODIFIED.uasset"))));
        }
示例#25
0
 public void Release()
 {
     Drain();
     if (_asset != null)
     {
         _asset.completed -= onAssetLoaded;
         _asset            = null;
     }
 }
示例#26
0
 private void OnCompleted(UAsset asset)
 {
     Object.Instantiate(asset.GetObject(), transform);
     if (!_loaded)
     {
         // Debug.Log($"asset loaded {_assetPath}");
         _loaded = true;
         OnLoaded();
     }
 }
示例#27
0
        public override void FromString(string[] d, UAsset asset)
        {
            var encoding = Encoding.ASCII;

            if (d.Length >= 5)
            {
                encoding = (d[4].Equals("utf-16") ? Encoding.Unicode : Encoding.ASCII);
            }
            Value = FString.FromString(d[0], encoding);
        }
示例#28
0
        public static FString GetImportNameReferenceWithoutZero(int j, UAsset asset)
        {
            FString refer = new FPackageIndex(j).ToImport(asset).ObjectName.Value;

            if (!asset.ContainsNameReference(refer))
            {
                return(refer);
            }
            return(asset.GetNameReferenceWithoutZero(asset.SearchNameReference(refer)));
        }
示例#29
0
        public static AssetHandle Attach(GameObject gameObject, UAsset asset, float ttl)
        {
            var handle = gameObject.AddComponent <AssetHandle>();

            handle._asset = asset;
            if (ttl > 0.0f)
            {
                handle.StartCoroutine(Helpers.DestroyAfter(gameObject, ttl));
            }
            return(handle);
        }
示例#30
0
 public override void FromString(string[] d, UAsset asset)
 {
     if (float.TryParse(d[0], out float res1))
     {
         X = res1;
     }
     if (float.TryParse(d[1], out float res2))
     {
         Y = res2;
     }
 }