From c0e9a502eb8cec5d4e7ebf1867ab317164245aa8 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 5 Mar 2018 17:10:35 +0100 Subject: [PATCH] Add support for changing world to API - Export World from RS client - Export changeWorld method - Create new method for creating RuneScape world Signed-off-by: Tomas Slusny --- .../main/java/net/runelite/api/Client.java | 18 +++ .../src/main/java/net/runelite/api/World.java | 132 ++++++++++++++++++ .../main/java/net/runelite/api/WorldType.java | 112 +++++++++++++++ .../net/runelite/mixins/RSWorldMixin.java | 49 +++++++ .../java/net/runelite/rs/api/RSClient.java | 10 ++ .../java/net/runelite/rs/api/RSWorld.java | 36 ++++- 6 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 runelite-api/src/main/java/net/runelite/api/World.java create mode 100644 runelite-api/src/main/java/net/runelite/api/WorldType.java create mode 100644 runelite-mixins/src/main/java/net/runelite/mixins/RSWorldMixin.java diff --git a/runelite-api/src/main/java/net/runelite/api/Client.java b/runelite-api/src/main/java/net/runelite/api/Client.java index a076d8ef4d..4591ff6738 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -114,6 +114,12 @@ public interface Client extends GameEngine int[] getPlayerMenuTypes(); + /** + * Get list of all RuneScape worlds + * @return world list + */ + World[] getWorldList(); + MenuEntry[] getMenuEntries(); void setMenuEntries(MenuEntry[] entries); @@ -308,4 +314,16 @@ public interface Client extends GameEngine void setStretchedKeepAspectRatio(boolean state); Dimension getStretchedDimensions(); + + /** + * Changes world. Works only on login screen + * @param world world + */ + void changeWorld(World world); + + /** + * Creates instance of new world + * @return world + */ + World createWorld(); } diff --git a/runelite-api/src/main/java/net/runelite/api/World.java b/runelite-api/src/main/java/net/runelite/api/World.java new file mode 100644 index 0000000000..a060d5f247 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/World.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.api; + + +import java.util.EnumSet; + +/** + * Holds data of RuneScape world. + */ +public interface World +{ + /** + * Gets world types. + * + * @return the types + */ + EnumSet getTypes(); + + /** + * Sets world types. + * + * @param types the types + */ + void setTypes(EnumSet types); + + /** + * Gets player count. + * + * @return the player count + */ + int getPlayerCount(); + + /** + * Sets player count. + * + * @param playerCount the player count + */ + void setPlayerCount(int playerCount); + + /** + * Gets location. + * + * @return the location + */ + int getLocation(); + + /** + * Sets location. + * + * @param location the location + */ + void setLocation(int location); + + /** + * Gets index. + * + * @return the index + */ + int getIndex(); + + /** + * Sets index. + * + * @param index the index + */ + void setIndex(int index); + + /** + * Gets id. + * + * @return the id + */ + int getId(); + + /** + * Sets id. + * + * @param id the id + */ + void setId(int id); + + /** + * Gets activity. + * + * @return the activity + */ + String getActivity(); + + /** + * Sets activity. + * + * @param activity the activity + */ + void setActivity(String activity); + + /** + * Gets address. + * + * @return the address + */ + String getAddress(); + + /** + * Sets address. + * + * @param address the address + */ + void setAddress(String address); +} diff --git a/runelite-api/src/main/java/net/runelite/api/WorldType.java b/runelite-api/src/main/java/net/runelite/api/WorldType.java new file mode 100644 index 0000000000..0024980b1e --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/WorldType.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.api; + +import java.util.EnumSet; + +/** + * Enum representing world type. + */ +public enum WorldType +{ + /** + * Members world type. + */ + MEMBERS(1), + /** + * Pvp world type. + */ + PVP(1 << 2), + /** + * Bounty world type. + */ + BOUNTY(1 << 5), + /** + * Skill total world type. + */ + SKILL_TOTAL(1 << 7), + /** + * Pvp high risk world type. + */ + PVP_HIGH_RISK(1 << 10), + /** + * Last man standing world type. + */ + LAST_MAN_STANDING(1 << 14), + /** + * Deadman world type. + */ + DEADMAN(1 << 29), + /** + * Seasonal deadman world type. + */ + SEASONAL_DEADMAN(1 << 30); + + private final int mask; + + WorldType(int mask) + { + this.mask = mask; + } + + /** + * Create enum set of world types from mask. + * + * @param mask the mask + * @return the enum set + */ + public static EnumSet fromMask(final int mask) + { + final EnumSet types = EnumSet.noneOf(WorldType.class); + + for (WorldType type : WorldType.values()) + { + if ((mask & type.mask) != 0) + { + types.add(type); + } + } + + return types; + } + + /** + * Create mask from enum set of world types. + * + * @param types the types + * @return the int + */ + public static int toMask(final EnumSet types) + { + int mask = 0; + + for (WorldType type : types) + { + mask |= type.mask; + } + + return mask; + } +} \ No newline at end of file diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSWorldMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSWorldMixin.java new file mode 100644 index 0000000000..ec576dcf06 --- /dev/null +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSWorldMixin.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.mixins; + +import java.util.EnumSet; +import net.runelite.api.WorldType; +import net.runelite.api.mixins.Inject; +import net.runelite.api.mixins.Mixin; +import net.runelite.rs.api.RSWorld; + +@Mixin(RSWorld.class) +public abstract class RSWorldMixin implements RSWorld +{ + @Inject + @Override + public EnumSet getTypes() + { + return WorldType.fromMask(getMask()); + } + + @Inject + @Override + public void setTypes(final EnumSet types) + { + setMask(WorldType.toMask(types)); + } +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java index 2c58b20afa..5a099109ea 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java @@ -27,6 +27,7 @@ package net.runelite.rs.api; import java.util.Map; import net.runelite.api.BufferProvider; import net.runelite.api.Client; +import net.runelite.api.World; import net.runelite.mapping.Construct; import net.runelite.mapping.Import; @@ -202,6 +203,7 @@ public interface RSClient extends RSGameEngine, Client int[] getMenuActionParams1(); @Import("worldList") + @Override RSWorld[] getWorldList(); @Import("addChatMessage") @@ -495,4 +497,12 @@ public interface RSClient extends RSGameEngine, Client @Import("renderOverview") RSRenderOverview getRenderOverview(); + + @Import("changeWorld") + @Override + void changeWorld(World world); + + @Construct + @Override + RSWorld createWorld(); } diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSWorld.java b/runescape-api/src/main/java/net/runelite/rs/api/RSWorld.java index 26105585e5..2a4a8c4925 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSWorld.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSWorld.java @@ -24,28 +24,62 @@ */ package net.runelite.rs.api; +import net.runelite.api.World; import net.runelite.mapping.Import; -public interface RSWorld +public interface RSWorld extends World { @Import("mask") int getMask(); + @Import("mask") + void setMask(int mask); + @Import("playerCount") + @Override int getPlayerCount(); + @Import("playerCount") + @Override + void setPlayerCount(int playerCount); + @Import("location") + @Override int getLocation(); + @Import("location") + @Override + void setLocation(int location); + @Import("index") + @Override int getIndex(); + @Import("index") + @Override + void setIndex(int index); + @Import("id") + @Override int getId(); + @Import("id") + @Override + void setId(int id); + @Import("activity") + @Override String getActivity(); + @Import("activity") + @Override + void setActivity(String activity); + @Import("address") + @Override String getAddress(); + + @Import("address") + @Override + void setAddress(String address); }