Merge branch 'upstream-master' into runelite

# Conflicts:
#	deobfuscator/src/test/java/net/runelite/deob/deobfuscators/gson/ColorTypeAdapterTest.java
#	deobfuscator/src/test/java/net/runelite/deob/deobfuscators/gson/InstantTypeAdapterTest.java
#	runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java
This commit is contained in:
zeruth
2021-02-01 12:06:49 -05:00
74 changed files with 470 additions and 115 deletions

View File

@@ -25,10 +25,16 @@
package net.runelite.http.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.awt.Color;
import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import net.runelite.http.api.gson.ColorTypeAdapter;
import net.runelite.http.api.gson.InstantTypeAdapter;
import net.runelite.http.api.gson.IllegalReflectionExclusion;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.MediaType;
@@ -46,7 +52,7 @@ public class RuneLiteAPI
public static final String RUNELITE_MACHINEID = "RUNELITE-MACHINEID";
public static final OkHttpClient CLIENT;
public static final Gson GSON = new Gson();
public static final Gson GSON;
public static final MediaType JSON = MediaType.parse("application/json");
public static String userAgent;
@@ -96,6 +102,23 @@ public class RuneLiteAPI
}
})
.build();
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder
.registerTypeAdapter(Instant.class, new InstantTypeAdapter())
.registerTypeAdapter(Color.class, new ColorTypeAdapter());
boolean assertionsEnabled = false;
assert assertionsEnabled = true;
if (assertionsEnabled)
{
IllegalReflectionExclusion jbe = new IllegalReflectionExclusion();
gsonBuilder.addSerializationExclusionStrategy(jbe);
gsonBuilder.addDeserializationExclusionStrategy(jbe);
}
GSON = gsonBuilder.create();
}
public static HttpUrl getSessionBase()

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2020 Abex
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.gson;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.awt.Color;
import java.io.IOException;
public class ColorTypeAdapter extends TypeAdapter<Color>
{
@Override
public void write(JsonWriter out, Color value) throws IOException
{
if (value == null)
{
out.nullValue();
return;
}
int rgba = value.getRGB();
out.beginObject()
.name("value")
.value(rgba)
.endObject();
}
@Override
public Color read(JsonReader in) throws IOException
{
switch (in.peek())
{
case NULL:
in.nextNull();
return null;
case BEGIN_OBJECT:
in.beginObject();
double value = 0;
while (in.peek() != JsonToken.END_OBJECT)
{
switch (in.nextName())
{
case "value":
value = in.nextDouble();
break;
default:
in.skipValue();
break;
}
}
in.endObject();
return new Color((int) value, true);
}
return null; // throws
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2020 Abex
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.gson;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import java.lang.reflect.Modifier;
public class IllegalReflectionExclusion implements ExclusionStrategy
{
@Override
public boolean shouldSkipField(FieldAttributes f)
{
if (f.getDeclaringClass().getName().startsWith("net.runelite"))
{
return false;
}
assert !Modifier.isPrivate(f.getDeclaringClass().getModifiers()) : "gsoning private class " + f.getDeclaringClass().getName();
try
{
f.getDeclaringClass().getField(f.getName());
}
catch (NoSuchFieldException e)
{
throw new AssertionError("gsoning private field " + f.getDeclaringClass() + "." + f.getName());
}
return false;
}
@Override
public boolean shouldSkipClass(Class<?> clazz)
{
return false;
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2020 Abex
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.gson;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.time.Instant;
// Just add water!
public class InstantTypeAdapter extends TypeAdapter<Instant>
{
@Override
public void write(JsonWriter out, Instant value) throws IOException
{
if (value == null)
{
out.nullValue();
return;
}
out.beginObject()
.name("seconds")
.value(value.getEpochSecond())
.name("nanos")
.value(value.getNano())
.endObject();
}
@Override
public Instant read(JsonReader in) throws IOException
{
if (in.peek() == JsonToken.NULL)
{
in.nextNull();
return null;
}
long seconds = 0;
int nanos = 0;
in.beginObject();
while (in.peek() != JsonToken.END_OBJECT)
{
switch (in.nextName())
{
case "nanos":
nanos = in.nextInt();
break;
case "seconds":
seconds = in.nextLong();
break;
}
}
in.endObject();
return Instant.ofEpochSecond(seconds, nanos);
}
}

View File

@@ -25,11 +25,11 @@
package net.runelite.http.api.ws;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.runelite.http.api.RuneLiteAPI;
import net.runelite.http.api.ws.messages.Handshake;
import net.runelite.http.api.ws.messages.LoginResponse;
import net.runelite.http.api.ws.messages.party.Join;
@@ -76,7 +76,7 @@ public class WebsocketGsonFactory
public static Gson build(final RuntimeTypeAdapterFactory<WebsocketMessage> factory)
{
return new GsonBuilder()
return RuneLiteAPI.GSON.newBuilder()
.registerTypeAdapterFactory(factory)
.create();
}