mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-01-27 18:51:32 +01:00
Syncronize before hacking into the packet list. In addition,
copy over any unprocessed packets into the new list. When we're done, we'll also clean up properly by copying over any remaining packets.
This commit is contained in:
parent
5a6f3be219
commit
1710ef343b
@ -214,7 +214,12 @@ class PlayerInjector {
|
||||
for (Field field : list.getFields()) {
|
||||
VolatileField overwriter = new VolatileField(field, networkManager, true);
|
||||
|
||||
overwriter.setValue(Collections.synchronizedList(new ArrayList<Packet>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Packet> minecraftList = (List<Packet>) overwriter.getOldValue();
|
||||
|
||||
synchronized(minecraftList) {
|
||||
// The list we'll be inserting
|
||||
List<Packet> hackedList = new ArrayList<Packet>() {
|
||||
@Override
|
||||
public boolean add(Packet packet) {
|
||||
|
||||
@ -245,7 +250,18 @@ class PlayerInjector {
|
||||
throw new RuntimeException("Reverting cancelled packet failed.", e.getTargetException());
|
||||
}
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
// Add every previously stored packet
|
||||
for (Packet packet : minecraftList) {
|
||||
hackedList.add(packet);
|
||||
}
|
||||
|
||||
// Don' keep stale packets around
|
||||
minecraftList.clear();
|
||||
overwriter.setValue(Collections.synchronizedList(hackedList));
|
||||
}
|
||||
|
||||
overridenLists.add(overwriter);
|
||||
}
|
||||
}
|
||||
@ -341,11 +357,29 @@ class PlayerInjector {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void cleanupAll() {
|
||||
// Clean up
|
||||
for (VolatileField overriden : overridenLists) {
|
||||
List<Packet> minecraftList = (List<Packet>) overriden.getOldValue();
|
||||
List<Packet> hacketList = (List<Packet>) overriden.getValue();
|
||||
|
||||
if (minecraftList == hacketList) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a lock before we modify the list
|
||||
synchronized(hacketList) {
|
||||
try {
|
||||
// Copy over current packets
|
||||
for (Packet packet : (List<Packet>) overriden.getValue()) {
|
||||
minecraftList.add(packet);
|
||||
}
|
||||
} finally {
|
||||
overriden.revertValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
overridenLists.clear();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user