timestamp: use less callbacks in script overlays

all of these separate callbacks are error prone to update and hard to
test
This commit is contained in:
Max Weber
2021-05-25 17:08:29 -06:00
committed by Adam
parent adabb68ff1
commit 58e351dca6
5 changed files with 107 additions and 107 deletions

View File

@@ -332,4 +332,23 @@ public final class ScriptID
*/ */
@ScriptArguments(integer = 4) @ScriptArguments(integer = 4)
public static final int WIKI_ICON_UPDATE = 3306; public static final int WIKI_ICON_UPDATE = 3306;
/**
* Builds a line in the chatbox when there is no username: prefix, such as
* a game or system message
*/
@ScriptArguments(integer = 11, string = 1)
public static final int CHATBOX_BUILD_LINE_WITHOUT_USER = 199;
/**
* Builds a line in the chatbox when there is a username: prefix
*/
@ScriptArguments(integer = 11, string = 2)
public static final int CHATBOX_BUILD_LINE_WITH_USER = 203;
/**
* Builds a line in the chatbox when it from a clan
*/
@ScriptArguments(integer = 14, string = 3)
public static final int CHATBOX_BUILD_LINE_WITH_CLAN = 4483;
} }

View File

@@ -196,12 +196,14 @@ public class ChatMessageManager
{ {
final String eventName = scriptCallbackEvent.getEventName(); final String eventName = scriptCallbackEvent.getEventName();
boolean wrap;
switch (eventName) switch (eventName)
{ {
case "privateChatFrom": case "splitPrivChatUsernameColor":
case "privateChatTo": wrap = false;
case "privateChatSplitFrom": break;
case "privateChatSplitTo": case "privChatUsername":
wrap = true;
break; break;
default: default:
return; return;
@@ -216,10 +218,17 @@ public class ChatMessageManager
final String[] stringStack = client.getStringStack(); final String[] stringStack = client.getStringStack();
final int stringStackSize = client.getStringStackSize(); final int stringStackSize = client.getStringStackSize();
// Stack is: To/From playername : String fromToUsername = stringStack[stringStackSize - 1];
String toFrom = stringStack[stringStackSize - 3]; if (wrap)
stringStack[stringStackSize - 3] = ColorUtil.prependColorTag(toFrom, usernameColor); {
fromToUsername = ColorUtil.wrapWithColorTag(fromToUsername, usernameColor);
}
else
{
fromToUsername = ColorUtil.colorTag(usernameColor);
}
stringStack[stringStackSize - 1] = fromToUsername;
} }
private static Color getDefaultColor(ChatMessageType type, boolean transparent) private static Color getDefaultColor(ChatMessageType type, boolean transparent)

View File

@@ -36,7 +36,9 @@ import javax.inject.Inject;
import lombok.Getter; import lombok.Getter;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.MessageNode; import net.runelite.api.MessageNode;
import net.runelite.api.ScriptID;
import net.runelite.api.Varbits; import net.runelite.api.Varbits;
import net.runelite.api.events.ScriptPreFired;
import net.runelite.client.events.ConfigChanged; import net.runelite.client.events.ConfigChanged;
import net.runelite.api.events.ScriptCallbackEvent; import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
@@ -62,6 +64,8 @@ public class TimestampPlugin extends Plugin
@Getter @Getter
private SimpleDateFormat formatter; private SimpleDateFormat formatter;
private MessageNode currentlyBuildingMessage = null;
@Provides @Provides
public TimestampConfig provideConfig(final ConfigManager configManager) public TimestampConfig provideConfig(final ConfigManager configManager)
{ {
@@ -90,32 +94,59 @@ public class TimestampPlugin extends Plugin
} }
@Subscribe @Subscribe
public void onScriptCallbackEvent(ScriptCallbackEvent event) private void onScriptCallbackEvent(ScriptCallbackEvent event)
{ {
if (!event.getEventName().equals("addTimestamp")) if (!"chatMessageBuilding".equals(event.getEventName()))
{ {
return; return;
} }
int[] intStack = client.getIntStack(); int uid = client.getIntStack()[client.getIntStackSize() - 1];
int intStackSize = client.getIntStackSize(); currentlyBuildingMessage = client.getMessages().get(uid);
}
@Subscribe
private void onScriptPreFired(ScriptPreFired ev)
{
int numStringArgs;
int messagePrefixArg = 0;
switch (ev.getScriptId())
{
case ScriptID.CHATBOX_BUILD_LINE_WITHOUT_USER:
numStringArgs = 1;
break;
case ScriptID.CHATBOX_BUILD_LINE_WITH_USER:
numStringArgs = 2;
break;
case ScriptID.CHATBOX_BUILD_LINE_WITH_CLAN:
numStringArgs = 3;
break;
default:
return;
}
if (currentlyBuildingMessage == null)
{
return;
}
MessageNode messageNode = currentlyBuildingMessage;
currentlyBuildingMessage = null;
String[] stringStack = client.getStringStack(); String[] stringStack = client.getStringStack();
int stringStackSize = client.getStringStackSize(); int stringArgStart = client.getStringStackSize() - numStringArgs;
int messageId = intStack[intStackSize - 1];
MessageNode messageNode = client.getMessages().get(messageId);
String timestamp = generateTimestamp(messageNode.getTimestamp(), ZoneId.systemDefault()) + " "; String timestamp = generateTimestamp(messageNode.getTimestamp(), ZoneId.systemDefault()) + " ";
Color timestampColour = getTimestampColour(); Color timestampColour = getTimestampColour();
if (timestampColour != null) if (timestampColour != null)
{ {
timestamp = ColorUtil.wrapWithColorTag(timestamp, timestampColour); timestamp = ColorUtil.wrapWithColorTag(timestamp, timestampColour);
} }
stringStack[stringStackSize - 1] = timestamp; String segment = stringStack[stringArgStart + messagePrefixArg];
segment = timestamp + segment;
stringStack[stringArgStart + messagePrefixArg] = segment;
} }
private Color getTimestampColour() private Color getTimestampColour()

View File

@@ -288,6 +288,10 @@ LABEL245:
if_icmpeq LABEL256 if_icmpeq LABEL256
jump LABEL1266 jump LABEL1266
LABEL256: LABEL256:
iload 10 ; message uid
sconst "chatMessageBuilding"
runelite_callback
pop_int ; pop uid
iload 11 iload 11
switch switch
1: LABEL259 1: LABEL259
@@ -312,14 +316,9 @@ LABEL256:
91: LABEL280 91: LABEL280
jump LABEL928 jump LABEL928
LABEL259: LABEL259:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sload 12 sload 12
sconst ":" sconst ":"
join_string 3 ; + 1 for timestamp join_string 2
sload 1 sload 1
sload 14 sload 14
sconst "</col>" sconst "</col>"
@@ -339,14 +338,9 @@ LABEL259:
istore 7 istore 7
jump LABEL942 jump LABEL942
LABEL280: LABEL280:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sload 12 sload 12
sconst ":" sconst ":"
join_string 3 ; + 1 for timestamp join_string 2
sload 3 sload 3
sload 14 sload 14
sconst "</col>" sconst "</col>"
@@ -366,17 +360,12 @@ LABEL280:
istore 7 istore 7
jump LABEL942 jump LABEL942
LABEL301: LABEL301:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sconst "From " sconst "From "
sload 12 sload 12
sconst ":" sconst ":"
sconst "privateChatFrom" join_string 3
runelite_callback ; for prepending color tags sconst "privChatUsername"
join_string 4 ; + 1 for timestamp runelite_callback
sload 2 sload 2
sload 14 sload 14
sconst "</col>" sconst "</col>"
@@ -396,15 +385,10 @@ LABEL301:
istore 7 istore 7
jump LABEL942 jump LABEL942
LABEL323: LABEL323:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sload 9 sload 9
sload 14 sload 14
sconst "</col>" sconst "</col>"
join_string 4 ; + 1 for timestamp join_string 3
iload 8 iload 8
iload 9 iload 9
iconst 10616888 iconst 10616888
@@ -420,15 +404,10 @@ LABEL323:
istore 7 istore 7
jump LABEL942 jump LABEL942
LABEL341: LABEL341:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sload 2 sload 2
sload 14 sload 14
sconst "</col>" sconst "</col>"
join_string 4 ; + 1 for timestamp join_string 3
iload 8 iload 8
iload 9 iload 9
iconst 10616888 iconst 10616888
@@ -461,17 +440,12 @@ LABEL362:
LABEL373: LABEL373:
jump LABEL942 jump LABEL942
LABEL374: LABEL374:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sconst "To " sconst "To "
sload 12 sload 12
sconst ":" sconst ":"
sconst "privateChatTo" join_string 3
runelite_callback ; for chat recolors sconst "privChatUsername"
join_string 4 ; + 1 for timestamp runelite_callback
sload 2 sload 2
sload 14 sload 14
sconst "</col>" sconst "</col>"
@@ -529,11 +503,6 @@ LABEL414:
istore 7 istore 7
jump LABEL942 jump LABEL942
LABEL432: LABEL432:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sconst "[" sconst "["
sload 5 sload 5
sload 13 sload 13
@@ -541,7 +510,7 @@ LABEL432:
sconst "] " sconst "] "
sload 12 sload 12
sconst ":" sconst ":"
join_string 8 ; + 1 for time stamp join_string 7
sload 6 sload 6
sload 14 sload 14
sconst "</col>" sconst "</col>"
@@ -623,17 +592,12 @@ LABEL485:
istore 7 istore 7
jump LABEL548 jump LABEL548
LABEL515: LABEL515:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sconst "[" sconst "["
sload 7 sload 7
sload 13 sload 13
sconst "</col>" sconst "</col>"
sconst "]" sconst "]"
join_string 6 ; + 1 for timestamp join_string 5
iconst -1 iconst -1
iconst 0 iconst 0
iconst 0 iconst 0
@@ -1003,13 +967,7 @@ LABEL845:
LABEL864: LABEL864:
jump LABEL942 jump LABEL942
LABEL865: LABEL865:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sload 14 sload 14
join_string 2
invoke 2066 invoke 2066
istore 13 istore 13
sstore 15 sstore 15
@@ -1077,13 +1035,7 @@ LABEL913:
LABEL927: LABEL927:
jump LABEL942 jump LABEL942
LABEL928: LABEL928:
iload 10 ; The id of the messageNode of the message being built
sconst ""
sconst "addTimestamp"
runelite_callback
pop_int ; pop message id
sload 14 sload 14
join_string 2 ; prepend the timestamp
iload 8 iload 8
iload 9 iload 9
iconst 10616888 iconst 10616888

View File

@@ -400,6 +400,10 @@ CHAT_FILTER:
if_icmpeq LABEL356 ; Check if we are building this message if_icmpeq LABEL356 ; Check if we are building this message
jump LABEL530 jump LABEL530
LABEL356: LABEL356:
iload 12 ; message uid
sconst "chatMessageBuilding"
runelite_callback
pop_int
iload 17 iload 17
switch switch
3: LABEL359 3: LABEL359
@@ -409,19 +413,14 @@ LABEL356:
jump LABEL446 jump LABEL446
LABEL359: LABEL359:
iload 7 iload 7
iload 12 ; Load the id of the messageNode
sconst "" ; Push a container for the timestamp
sconst "addTimestamp" ; Push event name
runelite_callback ; Invoke callback
pop_int ; Pop the id of the messageNode
sload 4 sload 4
sconst "splitPrivChatUsernameColor"
runelite_callback
sconst "From " sconst "From "
sload 1 sload 1
sconst ":" sconst ":"
sconst "privateChatSplitFrom"
runelite_callback
sconst "</col>" sconst "</col>"
join_string 6 ; Add the timestamp to the message join_string 5
sload 4 sload 4
sload 0 sload 0
sconst "</col>" sconst "</col>"
@@ -443,19 +442,14 @@ LABEL359:
jump LABEL462 jump LABEL462
LABEL385: LABEL385:
iload 7 iload 7
iload 12 ; Load the id of the messageNode
sconst "" ; Push container for the timestamp
sconst "addTimestamp" ; Push event name
runelite_callback ; Invoke callback
pop_int ; Pop the id of the messageNode
sload 4 sload 4
sconst "splitPrivChatUsernameColor"
runelite_callback
sconst "To " sconst "To "
sload 1 sload 1
sconst ":" sconst ":"
sconst "privateChatSplitTo"
runelite_callback
sconst "</col>" sconst "</col>"
join_string 6 ; Add the timestamp to the message join_string 5
sload 4 sload 4
sload 0 sload 0
sconst "</col>" sconst "</col>"
@@ -477,15 +471,10 @@ LABEL385:
jump LABEL462 jump LABEL462
LABEL411: LABEL411:
iload 7 iload 7
iload 12 ; Load the id of the messageNode sload 4
sconst "" ; Push a container for the timestamp
sconst "addTimestamp" ; Push event name
runelite_callback ; Invoke callback
pop_int ; Pop the id of the messageNode
sload 4 ; Load the log in/out message
sload 0 sload 0
sconst "</col>" sconst "</col>"
join_string 4 join_string 3
iload 9 iload 9
iload 10 iload 10
iconst 10682368 iconst 10682368