add getVarbitCount and warn instead of throw when varb doesnt exist

This commit is contained in:
Lucwousin
2020-06-29 02:08:26 +02:00
parent 934fad63b5
commit 2d9c26387a
4 changed files with 22 additions and 1 deletions

View File

@@ -809,6 +809,11 @@ public interface Client extends GameShell
*/ */
void setVarbitValue(int[] varps, int varbit, int value); void setVarbitValue(int[] varps, int varbit, int value);
/**
* @return the total number of VarbitDefinition
*/
int getVarbitCount();
/** /**
* Gets the widget flags table. * Gets the widget flags table.
* *

View File

@@ -16,6 +16,8 @@ import net.runelite.rs.api.RSVarbitDefinition;
@Mixin(RSClient.class) @Mixin(RSClient.class)
public abstract class VarbitMixin implements RSClient public abstract class VarbitMixin implements RSClient
{ {
private static final int VARBITS_GROUP = 14;
@Shadow("client") @Shadow("client")
private static RSClient client; private static RSClient client;
@@ -69,7 +71,8 @@ public abstract class VarbitMixin implements RSClient
if (v.getIndex() == 0 && v.getLeastSignificantBit() == 0 && v.getMostSignificantBit() == 0) if (v.getIndex() == 0 && v.getLeastSignificantBit() == 0 && v.getMostSignificantBit() == 0)
{ {
throw new IndexOutOfBoundsException("Varbit " + varbitId + " does not exist"); getLogger().debug("Varbit {} doesn't exist!", varbitId);
return 0;
} }
int value = varps[v.getIndex()]; int value = varps[v.getIndex()];
@@ -152,4 +155,11 @@ public abstract class VarbitMixin implements RSClient
{ {
return getVarcs().getVarcMap(); return getVarcs().getVarcMap();
} }
@Inject
@Override
public int getVarbitCount()
{
return getConfigArchive().getGroupFileCount(VARBITS_GROUP);
}
} }

View File

@@ -7,4 +7,7 @@ public interface RSAbstractArchive extends IndexDataBase
{ {
@Import("takeFile") @Import("takeFile")
byte[] getConfigData(int archiveId, int fileId); byte[] getConfigData(int archiveId, int fileId);
@Import("getGroupFileCount")
int getGroupFileCount(int group);
} }

View File

@@ -457,6 +457,9 @@ public interface RSClient extends RSGameShell, Client
@Import("SpriteBuffer_spritePalette") @Import("SpriteBuffer_spritePalette")
void setIndexedSpritePalette(int[] indexedSpritePalette); void setIndexedSpritePalette(int[] indexedSpritePalette);
@Import("archive2")
RSArchive getConfigArchive();
@Import("archive6") @Import("archive6")
RSArchive getMusicTracks(); RSArchive getMusicTracks();