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

View File

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

View File

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

View File

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