From 5deb7d495ffdca8698afcca897144b4859f586a3 Mon Sep 17 00:00:00 2001 From: mstoppelli Date: Sat, 22 Dec 2018 12:59:55 -0500 Subject: [PATCH] Testing Bdew's title injector, might work better now that EnumExtend seems to be broken --- .../actions/items/StableContractAction.java | 4 + .../mod/sin/wyvern/AchievementChanges.java | 5 +- .../java/mod/sin/wyvern/CombatChanges.java | 21 +- src/main/java/mod/sin/wyvern/ItemMod.java | 1 + src/main/java/mod/sin/wyvern/MiscChanges.java | 299 +++++++++--------- src/main/java/mod/sin/wyvern/WyvernMods.java | 4 +- .../bonusoverhaul/ItemBonusOverhaul.java | 2 +- .../mod/sin/wyvern/bounty/PlayerBounty.java | 2 + .../wyvern/mastercraft/AchievementTitles.java | 14 + .../sin/wyvern/mastercraft/BytecodeTools.java | 67 ++++ .../sin/wyvern/mastercraft/Mastercraft.java | 3 +- .../sin/wyvern/mastercraft/TitleInjector.java | 96 ++++++ 12 files changed, 365 insertions(+), 153 deletions(-) create mode 100644 src/main/java/mod/sin/wyvern/mastercraft/AchievementTitles.java create mode 100644 src/main/java/mod/sin/wyvern/mastercraft/TitleInjector.java diff --git a/src/main/java/mod/sin/actions/items/StableContractAction.java b/src/main/java/mod/sin/actions/items/StableContractAction.java index a02d85f..e46ea77 100644 --- a/src/main/java/mod/sin/actions/items/StableContractAction.java +++ b/src/main/java/mod/sin/actions/items/StableContractAction.java @@ -66,6 +66,10 @@ public class StableContractAction implements ModAction, BehaviourProvider, Actio performer.getCommunicator().sendNormalServerMessage("You cannot summon the stable master right now!"); return true; } + if(performer.getCurrentVillage() == null) { + performer.getCommunicator().sendNormalServerMessage("You must be part of a settlement to summon a stablemaster."); + return true; + } if(counter == 1.0f) { performer.getCommunicator().sendNormalServerMessage("You begin reading the contract..."); final int time = 5; diff --git a/src/main/java/mod/sin/wyvern/AchievementChanges.java b/src/main/java/mod/sin/wyvern/AchievementChanges.java index d10414d..ee9ae52 100644 --- a/src/main/java/mod/sin/wyvern/AchievementChanges.java +++ b/src/main/java/mod/sin/wyvern/AchievementChanges.java @@ -313,8 +313,9 @@ public class AchievementChanges { public static Titles.Title getAwardedTitle(Achievement a) { int count = a.getCounter(); if(a.getTemplate() == gremlinSlayer) { + logger.info("Achievement at " + count); if(count >= 100) { - return Titles.Title.getTitle(Mastercraft.GremlinSlayer); + return Titles.Title.getTitle(704); } } return null; @@ -325,8 +326,10 @@ public class AchievementChanges { Achievements achievments = Achievements.getAchievementObject(player.getWurmId()); Achievement achievment = achievments.getAchievement(tpl.getNumber()); if (achievment != null) { + logger.info("Achievemtn found"); Titles.Title title = getAwardedTitle(achievment); if (title != null) { + logger.info("Adding title"); player.addTitle(title); } } diff --git a/src/main/java/mod/sin/wyvern/CombatChanges.java b/src/main/java/mod/sin/wyvern/CombatChanges.java index 23fca28..34d4bb4 100644 --- a/src/main/java/mod/sin/wyvern/CombatChanges.java +++ b/src/main/java/mod/sin/wyvern/CombatChanges.java @@ -334,6 +334,26 @@ public class CombatChanges { replace = "$_ = true;"; Util.instrumentDescribed(thisClass, ctCombatHandler, "getDamage", desc2, "isThisAnEpicOrChallengeServer", replace); + CtClass ctAttackAction = classPool.get("com.wurmonline.server.creatures.AttackAction"); + CtClass[] paramsWoa1 = { + ctAttackAction, + ctItem + }; + CtClass[] paramsWoa2 = { + ctItem + }; + String descWoa1 = Descriptor.ofMethod(CtClass.floatType, paramsWoa1); + String descWoa2 = Descriptor.ofMethod(CtClass.floatType, paramsWoa2); + Util.setReason("Adjust WoA effect on weapons to be more noticeable"); + replace = "$_ = $proceed($$) * 2;"; + Util.instrumentDescribedCount(thisClass, ctCombatHandler, "getSpeed", descWoa1,"getSpellSpeedBonus", 2, replace); + Util.instrumentDescribedCount(thisClass, ctCombatHandler, "getSpeed", descWoa2,"getSpellSpeedBonus", 2, replace); + + Util.setReason("Adjust bloodthirst cap up to 17k from 10k"); + replace = "$1 = 17000;" + + "$_ = $proceed($$);"; + Util.instrumentDeclaredCount(thisClass, ctCombatHandler, "setDamage", "min", 5, replace); + Util.setReason("Fix magranon damage bonus stacking."); replace = "if(mildStack){" + " $_ = $proceed($$) * 8 / 5;" + @@ -343,7 +363,6 @@ public class CombatChanges { Util.instrumentDescribed(thisClass, ctCombatHandler, "getDamage", desc2, "getModifiedFloatEffect", replace); Util.setReason("Adjust bloodthirst to epic settings."); - CtClass ctAttackAction = classPool.get("com.wurmonline.server.creatures.AttackAction"); CtClass[] params3 = { ctCreature, ctAttackAction, diff --git a/src/main/java/mod/sin/wyvern/ItemMod.java b/src/main/java/mod/sin/wyvern/ItemMod.java index f86acde..7890dbc 100644 --- a/src/main/java/mod/sin/wyvern/ItemMod.java +++ b/src/main/java/mod/sin/wyvern/ItemMod.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.logging.Logger; import com.wurmonline.server.Servers; +import com.wurmonline.server.combat.ArmourTemplate; import mod.sin.actions.items.magicitems.MagicItemMenuProvider; import mod.sin.actions.items.magicitems.MagicItemRechargeAction; import mod.sin.items.schematicitems.SchematicItems; diff --git a/src/main/java/mod/sin/wyvern/MiscChanges.java b/src/main/java/mod/sin/wyvern/MiscChanges.java index 13338da..da13934 100644 --- a/src/main/java/mod/sin/wyvern/MiscChanges.java +++ b/src/main/java/mod/sin/wyvern/MiscChanges.java @@ -284,9 +284,7 @@ public class MiscChanges { // Sleep powder added toRestock.add(new TraderItem(ItemList.sleepPowder, 99, false, 99, 99, 20)); logger.info("Adding sleep powder to trader restock list"); - // Kingdom tokens added - toRestock.add(new TraderItem(ItemCreator.KINGDOM_TOKEN.getTemplateId(), 99, false, 99, 99, 20)); - logger.info("Adding kingdom tokens to trader restock list"); + // Kingdom tokens Removed // Sealed maps added, use ranom qualities between 10 and 100 (inclusive) toRestock.add(new TraderItem(SealedMap.templateId, 99, true, 10, 101, 3)); logger.info("Adding sealed maps to trader restock list"); @@ -400,14 +398,14 @@ public class MiscChanges { } public static void preInit(){ - try{ - ClassPool classPool = HookManager.getInstance().getClassPool(); - final Class thisClass = MiscChanges.class; - String replace; + try { + ClassPool classPool = HookManager.getInstance().getClassPool(); + final Class thisClass = MiscChanges.class; + String replace; - // - Create Server tab with initial messages - // + // - Create Server tab with initial messages - // CtClass ctVehicle = classPool.get("com.wurmonline.server.behaviours.Vehicle"); - CtClass ctPlayers = classPool.get("com.wurmonline.server.Players"); + CtClass ctPlayers = classPool.get("com.wurmonline.server.Players"); CtMethod m = ctPlayers.getDeclaredMethod("sendStartGlobalKingdomChat"); String infoTabTitle = "Server"; // Initial messages: @@ -432,13 +430,13 @@ public class MiscChanges { // - Disable mailboxes from being used while loaded - // CtClass ctItem = classPool.get("com.wurmonline.server.items.Item"); replace = "$_ = $proceed($$);" - + "com.wurmonline.server.items.Item theTarget = com.wurmonline.server.Items.getItem(targetId);" - + "if(theTarget != null && theTarget.getTemplateId() >= 510 && theTarget.getTemplateId() <= 513){" - + " if(theTarget.getTopParent() != theTarget.getWurmId()){" - + " mover.getCommunicator().sendNormalServerMessage(\"Mailboxes cannot be used while loaded.\");" - + " return false;" - + " }" - + "}"; + + "com.wurmonline.server.items.Item theTarget = com.wurmonline.server.Items.getItem(targetId);" + + "if(theTarget != null && theTarget.getTemplateId() >= 510 && theTarget.getTemplateId() <= 513){" + + " if(theTarget.getTopParent() != theTarget.getWurmId()){" + + " mover.getCommunicator().sendNormalServerMessage(\"Mailboxes cannot be used while loaded.\");" + + " return false;" + + " }" + + "}"; Util.instrumentDeclared(thisClass, ctItem, "moveToItem", "getOwnerId", replace); // - Enable creature custom colors - (Used for creating custom color creatures eg. Lilith) - // @@ -449,10 +447,10 @@ public class MiscChanges { // - Increase the amount of checks for new unique spawns by 5x - // CtClass ctServer = classPool.get("com.wurmonline.server.Server"); replace = "for(int i = 0; i < 5; i++){" - + " $_ = $proceed($$);" - + "}"; + + " $_ = $proceed($$);" + + "}"; Util.instrumentDeclared(thisClass, ctServer, "run", "checkDens", replace); - + // - Add Facebreyker to the list of spawnable uniques - // CtClass ctDens = classPool.get("com.wurmonline.server.zones.Dens"); replace = "com.wurmonline.server.zones.Dens.checkTemplate(2147483643, whileRunning);"; @@ -462,31 +460,31 @@ public class MiscChanges { // - Announce player titles in the Server tab - // CtClass ctPlayer = classPool.get("com.wurmonline.server.players.Player"); replace = "$_ = $proceed($$);" - + "if(!com.wurmonline.server.Servers.localServer.PVPSERVER && this.getPower() < 1){" - + " "+MiscChanges.class.getName()+".sendServerTabMessage(\"event\", this.getName()+\" just earned the title of \"+title.getName(this.isNotFemale())+\"!\", 200, 100, 0);" - + "}"; + + "if(!com.wurmonline.server.Servers.localServer.PVPSERVER && this.getPower() < 1){" + + " " + MiscChanges.class.getName() + ".sendServerTabMessage(\"event\", this.getName()+\" just earned the title of \"+title.getName(this.isNotFemale())+\"!\", 200, 100, 0);" + + "}"; Util.instrumentDeclared(thisClass, ctPlayer, "addTitle", "sendNormalServerMessage", replace); // - Make leather not suck even after it's able to be combined. - // CtClass ctMethodsItems = classPool.get("com.wurmonline.server.behaviours.MethodsItems"); replace = "if(com.wurmonline.server.behaviours.MethodsItems.getImproveTemplateId(target) != 72){" - + " $_ = $proceed($$);" - + "}else{" - + " $_ = false;" - + "}"; + + " $_ = $proceed($$);" + + "}else{" + + " $_ = false;" + + "}"; Util.instrumentDeclared(thisClass, ctMethodsItems, "improveItem", "isCombine", replace); - + // - Check new improve materials - // - replace = "int temp = "+ItemMod.class.getName()+".getModdedImproveTemplateId($1);" - + "if(temp != -10){" - + " return temp;" - + "}"; + replace = "int temp = " + ItemMod.class.getName() + ".getModdedImproveTemplateId($1);" + + "if(temp != -10){" + + " return temp;" + + "}"; Util.insertBeforeDeclared(thisClass, ctMethodsItems, "getImproveTemplateId", replace); - + // - Remove fatiguing actions requiring you to be on the ground - // CtClass ctAction = classPool.get("com.wurmonline.server.behaviours.Action"); CtConstructor[] ctActionConstructors = ctAction.getConstructors(); - for(CtConstructor constructor : ctActionConstructors) { + for (CtConstructor constructor : ctActionConstructors) { constructor.instrument(new ExprEditor() { public void edit(MethodCall m) throws CannotCompileException { if (m.getMethodName().equals("isFatigue")) { @@ -505,7 +503,7 @@ public class MiscChanges { } }); } - + Util.setReason("Fix Portal Issues."); CtClass ctPortal = classPool.get("com.wurmonline.server.questions.PortalQuestion"); Util.instrumentDeclared(thisClass, ctPortal, "sendQuestion", "willLeaveServer", "$_ = true;"); @@ -513,46 +511,46 @@ public class MiscChanges { Util.instrumentDeclared(thisClass, ctPortal, "sendQuestion", "getKnowledge", "$_ = true;"); Util.setReason("Disable the minimum 0.01 damage on shield damage, allowing damage modifiers to rule."); - CtClass ctCombatHandler = classPool.get("com.wurmonline.server.creatures.CombatHandler"); - replace = "if($1 < 0.5f){" - + " $_ = $proceed((float) 0, (float) $2);" - + "}else{" - + " $_ = $proceed($$);" - + "}"; - Util.instrumentDeclared(thisClass, ctCombatHandler, "checkShield", "max", replace); + CtClass ctCombatHandler = classPool.get("com.wurmonline.server.creatures.CombatHandler"); + replace = "if($1 < 0.5f){" + + " $_ = $proceed((float) 0, (float) $2);" + + "}else{" + + " $_ = $proceed($$);" + + "}"; + Util.instrumentDeclared(thisClass, ctCombatHandler, "checkShield", "max", replace); - // - Allow GM's to bypass the 5 second emote sound limit. - // - replace = "if(this.getPower() > 0){" - + " return true;" - + "}"; - Util.insertBeforeDeclared(thisClass, ctPlayer, "mayEmote", replace); + // - Allow GM's to bypass the 5 second emote sound limit. - // + replace = "if(this.getPower() > 0){" + + " return true;" + + "}"; + Util.insertBeforeDeclared(thisClass, ctPlayer, "mayEmote", replace); - // - Make creatures wander slightly if they are shot from afar by an arrow - // - CtClass ctArrows = classPool.get("com.wurmonline.server.combat.Arrows"); - replace = "if(!defender.isPathing()){" - + " defender.startPathing(com.wurmonline.server.Server.rand.nextInt(100));" - + "}" - + "$_ = $proceed($$);"; - Util.instrumentDeclared(thisClass, ctArrows, "addToHitCreature", "addAttacker", replace); + // - Make creatures wander slightly if they are shot from afar by an arrow - // + CtClass ctArrows = classPool.get("com.wurmonline.server.combat.Arrows"); + replace = "if(!defender.isPathing()){" + + " defender.startPathing(com.wurmonline.server.Server.rand.nextInt(100));" + + "}" + + "$_ = $proceed($$);"; + Util.instrumentDeclared(thisClass, ctArrows, "addToHitCreature", "addAttacker", replace); - Util.setReason("Broadcast death tabs to GL-Freedom."); - replace = MiscChanges.class.getName()+".broadCastDeaths($1, $2);"; + Util.setReason("Broadcast death tabs to GL-Freedom."); + replace = MiscChanges.class.getName() + ".broadCastDeaths($1, $2);"; Util.insertBeforeDeclared(thisClass, ctPlayers, "broadCastDeathInfo", replace); Util.setReason("Broadcast player death tabs always."); - replace = MiscChanges.class.getName()+".broadCastDeathsPvE($0, $0.attackers);"; + replace = MiscChanges.class.getName() + ".broadCastDeathsPvE($0, $0.attackers);"; Util.insertBeforeDeclared(thisClass, ctPlayer, "modifyRanking", replace); Util.setReason("Disable PvP only death tabs."); replace = "$_ = true;"; Util.instrumentDeclared(thisClass, ctPlayers, "broadCastDeathInfo", "isThisAPvpServer", replace); - Util.setReason("Attempt to prevent libila from losing faith when crossing servers."); + Util.setReason("Attempt to prevent libila from losing faith when crossing servers."); CtClass ctIntraServerConnection = classPool.get("com.wurmonline.server.intra.IntraServerConnection"); ctIntraServerConnection.getDeclaredMethod("savePlayerToDisk").instrument(new ExprEditor() { @Override public void edit(FieldAccess fieldAccess) throws CannotCompileException { - if (Objects.equals("PVPSERVER", fieldAccess.getFieldName())){ + if (Objects.equals("PVPSERVER", fieldAccess.getFieldName())) { fieldAccess.replace("$_ = false;"); logger.info("Instrumented PVPSERVER = false for Libila faith transfers."); } @@ -561,7 +559,7 @@ public class MiscChanges { ctIntraServerConnection.getDeclaredMethod("savePlayerToDisk").instrument(new ExprEditor() { @Override public void edit(FieldAccess fieldAccess) throws CannotCompileException { - if (Objects.equals("HOMESERVER", fieldAccess.getFieldName())){ + if (Objects.equals("HOMESERVER", fieldAccess.getFieldName())) { fieldAccess.replace("$_ = false;"); logger.info("Instrumented HOMESERVER = false for Libila faith transfers."); } @@ -569,60 +567,60 @@ public class MiscChanges { }); Util.setReason("Increase food affinity to give 30% increased skillgain instead of 10%."); - CtClass ctSkill = classPool.get("com.wurmonline.server.skills.Skill"); - CtClass[] params4 = { - CtClass.doubleType, - CtClass.booleanType, - CtClass.floatType, - CtClass.booleanType, - CtClass.doubleType - }; - String desc4 = Descriptor.ofMethod(CtClass.voidType, params4); - replace = "int timedAffinity = (com.wurmonline.server.skills.AffinitiesTimed.isTimedAffinity(pid, this.getNumber()) ? 2 : 0);" - + "advanceMultiplicator *= (double)(1.0f + (float)timedAffinity * 0.1f);" - + "$_ = $proceed($$);"; - Util.instrumentDescribed(thisClass, ctSkill, "alterSkill", desc4, "hasSleepBonus", replace); + CtClass ctSkill = classPool.get("com.wurmonline.server.skills.Skill"); + CtClass[] params4 = { + CtClass.doubleType, + CtClass.booleanType, + CtClass.floatType, + CtClass.booleanType, + CtClass.doubleType + }; + String desc4 = Descriptor.ofMethod(CtClass.voidType, params4); + replace = "int timedAffinity = (com.wurmonline.server.skills.AffinitiesTimed.isTimedAffinity(pid, this.getNumber()) ? 2 : 0);" + + "advanceMultiplicator *= (double)(1.0f + (float)timedAffinity * 0.1f);" + + "$_ = $proceed($$);"; + Util.instrumentDescribed(thisClass, ctSkill, "alterSkill", desc4, "hasSleepBonus", replace); - Util.setReason("Double the rate at which charcoal piles produce items."); - CtClass[] params5 = { - CtClass.booleanType, - CtClass.booleanType, - CtClass.longType - }; - String desc5 = Descriptor.ofMethod(CtClass.booleanType, params5); - replace = "this.createDaleItems();" - + "decayed = this.setDamage(this.damage + 1.0f * this.getDamageModifier());" - + "$_ = $proceed($$);"; - Util.instrumentDescribed(thisClass, ctItem, "poll", desc5, "createDaleItems", replace); + Util.setReason("Double the rate at which charcoal piles produce items."); + CtClass[] params5 = { + CtClass.booleanType, + CtClass.booleanType, + CtClass.longType + }; + String desc5 = Descriptor.ofMethod(CtClass.booleanType, params5); + replace = "this.createDaleItems();" + + "decayed = this.setDamage(this.damage + 1.0f * this.getDamageModifier());" + + "$_ = $proceed($$);"; + Util.instrumentDescribed(thisClass, ctItem, "poll", desc5, "createDaleItems", replace); - Util.setReason("Allow traders to display more than 9 items of a single type."); + Util.setReason("Allow traders to display more than 9 items of a single type."); CtClass ctTradeHandler = classPool.get("com.wurmonline.server.creatures.TradeHandler"); - ctTradeHandler.getDeclaredMethod("addItemsToTrade").instrument(new ExprEditor(){ + ctTradeHandler.getDeclaredMethod("addItemsToTrade").instrument(new ExprEditor() { public void edit(MethodCall m) throws CannotCompileException { - if(m.getMethodName().equals("size") && m.getLineNumber() > 200){ // I don't think the line number check matters, but I'm leaving it here anyway. - m.replace("$_ = 1;"); - logger.info("Instrumented size for trades to allow traders to show more than 9 items at a time."); + if (m.getMethodName().equals("size") && m.getLineNumber() > 200) { // I don't think the line number check matters, but I'm leaving it here anyway. + m.replace("$_ = 1;"); + logger.info("Instrumented size for trades to allow traders to show more than 9 items at a time."); } } }); - // -- Identify players making over 10 commands per second and causing the server log message -- // - CtClass ctCommunicator = classPool.get("com.wurmonline.server.creatures.Communicator"); - replace = "$_ = $proceed($$);" - + "if(this.player != null){" - + " logger.info(\"Potential player macro: \"+this.player.getName()+\" [\"+this.commandsThisSecond+\" commands]\");" - + "}"; - Util.instrumentDeclared(thisClass, ctCommunicator, "reallyHandle_CMD_ITEM_CREATION_LIST", "log", replace); - - //1f+0.5f*(1f-Math.pow(2, -Math.pow((eff-1f), pow1)/pow2)) - Util.setReason("Fix 100+ quality or power making certain interaction broken."); - replace = "{" - + "double pow1 = 1.0;" - + "double pow2 = 3.0;" - + "double newEff = $1 >= 1.0 ? 1.0+0.5*(1.0-Math.pow(2.0, -Math.pow(($1-1.0), pow1)/pow2)) : Math.max(0.05, 1.0 - (1.0 - $1) * (1.0 - $1));" - + "return newEff;" - + "}"; - Util.setBodyDeclared(thisClass, ctServer, "getBuffedQualityEffect", replace); + // -- Identify players making over 10 commands per second and causing the server log message -- // + CtClass ctCommunicator = classPool.get("com.wurmonline.server.creatures.Communicator"); + replace = "$_ = $proceed($$);" + + "if(this.player != null){" + + " logger.info(\"Potential player macro: \"+this.player.getName()+\" [\"+this.commandsThisSecond+\" commands]\");" + + "}"; + Util.instrumentDeclared(thisClass, ctCommunicator, "reallyHandle_CMD_ITEM_CREATION_LIST", "log", replace); + + //1f+0.5f*(1f-Math.pow(2, -Math.pow((eff-1f), pow1)/pow2)) + Util.setReason("Fix 100+ quality or power making certain interaction broken."); + replace = "{" + + "double pow1 = 1.0;" + + "double pow2 = 3.0;" + + "double newEff = $1 >= 1.0 ? 1.0+0.5*(1.0-Math.pow(2.0, -Math.pow(($1-1.0), pow1)/pow2)) : Math.max(0.05, 1.0 - (1.0 - $1) * (1.0 - $1));" + + "return newEff;" + + "}"; + Util.setBodyDeclared(thisClass, ctServer, "getBuffedQualityEffect", replace); // double advanceMultiplicator, boolean decay, float times, boolean useNewSystem, double skillDivider) CtClass[] params = { @@ -642,35 +640,35 @@ public class MiscChanges { "double maxRate = " + String.valueOf(maxRate) + ";" + "double newPower = " + String.valueOf(newPower) + ";" + "$1 = $1*(minRate+(maxRate-minRate)*Math.pow((100-this.knowledge)*0.01, newPower));"; - Util.insertBeforeDescribed(thisClass, ctSkill,"alterSkill", desc, replace); + Util.insertBeforeDescribed(thisClass, ctSkill, "alterSkill", desc, replace); Util.setReason("Reduce chance of lockpicks breaking."); replace = "$_ = 40f + $proceed($$);"; Util.instrumentDeclared(thisClass, ctMethodsItems, "checkLockpickBreakage", "getCurrentQualityLevel", replace); - CtClass ctTileBehaviour = classPool.get("com.wurmonline.server.behaviours.TileBehaviour"); - CtMethod[] ctGetBehavioursFors = ctTileBehaviour.getDeclaredMethods("getBehavioursFor"); - for(CtMethod method : ctGetBehavioursFors){ - method.instrument(new ExprEditor(){ - public void edit(MethodCall m) throws CannotCompileException { - if (m.getMethodName().equals("getKingdomTemplateId")) { - m.replace("$_ = 3;"); - } - } - }); - } + CtClass ctTileBehaviour = classPool.get("com.wurmonline.server.behaviours.TileBehaviour"); + CtMethod[] ctGetBehavioursFors = ctTileBehaviour.getDeclaredMethods("getBehavioursFor"); + for (CtMethod method : ctGetBehavioursFors) { + method.instrument(new ExprEditor() { + public void edit(MethodCall m) throws CannotCompileException { + if (m.getMethodName().equals("getKingdomTemplateId")) { + m.replace("$_ = 3;"); + } + } + }); + } - CtClass ctMethodsStructure = classPool.get("com.wurmonline.server.behaviours.MethodsStructure"); - Util.setReason("Allow players to construct larger houses."); - float carpentryMultiplier = 2f; - replace = "if(!com.wurmonline.server.Servers.localServer.PVPSERVER){" + - " $_ = $proceed($$)*"+String.valueOf(carpentryMultiplier)+";" + - "}else{" + - " $_ = $proceed($$);" + - "}"; - Util.instrumentDeclared(thisClass, ctMethodsStructure, "hasEnoughSkillToExpandStructure", "getKnowledge", replace); - Util.setReason("Allow players to construct larger houses."); - Util.instrumentDeclared(thisClass, ctMethodsStructure, "hasEnoughSkillToContractStructure", "getKnowledge", replace); + CtClass ctMethodsStructure = classPool.get("com.wurmonline.server.behaviours.MethodsStructure"); + Util.setReason("Allow players to construct larger houses."); + float carpentryMultiplier = 2f; + replace = "if(!com.wurmonline.server.Servers.localServer.PVPSERVER){" + + " $_ = $proceed($$)*" + String.valueOf(carpentryMultiplier) + ";" + + "}else{" + + " $_ = $proceed($$);" + + "}"; + Util.instrumentDeclared(thisClass, ctMethodsStructure, "hasEnoughSkillToExpandStructure", "getKnowledge", replace); + Util.setReason("Allow players to construct larger houses."); + Util.instrumentDeclared(thisClass, ctMethodsStructure, "hasEnoughSkillToContractStructure", "getKnowledge", replace); Util.setReason("Reduce power of imbues."); replace = "$_ = Math.max(-80d, -80d+$2);"; @@ -691,7 +689,7 @@ public class MiscChanges { Util.setReason("Remove guard tower guards helping against certain types of enemies."); CtClass ctGuardTower = classPool.get("com.wurmonline.server.kingdom.GuardTower"); - replace = "if($0.isUnique() || "+Titans.class.getName()+".isTitan($0) || "+RareSpawns.class.getName()+".isRareCreature($0)){" + + replace = "if($0.isUnique() || " + Titans.class.getName() + ".isTitan($0) || " + RareSpawns.class.getName() + ".isRareCreature($0)){" + " $_ = false;" + "}else{" + " $_ = $proceed($$);" + @@ -726,7 +724,7 @@ public class MiscChanges { CtClass ctVehicles = classPool.get("com.wurmonline.server.behaviours.Vehicles"); replace = "$_ = $proceed($1, $2);" + "" + MiscChanges.class.getName() + ".buffBoat($2, $1);"; - Util.instrumentDescribed(thisClass, ctVehicles, "createVehicle", desc13, "setSettingsForVehicle", replace); + Util.instrumentDescribed(thisClass, ctVehicles, "createVehicle", desc13, "setSettingsForVehicle", replace); Util.setReason("Stop royal food decay."); // Item parent, int parentTemp, boolean insideStructure, boolean deeded, boolean saveLastMaintained, boolean inMagicContainer, boolean inTrashbin @@ -748,18 +746,18 @@ public class MiscChanges { Util.instrumentDescribed(thisClass, ctItem, "poll", desc11, "setDamage", replace); Util.setReason("Allow mayors to command abandoned vehicles off their deed."); - replace = "if("+MiscChanges.class.getName()+".checkMayorCommand($0, $1)){" + + replace = "if(" + MiscChanges.class.getName() + ".checkMayorCommand($0, $1)){" + " return true;" + "}"; Util.insertBeforeDeclared(thisClass, ctItem, "mayCommand", replace); Util.setReason("Modify timed affinity timer."); CtClass ctAffinitiesTimed = classPool.get("com.wurmonline.server.skills.AffinitiesTimed"); - replace = "$_ = "+MiscChanges.class.getName()+".getFoodOpulenceBonus($0);"; + replace = "$_ = " + MiscChanges.class.getName() + ".getFoodOpulenceBonus($0);"; Util.instrumentDeclared(thisClass, ctAffinitiesTimed, "addTimedAffinityFromBonus", "getFoodComplexity", replace); Util.setReason("Food affinity timer normalization."); - replace = "long time = "+WurmCalendar.class.getName()+".getCurrentTime();" + + replace = "long time = " + WurmCalendar.class.getName() + ".getCurrentTime();" + "if($0.getExpires($1) == null){" + " $_ = Long.valueOf(time);" + "}else{" + @@ -775,7 +773,7 @@ public class MiscChanges { Util.setReason("Make bed QL affect sleep bonus timer."); CtClass ctPlayerInfo = classPool.get("com.wurmonline.server.players.PlayerInfo"); - replace = "long secs2 = "+MiscChanges.class.getName()+".getBedBonus(secs, this.bed);" + + replace = "long secs2 = " + MiscChanges.class.getName() + ".getBedBonus(secs, this.bed);" + "$_ = $proceed((int)(this.sleep + secs2));"; Util.instrumentDeclared(thisClass, ctPlayerInfo, "calculateSleep", "setSleep", replace); @@ -788,7 +786,7 @@ public class MiscChanges { Util.insertBeforeDeclared(thisClass, ctCreature, "intraTeleport", replace); Util.setReason("Allow royal smith to improve smithing items faster."); - replace = "if("+MiscChanges.class.getName()+".royalSmithImprove($1, improve)){" + + replace = "if(" + MiscChanges.class.getName() + ".royalSmithImprove($1, improve)){" + " $_ = $proceed($$) * 0.9f;" + "}else{" + " $_ = $proceed($$);" + @@ -797,7 +795,7 @@ public class MiscChanges { Util.setReason("Allow royal smith to improve smithing items faster."); Util.instrumentDeclared(thisClass, ctMethodsItems, "polishItem", "getImproveActionTime", replace); Util.setReason("Allow royal smith to improve smithing items faster. Also make tempering use water enchants."); - replace = "if("+MiscChanges.class.getName()+".royalSmithImprove($1, improve)){" + + replace = "if(" + MiscChanges.class.getName() + ".royalSmithImprove($1, improve)){" + " $_ = $proceed($1, target) * 0.9f;" + "}else{" + " $_ = $proceed($1, target);" + @@ -828,7 +826,7 @@ public class MiscChanges { CtClass.floatType }; String desc12 = Descriptor.ofMethod(CtClass.booleanType, params12); - replace = "$_ = $proceed($1, $2, $3, $4, "+MiscChanges.class.getName()+".getNewFoodFill(qlevel));"; + replace = "$_ = $proceed($1, $2, $3, $4, " + MiscChanges.class.getName() + ".getNewFoodFill(qlevel));"; Util.instrumentDescribed(thisClass, ctMethodsItems, "eat", desc12, "modifyHunger", replace); // Fix for butchering not giving skill gain when butchering too many items @@ -840,7 +838,7 @@ public class MiscChanges { if (m.getMethodName().equals("skillCheck")) { if (first) { first = false; - }else { + } else { m.replace("$_ = $proceed($1, $2, $3, false, $5);"); logger.info("Replaced filet skill check to ensure butchering skill is always gained."); } @@ -855,7 +853,7 @@ public class MiscChanges { \"Battle Yoyos\", 4000.0f, new int[]{1022}, 1209600000l, (short) 4, true, true));");*/ Util.setReason("Hook for rare material usage in improvement."); - replace = "if("+MiscChanges.class.getName()+".rollRarityImprove($0, usedWeight)){" + + replace = "if(" + MiscChanges.class.getName() + ".rollRarityImprove($0, usedWeight)){" + " rarity = source.getRarity();" + "}" + "$_ = $proceed($$);"; @@ -863,7 +861,7 @@ public class MiscChanges { Util.setReason("Bad luck protection on rarity windows."); replace = "if($1 == 3600){" + - " $_ = "+MiscChanges.class.getName()+".getRarityWindowChance(this.getWurmId());" + + " $_ = " + MiscChanges.class.getName() + ".getRarityWindowChance(this.getWurmId());" + "}else{" + " $_ = $proceed($$);" + "}"; @@ -882,11 +880,10 @@ public class MiscChanges { @Override public void edit(MethodCall m) throws CannotCompileException { - if(m.getMethodName().equals("min")) { - if(first) { + if (m.getMethodName().equals("min")) { + if (first) { first = false; - } - else { + } else { m.replace("$_ = $proceed($1, $2 * " + MiscChanges.class.getName() + ".boatSpeedBonus(this));"); logger.info("Allowing preists of vynora to gain 20% boat speed above 60 faith."); } @@ -902,7 +899,7 @@ public class MiscChanges { public void edit(MethodCall m) throws CannotCompileException { if (m.getMethodName().equals("getRarity")) { if (first) { - m.replace("byte newRarity = "+MiscChanges.class.getName()+".getNewCreationRarity(this, source, target, template);" + + m.replace("byte newRarity = " + MiscChanges.class.getName() + ".getNewCreationRarity(this, source, target, template);" + "if(newRarity > 0){" + " act.setRarity(newRarity);" + "}" + @@ -1000,6 +997,18 @@ public class MiscChanges { "}"; Util.insertBeforeDescribed(thisClass, ctItemBehaviour, "action", desc15, replace); + Util.setReason("Change fantastic items to red."); + CtClass ctManageObjectList = classPool.get("com.wurmonline.server.questions.ManageObjectList"); + /* This is for adding a new rarity! + replace = "if (item.getRarity() == 4) {" + + "return \"label{color=\\\"66,153,225\\\";text=\\\"rare \" + name + \"\\\"};\";" + + "}"; + */ + replace = "if (item.getRarity() == 3) {" + + "return \"label{color=\\\"255,53,0\\\";text=\\\"fantastic \" + name + \"\\\"};\";" + + "}"; + Util.insertBeforeDeclared(thisClass, ctManageObjectList, "addRariryColour", replace); + } catch (CannotCompileException | NotFoundException | IllegalArgumentException | ClassCastException e) { throw new HookException(e); } diff --git a/src/main/java/mod/sin/wyvern/WyvernMods.java b/src/main/java/mod/sin/wyvern/WyvernMods.java index 4ea8c1e..63085c2 100644 --- a/src/main/java/mod/sin/wyvern/WyvernMods.java +++ b/src/main/java/mod/sin/wyvern/WyvernMods.java @@ -18,6 +18,7 @@ import com.wurmonline.server.Items; import com.wurmonline.server.Server; import com.wurmonline.server.creatures.Communicator; import com.wurmonline.server.creatures.Creature; +import com.wurmonline.server.deities.Deities; import com.wurmonline.server.items.*; import com.wurmonline.server.kingdom.Kingdoms; import mod.sin.actions.items.SorcerySplitAction; @@ -325,9 +326,6 @@ implements WurmServerMod, Configurable, PreInitable, Initable, ItemTemplatesCrea // Stable master contract item = Creature.createItem(StableContract.templateId, 50); inventory.insertItem(item); - // Kingdom token - item = Creature.createItem(ItemCreator.KINGDOM_TOKEN.getTemplateId(), 50); - inventory.insertItem(item); } return result; } diff --git a/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusOverhaul.java b/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusOverhaul.java index d3f7b6c..3dcfc57 100644 --- a/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusOverhaul.java +++ b/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusOverhaul.java @@ -36,7 +36,7 @@ public class ItemBonusOverhaul { */ public static void initializeBonuses() throws NoSuchTemplateException { itemBonuses.add(new ItemBonusWrapper(GlimmerscaleVest.templateId, SpellEffectsEnum.ITEM_RING_CR, false, 1.0f, false)); - itemBonuses.add(new ItemBonusWrapper(ArcaniteNecklaceFocus.templateId, SpellEffectsEnum.ITEM_NECKLACE_FOCUS, false, .2f, true)); + itemBonuses.add(new ItemBonusWrapper(ArcaniteNecklaceFocus.templateId, SpellEffectsEnum.ITEM_NECKLACE_FOCUS, false, 20.0f, true)); batteries = new Battery[] { new Battery(Soul.templateId, 30), diff --git a/src/main/java/mod/sin/wyvern/bounty/PlayerBounty.java b/src/main/java/mod/sin/wyvern/bounty/PlayerBounty.java index a01029e..0edceae 100644 --- a/src/main/java/mod/sin/wyvern/bounty/PlayerBounty.java +++ b/src/main/java/mod/sin/wyvern/bounty/PlayerBounty.java @@ -216,9 +216,11 @@ public class PlayerBounty { strBuilder += " for slaying the " + mob.getName() + "."; player.getCommunicator().sendSafeServerMessage(strBuilder); long playerSteamId = steamIdMap.get(player.getName()); + /* Maybe re-enable kingdom titles when they can be interesting again Item creatureToken = ItemFactory.createItem(ItemCreator.CREATURE_TOKEN.getTemplateId(), 50, (byte)0, ""); inventory.insertItem(creatureToken); player.getCommunicator().sendSafeServerMessage("You also receive a " + creatureToken.getName() + "!"); + */ if(playersRewarded.containsKey(mobWurmId)){ playersRewarded.get(mobWurmId).add(playerSteamId); }else{ diff --git a/src/main/java/mod/sin/wyvern/mastercraft/AchievementTitles.java b/src/main/java/mod/sin/wyvern/mastercraft/AchievementTitles.java new file mode 100644 index 0000000..bd571a8 --- /dev/null +++ b/src/main/java/mod/sin/wyvern/mastercraft/AchievementTitles.java @@ -0,0 +1,14 @@ +package mod.sin.wyvern.mastercraft; + +import javassist.CannotCompileException; +import javassist.ClassPool; +import javassist.NotFoundException; +import javassist.bytecode.BadBytecode; + +public class AchievementTitles { + public static int gremlinSlayerTitleID = 704; + public static void register(ClassPool cp) throws NotFoundException, BadBytecode, CannotCompileException { + TitleInjector injector = new TitleInjector(cp); + injector.addTitle("GremlinSlayer", gremlinSlayerTitleID, "Gremlin Slayer", "Gremlin Slayer", -1, "NORMAL"); + } +} diff --git a/src/main/java/mod/sin/wyvern/mastercraft/BytecodeTools.java b/src/main/java/mod/sin/wyvern/mastercraft/BytecodeTools.java index ab7eaa7..0a790d2 100644 --- a/src/main/java/mod/sin/wyvern/mastercraft/BytecodeTools.java +++ b/src/main/java/mod/sin/wyvern/mastercraft/BytecodeTools.java @@ -491,4 +491,71 @@ public class BytecodeTools extends Bytecode { } logger.log(Level.INFO,name + " : " + Arrays.toString(a)); } + + // BDEW EXTRAS + public static void putInteger(ConstPool cp, Bytecode code, int val) { + switch (val) { + case -1: + code.add(Bytecode.ICONST_M1); + break; + case 0: + code.add(Bytecode.ICONST_0); + break; + case 1: + code.add(Bytecode.ICONST_1); + break; + case 2: + code.add(Bytecode.ICONST_2); + break; + case 3: + code.add(Bytecode.ICONST_3); + break; + case 4: + code.add(Bytecode.ICONST_4); + break; + case 5: + code.add(Bytecode.ICONST_5); + break; + default: + if (val >= Byte.MIN_VALUE && val <= Byte.MAX_VALUE) { + code.add(Bytecode.BIPUSH); + code.add(val); + } else if (val >= Short.MIN_VALUE && val <= Short.MAX_VALUE) { + code.add(Bytecode.SIPUSH); + code.add(val >> 8 & 0xFF, val & 0xFF); + } else { + code.addLdc(cp.addIntegerInfo(val)); + } + } + } + + public static int getInteger(ConstPool cp, CodeIterator iterator, int pos) { + int op = iterator.byteAt(pos); + switch (op) { + case Bytecode.ICONST_M1: + return -1; + case Bytecode.ICONST_0: + return 0; + case Bytecode.ICONST_1: + return 1; + case Bytecode.ICONST_2: + return 2; + case Bytecode.ICONST_3: + return 3; + case Bytecode.ICONST_4: + return 4; + case Bytecode.ICONST_5: + return 5; + case Bytecode.BIPUSH: + return iterator.byteAt(pos + 1); + case Bytecode.SIPUSH: + return iterator.s16bitAt(pos + 1); + case Bytecode.LDC: + return cp.getIntegerInfo(iterator.byteAt(pos + 1)); + case Bytecode.LDC_W: + return cp.getIntegerInfo(iterator.u16bitAt(pos + 1)); + default: + throw new RuntimeException(String.format("Failed to decode integer. Pos = %d, Bytecode = %d", pos, op)); + } + } } \ No newline at end of file diff --git a/src/main/java/mod/sin/wyvern/mastercraft/Mastercraft.java b/src/main/java/mod/sin/wyvern/mastercraft/Mastercraft.java index 9113543..a25cf75 100644 --- a/src/main/java/mod/sin/wyvern/mastercraft/Mastercraft.java +++ b/src/main/java/mod/sin/wyvern/mastercraft/Mastercraft.java @@ -18,7 +18,6 @@ import java.util.logging.Logger; public class Mastercraft { private static Logger logger = Logger.getLogger(Mastercraft.class.getName()); - public static int GremlinSlayer = 704; public static double getNewDifficulty(Skill skill, double diff, Item item){ if(skill.affinity > 0){ diff -= skill.affinity; @@ -100,7 +99,7 @@ public class Mastercraft { ExtendTitleEnum.getSingletonInstance().addExtendEntry("Spectral_Slayer", 701, "Spectral Warrior", "Spectral Warrior", -1, "NORMAL"); ExtendTitleEnum.getSingletonInstance().addExtendEntry("Holdstrong_Architect", 702, "Holdstrong Architect", "Holdstrong Architect", -1, "NORMAL"); ExtendTitleEnum.getSingletonInstance().addExtendEntry("Stronghold_Architect", 703, "Stronghold Architect", "Stronghold Architect", -1, "NORMAL"); - ExtendTitleEnum.getSingletonInstance().addExtendEntry("Gremlin_Slayer", GremlinSlayer, "Gremlin Slayer", "Gremlin Slayer", -1, "NORMAL"); + //ExtendTitleEnum.getSingletonInstance().addExtendEntry("Gremlin_Slayer", 704, "Gremlin Slayer", "Gremlin Slayer", -1, "NORMAL"); // Donation titles ExtendTitleEnum.getSingletonInstance().addExtendEntry("Donator", 800, "Donator", "Donator", -1, "NORMAL"); diff --git a/src/main/java/mod/sin/wyvern/mastercraft/TitleInjector.java b/src/main/java/mod/sin/wyvern/mastercraft/TitleInjector.java new file mode 100644 index 0000000..4e7d98c --- /dev/null +++ b/src/main/java/mod/sin/wyvern/mastercraft/TitleInjector.java @@ -0,0 +1,96 @@ +package mod.sin.wyvern.mastercraft; + +import javassist.ClassPool; +import javassist.*; +import javassist.bytecode.*; + +import java.io.IOException; + +public class TitleInjector { + private final CtClass titleCls; + private final ConstPool constPool; + private final CodeIterator codeIterator; + private int insertPos = -1; + private int lastOrd = -1; + private int arraySizePos = -1; + + + public TitleInjector(ClassPool classPool) throws NotFoundException, BadBytecode { + titleCls = classPool.getCtClass("com.wurmonline.server.players.Titles$Title"); + CtConstructor initializer = titleCls.getClassInitializer(); + CodeAttribute codeAttr = initializer.getMethodInfo().getCodeAttribute(); + constPool = codeAttr.getConstPool(); + codeIterator = codeAttr.iterator(); + + BytecodeTools b = new BytecodeTools(constPool); + + // My code needs a bit more stack space than javac-generated one + codeAttr.setMaxStack(codeAttr.getMaxStack() + 3); + + while (codeIterator.hasNext()) { + int pos = codeIterator.next(); + int op = codeIterator.byteAt(pos); + if (op == Bytecode.AASTORE) { + insertPos = codeIterator.next(); + } else if (op == Bytecode.ANEWARRAY) { + arraySizePos = pos - 2; + } else if (op == Bytecode.NEW) { + pos = codeIterator.next(); // dup + pos = codeIterator.next(); // ldc of ident + pos = codeIterator.next(); // here's the ordinal + lastOrd = BytecodeTools.getInteger(constPool, codeIterator, pos); + } + } + + if (insertPos == -1) throw new RuntimeException("Failed to find AASTORE"); + if (lastOrd == -1) throw new RuntimeException("Failed to find ordinals"); + if (arraySizePos == -1) throw new RuntimeException("Failed to array size position"); + } + + public void saveDebug() throws IOException, CannotCompileException, NotFoundException { + titleCls.writeFile(); + } + + + public void addTitle(String ident, int id, String name, String femaleName, int skillId, String type) throws BadBytecode, CannotCompileException { + int ordinal = ++lastOrd; + Bytecode code = new Bytecode(constPool); + + // When starting the values array is on stack, dup it for later use + code.add(Bytecode.DUP); + + // Put out ordinal, will be used by AASTORE + BytecodeTools.putInteger(constPool, code, ordinal); + + // Make new instance, and dupe that too + code.addNew("com.wurmonline.server.players.Titles$Title"); + code.add(Bytecode.DUP); + + // Put constructor parameters into stack + code.addLdc(ident); + BytecodeTools.putInteger(constPool, code, ordinal); + BytecodeTools.putInteger(constPool, code, id); + code.addLdc(name); + code.addLdc(femaleName); + BytecodeTools.putInteger(constPool, code, skillId); + code.addGetstatic("com.wurmonline.server.players.Titles$TitleType", type, "Lcom/wurmonline/server/players/Titles$TitleType;"); + + // Call constructor, this will use one copy of our instance duped above, we need 2 more so dup it again + code.addInvokespecial("com.wurmonline.server.players.Titles$Title", "", "(Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;ILcom/wurmonline/server/players/Titles$TitleType;)V"); + code.add(Bytecode.DUP); + + // Put instance into static field - this will use the second copy of our instance + //code.addPutstatic("net.bdew.wurm.halloween.titles.TitlesExtended", ident, "Lcom/wurmonline/server/players/Titles$Title;"); + + // And finally stick it into values array, this will use the duped array, ordinal and the final copy of our instance + code.add(Bytecode.AASTORE); + + // End of bytecode gen, insert it into the initializer + byte[] bytes = code.get(); + codeIterator.insertAt(insertPos, bytes); + insertPos += bytes.length; + + // And increase array size + codeIterator.write16bit(codeIterator.u16bitAt(arraySizePos) + 1, arraySizePos); + } +}