public static void Postfix(ResourcesPrefabManager __instance)
 {
     /* All we do is tell our sideloader that the initial loading of prefabs has finished, thus allowing us
      * to safely access the internals of ResourcesPrefabManager's prefab containers without fear of hitting
      * NullPointerExceptions :)
      */
     FinishedLoadingAllAssets(EventArgs.Empty);
 }
Ejemplo n.º 2
0
 public static void PostLoad(ResourcesPrefabManager __instance)
 {
     try
     {
         Dictionary <string, Item> ITEM_PREFABS = (Dictionary <string, Item>)AccessTools.Field(typeof(ResourcesPrefabManager), "ITEM_PREFABS").GetValue(__instance);
         ITEM_PREFABS.Where(i => i.Value.IsQuickSlotable).Do(i => i.Value.gameObject.AddComponent <QuickSlotSetExt>());
     }
     catch (Exception ex)
     {
         DynamicQuickslots.Instance.MyLogger.LogError("PostLoad: " + ex.Message);
     }
 }
        private void PrefabsLoadedHook(On.ResourcesPrefabManager.orig_Load orig, ResourcesPrefabManager self)
        {
            orig(self);

            // Remove items that dont have a valid itemID
            m_itemsToOverride.RemoveAll(item => ResourcesPrefabManager.Instance.GetItemPrefab(item.ItemID) == null);

            // Now add our items we want to modify together in a Dictionary container with the modification data from our configuration file.
            m_itemsToOverride.ForEach(itemOverrides => {
                if (!m_items.ContainsKey(itemOverrides))
                {
                    m_items.Add(itemOverrides, ResourcesPrefabManager.Instance.GetItemPrefab(itemOverrides.ItemID));
                }
            });

            // Parse our modification data and apply it to the item to modify
            if (m_items.Count > 0)
            {
                foreach (var item in m_items)
                {
                    ParseItemOverrides(item.Key, item.Value);
                }
            }
        }
Ejemplo n.º 4
0
        //Here's the method
        private void loadItemPrefabsHook(On.ResourcesPrefabManager.orig_LoadItemPrefabs orig, ResourcesPrefabManager self)
        {
            orig(self);
            //Be sure to call the original method you are hooking on to
            //99% of the time you will want to call it before you do anything yourself, failing to call this will stop whatever class you are hooking into from loading correctly
            //which could cause a lot of other problems

            //WE ARE HERE CODING TIME
            //Firstly Here's the ID's Of two Items
            //5110110_PistolHandCannon
            //3000300_BigHatArmorHelmBlue

            //I'm going to be usnig the PistolHandCannon because PistolHandCannon is a PistolHandCannon
            var item = self.GetItemPrefab("5110110");

            //Now we'll debug the item
            Debug.Log("ITEM");
            Debug.Log(item);


            //Since I want this PistolHandCannon to also give me a metric ton of magic reduction and the variable for this is private
            //We're going to have to use Reflection (yaaay :|)


            //Firstly we need the Type of the class we want the stat from
            //In this case and the case of probably all weapons is
            //EquipmentStats
            //myType = EquipmentStats now essentially
            Type myType = typeof(EquipmentStats);


            //then we need to use a function from the Reflection class
            //the first variable we need for this function is the variable we want to change but currently aren't allowed
            //in my case it's
            //m_manaUseModifier
            //the second are bindings for the reflection in most cases how they are set below should work fine since you wont need reflection if the vars are public
            FieldInfo field = myType.GetField("m_manaUseModifier", BindingFlags.NonPublic | BindingFlags.Instance);

            //Here I cache a reference to the component as doing GetComponent too often can seriously drag Unity and therefore the game down
            EquipmentStats equipStatComp = item.GetComponent <EquipmentStats>();

            //Here I am using the field variable and passing a reference to this items EquipmentStat Component
            //how do I know it had one? well I used ListComponentsInDebug which is a handy way to get all the components on a object in unity
            //because don't forget we are editing a Prefab here, which is basically the "mastercopy" of an item/object etc
            //if something needs to spawn a PistolHandCannon in it will ask for the prefab which contains the Model, Scripts, Textures references for the item/object.
            field.SetValue(equipStatComp, -100f);

            //and if you check consoleLog.txt or output_log.txt you will see the value is now -100 and it even shows in game on the tooltip
            Debug.Log(field.GetValue(equipStatComp));
        }