public object UploadMediaWave([FormField] string sourcePath, string inventoryName, string token) { if (tokens.Allow(token, "inventory", "UploadMediaWave", handleGetClientIP()) == false) { return(Failure("Token not accepted", "UploadMediaWave")); } byte[] audioData = File.ReadAllBytes(sourcePath); InventoryFolder AA = bot.GetClient.Inventory.Store.RootFolder; List <InventoryBase> T = bot.GetClient.Inventory.Store.GetContents(AA); AA = null; foreach (InventoryBase R in T) { if (R.Name == "Sounds") { AA = (InventoryFolder)R; break; } } AssetSound S = new AssetSound(); S.AssetData = audioData; S.Encode(); bot.GetClient.Inventory.RequestCreateItemFromAsset(S.AssetData, inventoryName, "", AssetType.Sound, InventoryType.Sound, AA.UUID, null); return(BasicReply("ok", "UploadMediaWave")); }
protected override string GuessAssetName() { if (_ServerAsset == null) { return(null); } Decode(ServerAsset); AssetSound S = (AssetSound)ServerAsset; AssetData = S.AssetData; return(UnknownName); }
void LoadAssets(string path) { try { string[] textures = Directory.GetFiles(path, "*.jp2", SearchOption.TopDirectoryOnly); string[] clothing = Directory.GetFiles(path, "*.clothing", SearchOption.TopDirectoryOnly); string[] bodyparts = Directory.GetFiles(path, "*.bodypart", SearchOption.TopDirectoryOnly); string[] sounds = Directory.GetFiles(path, "*.ogg", SearchOption.TopDirectoryOnly); for (int i = 0; i < textures.Length; i++) { UUID assetID = ParseUUIDFromFilename(textures[i]); Asset asset = new AssetTexture(assetID, File.ReadAllBytes(textures[i])); asset.Temporary = true; StoreAsset(asset); } for (int i = 0; i < clothing.Length; i++) { UUID assetID = ParseUUIDFromFilename(clothing[i]); Asset asset = new AssetClothing(assetID, File.ReadAllBytes(clothing[i])); asset.Temporary = true; StoreAsset(asset); } for (int i = 0; i < bodyparts.Length; i++) { UUID assetID = ParseUUIDFromFilename(bodyparts[i]); Asset asset = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i])); asset.Temporary = true; StoreAsset(asset); } for (int i = 0; i < sounds.Length; i++) { UUID assetID = ParseUUIDFromFilename(sounds[i]); Asset asset = new AssetSound(assetID, File.ReadAllBytes(sounds[i])); asset.Temporary = true; StoreAsset(asset); } } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Warning, ex); } }
private Asset CreateAssetWrapper(AssetType type) { Asset asset; switch (type) { case AssetType.Notecard: asset = new AssetNotecard(); break; case AssetType.LSLText: asset = new AssetScriptText(); break; case AssetType.LSLBytecode: asset = new AssetScriptBinary(); break; case AssetType.Texture: asset = new AssetTexture(); break; case AssetType.Object: asset = new AssetPrim(); break; case AssetType.Clothing: asset = new AssetClothing(); break; case AssetType.Bodypart: asset = new AssetBodypart(); break; case AssetType.Animation: asset = new AssetAnimation(); break; case AssetType.Sound: asset = new AssetSound(); break; case AssetType.Landmark: asset = new AssetLandmark(); break; case AssetType.Gesture: asset = new AssetGesture(); break; default: Logger.Log("Unimplemented asset type: " + type, Helpers.LogLevel.Error, Client); return null; } return asset; }
private static bool LoadAsset(string assetPath, byte[] data, AssetLoadedCallback assetCallback, long bytesRead, long totalBytes) { // Right now we're nastily obtaining the UUID from the filename string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length); int i = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR); if (i == -1) { Logger.Log(String.Format( "[OarFile]: Could not find extension information in asset path {0} since it's missing the separator {1}. Skipping", assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR), Helpers.LogLevel.Warning); return false; } string extension = filename.Substring(i); UUID uuid; UUID.TryParse(filename.Remove(filename.Length - extension.Length), out uuid); if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension)) { AssetType assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension]; Asset asset = null; switch (assetType) { case AssetType.Animation: asset = new AssetAnimation(uuid, data); break; case AssetType.Bodypart: asset = new AssetBodypart(uuid, data); break; case AssetType.Clothing: asset = new AssetClothing(uuid, data); break; case AssetType.Gesture: asset = new AssetGesture(uuid, data); break; case AssetType.Landmark: asset = new AssetLandmark(uuid, data); break; case AssetType.LSLBytecode: asset = new AssetScriptBinary(uuid, data); break; case AssetType.LSLText: asset = new AssetScriptText(uuid, data); break; case AssetType.Notecard: asset = new AssetNotecard(uuid, data); break; case AssetType.Object: asset = new AssetPrim(uuid, data); break; case AssetType.Sound: asset = new AssetSound(uuid, data); break; case AssetType.Texture: asset = new AssetTexture(uuid, data); break; default: Logger.Log("[OarFile] Unhandled asset type " + assetType, Helpers.LogLevel.Error); break; } if (asset != null) { assetCallback(asset, bytesRead, totalBytes); return true; } } Logger.Log("[OarFile] Failed to load asset", Helpers.LogLevel.Warning); return false; }
/** * Handle arrival of a sound resource. */ void Assets_OnSoundReceived(AssetDownload transfer, Asset asset) { if (transfer.Success) { // If this was a Prefetch, just stop here. if (prefetchOnly) { return; } // Logger.Log("Opening sound " + Id.ToString(), Helpers.LogLevel.Debug); // Decode the Ogg Vorbis buffer. AssetSound s = asset as AssetSound; s.Decode(); var data = s.AssetData; // Describe the data to FMOD extraInfo.length = (uint)data.Length; extraInfo.cbsize = Marshal.SizeOf(extraInfo); invoke(new SoundDelegate(delegate { try { // Create an FMOD sound of this Ogg data. FMODExec(system.createSound( data, mode, ref extraInfo, out sound)); // Register for callbacks. RegisterSound(sound); // If looping is requested, loop the entire thing. if (loopSound) { uint soundlen = 0; FMODExec(sound.getLength(out soundlen, TIMEUNIT.PCM)); FMODExec(sound.setLoopPoints(0, TIMEUNIT.PCM, soundlen - 1, TIMEUNIT.PCM)); FMODExec(sound.setLoopCount(-1)); } // Allocate a channel and set initial volume. Initially paused. FMODExec(system.playSound(sound, null, true, out channel)); #if TRACE_SOUND Logger.Log( String.Format("Channel {0} for {1} assigned to {2}", channel.getRaw().ToString("X"), sound.getRaw().ToString("X"), Id), Helpers.LogLevel.Debug); #endif RegisterChannel(channel); FMODExec(channel.setVolume(volumeSetting * AllObjectVolume)); // Take note of when the sound is finished playing. FMODExec(channel.setCallback(endCallback)); // Set attenuation limits. FMODExec(sound.set3DMinMaxDistance( 1.2f, // Any closer than this gets no louder 100.0f)); // Further than this gets no softer. // Set the sound point of origin. This is in SIM coordinates. FMODExec(channel.set3DAttributes(ref position, ref ZeroVector, ref ZeroVector)); // Turn off pause mode. The sound will start playing now. FMODExec(channel.setPaused(false)); } catch (Exception ex) { Logger.Log("Error playing sound: ", Helpers.LogLevel.Error, ex); } })); } else { Logger.Log("Failed to download sound: " + transfer.Status, Helpers.LogLevel.Error); } }
public static Asset CreateAssetWrapper(AssetType type, UUID uuid, byte[] data) { Asset asset; switch (type) { case AssetType.Animation: asset = new AssetAnimation(uuid, data); break; case AssetType.Gesture: asset = new AssetGesture(uuid, data); break; case AssetType.Landmark: asset = new AssetLandmark(uuid, data); break; case AssetType.Bodypart: asset = new AssetBodypart(uuid, data); break; case AssetType.Clothing: asset = new AssetClothing(uuid, data); break; case AssetType.LSLBytecode: asset = new AssetScriptBinary(uuid, data); break; case AssetType.LSLText: asset = new AssetScriptText(uuid, data); break; case AssetType.Notecard: asset = new AssetNotecard(uuid, data); break; case AssetType.Sound: asset = new AssetSound(uuid, data); break; case AssetType.Texture: asset = new AssetTexture(uuid, data); break; #if COGBOT_LIBOMV case AssetType.CallingCard: asset = new AssetCallingCard(uuid, data); break; #endif default: #if COGBOT_LIBOMV asset = new AssetMutable(type, uuid, data); Logger.Log("[OarFile] Not Implemented asset type " + type, Helpers.LogLevel.Error); #else throw new NotImplementedException("Unimplemented asset type: " + type); #endif break; } return asset; }
private static void ConvertSounds(ProjectFile pf) { var dataAssets = ((GMChunkSOND)pf.DataHandle.Chunks["SOND"]).List; var agrp = (GMChunkAGRP)pf.DataHandle.Chunks["AGRP"]; var groups = agrp.List; bool updatedVersion = pf.DataHandle.VersionInfo.IsNumberAtLeast(1, 0, 0, 9999); // First, sort sounds alphabetically List <AssetSound> sortedSounds = updatedVersion ? pf.Sounds.OrderBy(x => x.Name).ToList() : pf.Sounds; // Get all the AUDO chunk handles in the game GMChunkAUDO defaultChunk = (GMChunkAUDO)pf.DataHandle.Chunks["AUDO"]; defaultChunk.List.Clear(); Dictionary <string, GMChunkAUDO> audioChunks = new Dictionary <string, GMChunkAUDO>(); Dictionary <string, int> audioChunkIndices = new Dictionary <string, int>(); if (agrp.AudioData != null) { for (int i = 1; i < groups.Count; i++) { if (agrp.AudioData.ContainsKey(i)) { var currChunk = (GMChunkAUDO)agrp.AudioData[i].Chunks["AUDO"]; currChunk.List.Clear(); audioChunks.Add(groups[i].Name.Content, currChunk); audioChunkIndices.Add(groups[i].Name.Content, i); } } } dataAssets.Clear(); Dictionary <AssetSound, GMSound> finalMap = new Dictionary <AssetSound, GMSound>(); for (int i = 0; i < sortedSounds.Count; i++) { AssetSound asset = sortedSounds[i]; GMSound dataAsset = new GMSound() { Name = pf.DataHandle.DefineString(asset.Name), Volume = asset.Volume, Flags = GMSound.AudioEntryFlags.Regular, Effects = 0, Pitch = asset.Pitch, File = pf.DataHandle.DefineString(asset.OriginalSoundFile), Type = (asset.Type != null) ? pf.DataHandle.DefineString(asset.Type) : null }; finalMap[asset] = dataAsset; switch (asset.Attributes) { case AssetSound.Attribute.CompressedStreamed: if (updatedVersion) { dataAsset.AudioID = -1; } else { dataAsset.AudioID = defaultChunk.List.Count - 1; } dataAsset.GroupID = pf.DataHandle.VersionInfo.BuiltinAudioGroupID; // might be wrong File.WriteAllBytes(Path.Combine(pf.DataHandle.Directory, asset.SoundFile), asset.SoundFileBuffer); break; case AssetSound.Attribute.UncompressOnLoad: case AssetSound.Attribute.Uncompressed: dataAsset.Flags |= GMSound.AudioEntryFlags.IsEmbedded; goto case AssetSound.Attribute.CompressedNotStreamed; case AssetSound.Attribute.CompressedNotStreamed: if (asset.Attributes != AssetSound.Attribute.Uncompressed) { dataAsset.Flags |= GMSound.AudioEntryFlags.IsCompressed; } int ind; GMChunkAUDO chunk; if (!audioChunkIndices.TryGetValue(asset.AudioGroup, out ind)) { ind = pf.DataHandle.VersionInfo.BuiltinAudioGroupID; // might be wrong chunk = defaultChunk; } else { chunk = audioChunks[asset.AudioGroup]; } dataAsset.GroupID = ind; dataAsset.AudioID = chunk.List.Count; chunk.List.Add(new GMAudio() { Data = asset.SoundFileBuffer }); break; } } // Actually add sounds to the data foreach (AssetSound snd in pf.Sounds) { dataAssets.Add(finalMap[snd]); } }
public static Asset CreateAssetWrapper(AssetType type, UUID uuid, byte[] data) { Asset asset; switch (type) { case AssetType.Animation: asset = new AssetAnimation(uuid, data); break; case AssetType.Gesture: asset = new AssetGesture(uuid, data); break; case AssetType.Landmark: asset = new AssetLandmark(uuid, data); break; case AssetType.Bodypart: asset = new AssetBodypart(uuid, data); break; case AssetType.Clothing: asset = new AssetClothing(uuid, data); break; case AssetType.LSLBytecode: asset = new AssetScriptBinary(uuid, data); break; case AssetType.LSLText: asset = new AssetScriptText(uuid, data); break; case AssetType.Notecard: asset = new AssetNotecard(uuid, data); break; case AssetType.Sound: asset = new AssetSound(uuid, data); break; case AssetType.Texture: asset = new AssetTexture(uuid, data); break; #if COGBOT_LIBOMV case AssetType.CallingCard: asset = new AssetCallingCard(uuid, data); break; #endif default: #if COGBOT_LIBOMV asset = new AssetMutable(type, uuid, data); Logger.Log("[OarFile] Not Implemented asset type " + type, Helpers.LogLevel.Error); #else throw new NotImplementedException("Unimplemented asset type: " + type); #endif break; } return(asset); }
public static List <Asset> ConvertSounds(GMData data) { var dataAssets = ((GMChunkSOND)data.Chunks["SOND"]).List; var agrp = (GMChunkAGRP)data.Chunks["AGRP"]; var groups = agrp.List; // Get all the AUDO chunk handles in the game Dictionary <int, GMChunkAUDO> audioChunks = new Dictionary <int, GMChunkAUDO>() { { data.VersionInfo.BuiltinAudioGroupID, (GMChunkAUDO)data.Chunks["AUDO"] } }; if (agrp.AudioData != null) { for (int i = 1; i < groups.Count; i++) { if (agrp.AudioData.ContainsKey(i)) { audioChunks.Add(i, (GMChunkAUDO)agrp.AudioData[i].Chunks["AUDO"]); } } } List <Asset> list = new List <Asset>(); for (int i = 0; i < dataAssets.Count; i++) { GMSound asset = dataAssets[i]; AssetSound projectAsset = new AssetSound() { Name = asset.Name.Content, AudioGroup = (asset.GroupID >= 0 && asset.GroupID < groups.Count) ? groups[asset.GroupID].Name.Content : "", Volume = asset.Volume, Pitch = asset.Pitch, Type = asset.Type?.Content, OriginalSoundFile = asset.File.Content, SoundFile = asset.File.Content }; if ((asset.Flags & AudioEntryFlags.IsEmbedded) != AudioEntryFlags.IsEmbedded && (asset.Flags & AudioEntryFlags.IsCompressed) != AudioEntryFlags.IsCompressed) { // External file projectAsset.Attributes = AssetSound.Attribute.CompressedStreamed; string soundFilePath = Path.Combine(data.Directory, asset.File.Content); if (!soundFilePath.EndsWith(".ogg") && !soundFilePath.EndsWith(".mp3")) { soundFilePath += ".ogg"; } if (File.Exists(soundFilePath)) { projectAsset.SoundFileBuffer = File.ReadAllBytes(soundFilePath); if (!projectAsset.SoundFile.Contains(".")) { projectAsset.SoundFile += Path.GetExtension(soundFilePath); } } } else { // Internal file projectAsset.SoundFileBuffer = audioChunks[asset.GroupID].List[asset.AudioID].Data; if ((asset.Flags & AudioEntryFlags.IsCompressed) == AudioEntryFlags.IsCompressed) { // But compressed! if ((asset.Flags & AudioEntryFlags.IsEmbedded) == AudioEntryFlags.IsEmbedded) { projectAsset.Attributes = AssetSound.Attribute.UncompressOnLoad; } else { projectAsset.Attributes = AssetSound.Attribute.CompressedNotStreamed; } if (projectAsset.SoundFileBuffer.Length > 4 && !projectAsset.SoundFile.Contains(".")) { if (projectAsset.SoundFileBuffer[0] == 'O' && projectAsset.SoundFileBuffer[1] == 'g' && projectAsset.SoundFileBuffer[2] == 'g' && projectAsset.SoundFileBuffer[3] == 'S') { projectAsset.SoundFile += ".ogg"; } else { projectAsset.SoundFile += ".mp3"; } } } else { projectAsset.Attributes = AssetSound.Attribute.Uncompressed; if (!projectAsset.SoundFile.Contains(".")) { projectAsset.SoundFile += ".wav"; } } } list.Add(projectAsset); } return(list); }