Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LEGACY] Inventory Management Rework #1347

Merged
merged 18 commits into from Oct 10, 2023
Merged

Conversation

CzechHek
Copy link
Contributor

@CzechHek CzechHek commented Sep 20, 2023

Recoded AutoArmor, InventoryCleaner and ChestStealer using coroutines.

  • they are executed sequentially from a coroutine in InventoryManager util
  • added temporary modules CoroutineStealer, CoroutineArmorer, CoroutineCleaner to category Beta
  • order of execution: Stealer, Armorer, Cleaner
  • all modules clicks are scheduled to ticks from the coroutine, this prevents flags
  • it is possible to send multiple clicks in a tick, therefore delays are as precise as they can be when averaged, previously these clicks were scheduled from a render loop but that was fps dependent, coroutines are fps independent and as precise as possible

CoroutineStealer:

  • can steal to target sorting slots
  • compares items in chests with items in inventory and even equipped armor (no duplicates hopefully)
  • after stealing is finished, it checks all items in chest again and if any of actions failed, steals remaining items
  • added toggleable easing progress bar
  • added nomove values
  • proper start and close delay using coroutines

CoroutineArmorer:

  • using CoroutineArmorComparator
  • first correct 1.8.9 best armor calculation (LB had 1.9 calculations before)
  • for these calculations to be as good as possible, it finds all armor combinations and sorts them by average defense factor of the whole set
  • when swapping armor pieces, it doesn't just drop the worse one and equip the better one, instead, it grabs the better one, drags and swaps it with equipped one and drops the equipped one (this way there is no time of having no armor piece equipped)
  • proper start and close delay using coroutines
  • can autoclose inventory, if invopen is enabled

CoroutineCleaner:

  • using cleaning and sorting system from my InventoryManager script
  • better useful block comparison, no interactable blocks, half blocks, stairs, flowers and so on
  • no item duplicates, items are compared with their stats, durability, enchantment count, ... if both are equally good, the one that is sorted or lower in inventory wins
  • sorting targets allow duplicates for blocks, pearls, etc, but not for swords, tools, ...
  • added sorting target to Fire (lava, flint n' steel, ...)
  • added MaxBlockStacks, MaxFoodStacks sliders to limit how many stacks to keep
  • added HighlightUseful - highlights useful items dropped on ground, in comparison with equipped items, uses ItemESP settings
  • added MergeStacks - merges multiple stacks of the same type to clear up inventory space
  • proper start and close delay using coroutines
  • can autoclose inventory, if invopen is enabled

TickScheduler:

  • added object TickScheduler to each module
  • used as a bridge to TickedActions
  • has features like .schedule(), .scheduleClick(), +=, in, ...
  • added optional allowDuplicates argument to TickedActions
  • replaced usage of TickedActions to TickScheduler
  • modified TickedActions accordingly

DelayTimer:

  • new timer that is initialised with 2 arguments (min delay value, max delay value)
  • every time it gets reset a random delay gets chosen
  • it gets checked with .hasTimePassed() with no arguments
  • used in Scaffold

ItemUtils:

  • code cleanup
  • ItemStack.enchantments - map of all enchantments and levels, used in ItemStack.enchantmentCount, ItemStack.enchantmentSum, ItemStack.getEnchantmentLevel()
  • ItemStack.totalDurability = ItemStack.durability * unbreaking level

Minor improvements:

  • made variable in Ambience private
  • InventoryUtils.hasSpaceHotbar() -> hasSpaceInHotbar()
  • BlockUtils improvements regarding block filtering
  • increased maximal ClickGUI fade speed
  • removed unnecessary ; at line ends
  • added InventoryUtils.hasSpaceInInventory()
  • replaced some .count() with .size
  • Iterable.shuffled(shuffle: Boolean) - shuffling based on boolean, if false, does not shuffle, used in inventory managment rework
  • changed Refill to onTick, made it use CLICK_TIMER
  • CLICK_TIMER gets reset on every window click now (but its pretty useless because of this rework)
  • replaced some for loops with repeat loops for better readability
  • run block simplification

Recoded AutoArmor, InventoryCleaner and ChestStealer using coroutines.
* they are executed sequentially from a coroutine in ModuleManager
* added temporary modules CoroutineStealer, CoroutineArmorer, CoroutineCleaner to category Beta
* order of execution: Stealer, Armorer, Cleaner
* all modules clicks are scheduled to ticks from the coroutine, this prevents flags
* it is possible to send multiple clicks in a tick, therefore delays are as precise as they can be when averaged, previously these clicks were scheduled from a render loop but that was fps dependent, coroutines are fps independent and as precise as possible

CoroutineStealer:
* can steal to target sorting slots
* compares items in chests with items in inventory and even equipped armor (no duplicates hopefully)
* after stealing is finished, it checks all items in chest again and if any of actions failed, steals remaining items
* proper start and close delay using coroutines

CoroutineArmorer:
* using CoroutineArmorComparator
* first correct 1.8.9 best armor calculation (LB had 1.9 calculations before)
* for these calculations to be as good as possible, it finds all armor combinations and sorts them by average defense factor of the whole set
* when swapping armor pieces, it doesn't just drop the worse one and equip the better one, instead, it grabs the better one, drags and swaps it with equipped one and drops the equipped one
* this way there is no time of having no armor piece equipped
* proper start and close delay using coroutines
* can autoclose inventory, if invopen is enabled

CoroutineCleaner:
* using cleaning and sorting system from my InventoryManager script
* better useful block comparison, no interactable blocks, half blocks, stairs, flowers and so on
* no item duplicates, items are compared with their stats, durability, enchantment count, ... if both are equally good, the one that is sorted or lower in inventory wins
* sorting targets allow duplicates for blocks, pearls, etc, but not for swords, tools, ...
* added sorting target to Fire (lava, flint n' steel, ...)

TickScheduler:
* added object TickScheduler to each module
* used as a bridge to TickedActions
* has features like .schedule(), .scheduleClick(), +=, in, ...
* added optional allowDuplicates argument to TickedActions
* replaced usage of TickedActions to TickScheduler
* modified TickedActions accordingly

DelayTimer:
* new timer that is initialised with 2 arguments (min delay value, max delay value)
* every time it gets reset a random delay gets chosen
* it gets checked with .hasTimePassed() with no arguments
* used in Scaffold

ItemUtils:
* code cleanup
* ItemStack.enchantments - map of all enchantments and levels, used in ItemStack.enchantmentCount, ItemStack.enchantmentSum, ItemStack.getEnchantmentLevel()
* ItemStack.totalDurability = ItemStack.durability * unbreaking level

Minor improvements:
* made variable in Ambience private
* InventoryUtils.hasSpaceHotbar() -> hasSpaceInHotbar()
* BlockUtils improvements regarding block filtering
* increased maximal ClickGUI fade speed
* removed unnecessary ; at line ends
* added InventoryUtils.hasSpaceInInventory()
* replaced some .count() with .size
* Iterable.shuffled(shuffle: Boolean) - shuffling based on boolean, if false, does not shuffle, used in inventory managment rework
* changed refill to onTick, made it use CLICK_TIMER
* CLICK_TIMER gets reset on every window click now (but its pretty useless because of this rework)
* replaced some for loops with repeat loops for better readability
* run block simplification
* added sorting target: "Potion"
* added ItemStack.isSplashPotion(), replaced use of ItemPotion.isSplashPotion(stack.metadata) with it
* removed some commented out lines
* fixed stack trace printing
* fixed possible NPEs
* simplified code
@CzechHek
Copy link
Contributor Author

Also improved stealing progress bar in 698a269

CoroutineArmorer:
* improved delayedSlotSwitch: if disabled: schedules all clicks to next tick to equip 4 items at once, bypasses everything except Vulcan, Matrix, if enabled: schedules slot change and click per tick

CoroutineUtils:
* added waitUntil(condition) - suspends the thread with a while loop until the condition is met, used in coroutine modules

TickScheduler:
* added scheduleAndSuspend(vararg actions) - for scheduling multiple actions to be executed 1 per tick

TickedActions:
* fixed a bug: if you had an action scheduled to an id "x", you couldn't schedule another action to id "x" from it without allowing duplicates

Other:
* improved comments
* fixed a possible NPE
* moved modules to beta category package
CoroutineArmorer:
* made smart armor piece swapping stable and toggleable (https://youtu.be/5QyAOE9KY0I)

CoroutineCleaner:
* added MaxBlockStacks, determines how many slots can be occupied by blocks (https://youtu.be/v2VYRbvb_mA)
* removed separate sorting delay, just one delay is enough
* fixed possible sorting / isUseful / comparison issue
* stacks that were in target sorting slots had advantage even when sorting was disabled

CoroutineStealer:
* refactored TakeRandomized to RandomSlot

Other:
* refactored ItemDelay to MinItemAge
* refactored ItemStack.hasItemDelayPassed to hasItemAgePassed
* included delay() straight into click() and therefore simplified code
* reordered values
* added more comments
@CzechHek
Copy link
Contributor Author

Interesting videos from 828feae

https://youtu.be/5QyAOE9KY0I

https://youtu.be/v2VYRbvb_mA

@mems01 mems01 added 🔥 enhancement New feature or request ⚡ bypass A bypass for a specific anti cheat 🌕 legacy labels Sep 22, 2023
@mems01 mems01 added this to the b85 milestone Sep 22, 2023
Fixed major issue of waitUntil { TickScheduler.isEmpty() } not working at all because of the way how duplicated actions got managed.
* caused inventory desyncs, dropping whole armor sets and so on
* had to rollback TickedActions to how they were previously

CoroutineArmorer:
* fixed DelayedSlotSwitch still flagging on Vulcan
* made armor equipping instant again
* improved compatibility with CoroutineCleaner regarding inventory / simulated inventory management and closing
* improved code

CoroutineCleaner:
* improved compatibility with CoroutineArmorer, only executes if CoroutineArmorer finished first (if InvOpen was enabled, it would drop garbage and close the inventory, without Armorer equipping armor pieces before that)

More comments
Added HighlightUseful option to CoroutineCleaner
* renders green esp boxes for useful items that are dropped on ground
* integrated into ItemESP, uses its settings, when ItemESP is disabled it only renders useful items, otherwise it renders useful items with green color
* had to make item comparison compatible with dropped items on ground
* compares dropped items with inventory items + dropped items, if 2 dropped items are equally good it compares their squared distances

Fixed ItemStack.totalDurability not working correctly

Improved code of ESP modules
@CzechHek
Copy link
Contributor Author

Compatible with armor comparator:

image

Compares distances to player:

image

Compatible with MaxBlockStacks:

image
image

Added MaxFoodStacks
* compares food by total saturation sum of the stack

Now also compares dropped blocks and food items between themselves when highlighting.
@CzechHek
Copy link
Contributor Author

In this picture max food stacks is set to 5, they are compared by total sum of their saturation, 2 best food stacks on ground are highlighted.

image

image
image

@superblaubeere27
Copy link
Contributor

superblaubeere27 commented Sep 24, 2023

Compatible with armor comparator:

image

Compares distances to player:

image

Compatible with MaxBlockStacks:

image image

Good idea. I think this should also make it into nextgen. Btw, nextgen InvCleaner also has the feature to merge fragmented stacks. Maybe you want to add it too

@superblaubeere27 superblaubeere27 marked this pull request as draft September 24, 2023 10:31
@gabrielvicenteYT
Copy link
Contributor

Any known bugs?

CoroutineCleaner:
* added CompactStacks option

InventoryUtils:
* added InventoryUtils.isFirstInventoryClick - fixed start delays in coroutine modules with it

Fixed possible NPE.
Fixed AutoClose possibly closing too soon, if your delay settings were in sync with tick loop.
@CzechHek
Copy link
Contributor Author

# Conflicts:
#	src/main/java/net/ccbluex/liquidbounce/features/module/modules/world/Scaffold.kt
Simplified inventory, hotbar slot management in modules with these.
Added util InventoryManager:
* stores shared values of Armorer, Cleaner, InventoryMove, Refill, ... (NoMoveClicks and its options, for Armorer and Cleaner also start, close delay, autoclose, ...) - these values are shared between modules
* handles inventory management actions one by one
* if player is violating nomove or invopen, no inventory requiring actions even start waiting for nomove, because that could block hotbar equipping from doing its stuff
* properly fixed unwanted autoclosing

CoroutineCleaner:
* added LimitStackCounts that needs to be enabled for MaxBlockStacks and such to work
* renamed CompactStacks to MergeStacks
* fixed stack merging and also improved it by ignoring stack limits when checking what to merge, temporarily set max merging delay to 100
* whitelisted eggs and snowballs, added a sorting category for them called "Throwable"

CoroutineStealer:
* now cooperates with autoarmor to equip armor pieces even while still inside a chest
* fixed incorrectly assumed item swapping logic which could have problems when inventory was full
* if inventory is full, garbage items or items that occupy hotbar sorting slot are now moved to chest to free up inventory space
* fixed progress bar being shown in chests that were ignored because of their title or such
* fixed progress bar first appearing after start delay elapsed

InventoryMove:
* added value SilentlyCloseAndReopen - if player violates nomove check and inventory is open, close inventory and reopen it when still
* added value reopenOnClick - only reopen inventory, before a click
* renamed value Undetectable to NotInChests - if you invmove when a chest is open on Polar, the chest gets closed instantly
* improved code

TickedActions:
* fixed scheduling - nested schedules now aren't flagged as duplicates or cleared before ever being called
* added TickedActions.size(module) and TickScheduler.size

Fixed InventoryUtils getting into unescaped loops and freezing game by adding backing fields.
* improved server inventory closing detection by checking if server sent a packet to open a different window

Sprint:
* added value Inventory - stops you from sprinting when serverOpenInventory == true, needed to bypass Vulcan for example

MovementUtils:
* added serverOnGround, serverX, serverY, serverZ - used serverOnGround to improve NoMove checks for ground
* fixed hasMotion that got broken in previous commit

EventManager:
* simplified code
* improved performance by not sorting by priority every event call

Added comments.

Refactored some util packages and moved some utils around.
@CzechHek
Copy link
Contributor Author

CzechHek commented Oct 4, 2023

fd33169
+ inventory now gets closed on server-side when it violates NoMove checks

# Conflicts:
#	src/main/java/net/ccbluex/liquidbounce/features/module/modules/player/AntiFireball.kt
#	src/main/java/net/ccbluex/liquidbounce/utils/block/BlockUtils.kt
@CzechHek
Copy link
Contributor Author

CzechHek commented Oct 4, 2023

Equipping armor while inside a chest:
https://youtu.be/ThKXevO1QqE

@superblaubeere27
Copy link
Contributor

Equipping armor while inside a chest: https://youtu.be/ThKXevO1QqE

Nextgen also has this (but not indended haha)

@CzechHek
Copy link
Contributor Author

CzechHek commented Oct 5, 2023

fd33169
+ inventory now gets closed on server-side when it violates NoMove checks

+ stealer no longer randomly doesn't do anything sometimes (caused by simulated inventory getting closed even with chest open)

Improved coroutine modules
* Now they only work if gamemode is survival or adventure.
* Stealer now drops garbage items that block useful items from chest from being taken, when the chest is full as well...
* Stealer now checks whether armor slot isn't occupied, when equipping while stealing.
* Removed forgotten debug message.

Improved ItemStack?.isEmpty()
* Used kotlin contract to make stack smart-cast to not null ItemStack.

Improved AutoPot, AutoSoup
* No longer closes visually open inventory when simulating inventory closing after each click.

A bit of refactoring and other minor stuff.
@CzechHek
Copy link
Contributor Author

CzechHek commented Oct 10, 2023

01e9e3c
+ fixed Armorer spam equipping armor from hotbar with low delays
+ added missing delay after Armorer finishes equipping from hotbar

@CzechHek CzechHek changed the title [LEGACY] Inventory Management Rework BETA [LEGACY] Inventory Management Rework Oct 10, 2023
@CzechHek CzechHek marked this pull request as ready for review October 10, 2023 20:42
@CzechHek
Copy link
Contributor Author

This is now ready to be merged to be tested by nightly users. Modules are still in their own category "Beta", not replacing the stable ones.

@mems01 mems01 merged commit 959aa72 into CCBlueX:legacy Oct 10, 2023
1 check passed
@CzechHek CzechHek deleted the inventoryrework branch October 10, 2023 23:50
@superblaubeere27
Copy link
Contributor

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ bypass A bypass for a specific anti cheat 🔥 enhancement New feature or request 🌕 legacy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants