From 789221490e78ea8bbbbc505c9c8c88e5a7e41550 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 30 Jan 2018 09:47:07 -0500 Subject: [PATCH] runelite-api: add game object and wall object spawn/change/despawn events --- .../api/events/GameObjectChanged.java | 37 +++++++ .../api/events/GameObjectDespawned.java | 36 +++++++ ...ctsChanged.java => GameObjectSpawned.java} | 6 +- .../api/events/WallObjectChanged.java | 37 +++++++ .../api/events/WallObjectDespawned.java | 36 +++++++ .../api/events/WallObjectSpawned.java | 36 +++++++ .../java/net/runelite/mixins/RSTileMixin.java | 96 +++++++++++++++++-- 7 files changed, 274 insertions(+), 10 deletions(-) create mode 100644 runelite-api/src/main/java/net/runelite/api/events/GameObjectChanged.java create mode 100644 runelite-api/src/main/java/net/runelite/api/events/GameObjectDespawned.java rename runelite-api/src/main/java/net/runelite/api/events/{GameObjectsChanged.java => GameObjectSpawned.java} (91%) create mode 100644 runelite-api/src/main/java/net/runelite/api/events/WallObjectChanged.java create mode 100644 runelite-api/src/main/java/net/runelite/api/events/WallObjectDespawned.java create mode 100644 runelite-api/src/main/java/net/runelite/api/events/WallObjectSpawned.java diff --git a/runelite-api/src/main/java/net/runelite/api/events/GameObjectChanged.java b/runelite-api/src/main/java/net/runelite/api/events/GameObjectChanged.java new file mode 100644 index 0000000000..a3a2b73576 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/GameObjectChanged.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, Adam + * 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.events; + +import lombok.Data; +import net.runelite.api.GameObject; +import net.runelite.api.Tile; + +@Data +public class GameObjectChanged +{ + private Tile tile; + private GameObject previous; + private GameObject gameObject; +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/GameObjectDespawned.java b/runelite-api/src/main/java/net/runelite/api/events/GameObjectDespawned.java new file mode 100644 index 0000000000..ca576730ba --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/GameObjectDespawned.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Adam + * 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.events; + +import lombok.Data; +import net.runelite.api.GameObject; +import net.runelite.api.Tile; + +@Data +public class GameObjectDespawned +{ + private Tile tile; + private GameObject gameObject; +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/GameObjectsChanged.java b/runelite-api/src/main/java/net/runelite/api/events/GameObjectSpawned.java similarity index 91% rename from runelite-api/src/main/java/net/runelite/api/events/GameObjectsChanged.java rename to runelite-api/src/main/java/net/runelite/api/events/GameObjectSpawned.java index f5abaf6648..6e406d64d1 100644 --- a/runelite-api/src/main/java/net/runelite/api/events/GameObjectsChanged.java +++ b/runelite-api/src/main/java/net/runelite/api/events/GameObjectSpawned.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Robin Weymans + * Copyright (c) 2018, Adam * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,9 +26,11 @@ package net.runelite.api.events; import lombok.Data; import net.runelite.api.GameObject; +import net.runelite.api.Tile; @Data -public class GameObjectsChanged +public class GameObjectSpawned { + private Tile tile; private GameObject gameObject; } diff --git a/runelite-api/src/main/java/net/runelite/api/events/WallObjectChanged.java b/runelite-api/src/main/java/net/runelite/api/events/WallObjectChanged.java new file mode 100644 index 0000000000..c14fdbe999 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/WallObjectChanged.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, Adam + * 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.events; + +import lombok.Data; +import net.runelite.api.Tile; +import net.runelite.api.WallObject; + +@Data +public class WallObjectChanged +{ + private Tile tile; + private WallObject previous; + private WallObject wallObject; +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/WallObjectDespawned.java b/runelite-api/src/main/java/net/runelite/api/events/WallObjectDespawned.java new file mode 100644 index 0000000000..0188cf5e88 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/WallObjectDespawned.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Adam + * 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.events; + +import lombok.Data; +import net.runelite.api.Tile; +import net.runelite.api.WallObject; + +@Data +public class WallObjectDespawned +{ + private Tile tile; + private WallObject wallObject; +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/WallObjectSpawned.java b/runelite-api/src/main/java/net/runelite/api/events/WallObjectSpawned.java new file mode 100644 index 0000000000..d405227d53 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/WallObjectSpawned.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Adam + * 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.events; + +import lombok.Data; +import net.runelite.api.Tile; +import net.runelite.api.WallObject; + +@Data +public class WallObjectSpawned +{ + private Tile tile; + private WallObject wallObject; +} diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSTileMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSTileMixin.java index cd6b221e71..d212768f1d 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSTileMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSTileMixin.java @@ -24,16 +24,24 @@ */ package net.runelite.mixins; +import net.runelite.api.Actor; import net.runelite.api.GameObject; import net.runelite.api.Perspective; import net.runelite.api.Point; +import net.runelite.api.WallObject; +import net.runelite.api.events.GameObjectChanged; +import net.runelite.api.events.GameObjectDespawned; +import net.runelite.api.events.GameObjectSpawned; +import net.runelite.api.events.WallObjectChanged; +import net.runelite.api.events.WallObjectDespawned; +import net.runelite.api.events.WallObjectSpawned; import net.runelite.api.mixins.FieldHook; import net.runelite.api.mixins.Inject; import net.runelite.api.mixins.Mixin; import net.runelite.api.mixins.Shadow; -import net.runelite.api.events.GameObjectsChanged; import static net.runelite.client.callback.Hooks.eventBus; import net.runelite.rs.api.RSClient; +import net.runelite.rs.api.RSGameObject; import net.runelite.rs.api.RSTile; @Mixin(RSTile.class) @@ -42,6 +50,12 @@ public abstract class RSTileMixin implements RSTile @Shadow("clientInstance") private static RSClient client; + @Inject + private WallObject previousWallObject; + + @Inject + private GameObject[] previousGameObjects; + @Inject @Override public Point getWorldLocation() @@ -65,18 +79,84 @@ public abstract class RSTileMixin implements RSTile return Perspective.regionToLocal(client, regionLocation); } + @FieldHook("wallObject") + @Inject + public void wallObjectChanged(int idx) + { + WallObject previous = previousWallObject; + WallObject current = getWallObject(); + + previousWallObject = current; + + if (current == null && previous != null) + { + WallObjectDespawned wallObjectDespawned = new WallObjectDespawned(); + wallObjectDespawned.setTile(this); + wallObjectDespawned.setWallObject(previous); + eventBus.post(wallObjectDespawned); + } + else if (current != null && previous == null) + { + WallObjectSpawned wallObjectSpawned = new WallObjectSpawned(); + wallObjectSpawned.setTile(this); + wallObjectSpawned.setWallObject(current); + eventBus.post(wallObjectSpawned); + } + else if (current != null && previous != null) + { + WallObjectChanged wallObjectChanged = new WallObjectChanged(); + wallObjectChanged.setTile(this); + wallObjectChanged.setPrevious(previous); + wallObjectChanged.setWallObject(current); + eventBus.post(wallObjectChanged); + } + } + @FieldHook("objects") @Inject - public void animationChanged(int idx) + public void gameObjectsChanged(int idx) { - if (idx != -1) // this happens from the field assignment + if (idx == -1) // this happens from the field assignment { - // GameObject that was changed. - GameObject go = getGameObjects()[idx]; - if (go != null) + return; + } + + if (previousGameObjects == null) + { + previousGameObjects = new GameObject[5]; + } + + // Previous game object + GameObject previous = previousGameObjects[idx]; + // GameObject that was changed. + RSGameObject current = (RSGameObject) getGameObjects()[idx]; + + // Update previous object to current + previousGameObjects[idx] = current; + + // Characters seem to generate a constant stream of new GameObjects + if (current == null || !(current.getRenderable() instanceof Actor)) + { + if (current == null && previous != null) { - GameObjectsChanged gameObjectsChanged = new GameObjectsChanged(); - gameObjectsChanged.setGameObject(go); + GameObjectDespawned gameObjectDespawned = new GameObjectDespawned(); + gameObjectDespawned.setTile(this); + gameObjectDespawned.setGameObject(previous); + eventBus.post(gameObjectDespawned); + } + else if (current != null && previous == null) + { + GameObjectSpawned gameObjectSpawned = new GameObjectSpawned(); + gameObjectSpawned.setTile(this); + gameObjectSpawned.setGameObject(current); + eventBus.post(gameObjectSpawned); + } + else if (current != null && previous != null) + { + GameObjectChanged gameObjectsChanged = new GameObjectChanged(); + gameObjectsChanged.setTile(this); + gameObjectsChanged.setPrevious(previous); + gameObjectsChanged.setGameObject(current); eventBus.post(gameObjectsChanged); } }