Skip to content

Commit

Permalink
configurable brute force
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored and Wide-Cat committed Feb 9, 2024
1 parent 7b677fc commit 3776a5f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ public class Config extends System<Config> {
.build()
);

public final Setting<Boolean> heuristicCombatUtils = sgMisc.add(new BoolSetting.Builder()
.name("heuristic-damage-utils")
.description("Spends extra computation time in order to make combat-related calculations more accurate at the expense of framerate.")
.defaultValue(true)
.build()
);

public final Setting<Integer> heuristicDepth = sgMisc.add(new IntSetting.Builder()
.name("heuristic-depth")
.description("The amount of extra computation time to give, in an exponential scale.")
.defaultValue(4)
.min(2)
.sliderRange(2, 5)
.visible(heuristicCombatUtils::get)
.build()
);

public List<String> dontShowAgainPrompts = new ArrayList<>();

public Config() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.game.GameLeftEvent;
import meteordevelopment.meteorclient.mixin.LivingEntityAccessor;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.utils.PreInit;
import meteordevelopment.meteorclient.utils.entity.StatusEffectHelper;
import meteordevelopment.orbit.EventHandler;
Expand All @@ -35,7 +36,6 @@ public class StatusEffectBruteForce {
private static final TrackedData<Integer> POTION_SWIRLS_COLOR = LivingEntityAccessor.meteor$getPotionSwirlsColor();
private static final TrackedData<Boolean> POTION_SWRISL_AMBIENT = LivingEntityAccessor.meteor$getPotionSwirlsAmbient();
private static final int EMPTY_COLOR = 3694022;
private static final int MAX_DEPTH = 4;
public static final Set<StatusEffectEntry> ALL_ENTRIES = new ReferenceOpenHashSet<>();
public static final Set<StatusEffectEntry> BEACON_ENTRIES = new ReferenceOpenHashSet<>();
private static final Map<LivingEntity, EntityEffectCache> PLAYER_EFFECT_MAP = new Object2ObjectOpenHashMap<>();
Expand Down Expand Up @@ -174,28 +174,36 @@ private static void update(int particleColor, LivingEntity entity, EntityEffectC
// Map#computeIfAbsent(Object, Function) cannot cache null return values, so we use a separate cache for those
if (NULL_COLORS.contains(cacheKey)) return;

@Nullable Map<StatusEffect, StatusEffectInstance> match = EFFECT_CACHE_MAP.computeIfAbsent(cacheKey, key -> {
for (int depth = 2; depth <= MAX_DEPTH; depth++) {
for (var combination : Sets.combinations(possibleEntries, depth)) {
int color = blend(initialColor, combination);
if (color == particleColor) {
// If the amplifiers of all applied effects match, then it cannot be inferred and should be assumed to be 1
boolean assumeLowestAmplifier = combination.stream().mapToInt(o -> o.amplifier).reduce((i1, i2) -> i1 == i2 ? i1 : -1).orElse(-1) != -1;
@Nullable Map<StatusEffect, StatusEffectInstance> match = EFFECT_CACHE_MAP.get(cacheKey);
if (match == null && Config.get().heuristicCombatUtils.get()) {
match = bruteForce(possibleEntries, initialColor, particleColor);
if (match == null) NULL_COLORS.add(cacheKey);
}

if (match != null) container.statusEffects.putAll(match);
}

Map<StatusEffect, StatusEffectInstance> map = new Reference2ObjectOpenHashMap<>();
@Nullable
private static Map<StatusEffect, StatusEffectInstance> bruteForce(Set<StatusEffectEntry> entries, MutableParticleColor initialColor, int particleColor) {
int maxDepth = Config.get().heuristicDepth.get();
for (int depth = 2; depth <= maxDepth; depth++) {
for (var combination : Sets.combinations(entries, depth)) {
int color = blend(initialColor, combination);
if (color == particleColor) {
// If the amplifiers of all applied effects match, then it cannot be inferred and should be assumed to be 1
boolean assumeLowestAmplifier = combination.stream().mapToInt(o -> o.amplifier).reduce((i1, i2) -> i1 == i2 ? i1 : -1).orElse(-1) != -1;

for (var entry : combination) {
map.put(entry.effect, new StatusEffectInstance(entry.effect, 0, assumeLowestAmplifier ? 0 : entry.amplifier - 1));
}
Map<StatusEffect, StatusEffectInstance> map = new Reference2ObjectOpenHashMap<>();

return map;
for (var entry : combination) {
map.put(entry.effect, new StatusEffectInstance(entry.effect, 0, assumeLowestAmplifier ? 0 : entry.amplifier - 1));
}

return map;
}
}
return null;
});
if (match != null) container.statusEffects.putAll(match);
else NULL_COLORS.add(cacheKey);
}
return null;
}

@EventHandler
Expand Down

0 comments on commit 3776a5f

Please sign in to comment.