-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlinktothefast.lic
143 lines (111 loc) · 4.96 KB
/
linktothefast.lic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
=begin
Stormfront performance is negatively affected by links, but it handles highlights just fine.
linktothefast wraps all links with XML that says to use the link-colored preset, so you still get the benefits of
link colors even while links are turned off. Then you can turn links off (default: Alt+L) to gain better performance
in StormFront and just toggle them on if needed.
;autostart add --global linktothefast
author: LostRanger (thisgenericname@gmail.com)
game: any
tags: utility
version: 0.1.4 (2019-09-27)
changelog:
version 0.1.4 (2019-09-27)
* Fix assorted issues when multiple linkables are within a preset, like when people talk to animals.
version 0.1.3 (2019-09-27)
* Now prompts for trust on Ruby installs BEFORE breaking things.
version 0.1.2 (2019-09-25)
* Now prompts for trust on Ruby installs that need it.
* Handles cases where multiple links existed within one preset (i.e. directed speech)
version 0.1.1 (2019-09-25)
* Approximately 94% less broken
* Supports recolor.
version 0.1 (2019-09-25)
* Initial release
=end
=begin
HERE THERE BE DRAGONS
Welcome, curious source-diver!
This script does a few things unconventionally. The way it modifies output could potentially break other scripts that
are relying on DownstreamHook if they hook after LinkToTheFast does. To prevent this and ensure we always run last, we
take the unconventional step of modifying DownstreamHook itself.
This is NOT the recommended way of doing things normally, and you should NOT use this script as a general example on
how to modify output from the game. Also, the implementation route here may not work particularly well if multiple
scripts try to do it.
Otherwise, enjoy!
--LostRanger
=end
unless $SAFE == 0
echo "This script must be trusted due to the modifications it makes to Lich."
echo "You can trust it with the following command: #{$lich_char}trust #{script.name}"
exit
end
# Remove all of our patches when we die.
before_dying do
class <<DownstreamHook
undef_method :run
alias_method :run, :original_run
end
end
class <<DownstreamHook
alias_method :original_run, :run
def run(server_string)
# Follow Lich's normal DownstreamHook.run
server_string = original_run(server_string)
return server_string unless server_string
server_string = server_string.dup
# First, add presets around all links. If this does nothing, bail.
return server_string unless server_string.gsub!(/(<[ad](?: [^>]*)?>.*?<\/[ad]>)/, "<preset id='link'>\\1</preset>")
# Strip any of our freshly-added presets that occur during monsterbold, because in SF, bolded links use the
# bold formatting rather than a mix of the two and that ceases to be true if a preset is applied.
server_string.gsub!(/<pushBold\s*\/>.*?<popBold\s*\/>/) do |s|
s.gsub(/<preset id='link'>(.*?)<\/preset>/, "\\1")
end
# Do the above for regular bold text too, which SF supports.
server_string.gsub!(/<b\s*>.*?<\/b\s*>/) do |s|
s.gsub(/<preset id='link'>(.*?)<\/preset>/, "\\1")
end
# Recolor and speech use presets. We use presets. Links within a preset normally follow the preset color,
# so we need to strip any links we add within a preset...
#
# For performance reasons, and since we're unlikely to have 32 nested presets unless a script is misbehaving...
# We cheat and use an int as a stack of booleans
stack = 0
server_string.gsub!(/<\/?preset([^>]*)>/) do |tag|
if tag[1] == 'p' then # Opening tag
stack <<= 1 # Push next bits.
if stack == 0 or $1 != " id='link'"
# Stack is empty, or it wasn't a link.
stack |= 1
next tag
else
next ''
end
elsif stack == 0 then # Stack underflow. Silently ignore it.
next tag
elsif stack&1 == 1
stack >>= 1
next tag
else
stack >>= 1
next ''
end
end
return server_string
#
# This technically won't work if more than one preset is nested inside one, but that should be fine.
# (To future me from year 2030: I'm sorry!)
echo server_string if server_string.include?("Caendria")
nil while server_string.gsub!(
/(<preset(?:\s[^>]*)?>(?:(?!<\/preset\s*>).)*)<preset id='link'>(.*?)<\/preset\s*>/,
"\\1\\2"
)
echo server_string if server_string.include?("Caendria")
return server_string
end
end
unless $frontend == 'stormfront'
echo "Wait, this isn't StormFront. I'm probably only useful with StormFront, but you're welcome to try..."
end
echo "version 0.1.4 (2019-09-27) started. Stop me with #{$lich_char}kill #{script.name}"
hide_me
sleep