Enable nullable

This commit is contained in:
js6pak committed 2021-11-02 20:07:28 +01:00
1 parent 111ef34298
commit f8faf5117d
21 files changed
+70 -63

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ namespace Reactor
{
public delegate void PluginLoadHandler(BasePlugin plugin);
public static event PluginLoadHandler PluginLoad;
public static event PluginLoadHandler? PluginLoad;
internal static void OnPluginLoad(BasePlugin plugin)
{
+10 -6
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using UnhollowerBaseLib.Attributes;
using UnhollowerRuntimeLib;
@@ -12,7 +13,7 @@ namespace Reactor
[RegisterInIl2Cpp]
internal class Component : MonoBehaviour
{
internal static Component Instance { get; set; }
internal static Component? Instance { get; set; }
public Component(IntPtr ptr) : base(ptr)
{
@@ -47,21 +48,22 @@ namespace Reactor
return component.StartCoroutine(coroutine.Wrap());
}
public static IEnumerator Start(IEnumerator routine)
[return: NotNullIfNotNull("routine")]
public static IEnumerator? Start(IEnumerator? routine)
{
if (routine != null)
{
_ourCoroutineStore.AddOrUpdate(routine, Component.Instance.StartCoroutine(routine));
_ourCoroutineStore.AddOrUpdate(routine, Component.Instance!.StartCoroutine(routine));
}
return routine;
}
public static void Stop(IEnumerator enumerator)
public static void Stop(IEnumerator? enumerator)
{
if (enumerator != null && _ourCoroutineStore.TryGetValue(enumerator, out var routine))
{
Component.Instance.StopCoroutine(routine);
Component.Instance!.StopCoroutine(routine);
}
}
}
@@ -69,7 +71,9 @@ namespace Reactor
[RegisterInIl2Cpp(typeof(Il2CppSystem.Collections.IEnumerator))]
public sealed class CoroutineWrapper : Il2CppSystem.Object
{
#pragma warning disable 8618
public CoroutineWrapper(IntPtr ptr) : base(ptr) { }
#pragma warning restore 8618
/// <summary>
/// Creates an Il2Cpp IEnumerator with a System IEnumerator.
@@ -88,7 +92,7 @@ namespace Reactor
set;
}
public Il2CppSystem.Object Current
public Il2CppSystem.Object? Current
{
get
{
+5 -5
View File
@@ -23,7 +23,7 @@ namespace Reactor.Extensions
/// </summary>
public static void once_sceneLoaded(Action<Scene, LoadSceneMode> value)
{
UnityAction<Scene, LoadSceneMode> unityAction = null;
UnityAction<Scene, LoadSceneMode>? unityAction = null;
unityAction = (Action<Scene, LoadSceneMode>) ((scene, loadMode) =>
{
@@ -37,7 +37,7 @@ namespace Reactor.Extensions
/// <summary>
/// Returns random <typeparamref name="T"/> from <paramref name="input"/>
/// </summary>
public static T Random<T>(this IEnumerable<T> input)
public static T? Random<T>(this IEnumerable<T> input)
{
var list = input as IList<T> ?? input.ToList();
return list.Count == 0 ? default : list[UnityEngine.Random.Range(0, list.Count)];
@@ -77,9 +77,9 @@ namespace Reactor.Extensions
/// </summary>
public static Task SendAsync(this UnityWebRequest request)
{
var task = new TaskCompletionSource<object>();
var task = new TaskCompletionSource<object?>();
request.Send().m_completeCallback = (Action<AsyncOperation>) (x =>
request.Send().m_completeCallback = (Action<AsyncOperation>) (_ =>
{
task.SetResult(null);
});
@@ -115,7 +115,7 @@ namespace Reactor.Extensions
return type.GetMethods(AccessTools.all, returnType, parameterTypes);
}
public static T LoadAsset<T>(this AssetBundle assetBundle, string name) where T : UnityEngine.Object
public static T? LoadAsset<T>(this AssetBundle assetBundle, string name) where T : UnityEngine.Object
{
return assetBundle.LoadAsset(name, Il2CppType.Of<T>())?.Cast<T>();
}
+1 -1
View File
@@ -48,7 +48,7 @@ namespace Reactor.Extensions
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100f);
}
public static DefaultControls.Resources StandardResources { get; internal set; }
public static DefaultControls.Resources StandardResources { get; internal set; } = null!;
public static GameObject CreateCanvas()
{
+2
View File
@@ -12,7 +12,9 @@ namespace Reactor.Extensions
{
private readonly Stream _stream;
#pragma warning disable 8618
public StreamWrapper(IntPtr ptr) : base(ptr) { }
#pragma warning restore 8618
public StreamWrapper(Stream stream) : base(ClassInjector.DerivedConstructorPointer<StreamWrapper>())
{
+2 -2
View File
@@ -5,7 +5,7 @@ namespace Reactor
{
public sealed class Il2CppEqualityComparer<T> : IEqualityComparer<T> where T : Il2CppSystem.Object
{
private static Il2CppEqualityComparer<T> _instance;
private static Il2CppEqualityComparer<T>? _instance;
public static Il2CppEqualityComparer<T> Instance
{
@@ -25,7 +25,7 @@ namespace Reactor
return RuntimeHelpers.GetHashCode(value);
}
public bool Equals(T left, T right)
public bool Equals(T? left, T? right)
{
if (left == null || right == null)
{
+10 -10
View File
@@ -14,23 +14,23 @@ namespace Reactor.Networking
public TPlugin Plugin => (TPlugin) UnsafePlugin;
public override Type InnerNetObjectType => typeof(TInnerNetObject);
public abstract void Write(MessageWriter writer, TData data);
public abstract void Write(MessageWriter writer, TData? data);
public abstract TData Read(MessageReader reader);
public abstract void Handle(TInnerNetObject innerNetObject, TData data);
public abstract void Handle(TInnerNetObject innerNetObject, TData? data);
public override void UnsafeWrite(MessageWriter writer, object data)
public override void UnsafeWrite(MessageWriter writer, object? data)
{
Write(writer, (TData) data);
Write(writer, (TData?) data);
}
public override object UnsafeRead(MessageReader reader)
public override object? UnsafeRead(MessageReader reader)
{
return Read(reader);
}
public override void UnsafeHandle(InnerNetObject innerNetObject, object data)
public override void UnsafeHandle(InnerNetObject innerNetObject, object? data)
{
Handle((TInnerNetObject) innerNetObject, (TData) data);
Handle((TInnerNetObject) innerNetObject, (TData?) data);
}
public void Send(InnerNetObject netObject, TData data, bool immediately = false)
@@ -55,16 +55,16 @@ namespace Reactor.Networking
public abstract void Handle(TInnerNetObject innerNetObject);
public override void UnsafeWrite(MessageWriter writer, object data)
public override void UnsafeWrite(MessageWriter writer, object? data)
{
}
public override object UnsafeRead(MessageReader reader)
public override object? UnsafeRead(MessageReader reader)
{
return null;
}
public override void UnsafeHandle(InnerNetObject innerNetObject, object data)
public override void UnsafeHandle(InnerNetObject innerNetObject, object? data)
{
Handle((TInnerNetObject) innerNetObject);
}
+1 -1
View File
@@ -87,7 +87,7 @@ namespace Reactor.Networking
public static class Rpc<T> where T : UnsafeCustomRpc
{
private static T _instance;
private static T? _instance;
public static T Instance
{
+4 -4
View File
@@ -55,9 +55,9 @@ namespace Reactor.Networking.MethodRpc
public override RpcLocalHandling LocalHandling { get; }
public override SendOption SendOption { get; }
public override void UnsafeWrite(MessageWriter writer, object data)
public override void UnsafeWrite(MessageWriter writer, object? data)
{
var args = (object[]) data;
var args = (object[]) data!;
MessageSerializer.Serialize(writer, args);
}
@@ -67,9 +67,9 @@ namespace Reactor.Networking.MethodRpc
return args;
}
public override void UnsafeHandle(InnerNetObject innerNetObject, object data)
public override void UnsafeHandle(InnerNetObject innerNetObject, object? data)
{
var args = (object[]) data;
var args = (object[]) data!;
var result = Handle(innerNetObject, args);
if (result is IEnumerator enumerator)
+5 -5
View File
@@ -6,19 +6,19 @@ namespace Reactor.Networking
{
public static class ModList
{
private static Dictionary<string, Mod> _mapById;
private static Dictionary<uint, Mod> _mapByNetId;
private static Dictionary<string, Mod>? _mapById;
private static Dictionary<uint, Mod>? _mapByNetId;
public static ISet<Mod> Current { get; private set; }
public static ISet<Mod>? Current { get; private set; }
public static Mod GetById(string id)
{
return _mapById[id];
return _mapById![id];
}
public static Mod GetByNetId(uint netId)
{
return _mapByNetId[netId];
return _mapByNetId![netId];
}
internal static void Update()
+3 -3
View File
@@ -30,7 +30,7 @@ namespace Reactor.Networking.Patches
Logger<ReactorPlugin>.Info($"Connected to a modded server ({serverName} {serverVersion}, {pluginCount} plugins), sending mod declarations");
var mods = ModList.Current;
var mods = ModList.Current!;
var writer = MessageWriter.Get(SendOption.Reliable);
@@ -131,7 +131,7 @@ namespace Reactor.Networking.Patches
{
var reactorPlugin = PluginSingleton<ReactorPlugin>.Instance;
if (reactorPlugin.AllowVanillaServers.Value)
if (reactorPlugin.AllowVanillaServers!.Value)
{
if (reactorPlugin.CustomRpcManager.List.Any())
{
@@ -164,7 +164,7 @@ namespace Reactor.Networking.Patches
ModdedHandshakeC2S.Serialize(
handshake,
ModList.Current.Count
ModList.Current!.Count
);
__result = handshake.ToByteArray(false);
@@ -24,6 +24,6 @@ namespace Reactor.Networking.Serialization
public override void UnsafeWrite(MessageWriter writer, object value) => Write(writer, (T) value);
public override object UnsafeRead(MessageReader reader, Type objectType) => Read(reader, objectType);
public override object UnsafeRead(MessageReader reader, Type objectType) => Read(reader, objectType)!;
}
}
@@ -19,7 +19,7 @@ namespace Reactor.Networking.Serialization
MessageConverterMap.Clear();
}
public static UnsafeMessageConverter FindConverter(Type type)
public static UnsafeMessageConverter? FindConverter(Type type)
{
if (MessageConverterMap.TryGetValue(type, out var value))
{
+5 -5
View File
@@ -8,7 +8,7 @@ namespace Reactor.Networking
{
public abstract class UnsafeCustomRpc
{
internal CustomRpcManager Manager { get; set; }
internal CustomRpcManager? Manager { get; set; }
public uint Id { get; }
public BasePlugin UnsafePlugin { get; }
@@ -26,11 +26,11 @@ namespace Reactor.Networking
Id = id;
}
public abstract void UnsafeWrite(MessageWriter writer, object data);
public abstract object UnsafeRead(MessageReader reader);
public abstract void UnsafeHandle(InnerNetObject innerNetObject, object data);
public abstract void UnsafeWrite(MessageWriter writer, object? data);
public abstract object? UnsafeRead(MessageReader reader);
public abstract void UnsafeHandle(InnerNetObject innerNetObject, object? data);
public void UnsafeSend(InnerNetObject innerNetObject, object data, bool immediately = false, int targetClientId = -1)
public void UnsafeSend(InnerNetObject innerNetObject, object? data, bool immediately = false, int targetClientId = -1)
{
if (innerNetObject == null) throw new ArgumentNullException(nameof(innerNetObject));
+1 -1
View File
@@ -47,7 +47,7 @@ namespace Reactor.Patches
var offset = Vector3.up;
var gameObjects = toMove.Select(x => GameObject.Find("NormalMenu/" + x)).ToList();
if (gameObjects.Contains(null)) return false;
if (gameObjects.Contains(null!)) return false;
gameObjects.ForEach(x => {
x.transform.position = offset;
+4 -4
View File
@@ -12,9 +12,9 @@ namespace Reactor.Patches
{
public static class ReactorVersionShower
{
public static TextMeshPro Text { get; private set; }
public static TextMeshPro? Text { get; private set; }
public static event TextUpdatedHandler TextUpdated;
public static event TextUpdatedHandler? TextUpdated;
public delegate void TextUpdatedHandler(TextMeshPro text);
@@ -56,8 +56,8 @@ namespace Reactor.Patches
public static void UpdateText()
{
Text.text = "Reactor " + typeof(ReactorPlugin).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
Text.text += "\nBepInEx: " + Paths.BepInExVersion;
Text!.text = "Reactor " + typeof(ReactorPlugin).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
Text.text += "\nBepInEx " + Paths.BepInExVersion;
Text.text += "\nMods: " + IL2CPPChainloader.Instance.Plugins.Count;
TextUpdated?.Invoke(Text);
}
+1 -1
View File
@@ -6,7 +6,7 @@ namespace Reactor
{
public static class PluginSingleton<T> where T : BasePlugin
{
private static T _instance;
private static T? _instance;
public static T Instance => _instance ??= IL2CPPChainloader.Instance.Plugins.Values.Select(x => x.Instance).OfType<T>().Single();
+1
View File
@@ -3,6 +3,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<DebugType>embedded</DebugType>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<VersionPrefix>1.1.0</VersionPrefix>
+3 -3
View File
@@ -21,7 +21,7 @@ namespace Reactor
public Harmony Harmony { get; } = new Harmony(Id);
public CustomRpcManager CustomRpcManager { get; } = new CustomRpcManager();
public ConfigEntry<bool> AllowVanillaServers { get; private set; }
public ConfigEntry<bool>? AllowVanillaServers { get; private set; }
private RegionInfoWatcher RegionInfoWatcher { get; } = new RegionInfoWatcher();
@@ -63,7 +63,7 @@ namespace Reactor
public class ReactorComponent : MonoBehaviour
{
[HideFromIl2Cpp]
public ReactorPlugin Plugin { get; internal set; }
public ReactorPlugin? Plugin { get; internal set; }
public ReactorComponent(IntPtr ptr) : base(ptr)
{
@@ -76,7 +76,7 @@ namespace Reactor
private void Update()
{
if (Plugin.RegionInfoWatcher.Reload)
if (Plugin!.RegionInfoWatcher.Reload)
{
Plugin.RegionInfoWatcher.Reload = false;
ServerManager.Instance.LoadServers();
+1 -1
View File
@@ -33,7 +33,7 @@ namespace Reactor
var baseTypeAttribute = type.BaseType?.GetCustomAttribute<RegisterInIl2CppAttribute>();
if (baseTypeAttribute != null)
{
Register(type.BaseType, baseTypeAttribute.Interfaces);
Register(type.BaseType!, baseTypeAttribute.Interfaces);
}
if (ClassInjector.IsTypeRegisteredInIl2Cpp(type))
+8 -8
View File
@@ -8,7 +8,7 @@ namespace Reactor.Unstrip
{
public static void Load()
{
using var stream = typeof(ReactorPlugin).Assembly.GetManifestResourceStream("Reactor.Assets.default.bundle");
using var stream = typeof(ReactorPlugin).Assembly.GetManifestResourceStream("Reactor.Assets.default.bundle")!;
var bundle = AssetBundle.LoadFromStream(stream.AsIl2Cpp());
var backupShader = bundle.LoadAsset<Shader>("UI-Default");
@@ -20,13 +20,13 @@ namespace Reactor.Unstrip
GUIExtensions.StandardResources = new DefaultControls.Resources
{
background = bundle.LoadAsset<Sprite>("Background").DontUnload(),
checkmark = bundle.LoadAsset<Sprite>("Checkmark").DontUnload(),
dropdown = bundle.LoadAsset<Sprite>("DropdownArrow").DontUnload(),
knob = bundle.LoadAsset<Sprite>("Knob").DontUnload(),
mask = bundle.LoadAsset<Sprite>("UIMask").DontUnload(),
standard = bundle.LoadAsset<Sprite>("UISprite").DontUnload(),
inputField = bundle.LoadAsset<Sprite>("InputFieldBackground").DontUnload()
background = bundle.LoadAsset<Sprite>("Background")!.DontUnload(),
checkmark = bundle.LoadAsset<Sprite>("Checkmark")!.DontUnload(),
dropdown = bundle.LoadAsset<Sprite>("DropdownArrow")!.DontUnload(),
knob = bundle.LoadAsset<Sprite>("Knob")!.DontUnload(),
mask = bundle.LoadAsset<Sprite>("UIMask")!.DontUnload(),
standard = bundle.LoadAsset<Sprite>("UISprite")!.DontUnload(),
inputField = bundle.LoadAsset<Sprite>("InputFieldBackground")!.DontUnload()
};
bundle.Unload(false);