Ejemplo n.º 1
0
        public static void Postfix(LoadAssetPanel __instance, UIListBox ___m_SaveList)
        {
            try
            {
                // Taken from LoadAssetPanel.OnLoad
                var selectedIndex            = ___m_SaveList.selectedIndex;
                var getListingMetaDataMethod = typeof(LoadSavePanelBase <CustomAssetMetaData>).GetMethod(
                    "GetListingMetaData", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                var listingMetaData = (CustomAssetMetaData)getListingMetaDataMethod.Invoke(__instance, new object[] { selectedIndex });


                // Taken from LoadingManager.LoadCustomContent
                if (listingMetaData.userDataRef != null)
                {
                    AssetDataWrapper.UserAssetData userAssetData = listingMetaData.userDataRef.Instantiate() as AssetDataWrapper.UserAssetData;
                    if (userAssetData == null)
                    {
                        userAssetData = new AssetDataWrapper.UserAssetData();
                    }
                    AssetData.OnAssetLoadedImpl(listingMetaData.name, ToolsModifierControl.toolController.m_editPrefabInfo, userAssetData.Data);
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
Ejemplo n.º 2
0
        public static void LoadAssetPanelOnLoadPostfix(LoadAssetPanel __instance, UIListBox ___m_SaveList)
        {
            if (AccessTools.Method(typeof(LoadSavePanelBase <CustomAssetMetaData>), "GetListingMetaData") is not MethodInfo method)
            {
                return;
            }

            var listingMetaData = (CustomAssetMetaData)method.Invoke(__instance, new object[] { ___m_SaveList.selectedIndex });

            if (listingMetaData.userDataRef != null)
            {
                var userAssetData = (listingMetaData.userDataRef.Instantiate() as AssetDataWrapper.UserAssetData) ?? new AssetDataWrapper.UserAssetData();
                Instance.OnAssetLoaded(listingMetaData.name, ToolsModifierControl.toolController.m_editPrefabInfo, userAssetData.Data);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// when loading asset from a file, IAssetData.OnAssetLoaded() is called for all assets but the one that is loaded from the file.
        /// this postfix calls IAssetData.OnAssetLoaded() for asset loaded from file.
        /// Note: even if new road intanciated based on an AR Road, we still need to do this because
        ///       NetInfo metadata is stored in external array
        ///       also we cannot be sure that it is always instancitated properly.
        /// </summary>
        public static void Postfix(LoadAssetPanel __instance, UIListBox ___m_SaveList)
        {
            try {
                // Taken from LoadAssetPanel.OnLoad
                var selectedIndex   = ___m_SaveList.selectedIndex;
                var listingMetaData = (CustomAssetMetaData)mListingMetaData
                                      .Invoke(__instance, new object[] { selectedIndex });

                // Taken from LoadingManager.LoadCustomContent
                if (listingMetaData.userDataRef != null)
                {
                    AssetDataWrapper.UserAssetData userAssetData =
                        listingMetaData.userDataRef.Instantiate() as AssetDataWrapper.UserAssetData;
                    if (userAssetData == null)
                    {
                        userAssetData = new AssetDataWrapper.UserAssetData();
                    }
                    Log.Debug($"LoadAssetPanel.OnLoad().Postfix(): Loading asset from load asset panel");
                    AssetDataExtension.OnAssetLoadedImpl(
                        listingMetaData.name,
                        ToolsModifierControl.toolController.m_editPrefabInfo,
                        userAssetData.Data);

                    var originalInfo = GetOriginalNetInfo(listingMetaData);
                    if (originalInfo)
                    {
                        // OnLoad() calls IntializePrefab() which reverses metadata
                        // and can't be patched because its generic.
                        // so we restore asset metadata here
                        Log.Debug($" restoring original metadata.");
                        AssetDataExtension.OnAssetLoadedImpl(
                            listingMetaData.name,
                            originalInfo,
                            userAssetData.Data);
                    }
                }
                NetInfoExtionsion.Ensure_EditedNetInfos();
                Log.Debug($"LoadAssetPanel.OnLoad().Postfix() succeeded!");
            } catch (Exception ex) {
                Log.Exception(ex);
            }
        }
Ejemplo n.º 4
0
 public static void LoadAssetPanelOnLoadPostfix(LoadAssetPanel __instance, UIListBox ___m_SaveList) => ModsCommon.Patcher.LoadAssetPanelOnLoadPostfix <AssetDataExtension>(__instance, ___m_SaveList);