From fd5cc7c3231f93abe7843e9b0f0791ab9d9a34df Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:17:15 -0800 Subject: [PATCH] Vengeance Spirit Regex Cache --- README.md | 2 + dependencies.gradle | 2 + gradle.properties | 1 + .../universaltweaks/config/UTConfigMods.java | 12 +++++ .../universaltweaks/core/UTMixinLoader.java | 1 + .../mixin/UTVengeanceSpiritMixin.java | 54 +++++++++++++++++++ .../assets/universaltweaks/lang/en_us.lang | 1 + ...mixins.mods.evilcraft.vengeancespirit.json | 7 +++ 8 files changed, 80 insertions(+) create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/evilcraft/vengeancespirit/mixin/UTVengeanceSpiritMixin.java create mode 100644 src/main/resources/mixins.mods.evilcraft.vengeancespirit.json diff --git a/README.md b/README.md index d4da6cbc..f7098d67 100644 --- a/README.md +++ b/README.md @@ -429,6 +429,8 @@ All changes are toggleable via config files. * **Fix Cabbage Drop:** Fixes Cabbage not dropping the correct items in some situations * **Preserved Blocks Fix:** Prevents HWYLA/TOP crashes with preserved blocks * **Fix Quake Hammer Texture:** Fixes the Quake Hammer using the incorrect config option to control its size +* **EvilCraft** + * **Vengeance Spirit Regex Cache:** Cache the result of Vengeance Spirit checks against the config, which may attempt to build and check against hundreds of Regex Patterns every tick * **The Farlanders** * **Duplication Fixes:** Fixes various duplication exploits * **Thermal Expansion** diff --git a/dependencies.gradle b/dependencies.gradle index 73416639..008bd942 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -79,12 +79,14 @@ final def mod_dependencies = [ 'curse.maven:compactmachines-224218:2707509' : [debug_compact_machines], 'curse.maven:cqrepoured-303422:3953103' : [debug_cqrepoured], 'curse.maven:ctm-267602:2915363' : [debug_chisel], + 'curse.maven:cyclops-core-232758:3159497' : [debug_evilcraft], 'curse.maven:effortlessbuilding-302113:2847346' : [debug_effortless_building], 'curse.maven:elementary-staffs-346007:2995593' : [debug_elementary_staffs], 'curse.maven:elenaidodge2-442962:3343308' : [debug_elenai_dodge_2], 'curse.maven:emojicord-349107:4000684' : [debug_emojicord], 'curse.maven:enderstorage-245174:2755787' : [debug_enderstorage], 'curse.maven:epic-siege-mod-229449:3356157' : [debug_epic_siege_mod], + 'curse.maven:evilcraft-74610:2811267' : [debug_evilcraft], 'curse.maven:extrautilities-225561:2678374' : [debug_extra_utilities_2], 'curse.maven:forestry-59751:2918418' : [debug_forestry, debug_binnies_mods], 'curse.maven:forgemultipartcbe-258426:2755790' : [debug_forgemultipartcbe, debug_project_red], diff --git a/gradle.properties b/gradle.properties index d5747f7b..0f63ee83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,6 +30,7 @@ debug_enderio = false debug_enderstorage = false debug_epic_siege_mod = false debug_erebus = false +debug_evilcraft = false debug_extra_utilities_2 = false debug_forestry = false debug_forgemultipartcbe = false diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java index b0319a35..5f5e84a4 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java @@ -111,6 +111,10 @@ public class UTConfigMods @Config.Name("The Erebus") public static final ErebusCategory EREBUS = new ErebusCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.evilcraft") + @Config.Name("EvilCraft") + public static final EvilCraftCategory EVIL_CRAFT = new EvilCraftCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.extrautilities") @Config.Name("Extra Utilities 2") public static final ExtraUtilitiesCategory EXTRA_UTILITIES = new ExtraUtilitiesCategory(); @@ -562,6 +566,14 @@ public static class ErebusCategory public boolean utFixQuakeHammerTexture = true; } + public static class EvilCraftCategory + { + @Config.RequiresMcRestart + @Config.Name("Vengeance Spirit Regex Cache") + @Config.Comment("Cache the result of Vengeance Spirit checks against the config, which may attempt to build and check against hundreds of Regex Patterns every tick") + public boolean utVengeanceSpiritCache = true; + } + public static class ExtraUtilitiesCategory { @Config.RequiresMcRestart diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java index 9258feb2..bd274b1b 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java @@ -66,6 +66,7 @@ public class UTMixinLoader implements ILateMixinLoader put("mixins.mods.erebus.cabbage.json", () -> loaded("erebus") && UTConfigMods.EREBUS.utCabbageDrop); put("mixins.mods.erebus.json", () -> loaded("erebus")); put("mixins.mods.erebus.quakehammer.json", () -> loaded("erebus") && UTConfigMods.EREBUS.utFixQuakeHammerTexture); + put("mixins.mods.evilcraft.vengeancespirit.json", () -> loaded("evilcraft") && UTConfigMods.EVIL_CRAFT.utVengeanceSpiritCache); put("mixins.mods.extrautilities.breakcreativemill.json", () -> loaded("extrautils2") && UTConfigMods.EXTRA_UTILITIES.utFixCreativeMillHarvestability); put("mixins.mods.extrautilities.deepdarkstats.json", () -> loaded("extrautils2") && UTConfigMods.EXTRA_UTILITIES.utDeepDarkStats); put("mixins.mods.extrautilities.dupes.json", () -> loaded("extrautils2") && UTConfigMods.EXTRA_UTILITIES.utDuplicationFixesToggle); diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/evilcraft/vengeancespirit/mixin/UTVengeanceSpiritMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/evilcraft/vengeancespirit/mixin/UTVengeanceSpiritMixin.java new file mode 100644 index 00000000..a97063ba --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/evilcraft/vengeancespirit/mixin/UTVengeanceSpiritMixin.java @@ -0,0 +1,54 @@ +package mod.acgaming.universaltweaks.mods.evilcraft.vengeancespirit.mixin; + +import net.minecraft.util.ResourceLocation; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.sugar.Local; +import it.unimi.dsi.fastutil.objects.Object2BooleanMap; +import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; +import org.cyclops.evilcraft.entity.monster.VengeanceSpirit; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +// Courtesy of WaitingIdly +@Mixin(value = VengeanceSpirit.class, remap = false) +public class UTVengeanceSpiritMixin +{ + @Unique + private static final Object2BooleanMap REGEX_CACHE_MAP = new Object2BooleanOpenHashMap<>(); + + /** + * @author WaitingIdly + * @reason check if the ResourceLocation for the target entity is cached, and use it if so + */ + @Inject(method = {"canSustain", "canSustainClass"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ResourceLocation;toString()Ljava/lang/String;", remap = true), cancellable = true) + private static void utUseCache(CallbackInfoReturnable cir, @Local ResourceLocation id) + { + if (REGEX_CACHE_MAP.containsKey(id)) cir.setReturnValue(REGEX_CACHE_MAP.getBoolean(id)); + } + + /** + * @author WaitingIdly + * @reason cache the return result + */ + @ModifyReturnValue(method = {"canSustain", "canSustainClass"}, at = @At("RETURN")) + private static boolean utStoreReturnValue(boolean original, @Local ResourceLocation id) + { + REGEX_CACHE_MAP.put(id, original); + return original; + } + + /** + * @author WaitingIdly + * @reason clear the cache when reloading the blacklist + */ + @Inject(method = "setBlacklist", at = @At("HEAD")) + private static void utClearCache(CallbackInfo ci) + { + REGEX_CACHE_MAP.clear(); + } +} diff --git a/src/main/resources/assets/universaltweaks/lang/en_us.lang b/src/main/resources/assets/universaltweaks/lang/en_us.lang index 35fae7de..227f5b09 100644 --- a/src/main/resources/assets/universaltweaks/lang/en_us.lang +++ b/src/main/resources/assets/universaltweaks/lang/en_us.lang @@ -73,6 +73,7 @@ cfg.universaltweaks.modintegration.emojicord=Emojicord cfg.universaltweaks.modintegration.enderio=Ender IO cfg.universaltweaks.modintegration.enderstorage=Ender Storage cfg.universaltweaks.modintegration.erebus=The Erebus +cfg.universaltweaks.modintegration.evilcraft=EvilCraft cfg.universaltweaks.modintegration.esm=Epic Siege Mod cfg.universaltweaks.modintegration.extrautilities=Extra Utilities 2 cfg.universaltweaks.modintegration.forestry=Forestry diff --git a/src/main/resources/mixins.mods.evilcraft.vengeancespirit.json b/src/main/resources/mixins.mods.evilcraft.vengeancespirit.json new file mode 100644 index 00000000..77760178 --- /dev/null +++ b/src/main/resources/mixins.mods.evilcraft.vengeancespirit.json @@ -0,0 +1,7 @@ +{ + "package": "mod.acgaming.universaltweaks.mods.evilcraft.vengeancespirit.mixin", + "refmap": "universaltweaks.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": ["UTVengeanceSpiritMixin"] +}