コード例 #1
0
ファイル: vfs.cs プロジェクト: jira-sarec/ICSE-2012-TraceLab
			internal void Add(string name, VfsEntry entry)
			{
				lock (entries)
				{
					entries.Add(name, entry);
				}
			}
コード例 #2
0
ファイル: Config.cs プロジェクト: lgsvl/simulator
        public static void LoadExternalAssets()
        {
            var sw  = System.Diagnostics.Stopwatch.StartNew();
            var dir = Path.Combine(Application.dataPath, "..", "AssetBundles");

            Debug.Log("Pre-loading Assetbundles from root path " + dir);
            var vfs = VfsEntry.makeRoot(dir);

            // descend into each known dir looking for only specific asset types. todo: add asset type to manifest?
            CheckDir(vfs.GetChild(BundleConfig.pluralOf(BundleConfig.BundleTypes.Controllable)), LoadControllablePlugin);
            CheckDir(vfs.GetChild(BundleConfig.pluralOf(BundleConfig.BundleTypes.Bridge)), LoadBridgePlugin); // NOTE: bridges must be loaded before sensor plugins
            CheckDir(vfs.GetChild(BundleConfig.pluralOf(BundleConfig.BundleTypes.Sensor)), LoadSensorPlugin);
            CheckDir(vfs.GetChild(BundleConfig.pluralOf(BundleConfig.BundleTypes.NPC)), LoadNPCAsset);
            CheckDir(vfs.GetChild(BundleConfig.pluralOf(BundleConfig.BundleTypes.Pedestrian)), LoadPedestrianAsset);
            Debug.Log($"Loaded NPCs behaviours: {NPCBehaviours.Count}  NPC models: {NPCVehicles.Count}  Pedestrians: {Pedestrians.Count} Controllables: {Controllables.Count} Bridges: {BridgePlugins.All.Count } Sensors: {Sensors.Count} in {sw.Elapsed}");
        }
コード例 #3
0
        internal static int GetBooleanAttributes(string path)
        {
#if FIRST_PASS
            return(0);
#else
            VfsEntry entry = GetVfsEntry(path);
            if (entry == null)
            {
                return(0);
            }
            const int BA_EXISTS    = 0x01;
            const int BA_REGULAR   = 0x02;
            const int BA_DIRECTORY = 0x04;
            return(entry is VfsDirectory ? BA_EXISTS | BA_DIRECTORY : BA_EXISTS | BA_REGULAR);
#endif
        }
コード例 #4
0
ファイル: Config.cs プロジェクト: lemketron/simulator
        public static void CheckDir(VfsEntry dir, AssetLoadFunc loadFunc)
        {
            if (dir == null)
            {
                return;
            }

            var manifestFile = dir.Find("manifest.json");

            if (manifestFile != null && manifestFile.IsFile)
            {
                Debug.Log($"found manifest at {manifestFile.Path}");
                using (var reader = new StreamReader(manifestFile.SeekableStream()))
                {
                    try
                    {
                        if (reader == null)
                        {
                            Debug.Log("no reader cannot open stream");
                        }
                        Manifest manifest;
                        try
                        {
                            var buffer = reader.ReadToEnd();
                            manifest = Newtonsoft.Json.JsonConvert.DeserializeObject <Manifest>(buffer);
                        }
                        catch
                        {
                            throw new Exception("Out of date AssetBundle, rebuild or download latest AssetBundle.");
                        }
                        loadFunc(manifest, dir);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogWarning($"failed to load asset from {manifestFile.Path}");
                        Debug.LogException(ex);
                    }
                }
            }
            else
            {
                foreach (var entry in dir)
                {
                    CheckDir(entry, loadFunc);
                }
            }
        }
コード例 #5
0
ファイル: vfs.cs プロジェクト: tianlian0/ikvm
            internal virtual VfsEntry GetEntry(int index, string[] path)
            {
                VfsEntry entry = GetEntry(path[index++]);

                if (index == path.Length)
                {
                    return(entry);
                }
                else
                {
                    VfsDirectory dir = entry as VfsDirectory;
                    if (dir == null)
                    {
                        return(null);
                    }
                    return(dir.GetEntry(index, path));
                }
            }
コード例 #6
0
        public static void LoadBridgePlugin(Manifest manifest, VfsEntry dir)
        {
            if (manifest.bundleFormat != BundleConfig.Versions[BundleConfig.BundleTypes.Bridge])
            {
                throw new Exception($"manifest version mismatch, expected {BundleConfig.Versions[BundleConfig.BundleTypes.Sensor]}, got {manifest.bundleFormat}");
            }

            var pluginSource = loadAssembly(dir, $"{manifest.assetName}.dll");

            foreach (Type ty in pluginSource.GetTypes())
            {
                if (typeof(IBridgeFactory).IsAssignableFrom(ty))
                {
                    var bridgeFactory = Activator.CreateInstance(ty) as IBridgeFactory;
                    BridgePlugins.Add(bridgeFactory);
                }
            }
        }
コード例 #7
0
        public static void LoadControllablePlugin(Manifest manifest, VfsEntry dir)
        {
            if (manifest.assetFormat != BundleConfig.Versions[BundleConfig.BundleTypes.Controllable])
            {
                throw new Exception($"manifest version mismatch, expected {BundleConfig.Versions[BundleConfig.BundleTypes.Controllable]}, got {manifest.assetFormat}");
            }

            Assembly pluginSource = LoadAssembly(dir, $"{manifest.assetName}.dll");

            string      platform     = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "windows" : "linux";
            var         pluginStream = dir.Find($"{manifest.assetGuid}_controllable_main_{platform}").SeekableStream();
            AssetBundle pluginBundle = AssetBundle.LoadFromStream(pluginStream);
            var         pluginAssets = pluginBundle.GetAllAssetNames();

            var texDir = dir.Find($"{manifest.assetGuid}_controllable_textures");

            if (texDir != null)
            {
                var texStream     = dir.Find($"{manifest.assetGuid}_controllable_textures").SeekableStream();
                var textureBundle = AssetBundle.LoadFromStream(texStream, 0, 1 << 20);
                if (!AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
                {
                    textureBundle.LoadAllAssets();
                }
            }

            var prefabName = $"{manifest.assetName}.prefab";
            //Find a prefab with main asset name ignoring the characters case
            var mainPrefabName = pluginAssets.First(name => name.IndexOf(prefabName, StringComparison.InvariantCultureIgnoreCase) >= 0);
            var controllable   = pluginBundle.LoadAsset <GameObject>(mainPrefabName).GetComponent <IControllable>();

            Controllables.Add(manifest.assetName, controllable);
            var additionalAssets = new List <GameObject>();

            foreach (var pluginAsset in pluginAssets)
            {
                if (pluginAsset == mainPrefabName)
                {
                    continue;
                }
                additionalAssets.Add(pluginBundle.LoadAsset <GameObject>(pluginAsset));
            }
            ControllableAssets.Add(controllable, additionalAssets);
        }
コード例 #8
0
ファイル: Config.cs プロジェクト: lgsvl/simulator
        public static void LoadBridgePlugin(Manifest manifest, VfsEntry dir)
        {
#if UNITY_EDITOR
            if (EditorPrefs.GetBool("Simulator/Developer Debug Mode", false) == true)
            {
                Assembly bridgesAssembly = null;
                if (File.Exists(Path.Combine(BundleConfig.ExternalBase, "Bridges", manifest.assetName, $"{manifest.assetName}.cs")))
                {
                    if (bridgesAssembly == null)
                    {
                        bridgesAssembly = Assembly.Load("Simulator.Bridges");
                    }
                    foreach (Type ty in bridgesAssembly.GetTypes())
                    {
                        if (typeof(IBridgeFactory).IsAssignableFrom(ty) && !ty.IsAbstract && ty.GetCustomAttribute <BridgeNameAttribute>().Name == manifest.bridgeType)
                        {
                            Debug.LogWarning($"Loading {manifest.bridgeType} ({manifest.assetGuid}) in Developer Debug Mode. If you wish to use this bridge plugin from WISE, disable Developer Debug Mode in Simulator->Developer Debug Mode or remove the bridge from Assets/External/Bridges");
                            var bridgeFactory = Activator.CreateInstance(ty) as IBridgeFactory;
                            BridgePlugins.Add(bridgeFactory);

                            LoadedAssets.Add(manifest);
                        }
                    }
                    return;
                }
            }
#endif

            if (manifest.assetFormat != BundleConfig.Versions[BundleConfig.BundleTypes.Bridge])
            {
                throw new Exception($"Manifest version mismatch, expected {BundleConfig.Versions[BundleConfig.BundleTypes.Bridge]}, got {manifest.assetFormat}");
            }

            var pluginSource = LoadAssembly(dir, $"{manifest.assetName}.dll");
            foreach (Type ty in pluginSource.GetTypes())
            {
                if (typeof(IBridgeFactory).IsAssignableFrom(ty) && !ty.IsAbstract)
                {
                    var bridgeFactory = Activator.CreateInstance(ty) as IBridgeFactory;
                    BridgePlugins.Add(bridgeFactory);
                    LoadedAssets.Add(manifest);
                }
            }
        }
コード例 #9
0
        static void checkDir(VfsEntry dir, AssetLoadFunc loadFunc)
        {
            if (dir == null)
            {
                return;
            }
            var manifestFile = dir.Find("manifest");

            if (manifestFile != null && manifestFile.IsFile)
            {
                Debug.Log($"found manifest at {manifestFile.Path}");
                using (var reader = new StreamReader(manifestFile.SeekableStream())) {
                    try
                    {
                        if (reader == null)
                        {
                            Debug.Log("no reader?");
                        }
                        Manifest manifest;
                        try
                        {
                            manifest = new Deserializer().Deserialize <Manifest>(reader);
                        }
                        catch
                        {
                            throw new Exception("Out of date AssetBundle, rebuild or download latest AssetBundle.");
                        }
                        loadFunc(manifest, dir);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogWarning($"failed to load asset from {manifestFile.Path}: {ex.Message} STACK: {ex.StackTrace}");
                    }
                }
            }
            else
            {
                foreach (var entry in dir)
                {
                    checkDir(entry, loadFunc);
                }
            }
        }
コード例 #10
0
ファイル: PakFileReader.cs プロジェクト: FabianFG/CUE4Parse
        public override byte[] Extract(VfsEntry entry)
        {
            if (entry is not FPakEntry pakEntry || entry.Vfs != this)
            {
                throw new ArgumentException($"Wrong pak file reader, required {entry.Vfs.Name}, this is {Name}");
            }
            // If this reader is used as a concurrent reader create a clone of the main reader to provide thread safety
            var reader = IsConcurrent ? (FArchive)Ar.Clone() : Ar;

            if (pakEntry.IsCompressed)
            {
#if DEBUG
                Log.Debug($"{pakEntry.Name} is compressed with {pakEntry.CompressionMethod}");
#endif
                var uncompressed    = new byte[(int)pakEntry.UncompressedSize];
                var uncompressedOff = 0;
                foreach (var block in pakEntry.CompressionBlocks)
                {
                    reader.Position = block.CompressedStart;
                    var blockSize = (int)block.Size;
                    var srcSize   = blockSize.Align(pakEntry.IsEncrypted ? Aes.ALIGN : 1);
                    // Read the compressed block
                    byte[] compressed = ReadAndDecrypt(srcSize, reader, pakEntry.IsEncrypted);
                    // Calculate the uncompressed size,
                    // its either just the compression block size
                    // or if its the last block its the remaining data size
                    var uncompressedSize = (int)Math.Min(pakEntry.CompressionBlockSize, pakEntry.UncompressedSize - uncompressedOff);
                    Decompress(compressed, 0, blockSize, uncompressed, uncompressedOff, uncompressedSize, pakEntry.CompressionMethod);
                    uncompressedOff += (int)pakEntry.CompressionBlockSize;
                }

                return(uncompressed);
            }

            // Pak Entry is written before the file data,
            // but its the same as the one from the index, just without a name
            // We don't need to serialize that again so + file.StructSize
            reader.Position = pakEntry.Offset + pakEntry.StructSize; // Doesn't seem to be the case with older pak versions
            var size = (int)pakEntry.UncompressedSize.Align(pakEntry.IsEncrypted ? Aes.ALIGN : 1);
            var data = ReadAndDecrypt(size, reader, pakEntry.IsEncrypted);
            return(size != pakEntry.UncompressedSize ? data.SubByteArray((int)pakEntry.UncompressedSize) : data);
        }
コード例 #11
0
ファイル: vfs.cs プロジェクト: tianlian0/ikvm
            internal override VfsEntry GetEntry(string name)
            {
                VfsEntry entry = base.GetEntry(name);

                if (entry == null)
                {
                    ManifestResourceInfo resource = asm.GetManifestResourceInfo(name);
                    if (resource != null)
                    {
                        lock (entries)
                        {
                            if (!entries.TryGetValue(name, out entry))
                            {
                                entry = new VfsAssemblyResource(asm, name);
                                entries.Add(name, entry);
                            }
                        }
                    }
                }
                return(entry);
            }
コード例 #12
0
ファイル: vfs.cs プロジェクト: tianlian0/ikvm
            internal override VfsEntry GetEntry(string name)
            {
                VfsEntry entry = base.GetEntry(name);

                if (entry == null)
                {
                    Guid guid;
                    if (TryParseGuid(name, out guid))
                    {
                        foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                        {
                            if (asm.ManifestModule.ModuleVersionId == guid &&
                                !ReflectUtil.IsDynamicAssembly(asm))
                            {
                                return(GetOrAddEntry(name, asm));
                            }
                        }
                    }
                    string assemblyName = ParseName(name);
                    if (assemblyName != null)
                    {
                        Assembly asm = null;
                        try
                        {
                            asm = Assembly.Load(assemblyName);
                        }
                        catch
                        {
                        }
                        if (asm != null &&
                            !ReflectUtil.IsDynamicAssembly(asm) &&
                            name == GetName(asm))
                        {
                            return(GetOrAddEntry(name, asm));
                        }
                    }
                }
                return(entry);
            }
コード例 #13
0
        public static void LoadControllablePlugin(Manifest manifest, VfsEntry dir)
        {
            if (manifest.bundleFormat != BundleConfig.Versions[BundleConfig.BundleTypes.Controllable])
            {
                throw new Exception($"manifest version mismatch, expected {BundleConfig.Versions[BundleConfig.BundleTypes.Controllable]}, got {manifest.bundleFormat}");
            }
            var texStream     = dir.Find($"{manifest.assetGuid}_controllable_textures").SeekableStream();
            var textureBundle = AssetBundle.LoadFromStream(texStream, 0, 1 << 20);

            Assembly pluginSource = loadAssembly(dir, $"{manifest.assetName}.dll");

            string      platform     = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "windows" : "linux";
            var         pluginStream = dir.Find($"{manifest.assetGuid}_controllable_main_{platform}").SeekableStream();
            AssetBundle pluginBundle = AssetBundle.LoadFromStream(pluginStream);
            var         pluginAssets = pluginBundle.GetAllAssetNames();

            if (!AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
            {
                textureBundle.LoadAllAssets();
            }
            Controllables.Add(manifest.assetName, pluginBundle.LoadAsset <GameObject>(pluginAssets[0]).GetComponent <IControllable>());
        }
コード例 #14
0
    private void InstantiateSensors(SensorData[] sensors)
    {
        var parents = new Dictionary <string, GameObject>()
        {
            { string.Empty, gameObject },
        };

        var Controller = GetComponent <IAgentController>();
        var requested  = sensors.ToList();
        var baseLink   = transform.GetComponentInChildren <BaseLink>();

        while (requested.Count > 0)
        {
            // remember how many are still looking to find their parent
            int requestedCount = requested.Count;
            for (int i = 0; i < requested.Count(); i++)
            {
                var    item       = requested[i];
                string parentName = item.Parent != null ? item.Parent : string.Empty;
                if (!parents.ContainsKey(parentName))
                {
                    continue;
                }

                var        parentObject = parents[parentName];
                var        name         = item.Name;
                var        type         = item.Type;
                GameObject prefab       = null;
                if (item.Plugin.AssetGuid == null)
                {
                    prefab = Config.SensorPrefabs.FirstOrDefault(s => GetSensorType(s) == type).gameObject;
                }
                else if (Config.SensorTypeLookup.ContainsKey(item.Plugin.AssetGuid))
                {
                    prefab = Config.SensorTypeLookup[item.Plugin.AssetGuid]?.gameObject;
                }
                else
                {
                    var dir = Path.Combine(Config.PersistentDataPath, "Sensors");
                    var vfs = VfsEntry.makeRoot(dir);
                    Config.CheckDir(vfs.GetChild(item.Plugin.AssetGuid), Config.LoadSensorPlugin);
                    if (Config.SensorTypeLookup.ContainsKey(item.Plugin.AssetGuid))
                    {
                        prefab = Config.SensorTypeLookup[item.Plugin.AssetGuid]?.gameObject;
                    }
                }

                if (prefab == null)
                {
                    throw new Exception($"Issue loading sensor type {type} for gameobject {gameObject.name} check logs");
                }

                var sensor     = CreateSensor(gameObject, parentObject, prefab, item, baseLink);
                var sensorBase = sensor.GetComponent <SensorBase>();
                sensorBase.Name = name;
                sensor.name     = name;
                if (AgentBridgeClient != null)
                {
                    sensor.GetComponent <SensorBase>().OnBridgeSetup(AgentBridgeClient.Bridge);
                }

                parents.Add(name, sensor);
                requested.RemoveAt(i);
                i--;
                var sensorInstanceController = new SensorInstanceController(item, sensorBase);
                if (SimulatorManager.InstanceAvailable)
                {
                    SimulatorManager.Instance.Sensors.RegisterSensor(sensorBase);
                }

                sensorInstanceController.Enable();
                Controller?.AgentSensors.Add(sensorBase);
                sensorsInstances.Add(name, sensorInstanceController);
            }

            // no sensors found their parent this round, they also won't find it next round
            if (requestedCount == requested.Count)
            {
                throw new Exception($"Failed to create {requested.Count} sensor(s), cannot determine parent-child relationship");
            }

            SensorsChanged?.Invoke();
        }
    }
コード例 #15
0
        private static void loadNPCAsset(Manifest manifest, VfsEntry dir)
        {
            if (manifest.bundleFormat != BundleConfig.Versions[BundleConfig.BundleTypes.NPC])
            {
                throw new Exception($"manifest version mismatch, expected {BundleConfig.Versions[BundleConfig.BundleTypes.NPC]}, got {manifest.bundleFormat}");
            }
            Assembly pluginSource = loadAssembly(dir, $"{manifest.assetName}.dll");

            if (pluginSource != null)
            {
                foreach (Type ty in pluginSource.GetTypes())
                {
                    if (ty.IsAbstract)
                    {
                        continue;
                    }
                    if (typeof(NPCBehaviourBase).IsAssignableFrom(ty))
                    {
                        NPCBehaviours.Add(ty.ToString(), ty);
                    }
                    else if (typeof(ICommand).IsAssignableFrom(ty))
                    {
                        var cmd = Activator.CreateInstance(ty) as ICommand;
                        ApiManager.Commands.Add(cmd.Name, cmd);
                    }
                }
            }
            var         texEntry      = dir.Find($"{manifest.assetGuid}_npc_textures");
            AssetBundle textureBundle = null;

            if (texEntry != null)
            {
                var texStream = VirtualFileSystem.VirtualFileSystem.EnsureSeekable(texEntry.SeekableStream(), (int)texEntry.Size);
                textureBundle = AssetBundle.LoadFromStream(texStream, 0, 1 << 20);
            }

            string platform    = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "windows" : "linux";
            var    pluginEntry = dir.Find($"{manifest.assetGuid}_npc_main_{platform}");

            if (pluginEntry != null)
            {
                AssetBundle pluginBundle = AssetBundle.LoadFromStream(pluginEntry.SeekableStream());
                var         pluginAssets = pluginBundle.GetAllAssetNames();
                GameObject  prefab       = pluginBundle.LoadAsset <GameObject>(pluginAssets[0]);

                Map.NPCSizeType size = Map.NPCSizeType.MidSize;
                var             meta = prefab.GetComponent <NPCMetaData>();

                if (meta != null)
                {
                    size = meta.SizeType;
                }
                else
                {
                    Debug.LogWarning($"NPC {manifest.assetName} missing meta info, setting default type");
                }

                NPCVehicles.Add(manifest.assetName, new NPCAssetData()
                {
                    prefab    = prefab,
                    Name      = manifest.assetName,
                    AssetGuid = manifest.assetGuid,
                    NPCType   = size,
                });
            }

            if (pluginEntry == null && pluginSource == null)
            {
                Debug.LogError("Neither assembly nor prefab found in " + manifest.assetName);
            }

            if (textureBundle && !AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
            {
                textureBundle.LoadAllAssets();
            }
        }
コード例 #16
0
ファイル: ZipDevice.cs プロジェクト: ezhangle/RomScanner
 internal ZipDirectory(ZipArchiveEntry entry, ZipDevice device, VfsEntry parent = null)
     : base(entry.GetEntryName(), device, parent)
 {
     Attributes = FileAttributes.Directory;
 }
コード例 #17
0
ファイル: Config.cs プロジェクト: lemketron/simulator
        private static void LoadNPCAsset(Manifest manifest, VfsEntry dir)
        {
            if (manifest.assetFormat != BundleConfig.Versions[BundleConfig.BundleTypes.NPC])
            {
                throw new Exception($"manifest version mismatch, expected {BundleConfig.Versions[BundleConfig.BundleTypes.NPC]}, got {manifest.assetFormat}");
            }
            Assembly pluginSource = LoadAssembly(dir, $"{manifest.assetName}.dll");

            if (pluginSource != null)
            {
                foreach (Type ty in pluginSource.GetTypes())
                {
                    if (ty.IsAbstract)
                    {
                        continue;
                    }
                    if (typeof(NPCBehaviourBase).IsAssignableFrom(ty))
                    {
                        NPCBehaviours.Add(ty.ToString(), ty);
                    }
                    else if (typeof(ICommand).IsAssignableFrom(ty))
                    {
                        var cmd = Activator.CreateInstance(ty) as ICommand;
                        ApiManager.Commands.Add(cmd.Name, cmd);
                    }
                }
            }

            var         texEntry      = dir.Find($"{manifest.assetGuid}_npc_textures");
            AssetBundle textureBundle = null;

            if (texEntry != null)
            {
                var texStream = VirtualFileSystem.VirtualFileSystem.EnsureSeekable(texEntry.SeekableStream(), (int)texEntry.Size);
                textureBundle = AssetBundle.LoadFromStream(texStream, 0, 1 << 20);
            }

            string platform    = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "windows" : "linux";
            var    pluginEntry = dir.Find($"{manifest.assetGuid}_npc_main_{platform}");

#if UNITY_EDITOR
            if (EditorPrefs.GetBool("Simulator/Developer Debug Mode", false) == true)
            {
                foreach (var NPCDir in Directory.EnumerateDirectories(Path.Combine(BundleConfig.ExternalBase, BundleConfig.pluralOf(BundleConfig.BundleTypes.NPC))))
                {
                    var assembly = Assembly.Load("Simulator.NPCs");
                    if (File.Exists(Path.Combine(NPCDir, manifest.assetName, $"{manifest.assetName}.prefab")))
                    {
                        var prefab = (GameObject)AssetDatabase.LoadAssetAtPath(Path.Combine(NPCDir, manifest.assetName, $"{manifest.assetName}.prefab"), typeof(GameObject));

                        Map.NPCSizeType size = Map.NPCSizeType.MidSize;
                        var             meta = prefab.GetComponent <NPCMetaData>();

                        if (meta != null)
                        {
                            size = meta.SizeType;
                        }
                        else
                        {
                            Debug.LogWarning($"NPC {manifest.assetName} missing meta info, setting default type");
                        }

                        NPCVehicles.Add(manifest.assetName, new NPCAssetData()
                        {
                            Prefab    = prefab,
                            Name      = manifest.assetName,
                            AssetGuid = manifest.assetGuid,
                            NPCType   = size,
                        });

                        if (textureBundle && !AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
                        {
                            textureBundle.LoadAllAssets();
                        }

                        return;
                    }
                }
            }
#endif

            if (pluginEntry != null)
            {
                AssetBundle pluginBundle   = AssetBundle.LoadFromStream(pluginEntry.SeekableStream());
                var         pluginAssets   = pluginBundle.GetAllAssetNames();
                var         prefabName     = $"{manifest.assetName}.prefab";
                var         mainPrefabName =
                    pluginAssets.First(name => name.IndexOf(prefabName, StringComparison.InvariantCultureIgnoreCase) >= 0);
                GameObject prefab = pluginBundle.LoadAsset <GameObject>(mainPrefabName);

                Map.NPCSizeType size = Map.NPCSizeType.MidSize;
                var             meta = prefab.GetComponent <NPCMetaData>();

                if (meta != null)
                {
                    size = meta.SizeType;
                }
                else
                {
                    Debug.LogWarning($"NPC {manifest.assetName} missing meta info, setting default type");
                }

                NPCVehicles.Add(manifest.assetName, new NPCAssetData()
                {
                    Prefab    = prefab,
                    Name      = manifest.assetName,
                    AssetGuid = manifest.assetGuid,
                    NPCType   = size,
                });
            }

            if (pluginEntry == null && pluginSource == null)
            {
                Debug.LogWarning("Neither assembly nor prefab found in " + manifest.assetName);
            }

            if (textureBundle && !AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
            {
                textureBundle.LoadAllAssets();
            }
        }
コード例 #18
0
ファイル: ZipDevice.cs プロジェクト: ezhangle/RomScanner
 internal ZipFile(ZipArchiveEntry entry, ZipDevice device, VfsEntry parent = null)
     : base(entry.GetEntryName(), device, parent)
 {
     _entry = entry;
     Size   = entry.Length;
 }
コード例 #19
0
        public static void LoadSensorPlugin(Manifest manifest, VfsEntry dir)
        {
#if UNITY_EDITOR
            //if (SensorDebugModeEnabled == true) // TODO Why is this not working?
            if (EditorPrefs.GetBool("Simulator/Sensor Debug Mode", false) == true)
            {
                if (File.Exists(Path.Combine(BundleConfig.ExternalBase, "Sensors", manifest.assetName, $"{manifest.assetName}.prefab")))
                {
                    Debug.Log($"Loading {manifest.assetName} in Sensor Debug Mode. If you wish to use this sensor plugin from WISE, disable Sensor Debug Mode in Simulator->Sensor Debug Mode or remove the sensor from Assets/External/Sensors");
                    var prefab = (GameObject)AssetDatabase.LoadAssetAtPath(Path.Combine(BundleConfig.ExternalBase, "Sensors", manifest.assetName, $"{manifest.assetName}.prefab"), typeof(GameObject));
                    SensorPrefabs.Add(prefab.GetComponent <SensorBase>());
                    Sensors.Add(SensorTypes.GetConfig(prefab.GetComponent <SensorBase>()));
                    if (!SensorTypeLookup.ContainsKey(manifest.assetGuid))
                    {
                        SensorTypeLookup.Add(manifest.assetGuid, prefab.GetComponent <SensorBase>());
                    }

                    var pluginType = prefab.GetComponent <SensorBase>().GetDataBridgePlugin();
                    if (pluginType != null)
                    {
                        var sensorBridgePlugin = Activator.CreateInstance(pluginType) as ISensorBridgePlugin;
                        foreach (var kv in BridgePlugins.All)
                        {
                            sensorBridgePlugin.Register(kv.Value);
                        }
                    }

                    return;
                }
            }
#endif
            if (SensorTypeLookup.ContainsKey(manifest.assetGuid))
            {
                return;
            }

            if (manifest.assetFormat != BundleConfig.Versions[BundleConfig.BundleTypes.Sensor])
            {
                throw new Exception($"Manifest version mismatch, expected {BundleConfig.Versions[BundleConfig.BundleTypes.Sensor]}, got {manifest.assetFormat}");
            }

            if (Sensors.FirstOrDefault(s => s.Guid == manifest.assetGuid) != null)
            {
                return;
            }

            Assembly pluginSource = LoadAssembly(dir, $"{manifest.assetName}.dll");
            foreach (Type ty in pluginSource.GetTypes())
            {
                if (typeof(ISensorBridgePlugin).IsAssignableFrom(ty))
                {
                    var sensorBridgePlugin = Activator.CreateInstance(ty) as ISensorBridgePlugin;
                    foreach (var kv in BridgePlugins.All)
                    {
                        sensorBridgePlugin.Register(kv.Value);
                    }
                }
            }

            string      platform     = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "windows" : "linux";
            var         pluginStream = dir.Find($"{manifest.assetGuid}_sensor_main_{platform}").SeekableStream();
            AssetBundle pluginBundle = AssetBundle.LoadFromStream(pluginStream);
            var         pluginAssets = pluginBundle.GetAllAssetNames();

            var texDir = dir.Find($"{manifest.assetGuid}_sensor_textures");
            if (texDir != null)
            {
                var texStream     = dir.Find($"{manifest.assetGuid}_sensor_textures").SeekableStream();
                var textureBundle = AssetBundle.LoadFromStream(texStream, 0, 1 << 20);
                if (!AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
                {
                    textureBundle.LoadAllAssets();
                }
            }

            SensorBase   pluginBase = pluginBundle.LoadAsset <GameObject>(pluginAssets[0]).GetComponent <SensorBase>();
            SensorConfig config     = SensorTypes.GetConfig(pluginBase);
            config.Guid = manifest.assetGuid;
            Sensors.Add(config);
            SensorPrefabs.Add(pluginBase);
            if (!SensorTypeLookup.ContainsKey(manifest.assetGuid))
            {
                SensorTypeLookup.Add(manifest.assetGuid, pluginBase);
            }
        }
コード例 #20
0
ファイル: VfsDirectory.cs プロジェクト: ezhangle/RomScanner
 protected VfsDirectory(string path, VfsDevice device, VfsEntry parent = null)
     : base(path, device, parent)
 {
 }
コード例 #21
0
        public override byte[] Extract(VfsEntry entry)
        {
            if (!(entry is FPakEntry pakEntry) || entry.Vfs != this)
            {
                throw new ArgumentException($"Wrong pak file reader, required {entry.Vfs.Name}, this is {Name}");
            }
            // If this reader is used as a concurrent reader create a clone of the main reader to provide thread safety
            var reader = IsConcurrent ? (FArchive)Ar.Clone() : Ar;

            // Pak Entry is written before the file data,
            // but its the same as the one from the index, just without a name
            // We don't need to serialize that again so + file.StructSize
            reader.Position = pakEntry.Offset + pakEntry.StructSize; // doesnt seem to be the case with older pak versions

            Pro_Swapper.Fortnite.FortniteExport.Offset = reader.Position;

            long Start = pakEntry.CompressionBlocks[0].CompressedStart;
            long End   = pakEntry.CompressionBlocks[pakEntry.CompressionBlocks.Length - 1].CompressedEnd;

            if (pakEntry.IsCompressed)
            {
#if DEBUG
                Log.Debug($"{pakEntry.Name} is compressed with {pakEntry.CompressionMethod}");
#endif
                var data = new MemoryStream((int)pakEntry.UncompressedSize)
                {
                    Position = 0
                };
                foreach (var block in pakEntry.CompressionBlocks)
                {
                    reader.Position = block.CompressedStart;

                    var srcSize = (int)block.Size.Align(pakEntry.IsEncrypted ? Aes.ALIGN : 1);
                    // Read the compressed block
                    byte[] src = ReadAndDecrypt(srcSize, reader, pakEntry.IsEncrypted);

                    // Calculate the uncompressed size,
                    // its either just the compression block size
                    // or if its the last block its the remaining data size
                    var uncompressedSize = (int)Math.Min(pakEntry.CompressionBlockSize, pakEntry.UncompressedSize - data.Length);

                    byte[] decompressed = Compression.Compression.Decompress(src, uncompressedSize, pakEntry.CompressionMethod, reader);

                    data.Write(decompressed, 0, uncompressedSize);

                    if (Encoding.Default.GetString(decompressed).Contains(Pro_Swapper.ZlibSwap.SearchString))
                    {
                        Pro_Swapper.ZlibSwap.zlibblock = new Pro_Swapper.ZlibSwap.ZlibBlock(block.CompressedStart, block.CompressedEnd, decompressed, src);
                        return(new byte[] { 0 });
                    }
                }

                if (data.Length == pakEntry.UncompressedSize)
                {
                    return(data.GetBuffer());
                }
                if (data.Length > pakEntry.UncompressedSize)
                {
                    return(data.GetBuffer().SubByteArray((int)pakEntry.UncompressedSize));
                }
                throw new ParserException(reader, $"Decompression of {pakEntry.Name} failed, {data.Length} < {pakEntry.UncompressedSize}");
            }
            else
            {
                // File might be encrypted or just stored normally
                var size = (int)pakEntry.UncompressedSize.Align(pakEntry.IsEncrypted ? Aes.ALIGN : 1);
                var data = ReadAndDecrypt(size, reader, pakEntry.IsEncrypted);
                return(size != pakEntry.UncompressedSize ? data.SubByteArray((int)pakEntry.UncompressedSize) : data);
            }
        }
コード例 #22
0
 internal ArchiveDirectory(string path, VfsDevice device, VfsEntry parent = null)
     : base(GetEntryName(path), device, parent)
 {
 }
コード例 #23
0
ファイル: Config.cs プロジェクト: lemketron/simulator
        public static void LoadControllablePlugin(Manifest manifest, VfsEntry dir)
        {
            if (manifest.assetFormat != BundleConfig.Versions[BundleConfig.BundleTypes.Controllable])
            {
                throw new Exception($"manifest version mismatch, expected {BundleConfig.Versions[BundleConfig.BundleTypes.Controllable]}, got {manifest.assetFormat}");
            }

            Assembly pluginSource = LoadAssembly(dir, $"{manifest.assetName}.dll");

            string      platform     = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "windows" : "linux";
            var         pluginStream = dir.Find($"{manifest.assetGuid}_controllable_main_{platform}").SeekableStream();
            AssetBundle pluginBundle = AssetBundle.LoadFromStream(pluginStream);
            var         pluginAssets = pluginBundle.GetAllAssetNames();

            var texDir = dir.Find($"{manifest.assetGuid}_controllable_textures");

            if (texDir != null)
            {
                var texStream     = dir.Find($"{manifest.assetGuid}_controllable_textures").SeekableStream();
                var textureBundle = AssetBundle.LoadFromStream(texStream, 0, 1 << 20);
                if (!AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
                {
                    textureBundle.LoadAllAssets();
                }
            }

            var prefabName = $"{manifest.assetName}.prefab";
            //Find a prefab with main asset name ignoring the characters case
            var mainPrefabName = pluginAssets.First(name => name.IndexOf(prefabName, StringComparison.InvariantCultureIgnoreCase) >= 0);
            var controllable   = pluginBundle.LoadAsset <GameObject>(mainPrefabName).GetComponent <IControllable>();

#if UNITY_EDITOR
            if (EditorPrefs.GetBool("Simulator/Developer Debug Mode", false) == true)
            {
                if (File.Exists(Path.Combine(BundleConfig.ExternalBase, "Controllables", manifest.assetName, $"{manifest.assetName}.prefab")))
                {
                    var prefab = (GameObject)AssetDatabase.LoadAssetAtPath(Path.Combine(BundleConfig.ExternalBase, "Controllables", manifest.assetName, $"{manifest.assetName}.prefab"), typeof(GameObject));
                    Controllables.Add(manifest.assetName, prefab.GetComponent <IControllable>());

                    var debugAssets = new List <GameObject>();
                    foreach (var pluginAsset in pluginAssets)
                    {
                        if (pluginAsset == mainPrefabName)
                        {
                            continue;
                        }
                        debugAssets.Add(pluginBundle.LoadAsset <GameObject>(pluginAsset));
                    }
                    ControllableAssets.Add(controllable, debugAssets);

                    return;
                }
            }
#endif

            Controllables.Add(manifest.assetName, controllable);
            var additionalAssets = new List <GameObject>();
            foreach (var pluginAsset in pluginAssets)
            {
                if (pluginAsset == mainPrefabName)
                {
                    continue;
                }
                additionalAssets.Add(pluginBundle.LoadAsset <GameObject>(pluginAsset));
            }
            ControllableAssets.Add(controllable, additionalAssets);
        }
コード例 #24
0
ファイル: Config.cs プロジェクト: lemketron/simulator
        private static void LoadPedestrianAsset(Manifest manifest, VfsEntry dir)
        {
            if (manifest.assetFormat != BundleConfig.Versions[BundleConfig.BundleTypes.Pedestrian])
            {
                throw new Exception($"manifest version mismatch, expected {BundleConfig.Versions[BundleConfig.BundleTypes.Pedestrian]}, got {manifest.assetFormat}");
            }

            var         texEntry      = dir.Find($"{manifest.assetGuid}_pedestrian_textures");
            AssetBundle textureBundle = null;

            if (texEntry != null)
            {
                var texStream = VirtualFileSystem.VirtualFileSystem.EnsureSeekable(texEntry.SeekableStream(), (int)texEntry.Size);
                textureBundle = AssetBundle.LoadFromStream(texStream, 0, 1 << 20);
            }

            string platform    = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "windows" : "linux";
            var    pluginEntry = dir.Find($"{manifest.assetGuid}_pedestrian_main_{platform}");

#if UNITY_EDITOR
            if (EditorPrefs.GetBool("Simulator/Developer Debug Mode", false) == true)
            {
                var assembly = Assembly.Load("Simulator.Pedestrians");
                foreach (var PedDir in Directory.EnumerateDirectories(Path.Combine(BundleConfig.ExternalBase, BundleConfig.pluralOf(BundleConfig.BundleTypes.Pedestrian))))
                {
                    if (File.Exists(Path.Combine(PedDir, manifest.assetName, $"{manifest.assetName}.prefab")))
                    {
                        var prefab = (GameObject)AssetDatabase.LoadAssetAtPath(Path.Combine(PedDir, manifest.assetName, $"{manifest.assetName}.prefab"), typeof(GameObject));

                        Pedestrians.Add(manifest.assetName, new PedAssetData()
                        {
                            Prefab    = prefab,
                            Name      = manifest.assetName,
                            AssetGuid = manifest.assetGuid,
                        });

                        if (textureBundle && !AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
                        {
                            textureBundle.LoadAllAssets();
                        }

                        return;
                    }
                }
            }
#endif

            if (pluginEntry != null)
            {
                AssetBundle pluginBundle   = AssetBundle.LoadFromStream(pluginEntry.SeekableStream());
                var         pluginAssets   = pluginBundle.GetAllAssetNames();
                var         prefabName     = $"{manifest.assetName}.prefab";
                var         mainPrefabName = pluginAssets.First(name => name.IndexOf(prefabName, StringComparison.InvariantCultureIgnoreCase) >= 0);
                GameObject  prefab         = pluginBundle.LoadAsset <GameObject>(mainPrefabName);

                Pedestrians.Add(manifest.assetName, new PedAssetData()
                {
                    Prefab    = prefab,
                    Name      = manifest.assetName,
                    AssetGuid = manifest.assetGuid,
                });
            }

            if (pluginEntry == null)
            {
                Debug.LogWarning("No prefab found in " + manifest.assetName);
            }

            if (textureBundle && !AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
            {
                textureBundle.LoadAllAssets();
            }
        }
コード例 #25
0
 public ArchiveFile(TEntry entry, VfsDevice device, VfsEntry parent = null)
     : base(GetEntryName(entry.Key), device, parent)
 {
     _entry = entry;
     Size   = entry.Size;
 }
コード例 #26
0
    public GameObject SpawnAgent(AgentConfig config)
    {
        var go = Instantiate(config.Prefab, transform);

        go.name = config.Name;
        // set it inactive until we can be sure setting up sensors etc worked without exceptions and it AgentController was initialized
        go.SetActive(false);
        var controller = go.GetComponent <IAgentController>();

        if (controller == null)
        {
            Debug.LogWarning($"{nameof(IAgentController)} implementation not found on the {config.Name} vehicle. This vehicle can't be used as an ego vehicle.");
        }
        else
        {
            controller.Config         = config;
            controller.Config.AgentGO = go;
            ActiveAgents.Add(controller.Config);
            controller.GTID        = ++SimulatorManager.Instance.GTIDs;
            controller.Config.GTID = controller.GTID;
        }

        var lane = go.AddComponent <VehicleLane>();

        var baseLink = go.GetComponentInChildren <BaseLink>();

        if (baseLink == null)
        {
            baseLink = new GameObject("BaseLink").AddComponent <BaseLink>();
            baseLink.transform.SetParent(go.transform, false);
        }

        var sensorsController = go.GetComponent <ISensorsController>() ?? go.AddComponent <SensorsController>();

        if (controller != null)
        {
            controller.AgentSensorsController = sensorsController;
        }

        //Add required components for distributing rigidbody from master to clients
        var network = Loader.Instance.Network;

        if (network.IsClusterSimulation)
        {
            HierarchyUtilities.ChangeToUniqueName(go);

            //Add the rest required components for cluster simulation
            ClusterSimulationUtilities.AddDistributedComponents(go);
            if (network.IsClient)
            {
                controller?.DisableControl();
            }
        }

        BridgeClient bridgeClient = null;

        if (config.BridgeData != null)
        {
            var dir = Path.Combine(Simulator.Web.Config.PersistentDataPath, "Bridges");
            var vfs = VfsEntry.makeRoot(dir);
            Simulator.Web.Config.CheckDir(vfs.GetChild(config.BridgeData.AssetGuid), Simulator.Web.Config.LoadBridgePlugin);

            bridgeClient  = go.AddComponent <BridgeClient>();
            config.Bridge = BridgePlugins.Get(config.BridgeData.Type);
            bridgeClient.Init(config.Bridge);

            if (!String.IsNullOrEmpty(config.Connection))
            {
                bridgeClient.Connect(config.Connection);
            }
        }

        go.transform.position = config.Position;
        go.transform.rotation = config.Rotation;
        sensorsController.SetupSensors(config.Sensors);

        controller?.Init();

        if (SimulatorManager.Instance.IsAPI)
        {
            SimulatorManager.Instance.EnvironmentEffectsManager.InitRainVFX(go.transform);
        }

        go.SetActive(true);
        return(go);
    }