UseItem probable exploit prevention.

Author: Tryskell
Source: https://maxcheaters.com/topic/225947-useitem-exploit-fix-duplicate-items-all-l2j-versions/
This commit is contained in:
MobiusDev 2019-02-07 07:42:12 +00:00
parent ed20b40a22
commit 0c5786e457
11 changed files with 100 additions and 99 deletions

View File

@ -243,21 +243,22 @@ public final class UseItem implements IClientIncomingPacket
if (activeChar.isCastingNow()) if (activeChar.isCastingNow())
{ {
// Create and Bind the next action to the AI // Create and Bind the next action to the AI.
activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true))); activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true)));
} }
else if (activeChar.isAttackingNow()) else if (activeChar.isAttackingNow())
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else

View File

@ -243,21 +243,22 @@ public final class UseItem implements IClientIncomingPacket
if (activeChar.isCastingNow()) if (activeChar.isCastingNow())
{ {
// Create and Bind the next action to the AI // Create and Bind the next action to the AI.
activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true))); activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true)));
} }
else if (activeChar.isAttackingNow()) else if (activeChar.isAttackingNow())
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else

View File

@ -243,21 +243,22 @@ public final class UseItem implements IClientIncomingPacket
if (activeChar.isCastingNow()) if (activeChar.isCastingNow())
{ {
// Create and Bind the next action to the AI // Create and Bind the next action to the AI.
activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true))); activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true)));
} }
else if (activeChar.isAttackingNow()) else if (activeChar.isAttackingNow())
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else

View File

@ -243,21 +243,22 @@ public final class UseItem implements IClientIncomingPacket
if (activeChar.isCastingNow()) if (activeChar.isCastingNow())
{ {
// Create and Bind the next action to the AI // Create and Bind the next action to the AI.
activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true))); activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true)));
} }
else if (activeChar.isAttackingNow()) else if (activeChar.isAttackingNow())
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else

View File

@ -240,21 +240,22 @@ public final class UseItem implements IClientIncomingPacket
if (activeChar.isCastingNow()) if (activeChar.isCastingNow())
{ {
// Create and Bind the next action to the AI // Create and Bind the next action to the AI.
activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true))); activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true)));
} }
else if (activeChar.isAttackingNow()) else if (activeChar.isAttackingNow())
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else

View File

@ -256,14 +256,15 @@ public final class UseItem implements IClientIncomingPacket
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else

View File

@ -55,26 +55,6 @@ public final class UseItem implements IClientIncomingPacket
private boolean _ctrlPressed; private boolean _ctrlPressed;
private int _itemId; private int _itemId;
/** Weapon Equip Task */
private static class WeaponEquipTask implements Runnable
{
private final L2ItemInstance item;
private final L2PcInstance activeChar;
protected WeaponEquipTask(L2ItemInstance it, L2PcInstance character)
{
item = it;
activeChar = character;
}
@Override
public void run()
{
// Equip or unEquip
activeChar.useEquippableItem(item, false);
}
}
@Override @Override
public boolean read(L2GameClient client, PacketReader packet) public boolean read(L2GameClient client, PacketReader packet)
{ {
@ -315,7 +295,18 @@ public final class UseItem implements IClientIncomingPacket
} }
else if (activeChar.isAttackingNow()) else if (activeChar.isAttackingNow())
{ {
ThreadPool.schedule(new WeaponEquipTask(item, activeChar), TimeUnit.MILLISECONDS.convert(activeChar.getAttackEndTime() - System.nanoTime(), TimeUnit.NANOSECONDS)); ThreadPool.schedule(() ->
{
// Check if the item is still on inventory.
final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
if (equipItem == null)
{
return;
}
// Equip or unEquip.
activeChar.useEquippableItem(equipItem, false);
}, TimeUnit.MILLISECONDS.convert(activeChar.getAttackEndTime() - System.nanoTime(), TimeUnit.NANOSECONDS));
} }
else else
{ {

View File

@ -243,21 +243,22 @@ public final class UseItem implements IClientIncomingPacket
if (activeChar.isCastingNow()) if (activeChar.isCastingNow())
{ {
// Create and Bind the next action to the AI // Create and Bind the next action to the AI.
activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true))); activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true)));
} }
else if (activeChar.isAttackingNow()) else if (activeChar.isAttackingNow())
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else

View File

@ -243,21 +243,22 @@ public final class UseItem implements IClientIncomingPacket
if (activeChar.isCastingNow()) if (activeChar.isCastingNow())
{ {
// Create and Bind the next action to the AI // Create and Bind the next action to the AI.
activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true))); activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true)));
} }
else if (activeChar.isAttackingNow()) else if (activeChar.isAttackingNow())
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else

View File

@ -240,21 +240,22 @@ public final class UseItem implements IClientIncomingPacket
if (activeChar.isCastingNow()) if (activeChar.isCastingNow())
{ {
// Create and Bind the next action to the AI // Create and Bind the next action to the AI.
activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true))); activeChar.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> activeChar.useEquippableItem(item, true)));
} }
else if (activeChar.isAttackingNow()) else if (activeChar.isAttackingNow())
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else

View File

@ -256,14 +256,15 @@ public final class UseItem implements IClientIncomingPacket
{ {
ThreadPool.schedule(() -> ThreadPool.schedule(() ->
{ {
// Removed for preventing retail behavior. // Check if the item is still on inventory.
// if (activeChar.isAttackingNow()) // If character is still engaged in strike we should not change weapon final L2ItemInstance equipItem = activeChar.getInventory().getItemByObjectId(_objectId);
// { if (equipItem == null)
// return; {
// } return;
}
// Equip or unEquip // Equip or unEquip.
activeChar.useEquippableItem(item, false); activeChar.useEquippableItem(equipItem, false);
}, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())); }, activeChar.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
} }
else else