diff --git a/include/Assets/BundleLoader.hpp b/include/Assets/BundleLoader.hpp index 550c4c9..c6912ad 100644 --- a/include/Assets/BundleLoader.hpp +++ b/include/Assets/BundleLoader.hpp @@ -11,6 +11,8 @@ #include "custom-types/shared/macros.hpp" #include "custom-types/shared/coroutine.hpp" +#include "System/Collections/Generic/Dictionary_2.hpp" + using namespace UnityEngine; using namespace std; @@ -19,7 +21,13 @@ using namespace std; #define DECLARE_FILE(name, prefix) extern "C" uint8_t _binary_##name##_start[]; extern "C" uint8_t _binary_##name##_end[]; struct prefix##name { static size_t getLength() { return _binary_##name##_end - _binary_##name##_start; } static uint8_t* getData() { return _binary_##name##_start; } }; DECLARE_FILE(bl_bundle,) +typedef System::Collections::Generic::Dictionary_2 MaterialsDictionary; +typedef System::Collections::Generic::Dictionary_2 SpritesDictionary; + DECLARE_CLASS_CODEGEN(BeatLeader, Bundle, MonoBehaviour, + + DECLARE_INSTANCE_FIELD(MaterialsDictionary*, materials); + DECLARE_INSTANCE_FIELD(SpritesDictionary*, sprites); DECLARE_INSTANCE_FIELD(Material*, logoMaterial); DECLARE_INSTANCE_FIELD(Material*, defaultAvatarMaterial); DECLARE_INSTANCE_FIELD(Material*, UIAdditiveGlowMaterial); @@ -33,6 +41,7 @@ DECLARE_CLASS_CODEGEN(BeatLeader, Bundle, MonoBehaviour, DECLARE_INSTANCE_FIELD(Material*, accDetailsRowMaterial); DECLARE_INSTANCE_FIELD(Material*, miniProfileBackgroundMaterial); DECLARE_INSTANCE_FIELD(Material*, skillTriangleMaterial); + DECLARE_INSTANCE_FIELD(Material*, clanTagBackgroundMaterial); DECLARE_INSTANCE_FIELD(Sprite*, locationIcon); DECLARE_INSTANCE_FIELD(Sprite*, rowSeparatorIcon); @@ -74,6 +83,9 @@ DECLARE_CLASS_CODEGEN(BeatLeader, Bundle, MonoBehaviour, DECLARE_INSTANCE_METHOD(void, Init, AssetBundle* bundle); DECLARE_INSTANCE_METHOD(Material*, GetAvatarMaterial, StringW effectName); DECLARE_INSTANCE_METHOD(Sprite*, GetCountryIcon, StringW country); + + DECLARE_INSTANCE_METHOD(Material*, GetMaterial, StringW name); + DECLARE_INSTANCE_METHOD(Sprite*, GetSprite, StringW name); ) class BundleLoader { diff --git a/src/Assets/BundleLoader.cpp b/src/Assets/BundleLoader.cpp index 3e88c56..df4da74 100644 --- a/src/Assets/BundleLoader.cpp +++ b/src/Assets/BundleLoader.cpp @@ -1,5 +1,7 @@ #include "Assets/BundleLoader.hpp" +#include "include/Utils/StringUtils.hpp" + #include #include "main.hpp" @@ -30,71 +32,102 @@ custom_types::Helpers::Coroutine BundleLoader::LoadBundle(UnityEngine::GameObjec co_return; } -Material* getMaterial(std::string name, AssetBundle* assetBundle) { - return assetBundle->LoadAsset(std::move(name)); -} - -void BeatLeader::Bundle::Init(AssetBundle* assetBundle) { - logoMaterial = getMaterial("LogoMaterial", assetBundle); - defaultAvatarMaterial = getMaterial("DefaultAvatar", assetBundle); - UIAdditiveGlowMaterial = getMaterial("UIAdditiveGlow", assetBundle); - scoreBackgroundMaterial = getMaterial("ScoreBackgroundMaterial", assetBundle); - scoreUnderlineMaterial = getMaterial("ScoreUnderlineMaterial", assetBundle); - VotingButtonMaterial = getMaterial("VotingButtonMaterial", assetBundle); - handAccIndicatorMaterial = getMaterial("HandAccIndicatorMaterial", assetBundle); - accGridBackgroundMaterial = getMaterial("AccGridBackgroundMaterial", assetBundle); - accuracyGraphMaterial = getMaterial("AccuracyGraphBackground", assetBundle); - accuracyGraphLine = getMaterial("AccuracyGraphLine", assetBundle); - accDetailsRowMaterial = getMaterial("AccDetailsRowMaterial", assetBundle); - miniProfileBackgroundMaterial = getMaterial("UIMiniProfileBackgroundMaterial", assetBundle); - skillTriangleMaterial = getMaterial("UISkillTriangleMaterial", assetBundle); - - locationIcon = assetBundle->LoadAsset("LocationIcon"); - rowSeparatorIcon = assetBundle->LoadAsset("RowSeparatorIcon"); - beatLeaderLogoGradient = assetBundle->LoadAsset("BeatLeaderLogoGradient"); - transparentPixel = assetBundle->LoadAsset("TransparentPixel"); - fileError = assetBundle->LoadAsset("FileError"); - modifiersIcon = assetBundle->LoadAsset("ModifiersIcon"); - settingsIcon = assetBundle->LoadAsset("BL_SettingsIcon"); - - overview1Icon = assetBundle->LoadAsset("BL_Overview1Icon"); - overview2Icon = assetBundle->LoadAsset("BL_Overview2Icon"); - detailsIcon = assetBundle->LoadAsset("BL_DetailsIcon"); - gridIcon = assetBundle->LoadAsset("BL_GridIcon"); - graphIcon = assetBundle->LoadAsset("BL_GraphIcon"); - websiteLinkIcon = assetBundle->LoadAsset("BL_Website"); - discordLinkIcon = assetBundle->LoadAsset("BL_Discord"); - patreonLinkIcon = assetBundle->LoadAsset("BL_Patreon"); - replayIcon = assetBundle->LoadAsset("BL_QuestReplayIcon"); - - twitterIcon = assetBundle->LoadAsset("BL_TwitterIcon"); - twitchIcon = assetBundle->LoadAsset("BL_TwitchIcon"); - youtubeIcon = assetBundle->LoadAsset("BL_YoutubeIcon"); - profileIcon = assetBundle->LoadAsset("BL_ProfileIcon"); - friendsIcon = assetBundle->LoadAsset("BL_FriendsIcon"); - incognitoIcon = assetBundle->LoadAsset("BL_IncognitoIcon"); - defaultAvatar = assetBundle->LoadAsset("BL_DefaultAvatar"); - - friendsSelectorIcon = assetBundle->LoadAsset("BL_FriendsSelectorIcon"); - globeIcon = assetBundle->LoadAsset("BL_GlobeIcon"); - - generalContextIcon = assetBundle->LoadAsset("BL_ContextGeneral"); - noModifiersIcon = assetBundle->LoadAsset("BL_ContextNoModifiers"); - noPauseIcon = assetBundle->LoadAsset("BL_ContextNoPause"); - golfIcon = assetBundle->LoadAsset("BL_ContextGolf"); - scpmIcon = assetBundle->LoadAsset("BL_ContextSCPM"); - - TMP_SpriteCurved = assetBundle->LoadAsset("TMP_SpriteCurved"); +Material* BeatLeader::Bundle::GetMaterial(StringW name) { + if (materials->ContainsKey(name)) { + return materials->get_Item(name); + } else { + return NULL; + } } Material* BeatLeader::Bundle::GetAvatarMaterial(StringW effectName) { - Material* result; + Material* result = NULL; + if (((string)effectName).find("_") != string::npos) { - result = getMaterial(effectName, BundleLoader::assetBundle); + result = GetMaterial(effectName); } return result != NULL ? result : defaultAvatarMaterial; } +Sprite* BeatLeader::Bundle::GetSprite(StringW name) { + if (sprites->ContainsKey(name)) { + return sprites->get_Item(name); + } else { + return NULL; + } +} + Sprite* BeatLeader::Bundle::GetCountryIcon(StringW country) { - return BundleLoader::assetBundle->LoadAsset(country); + return GetSprite(toLower((string)country)); +} + +void BeatLeader::Bundle::Init(AssetBundle* assetBundle) { + auto allnames = assetBundle->GetAllAssetNames(); + materials = System::Collections::Generic::Dictionary_2::New_ctor(); + sprites = System::Collections::Generic::Dictionary_2::New_ctor(); + + for (size_t i = 0; i < allnames.Length(); i++) + { + StringW name = allnames[i]; + auto material = assetBundle->LoadAsset(name); + if (material != NULL) { + materials->Add(material->get_name(), material); + } + auto sprite = assetBundle->LoadAsset(name); + if (sprite != NULL) { + sprites->Add(sprite->get_name(), sprite); + } + } + + logoMaterial = GetMaterial("LogoMaterial"); + defaultAvatarMaterial = GetMaterial("DefaultAvatar"); + UIAdditiveGlowMaterial = GetMaterial("UIAdditiveGlow"); + scoreBackgroundMaterial = GetMaterial("ScoreBackgroundMaterial"); + scoreUnderlineMaterial = GetMaterial("ScoreUnderlineMaterial"); + VotingButtonMaterial = GetMaterial("VotingButtonMaterial"); + handAccIndicatorMaterial = GetMaterial("HandAccIndicatorMaterial"); + accGridBackgroundMaterial = GetMaterial("AccGridBackgroundMaterial"); + accuracyGraphMaterial = GetMaterial("AccuracyGraphBackground"); + accuracyGraphLine = GetMaterial("AccuracyGraphLine"); + accDetailsRowMaterial = GetMaterial("AccDetailsRowMaterial"); + miniProfileBackgroundMaterial = GetMaterial("UIMiniProfileBackgroundMaterial"); + skillTriangleMaterial = GetMaterial("UISkillTriangleMaterial"); + clanTagBackgroundMaterial = GetMaterial("ClanTagBackgroundMaterial"); + + locationIcon = GetSprite("LocationIcon"); + rowSeparatorIcon = GetSprite("RowSeparatorIcon"); + beatLeaderLogoGradient = GetSprite("BeatLeaderLogoGradient"); + transparentPixel = GetSprite("TransparentPixel"); + fileError = GetSprite("FileError"); + modifiersIcon = GetSprite("ModifiersIcon"); + settingsIcon = GetSprite("BL_SettingsIcon"); + + overview1Icon = GetSprite("BL_Overview1Icon"); + overview2Icon = GetSprite("BL_Overview2Icon"); + detailsIcon = GetSprite("BL_DetailsIcon"); + gridIcon = GetSprite("BL_GridIcon"); + graphIcon = GetSprite("BL_GraphIcon"); + websiteLinkIcon = GetSprite("BL_Website"); + discordLinkIcon = GetSprite("BL_Discord"); + patreonLinkIcon = GetSprite("BL_Patreon"); + replayIcon = GetSprite("BL_QuestReplayIcon"); + + twitterIcon = GetSprite("BL_TwitterIcon"); + twitchIcon = GetSprite("BL_TwitchIcon"); + youtubeIcon = GetSprite("BL_YoutubeIcon"); + profileIcon = GetSprite("BL_ProfileIcon"); + friendsIcon = GetSprite("BL_FriendsIcon"); + incognitoIcon = GetSprite("BL_IncognitoIcon"); + defaultAvatar = GetSprite("BL_DefaultAvatar"); + + friendsSelectorIcon = GetSprite("BL_FriendsSelectorIcon"); + globeIcon = GetSprite("BL_GlobeIcon"); + + generalContextIcon = GetSprite("BL_ContextGeneral"); + noModifiersIcon = GetSprite("BL_ContextNoModifiers"); + noPauseIcon = GetSprite("BL_ContextNoPause"); + golfIcon = GetSprite("BL_ContextGolf"); + scpmIcon = GetSprite("BL_ContextSCPM"); + + TMP_SpriteCurved = assetBundle->LoadAsset("TMP_SpriteCurved"); } \ No newline at end of file