Skip to content

Commit

Permalink
Move stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen1212055 committed Dec 29, 2024
1 parent 2754c27 commit 96734a2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,75 +373,20 @@ public class Obfuscation extends ConfigurationPart {
public Items items = new Items();

public class Items extends ConfigurationPart {
public static Set<DataComponentType<?>> BASE_OVERRIDERS = Set.of(
DataComponents.MAX_STACK_SIZE,
DataComponents.MAX_DAMAGE,
DataComponents.DAMAGE,
DataComponents.UNBREAKABLE,
DataComponents.CUSTOM_NAME,
DataComponents.ITEM_NAME,
DataComponents.LORE,
DataComponents.RARITY,
DataComponents.ENCHANTMENTS,
DataComponents.CAN_PLACE_ON,
DataComponents.CAN_BREAK,
DataComponents.ATTRIBUTE_MODIFIERS,
DataComponents.HIDE_ADDITIONAL_TOOLTIP,
DataComponents.HIDE_TOOLTIP,
DataComponents.REPAIR_COST,
DataComponents.USE_REMAINDER,
DataComponents.FOOD,
DataComponents.DAMAGE_RESISTANT, // Not important on the player
DataComponents.TOOL,
DataComponents.ENCHANTABLE,
DataComponents.REPAIRABLE,
DataComponents.GLIDER,
DataComponents.TOOLTIP_STYLE,
DataComponents.DEATH_PROTECTION,
DataComponents.STORED_ENCHANTMENTS,
DataComponents.MAP_ID,
DataComponents.POTION_CONTENTS,
DataComponents.SUSPICIOUS_STEW_EFFECTS,
DataComponents.WRITABLE_BOOK_CONTENT,
DataComponents.WRITTEN_BOOK_CONTENT,
DataComponents.CUSTOM_DATA,
DataComponents.ENTITY_DATA,
DataComponents.BUCKET_ENTITY_DATA,
DataComponents.BLOCK_ENTITY_DATA,
DataComponents.INSTRUMENT,
DataComponents.OMINOUS_BOTTLE_AMPLIFIER,
DataComponents.JUKEBOX_PLAYABLE,
DataComponents.LODESTONE_TRACKER,
DataComponents.FIREWORKS,
DataComponents.NOTE_BLOCK_SOUND,
DataComponents.BEES,
DataComponents.LOCK,
DataComponents.CONTAINER_LOOT
);

public boolean enableItemObfuscation = false;
public AssetObfuscationConfiguration allModels = new AssetObfuscationConfiguration(true,
public DataSanitizationUtil.AssetObfuscationConfiguration allModels = new DataSanitizationUtil.AssetObfuscationConfiguration(true,
Set.of(DataComponents.LODESTONE_TRACKER),
Set.of()
);

public Map<String, AssetObfuscationConfiguration> modelOverrides = Map.of(
net.minecraft.world.item.Items.ELYTRA.components().get(DataComponents.ITEM_MODEL).toString(), new AssetObfuscationConfiguration(true,
public Map<String, DataSanitizationUtil.AssetObfuscationConfiguration> modelOverrides = Map.of(
net.minecraft.world.item.Items.ELYTRA.components().get(DataComponents.ITEM_MODEL).toString(), new DataSanitizationUtil.AssetObfuscationConfiguration(true,
Set.of(DataComponents.DAMAGE),
Set.of()
)
);

@ConfigSerializable
public record AssetObfuscationConfiguration(@Required boolean sanitizeCount, Set<DataComponentType<?>> dontObfuscate, Set<DataComponentType<?>> alsoObfuscate) {
public AssetObfuscationConfiguration(final boolean sanitizeCount, final @Nullable Set<DataComponentType<?>> dontObfuscate, final @Nullable Set<DataComponentType<?>> alsoObfuscate) {
this.sanitizeCount = sanitizeCount;
this.dontObfuscate = Objects.requireNonNullElse(dontObfuscate, Set.of());
this.alsoObfuscate = Objects.requireNonNullElse(alsoObfuscate, Set.of());
}

}

@PostProcess
public void computeOverridenTypes() {
DataSanitizationUtil.compute(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import com.google.common.base.Preconditions;
import io.papermc.paper.configuration.GlobalConfiguration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.UnaryOperator;
Expand All @@ -18,12 +13,60 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.spongepowered.configurate.objectmapping.*;
import org.spongepowered.configurate.objectmapping.meta.*;

@DefaultQualifier(NonNull.class)
public final class DataSanitizationUtil {

static final ThreadLocal<DataSanitizer> DATA_SANITIZER = ThreadLocal.withInitial(DataSanitizer::new);

static Set<DataComponentType<?>> BASE_OVERRIDERS = Set.of(
DataComponents.MAX_STACK_SIZE,
DataComponents.MAX_DAMAGE,
DataComponents.DAMAGE,
DataComponents.UNBREAKABLE,
DataComponents.CUSTOM_NAME,
DataComponents.ITEM_NAME,
DataComponents.LORE,
DataComponents.RARITY,
DataComponents.ENCHANTMENTS,
DataComponents.CAN_PLACE_ON,
DataComponents.CAN_BREAK,
DataComponents.ATTRIBUTE_MODIFIERS,
DataComponents.HIDE_ADDITIONAL_TOOLTIP,
DataComponents.HIDE_TOOLTIP,
DataComponents.REPAIR_COST,
DataComponents.USE_REMAINDER,
DataComponents.FOOD,
DataComponents.DAMAGE_RESISTANT, // Not important on the player
DataComponents.TOOL,
DataComponents.ENCHANTABLE,
DataComponents.REPAIRABLE,
DataComponents.GLIDER,
DataComponents.TOOLTIP_STYLE,
DataComponents.DEATH_PROTECTION,
DataComponents.STORED_ENCHANTMENTS,
DataComponents.MAP_ID,
DataComponents.POTION_CONTENTS,
DataComponents.SUSPICIOUS_STEW_EFFECTS,
DataComponents.WRITABLE_BOOK_CONTENT,
DataComponents.WRITTEN_BOOK_CONTENT,
DataComponents.CUSTOM_DATA,
DataComponents.ENTITY_DATA,
DataComponents.BUCKET_ENTITY_DATA,
DataComponents.BLOCK_ENTITY_DATA,
DataComponents.INSTRUMENT,
DataComponents.OMINOUS_BOTTLE_AMPLIFIER,
DataComponents.JUKEBOX_PLAYABLE,
DataComponents.LODESTONE_TRACKER,
DataComponents.FIREWORKS,
DataComponents.NOTE_BLOCK_SOUND,
DataComponents.BEES,
DataComponents.LOCK,
DataComponents.CONTAINER_LOOT
);

static BoundObfuscationConfiguration BOUND_BASE = null;
static Map<ResourceLocation, BoundObfuscationConfiguration> BOUND_OVERRIDES = new HashMap<>();
// We need to have a special ignore item to indicate this item should not be obfuscated.
Expand All @@ -33,7 +76,7 @@ public final class DataSanitizationUtil {
public static void compute(GlobalConfiguration.Anticheat.Obfuscation.Items items) {
// now bind them all
BOUND_BASE = bind(items.allModels);
for (Map.Entry<String, GlobalConfiguration.Anticheat.Obfuscation.Items.AssetObfuscationConfiguration> entry : items.modelOverrides.entrySet()) {
for (Map.Entry<String, AssetObfuscationConfiguration> entry : items.modelOverrides.entrySet()) {
BOUND_OVERRIDES.put(ResourceLocation.parse(entry.getKey()), bind(entry.getValue()));
}
BOUND_OVERRIDES.put(IGNORE_OBFUSCATION_ITEM, new BoundObfuscationConfiguration(false, Map.of()));
Expand Down Expand Up @@ -63,8 +106,13 @@ record Sanitize(UnaryOperator sanitizer) implements MutationType {
}
}

public static BoundObfuscationConfiguration bind(GlobalConfiguration.Anticheat.Obfuscation.Items.AssetObfuscationConfiguration config) {
Set<DataComponentType<?>> base = new HashSet<>(GlobalConfiguration.Anticheat.Obfuscation.Items.BASE_OVERRIDERS);
@org.spongepowered.configurate.objectmapping.ConfigSerializable
public record AssetObfuscationConfiguration(@Required boolean sanitizeCount, Set<DataComponentType<?>> dontObfuscate, Set<DataComponentType<?>> alsoObfuscate) {

}

public static BoundObfuscationConfiguration bind(AssetObfuscationConfiguration config) {
Set<DataComponentType<?>> base = new HashSet<>(BASE_OVERRIDERS);
base.addAll(config.alsoObfuscate());
base.removeAll(config.dontObfuscate());

Expand Down

0 comments on commit 96734a2

Please sign in to comment.