Skip to content

Commit

Permalink
[AccessoriesToStudioItems] Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Dec 17, 2023
1 parent 9ac06ec commit e8be8bf
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AccessoriesToStudioItemsPlugin : BaseUnityPlugin
{
public const string GUID = "AccessoriesToStudioItems";
public const string DisplayName = "Accessories to Studio Items";
public const string Version = "1.0";
public const string Version = "1.0.1";

internal static new BepInEx.Logging.ManualLogSource Logger;

Expand Down Expand Up @@ -189,7 +189,7 @@ private static Sprite TryGetThumbnail(ItemInfo item)
if (item.GroupNo != AccessoriesAsItemsGroupNumber)
return null;

var cacheId = item.LocalSlot + ((long)item.CategoryNo << 32);
var cacheId = MakeCacheId(item.LocalSlot, item.CategoryNo);
if (!_TextureLookup.TryGetValue(cacheId, out var abInfo)) return null;

return CommonLib.LoadAsset<Texture2D>(abInfo.Key, abInfo.Value)?.ToSprite();
Expand All @@ -198,9 +198,10 @@ private static void AddThumbnail(ListInfoBase accessoryInfo)
{
var thumbAb = accessoryInfo.dictInfo[(int)ChaListDefine.KeyType.ThumbAB];
var thumbTex = accessoryInfo.dictInfo[(int)ChaListDefine.KeyType.ThumbTex];
var cacheId = accessoryInfo.Id + ((long)accessoryInfo.Category << 32);
var cacheId = MakeCacheId(accessoryInfo.Id, accessoryInfo.Category);
_TextureLookup[cacheId] = new KeyValuePair<string, string>(thumbAb, thumbTex);
}
private static long MakeCacheId(int localSlot, int categoryNo) => localSlot + ((long)categoryNo << 32);

#endregion

Expand All @@ -214,7 +215,7 @@ private static class Hooks
private static IEnumerable<CodeInstruction> StudioLoadItemsHook(IEnumerable<CodeInstruction> instructions)
{
// Doesn't matter at what part of the original coroutine we inject our code as long as it's after dictionaries are cleared and before isLoadList is set to true.
// Just to be safe we'll inject it right before isLoadList is set to true. Downside is that the Accessory group will be at the very bottom of the item list.
// Just to be safe we'll inject it right before isLoadList is set to true. Downside is that the Accessory group will be at the very bottom of the item list (in some games).
return new CodeMatcher(instructions).End()
.MatchBack(false, new CodeMatch(OpCodes.Call, AccessTools.PropertySetter(typeof(Info), nameof(Studio.Info.isLoadList))))
.ThrowIfInvalid("Hook point missing")
Expand Down

0 comments on commit e8be8bf

Please sign in to comment.