Move field hooks to mixins
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* 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.mixins;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD, ElementType.FIELD})
|
||||
@Documented
|
||||
public @interface FieldHook
|
||||
{
|
||||
String value();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* 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.client.callback;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
/**
|
||||
* Dummy class to make the mixins to compile.
|
||||
*
|
||||
* @author Adam
|
||||
*/
|
||||
public class Hooks
|
||||
{
|
||||
public static EventBus eventBus;
|
||||
}
|
||||
@@ -34,9 +34,12 @@ import static net.runelite.api.Perspective.LOCAL_COORD_BITS;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.SpritePixels;
|
||||
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.AnimationChanged;
|
||||
import static net.runelite.client.callback.Hooks.eventBus;
|
||||
import net.runelite.rs.api.RSActor;
|
||||
import net.runelite.rs.api.RSClient;
|
||||
import net.runelite.rs.api.RSCombatInfo1;
|
||||
@@ -173,4 +176,13 @@ public abstract class RSActorMixin implements RSActor
|
||||
{
|
||||
return Perspective.worldToMiniMap(client, getX(), getY());
|
||||
}
|
||||
|
||||
@FieldHook("animation")
|
||||
@Inject
|
||||
public void animationChanged(int idx)
|
||||
{
|
||||
AnimationChanged animationChange = new AnimationChanged();
|
||||
animationChange.setActor(this);
|
||||
eventBus.post(animationChange);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,20 @@ import net.runelite.api.Point;
|
||||
import net.runelite.api.Prayer;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.Varbits;
|
||||
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.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.api.events.ClanMembersChanged;
|
||||
import net.runelite.api.events.ExperienceChanged;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.MapRegionChanged;
|
||||
import net.runelite.api.events.PlayerMenuOptionsChanged;
|
||||
import net.runelite.api.events.ResizeableChanged;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
import static net.runelite.client.callback.Hooks.eventBus;
|
||||
import net.runelite.rs.api.RSClient;
|
||||
import net.runelite.rs.api.RSIndexedSprite;
|
||||
import net.runelite.rs.api.RSWidget;
|
||||
@@ -48,6 +58,9 @@ import net.runelite.rs.api.RSWidget;
|
||||
@Mixin(RSClient.class)
|
||||
public abstract class RSClientMixin implements RSClient
|
||||
{
|
||||
@Shadow("clientInstance")
|
||||
private static RSClient client;
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public List<Player> getPlayers()
|
||||
@@ -324,4 +337,73 @@ public abstract class RSClientMixin implements RSClient
|
||||
{
|
||||
setRSModIcons((RSIndexedSprite[]) modIcons);
|
||||
}
|
||||
|
||||
@FieldHook("skillExperiences")
|
||||
@Inject
|
||||
public static void experiencedChanged(int idx)
|
||||
{
|
||||
ExperienceChanged experienceChanged = new ExperienceChanged();
|
||||
Skill[] possibleSkills = Skill.values();
|
||||
|
||||
// We subtract one here because 'Overall' isn't considered a skill that's updated.
|
||||
if (idx < possibleSkills.length - 1)
|
||||
{
|
||||
Skill updatedSkill = possibleSkills[idx];
|
||||
experienceChanged.setSkill(updatedSkill);
|
||||
eventBus.post(experienceChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@FieldHook("mapRegions")
|
||||
@Inject
|
||||
public static void mapRegionsChanged(int idx)
|
||||
{
|
||||
MapRegionChanged regionChanged = new MapRegionChanged();
|
||||
regionChanged.setIndex(idx);
|
||||
eventBus.post(regionChanged);
|
||||
}
|
||||
|
||||
@FieldHook("playerOptions")
|
||||
@Inject
|
||||
public static void playerOptionsChanged(int idx)
|
||||
{
|
||||
PlayerMenuOptionsChanged optionsChanged = new PlayerMenuOptionsChanged();
|
||||
optionsChanged.setIndex(idx);
|
||||
eventBus.post(optionsChanged);
|
||||
}
|
||||
|
||||
@FieldHook("gameState")
|
||||
@Inject
|
||||
public static void gameStateChanged(int idx)
|
||||
{
|
||||
GameStateChanged gameStateChange = new GameStateChanged();
|
||||
gameStateChange.setGameState(client.getGameState());
|
||||
eventBus.post(gameStateChange);
|
||||
}
|
||||
|
||||
@FieldHook("settings")
|
||||
@Inject
|
||||
public static void settingsChanged(int idx)
|
||||
{
|
||||
VarbitChanged varbitChanged = new VarbitChanged();
|
||||
eventBus.post(varbitChanged);
|
||||
}
|
||||
|
||||
@FieldHook("clanMembers")
|
||||
@Inject
|
||||
public static void clanMembersChanged(int idx)
|
||||
{
|
||||
ClanMembersChanged clanMembersChanged = new ClanMembersChanged();
|
||||
eventBus.post(clanMembersChanged);
|
||||
}
|
||||
|
||||
@FieldHook("isResized")
|
||||
@Inject
|
||||
public static void resizeChanged(int idx)
|
||||
{
|
||||
//maybe couple with varbitChanged. resizeable may not be a varbit but it would fit with the other client settings.
|
||||
ResizeableChanged resizeableChanged = new ResizeableChanged();
|
||||
resizeableChanged.setResized(client.isResized());
|
||||
eventBus.post(resizeableChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,15 @@
|
||||
*/
|
||||
package net.runelite.mixins;
|
||||
|
||||
import net.runelite.api.GameObject;
|
||||
import net.runelite.api.Perspective;
|
||||
import net.runelite.api.Point;
|
||||
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.RSTile;
|
||||
|
||||
@@ -60,4 +64,21 @@ public abstract class RSTileMixin implements RSTile
|
||||
Point regionLocation = getRegionLocation();
|
||||
return Perspective.regionToLocal(client, regionLocation);
|
||||
}
|
||||
|
||||
@FieldHook("objects")
|
||||
@Inject
|
||||
public void animationChanged(int idx)
|
||||
{
|
||||
if (idx != -1) // this happens from the field assignment
|
||||
{
|
||||
// GameObject that was changed.
|
||||
GameObject go = getGameObjects()[idx];
|
||||
if (go != null)
|
||||
{
|
||||
GameObjectsChanged gameObjectsChanged = new GameObjectsChanged();
|
||||
gameObjectsChanged.setGameObject(go);
|
||||
eventBus.post(gameObjectsChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user