What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

[Plugin] Instant MF Swap

Apoc

Well-Known Member
Joined
Jan 16, 2010
Messages
2,790
Reaction score
94
So, I got tired of using my slow scripts to switch between MF and DPS gear, so I wrote a quick plugin to handle it for me.

It will swap any gear in your backpack that has MF into their correct slot, and then revert those changes, all by the press of a hotkey! (Default is F1)

The plugin doesn't care where your items are, or what type. I wrote this very quickly as a proof-of-concept and maybe some example code of how hotkeys work in Demonbuddy.

I will not be supporting this plugin. If you guys find bugs, hopefully you can fix them yourselves.

Usage: simply hit F1 in game and it will swap your gear!

Code:
using System;using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using Zeta;
using Zeta.Common;
using Zeta.Common.Plugins;
using Zeta.Internals.Actors;


namespace Demonbuddy.Plugins.QuickMFSwap
{
    internal class MFSwap : IPlugin
    {
        private static Dictionary<InventorySlot, ACDItem> _originalItems;
        private static readonly HashSet<int> IgnoreItems = new HashSet<int>();
        private static bool _wearingMagicFindGear;


        #region IPlugin Members


        public bool Equals(IPlugin other)
        {
            return Name == other.Name;
        }


        public string Author { get { return "Apoc"; } }


        public Version Version { get { return new Version(1, 0); } }


        public string Name { get { return "MF Swapper"; } }


        public string Description { get { return "Instantly swaps between MF gear and DPS gear"; } }


        public Window DisplayWindow { get { return null; } }


        public void OnPulse()
        {
        }


        public void OnInitialize()
        {
        }


        public void OnShutdown()
        {
        }


        public void OnEnabled()
        {
            Hotkeys.RegisterHotkey("Quick MF Swap", SwapGear, Keys.F1);
        }


        public void OnDisabled()
        {
#if DEBUG
            // Only available in the next build of DB.
            Hotkeys.RemoveHotkey("Quick MF Swap");
#endif
        }


        #endregion


        private static void SwapGear()
        {
            using (ZetaDia.Memory.AcquireFrame())
            {
                ZetaDia.Actors.Update();
                if (!_wearingMagicFindGear)
                {
                    _originalItems =
                        ZetaDia.Me.Inventory.Equipped.ToDictionary(
                            key => key.InventorySlot, v => v);
                    IgnoreItems.Clear();


                    // Equip MF items for each slot. (Find the highest MF ones and equip)
                    Equip(InventorySlot.PlayerNeck);
                    Equip(InventorySlot.PlayerRightFinger);
                    Equip(InventorySlot.PlayerLeftFinger);


                    Equip(InventorySlot.PlayerHead);
                    Equip(InventorySlot.PlayerShoulders);
                    Equip(InventorySlot.PlayerTorso);
                    Equip(InventorySlot.PlayerBracers);
                    Equip(InventorySlot.PlayerHands);
                    Equip(InventorySlot.PlayerWaist);
                    Equip(InventorySlot.PlayerLegs);
                    Equip(InventorySlot.PlayerFeet);


                    Equip(InventorySlot.PlayerRightHand);
                    Equip(InventorySlot.PlayerLeftHand);


                    // Simple state holder so we know when we're wearing MF gear.
                    _wearingMagicFindGear = true;
                }
                else
                {
                    // Go back to our original set of gear, in their exact places!
                    foreach (var i in _originalItems)
                    {
                        ZetaDia.Me.Inventory.EquipItem(i.Value.DynamicId, i.Key);
                    }
                    _wearingMagicFindGear = false;
                }
            }
        }


        private static ACDItem GetBestMagicFindItem(InventorySlot slot)
        {
            List<int> ignoreItemIds = _originalItems.Values.Select(i => i.DynamicId).ToList();


            // For each item that matches the slot we're requesting, get the highest MF.
            return (from i in ZetaDia.Me.Inventory.Backpack
                    // Ensure the item is valid.
                    // Correct slot, and not on ignore lists.
                    where i.ValidInventorySlots.Contains(slot) &&
                          !ignoreItemIds.Contains(i.DynamicId) &&
                          !IgnoreItems.Contains(i.DynamicId) &&
                          // Make sure the item actually has MF!
                          i.Stats.MagicFind > 0
                    // Order by highest MF
                    orderby i.Stats.MagicFind descending
                    // Grab the first.
                    select i).FirstOrDefault();
        }


        private static void Equip(InventorySlot slot)
        {
            ACDItem i = GetBestMagicFindItem(slot);
            if (i != null)
            {
                ZetaDia.Me.Inventory.EquipItem(i.DynamicId, slot);
                // We equipped the item, so lets ignore it for the next run of getting best equip.
                // This avoids a bug with equipping the same ring twice!
                IgnoreItems.Add(i.DynamicId);
            }
        }
    }
}
 
I copy and pasted into a notepad saved as .cs but it does not show up in the bot's list of plugins. Not sure if I did something wrong?
 
try naming as MFSwap.cs

with the folder structure Plugins --> QuickMFSwap
 
[14:20:27.727 N] Compiler Error: c:\Users\Vertraag\Desktop\DB\1\Plugins\QuickMFSwap\MFSwap.cs(79,35) : error CS1061: 'Zeta.MemoryManagement.ExternalProcessReader' does not contain a definition for 'AcquireFrame' and no extension method 'AcquireFrame' accepting a first argument of type 'Zeta.MemoryManagement.ExternalProcessReader' could be found (are you missing a using directive or an assembly reference?)
 
I'm pretty sure we will have to wait for the next version of DB to use that. :o
 
You can just comment that line (with the AcquireFrame() call). I'll check our stuff for the next release to ensure its actually being exposed properly.
 
damn thanks very useful, been looking for something like this. will try tomorrow but will prob get errors like most ppl lol ;p
 
What AquireFrame is suposed to do?
Does it speed up following memory reads ?
 
Last edited:
work why the last version of DB? dont work for me :(

PHP:
[15:29:45.655 N] Compiler Error: d:\DemonBuddy\Plugins\QuickMFSwap\MFSwap.cs(69,21) : error CS0117: 'Zeta.Common.Hotkeys' does not contain a definition for 'RemoveHotkey'
 
Last edited:
AquireFrame seems to be fixed but not Hotkeys :)

anyway just tested AcquireFrame
don't know if its suposed to speed up something, i just tried to play with it and it give a huge more lags :)
 
He fixed it for .180. If it's still not working, there's another issue other than ZetaDia.Memory not being exposed properly.
 
Back
Top