private Terraria.Localization.LocalizedText GetPrefixName(int pre)
 {
     Terraria.Localization.LocalizedText result = Terraria.Localization.LocalizedText.Empty;
     if (pre > 0)
     {
         result = Lang.prefix[pre];
     }
     return(result);
 }
        public static bool GetItemName_GetItemName(Terraria.Localization.LocalizedText __result, int id)
        {
            // By assigning something to the specially named __result parameter, we are changing the return value of the original method.
            // The id parameter is automatically filled in by Harmony to be the same value as the id parameter that was passed to the original method.

            if (!PluginLoadedSuccessfully) // If there was a problem loading things for our plugin, we will abort this stub method so we dont crash Terraria.
            {
                return(true);              // Allow the original method to execute
            }
            if (id == WeaponItemID)        // Only skip the original method and return our weapon's name if the id is actually our weapon's ID
            {
                __result = WeaponItemName;

                return(false); // Don't allow the original method to execute
            }

            return(true); // Allow the original method to execute
        }
 public ItemDropLogInfo(string action, string sourcePlayerName, string targetPlayerName, int itemNetId, int itemStack, int itemPrefix, float dropX, float dropY)
 {
     this.Timestamp        = DateTime.Now;
     this.ServerName       = TShock.Config.ServerName;
     this.SourcePlayerName = sourcePlayerName;
     this.SourceIP         = string.Empty;
     this.TargetPlayerName = targetPlayerName;
     this.TargetIP         = string.Empty;
     this.Action           = action;
     this.ItemNetId        = itemNetId;
     this.ItemName         = string.Empty;
     this.ItemStack        = itemStack;
     this.ItemPrefix       = Terraria.Localization.LocalizedText.Empty;
     this.DropX            = dropX;
     this.DropY            = dropY;
     if (itemNetId != 0)
     {
         this.ItemName = this.GetItemName(itemNetId);
         if (itemPrefix != 0)
         {
             this.ItemPrefix = this.GetPrefixName(itemPrefix);
         }
     }
 }
        public static void LoadContent_LoadWeaponAssets(Terraria.Main __instance)
        {
            // The specially named __instance parameter is automatically filled in by Harmony to reference the Main instance that is calling this method.

            // We'll do all our setup in a try-catch so we don't crash Terraria if something goes wrong.
            try
            {
                // Load our weapon's texture from the embedded resource bytes we extracted in ConfigurationLoaded()
                ItemGraphic = HHelpers.AssetHandling.CreateTexture2DFromImageBytes(ItemGraphicBytes, __instance.GraphicsDevice);
                // Using CreateTexture2DFromImageBytes() is compliant with all security levels and is the recommended way to create Texture2Ds.
                // You could use your own Streams, but using Streams (or any other type in System.IO) will make your plugin violate Security Level 3.

                // We will also modify some necessary arrays here (this method will only be called once, so this is a good time to modify these arrays).
                // There are many arrays which are indexed using the item's type (aka ID). We need to expand all those arrays to reach up to our item's ID.
                // We will fill the placeholder spaces between the last vanilla ID and our new ID with default values.
                Helper_ExpandArray(ref Terraria.Item.cachedItemSpawnsByType, WeaponItemID, -1);
                Helper_ExpandArray(ref Terraria.Item.claw, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.Item.staff, WeaponItemID, false);
                Terraria.Item.staff[WeaponItemID] = true;     // Our item is a staff, so we set this to true for our slot
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.AlsoABuildingItem, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.AnimatesAsSoul, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.BonusMeleeSpeedMultiplier, WeaponItemID, 1f);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.CanBePlacedOnWeaponRacks, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.CanBeQuickusedOnGamepad, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.CanGetPrefixes, WeaponItemID, false);
                Terraria.ID.ItemID.Sets.CanGetPrefixes[WeaponItemID] = true;     // Our item is a weapon & we want to it be able to get prefixes, so we set this to true for our slot
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.Deprecated, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.DrinkParticleColors, WeaponItemID, new Color[0]);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.ExtractinatorMode, WeaponItemID, -1);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.FoodParticleColors, WeaponItemID, new Color[0]);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.ForceConsumption, WeaponItemID, null);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.GamepadExtraRange, WeaponItemID, 0);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.GamepadSmartQuickReach, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.GamepadWholeScreenUseRange, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.gunProj, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.HasAProjectileThatHasAUsabilityCheck, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IgnoresEncumberingStone, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsAKite, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsAMaterial, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsAPickup, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsChainsaw, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsDrill, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsFishingCrate, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsFishingCrateHardmode, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsFood, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsLavaBait, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.IsPaintScraper, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.ItemIconPulse, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.ItemNoGravity, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.ItemSpawnDecaySpeed, WeaponItemID, 1);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.ItemsThatAllowRepeatedRightClick, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.ItemsThatCountAsBombsForDemolitionistToSpawn, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.KillsToBanner, WeaponItemID, 50);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.LockOnAimAbove, WeaponItemID, 0);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.LockOnIgnoresCollision, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.NebulaPickup, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.NeverAppearsAsNewInInventory, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.NewItemSpawnPriority, WeaponItemID, 0);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.SingleUseInGamepad, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.SkipsInitialUseSound, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.SummonerWeaponThatScalesWithAttackSpeed, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.TextureCopyLoad, WeaponItemID, -1);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.ToolTipDamageMultiplier, WeaponItemID, 1f);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.Torches, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.TrapSigned, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.UsesCursedByPlanteraTooltip, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.WaterTorches, WeaponItemID, false);
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.Yoyo, WeaponItemID, false);

                // We also need to expand Terraria.Main.itemAnimations to reach up to our item's ID and include a Terraria.DataStructures.DrawAnimation for our weapon's Item
                Helper_ExpandArray(ref Terraria.Main.itemAnimations, WeaponItemID, null); // Add null DrawAnimations in the dummy slots (and in our weapon's slot as well, since the sprite has a single frame and no animations)

                // We also need to expand Terraria.ID.ItemID.Sets.TextureCopyLoad to reach up to our item's ID
                Helper_ExpandArray(ref Terraria.ID.ItemID.Sets.TextureCopyLoad, WeaponItemID, 0); // We will have all the empty placeholder spots set to 0 so that they mirror load the texture in index 0 (as opposed to crashing from trying to load an out-of-range texture index)

                // Next we need to extend the Terraria.GameContent.TextureAssets.Item array to reach our item's ID in size and include our Item's texture
                Helper_ExpandArray(ref Terraria.GameContent.TextureAssets.Item, WeaponItemID, Terraria.GameContent.TextureAssets.Item[0]); // Use the first texture in the list as a default placeholder
                // Now create a ReLogic.Content.Asset<Texture2D> to hold our item graphic
                Type assetType = typeof(ReLogic.Content.Asset <Texture2D>);
                ItemGraphicAsset = (ReLogic.Content.Asset <Texture2D>)HHelpers.ActivateInstanceUsingFirstConstructor(assetType, new object[] { "Item_WeaponProcessorOnAStick" }); // This type has only one constructor
                // By using the ActivateInstanceUsingFirstConstructor() helper method, we avoid directly using Reflection and thus don't violate plugin Security Level 4
                HHelpers.SetPropertyValueWithReflection("Value", ItemGraphicAsset, ItemGraphic);                                                                                  // Set the Value (which is of type Texture2D)
                HHelpers.SetPropertyValueWithReflection("State", ItemGraphicAsset, ReLogic.Content.AssetState.Loaded);                                                            // Set the loaded state to Loaded
                Terraria.GameContent.TextureAssets.Item[WeaponItemID] = ItemGraphicAsset;                                                                                         // Assign the newly created asset to our item's slot in the array

                // We also need to create a LocalizedText to hold our weapon Item's name
                Type localizedTextType = typeof(Terraria.Localization.LocalizedText);
                WeaponItemName = (Terraria.Localization.LocalizedText)HHelpers.ActivateInstanceUsingFirstConstructor(localizedTextType, new object[] { "", WeaponItemNameText }); // This type has only one constructor
                // By using the ActivateInstanceUsingFirstConstructor() helper method, we avoid directly using Reflection and thus don't violate plugin Security Level 4
            }
            catch (Exception e)
            {
                // Something went wrong, so we will set PluginLoadedSuccessfully to false and thus disable the rest of our plugin code.
                // If you are debugging a plugin, however, you probably DONT want to do this, or you might miss thrown exceptions.
                PluginLoadedSuccessfully = false;
                return;
            }
        }