Originally Posted by
Shatterhand
Nice. That confirms it. Took this long to actually realise what was happening (wasn't sure if the client modified the existing array or not)..
Problem: The assignment does not clone the array. Changes made to one is made to the other automatically. Basically, what you have is an atomic reference. Remember that even though it's an array of primitive, assignments are always referenced. As shown here..
Java Code:
package test;import java.lang.reflect.Field;public class Test
{ static int[] test
= {1,
2,
3,
4}; public static void main
(String[] args
) { int[] arr
= (int[])getClassFieldObject
("test.Test",
"test",
null); test
[2] = 5; //change the value in one array, it changes in both.. for (int i
= 0; i
< arr.
length; ++i
) { if (arr
[i
] != test
[i
]) //comparison fails because both arrays contain the same information. System.
out.
println(arr
[i
]); } }}
Now compare the above to:
Java Code:
static int[] test
= {1,
2,
3,
4}; public static void main
(String[] args
) { int[] arr
= (int[])getClassFieldObject
("test.Test",
"test",
null); test
= new int[]{1,
2,
3,
5}; //still only one value change but it does not affect the other array. for (int i
= 0; i
< arr.
length; ++i
) { if (arr
[i
] != test
[i
]) //comparison succeeds because they are two different arrays now.. System.
out.
println(arr
[i
]); } }
I know this is a reference problem because that's what your assignment operator does: settings = currentSettings; does not copy the array like you think it would. It simply takes the address of it, store it and increases the array's reference count.
You can tell this is happening because no matter how many times you change your spec, the settings array always has the same value as the currentSettings array.. and so the comparison fails. Jagex does not create a new array.. rather they just modify the already existing static one and the changes are also done to your array as well..
As to why it fails when you use "==", that I'm not sure of as it does not happen in the above example.. It should not fail with both "!=" and "==". That can't be. It's either one or the other. Could always be that the compiler optimised out the for-loop after realising you're doing self comparison but I highly doubt that..
Try cloning/copying the array instead and see if it works. (Ex: settings = currentSettings.clone()).