Skip to content

Commit

Permalink
Fix Primitive Crafting exploit
Browse files Browse the repository at this point in the history
  • Loading branch information
LXGaming committed Jul 7, 2020
1 parent bf3379c commit f8124fb
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ targetCompatibility = 1.8

group = "io.github.lxgaming"
archivesBaseName = "Sledgehammer"
version = "1.12.2-2.0.5"
version = "1.12.2-2.0.6"

minecraft {
version = "1.12.2-14.23.5.2838"
Expand Down Expand Up @@ -128,6 +128,7 @@ dependencies {
}
provided("natures-aura:NaturesAura:26.0")
provided("primalcore:PrimalCore:1.12.2:0.6.105")
provided("primitive-crafting:PrimitiveCrafting:1.12.2:1.4.0")
provided("primitive-mobs:primitivemobs:1.2.3a")
provided("pyrotech:pyrotech:1.12.2:1.3.13")
provided("quark:Quark:r1.5:145")
Expand Down Expand Up @@ -177,6 +178,7 @@ jar {
+ "mixins.sledgehammer.morph.json,"
+ "mixins.sledgehammer.naturesaura.json,"
+ "mixins.sledgehammer.platform.json,"
+ "mixins.sledgehammer.primitivecrafting.json,"
+ "mixins.sledgehammer.primitivemobs.json,"
+ "mixins.sledgehammer.projectred.json,"
+ "mixins.sledgehammer.pyrotech.json,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.github.lxgaming.sledgehammer.configuration.category.mixin.MatterOverdriveMixinCategory;
import io.github.lxgaming.sledgehammer.configuration.category.mixin.MorphMixinCategory;
import io.github.lxgaming.sledgehammer.configuration.category.mixin.NaturesAuraMixinCategory;
import io.github.lxgaming.sledgehammer.configuration.category.mixin.PrimitiveCraftingMixinCategory;
import io.github.lxgaming.sledgehammer.configuration.category.mixin.PrimitiveMobsMixinCategory;
import io.github.lxgaming.sledgehammer.configuration.category.mixin.ProjectRedMixinCategory;
import io.github.lxgaming.sledgehammer.configuration.category.mixin.PyrotechMixinCategory;
Expand Down Expand Up @@ -108,6 +109,9 @@ public class MixinCategory {
@Setting(value = "naturesaura", comment = "Nature's Aura")
private NaturesAuraMixinCategory naturesAuraMixinCategory = new NaturesAuraMixinCategory();

@Setting(value = "primitivecrafting", comment = "Primitive Crafting")
private PrimitiveCraftingMixinCategory primitiveCraftingMixinCategory = new PrimitiveCraftingMixinCategory();

@Setting(value = "primitive-mobs", comment = "Primitive Mobs")
private PrimitiveMobsMixinCategory primitiveMobsMixinCategory = new PrimitiveMobsMixinCategory();

Expand Down Expand Up @@ -222,6 +226,10 @@ public NaturesAuraMixinCategory getNaturesAuraMixinCategory() {
return naturesAuraMixinCategory;
}

public PrimitiveCraftingMixinCategory getPrimitiveCraftingMixinCategory() {
return primitiveCraftingMixinCategory;
}

public PrimitiveMobsMixinCategory getPrimitiveMobsMixinCategory() {
return primitiveMobsMixinCategory;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2020 Alex Thomson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.lxgaming.sledgehammer.configuration.category.mixin;

import io.github.lxgaming.sledgehammer.configuration.annotation.Mapping;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;

@ConfigSerializable
public class PrimitiveCraftingMixinCategory {

@Mapping(value = "primitivecrafting.common.crafting.PrimitiveRecipeMixin", dependencies = {"primitivecrafting"})
@Mapping(value = "primitivecrafting.network.AddItemMixin", dependencies = {"primitivecrafting"})
@Setting(value = "packet-exploit", comment = "If 'true', fixes item spawn packet exploit.")
private boolean packetExploit = false;

public boolean isPacketExploit() {
return packetExploit;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 Alex Thomson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.lxgaming.sledgehammer.mixin.primitivecrafting.common.crafting;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import tschipp.primitivecrafting.common.crafting.PrimitiveRecipe;

@Mixin(value = PrimitiveRecipe.class, remap = false)
public abstract class PrimitiveRecipeMixin {

/**
* @author LX_Gaming
* @reason Re-implement Logic.
*/
@Overwrite
public static void addItem(EntityPlayer player, ItemStack stack) {
if (player != null && !player.world.isRemote) {
if (!player.inventory.addItemStackToInventory(stack)) {
player.dropItem(stack, false);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2020 Alex Thomson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.lxgaming.sledgehammer.mixin.primitivecrafting.network;

import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import tschipp.primitivecrafting.network.AddItem;

@Mixin(value = AddItem.class, remap = false)
public abstract class AddItemMixin {

/**
* Woop-woop! That's the sound of da police! That's the sound of the beast!
*/
@Inject(
method = "onMessage",
at = @At(
value = "HEAD"
),
cancellable = true
)
private void onMessage(AddItem message, MessageContext ctx, CallbackInfoReturnable<IMessage> callbackInfoReturnable) {
callbackInfoReturnable.setReturnValue(null);
}
}
16 changes: 16 additions & 0 deletions src/main/resources/mixins.sledgehammer.primitivecrafting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"required": false,
"minVersion": "0.7.10",
"package": "io.github.lxgaming.sledgehammer.mixin.primitivecrafting",
"refmap": "mixins.sledgehammer.refmap.json",
"plugin": "io.github.lxgaming.sledgehammer.mixin.plugin.CorePlugin",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"mixins": [
"common.crafting.PrimitiveRecipeMixin",
"network.AddItemMixin"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit f8124fb

Please sign in to comment.