Open rikai opened 5 months ago
After some further investigation, I was able to track down the issues at least partially. The first issue seems to be due to some issues with not correctly loading the paths in the loop for the content pack code. Some messing around seems to have fixed this, but C# is not my forte, so I'm not sure I fixed it in a way that makes actual sense.
In short, I modified this section of the code to the following:
foreach (StardewModdingAPI.IContentPack pack in contentPacks)
{
string folderName = pack.Manifest.UniqueID;
folders.Add(folderName);
foreach (string file in Directory.EnumerateFiles(pack.DirectoryPath, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".png") || s.EndsWith(".xnb")))
{
string fileName = Path.GetFileName(file);
string name = Path.GetFileNameWithoutExtension(file);
string extension = Path.GetExtension(file).ToLower();
if (extension == "xnb")
fileName = name;
string relativePath = Path.GetRelativePath(pack.DirectoryPath, file);
Texture2D texture = pack.ModContent.Load<Texture2D>(relativePath.Replace("\\", "/"));
int tileWidth = Math.Max(texture.Width / 2, 64);
float scale = tileWidth / 64f;
ScaledTexture2D scaled = ScaledTexture2D.FromTexture(Game1.getCharacterFromName(name).Portrait, texture, scale);
if (!pTextures.ContainsKey(folderName + ">" + name))
pTextures.Add(folderName + ">" + name, scaled);
else
pTextures[folderName + ">" + name] = scaled;
}
}
As I said though, I'm not sure if this is a GOOD fix, just what seemed to fix the folder issue for me with just some minor changes, and I thought sharing it might help understand where the issue may lie.
I also seem to have found the cause of the second crash, but the ability to understand how to fix that one is a bit beyond my capabilities.
In short, it seems that the logic used for the portrait loading via the Portraits folder is not being used with content packs and this is causing null reference exceptions when trying to load variant portraits such as Abigail_Beach, as it's looking for an NPC named Abigail_Beach. This also causes crashes for NPCs that do exist that may just not necessarily be loaded in a save immediately, such as the Bear.
I was able to verify this was the case in combination with the above fix by creating a pack that only loaded non-variant base NPCs, and the content pack loaded without issues. The moment I add a portrait for an NPC that does not exist yet or add a variant photo such as _Beach or _Summer, the mod then crashes with an NRE, which does not happen in the Portraiture folder code path.
Apologies if none of this is helpful, I just wanted to provide as much info as I possibly could to try to assist!
Same issue, planning to give it a try with your approach
Hello,
I followed the instructions listed on the Portraiture mod description for creating a content pack as listed here:
In the folder containing the manifest I created a "Portraits" folder that contains the Portraits. These portraits are confirmed to work using the non-content pack method without issue. I used the below manifest for testing using a set of portraits from another mod:
The content pack is recognized and loaded as a content pack as seen above, however, an error is received once the game loads:
Moving the images to sit beside the manifest resolves this issue and is still recognized as a content pack, but instead crashes the mod in another way upon load:
This happens when loading any save, even a fresh one, and the mod loadout when testing this is very minimal as seen above. I also tested this with several portrait sets to eliminate weird image encoding as a potential issue.
I assume one of these methods is correct based on the original description, but it appears that something may have broken in the 1.6 transition if that is indeed the case. Please let me know if you require any additional information!