public T Load <T>(ContentManager contentManager, string assetName) { var output = default(T); var item = XnbRegistry.GetItem(assetName); try { if (item.IsXnb) { var currentDirectory = Path.GetDirectoryName(item.AbsoluteFilePath); var modContentManager = GetContentManagerForMod(contentManager, item); var relPath = modContentManager.RootDirectory + "\\"; if (currentDirectory != null) { var relRootUri = new Uri(relPath, UriKind.Absolute); var fullPath = new Uri(currentDirectory, UriKind.Absolute); var relUri = relRootUri.MakeRelativeUri(fullPath) + "/" + item.File; Log.Verbose($"Using own asset replacement: {assetName} = {relUri}"); output = modContentManager.Load <T>(relUri); } } else if (item.IsTexture && typeof(T) == typeof(Texture2D)) { output = (T)(LoadTexture(contentManager, assetName, item)); } } catch (Exception ex) { Log.Exception("Error reading own file", ex); } return(output); }
public T Load <T>(ContentManager contentManager, string assetName) { var output = default(T); var items = XnbRegistry.GetItem(assetName, null, true); var isDirty = XnbRegistry.IsDirty(assetName, null, true); try { var modXnbs = items as ModXnb[] ?? items.ToArray(); if (modXnbs.Any(x => x.IsXnb)) { var item = modXnbs.First(x => x.IsXnb); if (modXnbs.Length > 1) { var outputMessage = modXnbs.Skip(1) .Select(n => n.OwningMod.Name + " (" + n.Texture + ")") .Aggregate((a, b) => a + ", " + b); Log.Warning( $"XNB Conflict on asset {assetName}. Using {item.OwningMod} ({item.File}) and ignoring: {outputMessage}"); } var currentDirectory = Path.GetDirectoryName(item.AbsoluteFilePath); var modContentManager = this.GetContentManagerForMod(contentManager, item); var relPath = modContentManager.RootDirectory + "\\"; if (currentDirectory != null) { var relRootUri = new Uri(relPath, UriKind.Absolute); var fullPath = new Uri(currentDirectory, UriKind.Absolute); var relUri = relRootUri.MakeRelativeUri(fullPath) + "/" + item.File; Log.Verbose($"Using own asset replacement: {assetName} = {relUri}"); output = modContentManager.Load <T>(relUri); } } else if (modXnbs.Any(i => i.IsTexture) && typeof(T) == typeof(Texture2D)) { output = (T)this.LoadTexture(contentManager, assetName, modXnbs, isDirty); } } catch (Exception ex) { Log.Exception("Error reading own file", ex); } XnbRegistry.ClearDirtyFlag(assetName, null, true); return(output); }
public void LoadContent(ModManifest mod) { Logging.Log.Verbose("Loading Content"); if (Textures != null) { foreach (var texture in Textures) { texture.AbsoluteFilePath = $"{mod.ModDirectory}\\{Constants.ModContentDirectory}\\{texture.File}"; if (!texture.Exists()) { throw new Exception($"Missing Texture: {texture.AbsoluteFilePath}"); } Logging.Log.Verbose($"Registering new texture: {texture.Id}"); TextureRegistry.RegisterItem(texture.Id, texture, mod); } } if (Xnb == null) { return; } foreach (var file in Xnb) { if (file.IsXnb) { file.AbsoluteFilePath = $"{mod.ModDirectory}\\{Constants.ModContentDirectory}\\{file.File}"; } file.OwningMod = mod; if (!file.Exists(mod)) { if (file.IsXnb) { throw new Exception($"Replacement File: {file.AbsoluteFilePath}"); } if (file.IsTexture) { throw new Exception($"Replacement Texture: {file.Texture}"); } } Logging.Log.Verbose("Registering new texture XNB override"); XnbRegistry.RegisterItem(file.Original, file); } }
public void LoadContent() { if (this.Content == null) { return; } Log.Verbose("Loading Content"); if (this.Content.Textures != null) { foreach (var texture in this.Content.Textures) { texture.Texture = ApplicationResourcesUtility.LoadTexture(texture.File); if (texture.Texture == null) { throw new Exception($"Missing API Texture: {texture.File}"); } Log.Verbose($"Registering new API texture: {texture.Id}"); TextureRegistry.RegisterItem(texture.Id, texture); } } if (this.Content.Maps != null) { foreach (var map in this.Content.Maps) { map.Map = ApplicationResourcesUtility.LoadMap(map.File); if (map.Map == null) { throw new Exception($"Missing API map: {map.AbsoluteFilePath}"); } Log.Verbose($"Registering new API map: {map.Id}"); MapRegistry.RegisterItem(map.Id, map); } } if (this.Content.Xnb == null) { return; } foreach (var file in this.Content.Xnb) { if (file.IsXnb) { throw new NotImplementedException(); } file.OwningMod = null; if (!file.Exists(null)) { if (file.IsXnb) { throw new Exception($"Replacement File: {file.AbsoluteFilePath}"); } if (file.IsTexture) { throw new Exception($"Replacement Texture: {file.Texture}"); } } Log.Verbose("Registering new API texture XNB override"); XnbRegistry.RegisterItem(file.Original, file); } }
internal void LoadContent() { if (this.Content == null) { return; } Log.Verbose("Loading Content"); if (this.Content.Textures != null) { foreach (var texture in this.Content.Textures) { texture.AbsoluteFilePath = $"{this.ModDirectory}\\{Constants.ModContentDirectory}\\{texture.File}"; if (!texture.Exists()) { throw new Exception($"Missing Texture: {texture.AbsoluteFilePath}"); } Log.Verbose($"Registering new texture: {texture.Id}"); TextureRegistry.RegisterItem(texture.Id, texture, this); } } if (this.Content.Maps != null) { foreach (var map in this.Content.Maps) { map.AbsoluteFilePath = $"{this.ModDirectory}\\{Constants.ModContentDirectory}\\{map.File}"; if (!map.Exists()) { throw new Exception($"Missing map: {map.AbsoluteFilePath}"); } Log.Verbose($"Registering new map: {map.Id}"); MapRegistry.RegisterItem(map.Id, map, this); } } if (this.Content.Xnb == null) { return; } foreach (var file in this.Content.Xnb) { if (file.IsXnb) { file.AbsoluteFilePath = $"{this.ModDirectory}\\{Constants.ModContentDirectory}\\{file.File}"; } file.OwningMod = this; if (!file.Exists(this)) { if (file.IsXnb) { throw new Exception($"Replacement File: {file.AbsoluteFilePath}"); } if (file.IsTexture) { throw new Exception($"Replacement Texture: {file.Texture}"); } } Log.Verbose("Registering new texture XNB override"); XnbRegistry.RegisterItem(file.Original, file, this); } }
public bool HandlesAsset(Type type, string assetName) { var item = XnbRegistry.GetItem(assetName, null, true); return(item?.Any(x => x.OwningMod?.ModState != null && x.OwningMod.ModState == ModState.Loaded) ?? false); }
public bool HandlesAsset(Type type, string assetName) { var item = XnbRegistry.GetItem(assetName); return(item?.OwningMod?.ModState != null && item.OwningMod.ModState == ModState.Loaded); }