14
14
15
15
public class ClientScript extends CachedNode {
16
16
17
- private static NodeCache clientScriptCache = new NodeCache (128 );
17
+ private static NodeCache scriptCache = new NodeCache (128 );
18
18
19
19
public int [] intOperands ;
20
- public int intStackCount ;
21
- public int stringStackCount ;
22
- public int localStringCount ;
20
+ public int intArgCount ;
21
+ public int stringArgCount ;
22
+ public int stringLocalCount ;
23
23
public String [] stringOperands ;
24
- public int localIntCount ;
24
+ public int intLocalCount ;
25
25
public int [] opcodes ;
26
26
27
27
public static void clearClientScriptCache () {
28
- clientScriptCache .clear ();
28
+ scriptCache .clear ();
29
29
}
30
30
31
31
@@ -41,165 +41,163 @@ public static void clientScriptDebugger() {
41
41
}
42
42
}
43
43
44
- public static ClientScript decodeClientScript (int arg0 , int arg1 ) {
44
+ public static ClientScript get (int arg0 , int arg1 ) {
45
45
long scriptId = arg0 + (arg1 << 16 );
46
- ClientScript clientScript = (ClientScript ) clientScriptCache .get (scriptId );
47
- if ( clientScript != null ) {
48
- return clientScript ;
46
+ ClientScript script = (ClientScript ) scriptCache .get (scriptId );
47
+ if ( script != null ) {
48
+ return script ;
49
49
}
50
50
51
51
Buffer buffer = new Buffer (CacheArchive .clientScriptCacheArchive .getFileByName (arg1 + Native .comma + arg0 , Native .emptyString ));
52
- clientScript = new ClientScript ();
52
+ script = new ClientScript ();
53
53
buffer .currentPosition = buffer .buffer .length - 12 ;
54
54
int opcodeCount = buffer .getIntBE ();
55
55
int operandIndex = 0 ;
56
- clientScript . localIntCount = buffer .getUnsignedShortBE ();
57
- clientScript . localStringCount = buffer .getUnsignedShortBE ();
58
- clientScript . intStackCount = buffer .getUnsignedShortBE ();
59
- clientScript . stringStackCount = buffer .getUnsignedShortBE ();
60
- clientScript .stringOperands = new String [opcodeCount ];
61
- clientScript .intOperands = new int [opcodeCount ];
56
+ script . intLocalCount = buffer .getUnsignedShortBE ();
57
+ script . stringLocalCount = buffer .getUnsignedShortBE ();
58
+ script . intArgCount = buffer .getUnsignedShortBE ();
59
+ script . stringArgCount = buffer .getUnsignedShortBE ();
60
+ script .stringOperands = new String [opcodeCount ];
61
+ script .intOperands = new int [opcodeCount ];
62
62
buffer .currentPosition = 0 ;
63
- clientScript .opcodes = new int [opcodeCount ];
64
- while (buffer .currentPosition < -12 + buffer .buffer .length ) {
63
+ script .opcodes = new int [opcodeCount ];
64
+ while (buffer .currentPosition < -12 + buffer .buffer .length ) {
65
65
int opcode = buffer .getUnsignedShortBE ();
66
- if (opcode == 3 ) {
67
- clientScript .stringOperands [operandIndex ] = buffer .getString ();
68
- } else if (opcode >= 100 || opcode == 21 || opcode == 38 || opcode == 39 ) {
69
- clientScript .intOperands [operandIndex ] = buffer .getUnsignedByte ();
66
+ if (opcode == 3 ) {
67
+ script .stringOperands [operandIndex ] = buffer .getString ();
68
+ } else if (opcode >= 100 || opcode == 21 || opcode == 38 || opcode == 39 ) {
69
+ script .intOperands [operandIndex ] = buffer .getUnsignedByte ();
70
70
} else {
71
- clientScript .intOperands [operandIndex ] = buffer .getIntBE ();
71
+ script .intOperands [operandIndex ] = buffer .getIntBE ();
72
72
}
73
- clientScript .opcodes [operandIndex ++] = opcode ;
73
+ script .opcodes [operandIndex ++] = opcode ;
74
74
}
75
75
System .out .println ("Caching script " + scriptId );
76
- clientScriptCache .put (scriptId , clientScript );
77
- return clientScript ;
76
+ scriptCache .put (scriptId , script );
77
+ return script ;
78
78
}
79
79
80
-
81
- public static int parseClientScripts (int scriptIndex , GameInterface gameInterface1 ) {
82
- if (gameInterface1 . clientScripts == null || scriptIndex >= gameInterface1 . clientScripts .length ) {
80
+ // execute if1 scripts (would be ideal to put this into another class ala Cs1ScriptRunner)
81
+ public static int run (int id , GameInterface component ) {
82
+ if (component . scripts == null || id >= component . scripts .length ) {
83
83
return -2 ;
84
84
}
85
+
85
86
try {
86
- int [] opcodes = gameInterface1 . clientScripts [ scriptIndex ];
87
- int i = 0 ;
88
- int scriptDataIndex = 0 ;
87
+ int [] script = component . scripts [ id ];
88
+ int accumulator = 0 ;
89
+ int pc = 0 ;
89
90
int operator = 0 ;
91
+
90
92
while (true ) {
91
- int operand = 0 ;
92
- int nextOperator = 0 ;
93
- int opcode = opcodes [scriptDataIndex ++];
93
+ int value = 0 ;
94
+ int nextAccumulatorMode = 0 ;
95
+ int opcode = script [pc ++];
96
+
94
97
if (opcode == 0 ) {
95
- return i ;
96
- }
97
- if (opcode == 15 ) {
98
- nextOperator = 1 ;
99
- }
100
- if (opcode == 16 ) {
101
- nextOperator = 2 ;
98
+ return accumulator ;
102
99
}
100
+
103
101
if (opcode == 1 ) {
104
- operand = Player .playerLevels [opcodes [scriptDataIndex ++]];
105
- }
106
- if (opcode == 2 ) {
107
- operand = Player .nextLevels [opcodes [scriptDataIndex ++]];
108
- }
109
- if (opcode == 3 ) {
110
- operand = Player .playerExperience [opcodes [scriptDataIndex ++]];
111
- }
112
- if (opcode == 17 ) {
113
- nextOperator = 3 ;
114
- }
115
- if (opcode == 4 ) {
116
- int i_19_ = opcodes [scriptDataIndex ++] << 16 ;
117
- i_19_ += opcodes [scriptDataIndex ++];
118
- GameInterface gameInterface = GameInterface .getInterface (i_19_ );
119
- int i_20_ = opcodes [scriptDataIndex ++];
120
- if (i_20_ != -1 && (!ItemDefinition .forId (i_20_ , 10 ).members || MovedStatics .membersWorld )) {
121
- for (int i_21_ = 0 ; i_21_ < gameInterface .items .length ; i_21_ ++) {
122
- if (1 + i_20_ == gameInterface .items [i_21_ ]) {
123
- operand += gameInterface .itemAmounts [i_21_ ];
102
+ // stat_level
103
+ value = Player .boostedLevels [script [pc ++]];
104
+ } else if (opcode == 2 ) {
105
+ // stat_base_level
106
+ value = Player .baseLevels [script [pc ++]];
107
+ } else if (opcode == 3 ) {
108
+ // stat_xp
109
+ value = Player .experience [script [pc ++]];
110
+ } else if (opcode == 4 ) {
111
+ // inv_count
112
+ int componentId = script [pc ++] << 16 ;
113
+ componentId += script [pc ++];
114
+ GameInterface otherComponent = GameInterface .getInterface (componentId );
115
+ int objType = script [pc ++];
116
+ if (objType != -1 && (!ItemDefinition .forId (objType , 10 ).members || MovedStatics .membersWorld )) {
117
+ for (int slot = 0 ; slot < otherComponent .invSlotObjId .length ; slot ++) {
118
+ if (otherComponent .invSlotObjId [slot ] == objType + 1 ) {
119
+ value += otherComponent .invSlotObjCount [slot ];
124
120
}
125
121
}
126
122
}
127
- }
128
- if (opcode == 5 ) {
129
- int temp = opcodes [scriptDataIndex ++];
130
- operand = VarPlayerDefinition .varPlayers [temp ];
131
- }
132
- if (opcode == 6 ) {
133
- operand = Player .experienceForLevels [-1 + Player .nextLevels [opcodes [scriptDataIndex ++]]];
134
- }
135
- if (opcode == 7 ) {
136
- int varPlayerIndex = opcodes [scriptDataIndex ++];
137
- operand = 100 * VarPlayerDefinition .varPlayers [varPlayerIndex ] / 46875 ;
138
- }
139
- if (opcode == 8 ) {
140
- operand = Player .localPlayer .combatLevel ;
141
- }
142
- if (opcode == 9 ) {
143
- for (int i_22_ = 0 ; i_22_ < 25 ; i_22_ ++) {
144
- if (ClientScriptRunner .aBooleanArray548 [i_22_ ]) {
145
- operand += Player .nextLevels [i_22_ ];
123
+ } else if (opcode == 5 ) {
124
+ // testvar
125
+ int temp = script [pc ++];
126
+ value = VarPlayerDefinition .varPlayers [temp ];
127
+ } else if (opcode == 6 ) {
128
+ // stat_xp_remaining
129
+ value = Player .experienceForLevels [-1 + Player .baseLevels [script [pc ++]]];
130
+ } else if (opcode == 7 ) {
131
+ int varPlayerIndex = script [pc ++];
132
+ value = 100 * VarPlayerDefinition .varPlayers [varPlayerIndex ] / 46875 ;
133
+ } else if (opcode == 8 ) {
134
+ // comlevel
135
+ value = Player .localPlayer .combatLevel ;
136
+ } else if (opcode == 9 ) {
137
+ // stat_total
138
+ for (int skill = 0 ; skill < 25 ; skill ++) {
139
+ if (ClientScriptRunner .ENABLED_SKILLS [skill ]) {
140
+ value += Player .baseLevels [skill ];
146
141
}
147
142
}
148
- }
149
- if ( opcode == 10 ) {
150
- int i_23_ = opcodes [ scriptDataIndex ++] << 16 ;
151
- i_23_ += opcodes [ scriptDataIndex ++];
152
- GameInterface gameInterface = GameInterface .getInterface (i_23_ );
153
- int i_24_ = opcodes [ scriptDataIndex ++];
154
- if (i_24_ != -1 && (!ItemDefinition .forId (i_24_ , 10 ).members || MovedStatics .membersWorld )) {
155
- for (int i_25_ = 0 ; gameInterface . items .length > i_25_ ; i_25_ ++) {
156
- if (i_24_ + 1 == gameInterface . items [ i_25_ ]) {
157
- operand = 999999999 ;
143
+ } else if ( opcode == 10 ) {
144
+ // inv_contains
145
+ int componentId = script [ pc ++] << 16 ;
146
+ componentId += script [ pc ++];
147
+ GameInterface otherComponent = GameInterface .getInterface (componentId );
148
+ int objType = script [ pc ++];
149
+ if (objType != -1 && (!ItemDefinition .forId (objType , 10 ).members || MovedStatics .membersWorld )) {
150
+ for (int slot = 0 ; otherComponent . invSlotObjId .length > slot ; slot ++) {
151
+ if (objType + 1 == otherComponent . invSlotObjId [ slot ]) {
152
+ value = 999999999 ;
158
153
break ;
159
154
}
160
155
}
161
156
}
157
+ } else if (opcode == 11 ) {
158
+ // runenergy
159
+ value = ClientScriptRunner .runEnergy ;
160
+ } else if (opcode == 12 ) {
161
+ // runweight
162
+ value = MovedStatics .runWeight ;
163
+ } else if (opcode == 13 ) {
164
+ // testbit
165
+ int varpValue = VarPlayerDefinition .varPlayers [script [pc ++]];
166
+ int bit = script [pc ++];
167
+ value = (1 << bit & varpValue ) != 0 ? 1 : 0 ;
168
+ } else if (opcode == 14 ) {
169
+ // getvarbit
170
+ int varbit = script [pc ++];
171
+ value = VarbitDefinition .getVarbitValue (varbit );
172
+ } else if (opcode == 15 ) {
173
+ nextAccumulatorMode = 1 ;
174
+ } else if (opcode == 16 ) {
175
+ nextAccumulatorMode = 2 ;
176
+ } else if (opcode == 17 ) {
177
+ nextAccumulatorMode = 3 ;
178
+ } else if (opcode == 18 ) {
179
+ value = (Player .localPlayer .worldX >> 7 ) + MovedStatics .baseX ;
180
+ } else if (opcode == 19 ) {
181
+ value = (Player .localPlayer .worldY >> 7 ) + MovedStatics .baseY ;
182
+ } else if (opcode == 20 ) {
183
+ // push_int
184
+ value = script [pc ++];
162
185
}
163
- if (opcode == 11 ) {
164
- operand = ClientScriptRunner .runEnergy ;
165
- }
166
- if (opcode == 12 ) {
167
- operand = MovedStatics .carryWeight ;
168
- }
169
- if (opcode == 13 ) {
170
- int varPlayerValue = VarPlayerDefinition .varPlayers [opcodes [scriptDataIndex ++]];
171
- int leastSignificantBit = opcodes [scriptDataIndex ++];
172
- operand = (1 << leastSignificantBit & varPlayerValue ) != 0 ? 1 : 0 ;
173
- }
174
- if (opcode == 14 ) {
175
- int varbitId = opcodes [scriptDataIndex ++];
176
- operand = VarbitDefinition .getVarbitValue (varbitId );
177
- }
178
- if (opcode == 18 ) {
179
- operand = (Player .localPlayer .worldX >> 7 ) + MovedStatics .baseX ;
180
- }
181
- if (opcode == 19 ) {
182
- operand = (Player .localPlayer .worldY >> 7 ) + MovedStatics .baseY ;
183
- }
184
- if (opcode == 20 ) {
185
- operand = opcodes [scriptDataIndex ++];
186
- }
187
- if (nextOperator == 0 ) {
186
+
187
+ if (nextAccumulatorMode == 0 ) {
188
188
if (operator == 0 ) {
189
- i += operand ;
190
- }
191
- if (operator == 1 ) {
192
- i -= operand ;
193
- }
194
- if (operator == 2 && operand != 0 ) {
195
- i /= operand ;
196
- }
197
- if (operator == 3 ) {
198
- i *= operand ;
189
+ accumulator += value ;
190
+ } else if (operator == 1 ) {
191
+ accumulator -= value ;
192
+ } else if (operator == 2 && value != 0 ) {
193
+ accumulator /= value ;
194
+ } else if (operator == 3 ) {
195
+ accumulator *= value ;
199
196
}
197
+
200
198
operator = 0 ;
201
199
} else {
202
- operator = nextOperator ;
200
+ operator = nextAccumulatorMode ;
203
201
}
204
202
}
205
203
} catch (Exception exception ) {
0 commit comments