diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..027192c6 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,34 @@ +name: Build + +on: + push: + branches: [dev] + pull_request: + workflow_dispatch: + +jobs: + build: + if: (github.event_name == 'pull_request' && github.event.pull_request.merged != 'true') || github.event_name == 'push' + runs-on: windows-latest + steps: + + # Replace / with _ in ref name so that it can be used in a filename + - uses: mad9000/actions-find-and-replace-string@2 + id: sanitizeRef + with: + source: ${{ github.ref_name }} + find: '/' + replace: '_' + # Get short-sha so that it can be used in a filename + - uses: benjlevesque/short-sha@v1.2 + id: short-sha + + - uses: actions/checkout@v2 + - uses: actions/setup-dotnet@v1 + with: + dotnet-version: "5.0.x" + - run: dotnet build -c Release + - uses: actions/upload-artifact@v2 + with: + name: QSB-${{ steps.sanitizeRef.outputs.value }}-${{ steps.short-sha.outputs.sha }} + path: .\QSB\Bin\Release \ No newline at end of file diff --git a/.gitignore b/.gitignore index f8963d8c..8a1664ce 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +.idea + # User-specific files *.rsuser *.suo @@ -365,3 +367,7 @@ IgnoreInGithub/ OWML.Config.json WeavedFiles/QSB.dll WeavedFiles/QSB.dll.mdb +qsb-unityproject + +# User specific locations +DevEnv.targets diff --git a/AssetBundles/conversation b/AssetBundles/conversation deleted file mode 100644 index 05538ff9..00000000 Binary files a/AssetBundles/conversation and /dev/null differ diff --git a/AssetBundles/debug b/AssetBundles/debug deleted file mode 100644 index 71c1eeac..00000000 Binary files a/AssetBundles/debug and /dev/null differ diff --git a/AssetBundles/debug.manifest b/AssetBundles/debug.manifest deleted file mode 100644 index 494f867b..00000000 --- a/AssetBundles/debug.manifest +++ /dev/null @@ -1,49 +0,0 @@ -ManifestFileVersion: 0 -CRC: 3095198160 -Hashes: - AssetFileHash: - serializedVersion: 2 - Hash: 44badca86c2222e5cc39a8497439be0c - TypeTreeHash: - serializedVersion: 2 - Hash: b2ece8ae09df261ff59d764d08696641 -HashAppended: 0 -ClassTypes: -- Class: 1 - Script: {instanceID: 0} -- Class: 4 - Script: {instanceID: 0} -- Class: 21 - Script: {instanceID: 0} -- Class: 23 - Script: {instanceID: 0} -- Class: 28 - Script: {instanceID: 0} -- Class: 33 - Script: {instanceID: 0} -- Class: 43 - Script: {instanceID: 0} -- Class: 48 - Script: {instanceID: 0} -- Class: 114 - Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} -- Class: 114 - Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} -- Class: 115 - Script: {instanceID: 0} -- Class: 128 - Script: {instanceID: 0} -- Class: 222 - Script: {instanceID: 0} -- Class: 223 - Script: {instanceID: 0} -- Class: 224 - Script: {instanceID: 0} -SerializeReferenceClassIdentifiers: [] -Assets: -- Assets/Cube.prefab -- Assets/Capsule.prefab -- Assets/DebugVis.mat -- Assets/LogCanvas.prefab -- Assets/Sphere.prefab -Dependencies: [] diff --git a/AssetBundles/instruments b/AssetBundles/instruments deleted file mode 100644 index 0a4958b0..00000000 Binary files a/AssetBundles/instruments and /dev/null differ diff --git a/AssetBundles/instruments.manifest b/AssetBundles/instruments.manifest deleted file mode 100644 index c13bb169..00000000 --- a/AssetBundles/instruments.manifest +++ /dev/null @@ -1,34 +0,0 @@ -ManifestFileVersion: 0 -CRC: 2593345828 -Hashes: - AssetFileHash: - serializedVersion: 2 - Hash: d97fbc9cde41b6514223a2f68ba96af8 - TypeTreeHash: - serializedVersion: 2 - Hash: ff0e1233df027a80b5add90668c49830 -HashAppended: 0 -ClassTypes: -- Class: 43 - Script: {instanceID: 0} -- Class: 74 - Script: {instanceID: 0} -- Class: 91 - Script: {instanceID: 0} -Assets: -- Assets/Riebeck/Idle_to_playing.anim -- Assets/Chert/Chert_Drum_Panicked.anim -- Assets/Riebeck/Traveller_Riebeck.controller -- Assets/Chert/Traveller_Chert.controller -- Assets/Chert/Chert_Drum_Chipper.anim -- Assets/Riebeck/Riebeck_DreamIdle.anim -- Assets/Chert/Chert_Chatter_Chipper.anim -- Assets/Riebeck/Riebeck_Playing.anim -- Assets/Chert/Chert_Chatter_Panicked.anim -- Assets/Chert/Chert_Chatter_Nervous.anim -- Assets/Chert/hourglasstwinsmeshescharacters2.asset -- Assets/Riebeck/Playing_banjo.anim -- Assets/Riebeck/Playing_to_idle.anim -- Assets/Chert/Chert_Dream.anim -- Assets/Riebeck/Riebeck_Talking.anim -Dependencies: [] diff --git a/AssetBundles/network b/AssetBundles/network deleted file mode 100644 index b5f3712f..00000000 Binary files a/AssetBundles/network and /dev/null differ diff --git a/AssetBundles/network.manifest b/AssetBundles/network.manifest deleted file mode 100644 index a4d9d43c..00000000 --- a/AssetBundles/network.manifest +++ /dev/null @@ -1,30 +0,0 @@ -ManifestFileVersion: 0 -CRC: 1991351671 -Hashes: - AssetFileHash: - serializedVersion: 2 - Hash: e0f93ad04981fd266a4300b0be721792 - TypeTreeHash: - serializedVersion: 2 - Hash: 6968c5d2bbef57a79632abd61ea01bb3 -HashAppended: 0 -ClassTypes: -- Class: 1 - Script: {instanceID: 0} -- Class: 4 - Script: {instanceID: 0} -- Class: 114 - Script: {fileID: 372142912, guid: 93b08009869340045a8e7321508b6355, type: 3} -- Class: 114 - Script: {fileID: -1768714887, guid: 93b08009869340045a8e7321508b6355, type: 3} -- Class: 114 - Script: {fileID: -1267208747, guid: 93b08009869340045a8e7321508b6355, type: 3} -- Class: 115 - Script: {instanceID: 0} -SerializeReferenceClassIdentifiers: [] -Assets: -- Assets/NetworkProbe.prefab -- Assets/NETWORK_Player_Body.prefab -- Assets/NetworkOrb.prefab -- Assets/NetworkShip.prefab -Dependencies: [] diff --git a/DevEnv.targets.example b/DevEnv.targets.example new file mode 100644 index 00000000..76f604d8 --- /dev/null +++ b/DevEnv.targets.example @@ -0,0 +1,8 @@ + + + + C:\Program Files\Epic Games\OuterWilds + $(AppData)\OuterWildsModManager\OWML + $(SolutionDir)\qsb-unityproject\Assets + + \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 00000000..8165de0a --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,33 @@ + + + + + $(MSBuildThisFileDirectory)DevEnv.targets + + + + + net48 + true + 9 + false + false + false + bin\$(Configuration)\QSB + $(OwmlDir)\Mods\QSB + en-GB + Henry Pointer, Aleksander Waage, Ricardo Lopes + Copyright © Henry Pointer, Aleksander Waage, Ricardo Lopes 2020-2021 + + + + C:\Program Files\Epic Games\OuterWilds + $(AppData)\OuterWildsModManager\OWML + $(SolutionDir)\qsb-unityproject\Assets + + + + + + + \ No newline at end of file diff --git a/QNetWeaver/Helpers.cs b/QNetWeaver/Helpers.cs deleted file mode 100644 index aed3161d..00000000 --- a/QNetWeaver/Helpers.cs +++ /dev/null @@ -1,236 +0,0 @@ -using Mono.Cecil; -using Mono.Cecil.Cil; -using Mono.Cecil.Mdb; -using Mono.Cecil.Pdb; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; - -namespace QNetWeaver -{ - internal class Helpers - { - public static string UnityEngineDLLDirectoryName() - { - var directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); - return (directoryName == null) ? null : directoryName.Replace("file:\\", ""); - } - - public static ISymbolReaderProvider GetSymbolReaderProvider(string inputFile) - { - var text = inputFile.Substring(0, inputFile.Length - 4); - ISymbolReaderProvider result; - if (File.Exists(text + ".pdb")) - { - Console.WriteLine("Symbols will be read from " + text + ".pdb"); - result = new PdbReaderProvider(); - } - else if (File.Exists(text + ".dll.mdb")) - { - Console.WriteLine("Symbols will be read from " + text + ".dll.mdb"); - result = new MdbReaderProvider(); - } - else - { - Console.WriteLine("No symbols for " + inputFile); - result = null; - } - - return result; - } - - public static bool InheritsFromSyncList(TypeReference typeRef) - { - try - { - if (typeRef.IsValueType) - { - return false; - } - - foreach (var typeReference in ResolveInheritanceHierarchy(typeRef)) - { - if (typeReference.IsGenericInstance) - { - var typeDefinition = typeReference.Resolve(); - if (typeDefinition.HasGenericParameters && typeDefinition.FullName == Weaver.SyncListType.FullName) - { - return true; - } - } - } - } - catch - { - } - - return false; - } - - public static IEnumerable ResolveInheritanceHierarchy(TypeReference type) - { - if (type.IsValueType) - { - yield return type; - yield return Weaver.valueTypeType; - yield return Weaver.objectType; - yield break; - } - - while (type != null && type.FullName != Weaver.objectType.FullName) - { - yield return type; - try - { - var typeDefinition = type.Resolve(); - if (typeDefinition == null) - { - break; - } - - type = typeDefinition.BaseType; - } - catch - { - break; - } - } - - yield return Weaver.objectType; - yield break; - } - - public static string DestinationFileFor(string outputDir, string assemblyPath) - { - var fileName = Path.GetFileName(assemblyPath); - return Path.Combine(outputDir, fileName); - } - - public static string PrettyPrintType(TypeReference type) - { - string result; - if (type.IsGenericInstance) - { - var genericInstanceType = (GenericInstanceType)type; - var text = genericInstanceType.Name.Substring(0, genericInstanceType.Name.Length - 2); - var text2 = "<"; - var text3 = ", "; - IEnumerable genericArguments = genericInstanceType.GenericArguments; - result = text + text2 + string.Join(text3, Enumerable.ToArray(Enumerable.Select(genericArguments, new Func(PrettyPrintType)))) + ">"; - } - else if (type.HasGenericParameters) - { - result = type.Name.Substring(0, type.Name.Length - 2) + "<" + string.Join(", ", Enumerable.ToArray(Enumerable.Select(type.GenericParameters, (GenericParameter x) => x.Name))) + ">"; - } - else - { - result = type.Name; - } - - return result; - } - - public static ReaderParameters ReaderParameters(string assemblyPath, IEnumerable extraPaths, IAssemblyResolver assemblyResolver, string unityEngineDLLPath, string unityUNetDLLPath) - { - var readerParameters = new ReaderParameters(); - if (assemblyResolver == null) - { - assemblyResolver = new DefaultAssemblyResolver(); - } - - var addSearchDirectoryHelper = new Helpers.AddSearchDirectoryHelper(assemblyResolver); - addSearchDirectoryHelper.AddSearchDirectory(Path.GetDirectoryName(assemblyPath)); - addSearchDirectoryHelper.AddSearchDirectory(UnityEngineDLLDirectoryName()); - addSearchDirectoryHelper.AddSearchDirectory(Path.GetDirectoryName(unityEngineDLLPath)); - addSearchDirectoryHelper.AddSearchDirectory(Path.GetDirectoryName(unityUNetDLLPath)); - if (extraPaths != null) - { - foreach (var directory in extraPaths) - { - addSearchDirectoryHelper.AddSearchDirectory(directory); - } - } - - readerParameters.AssemblyResolver = assemblyResolver; - readerParameters.SymbolReaderProvider = GetSymbolReaderProvider(assemblyPath); - return readerParameters; - } - - public static WriterParameters GetWriterParameters(ReaderParameters readParams) - { - var writerParameters = new WriterParameters(); - if (readParams.SymbolReaderProvider is PdbReaderProvider) - { - writerParameters.SymbolWriterProvider = new PdbWriterProvider(); - } - else if (readParams.SymbolReaderProvider is MdbReaderProvider) - { - writerParameters.SymbolWriterProvider = new MdbWriterProvider(); - } - - return writerParameters; - } - - public static TypeReference MakeGenericType(TypeReference self, params TypeReference[] arguments) - { - if (self.GenericParameters.Count != arguments.Length) - { - throw new ArgumentException(); - } - - var genericInstanceType = new GenericInstanceType(self); - foreach (var item in arguments) - { - genericInstanceType.GenericArguments.Add(item); - } - - return genericInstanceType; - } - - public static MethodReference MakeHostInstanceGeneric(MethodReference self, params TypeReference[] arguments) - { - var methodReference = new MethodReference(self.Name, self.ReturnType, MakeGenericType(self.DeclaringType, arguments)) - { - HasThis = self.HasThis, - ExplicitThis = self.ExplicitThis, - CallingConvention = self.CallingConvention - }; - foreach (var parameterDefinition in self.Parameters) - { - methodReference.Parameters.Add(new ParameterDefinition(parameterDefinition.ParameterType)); - } - - foreach (var genericParameter in self.GenericParameters) - { - methodReference.GenericParameters.Add(new GenericParameter(genericParameter.Name, methodReference)); - } - - return methodReference; - } - - private class AddSearchDirectoryHelper - { - public AddSearchDirectoryHelper(IAssemblyResolver assemblyResolver) - { - var method = assemblyResolver.GetType().GetMethod("AddSearchDirectory", (BindingFlags)20, null, new Type[] - { - typeof(string) - }, null); - if (method == null) - { - throw new Exception("Assembly resolver doesn't implement AddSearchDirectory method."); - } - - _addSearchDirectory = (Helpers.AddSearchDirectoryHelper.AddSearchDirectoryDelegate)Delegate.CreateDelegate(typeof(Helpers.AddSearchDirectoryHelper.AddSearchDirectoryDelegate), assemblyResolver, method); - } - - public void AddSearchDirectory(string directory) => _addSearchDirectory(directory); - - private readonly Helpers.AddSearchDirectoryHelper.AddSearchDirectoryDelegate _addSearchDirectory; - - private delegate void AddSearchDirectoryDelegate(string directory); - } - } -} diff --git a/QNetWeaver/Log.cs b/QNetWeaver/Log.cs deleted file mode 100644 index 7e358fae..00000000 --- a/QNetWeaver/Log.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace QNetWeaver -{ - public static class Log - { - public static void Warning(string msg) - { - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine($"WARN : {msg}"); - Console.ResetColor(); - } - - public static void Error(string msg) - { - Console.ForegroundColor = ConsoleColor.DarkRed; - Console.WriteLine($"ERR : {msg}"); - Console.ResetColor(); - } - } -} diff --git a/QNetWeaver/MessageClassProcessor.cs b/QNetWeaver/MessageClassProcessor.cs deleted file mode 100644 index 9e4ffe7e..00000000 --- a/QNetWeaver/MessageClassProcessor.cs +++ /dev/null @@ -1,174 +0,0 @@ -using Mono.Cecil; -using Mono.Cecil.Cil; - -namespace QNetWeaver -{ - internal class MessageClassProcessor - { - public MessageClassProcessor(TypeDefinition td) - { - Weaver.DLog(td, "MessageClassProcessor for " + td.Name, new object[0]); - m_td = td; - } - - public void Process() - { - Weaver.DLog(m_td, "MessageClassProcessor Start", new object[0]); - Weaver.ResetRecursionCount(); - GenerateSerialization(); - if (!Weaver.fail) - { - GenerateDeSerialization(); - Weaver.DLog(m_td, "MessageClassProcessor Done", new object[0]); - } - } - - private void GenerateSerialization() - { - Weaver.DLog(m_td, " MessageClass GenerateSerialization", new object[0]); - foreach (var methodDefinition in m_td.Methods) - { - if (methodDefinition.Name == "Serialize") - { - Weaver.DLog(m_td, " Abort - is Serialize", new object[0]); - return; - } - } - - if (m_td.Fields.Count != 0) - { - foreach (var fieldDefinition in m_td.Fields) - { - if (fieldDefinition.FieldType.FullName == m_td.FullName) - { - Weaver.fail = true; - Log.Error(string.Concat(new string[] - { - "GenerateSerialization for ", - m_td.Name, - " [", - fieldDefinition.FullName, - "]. [MessageBase] member cannot be self referencing." - })); - return; - } - } - - var methodDefinition2 = new MethodDefinition("Serialize", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, Weaver.voidType); - methodDefinition2.Parameters.Add(new ParameterDefinition("writer", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkWriterType))); - var ilprocessor = methodDefinition2.Body.GetILProcessor(); - foreach (var fieldDefinition2 in m_td.Fields) - { - if (!fieldDefinition2.IsStatic && !fieldDefinition2.IsPrivate && !fieldDefinition2.IsSpecialName) - { - if (fieldDefinition2.FieldType.Resolve().HasGenericParameters) - { - Weaver.fail = true; - Log.Error(string.Concat(new object[] - { - "GenerateSerialization for ", - m_td.Name, - " [", - fieldDefinition2.FieldType, - "/", - fieldDefinition2.FieldType.FullName, - "]. [MessageBase] member cannot have generic parameters." - })); - return; - } - - if (fieldDefinition2.FieldType.Resolve().IsInterface) - { - Weaver.fail = true; - Log.Error(string.Concat(new object[] - { - "GenerateSerialization for ", - m_td.Name, - " [", - fieldDefinition2.FieldType, - "/", - fieldDefinition2.FieldType.FullName, - "]. [MessageBase] member cannot be an interface." - })); - return; - } - - var writeFunc = Weaver.GetWriteFunc(fieldDefinition2.FieldType); - if (writeFunc == null) - { - Weaver.fail = true; - Log.Error(string.Concat(new object[] - { - "GenerateSerialization for ", - m_td.Name, - " unknown type [", - fieldDefinition2.FieldType, - "/", - fieldDefinition2.FieldType.FullName, - "]. [MessageBase] member variables must be basic types." - })); - return; - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fieldDefinition2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, writeFunc)); - } - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition2); - } - } - - private void GenerateDeSerialization() - { - Weaver.DLog(m_td, " GenerateDeserialization", new object[0]); - foreach (var methodDefinition in m_td.Methods) - { - if (methodDefinition.Name == "Deserialize") - { - return; - } - } - - if (m_td.Fields.Count != 0) - { - var methodDefinition2 = new MethodDefinition("Deserialize", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, Weaver.voidType); - methodDefinition2.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkReaderType))); - var ilprocessor = methodDefinition2.Body.GetILProcessor(); - foreach (var fieldDefinition in m_td.Fields) - { - if (!fieldDefinition.IsStatic && !fieldDefinition.IsPrivate && !fieldDefinition.IsSpecialName) - { - var readFunc = Weaver.GetReadFunc(fieldDefinition.FieldType); - if (readFunc == null) - { - Weaver.fail = true; - Log.Error(string.Concat(new object[] - { - "GenerateDeSerialization for ", - m_td.Name, - " unknown type [", - fieldDefinition.FieldType, - "]. [SyncVar] member variables must be basic types." - })); - return; - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, readFunc)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stfld, fieldDefinition)); - } - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition2); - } - } - - private TypeDefinition m_td; - } -} diff --git a/QNetWeaver/MonoBehaviourProcessor.cs b/QNetWeaver/MonoBehaviourProcessor.cs deleted file mode 100644 index f974afe9..00000000 --- a/QNetWeaver/MonoBehaviourProcessor.cs +++ /dev/null @@ -1,143 +0,0 @@ -using Mono.Cecil; - -namespace QNetWeaver -{ - internal class MonoBehaviourProcessor - { - public MonoBehaviourProcessor(TypeDefinition td) => m_td = td; - - public void Process() - { - ProcessSyncVars(); - ProcessMethods(); - } - - private void ProcessSyncVars() - { - foreach (var fieldDefinition in m_td.Fields) - { - foreach (var customAttribute in fieldDefinition.CustomAttributes) - { - if (customAttribute.AttributeType.FullName == Weaver.SyncVarType.FullName) - { - Log.Error(string.Concat(new string[] - { - "Script ", - m_td.FullName, - " uses [SyncVar] ", - fieldDefinition.Name, - " but is not a NetworkBehaviour." - })); - Weaver.fail = true; - } - } - - if (Helpers.InheritsFromSyncList(fieldDefinition.FieldType)) - { - Log.Error(string.Format("Script {0} defines field {1} with type {2}, but it's not a NetworkBehaviour", m_td.FullName, fieldDefinition.Name, Helpers.PrettyPrintType(fieldDefinition.FieldType))); - Weaver.fail = true; - } - } - } - - private void ProcessMethods() - { - foreach (var methodDefinition in m_td.Methods) - { - foreach (var customAttribute in methodDefinition.CustomAttributes) - { - if (customAttribute.AttributeType.FullName == Weaver.CommandType.FullName) - { - Log.Error(string.Concat(new string[] - { - "Script ", - m_td.FullName, - " uses [Command] ", - methodDefinition.Name, - " but is not a NetworkBehaviour." - })); - Weaver.fail = true; - } - - if (customAttribute.AttributeType.FullName == Weaver.ClientRpcType.FullName) - { - Log.Error(string.Concat(new string[] - { - "Script ", - m_td.FullName, - " uses [ClientRpc] ", - methodDefinition.Name, - " but is not a NetworkBehaviour." - })); - Weaver.fail = true; - } - - if (customAttribute.AttributeType.FullName == Weaver.TargetRpcType.FullName) - { - Log.Error(string.Concat(new string[] - { - "Script ", - m_td.FullName, - " uses [TargetRpc] ", - methodDefinition.Name, - " but is not a NetworkBehaviour." - })); - Weaver.fail = true; - } - - var text = customAttribute.Constructor.DeclaringType.ToString(); - if (text == "UnityEngine.Networking.ServerAttribute") - { - Log.Error(string.Concat(new string[] - { - "Script ", - m_td.FullName, - " uses the attribute [Server] on the method ", - methodDefinition.Name, - " but is not a NetworkBehaviour." - })); - Weaver.fail = true; - } - else if (text == "UnityEngine.Networking.ServerCallbackAttribute") - { - Log.Error(string.Concat(new string[] - { - "Script ", - m_td.FullName, - " uses the attribute [ServerCallback] on the method ", - methodDefinition.Name, - " but is not a NetworkBehaviour." - })); - Weaver.fail = true; - } - else if (text == "UnityEngine.Networking.ClientAttribute") - { - Log.Error(string.Concat(new string[] - { - "Script ", - m_td.FullName, - " uses the attribute [Client] on the method ", - methodDefinition.Name, - " but is not a NetworkBehaviour." - })); - Weaver.fail = true; - } - else if (text == "UnityEngine.Networking.ClientCallbackAttribute") - { - Log.Error(string.Concat(new string[] - { - "Script ", - m_td.FullName, - " uses the attribute [ClientCallback] on the method ", - methodDefinition.Name, - " but is not a NetworkBehaviour." - })); - Weaver.fail = true; - } - } - } - } - - private TypeDefinition m_td; - } -} diff --git a/QNetWeaver/NetworkBehaviourProcessor.cs b/QNetWeaver/NetworkBehaviourProcessor.cs deleted file mode 100644 index 7f4eb714..00000000 --- a/QNetWeaver/NetworkBehaviourProcessor.cs +++ /dev/null @@ -1,2237 +0,0 @@ -using Mono.Cecil; -using Mono.Cecil.Cil; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace QNetWeaver -{ - internal class NetworkBehaviourProcessor - { - public NetworkBehaviourProcessor(TypeDefinition td) - { - Weaver.DLog(td, "NetworkBehaviourProcessor", new object[0]); - m_td = td; - } - - public void Process() - { - if (m_td.HasGenericParameters) - { - Weaver.fail = true; - Log.Error("NetworkBehaviour " + m_td.Name + " cannot have generic parameters"); - } - else - { - Weaver.DLog(m_td, "Process Start", new object[0]); - ProcessVersion(); - ProcessSyncVars(); - Weaver.ResetRecursionCount(); - ProcessMethods(); - ProcessEvents(); - if (!Weaver.fail) - { - GenerateNetworkSettings(); - GenerateConstants(); - Weaver.ResetRecursionCount(); - GenerateSerialization(); - if (!Weaver.fail) - { - GenerateDeSerialization(); - GeneratePreStartClient(); - Weaver.DLog(m_td, "Process Done", new object[0]); - } - } - } - } - - private static void WriteClientActiveCheck(ILProcessor worker, string mdName, Instruction label, string errString) - { - worker.Append(worker.Create(OpCodes.Call, Weaver.NetworkClientGetActive)); - worker.Append(worker.Create(OpCodes.Brtrue, label)); - worker.Append(worker.Create(OpCodes.Ldstr, errString + " " + mdName + " called on server.")); - worker.Append(worker.Create(OpCodes.Call, Weaver.logErrorReference)); - worker.Append(worker.Create(OpCodes.Ret)); - worker.Append(label); - } - - private static void WriteServerActiveCheck(ILProcessor worker, string mdName, Instruction label, string errString) - { - worker.Append(worker.Create(OpCodes.Call, Weaver.NetworkServerGetActive)); - worker.Append(worker.Create(OpCodes.Brtrue, label)); - worker.Append(worker.Create(OpCodes.Ldstr, errString + " " + mdName + " called on client.")); - worker.Append(worker.Create(OpCodes.Call, Weaver.logErrorReference)); - worker.Append(worker.Create(OpCodes.Ret)); - worker.Append(label); - } - - private static void WriteSetupLocals(ILProcessor worker) - { - worker.Body.InitLocals = true; - worker.Body.Variables.Add(new VariableDefinition(Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkWriterType))); - } - - private static void WriteCreateWriter(ILProcessor worker) - { - worker.Append(worker.Create(OpCodes.Newobj, Weaver.NetworkWriterCtor)); - worker.Append(worker.Create(OpCodes.Stloc_0)); - worker.Append(worker.Create(OpCodes.Ldloc_0)); - } - - private static void WriteMessageSize(ILProcessor worker) - { - worker.Append(worker.Create(OpCodes.Ldc_I4_0)); - worker.Append(worker.Create(OpCodes.Callvirt, Weaver.NetworkWriterWriteInt16)); - } - - private static void WriteMessageId(ILProcessor worker, int msgId) - { - worker.Append(worker.Create(OpCodes.Ldloc_0)); - worker.Append(worker.Create(OpCodes.Ldc_I4, msgId)); - worker.Append(worker.Create(OpCodes.Conv_U2)); - worker.Append(worker.Create(OpCodes.Callvirt, Weaver.NetworkWriterWriteInt16)); - } - - private static bool WriteArguments(ILProcessor worker, MethodDefinition md, string errString, bool skipFirst) - { - short num = 1; - foreach (var parameterDefinition in md.Parameters) - { - if (num == 1 && skipFirst) - { - num += 1; - } - else - { - var writeFunc = Weaver.GetWriteFunc(parameterDefinition.ParameterType); - if (writeFunc == null) - { - Log.Error(string.Concat(new object[] - { - "WriteArguments for ", - md.Name, - " type ", - parameterDefinition.ParameterType, - " not supported" - })); - Weaver.fail = true; - return false; - } - - worker.Append(worker.Create(OpCodes.Ldloc_0)); - worker.Append(worker.Create(OpCodes.Ldarg, num)); - worker.Append(worker.Create(OpCodes.Call, writeFunc)); - num += 1; - } - } - - return true; - } - - private void ProcessVersion() - { - foreach (var methodDefinition in m_td.Methods) - { - if (methodDefinition.Name == "UNetVersion") - { - return; - } - } - - var methodDefinition2 = new MethodDefinition("UNetVersion", MethodAttributes.Private, Weaver.voidType); - var ilprocessor = methodDefinition2.Body.GetILProcessor(); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition2); - } - - private void GenerateConstants() - { - if (m_Cmds.Count != 0 || m_Rpcs.Count != 0 || m_TargetRpcs.Count != 0 || m_Events.Count != 0 || m_SyncLists.Count != 0) - { - Weaver.DLog(m_td, " GenerateConstants ", new object[0]); - MethodDefinition cctorMethodDef = null; - - var flag = false; - foreach (var methodDef in m_td.Methods) - { - if (methodDef.Name == ".cctor") - { - cctorMethodDef = methodDef; - flag = true; - } - } - - if (cctorMethodDef != null) - { - if (cctorMethodDef.Body.Instructions.Count != 0) - { - var returnInstruction = cctorMethodDef.Body.Instructions[cctorMethodDef.Body.Instructions.Count - 1]; - if (!(returnInstruction.OpCode == OpCodes.Ret)) - { - Log.Error("No .cctor for " + m_td.Name); - Weaver.fail = true; - return; - } - - cctorMethodDef.Body.Instructions.RemoveAt(cctorMethodDef.Body.Instructions.Count - 1); - } - } - else - { - Weaver.DLog(m_td, " No. cctor found, making... ", new object[0]); - cctorMethodDef = new MethodDefinition(".cctor", MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, Weaver.voidType); - } - - MethodDefinition ctorMethodDef = null; - foreach (var methodDef in m_td.Methods) - { - if (methodDef.Name == ".ctor") - { - ctorMethodDef = methodDef; - var returnInstruction = ctorMethodDef.Body.Instructions[ctorMethodDef.Body.Instructions.Count - 1]; - if (returnInstruction.OpCode == OpCodes.Ret) - { - Weaver.DLog(m_td, " Found .ctor ", new object[0]); - ctorMethodDef.Body.Instructions.RemoveAt(ctorMethodDef.Body.Instructions.Count - 1); - break; - } - - Weaver.fail = true; - Log.Error("No .ctor for " + m_td.Name); - return; - } - } - - if (ctorMethodDef == null) - { - Weaver.fail = true; - Log.Error("No .ctor for " + m_td.Name); - } - else - { - var ilprocessor = ctorMethodDef.Body.GetILProcessor(); - var ilprocessor2 = cctorMethodDef.Body.GetILProcessor(); - - var commandIndex = 0; - foreach (var commandDef in m_Cmds) - { - Weaver.DLog(m_td, $" Found command {commandDef.Name}", new object[0]); - var field = Weaver.ResolveField(m_td, "kCmd" + commandDef.Name); - Weaver.DLog(m_td, $" got field", new object[0]); - var hashCode = GetHashCode(m_td.Name + ":Cmd:" + commandDef.Name); - Weaver.DLog(m_td, $" got hashcode", new object[0]); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Ldc_I4, hashCode)); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Stsfld, field)); - - GenerateCommandDelegate(ilprocessor2, Weaver.registerCommandDelegateReference, m_CmdInvocationFuncs[commandIndex], field); - commandIndex++; - } - - var rpcIndex = 0; - foreach (var rpcDef in m_Rpcs) - { - var field2 = Weaver.ResolveField(m_td, "kRpc" + rpcDef.Name); - var hashCode2 = GetHashCode(m_td.Name + ":Rpc:" + rpcDef.Name); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Ldc_I4, hashCode2)); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Stsfld, field2)); - GenerateCommandDelegate(ilprocessor2, Weaver.registerRpcDelegateReference, m_RpcInvocationFuncs[rpcIndex], field2); - rpcIndex++; - } - - var targetRpcIndex = 0; - foreach (var targetRpcDef in m_TargetRpcs) - { - var field3 = Weaver.ResolveField(m_td, "kTargetRpc" + targetRpcDef.Name); - var hashCode3 = GetHashCode(m_td.Name + ":TargetRpc:" + targetRpcDef.Name); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Ldc_I4, hashCode3)); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Stsfld, field3)); - GenerateCommandDelegate(ilprocessor2, Weaver.registerRpcDelegateReference, m_TargetRpcInvocationFuncs[targetRpcIndex], field3); - targetRpcIndex++; - } - - var eventIndex = 0; - foreach (var eventDef in m_Events) - { - var field4 = Weaver.ResolveField(m_td, "kEvent" + eventDef.Name); - var hashCode4 = GetHashCode(m_td.Name + ":Event:" + eventDef.Name); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Ldc_I4, hashCode4)); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Stsfld, field4)); - GenerateCommandDelegate(ilprocessor2, Weaver.registerEventDelegateReference, m_EventInvocationFuncs[eventIndex], field4); - eventIndex++; - } - - var syncListIndex = 0; - foreach (var syncListDef in m_SyncLists) - { - var field5 = Weaver.ResolveField(m_td, "kList" + syncListDef.Name); - var hashCode5 = GetHashCode(m_td.Name + ":List:" + syncListDef.Name); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Ldc_I4, hashCode5)); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Stsfld, field5)); - GenerateSyncListInstanceInitializer(ilprocessor, syncListDef); - GenerateCommandDelegate(ilprocessor2, Weaver.registerSyncListDelegateReference, m_SyncListInvocationFuncs[syncListIndex], field5); - syncListIndex++; - } - - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Ldstr, m_td.Name)); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Ldc_I4, m_QosChannel)); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Call, Weaver.RegisterBehaviourReference)); - ilprocessor2.Append(ilprocessor2.Create(OpCodes.Ret)); - if (!flag) - { - m_td.Methods.Add(cctorMethodDef); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Attributes = (m_td.Attributes & ~TypeAttributes.BeforeFieldInit); - if (m_SyncLists.Count != 0) - { - MethodDefinition methodDefinition8 = null; - var flag2 = false; - foreach (var methodDefinition9 in m_td.Methods) - { - if (methodDefinition9.Name == "Awake") - { - methodDefinition8 = methodDefinition9; - flag2 = true; - } - } - - if (methodDefinition8 != null) - { - if (methodDefinition8.Body.Instructions.Count != 0) - { - var instruction3 = methodDefinition8.Body.Instructions[methodDefinition8.Body.Instructions.Count - 1]; - if (!(instruction3.OpCode == OpCodes.Ret)) - { - Log.Error("No awake for " + m_td.Name); - Weaver.fail = true; - return; - } - - methodDefinition8.Body.Instructions.RemoveAt(methodDefinition8.Body.Instructions.Count - 1); - } - } - else - { - methodDefinition8 = new MethodDefinition("Awake", MethodAttributes.Private, Weaver.voidType); - } - - var ilprocessor3 = methodDefinition8.Body.GetILProcessor(); - if (!flag2) - { - CheckForCustomBaseClassAwakeMethod(ilprocessor3); - } - - var num6 = 0; - foreach (var fd in m_SyncLists) - { - GenerateSyncListInitializer(ilprocessor3, fd, num6); - num6++; - } - - ilprocessor3.Append(ilprocessor3.Create(OpCodes.Ret)); - if (!flag2) - { - m_td.Methods.Add(methodDefinition8); - } - } - } - } - } - - private void CheckForCustomBaseClassAwakeMethod(ILProcessor awakeWorker) - { - var baseType = m_td.BaseType; - while (baseType.FullName != Weaver.NetworkBehaviourType.FullName) - { - var methodDefinition = Enumerable.FirstOrDefault(baseType.Resolve().Methods, (MethodDefinition x) => x.Name == "Awake" && !x.HasParameters); - if (methodDefinition != null) - { - awakeWorker.Append(awakeWorker.Create(OpCodes.Ldarg_0)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Call, methodDefinition)); - break; - } - - baseType = baseType.Resolve().BaseType; - } - } - - private void GenerateSyncListInstanceInitializer(ILProcessor ctorWorker, FieldDefinition fd) - { - foreach (var instruction in ctorWorker.Body.Instructions) - { - if (instruction.OpCode.Code == Code.Stfld) - { - var fieldDefinition = (FieldDefinition)instruction.Operand; - if (fieldDefinition.DeclaringType == fd.DeclaringType && fieldDefinition.Name == fd.Name) - { - return; - } - } - } - - var method = Weaver.scriptDef.MainModule.ImportReference(Enumerable.First(fd.FieldType.Resolve().Methods, (MethodDefinition x) => x.Name == ".ctor" && !x.HasParameters)); - ctorWorker.Append(ctorWorker.Create(OpCodes.Ldarg_0)); - ctorWorker.Append(ctorWorker.Create(OpCodes.Newobj, method)); - ctorWorker.Append(ctorWorker.Create(OpCodes.Stfld, fd)); - } - - private void GenerateCommandDelegate(ILProcessor awakeWorker, MethodReference registerMethod, MethodDefinition func, FieldReference field) - { - Weaver.DLog(m_td, " GenerateCommandDelegate ", new object[0]); - awakeWorker.Append(awakeWorker.Create(OpCodes.Ldtoken, m_td)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Call, Weaver.getTypeFromHandleReference)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Ldsfld, field)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Ldnull)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Ldftn, func)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Newobj, Weaver.CmdDelegateConstructor)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Call, registerMethod)); - } - - private void GenerateSyncListInitializer(ILProcessor awakeWorker, FieldReference fd, int index) - { - awakeWorker.Append(awakeWorker.Create(OpCodes.Ldarg_0)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Ldfld, fd)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Ldarg_0)); - awakeWorker.Append(awakeWorker.Create(OpCodes.Ldsfld, m_SyncListStaticFields[index])); - var genericInstanceType = (GenericInstanceType)fd.FieldType.Resolve().BaseType; - genericInstanceType = (GenericInstanceType)Weaver.scriptDef.MainModule.ImportReference(genericInstanceType); - var typeReference = genericInstanceType.GenericArguments[0]; - var method = Helpers.MakeHostInstanceGeneric(Weaver.SyncListInitBehaviourReference, new TypeReference[] - { - typeReference - }); - awakeWorker.Append(awakeWorker.Create(OpCodes.Callvirt, method)); - Weaver.scriptDef.MainModule.ImportReference(method); - } - - private void GenerateSerialization() - { - Weaver.DLog(m_td, " NetworkBehaviour GenerateSerialization", new object[0]); - foreach (var methodDefinition in m_td.Methods) - { - if (methodDefinition.Name == "OnSerialize") - { - Weaver.DLog(m_td, " Abort - is OnSerialize", new object[0]); - return; - } - } - - var methodDefinition2 = new MethodDefinition("OnSerialize", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, Weaver.boolType); - methodDefinition2.Parameters.Add(new ParameterDefinition("writer", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkWriterType))); - methodDefinition2.Parameters.Add(new ParameterDefinition("forceAll", ParameterAttributes.None, Weaver.boolType)); - var ilprocessor = methodDefinition2.Body.GetILProcessor(); - methodDefinition2.Body.InitLocals = true; - var item = new VariableDefinition(Weaver.boolType); - methodDefinition2.Body.Variables.Add(item); - var flag = false; - - if (m_td.BaseType.FullName != Weaver.NetworkBehaviourType.FullName) - { - var methodReference = Weaver.ResolveMethod(m_td.BaseType, "OnSerialize"); - if (methodReference != null) - { - var item2 = new VariableDefinition(Weaver.boolType); - methodDefinition2.Body.Variables.Add(item2); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, methodReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_1)); - flag = true; - } - } - - if (m_SyncVars.Count == 0) - { - Weaver.DLog(m_td, " No syncvars", new object[0]); - if (flag) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Or)); - } - else - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition2); - } - else - { - Weaver.DLog(m_td, " Syncvars exist", new object[0]); - var instruction = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brfalse, instruction)); - foreach (var fieldDefinition in m_SyncVars) - { - Weaver.DLog(m_td, $" For {fieldDefinition.Name}", new object[0]); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fieldDefinition)); - var writeFunc = Weaver.GetWriteFunc(fieldDefinition.FieldType); - if (writeFunc == null) - { - Weaver.fail = true; - Log.Error(string.Concat(new object[] - { - "GenerateSerialization for ", - m_td.Name, - " unknown type [", - fieldDefinition.FieldType, - "]. UNet [SyncVar] member variables must be basic types." - })); - return; - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, writeFunc)); - } - - Weaver.DLog(m_td, $" Finish foreach 1", new object[0]); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - ilprocessor.Append(instruction); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_0)); - var num = Weaver.GetSyncVarStart(m_td.BaseType.FullName); - foreach (var fieldDefinition2 in m_SyncVars) - { - Weaver.DLog(m_td, $" For {fieldDefinition2.Name}", new object[0]); - var instruction2 = ilprocessor.Create(OpCodes.Nop); - Weaver.DLog(m_td, $" Got instruction2", new object[0]); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - Weaver.DLog(m_td, $" call dirtbits reference", new object[0]); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.NetworkBehaviourDirtyBitsReference)); - Weaver.DLog(m_td, $" finish call dirtbits reference", new object[0]); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4, 1 << num)); - ilprocessor.Append(ilprocessor.Create(OpCodes.And)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brfalse, instruction2)); - Weaver.DLog(m_td, $" writing dirtycheck", new object[0]); - WriteDirtyCheck(ilprocessor, true); - Weaver.DLog(m_td, $" done writing dirtycheck", new object[0]); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fieldDefinition2)); - Weaver.DLog(m_td, $" Getting writeFunc2", new object[0]); - var writeFunc2 = Weaver.GetWriteFunc(fieldDefinition2.FieldType); - Weaver.DLog(m_td, $" Got writeFunc2", new object[0]); - if (writeFunc2 == null) - { - Log.Error(string.Concat(new object[] - { - "GenerateSerialization for ", - m_td.Name, - " unknown type [", - fieldDefinition2.FieldType, - "]. UNet [SyncVar] member variables must be basic types." - })); - Weaver.fail = true; - return; - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, writeFunc2)); - ilprocessor.Append(instruction2); - num++; - } - - Weaver.DLog(m_td, $" Finish foreach 2", new object[0]); - WriteDirtyCheck(ilprocessor, false); - if (Weaver.generateLogErrors) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldstr, "Injected Serialize " + m_td.Name)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.logErrorReference)); - } - - if (flag) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Or)); - } - else - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition2); - Weaver.DLog(m_td, $" Finish", new object[0]); - } - - Weaver.DLog(m_td, $" Finish", new object[0]); - } - - private static void WriteDirtyCheck(ILProcessor serWorker, bool reset) - { - var instruction = serWorker.Create(OpCodes.Nop); - serWorker.Append(serWorker.Create(OpCodes.Ldloc_0)); - serWorker.Append(serWorker.Create(OpCodes.Brtrue, instruction)); - serWorker.Append(serWorker.Create(OpCodes.Ldarg_1)); - serWorker.Append(serWorker.Create(OpCodes.Ldarg_0)); - serWorker.Append(serWorker.Create(OpCodes.Call, Weaver.NetworkBehaviourDirtyBitsReference)); - serWorker.Append(serWorker.Create(OpCodes.Callvirt, Weaver.NetworkWriterWritePacked32)); - if (reset) - { - serWorker.Append(serWorker.Create(OpCodes.Ldc_I4_1)); - serWorker.Append(serWorker.Create(OpCodes.Stloc_0)); - } - - serWorker.Append(instruction); - } - - private static int GetChannelId(FieldDefinition field) - { - var result = 0; - foreach (var customAttribute in field.CustomAttributes) - { - if (customAttribute.AttributeType.FullName == Weaver.SyncVarType.FullName) - { - foreach (var customAttributeNamedArgument in customAttribute.Fields) - { - if (customAttributeNamedArgument.Name == "channel") - { - result = (int)customAttributeNamedArgument.Argument.Value; - break; - } - } - } - } - - return result; - } - - private bool CheckForHookFunction(FieldDefinition syncVar, out MethodDefinition foundMethod) - { - foundMethod = null; - foreach (var customAttribute in syncVar.CustomAttributes) - { - if (customAttribute.AttributeType.FullName == Weaver.SyncVarType.FullName) - { - foreach (var customAttributeNamedArgument in customAttribute.Fields) - { - if (customAttributeNamedArgument.Name == "hook") - { - var text = customAttributeNamedArgument.Argument.Value as string; - foreach (var methodDefinition in m_td.Methods) - { - if (methodDefinition.Name == text) - { - if (methodDefinition.Parameters.Count != 1) - { - Log.Error("SyncVar Hook function " + text + " must have one argument " + m_td.Name); - Weaver.fail = true; - return false; - } - - if (methodDefinition.Parameters[0].ParameterType != syncVar.FieldType) - { - Log.Error("SyncVar Hook function " + text + " has wrong type signature for " + m_td.Name); - Weaver.fail = true; - return false; - } - - foundMethod = methodDefinition; - return true; - } - } - - Log.Error("SyncVar Hook function " + text + " not found for " + m_td.Name); - Weaver.fail = true; - return false; - } - } - } - } - - return true; - } - - private void GenerateNetworkChannelSetting(int channel) - { - var methodDefinition = new MethodDefinition("GetNetworkChannel", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, Weaver.int32Type); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4, channel)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition); - } - - private void GenerateNetworkIntervalSetting(float interval) - { - var methodDefinition = new MethodDefinition("GetNetworkSendInterval", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, Weaver.singleType); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_R4, interval)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition); - } - - private void GenerateNetworkSettings() - { - foreach (var customAttribute in m_td.CustomAttributes) - { - if (customAttribute.AttributeType.FullName == Weaver.NetworkSettingsType.FullName) - { - foreach (var customAttributeNamedArgument in customAttribute.Fields) - { - if (customAttributeNamedArgument.Name == "channel") - { - if ((int)customAttributeNamedArgument.Argument.Value == 0) - { - continue; - } - - if (HasMethod("GetNetworkChannel")) - { - Log.Error("GetNetworkChannel, is already implemented, please make sure you either use NetworkSettings or GetNetworkChannel"); - Weaver.fail = true; - return; - } - - m_QosChannel = (int)customAttributeNamedArgument.Argument.Value; - GenerateNetworkChannelSetting(m_QosChannel); - } - - if (customAttributeNamedArgument.Name == "sendInterval") - { - if (Math.Abs((float)customAttributeNamedArgument.Argument.Value - 0.1f) > 1E-05f) - { - if (HasMethod("GetNetworkSendInterval")) - { - Log.Error("GetNetworkSendInterval, is already implemented, please make sure you either use NetworkSettings or GetNetworkSendInterval"); - Weaver.fail = true; - return; - } - - GenerateNetworkIntervalSetting((float)customAttributeNamedArgument.Argument.Value); - } - } - } - } - } - } - - private void GeneratePreStartClient() - { - m_NetIdFieldCounter = 0; - MethodDefinition methodDefinition = null; - ILProcessor ilprocessor = null; - foreach (var methodDefinition2 in m_td.Methods) - { - if (methodDefinition2.Name == "PreStartClient") - { - return; - } - } - - foreach (var fieldDefinition in m_SyncVars) - { - if (fieldDefinition.FieldType.FullName == Weaver.gameObjectType.FullName) - { - if (methodDefinition == null) - { - methodDefinition = new MethodDefinition("PreStartClient", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, Weaver.voidType); - ilprocessor = methodDefinition.Body.GetILProcessor(); - } - - var field = m_SyncVarNetIds[m_NetIdFieldCounter]; - m_NetIdFieldCounter++; - var instruction = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldflda, field)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.NetworkInstanceIsEmpty)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brtrue, instruction)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, field)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.FindLocalObjectReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stfld, fieldDefinition)); - ilprocessor.Append(instruction); - } - } - - if (methodDefinition != null) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition); - } - } - - private void GenerateDeSerialization() - { - Weaver.DLog(m_td, " GenerateDeSerialization", new object[0]); - m_NetIdFieldCounter = 0; - foreach (var methodDefinition in m_td.Methods) - { - if (methodDefinition.Name == "OnDeserialize") - { - return; - } - } - - var methodDefinition2 = new MethodDefinition("OnDeserialize", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, Weaver.voidType); - methodDefinition2.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkReaderType))); - methodDefinition2.Parameters.Add(new ParameterDefinition("initialState", ParameterAttributes.None, Weaver.boolType)); - var ilprocessor = methodDefinition2.Body.GetILProcessor(); - if (m_td.BaseType.FullName != Weaver.NetworkBehaviourType.FullName) - { - var methodReference = Weaver.ResolveMethod(m_td.BaseType, "OnDeserialize"); - if (methodReference != null) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, methodReference)); - } - } - - if (m_SyncVars.Count == 0) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition2); - } - else - { - var instruction = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brfalse, instruction)); - foreach (var fieldDefinition in m_SyncVars) - { - var readByReferenceFunc = Weaver.GetReadByReferenceFunc(fieldDefinition.FieldType); - if (readByReferenceFunc != null) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fieldDefinition)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, readByReferenceFunc)); - } - else - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - if (fieldDefinition.FieldType.FullName == Weaver.gameObjectType.FullName) - { - var field = m_SyncVarNetIds[m_NetIdFieldCounter]; - m_NetIdFieldCounter++; - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkReaderReadNetworkInstanceId)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stfld, field)); - } - else - { - var readFunc = Weaver.GetReadFunc(fieldDefinition.FieldType); - if (readFunc == null) - { - Log.Error(string.Concat(new object[] - { - "GenerateDeSerialization for ", - m_td.Name, - " unknown type [", - fieldDefinition.FieldType, - "]. UNet [SyncVar] member variables must be basic types." - })); - Weaver.fail = true; - return; - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, readFunc)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stfld, fieldDefinition)); - } - } - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - ilprocessor.Append(instruction); - methodDefinition2.Body.InitLocals = true; - var item = new VariableDefinition(Weaver.int32Type); - methodDefinition2.Body.Variables.Add(item); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkReaderReadPacked32)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_0)); - var num = Weaver.GetSyncVarStart(m_td.BaseType.FullName); - foreach (var fieldDefinition2 in m_SyncVars) - { - var instruction2 = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4, 1 << num)); - ilprocessor.Append(ilprocessor.Create(OpCodes.And)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brfalse, instruction2)); - var readByReferenceFunc2 = Weaver.GetReadByReferenceFunc(fieldDefinition2.FieldType); - if (readByReferenceFunc2 != null) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fieldDefinition2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, readByReferenceFunc2)); - } - else - { - var readFunc2 = Weaver.GetReadFunc(fieldDefinition2.FieldType); - if (readFunc2 == null) - { - Log.Error(string.Concat(new object[] - { - "GenerateDeSerialization for ", - m_td.Name, - " unknown type [", - fieldDefinition2.FieldType, - "]. UNet [SyncVar] member variables must be basic types." - })); - Weaver.fail = true; - return; - } - - if (!CheckForHookFunction(fieldDefinition2, out var methodDefinition3)) - { - return; - } - - if (methodDefinition3 == null) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, readFunc2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stfld, fieldDefinition2)); - } - else - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, readFunc2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, methodDefinition3)); - } - } - - ilprocessor.Append(instruction2); - num++; - } - - if (Weaver.generateLogErrors) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldstr, "Injected Deserialize " + m_td.Name)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.logErrorReference)); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_td.Methods.Add(methodDefinition2); - } - } - - private bool ProcessNetworkReaderParameters(MethodDefinition md, ILProcessor worker, bool skipFirst) - { - var num = 0; - foreach (var parameterDefinition in md.Parameters) - { - if (num++ != 0 || !skipFirst) - { - var readFunc = Weaver.GetReadFunc(parameterDefinition.ParameterType); - if (readFunc == null) - { - Log.Error(string.Concat(new object[] - { - "ProcessNetworkReaderParameters for ", - m_td.Name, - ":", - md.Name, - " type ", - parameterDefinition.ParameterType, - " not supported" - })); - Weaver.fail = true; - return false; - } - - worker.Append(worker.Create(OpCodes.Ldarg_1)); - worker.Append(worker.Create(OpCodes.Call, readFunc)); - if (parameterDefinition.ParameterType.FullName == Weaver.singleType.FullName) - { - worker.Append(worker.Create(OpCodes.Conv_R4)); - } - else if (parameterDefinition.ParameterType.FullName == Weaver.doubleType.FullName) - { - worker.Append(worker.Create(OpCodes.Conv_R8)); - } - } - } - - return true; - } - - private MethodDefinition ProcessCommandInvoke(MethodDefinition md) - { - var methodDefinition = new MethodDefinition("InvokeCmd" + md.Name, MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, Weaver.voidType); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var label = ilprocessor.Create(OpCodes.Nop); - WriteServerActiveCheck(ilprocessor, md.Name, label, "Command"); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Castclass, m_td)); - MethodDefinition result; - if (!ProcessNetworkReaderParameters(md, ilprocessor, false)) - { - result = null; - } - else - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, md)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - AddInvokeParameters(methodDefinition.Parameters); - result = methodDefinition; - } - - return result; - } - - private static void AddInvokeParameters(ICollection collection) - { - collection.Add(new ParameterDefinition("obj", ParameterAttributes.None, Weaver.NetworkBehaviourType2)); - collection.Add(new ParameterDefinition("reader", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkReaderType))); - } - - private MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca) - { - var methodDefinition = new MethodDefinition("Call" + md.Name, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig, Weaver.voidType); - foreach (var parameterDefinition in md.Parameters) - { - methodDefinition.Parameters.Add(new ParameterDefinition(parameterDefinition.Name, ParameterAttributes.None, parameterDefinition.ParameterType)); - } - - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var label = ilprocessor.Create(OpCodes.Nop); - WriteSetupLocals(ilprocessor); - if (Weaver.generateLogErrors) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldstr, "Call Command function " + md.Name)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.logErrorReference)); - } - - WriteClientActiveCheck(ilprocessor, md.Name, label, "Command function"); - var instruction = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.UBehaviourIsServer)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brfalse, instruction)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - for (var i = 0; i < md.Parameters.Count; i++) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg, i + 1)); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, md)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - ilprocessor.Append(instruction); - WriteCreateWriter(ilprocessor); - WriteMessageSize(ilprocessor); - WriteMessageId(ilprocessor, 5); - var fieldDefinition = new FieldDefinition("kCmd" + md.Name, FieldAttributes.Private | FieldAttributes.Static, Weaver.int32Type); - m_td.Fields.Add(fieldDefinition); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldsfld, fieldDefinition)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkWriterWritePacked32)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.getComponentReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.getUNetIdReference)); - var writeFunc = Weaver.GetWriteFunc(Weaver.NetworkInstanceIdType); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, writeFunc)); - MethodDefinition result; - if (!WriteArguments(ilprocessor, md, "Command", false)) - { - result = null; - } - else - { - var value = 0; - foreach (var customAttributeNamedArgument in ca.Fields) - { - if (customAttributeNamedArgument.Name == "channel") - { - value = (int)customAttributeNamedArgument.Argument.Value; - } - } - - var text = md.Name; - var num = text.IndexOf("InvokeCmd"); - if (num > -1) - { - text = text.Substring("InvokeCmd".Length); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4, value)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldstr, text)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.sendCommandInternal)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - result = methodDefinition; - } - - return result; - } - - private MethodDefinition ProcessTargetRpcInvoke(MethodDefinition md) - { - var methodDefinition = new MethodDefinition("InvokeRpc" + md.Name, MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, Weaver.voidType); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var label = ilprocessor.Create(OpCodes.Nop); - WriteClientActiveCheck(ilprocessor, md.Name, label, "TargetRPC"); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Castclass, m_td)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.ReadyConnectionReference)); - MethodDefinition result; - if (!ProcessNetworkReaderParameters(md, ilprocessor, true)) - { - result = null; - } - else - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, md)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - AddInvokeParameters(methodDefinition.Parameters); - result = methodDefinition; - } - - return result; - } - - private MethodDefinition ProcessRpcInvoke(MethodDefinition md) - { - var methodDefinition = new MethodDefinition("InvokeRpc" + md.Name, MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, Weaver.voidType); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var label = ilprocessor.Create(OpCodes.Nop); - WriteClientActiveCheck(ilprocessor, md.Name, label, "RPC"); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Castclass, m_td)); - MethodDefinition result; - if (!ProcessNetworkReaderParameters(md, ilprocessor, false)) - { - result = null; - } - else - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, md)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - AddInvokeParameters(methodDefinition.Parameters); - result = methodDefinition; - } - - return result; - } - - private MethodDefinition ProcessTargetRpcCall(MethodDefinition md, CustomAttribute ca) - { - var methodDefinition = new MethodDefinition("Call" + md.Name, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig, Weaver.voidType); - foreach (var parameterDefinition in md.Parameters) - { - methodDefinition.Parameters.Add(new ParameterDefinition(parameterDefinition.Name, ParameterAttributes.None, parameterDefinition.ParameterType)); - } - - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var label = ilprocessor.Create(OpCodes.Nop); - WriteSetupLocals(ilprocessor); - WriteServerActiveCheck(ilprocessor, md.Name, label, "TargetRPC Function"); - var instruction = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Isinst, Weaver.ULocalConnectionToServerType)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brfalse, instruction)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldstr, string.Format("TargetRPC Function {0} called on connection to server", md.Name))); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.logErrorReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - ilprocessor.Append(instruction); - WriteCreateWriter(ilprocessor); - WriteMessageSize(ilprocessor); - WriteMessageId(ilprocessor, 2); - var fieldDefinition = new FieldDefinition("kTargetRpc" + md.Name, FieldAttributes.Private | FieldAttributes.Static, Weaver.int32Type); - m_td.Fields.Add(fieldDefinition); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldsfld, fieldDefinition)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkWriterWritePacked32)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.getComponentReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.getUNetIdReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkWriterWriteNetworkInstanceId)); - MethodDefinition result; - if (!WriteArguments(ilprocessor, md, "TargetRPC", true)) - { - result = null; - } - else - { - var value = 0; - foreach (var customAttributeNamedArgument in ca.Fields) - { - if (customAttributeNamedArgument.Name == "channel") - { - value = (int)customAttributeNamedArgument.Argument.Value; - } - } - - var text = md.Name; - var num = text.IndexOf("InvokeTargetRpc"); - if (num > -1) - { - text = text.Substring("InvokeTargetRpc".Length); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4, value)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldstr, text)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.sendTargetRpcInternal)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - result = methodDefinition; - } - - return result; - } - - private MethodDefinition ProcessRpcCall(MethodDefinition md, CustomAttribute ca) - { - var methodDefinition = new MethodDefinition("Call" + md.Name, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig, Weaver.voidType); - foreach (var parameterDefinition in md.Parameters) - { - methodDefinition.Parameters.Add(new ParameterDefinition(parameterDefinition.Name, ParameterAttributes.None, parameterDefinition.ParameterType)); - } - - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var label = ilprocessor.Create(OpCodes.Nop); - WriteSetupLocals(ilprocessor); - WriteServerActiveCheck(ilprocessor, md.Name, label, "RPC Function"); - WriteCreateWriter(ilprocessor); - WriteMessageSize(ilprocessor); - WriteMessageId(ilprocessor, 2); - var fieldDefinition = new FieldDefinition("kRpc" + md.Name, FieldAttributes.Private | FieldAttributes.Static, Weaver.int32Type); - m_td.Fields.Add(fieldDefinition); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldsfld, fieldDefinition)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkWriterWritePacked32)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.getComponentReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.getUNetIdReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkWriterWriteNetworkInstanceId)); - MethodDefinition result; - if (!WriteArguments(ilprocessor, md, "RPC", false)) - { - result = null; - } - else - { - var value = 0; - foreach (var customAttributeNamedArgument in ca.Fields) - { - if (customAttributeNamedArgument.Name == "channel") - { - value = (int)customAttributeNamedArgument.Argument.Value; - } - } - - var text = md.Name; - var num = text.IndexOf("InvokeRpc"); - if (num > -1) - { - text = text.Substring("InvokeRpc".Length); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4, value)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldstr, text)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.sendRpcInternal)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - result = methodDefinition; - } - - return result; - } - - private bool ProcessMethodsValidateFunction(MethodReference md, CustomAttribute ca, string actionType) - { - bool result; - if (md.ReturnType.FullName == Weaver.IEnumeratorType.FullName) - { - Log.Error(string.Concat(new string[] - { - actionType, - " function [", - m_td.FullName, - ":", - md.Name, - "] cannot be a coroutine" - })); - Weaver.fail = true; - result = false; - } - else if (md.ReturnType.FullName != Weaver.voidType.FullName) - { - Log.Error(string.Concat(new string[] - { - actionType, - " function [", - m_td.FullName, - ":", - md.Name, - "] must have a void return type." - })); - Weaver.fail = true; - result = false; - } - else if (md.HasGenericParameters) - { - Log.Error(string.Concat(new string[] - { - actionType, - " [", - m_td.FullName, - ":", - md.Name, - "] cannot have generic parameters" - })); - Weaver.fail = true; - result = false; - } - else - { - result = true; - } - - return result; - } - - private bool ProcessMethodsValidateParameters(MethodReference md, CustomAttribute ca, string actionType) - { - var i = 0; - while (i < md.Parameters.Count) - { - var parameterDefinition = md.Parameters[i]; - bool result; - if (parameterDefinition.IsOut) - { - Log.Error(string.Concat(new string[] - { - actionType, - " function [", - m_td.FullName, - ":", - md.Name, - "] cannot have out parameters" - })); - Weaver.fail = true; - result = false; - } - else if (parameterDefinition.IsOptional) - { - Log.Error(string.Concat(new string[] - { - actionType, - "function [", - m_td.FullName, - ":", - md.Name, - "] cannot have optional parameters" - })); - Weaver.fail = true; - result = false; - } - else if (parameterDefinition.ParameterType.Resolve().IsAbstract) - { - Log.Error(string.Concat(new string[] - { - actionType, - " function [", - m_td.FullName, - ":", - md.Name, - "] cannot have abstract parameters" - })); - Weaver.fail = true; - result = false; - } - else if (parameterDefinition.ParameterType.IsByReference) - { - Log.Error(string.Concat(new string[] - { - actionType, - " function [", - m_td.FullName, - ":", - md.Name, - "] cannot have ref parameters" - })); - Weaver.fail = true; - result = false; - } - else - { - if (!(parameterDefinition.ParameterType.FullName == Weaver.NetworkConnectionType.FullName) || (ca.AttributeType.FullName == Weaver.TargetRpcType.FullName && i == 0)) - { - if (Weaver.IsDerivedFrom(parameterDefinition.ParameterType.Resolve(), Weaver.ComponentType)) - { - if (parameterDefinition.ParameterType.FullName != Weaver.NetworkIdentityType.FullName) - { - Log.Error(string.Concat(new string[] - { - actionType, - " function [", - m_td.FullName, - ":", - md.Name, - "] parameter [", - parameterDefinition.Name, - "] is of the type [", - parameterDefinition.ParameterType.Name, - "] which is a Component. You cannot pass a Component to a remote call. Try passing data from within the component." - })); - Weaver.fail = true; - return false; - } - } - - i++; - continue; - } - - Log.Error(string.Concat(new string[] - { - actionType, - " [", - m_td.FullName, - ":", - md.Name, - "] cannot use a NetworkConnection as a parameter. To access a player object's connection on the server use connectionToClient" - })); - Log.Error("Name: " + ca.AttributeType.FullName + " parameter: " + md.Parameters[0].ParameterType.FullName); - Weaver.fail = true; - result = false; - } - - return result; - } - - return true; - } - - private bool ProcessMethodsValidateCommand(MethodDefinition md, CustomAttribute ca) - { - bool result; - if (md.Name.Length > 2 && md.Name.Substring(0, 3) != "Cmd") - { - Log.Error(string.Concat(new string[] - { - "Command function [", - m_td.FullName, - ":", - md.Name, - "] doesnt have 'Cmd' prefix" - })); - Weaver.fail = true; - result = false; - } - else if (md.IsStatic) - { - Log.Error(string.Concat(new string[] - { - "Command function [", - m_td.FullName, - ":", - md.Name, - "] cant be a static method" - })); - Weaver.fail = true; - result = false; - } - else - { - result = (ProcessMethodsValidateFunction(md, ca, "Command") && ProcessMethodsValidateParameters(md, ca, "Command")); - } - - return result; - } - - private bool ProcessMethodsValidateTargetRpc(MethodDefinition md, CustomAttribute ca) - { - var length = "Target".Length; - bool result; - if (md.Name.Length > length && md.Name.Substring(0, length) != "Target") - { - Log.Error(string.Concat(new string[] - { - "Target Rpc function [", - m_td.FullName, - ":", - md.Name, - "] doesnt have 'Target' prefix" - })); - Weaver.fail = true; - result = false; - } - else if (md.IsStatic) - { - Log.Error(string.Concat(new string[] - { - "TargetRpc function [", - m_td.FullName, - ":", - md.Name, - "] cant be a static method" - })); - Weaver.fail = true; - result = false; - } - else if (!ProcessMethodsValidateFunction(md, ca, "Target Rpc")) - { - result = false; - } - else if (md.Parameters.Count < 1) - { - Log.Error(string.Concat(new string[] - { - "Target Rpc function [", - m_td.FullName, - ":", - md.Name, - "] must have a NetworkConnection as the first parameter" - })); - Weaver.fail = true; - result = false; - } - else if (md.Parameters[0].ParameterType.FullName != Weaver.NetworkConnectionType.FullName) - { - Log.Error(string.Concat(new string[] - { - "Target Rpc function [", - m_td.FullName, - ":", - md.Name, - "] first parameter must be a NetworkConnection" - })); - Weaver.fail = true; - result = false; - } - else - { - result = ProcessMethodsValidateParameters(md, ca, "Target Rpc"); - } - - return result; - } - - private bool ProcessMethodsValidateRpc(MethodDefinition md, CustomAttribute ca) - { - bool result; - if (md.Name.Length > 2 && md.Name.Substring(0, 3) != "Rpc") - { - Log.Error(string.Concat(new string[] - { - "Rpc function [", - m_td.FullName, - ":", - md.Name, - "] doesnt have 'Rpc' prefix" - })); - Weaver.fail = true; - result = false; - } - else if (md.IsStatic) - { - Log.Error(string.Concat(new string[] - { - "ClientRpc function [", - m_td.FullName, - ":", - md.Name, - "] cant be a static method" - })); - Weaver.fail = true; - result = false; - } - else - { - result = (ProcessMethodsValidateFunction(md, ca, "Rpc") && ProcessMethodsValidateParameters(md, ca, "Rpc")); - } - - return result; - } - - private void ProcessMethods() - { - var hashSet = new HashSet(); - foreach (var methodDefinition in m_td.Methods) - { - Weaver.ResetRecursionCount(); - foreach (var customAttribute in methodDefinition.CustomAttributes) - { - if (customAttribute.AttributeType.FullName == Weaver.CommandType.FullName) - { - if (!ProcessMethodsValidateCommand(methodDefinition, customAttribute)) - { - return; - } - - if (hashSet.Contains(methodDefinition.Name)) - { - Log.Error(string.Concat(new string[] - { - "Duplicate Command name [", - m_td.FullName, - ":", - methodDefinition.Name, - "]" - })); - Weaver.fail = true; - return; - } - - hashSet.Add(methodDefinition.Name); - m_Cmds.Add(methodDefinition); - var methodDefinition2 = ProcessCommandInvoke(methodDefinition); - if (methodDefinition2 != null) - { - m_CmdInvocationFuncs.Add(methodDefinition2); - } - - var methodDefinition3 = ProcessCommandCall(methodDefinition, customAttribute); - if (methodDefinition3 != null) - { - m_CmdCallFuncs.Add(methodDefinition3); - Weaver.lists.replacedMethods.Add(methodDefinition); - Weaver.lists.replacementMethods.Add(methodDefinition3); - } - - break; - } - else if (customAttribute.AttributeType.FullName == Weaver.TargetRpcType.FullName) - { - if (!ProcessMethodsValidateTargetRpc(methodDefinition, customAttribute)) - { - return; - } - - if (hashSet.Contains(methodDefinition.Name)) - { - Log.Error(string.Concat(new string[] - { - "Duplicate Target Rpc name [", - m_td.FullName, - ":", - methodDefinition.Name, - "]" - })); - Weaver.fail = true; - return; - } - - hashSet.Add(methodDefinition.Name); - m_TargetRpcs.Add(methodDefinition); - var methodDefinition4 = ProcessTargetRpcInvoke(methodDefinition); - if (methodDefinition4 != null) - { - m_TargetRpcInvocationFuncs.Add(methodDefinition4); - } - - var methodDefinition5 = ProcessTargetRpcCall(methodDefinition, customAttribute); - if (methodDefinition5 != null) - { - m_TargetRpcCallFuncs.Add(methodDefinition5); - Weaver.lists.replacedMethods.Add(methodDefinition); - Weaver.lists.replacementMethods.Add(methodDefinition5); - } - - break; - } - else if (customAttribute.AttributeType.FullName == Weaver.ClientRpcType.FullName) - { - if (!ProcessMethodsValidateRpc(methodDefinition, customAttribute)) - { - return; - } - - if (hashSet.Contains(methodDefinition.Name)) - { - Log.Error(string.Concat(new string[] - { - "Duplicate ClientRpc name [", - m_td.FullName, - ":", - methodDefinition.Name, - "]" - })); - Weaver.fail = true; - return; - } - - hashSet.Add(methodDefinition.Name); - m_Rpcs.Add(methodDefinition); - var methodDefinition6 = ProcessRpcInvoke(methodDefinition); - if (methodDefinition6 != null) - { - m_RpcInvocationFuncs.Add(methodDefinition6); - } - - var methodDefinition7 = ProcessRpcCall(methodDefinition, customAttribute); - if (methodDefinition7 != null) - { - m_RpcCallFuncs.Add(methodDefinition7); - Weaver.lists.replacedMethods.Add(methodDefinition); - Weaver.lists.replacementMethods.Add(methodDefinition7); - } - - break; - } - } - } - - foreach (var item in m_CmdInvocationFuncs) - { - m_td.Methods.Add(item); - } - - foreach (var item2 in m_CmdCallFuncs) - { - m_td.Methods.Add(item2); - } - - foreach (var item3 in m_RpcInvocationFuncs) - { - m_td.Methods.Add(item3); - } - - foreach (var item4 in m_TargetRpcInvocationFuncs) - { - m_td.Methods.Add(item4); - } - - foreach (var item5 in m_RpcCallFuncs) - { - m_td.Methods.Add(item5); - } - - foreach (var item6 in m_TargetRpcCallFuncs) - { - m_td.Methods.Add(item6); - } - } - - private MethodDefinition ProcessEventInvoke(EventDefinition ed) - { - FieldDefinition fieldDefinition = null; - foreach (var fieldDefinition2 in m_td.Fields) - { - if (fieldDefinition2.FullName == ed.FullName) - { - fieldDefinition = fieldDefinition2; - break; - } - } - - MethodDefinition result; - if (fieldDefinition == null) - { - Weaver.DLog(m_td, "ERROR: no event field?!", new object[0]); - Weaver.fail = true; - result = null; - } - else - { - var methodDefinition = new MethodDefinition("InvokeSyncEvent" + ed.Name, MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, Weaver.voidType); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var label = ilprocessor.Create(OpCodes.Nop); - var instruction = ilprocessor.Create(OpCodes.Nop); - WriteClientActiveCheck(ilprocessor, ed.Name, label, "Event"); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Castclass, m_td)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fieldDefinition)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brtrue, instruction)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - ilprocessor.Append(instruction); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Castclass, m_td)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fieldDefinition)); - var methodReference = Weaver.ResolveMethod(fieldDefinition.FieldType, "Invoke"); - if (!ProcessNetworkReaderParameters(methodReference.Resolve(), ilprocessor, false)) - { - result = null; - } - else - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, methodReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - AddInvokeParameters(methodDefinition.Parameters); - result = methodDefinition; - } - } - - return result; - } - - private MethodDefinition ProcessEventCall(EventDefinition ed, CustomAttribute ca) - { - var methodReference = Weaver.ResolveMethod(ed.EventType, "Invoke"); - var methodDefinition = new MethodDefinition("Call" + ed.Name, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig, Weaver.voidType); - foreach (var parameterDefinition in methodReference.Parameters) - { - methodDefinition.Parameters.Add(new ParameterDefinition(parameterDefinition.Name, ParameterAttributes.None, parameterDefinition.ParameterType)); - } - - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var label = ilprocessor.Create(OpCodes.Nop); - WriteSetupLocals(ilprocessor); - WriteServerActiveCheck(ilprocessor, ed.Name, label, "Event"); - WriteCreateWriter(ilprocessor); - WriteMessageSize(ilprocessor); - WriteMessageId(ilprocessor, 7); - var fieldDefinition = new FieldDefinition("kEvent" + ed.Name, FieldAttributes.Private | FieldAttributes.Static, Weaver.int32Type); - m_td.Fields.Add(fieldDefinition); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldsfld, fieldDefinition)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkWriterWritePacked32)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.getComponentReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.getUNetIdReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkWriterWriteNetworkInstanceId)); - MethodDefinition result; - if (!WriteArguments(ilprocessor, methodReference.Resolve(), "SyncEvent", false)) - { - result = null; - } - else - { - var value = 0; - foreach (var customAttributeNamedArgument in ca.Fields) - { - if (customAttributeNamedArgument.Name == "channel") - { - value = (int)customAttributeNamedArgument.Argument.Value; - } - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4, value)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldstr, ed.Name)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.sendEventInternal)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - result = methodDefinition; - } - - return result; - } - - private void ProcessEvents() - { - foreach (var eventDefinition in m_td.Events) - { - foreach (var customAttribute in eventDefinition.CustomAttributes) - { - if (customAttribute.AttributeType.FullName == Weaver.SyncEventType.FullName) - { - if (eventDefinition.Name.Length > 4 && eventDefinition.Name.Substring(0, 5) != "Event") - { - Log.Error(string.Concat(new string[] - { - "Event [", - m_td.FullName, - ":", - eventDefinition.FullName, - "] doesnt have 'Event' prefix" - })); - Weaver.fail = true; - return; - } - - if (eventDefinition.EventType.Resolve().HasGenericParameters) - { - Log.Error(string.Concat(new string[] - { - "Event [", - m_td.FullName, - ":", - eventDefinition.FullName, - "] cannot have generic parameters" - })); - Weaver.fail = true; - return; - } - - m_Events.Add(eventDefinition); - var methodDefinition = ProcessEventInvoke(eventDefinition); - if (methodDefinition == null) - { - return; - } - - m_td.Methods.Add(methodDefinition); - m_EventInvocationFuncs.Add(methodDefinition); - Weaver.DLog(m_td, "ProcessEvent " + eventDefinition, new object[0]); - var methodDefinition2 = ProcessEventCall(eventDefinition, customAttribute); - m_td.Methods.Add(methodDefinition2); - Weaver.lists.replacedEvents.Add(eventDefinition); - Weaver.lists.replacementEvents.Add(methodDefinition2); - Weaver.DLog(m_td, " Event: " + eventDefinition.Name, new object[0]); - break; - } - } - } - } - - private static MethodDefinition ProcessSyncVarGet(FieldDefinition fd, string originalName) - { - var methodDefinition = new MethodDefinition("get_Network" + originalName, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.SpecialName, fd.FieldType); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fd)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - methodDefinition.Body.Variables.Add(new VariableDefinition(fd.FieldType)); - methodDefinition.Body.InitLocals = true; - methodDefinition.SemanticsAttributes = MethodSemanticsAttributes.Getter; - return methodDefinition; - } - - private MethodDefinition ProcessSyncVarSet(FieldDefinition fd, string originalName, int dirtyBit, FieldDefinition netFieldId) - { - var methodDefinition = new MethodDefinition("set_Network" + originalName, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.SpecialName, Weaver.voidType); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - - var noOperatorInstruction = ilprocessor.Create(OpCodes.Nop); - var returnInstruction = ilprocessor.Create(OpCodes.Ret); - - CheckForHookFunction(fd, out var methodDefinition2); - if (methodDefinition2 != null) - { - - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.NetworkServerGetLocalClientActive)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brfalse, noOperatorInstruction)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.getSyncVarHookGuard)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brtrue, noOperatorInstruction)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.setSyncVarHookGuard)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, methodDefinition2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.setSyncVarHookGuard)); - ilprocessor.Append(noOperatorInstruction); - } - - if (fd.FieldType.FullName == Weaver.gameObjectType.FullName) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldflda, netFieldId)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.setSyncVarGameObjectReference)); - } - else - { - var genericInstanceMethod = new GenericInstanceMethod(Weaver.setSyncVarReference); - genericInstanceMethod.GenericArguments.Add(fd.FieldType); - - var index11 = ilprocessor.Create(OpCodes.Ldarg_0); - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.UBehaviourIsServer)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brfalse_S, index11)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldflda, fd)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4, dirtyBit)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, genericInstanceMethod)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Pop)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - ilprocessor.Append(index11); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldflda, fd)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4, dirtyBit)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, genericInstanceMethod)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brfalse_S, returnInstruction)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, Weaver.NetworkBehaviourClientSendUpdateVars)); - } - - ilprocessor.Append(returnInstruction); - methodDefinition.Parameters.Add(new ParameterDefinition("value", ParameterAttributes.In, fd.FieldType)); - methodDefinition.SemanticsAttributes = MethodSemanticsAttributes.Setter; - return methodDefinition; - } - - private void ProcessSyncVar(FieldDefinition fd, int dirtyBit) - { - var name = fd.Name; - Weaver.lists.replacedFields.Add(fd); - Weaver.DLog(m_td, $"Found SyncVar {fd.Name} of type {fd.FieldType}", new object[0]); - FieldDefinition fieldDefinition = null; - if (fd.FieldType.FullName == Weaver.gameObjectType.FullName) - { - fieldDefinition = new FieldDefinition("___" + fd.Name + "NetId", FieldAttributes.Private, Weaver.NetworkInstanceIdType); - m_SyncVarNetIds.Add(fieldDefinition); - Weaver.lists.netIdFields.Add(fieldDefinition); - } - - var methodDefinition = ProcessSyncVarGet(fd, name); - var methodDefinition2 = ProcessSyncVarSet(fd, name, dirtyBit, fieldDefinition); - var item = new PropertyDefinition("Network" + name, PropertyAttributes.None, fd.FieldType) - { - GetMethod = methodDefinition, - SetMethod = methodDefinition2 - }; - m_td.Methods.Add(methodDefinition); - m_td.Methods.Add(methodDefinition2); - m_td.Properties.Add(item); - Weaver.lists.replacementProperties.Add(methodDefinition2); - } - - private static MethodDefinition ProcessSyncListInvoke(FieldDefinition fd) - { - var methodDefinition = new MethodDefinition("InvokeSyncList" + fd.Name, MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, Weaver.voidType); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var label = ilprocessor.Create(OpCodes.Nop); - WriteClientActiveCheck(ilprocessor, fd.Name, label, "SyncList"); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Castclass, fd.DeclaringType)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fd)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - var genericInstanceType = (GenericInstanceType)fd.FieldType.Resolve().BaseType; - genericInstanceType = (GenericInstanceType)Weaver.scriptDef.MainModule.ImportReference(genericInstanceType); - var typeReference = genericInstanceType.GenericArguments[0]; - var method = Helpers.MakeHostInstanceGeneric(Weaver.SyncListInitHandleMsg, new TypeReference[] - { - typeReference - }); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, method)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - AddInvokeParameters(methodDefinition.Parameters); - return methodDefinition; - } - - private FieldDefinition ProcessSyncList(FieldDefinition fd, int dirtyBit) - { - var methodDefinition = ProcessSyncListInvoke(fd); - m_SyncListInvocationFuncs.Add(methodDefinition); - return new FieldDefinition("kList" + fd.Name, FieldAttributes.Private | FieldAttributes.Static, Weaver.int32Type); - } - - private void ProcessSyncVars() - { - var num = 0; - var num2 = Weaver.GetSyncVarStart(m_td.BaseType.FullName); - m_SyncVarNetIds.Clear(); - var list = new List(); - foreach (var fieldDefinition in m_td.Fields) - { - foreach (var customAttribute in fieldDefinition.CustomAttributes) - { - if (customAttribute.AttributeType.FullName == Weaver.SyncVarType.FullName) - { - var typeDefinition = fieldDefinition.FieldType.Resolve(); - if (Weaver.IsDerivedFrom(typeDefinition, Weaver.NetworkBehaviourType)) - { - Log.Error("SyncVar [" + fieldDefinition.FullName + "] cannot be derived from NetworkBehaviour."); - Weaver.fail = true; - return; - } - - if (Weaver.IsDerivedFrom(typeDefinition, Weaver.ScriptableObjectType)) - { - Log.Error("SyncVar [" + fieldDefinition.FullName + "] cannot be derived from ScriptableObject."); - Weaver.fail = true; - return; - } - - if ((ushort)(fieldDefinition.Attributes & FieldAttributes.Static) != 0) - { - Log.Error("SyncVar [" + fieldDefinition.FullName + "] cannot be static."); - Weaver.fail = true; - return; - } - - if (typeDefinition.HasGenericParameters) - { - Log.Error("SyncVar [" + fieldDefinition.FullName + "] cannot have generic parameters."); - Weaver.fail = true; - return; - } - - if (typeDefinition.IsInterface) - { - Log.Error("SyncVar [" + fieldDefinition.FullName + "] cannot be an interface."); - Weaver.fail = true; - return; - } - - var name = typeDefinition.Module.Name; - if (name != Weaver.scriptDef.MainModule.Name && name != Weaver.UnityAssemblyDefinition.MainModule.Name && name != Weaver.QNetAssemblyDefinition.MainModule.Name && name != Weaver.corLib.Name && name != "System.Runtime.dll") - { - Log.Error($"SyncVar [{fieldDefinition.FullName}] is from an inaccessible module! : [{name}]"); - Weaver.fail = true; - return; - } - - if (fieldDefinition.FieldType.IsArray) - { - Log.Error("SyncVar [" + fieldDefinition.FullName + "] cannot be an array. Use a SyncList instead."); - Weaver.fail = true; - return; - } - - if (Helpers.InheritsFromSyncList(fieldDefinition.FieldType)) - { - Log.Warning(string.Format("Script class [{0}] has [SyncVar] attribute on SyncList field {1}, SyncLists should not be marked with SyncVar.", m_td.FullName, fieldDefinition.Name)); - break; - } - - m_SyncVars.Add(fieldDefinition); - ProcessSyncVar(fieldDefinition, 1 << num2); - num2++; - num++; - if (num2 == 32) - { - Log.Error(string.Concat(new object[] - { - "Script class [", - m_td.FullName, - "] has too many SyncVars (", - 32, - "). (This could include base classes)" - })); - Weaver.fail = true; - return; - } - - break; - } - } - - if (fieldDefinition.FieldType.FullName.Contains("UnityEngine.Networking.SyncListStruct")) - { - Log.Error("SyncListStruct member variable [" + fieldDefinition.FullName + "] must use a dervied class, like \"class MySyncList : SyncListStruct {}\"."); - Weaver.fail = true; - return; - } - - if (Weaver.IsDerivedFrom(fieldDefinition.FieldType.Resolve(), Weaver.SyncListType)) - { - if (fieldDefinition.IsStatic) - { - Log.Error(string.Concat(new string[] - { - "SyncList [", - m_td.FullName, - ":", - fieldDefinition.FullName, - "] cannot be a static" - })); - Weaver.fail = true; - return; - } - - m_SyncVars.Add(fieldDefinition); - m_SyncLists.Add(fieldDefinition); - list.Add(ProcessSyncList(fieldDefinition, 1 << num2)); - num2++; - num++; - if (num2 == 32) - { - Log.Error(string.Concat(new object[] - { - "Script class [", - m_td.FullName, - "] has too many SyncVars (", - 32, - "). (This could include base classes)" - })); - Weaver.fail = true; - return; - } - } - } - - foreach (var fieldDefinition2 in list) - { - m_td.Fields.Add(fieldDefinition2); - m_SyncListStaticFields.Add(fieldDefinition2); - } - - foreach (var item in m_SyncVarNetIds) - { - m_td.Fields.Add(item); - } - - foreach (var item2 in m_SyncListInvocationFuncs) - { - m_td.Methods.Add(item2); - } - - Weaver.SetNumSyncVars(m_td.FullName, num); - } - - private static int GetHashCode(string s) - { - var assembly = typeof(Unity.UNetWeaver.Program).Assembly; - var networkProcessorType = assembly.GetType("Unity.UNetWeaver.NetworkBehaviourProcessor"); - var methodInfo = networkProcessorType.GetMethod("GetHashCode", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); - return (int)methodInfo.Invoke(null, new object[] { s }); - } - - private bool HasMethod(string name) - { - foreach (var methodDefinition in m_td.Methods) - { - if (methodDefinition.Name == name) - { - return true; - } - } - - return false; - } - - private List m_SyncVars = new List(); - - private List m_SyncLists = new List(); - - private List m_SyncVarNetIds = new List(); - - private List m_Cmds = new List(); - - private List m_Rpcs = new List(); - - private List m_TargetRpcs = new List(); - - private List m_Events = new List(); - - private List m_SyncListStaticFields = new List(); - - private List m_CmdInvocationFuncs = new List(); - - private List m_SyncListInvocationFuncs = new List(); - - private List m_RpcInvocationFuncs = new List(); - - private List m_TargetRpcInvocationFuncs = new List(); - - private List m_EventInvocationFuncs = new List(); - - private List m_CmdCallFuncs = new List(); - - private List m_RpcCallFuncs = new List(); - - private List m_TargetRpcCallFuncs = new List(); - - private const int k_SyncVarLimit = 32; - - private int m_QosChannel; - - private TypeDefinition m_td; - - private int m_NetIdFieldCounter; - - private const string k_CmdPrefix = "InvokeCmd"; - - private const string k_RpcPrefix = "InvokeRpc"; - - private const string k_TargetRpcPrefix = "InvokeTargetRpc"; - } -} diff --git a/QNetWeaver/Program.cs b/QNetWeaver/Program.cs deleted file mode 100644 index 8891e550..00000000 --- a/QNetWeaver/Program.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.IO; - -namespace QNetWeaver -{ - public class Program - { - private static void Main(string[] args) - { - Console.WriteLine("Start weaving process."); - - if (args.Length == 0) - { - Log.Error("No args supplied!"); - } - - var unityEngine = args[0]; - var qnetDLL = args[1]; - var unetDLL = args[2]; - var outputDirectory = args[3]; - var assembly = args[4]; - - CheckDLLPath(unityEngine); - CheckDLLPath(qnetDLL); - CheckDLLPath(unetDLL); - CheckOutputDirectory(outputDirectory); - CheckAssemblyPath(assembly); - Weaver.WeaveAssemblies(assembly, null, null, outputDirectory, unityEngine, qnetDLL, unetDLL); - } - - private static void CheckDLLPath(string path) - { - Console.WriteLine($"Check dll {path} ..."); - if (!File.Exists(path)) - { - throw new Exception("dll could not be located at " + path + "!"); - } - - Console.WriteLine($"Path OK!"); - } - - private static void CheckAssemblyPath(string assemblyPath) - { - Console.WriteLine($"Check assembly path {assemblyPath} ..."); - if (!File.Exists(assemblyPath)) - { - throw new Exception("Assembly " + assemblyPath + " does not exist!"); - } - - Console.WriteLine($"Assembly Path OK!"); - } - - private static void CheckOutputDirectory(string outputDir) - { - Console.WriteLine($"Check output path {outputDir} ..."); - if (!Directory.Exists(outputDir)) - { - Directory.CreateDirectory(outputDir); - } - - Console.WriteLine($"Output Path OK!"); - } - } -} diff --git a/QNetWeaver/Properties/AssemblyInfo.cs b/QNetWeaver/Properties/AssemblyInfo.cs deleted file mode 100644 index ad8f0317..00000000 --- a/QNetWeaver/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("QNetWeaver")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("QNetWeaver")] -[assembly: AssemblyCopyright("Copyright © 2021")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("e23551f3-c095-4f50-8bf7-85bb2661859b")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/QNetWeaver/QNetWeaver.csproj b/QNetWeaver/QNetWeaver.csproj deleted file mode 100644 index be1b5de5..00000000 --- a/QNetWeaver/QNetWeaver.csproj +++ /dev/null @@ -1,72 +0,0 @@ - - - - - Debug - AnyCPU - {E23551F3-C095-4F50-8BF7-85BB2661859B} - Exe - QNetWeaver - QNetWeaver - v3.5 - 512 - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - true - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - true - - - 9.0 - - - - - - - - - - ..\..\..\..\..\..\Program Files\Unity\Hub\Editor\2017.4.33f1\Editor\Data\Managed\Unity.Cecil.dll - - - ..\..\..\..\..\..\Program Files\Unity\Hub\Editor\2017.4.33f1\Editor\Data\Managed\Unity.Cecil.Mdb.dll - - - ..\..\..\..\..\..\Program Files\Unity\Hub\Editor\2017.4.33f1\Editor\Data\Managed\Unity.Cecil.Pdb.dll - - - ..\..\..\..\..\..\Program Files\Unity\Hub\Editor\2017.4.33f1\Editor\Data\Managed\Unity.UNetWeaver.dll - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/QNetWeaver/SyncListStructProcessor.cs b/QNetWeaver/SyncListStructProcessor.cs deleted file mode 100644 index 30bc3d4b..00000000 --- a/QNetWeaver/SyncListStructProcessor.cs +++ /dev/null @@ -1,309 +0,0 @@ -using Mono.Cecil; -using Mono.Cecil.Cil; - -namespace QNetWeaver -{ - internal class SyncListStructProcessor - { - public SyncListStructProcessor(TypeDefinition typeDef) - { - Weaver.DLog(typeDef, "SyncListStructProcessor for " + typeDef.Name, new object[0]); - m_TypeDef = typeDef; - } - - public void Process() - { - var genericInstanceType = (GenericInstanceType)m_TypeDef.BaseType; - if (genericInstanceType.GenericArguments.Count == 0) - { - Weaver.fail = true; - Log.Error("SyncListStructProcessor no generic args"); - } - else - { - m_ItemType = Weaver.scriptDef.MainModule.ImportReference(genericInstanceType.GenericArguments[0]); - Weaver.DLog(m_TypeDef, "SyncListStructProcessor Start item:" + m_ItemType.FullName, new object[0]); - Weaver.ResetRecursionCount(); - var methodReference = GenerateSerialization(); - if (!Weaver.fail) - { - var methodReference2 = GenerateDeserialization(); - if (methodReference2 != null && methodReference != null) - { - GenerateReadFunc(methodReference2); - GenerateWriteFunc(methodReference); - Weaver.DLog(m_TypeDef, "SyncListStructProcessor Done", new object[0]); - } - } - } - } - - private void GenerateReadFunc(MethodReference readItemFunc) - { - var text = "_ReadStruct" + m_TypeDef.Name + "_"; - if (m_TypeDef.DeclaringType != null) - { - text += m_TypeDef.DeclaringType.Name; - } - else - { - text += "None"; - } - - var methodDefinition = new MethodDefinition(text, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, Weaver.voidType); - methodDefinition.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkReaderType))); - methodDefinition.Parameters.Add(new ParameterDefinition("instance", ParameterAttributes.None, m_TypeDef)); - methodDefinition.Body.Variables.Add(new VariableDefinition(Weaver.uint16Type)); - methodDefinition.Body.Variables.Add(new VariableDefinition(Weaver.uint16Type)); - methodDefinition.Body.InitLocals = true; - var ilprocessor = methodDefinition.Body.GetILProcessor(); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkReadUInt16)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - var method = Helpers.MakeHostInstanceGeneric(Weaver.SyncListClear, new TypeReference[] - { - m_ItemType - }); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, method)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_1)); - var instruction = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Br, instruction)); - var instruction2 = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(instruction2); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, readItemFunc)); - var self = Weaver.ResolveMethod(Weaver.SyncListStructType, "AddInternal"); - var method2 = Helpers.MakeHostInstanceGeneric(self, new TypeReference[] - { - m_ItemType - }); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, method2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Add)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Conv_U2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_1)); - ilprocessor.Append(instruction); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Blt, instruction2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - Weaver.RegisterReadByReferenceFunc(m_TypeDef.FullName, methodDefinition); - } - - private void GenerateWriteFunc(MethodReference writeItemFunc) - { - var text = "_WriteStruct" + m_TypeDef.GetElementType().Name + "_"; - if (m_TypeDef.DeclaringType != null) - { - text += m_TypeDef.DeclaringType.Name; - } - else - { - text += "None"; - } - - var methodDefinition = new MethodDefinition(text, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, Weaver.voidType); - methodDefinition.Parameters.Add(new ParameterDefinition("writer", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkWriterType))); - methodDefinition.Parameters.Add(new ParameterDefinition("value", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(m_TypeDef))); - methodDefinition.Body.Variables.Add(new VariableDefinition(Weaver.uint16Type)); - methodDefinition.Body.Variables.Add(new VariableDefinition(Weaver.uint16Type)); - methodDefinition.Body.InitLocals = true; - var ilprocessor = methodDefinition.Body.GetILProcessor(); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - var self = Weaver.ResolveMethod(Weaver.SyncListStructType, "get_Count"); - var method = Helpers.MakeHostInstanceGeneric(self, new TypeReference[] - { - m_ItemType - }); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, method)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, Weaver.NetworkWriteUInt16)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_1)); - var instruction = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Br, instruction)); - var instruction2 = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(instruction2); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - var self2 = Weaver.ResolveMethod(Weaver.SyncListStructType, "GetItem"); - var method2 = Helpers.MakeHostInstanceGeneric(self2, new TypeReference[] - { - m_ItemType - }); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, method2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Callvirt, writeItemFunc)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Add)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Conv_U2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_1)); - ilprocessor.Append(instruction); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Blt, instruction2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - Weaver.RegisterWriteFunc(m_TypeDef.FullName, methodDefinition); - } - - private MethodReference GenerateSerialization() - { - Weaver.DLog(m_TypeDef, " SyncListStruct GenerateSerialization", new object[0]); - foreach (var methodDefinition in m_TypeDef.Methods) - { - if (methodDefinition.Name == "SerializeItem") - { - Weaver.DLog(m_TypeDef, " Abort - is SerializeItem", new object[0]); - return methodDefinition; - } - } - - var methodDefinition2 = new MethodDefinition("SerializeItem", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, Weaver.voidType); - methodDefinition2.Parameters.Add(new ParameterDefinition("writer", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkWriterType))); - methodDefinition2.Parameters.Add(new ParameterDefinition("item", ParameterAttributes.None, m_ItemType)); - var ilprocessor = methodDefinition2.Body.GetILProcessor(); - MethodReference result; - if (m_ItemType.IsGenericInstance) - { - Weaver.fail = true; - Log.Error("GenerateSerialization for " + Helpers.PrettyPrintType(m_ItemType) + " failed. Struct passed into SyncListStruct can't have generic parameters"); - result = null; - } - else - { - foreach (var fieldDefinition in m_ItemType.Resolve().Fields) - { - if (!fieldDefinition.IsStatic && !fieldDefinition.IsPrivate && !fieldDefinition.IsSpecialName) - { - var fieldReference = Weaver.scriptDef.MainModule.ImportReference(fieldDefinition); - var typeDefinition = fieldReference.FieldType.Resolve(); - if (typeDefinition.HasGenericParameters) - { - Weaver.fail = true; - Log.Error(string.Concat(new object[] - { - "GenerateSerialization for ", - m_TypeDef.Name, - " [", - typeDefinition, - "/", - typeDefinition.FullName, - "]. UNet [MessageBase] member cannot have generic parameters." - })); - return null; - } - - if (typeDefinition.IsInterface) - { - Weaver.fail = true; - Log.Error(string.Concat(new object[] - { - "GenerateSerialization for ", - m_TypeDef.Name, - " [", - typeDefinition, - "/", - typeDefinition.FullName, - "]. UNet [MessageBase] member cannot be an interface." - })); - return null; - } - - var writeFunc = Weaver.GetWriteFunc(fieldDefinition.FieldType); - if (writeFunc == null) - { - Weaver.fail = true; - Log.Error(string.Concat(new object[] - { - "GenerateSerialization for ", - m_TypeDef.Name, - " unknown type [", - typeDefinition, - "/", - typeDefinition.FullName, - "]. UNet [MessageBase] member variables must be basic types." - })); - return null; - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fieldReference)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, writeFunc)); - } - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_TypeDef.Methods.Add(methodDefinition2); - result = methodDefinition2; - } - - return result; - } - - private MethodReference GenerateDeserialization() - { - Weaver.DLog(m_TypeDef, " GenerateDeserialization", new object[0]); - foreach (var methodDefinition in m_TypeDef.Methods) - { - if (methodDefinition.Name == "DeserializeItem") - { - return methodDefinition; - } - } - - var methodDefinition2 = new MethodDefinition("DeserializeItem", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, m_ItemType); - methodDefinition2.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, Weaver.scriptDef.MainModule.ImportReference(Weaver.NetworkReaderType))); - var ilprocessor = methodDefinition2.Body.GetILProcessor(); - ilprocessor.Body.InitLocals = true; - ilprocessor.Body.Variables.Add(new VariableDefinition(m_ItemType)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloca, 0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Initobj, m_ItemType)); - foreach (var fieldDefinition in m_ItemType.Resolve().Fields) - { - if (!fieldDefinition.IsStatic && !fieldDefinition.IsPrivate && !fieldDefinition.IsSpecialName) - { - var fieldReference = Weaver.scriptDef.MainModule.ImportReference(fieldDefinition); - var typeDefinition = fieldReference.FieldType.Resolve(); - var readFunc = Weaver.GetReadFunc(fieldDefinition.FieldType); - if (readFunc == null) - { - Weaver.fail = true; - Log.Error(string.Concat(new object[] - { - "GenerateDeserialization for ", - m_TypeDef.Name, - " unknown type [", - typeDefinition, - "]. UNet [SyncVar] member variables must be basic types." - })); - return null; - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloca, 0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, readFunc)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stfld, fieldReference)); - } - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - m_TypeDef.Methods.Add(methodDefinition2); - return methodDefinition2; - } - - private TypeDefinition m_TypeDef; - - private TypeReference m_ItemType; - } -} diff --git a/QNetWeaver/Weaver.cs b/QNetWeaver/Weaver.cs deleted file mode 100644 index 8f3ee305..00000000 --- a/QNetWeaver/Weaver.cs +++ /dev/null @@ -1,2038 +0,0 @@ -using Mono.Cecil; -using Mono.Cecil.Cil; -using Mono.Cecil.Mdb; -using Mono.Cecil.Pdb; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; - -namespace QNetWeaver -{ - internal class Weaver - { - public static void ResetRecursionCount() => s_RecursionCount = 0; - - public static bool CanBeResolved(TypeReference parent) - { - while (parent != null) - { - bool result; - if (parent.Scope.Name == "Windows") - { - result = false; - } - else - { - if (!(parent.Scope.Name == "mscorlib")) - { - try - { - parent = parent.Resolve().BaseType; - } - catch - { - return false; - } - - continue; - } - - var typeDefinition = parent.Resolve(); - result = (typeDefinition != null); - } - - return result; - } - - return true; - } - - public static bool IsArrayType(TypeReference variable) => (!variable.IsArray || !((ArrayType)variable).ElementType.IsArray) && (!variable.IsArray || ((ArrayType)variable).Rank <= 1); - - public static void DLog(TypeDefinition td, string fmt, params object[] args) - { - if (m_DebugFlag) - { - Console.WriteLine("[" + td.Name + "] " + string.Format(fmt, args)); - } - } - - public static int GetSyncVarStart(string className) - { - int result; - if (lists.numSyncVars.ContainsKey(className)) - { - var num = lists.numSyncVars[className]; - result = num; - } - else - { - result = 0; - } - - return result; - } - - public static void SetNumSyncVars(string className, int num) => lists.numSyncVars[className] = num; - - public static MethodReference GetWriteFunc(TypeReference variable) - { - MethodReference result; - if (s_RecursionCount++ > 128) - { - Log.Error("GetWriteFunc recursion depth exceeded for " + variable.Name + ". Check for self-referencing member variables."); - fail = true; - result = null; - } - else - { - if (lists.writeFuncs.ContainsKey(variable.FullName)) - { - var methodReference = lists.writeFuncs[variable.FullName]; - if (methodReference.Parameters[0].ParameterType.IsArray == variable.IsArray) - { - return methodReference; - } - } - - if (variable.IsByReference) - { - Log.Error("GetWriteFunc variable.IsByReference error."); - result = null; - } - else - { - MethodDefinition methodDefinition; - if (variable.IsArray) - { - var elementType = variable.GetElementType(); - var writeFunc = GetWriteFunc(elementType); - if (writeFunc == null) - { - return null; - } - - methodDefinition = GenerateArrayWriteFunc(variable, writeFunc); - } - else - { - if (variable.Resolve().IsEnum) - { - return NetworkWriterWriteInt32; - } - - methodDefinition = GenerateWriterFunction(variable); - } - - if (methodDefinition == null) - { - result = null; - } - else - { - RegisterWriteFunc(variable.FullName, methodDefinition); - result = methodDefinition; - } - } - } - - return result; - } - - public static void RegisterWriteFunc(string name, MethodDefinition newWriterFunc) - { - lists.writeFuncs[name] = newWriterFunc; - lists.generatedWriteFunctions.Add(newWriterFunc); - ConfirmGeneratedCodeClass(scriptDef.MainModule); - lists.generateContainerClass.Methods.Add(newWriterFunc); - } - - public static MethodReference GetReadByReferenceFunc(TypeReference variable) - { - MethodReference result; - if (lists.readByReferenceFuncs.ContainsKey(variable.FullName)) - { - result = lists.readByReferenceFuncs[variable.FullName]; - } - else - { - result = null; - } - - return result; - } - - public static MethodReference GetReadFunc(TypeReference variable) - { - if (lists.readFuncs.ContainsKey(variable.FullName)) - { - var methodReference = lists.readFuncs[variable.FullName]; - if (methodReference.ReturnType.IsArray == variable.IsArray) - { - return methodReference; - } - } - - var typeDefinition = variable.Resolve(); - MethodReference result; - if (typeDefinition == null) - { - Log.Error("GetReadFunc unsupported type " + variable.FullName); - result = null; - } - else if (variable.IsByReference) - { - Log.Error("GetReadFunc variable.IsByReference error."); - result = null; - } - else - { - MethodDefinition methodDefinition; - if (variable.IsArray) - { - var elementType = variable.GetElementType(); - var readFunc = GetReadFunc(elementType); - if (readFunc == null) - { - return null; - } - - methodDefinition = GenerateArrayReadFunc(variable, readFunc); - } - else - { - if (typeDefinition.IsEnum) - { - return NetworkReaderReadInt32; - } - - methodDefinition = GenerateReadFunction(variable); - } - - if (methodDefinition == null) - { - Log.Error("GetReadFunc unable to generate function for:" + variable.FullName); - result = null; - } - else - { - RegisterReadFunc(variable.FullName, methodDefinition); - result = methodDefinition; - } - } - - return result; - } - - public static void RegisterReadByReferenceFunc(string name, MethodDefinition newReaderFunc) - { - lists.readByReferenceFuncs[name] = newReaderFunc; - lists.generatedReadFunctions.Add(newReaderFunc); - ConfirmGeneratedCodeClass(scriptDef.MainModule); - lists.generateContainerClass.Methods.Add(newReaderFunc); - } - - public static void RegisterReadFunc(string name, MethodDefinition newReaderFunc) - { - lists.readFuncs[name] = newReaderFunc; - lists.generatedReadFunctions.Add(newReaderFunc); - ConfirmGeneratedCodeClass(scriptDef.MainModule); - lists.generateContainerClass.Methods.Add(newReaderFunc); - } - - private static MethodDefinition GenerateArrayReadFunc(TypeReference variable, MethodReference elementReadFunc) - { - MethodDefinition result; - if (!IsArrayType(variable)) - { - Log.Error(variable.FullName + " is an unsupported array type. Jagged and multidimensional arrays are not supported"); - result = null; - } - else - { - var text = "_ReadArray" + variable.GetElementType().Name + "_"; - if (variable.DeclaringType != null) - { - text += variable.DeclaringType.Name; - } - else - { - text += "None"; - } - - var methodDefinition = new MethodDefinition(text, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, variable); - methodDefinition.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, scriptDef.MainModule.ImportReference(NetworkReaderType))); - methodDefinition.Body.Variables.Add(new VariableDefinition(int32Type)); - methodDefinition.Body.Variables.Add(new VariableDefinition(variable)); - methodDefinition.Body.Variables.Add(new VariableDefinition(int32Type)); - methodDefinition.Body.InitLocals = true; - var ilprocessor = methodDefinition.Body.GetILProcessor(); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, NetworkReadUInt16)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - var instruction = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brtrue, instruction)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Newarr, variable.GetElementType())); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - ilprocessor.Append(instruction); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Newarr, variable.GetElementType())); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_2)); - var instruction2 = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Br, instruction2)); - var instruction3 = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(instruction3); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldelema, variable.GetElementType())); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, elementReadFunc)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stobj, variable.GetElementType())); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Add)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_2)); - ilprocessor.Append(instruction2); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Blt, instruction3)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - result = methodDefinition; - } - - return result; - } - - private static MethodDefinition GenerateArrayWriteFunc(TypeReference variable, MethodReference elementWriteFunc) - { - MethodDefinition result; - if (!IsArrayType(variable)) - { - Log.Error(variable.FullName + " is an unsupported array type. Jagged and multidimensional arrays are not supported"); - result = null; - } - else - { - var text = "_WriteArray" + variable.GetElementType().Name + "_"; - if (variable.DeclaringType != null) - { - text += variable.DeclaringType.Name; - } - else - { - text += "None"; - } - - var methodDefinition = new MethodDefinition(text, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, voidType); - methodDefinition.Parameters.Add(new ParameterDefinition("writer", ParameterAttributes.None, scriptDef.MainModule.ImportReference(NetworkWriterType))); - methodDefinition.Parameters.Add(new ParameterDefinition("value", ParameterAttributes.None, scriptDef.MainModule.ImportReference(variable))); - methodDefinition.Body.Variables.Add(new VariableDefinition(uint16Type)); - methodDefinition.Body.Variables.Add(new VariableDefinition(uint16Type)); - methodDefinition.Body.InitLocals = true; - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var instruction = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Brtrue, instruction)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, NetworkWriteUInt16)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - ilprocessor.Append(instruction); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldlen)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Conv_I4)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Conv_U2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, NetworkWriteUInt16)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_1)); - var instruction2 = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(ilprocessor.Create(OpCodes.Br, instruction2)); - var instruction3 = ilprocessor.Create(OpCodes.Nop); - ilprocessor.Append(instruction3); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldelema, variable.GetElementType())); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldobj, variable.GetElementType())); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, elementWriteFunc)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldc_I4_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Add)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Conv_U2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_1)); - ilprocessor.Append(instruction2); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldlen)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Conv_I4)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Blt, instruction3)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - result = methodDefinition; - } - - return result; - } - - private static MethodDefinition GenerateWriterFunction(TypeReference variable) - { - MethodDefinition result; - if (!IsValidTypeToGenerate(variable.Resolve())) - { - result = null; - } - else - { - var text = "_Write" + variable.Name + "_"; - if (variable.DeclaringType != null) - { - text += variable.DeclaringType.Name; - } - else - { - text += "None"; - } - - var methodDefinition = new MethodDefinition(text, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, voidType); - methodDefinition.Parameters.Add(new ParameterDefinition("writer", ParameterAttributes.None, scriptDef.MainModule.ImportReference(NetworkWriterType))); - methodDefinition.Parameters.Add(new ParameterDefinition("value", ParameterAttributes.None, scriptDef.MainModule.ImportReference(variable))); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - var num = 0U; - foreach (var fieldDefinition in variable.Resolve().Fields) - { - if (!fieldDefinition.IsStatic && !fieldDefinition.IsPrivate) - { - if (fieldDefinition.FieldType.Resolve().HasGenericParameters) - { - fail = true; - Log.Error(string.Concat(new object[] - { - "WriteReadFunc for ", - fieldDefinition.Name, - " [", - fieldDefinition.FieldType, - "/", - fieldDefinition.FieldType.FullName, - "]. Cannot have generic parameters." - })); - return null; - } - - if (fieldDefinition.FieldType.Resolve().IsInterface) - { - fail = true; - Log.Error(string.Concat(new object[] - { - "WriteReadFunc for ", - fieldDefinition.Name, - " [", - fieldDefinition.FieldType, - "/", - fieldDefinition.FieldType.FullName, - "]. Cannot be an interface." - })); - return null; - } - - var writeFunc = GetWriteFunc(fieldDefinition.FieldType); - if (writeFunc == null) - { - Log.Error(string.Concat(new object[] - { - "WriteReadFunc for ", - fieldDefinition.Name, - " type ", - fieldDefinition.FieldType, - " no supported" - })); - fail = true; - return null; - } - - num += 1U; - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_1)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldfld, fieldDefinition)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, writeFunc)); - } - } - - if (num == 0U) - { - Log.Warning("The class / struct " + variable.Name + " has no public or non-static fields to serialize"); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - result = methodDefinition; - } - - return result; - } - - private static MethodDefinition GenerateReadFunction(TypeReference variable) - { - MethodDefinition result; - if (!IsValidTypeToGenerate(variable.Resolve())) - { - result = null; - } - else - { - var text = "_Read" + variable.Name + "_"; - if (variable.DeclaringType != null) - { - text += variable.DeclaringType.Name; - } - else - { - text += "None"; - } - - var methodDefinition = new MethodDefinition(text, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, variable); - methodDefinition.Body.Variables.Add(new VariableDefinition(variable)); - methodDefinition.Body.InitLocals = true; - methodDefinition.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, scriptDef.MainModule.ImportReference(NetworkReaderType))); - var ilprocessor = methodDefinition.Body.GetILProcessor(); - if (variable.IsValueType) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloca, 0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Initobj, variable)); - } - else - { - var methodDefinition2 = ResolveDefaultPublicCtor(variable); - if (methodDefinition2 == null) - { - Log.Error("The class " + variable.Name + " has no default constructor or it's private, aborting."); - return null; - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Newobj, methodDefinition2)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stloc_0)); - } - - var num = 0U; - foreach (var fieldDefinition in variable.Resolve().Fields) - { - if (!fieldDefinition.IsStatic && !fieldDefinition.IsPrivate) - { - if (variable.IsValueType) - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloca, 0)); - } - else - { - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc, 0)); - } - - var readFunc = GetReadFunc(fieldDefinition.FieldType); - if (readFunc == null) - { - Log.Error(string.Concat(new object[] - { - "GetReadFunc for ", - fieldDefinition.Name, - " type ", - fieldDefinition.FieldType, - " no supported" - })); - fail = true; - return null; - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldarg_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Call, readFunc)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Stfld, fieldDefinition)); - num += 1U; - } - } - - if (num == 0U) - { - Log.Warning("The class / struct " + variable.Name + " has no public or non-static fields to serialize"); - } - - ilprocessor.Append(ilprocessor.Create(OpCodes.Ldloc_0)); - ilprocessor.Append(ilprocessor.Create(OpCodes.Ret)); - result = methodDefinition; - } - - return result; - } - - private static Instruction GetEventLoadInstruction(ModuleDefinition moduleDef, TypeDefinition td, MethodDefinition md, int iCount, FieldReference foundEventField) - { - while (iCount > 0) - { - iCount--; - var instruction = md.Body.Instructions[iCount]; - if (instruction.OpCode == OpCodes.Ldfld) - { - if (instruction.Operand == foundEventField) - { - DLog(td, " " + instruction.Operand, new object[0]); - return instruction; - } - } - } - - return null; - } - - private static void ProcessInstructionMethod(ModuleDefinition moduleDef, TypeDefinition td, MethodDefinition md, Instruction instr, MethodReference opMethodRef, int iCount) - { - if (opMethodRef.Name == "Invoke") - { - var flag = false; - while (iCount > 0 && !flag) - { - iCount--; - var instruction = md.Body.Instructions[iCount]; - if (instruction.OpCode == OpCodes.Ldfld) - { - var fieldReference = instruction.Operand as FieldReference; - for (var i = 0; i < lists.replacedEvents.Count; i++) - { - var eventDefinition = lists.replacedEvents[i]; - if (eventDefinition.Name == fieldReference.Name) - { - instr.Operand = lists.replacementEvents[i]; - instruction.OpCode = OpCodes.Nop; - flag = true; - break; - } - } - } - } - } - else if (lists.replacementMethodNames.Contains(opMethodRef.FullName)) - { - for (var j = 0; j < lists.replacedMethods.Count; j++) - { - var methodDefinition = lists.replacedMethods[j]; - if (opMethodRef.FullName == methodDefinition.FullName) - { - instr.Operand = lists.replacementMethods[j]; - break; - } - } - } - } - - private static void ConfirmGeneratedCodeClass(ModuleDefinition moduleDef) - { - if (lists.generateContainerClass == null) - { - lists.generateContainerClass = new TypeDefinition("Unity", "GeneratedNetworkCode", TypeAttributes.Public | TypeAttributes.AutoClass | TypeAttributes.BeforeFieldInit, objectType); - var methodDefinition = new MethodDefinition(".ctor", MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, voidType); - methodDefinition.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0)); - methodDefinition.Body.Instructions.Add(Instruction.Create(OpCodes.Call, ResolveMethod(objectType, ".ctor"))); - methodDefinition.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); - lists.generateContainerClass.Methods.Add(methodDefinition); - } - } - - private static void ProcessInstructionField(TypeDefinition td, MethodDefinition md, Instruction i, FieldDefinition opField) - { - if (!(md.Name == ".ctor") && !(md.Name == "OnDeserialize")) - { - for (var j = 0; j < lists.replacedFields.Count; j++) - { - var fieldDefinition = lists.replacedFields[j]; - if (opField == fieldDefinition) - { - i.OpCode = OpCodes.Call; - i.Operand = lists.replacementProperties[j]; - break; - } - } - } - } - - private static void ProcessInstruction(ModuleDefinition moduleDef, TypeDefinition td, MethodDefinition md, Instruction i, int iCount) - { - if (i.OpCode == OpCodes.Call || i.OpCode == OpCodes.Callvirt) - { - var methodReference = i.Operand as MethodReference; - if (methodReference != null) - { - ProcessInstructionMethod(moduleDef, td, md, i, methodReference, iCount); - } - } - - if (i.OpCode == OpCodes.Stfld) - { - var fieldDefinition = i.Operand as FieldDefinition; - if (fieldDefinition != null) - { - ProcessInstructionField(td, md, i, fieldDefinition); - } - } - } - - private static void InjectGuardParameters(MethodDefinition md, ILProcessor worker, Instruction top) - { - var num = (!md.Resolve().IsStatic) ? 1 : 0; - for (var i = 0; i < md.Parameters.Count; i++) - { - var parameterDefinition = md.Parameters[i]; - if (parameterDefinition.IsOut) - { - var elementType = parameterDefinition.ParameterType.GetElementType(); - if (elementType.IsPrimitive) - { - worker.InsertBefore(top, worker.Create(OpCodes.Ldarg, i + num)); - worker.InsertBefore(top, worker.Create(OpCodes.Ldc_I4_0)); - worker.InsertBefore(top, worker.Create(OpCodes.Stind_I4)); - } - else - { - md.Body.Variables.Add(new VariableDefinition(elementType)); - md.Body.InitLocals = true; - worker.InsertBefore(top, worker.Create(OpCodes.Ldarg, i + num)); - worker.InsertBefore(top, worker.Create(OpCodes.Ldloca_S, (byte)(md.Body.Variables.Count - 1))); - worker.InsertBefore(top, worker.Create(OpCodes.Initobj, elementType)); - worker.InsertBefore(top, worker.Create(OpCodes.Ldloc, md.Body.Variables.Count - 1)); - worker.InsertBefore(top, worker.Create(OpCodes.Stobj, elementType)); - } - } - } - } - - private static void InjectGuardReturnValue(MethodDefinition md, ILProcessor worker, Instruction top) - { - if (md.ReturnType.FullName != voidType.FullName) - { - if (md.ReturnType.IsPrimitive) - { - worker.InsertBefore(top, worker.Create(OpCodes.Ldc_I4_0)); - } - else - { - md.Body.Variables.Add(new VariableDefinition(md.ReturnType)); - md.Body.InitLocals = true; - worker.InsertBefore(top, worker.Create(OpCodes.Ldloca_S, (byte)(md.Body.Variables.Count - 1))); - worker.InsertBefore(top, worker.Create(OpCodes.Initobj, md.ReturnType)); - worker.InsertBefore(top, worker.Create(OpCodes.Ldloc, md.Body.Variables.Count - 1)); - } - } - } - - private static void InjectServerGuard(ModuleDefinition moduleDef, TypeDefinition td, MethodDefinition md, bool logWarning) - { - if (!IsNetworkBehaviour(td)) - { - Log.Error("[Server] guard on non-NetworkBehaviour script at [" + md.FullName + "]"); - } - else - { - var ilprocessor = md.Body.GetILProcessor(); - var instruction = md.Body.Instructions[0]; - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Call, NetworkServerGetActive)); - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Brtrue, instruction)); - if (logWarning) - { - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Ldstr, "[Server] function '" + md.FullName + "' called on client")); - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Call, logWarningReference)); - } - - InjectGuardParameters(md, ilprocessor, instruction); - InjectGuardReturnValue(md, ilprocessor, instruction); - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Ret)); - } - } - - private static void InjectClientGuard(ModuleDefinition moduleDef, TypeDefinition td, MethodDefinition md, bool logWarning) - { - if (!IsNetworkBehaviour(td)) - { - Log.Error("[Client] guard on non-NetworkBehaviour script at [" + md.FullName + "]"); - } - else - { - var ilprocessor = md.Body.GetILProcessor(); - var instruction = md.Body.Instructions[0]; - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Call, NetworkClientGetActive)); - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Brtrue, instruction)); - if (logWarning) - { - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Ldstr, "[Client] function '" + md.FullName + "' called on server")); - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Call, logWarningReference)); - } - - InjectGuardParameters(md, ilprocessor, instruction); - InjectGuardReturnValue(md, ilprocessor, instruction); - ilprocessor.InsertBefore(instruction, ilprocessor.Create(OpCodes.Ret)); - } - } - - private static void ProcessSiteMethod(ModuleDefinition moduleDef, TypeDefinition td, MethodDefinition md) - { - if (!(md.Name == ".cctor") && !(md.Name == "OnUnserializeVars")) - { - var text = md.Name.Substring(0, Math.Min(md.Name.Length, 4)); - if (!(text == "UNet")) - { - text = md.Name.Substring(0, Math.Min(md.Name.Length, 7)); - if (!(text == "CallCmd")) - { - text = md.Name.Substring(0, Math.Min(md.Name.Length, 9)); - if (!(text == "InvokeCmd") && !(text == "InvokeRpc") && !(text == "InvokeSyn")) - { - if (md.Body != null && md.Body.Instructions != null) - { - foreach (var customAttribute in md.CustomAttributes) - { - if (customAttribute.Constructor.DeclaringType.ToString() == "UnityEngine.Networking.ServerAttribute") - { - InjectServerGuard(moduleDef, td, md, true); - } - else if (customAttribute.Constructor.DeclaringType.ToString() == "UnityEngine.Networking.ServerCallbackAttribute") - { - InjectServerGuard(moduleDef, td, md, false); - } - else if (customAttribute.Constructor.DeclaringType.ToString() == "UnityEngine.Networking.ClientAttribute") - { - InjectClientGuard(moduleDef, td, md, true); - } - else if (customAttribute.Constructor.DeclaringType.ToString() == "UnityEngine.Networking.ClientCallbackAttribute") - { - InjectClientGuard(moduleDef, td, md, false); - } - } - - var num = 0; - foreach (var i in md.Body.Instructions) - { - ProcessInstruction(moduleDef, td, md, i, num); - num++; - } - } - } - } - } - } - } - - private static void ProcessSiteClass(ModuleDefinition moduleDef, TypeDefinition td) - { - foreach (var md in td.Methods) - { - ProcessSiteMethod(moduleDef, td, md); - } - - foreach (var td2 in td.NestedTypes) - { - ProcessSiteClass(moduleDef, td2); - } - } - - private static void ProcessSitesModule(ModuleDefinition moduleDef) - { - var now = DateTime.Now; - foreach (var typeDefinition in moduleDef.Types) - { - if (typeDefinition.IsClass) - { - ProcessSiteClass(moduleDef, typeDefinition); - } - } - - if (lists.generateContainerClass != null) - { - moduleDef.Types.Add(lists.generateContainerClass); - scriptDef.MainModule.ImportReference(lists.generateContainerClass); - foreach (var method in lists.generatedReadFunctions) - { - scriptDef.MainModule.ImportReference(method); - } - - foreach (var method2 in lists.generatedWriteFunctions) - { - scriptDef.MainModule.ImportReference(method2); - } - } - - Console.WriteLine(string.Concat(new object[] - { - " ProcessSitesModule ", - moduleDef.Name, - " elapsed time:", - DateTime.Now - now - })); - } - - private static void ProcessPropertySites() => ProcessSitesModule(scriptDef.MainModule); - - private static bool ProcessMessageType(TypeDefinition td) - { - var messageClassProcessor = new MessageClassProcessor(td); - messageClassProcessor.Process(); - return true; - } - - private static bool ProcessSyncListStructType(TypeDefinition td) - { - var syncListStructProcessor = new SyncListStructProcessor(td); - syncListStructProcessor.Process(); - return true; - } - - private static void ProcessMonoBehaviourType(TypeDefinition td) - { - var monoBehaviourProcessor = new MonoBehaviourProcessor(td); - monoBehaviourProcessor.Process(); - } - - private static bool ProcessNetworkBehaviourType(TypeDefinition td) - { - foreach (var methodDefinition in td.Resolve().Methods) - { - if (methodDefinition.Name == "UNetVersion") - { - DLog(td, " Already processed", new object[0]); - return false; - } - } - - DLog(td, "Found NetworkBehaviour " + td.FullName, new object[0]); - var networkBehaviourProcessor = new NetworkBehaviourProcessor(td); - networkBehaviourProcessor.Process(); - return true; - } - - public static MethodReference ResolveMethod(TypeReference t, string name) - { - MethodReference result; - if (t == null) - { - Log.Error("Type missing for " + name); - fail = true; - result = null; - } - else - { - foreach (var methodDefinition in t.Resolve().Methods) - { - if (methodDefinition.Name == name) - { - return scriptDef.MainModule.ImportReference(methodDefinition); - } - } - - Log.Error($"ResolveMethod failed - Couldn't find {name} in {t.Name}"); - foreach (var methodDefinition2 in t.Resolve().Methods) - { - Log.Error("- has method " + methodDefinition2.Name); - } - - fail = true; - result = null; - } - - return result; - } - - private static MethodReference ResolveMethodWithArg(TypeReference t, string name, TypeReference argType) - { - foreach (var methodDefinition in t.Resolve().Methods) - { - if (methodDefinition.Name == name) - { - if (methodDefinition.Parameters.Count == 1) - { - if (methodDefinition.Parameters[0].ParameterType.FullName == argType.FullName) - { - return scriptDef.MainModule.ImportReference(methodDefinition); - } - } - } - } - - Log.Error(string.Concat(new object[] - { - "ResolveMethodWithArg failed ", - t.Name, - "::", - name, - " ", - argType - })); - fail = true; - return null; - } - - private static MethodDefinition ResolveDefaultPublicCtor(TypeReference variable) - { - foreach (var methodDefinition in variable.Resolve().Methods) - { - if (methodDefinition.Name == ".ctor" && methodDefinition.Resolve().IsPublic && methodDefinition.Parameters.Count == 0) - { - return methodDefinition; - } - } - - return null; - } - - private static GenericInstanceMethod ResolveMethodGeneric(TypeReference t, string name, TypeReference genericType) - { - foreach (var methodDefinition in t.Resolve().Methods) - { - if (methodDefinition.Name == name) - { - if (methodDefinition.Parameters.Count == 0) - { - if (methodDefinition.GenericParameters.Count == 1) - { - var method = scriptDef.MainModule.ImportReference(methodDefinition); - var genericInstanceMethod = new GenericInstanceMethod(method); - genericInstanceMethod.GenericArguments.Add(genericType); - if (genericInstanceMethod.GenericArguments[0].FullName == genericType.FullName) - { - return genericInstanceMethod; - } - } - } - } - } - - Log.Error(string.Concat(new object[] - { - "ResolveMethodGeneric failed ", - t.Name, - "::", - name, - " ", - genericType - })); - fail = true; - return null; - } - - public static FieldReference ResolveField(TypeReference t, string name) - { - foreach (var fieldDefinition in t.Resolve().Fields) - { - if (fieldDefinition.Name == name) - { - return scriptDef.MainModule.ImportReference(fieldDefinition); - } - } - - return null; - } - - public static MethodReference ResolveProperty(TypeReference t, string name) - { - foreach (var propertyDefinition in t.Resolve().Properties) - { - if (propertyDefinition.Name == name) - { - return scriptDef.MainModule.ImportReference(propertyDefinition.GetMethod); - } - } - - Log.Error($"ResolveProperty failed - Couldn't find {name} in {t.Name}"); - return null; - } - - private static void SetupUnityTypes() - { - vector2Type = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Vector2"); - if (vector2Type == null) - { - Log.Error("Vector2Type is null!"); - } - - vector3Type = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Vector3"); - vector4Type = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Vector4"); - colorType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Color"); - color32Type = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Color32"); - quaternionType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Quaternion"); - rectType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Rect"); - planeType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Plane"); - rayType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Ray"); - matrixType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Matrix4x4"); - gameObjectType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.GameObject"); - if (gameObjectType == null) - { - Log.Error("GameObjectType is null!"); - } - - transformType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Transform"); - unityObjectType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Object"); - - hashType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkHash128"); - - NetworkClientType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QNetworkClient"); - NetworkServerType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QNetworkServer"); - NetworkCRCType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QNetworkCRC"); - - SyncVarType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncVarAttribute"); - - CommandType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.CommandAttribute"); - - ClientRpcType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.ClientRpcAttribute"); - - TargetRpcType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.TargetRpcAttribute"); - - SyncEventType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncEventAttribute"); - - SyncListType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncList`1"); - - NetworkSettingsType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkSettingsAttribute"); - - SyncListFloatType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncListFloat"); - - SyncListIntType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncListInt"); - - SyncListUIntType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncListUInt"); - - SyncListBoolType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncListBool"); - - SyncListStringType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncListString"); - - } - - private static void SetupCorLib() - { - var name = AssemblyNameReference.Parse("mscorlib"); - var parameters = new ReaderParameters - { - AssemblyResolver = scriptDef.MainModule.AssemblyResolver - }; - corLib = scriptDef.MainModule.AssemblyResolver.Resolve(name, parameters).MainModule; - } - - private static TypeReference ImportCorLibType(string fullName) - { - var type = corLib.GetType(fullName) ?? Enumerable.First(corLib.ExportedTypes, (ExportedType t) => t.FullName == fullName).Resolve(); - return scriptDef.MainModule.ImportReference(type); - } - - private static void SetupTargetTypes() - { - SetupCorLib(); - voidType = ImportCorLibType("System.Void"); - singleType = ImportCorLibType("System.Single"); - doubleType = ImportCorLibType("System.Double"); - decimalType = ImportCorLibType("System.Decimal"); - boolType = ImportCorLibType("System.Boolean"); - stringType = ImportCorLibType("System.String"); - int64Type = ImportCorLibType("System.Int64"); - uint64Type = ImportCorLibType("System.UInt64"); - int32Type = ImportCorLibType("System.Int32"); - uint32Type = ImportCorLibType("System.UInt32"); - int16Type = ImportCorLibType("System.Int16"); - uint16Type = ImportCorLibType("System.UInt16"); - byteType = ImportCorLibType("System.Byte"); - sbyteType = ImportCorLibType("System.SByte"); - charType = ImportCorLibType("System.Char"); - objectType = ImportCorLibType("System.Object"); - valueTypeType = ImportCorLibType("System.ValueType"); - typeType = ImportCorLibType("System.Type"); - IEnumeratorType = ImportCorLibType("System.Collections.IEnumerator"); - MemoryStreamType = ImportCorLibType("System.IO.MemoryStream"); - - NetworkReaderType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.Transport.QNetworkReader"); - - NetworkReaderDef = NetworkReaderType.Resolve(); - NetworkReaderCtor = ResolveMethod(NetworkReaderDef, ".ctor"); - - NetworkWriterType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.Transport.QNetworkWriter"); - - NetworkWriterDef = NetworkWriterType.Resolve(); - NetworkWriterCtor = ResolveMethod(NetworkWriterDef, ".ctor"); - MemoryStreamCtor = ResolveMethod(MemoryStreamType, ".ctor"); - - NetworkInstanceIdType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkInstanceId"); - NetworkSceneIdType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkSceneId"); - NetworkInstanceIdType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkInstanceId"); - NetworkSceneIdType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkSceneId"); - - NetworkServerGetActive = ResolveMethod(NetworkServerType, "get_active"); - NetworkServerGetLocalClientActive = ResolveMethod(NetworkServerType, "get_localClientActive"); - NetworkClientGetActive = ResolveMethod(NetworkClientType, "get_active"); - NetworkReaderReadInt32 = ResolveMethod(NetworkReaderType, "ReadInt32"); - NetworkWriterWriteInt32 = ResolveMethodWithArg(NetworkWriterType, "Write", int32Type); - NetworkWriterWriteInt16 = ResolveMethodWithArg(NetworkWriterType, "Write", int16Type); - NetworkReaderReadPacked32 = ResolveMethod(NetworkReaderType, "ReadPackedUInt32"); - NetworkReaderReadPacked64 = ResolveMethod(NetworkReaderType, "ReadPackedUInt64"); - NetworkReaderReadByte = ResolveMethod(NetworkReaderType, "ReadByte"); - NetworkWriterWritePacked32 = ResolveMethod(NetworkWriterType, "WritePackedUInt32"); - NetworkWriterWritePacked64 = ResolveMethod(NetworkWriterType, "WritePackedUInt64"); - NetworkWriterWriteNetworkInstanceId = ResolveMethodWithArg(NetworkWriterType, "Write", NetworkInstanceIdType); - NetworkWriterWriteNetworkSceneId = ResolveMethodWithArg(NetworkWriterType, "Write", NetworkSceneIdType); - NetworkWriterStartMessage = ResolveMethod(NetworkWriterType, "StartMessage"); - NetworkWriterFinishMessage = ResolveMethod(NetworkWriterType, "FinishMessage"); - NetworkReaderReadNetworkInstanceId = ResolveMethod(NetworkReaderType, "ReadNetworkId"); - NetworkReaderReadNetworkSceneId = ResolveMethod(NetworkReaderType, "ReadSceneId"); - NetworkInstanceIsEmpty = ResolveMethod(NetworkInstanceIdType, "IsEmpty"); - NetworkReadUInt16 = ResolveMethod(NetworkReaderType, "ReadUInt16"); - NetworkWriteUInt16 = ResolveMethodWithArg(NetworkWriterType, "Write", uint16Type); - - CmdDelegateReference = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QNetworkBehaviour/CmdDelegate"); - - CmdDelegateConstructor = ResolveMethod(CmdDelegateReference, ".ctor"); - Console.WriteLine("gameobject"); - scriptDef.MainModule.ImportReference(gameObjectType); - Console.WriteLine("transform"); - scriptDef.MainModule.ImportReference(transformType); - - TypeReference type = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.Components.QNetworkIdentity"); - - Console.WriteLine("type"); - NetworkIdentityType = scriptDef.MainModule.ImportReference(type); - Console.WriteLine("networkinstanceidtype"); - NetworkInstanceIdType = scriptDef.MainModule.ImportReference(NetworkInstanceIdType); - SyncListFloatReadType = ResolveMethod(SyncListFloatType, "ReadReference"); - SyncListIntReadType = ResolveMethod(SyncListIntType, "ReadReference"); - SyncListUIntReadType = ResolveMethod(SyncListUIntType, "ReadReference"); - SyncListBoolReadType = ResolveMethod(SyncListBoolType, "ReadReference"); - SyncListStringReadType = ResolveMethod(SyncListStringType, "ReadReference"); - SyncListFloatWriteType = ResolveMethod(SyncListFloatType, "WriteInstance"); - SyncListIntWriteType = ResolveMethod(SyncListIntType, "WriteInstance"); - SyncListUIntWriteType = ResolveMethod(SyncListUIntType, "WriteInstance"); - SyncListBoolWriteType = ResolveMethod(SyncListBoolType, "WriteInstance"); - SyncListStringWriteType = ResolveMethod(SyncListStringType, "WriteInstance"); - - NetworkBehaviourType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QNetworkBehaviour"); - - Console.WriteLine("networkbehaviourtype"); - NetworkBehaviourType2 = scriptDef.MainModule.ImportReference(NetworkBehaviourType); - - NetworkConnectionType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QNetworkConnection"); - - MonoBehaviourType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.MonoBehaviour"); - ScriptableObjectType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.ScriptableObject"); - - NetworkConnectionType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QNetworkConnection"); - - NetworkConnectionType = scriptDef.MainModule.ImportReference(NetworkConnectionType); - - ULocalConnectionToServerType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QULocalConnectionToServer"); - - ULocalConnectionToServerType = scriptDef.MainModule.ImportReference(ULocalConnectionToServerType); - - ULocalConnectionToClientType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QULocalConnectionToClient"); - - ULocalConnectionToClientType = scriptDef.MainModule.ImportReference(ULocalConnectionToClientType); - - MessageBaseType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.Messages.QMessageBase"); - SyncListStructType = UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncListStruct`1"); - - NetworkBehaviourDirtyBitsReference = ResolveProperty(NetworkBehaviourType, "SyncVarDirtyBits"); - NetworkBehaviourOnSerialize = ResolveMethod(NetworkBehaviourType, "OnSerialize"); - NetworkBehaviourClearAllDirtyBits = ResolveMethod(NetworkBehaviourType, "ClearAllDirtyBits"); - NetworkBehaviourGetNetworkChannel = ResolveMethod(NetworkBehaviourType, "GetNetworkChannel"); - NetworkBehaviourClientSendUpdateVars = ResolveMethod(NetworkBehaviourType, "ClientSendUpdateVars"); - NetworkConnectionSendWriter = ResolveMethod(NetworkConnectionType, "SendWriter"); - ComponentType = UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Component"); - - ClientSceneType = QNetAssemblyDefinition.MainModule.GetType("QuantumUNET.QClientScene"); - - FindLocalObjectReference = ResolveMethod(ClientSceneType, "FindLocalObject"); - RegisterBehaviourReference = ResolveMethod(NetworkCRCType, "RegisterBehaviour"); - ReadyConnectionReference = ResolveMethod(ClientSceneType, "get_readyConnection"); - getComponentReference = ResolveMethodGeneric(ComponentType, "GetComponent", NetworkIdentityType); - getUNetIdReference = ResolveMethod(type, "get_NetId"); - gameObjectInequality = ResolveMethod(unityObjectType, "op_Inequality"); - UBehaviourIsServer = ResolveMethod(NetworkBehaviourType, "get_IsServer"); - getPlayerIdReference = ResolveMethod(NetworkBehaviourType, "get_PlayerControllerId"); - setSyncVarReference = ResolveMethod(NetworkBehaviourType, "SetSyncVar"); - setSyncVarHookGuard = ResolveMethod(NetworkBehaviourType, "set_SyncVarHookGuard"); - getSyncVarHookGuard = ResolveMethod(NetworkBehaviourType, "get_SyncVarHookGuard"); - setSyncVarGameObjectReference = ResolveMethod(NetworkBehaviourType, "SetSyncVarGameObject"); - registerCommandDelegateReference = ResolveMethod(NetworkBehaviourType, "RegisterCommandDelegate"); - registerRpcDelegateReference = ResolveMethod(NetworkBehaviourType, "RegisterRpcDelegate"); - registerEventDelegateReference = ResolveMethod(NetworkBehaviourType, "RegisterEventDelegate"); - registerSyncListDelegateReference = ResolveMethod(NetworkBehaviourType, "RegisterSyncListDelegate"); - getTypeReference = ResolveMethod(objectType, "GetType"); - getTypeFromHandleReference = ResolveMethod(typeType, "GetTypeFromHandle"); - logErrorReference = ResolveMethod(UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Debug"), "LogError"); - logWarningReference = ResolveMethod(UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Debug"), "LogWarning"); - sendCommandInternal = ResolveMethod(NetworkBehaviourType, "SendCommandInternal"); - sendRpcInternal = ResolveMethod(NetworkBehaviourType, "SendRPCInternal"); - sendTargetRpcInternal = ResolveMethod(NetworkBehaviourType, "SendTargetRPCInternal"); - sendEventInternal = ResolveMethod(NetworkBehaviourType, "SendEventInternal"); - Console.WriteLine("synclisttype"); - SyncListType = scriptDef.MainModule.ImportReference(SyncListType); - SyncListInitBehaviourReference = ResolveMethod(SyncListType, "InitializeBehaviour"); - SyncListInitHandleMsg = ResolveMethod(SyncListType, "HandleMsg"); - SyncListClear = ResolveMethod(SyncListType, "Clear"); - } - - private static void SetupReadFunctions() - { - var weaverLists = lists; - var dictionary = new Dictionary - { - { singleType.FullName, ResolveMethod(NetworkReaderType, "ReadSingle") }, - { doubleType.FullName, ResolveMethod(NetworkReaderType, "ReadDouble") }, - { boolType.FullName, ResolveMethod(NetworkReaderType, "ReadBoolean") }, - { stringType.FullName, ResolveMethod(NetworkReaderType, "ReadString") }, - { int64Type.FullName, NetworkReaderReadPacked64 }, - { uint64Type.FullName, NetworkReaderReadPacked64 }, - { int32Type.FullName, NetworkReaderReadPacked32 }, - { uint32Type.FullName, NetworkReaderReadPacked32 }, - { int16Type.FullName, NetworkReaderReadPacked32 }, - { uint16Type.FullName, NetworkReaderReadPacked32 }, - { byteType.FullName, NetworkReaderReadPacked32 }, - { sbyteType.FullName, NetworkReaderReadPacked32 }, - { charType.FullName, NetworkReaderReadPacked32 }, - { decimalType.FullName, ResolveMethod(NetworkReaderType, "ReadDecimal") }, - { vector2Type.FullName, ResolveMethod(NetworkReaderType, "ReadVector2") }, - { vector3Type.FullName, ResolveMethod(NetworkReaderType, "ReadVector3") }, - { vector4Type.FullName, ResolveMethod(NetworkReaderType, "ReadVector4") }, - { colorType.FullName, ResolveMethod(NetworkReaderType, "ReadColor") }, - { color32Type.FullName, ResolveMethod(NetworkReaderType, "ReadColor32") }, - { quaternionType.FullName, ResolveMethod(NetworkReaderType, "ReadQuaternion") }, - { rectType.FullName, ResolveMethod(NetworkReaderType, "ReadRect") }, - { planeType.FullName, ResolveMethod(NetworkReaderType, "ReadPlane") }, - { rayType.FullName, ResolveMethod(NetworkReaderType, "ReadRay") }, - { matrixType.FullName, ResolveMethod(NetworkReaderType, "ReadMatrix4x4") }, - { hashType.FullName, ResolveMethod(NetworkReaderType, "ReadNetworkHash128") }, - { gameObjectType.FullName, ResolveMethod(NetworkReaderType, "ReadGameObject") }, - { NetworkIdentityType.FullName, ResolveMethod(NetworkReaderType, "ReadNetworkIdentity") }, - { NetworkInstanceIdType.FullName, NetworkReaderReadNetworkInstanceId }, - { NetworkSceneIdType.FullName, NetworkReaderReadNetworkSceneId }, - { transformType.FullName, ResolveMethod(NetworkReaderType, "ReadTransform") }, - { "System.Byte[]", ResolveMethod(NetworkReaderType, "ReadBytesAndSize") } - }; - weaverLists.readFuncs = dictionary; - var weaverLists2 = lists; - dictionary = new Dictionary - { - { SyncListFloatType.FullName, SyncListFloatReadType }, - { SyncListIntType.FullName, SyncListIntReadType }, - { SyncListUIntType.FullName, SyncListUIntReadType }, - { SyncListBoolType.FullName, SyncListBoolReadType }, - { SyncListStringType.FullName, SyncListStringReadType } - }; - weaverLists2.readByReferenceFuncs = dictionary; - } - - private static void SetupWriteFunctions() - { - var weaverLists = lists; - var dictionary = new Dictionary - { - { singleType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", singleType) }, - { doubleType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", doubleType) }, - { boolType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", boolType) }, - { stringType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", stringType) }, - { int64Type.FullName, NetworkWriterWritePacked64 }, - { uint64Type.FullName, NetworkWriterWritePacked64 }, - { int32Type.FullName, NetworkWriterWritePacked32 }, - { uint32Type.FullName, NetworkWriterWritePacked32 }, - { int16Type.FullName, NetworkWriterWritePacked32 }, - { uint16Type.FullName, NetworkWriterWritePacked32 }, - { byteType.FullName, NetworkWriterWritePacked32 }, - { sbyteType.FullName, NetworkWriterWritePacked32 }, - { charType.FullName, NetworkWriterWritePacked32 }, - { decimalType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", decimalType) }, - { vector2Type.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", vector2Type) }, - { vector3Type.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", vector3Type) }, - { vector4Type.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", vector4Type) }, - { colorType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", colorType) }, - { color32Type.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", color32Type) }, - { quaternionType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", quaternionType) }, - { rectType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", rectType) }, - { planeType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", planeType) }, - { rayType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", rayType) }, - { matrixType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", matrixType) }, - { hashType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", hashType) }, - { gameObjectType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", gameObjectType) }, - { NetworkIdentityType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", NetworkIdentityType) }, - { NetworkInstanceIdType.FullName, NetworkWriterWriteNetworkInstanceId }, - { NetworkSceneIdType.FullName, NetworkWriterWriteNetworkSceneId }, - { transformType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", transformType) }, - { "System.Byte[]", ResolveMethod(NetworkWriterType, "WriteBytesFull") }, - { SyncListFloatType.FullName, SyncListFloatWriteType }, - { SyncListIntType.FullName, SyncListIntWriteType }, - { SyncListUIntType.FullName, SyncListUIntWriteType }, - { SyncListBoolType.FullName, SyncListBoolWriteType }, - { SyncListStringType.FullName, SyncListStringWriteType } - }; - weaverLists.writeFuncs = dictionary; - } - - private static bool IsNetworkBehaviour(TypeDefinition td) - { - bool result; - if (!td.IsClass) - { - result = false; - } - else - { - var baseType = td.BaseType; - while (baseType != null) - { - if (baseType.FullName == NetworkBehaviourType.FullName) - { - return true; - } - - try - { - baseType = baseType.Resolve().BaseType; - } - catch (AssemblyResolutionException) - { - break; - } - } - - result = false; - } - - return result; - } - - public static bool IsDerivedFrom(TypeDefinition td, TypeReference baseClass) - { - bool result; - if (!td.IsClass) - { - result = false; - } - else - { - var baseType = td.BaseType; - while (baseType != null) - { - var text = baseType.FullName; - var num = text.IndexOf('<'); - if (num != -1) - { - text = text.Substring(0, num); - } - - if (text == baseClass.FullName) - { - return true; - } - - try - { - baseType = baseType.Resolve().BaseType; - } - catch (AssemblyResolutionException) - { - break; - } - } - - result = false; - } - - return result; - } - - public static bool IsValidTypeToGenerate(TypeDefinition variable) - { - var name = scriptDef.MainModule.Name; - bool result; - if (variable.Module.Name != name) - { - Log.Error(string.Concat(new string[] - { - "parameter [", - variable.Name, - "] is of the type [", - variable.FullName, - "] is not a valid type, please make sure to use a valid type." - })); - fail = true; - fail = true; - result = false; - } - else - { - result = true; - } - - return result; - } - - private static void CheckMonoBehaviour(TypeDefinition td) - { - if (IsDerivedFrom(td, MonoBehaviourType)) - { - ProcessMonoBehaviourType(td); - } - } - - private static bool CheckNetworkBehaviour(TypeDefinition td) - { - bool result; - if (!td.IsClass) - { - result = false; - } - else if (!IsNetworkBehaviour(td)) - { - CheckMonoBehaviour(td); - result = false; - } - else - { - var list = new List(); - var typeDefinition = td; - while (typeDefinition != null) - { - if (typeDefinition.FullName == NetworkBehaviourType.FullName) - { - break; - } - - try - { - list.Insert(0, typeDefinition); - typeDefinition = typeDefinition.BaseType.Resolve(); - } - catch (AssemblyResolutionException) - { - break; - } - } - - var flag = false; - foreach (var td2 in list) - { - flag |= ProcessNetworkBehaviourType(td2); - } - - result = flag; - } - - return result; - } - - private static bool CheckMessageBase(TypeDefinition td) - { - bool result; - if (!td.IsClass) - { - result = false; - } - else - { - var flag = false; - var baseType = td.BaseType; - while (baseType != null) - { - if (baseType.FullName == MessageBaseType.FullName) - { - flag |= ProcessMessageType(td); - break; - } - - try - { - baseType = baseType.Resolve().BaseType; - } - catch (AssemblyResolutionException) - { - break; - } - } - - foreach (var td2 in td.NestedTypes) - { - flag |= CheckMessageBase(td2); - } - - result = flag; - } - - return result; - } - - private static bool CheckSyncListStruct(TypeDefinition td) - { - bool result; - if (!td.IsClass) - { - result = false; - } - else - { - var flag = false; - var baseType = td.BaseType; - while (baseType != null) - { - if (baseType.FullName.Contains("SyncListStruct")) - { - flag |= ProcessSyncListStructType(td); - break; - } - - try - { - baseType = baseType.Resolve().BaseType; - } - catch (AssemblyResolutionException) - { - break; - } - } - - foreach (var td2 in td.NestedTypes) - { - flag |= CheckSyncListStruct(td2); - } - - result = flag; - } - - return result; - } - - private static bool Weave(string assName, IEnumerable dependencies, IAssemblyResolver assemblyResolver, string unityEngineDLLPath, string unityUNetDLLPath, string outputDir) - { - var readerParameters = Helpers.ReaderParameters(assName, dependencies, assemblyResolver, unityEngineDLLPath, unityUNetDLLPath); - scriptDef = AssemblyDefinition.ReadAssembly(assName, readerParameters); - SetupTargetTypes(); - SetupReadFunctions(); - SetupWriteFunctions(); - var mainModule = scriptDef.MainModule; - Console.WriteLine("Script Module: {0}", mainModule.Name); - var flag = false; - for (var i = 0; i < 2; i++) - { - var stopwatch = Stopwatch.StartNew(); - foreach (var typeDefinition in mainModule.Types) - { - if (typeDefinition.IsClass && CanBeResolved(typeDefinition.BaseType)) - { - try - { - if (i == 0) - { - flag |= CheckSyncListStruct(typeDefinition); - } - else - { - flag |= CheckNetworkBehaviour(typeDefinition); - flag |= CheckMessageBase(typeDefinition); - } - } - catch (Exception ex) - { - if (scriptDef.MainModule.SymbolReader != null) - { - scriptDef.MainModule.SymbolReader.Dispose(); - } - - fail = true; - throw ex; - } - } - - if (fail) - { - if (scriptDef.MainModule.SymbolReader != null) - { - scriptDef.MainModule.SymbolReader.Dispose(); - } - - return false; - } - } - - stopwatch.Stop(); - Console.WriteLine(string.Concat(new object[] - { - "Pass: ", - i, - " took ", - stopwatch.ElapsedMilliseconds, - " milliseconds" - })); - } - - if (flag) - { - foreach (var methodDefinition in lists.replacedMethods) - { - lists.replacementMethodNames.Add(methodDefinition.FullName); - } - - try - { - ProcessPropertySites(); - } - catch (Exception ex2) - { - Log.Error("ProcessPropertySites exception: " + ex2); - if (scriptDef.MainModule.SymbolReader != null) - { - scriptDef.MainModule.SymbolReader.Dispose(); - } - - return false; - } - - if (fail) - { - if (scriptDef.MainModule.SymbolReader != null) - { - scriptDef.MainModule.SymbolReader.Dispose(); - } - - return false; - } - - var fileName = Helpers.DestinationFileFor(outputDir, assName); - var writerParameters = Helpers.GetWriterParameters(readerParameters); - if (writerParameters.SymbolWriterProvider is PdbWriterProvider) - { - writerParameters.SymbolWriterProvider = new MdbWriterProvider(); - var text = Path.ChangeExtension(assName, ".pdb"); - File.Delete(text); - } - - scriptDef.Write(fileName, writerParameters); - } - - if (scriptDef.MainModule.SymbolReader != null) - { - scriptDef.MainModule.SymbolReader.Dispose(); - } - - return true; - } - - public static bool WeaveAssemblies(string assembly, IEnumerable dependencies, IAssemblyResolver assemblyResolver, string outputDir, string unityEngineDLLPath, string unityQNetDLLPath, string unityUNetDLLPath) - { - fail = false; - lists = new WeaverLists(); - Console.WriteLine($"load unity engine from {unityEngineDLLPath}"); - UnityAssemblyDefinition = AssemblyDefinition.ReadAssembly(unityEngineDLLPath); - Console.WriteLine($"load qnet from {unityQNetDLLPath}"); - QNetAssemblyDefinition = AssemblyDefinition.ReadAssembly(unityQNetDLLPath); - Console.WriteLine($"load unet from {unityUNetDLLPath}"); - UNetAssemblyDefinition = AssemblyDefinition.ReadAssembly(unityUNetDLLPath); - SetupUnityTypes(); - try - { - if (!Weave(assembly, dependencies, assemblyResolver, unityEngineDLLPath, unityQNetDLLPath, outputDir)) - { - return false; - } - } - catch (Exception ex) - { - Log.Error("Exception :" + ex); - return false; - } - - corLib = null; - return true; - } - - public static TypeReference NetworkBehaviourType; - - public static TypeReference NetworkBehaviourType2; - - public static TypeReference MonoBehaviourType; - - public static TypeReference ScriptableObjectType; - - public static TypeReference NetworkConnectionType; - - public static TypeReference ULocalConnectionToServerType; - - public static TypeReference ULocalConnectionToClientType; - - public static TypeReference MessageBaseType; - - public static TypeReference SyncListStructType; - - public static MethodReference NetworkBehaviourDirtyBitsReference; - - public static MethodReference NetworkBehaviourOnSerialize; - - public static MethodReference NetworkBehaviourClearAllDirtyBits; - - public static MethodReference NetworkBehaviourGetNetworkChannel; - - public static MethodReference NetworkConnectionSendWriter; - - public static MethodReference NetworkBehaviourClientSendUpdateVars; - - public static TypeReference NetworkClientType; - - public static TypeReference NetworkServerType; - - public static TypeReference NetworkCRCType; - - public static TypeReference NetworkReaderType; - - public static TypeDefinition NetworkReaderDef; - - public static TypeReference NetworkWriterType; - - public static TypeDefinition NetworkWriterDef; - - public static MethodReference NetworkWriterCtor; - - public static MethodReference NetworkReaderCtor; - - public static TypeReference MemoryStreamType; - - public static MethodReference MemoryStreamCtor; - - public static MethodReference getComponentReference; - - public static MethodReference getUNetIdReference; - - public static MethodReference getPlayerIdReference; - - public static TypeReference NetworkIdentityType; - - public static TypeReference NetworkInstanceIdType; - - public static TypeReference NetworkSceneIdType; - - public static TypeReference IEnumeratorType; - - public static TypeReference ClientSceneType; - - public static MethodReference FindLocalObjectReference; - - public static MethodReference RegisterBehaviourReference; - - public static MethodReference ReadyConnectionReference; - - public static TypeReference ComponentType; - - public static TypeReference CmdDelegateReference; - - public static MethodReference CmdDelegateConstructor; - - public static MethodReference NetworkReaderReadInt32; - - public static MethodReference NetworkWriterWriteInt32; - - public static MethodReference NetworkWriterWriteInt16; - - public static MethodReference NetworkServerGetActive; - - public static MethodReference NetworkServerGetLocalClientActive; - - public static MethodReference NetworkClientGetActive; - - public static MethodReference UBehaviourIsServer; - - public static MethodReference NetworkReaderReadPacked32; - - public static MethodReference NetworkReaderReadPacked64; - - public static MethodReference NetworkReaderReadByte; - - public static MethodReference NetworkWriterWritePacked32; - - public static MethodReference NetworkWriterWritePacked64; - - public static MethodReference NetworkWriterWriteNetworkInstanceId; - - public static MethodReference NetworkWriterWriteNetworkSceneId; - - public static MethodReference NetworkWriterStartMessage; - - public static MethodReference NetworkWriterFinishMessage; - - public static MethodReference NetworkReaderReadNetworkInstanceId; - - public static MethodReference NetworkReaderReadNetworkSceneId; - - public static MethodReference NetworkInstanceIsEmpty; - - public static MethodReference NetworkReadUInt16; - - public static MethodReference NetworkWriteUInt16; - - public static TypeReference SyncVarType; - - public static TypeReference CommandType; - - public static TypeReference ClientRpcType; - - public static TypeReference TargetRpcType; - - public static TypeReference SyncEventType; - - public static TypeReference SyncListType; - - public static MethodReference SyncListInitBehaviourReference; - - public static MethodReference SyncListInitHandleMsg; - - public static MethodReference SyncListClear; - - public static TypeReference NetworkSettingsType; - - public static TypeReference SyncListFloatType; - - public static TypeReference SyncListIntType; - - public static TypeReference SyncListUIntType; - - public static TypeReference SyncListBoolType; - - public static TypeReference SyncListStringType; - - public static MethodReference SyncListFloatReadType; - - public static MethodReference SyncListIntReadType; - - public static MethodReference SyncListUIntReadType; - - public static MethodReference SyncListStringReadType; - - public static MethodReference SyncListBoolReadType; - - public static MethodReference SyncListFloatWriteType; - - public static MethodReference SyncListIntWriteType; - - public static MethodReference SyncListUIntWriteType; - - public static MethodReference SyncListBoolWriteType; - - public static MethodReference SyncListStringWriteType; - - public static TypeReference voidType; - - public static TypeReference singleType; - - public static TypeReference doubleType; - - public static TypeReference decimalType; - - public static TypeReference boolType; - - public static TypeReference stringType; - - public static TypeReference int64Type; - - public static TypeReference uint64Type; - - public static TypeReference int32Type; - - public static TypeReference uint32Type; - - public static TypeReference int16Type; - - public static TypeReference uint16Type; - - public static TypeReference byteType; - - public static TypeReference sbyteType; - - public static TypeReference charType; - - public static TypeReference objectType; - - public static TypeReference valueTypeType; - - public static TypeReference vector2Type; - - public static TypeReference vector3Type; - - public static TypeReference vector4Type; - - public static TypeReference colorType; - - public static TypeReference color32Type; - - public static TypeReference quaternionType; - - public static TypeReference rectType; - - public static TypeReference rayType; - - public static TypeReference planeType; - - public static TypeReference matrixType; - - public static TypeReference hashType; - - public static TypeReference typeType; - - public static TypeReference gameObjectType; - - public static TypeReference transformType; - - public static TypeReference unityObjectType; - - public static MethodReference gameObjectInequality; - - public static MethodReference setSyncVarReference; - - public static MethodReference setSyncVarHookGuard; - - public static MethodReference getSyncVarHookGuard; - - public static MethodReference setSyncVarGameObjectReference; - - public static MethodReference registerCommandDelegateReference; - - public static MethodReference registerRpcDelegateReference; - - public static MethodReference registerEventDelegateReference; - - public static MethodReference registerSyncListDelegateReference; - - public static MethodReference getTypeReference; - - public static MethodReference getTypeFromHandleReference; - - public static MethodReference logErrorReference; - - public static MethodReference logWarningReference; - - public static MethodReference sendCommandInternal; - - public static MethodReference sendRpcInternal; - - public static MethodReference sendTargetRpcInternal; - - public static MethodReference sendEventInternal; - - public static WeaverLists lists; - - public static AssemblyDefinition scriptDef; - - public static ModuleDefinition corLib; - - public static AssemblyDefinition UnityAssemblyDefinition; - - public static AssemblyDefinition QNetAssemblyDefinition; - - public static AssemblyDefinition UNetAssemblyDefinition; - - private static bool m_DebugFlag = true; - - public static bool fail; - - public static bool generateLogErrors = false; - - private const int MaxRecursionCount = 128; - - private static int s_RecursionCount; - } -} diff --git a/QNetWeaver/WeaverLists.cs b/QNetWeaver/WeaverLists.cs deleted file mode 100644 index e8a96c60..00000000 --- a/QNetWeaver/WeaverLists.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Mono.Cecil; -using System.Collections.Generic; - -namespace QNetWeaver -{ - internal class WeaverLists - { - public List replacedFields = new List(); - - public List replacementProperties = new List(); - - public List netIdFields = new List(); - - public List replacedMethods = new List(); - - public List replacementMethods = new List(); - - public HashSet replacementMethodNames = new HashSet(); - - public List replacedEvents = new List(); - - public List replacementEvents = new List(); - - public Dictionary readFuncs; - - public Dictionary readByReferenceFuncs; - - public Dictionary writeFuncs; - - public List generatedReadFunctions = new List(); - - public List generatedWriteFunctions = new List(); - - public TypeDefinition generateContainerClass; - - public Dictionary numSyncVars = new Dictionary(); - } -} diff --git a/QSB.sln b/QSB.sln index b7e39c4d..15709d10 100644 --- a/QSB.sln +++ b/QSB.sln @@ -1,22 +1,18 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29613.14 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QSB", "QSB\QSB.csproj", "{1F00090A-C697-4C55-B401-192F3CFB9DC2}" - ProjectSection(ProjectDependencies) = postProject - {E23551F3-C095-4F50-8BF7-85BB2661859B} = {E23551F3-C095-4F50-8BF7-85BB2661859B} - EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantumUNET", "QuantumUNET\QuantumUNET.csproj", "{C8C53004-1508-4F86-A419-4292C188DC2A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QSBTests", "QSBTests\QSBTests.csproj", "{2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QNetWeaver", "QNetWeaver\QNetWeaver.csproj", "{E23551F3-C095-4F50-8BF7-85BB2661859B}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2569F98D-F671-42AA-82DE-505B05CDCEF2}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore + Directory.Build.targets = Directory.Build.targets LICENSE = LICENSE README.md = README.md EndProjectSection @@ -39,10 +35,6 @@ Global {2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Debug|Any CPU.Build.0 = Debug|Any CPU {2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Release|Any CPU.ActiveCfg = Release|Any CPU {2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Release|Any CPU.Build.0 = Release|Any CPU - {E23551F3-C095-4F50-8BF7-85BB2661859B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E23551F3-C095-4F50-8BF7-85BB2661859B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E23551F3-C095-4F50-8BF7-85BB2661859B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E23551F3-C095-4F50-8BF7-85BB2661859B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/QSB/Anglerfish/AnglerManager.cs b/QSB/Anglerfish/AnglerManager.cs new file mode 100644 index 00000000..09ea3945 --- /dev/null +++ b/QSB/Anglerfish/AnglerManager.cs @@ -0,0 +1,11 @@ +using QSB.Anglerfish.WorldObjects; +using QSB.WorldSync; + +namespace QSB.Anglerfish +{ + public class AnglerManager : WorldObjectManager + { + protected override void RebuildWorldObjects(OWScene scene) + => QSBWorldSync.Init(); + } +} diff --git a/QSB/Anglerfish/Events/AnglerChangeStateEvent.cs b/QSB/Anglerfish/Events/AnglerChangeStateEvent.cs new file mode 100644 index 00000000..efd0dcfa --- /dev/null +++ b/QSB/Anglerfish/Events/AnglerChangeStateEvent.cs @@ -0,0 +1,82 @@ +using QSB.Anglerfish.WorldObjects; +using QSB.Events; +using QSB.Player; +using QSB.WorldSync; +using UnityEngine; +using EventType = QSB.Events.EventType; + +namespace QSB.Anglerfish.Events +{ + public class AnglerChangeStateEvent : QSBEvent + { + public override EventType Type => EventType.AnglerChangeState; + + public override void SetupListener() + => GlobalMessenger.AddListener(EventNames.QSBAnglerChangeState, Handler); + + public override void CloseListener() + => GlobalMessenger.RemoveListener(EventNames.QSBAnglerChangeState, Handler); + + private void Handler(QSBAngler qsbAngler) => SendEvent(CreateMessage(qsbAngler)); + + private AnglerChangeStateMessage CreateMessage(QSBAngler qsbAngler) => new() + { + ObjectId = qsbAngler.ObjectId, + EnumValue = qsbAngler.AttachedObject._currentState, + TargetId = TargetToId(qsbAngler.TargetTransform), + LocalDisturbancePos = qsbAngler.AttachedObject._localDisturbancePos + }; + + public override void OnReceiveLocal(bool isHost, AnglerChangeStateMessage message) => OnReceive(isHost, message); + public override void OnReceiveRemote(bool isHost, AnglerChangeStateMessage message) => OnReceive(isHost, message); + + private static void OnReceive(bool isHost, AnglerChangeStateMessage message) + { + if (!QSBCore.WorldObjectsReady) + { + return; + } + + var qsbAngler = QSBWorldSync.GetWorldFromId(message.ObjectId); + + if (isHost) + { + qsbAngler.TransferAuthority(message.FromId); + } + + qsbAngler.TargetTransform = IdToTarget(message.TargetId); + qsbAngler.AttachedObject._localDisturbancePos = message.LocalDisturbancePos; + qsbAngler.AttachedObject.ChangeState(message.EnumValue); + } + + private static uint TargetToId(Transform transform) + { + if (transform == null) + { + return uint.MaxValue; + } + + if (transform == Locator.GetShipTransform()) + { + return uint.MaxValue - 1; + } + + return QSBPlayerManager.LocalPlayerId; + } + + private static Transform IdToTarget(uint id) + { + if (id == uint.MaxValue) + { + return null; + } + + if (id == uint.MaxValue - 1) + { + return Locator.GetShipTransform(); + } + + return QSBPlayerManager.GetPlayer(id).Body.transform; + } + } +} diff --git a/QSB/Anglerfish/Events/AnglerChangeStateMessage.cs b/QSB/Anglerfish/Events/AnglerChangeStateMessage.cs new file mode 100644 index 00000000..0615153d --- /dev/null +++ b/QSB/Anglerfish/Events/AnglerChangeStateMessage.cs @@ -0,0 +1,26 @@ +using QSB.WorldSync.Events; +using QuantumUNET.Transport; +using UnityEngine; + +namespace QSB.Anglerfish.Events +{ + public class AnglerChangeStateMessage : EnumWorldObjectMessage + { + public uint TargetId; + public Vector3 LocalDisturbancePos; + + public override void Deserialize(QNetworkReader reader) + { + base.Deserialize(reader); + TargetId = reader.ReadUInt32(); + LocalDisturbancePos = reader.ReadVector3(); + } + + public override void Serialize(QNetworkWriter writer) + { + base.Serialize(writer); + writer.Write(TargetId); + writer.Write(LocalDisturbancePos); + } + } +} diff --git a/QSB/Anglerfish/Patches/AnglerPatches.cs b/QSB/Anglerfish/Patches/AnglerPatches.cs new file mode 100644 index 00000000..198f87fa --- /dev/null +++ b/QSB/Anglerfish/Patches/AnglerPatches.cs @@ -0,0 +1,362 @@ +using HarmonyLib; +using QSB.Anglerfish.WorldObjects; +using QSB.Events; +using QSB.Patches; +using QSB.WorldSync; +using System; +using UnityEngine; + +namespace QSB.Anglerfish.Patches +{ + public class AnglerPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.GetTargetPosition))] + public static bool GetTargetPosition(AnglerfishController __instance, ref Vector3 __result) + { + var qsbAngler = QSBWorldSync.GetWorldFromUnity(__instance); + if (qsbAngler == null || qsbAngler.TransformSync == null) + { + return false; + } + + __result = qsbAngler.TargetTransform != null + ? qsbAngler.TargetTransform.position + : __instance._brambleBody.transform.TransformPoint(__instance._localDisturbancePos); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.OnSectorOccupantRemoved))] + public static bool OnSectorOccupantRemoved(AnglerfishController __instance, + SectorDetector sectorDetector) + { + var qsbAngler = QSBWorldSync.GetWorldFromUnity(__instance); + if (qsbAngler == null || qsbAngler.TransformSync == null) + { + return false; + } + + if (!(qsbAngler.TargetTransform != null) || !(sectorDetector.GetAttachedOWRigidbody().transform == qsbAngler.TargetTransform)) + { + return false; + } + + qsbAngler.TargetTransform = null; + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.UpdateState))] + public static bool UpdateState(AnglerfishController __instance) + { + var qsbAngler = QSBWorldSync.GetWorldFromUnity(__instance); + if (qsbAngler == null || qsbAngler.TransformSync == null) + { + return false; + } + + switch (__instance._currentState) + { + case AnglerfishController.AnglerState.Investigating: + if ((__instance._brambleBody.transform.TransformPoint(__instance._localDisturbancePos) - __instance._anglerBody.GetPosition()).sqrMagnitude >= __instance._arrivalDistance * (double)__instance._arrivalDistance) + { + break; + } + + __instance.ChangeState(AnglerfishController.AnglerState.Lurking); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + break; + + case AnglerfishController.AnglerState.Chasing: + if (qsbAngler.TargetTransform == null) + { + __instance.ChangeState(AnglerfishController.AnglerState.Lurking); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + break; + } + + if ((qsbAngler.TargetTransform.position - __instance._anglerBody.GetPosition()).sqrMagnitude <= __instance._escapeDistance * (double)__instance._escapeDistance) + { + break; + } + + qsbAngler.TargetTransform = null; + __instance.ChangeState(AnglerfishController.AnglerState.Lurking); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + break; + + case AnglerfishController.AnglerState.Consuming: + if (__instance._consumeComplete) + { + break; + } + + if (qsbAngler.TargetTransform == null) + { + __instance.ChangeState(AnglerfishController.AnglerState.Lurking); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + break; + } + + var num = Time.time - __instance._consumeStartTime; + if (qsbAngler.TargetTransform.CompareTag("Player") && num > (double)__instance._consumeDeathDelay) + { + qsbAngler.TargetTransform = null; + __instance.ChangeState(AnglerfishController.AnglerState.Lurking); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + __instance.ApplyDrag(1f); + + Locator.GetDeathManager().KillPlayer(DeathType.Digestion); + __instance._consumeComplete = true; + break; + } + + if (!qsbAngler.TargetTransform.CompareTag("Ship")) + { + break; + } + + if (num > (double)__instance._consumeShipCrushDelay) + { + qsbAngler.TargetTransform.GetComponentInChildren().TriggerSystemFailure(); + } + + if (num <= (double)__instance._consumeDeathDelay) + { + break; + } + + if (PlayerState.IsInsideShip()) + { + qsbAngler.TargetTransform = null; + __instance.ChangeState(AnglerfishController.AnglerState.Lurking); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + __instance.ApplyDrag(1f); + + Locator.GetDeathManager().KillPlayer(DeathType.Digestion); + } + + __instance._consumeComplete = true; + break; + + case AnglerfishController.AnglerState.Stunned: + __instance._stunTimer -= Time.deltaTime; + if (__instance._stunTimer > 0.0) + { + break; + } + + if (qsbAngler.TargetTransform != null) + { + __instance.ChangeState(AnglerfishController.AnglerState.Chasing); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + break; + } + + __instance.ChangeState(AnglerfishController.AnglerState.Lurking); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + break; + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.UpdateMovement))] + public static bool UpdateMovement(AnglerfishController __instance) + { + var qsbAngler = QSBWorldSync.GetWorldFromUnity(__instance); + if (qsbAngler == null || qsbAngler.TransformSync == null) + { + return false; + } + + qsbAngler.FixedUpdate(); + + if (__instance._anglerBody.GetVelocity().sqrMagnitude > (double)Mathf.Pow(__instance._chaseSpeed * 1.5f, 2f)) + { + __instance.ApplyDrag(10f); + } + + switch (__instance._currentState) + { + case AnglerfishController.AnglerState.Lurking: + __instance.ApplyDrag(1f); + break; + + case AnglerfishController.AnglerState.Investigating: + var targetPos = __instance._brambleBody.transform.TransformPoint(__instance._localDisturbancePos); + __instance.RotateTowardsTarget(targetPos, __instance._turnSpeed, __instance._turnSpeed); + if (__instance._turningInPlace) + { + break; + } + + __instance.MoveTowardsTarget(targetPos, __instance._investigateSpeed, __instance._acceleration); + break; + + case AnglerfishController.AnglerState.Chasing: + var velocity = qsbAngler.TargetVelocity; + var normalized = velocity.normalized; + var from = __instance._anglerBody.GetPosition() + __instance.transform.TransformDirection(__instance._mouthOffset) - qsbAngler.TargetTransform.position; + var magnitude1 = velocity.magnitude; + var num1 = Vector3.Angle(from, normalized); + var a = magnitude1 * 2f; + var num2 = a; + if (num1 < 90.0) + { + var magnitude2 = (double)from.magnitude; + var num3 = (float)magnitude2 * Mathf.Sin(num1 * ((float)Math.PI / 180f)); + var num4 = (float)magnitude2 * Mathf.Cos(num1 * ((float)Math.PI / 180f)); + var magnitude3 = __instance._anglerBody.GetVelocity().magnitude; + var num5 = num4 / Mathf.Max(magnitude1, 0.0001f) / (num3 / Mathf.Max(magnitude3, 0.0001f)); + if (num5 <= 1.0) + { + var t = Mathf.Clamp01(num5); + num2 = Mathf.Lerp(a, num4, t); + } + else + { + var num6 = Mathf.InverseLerp(1f, 4f, num5); + num2 = Mathf.Lerp(num4, 0.0f, num6 * num6); + } + } + + __instance._targetPos = qsbAngler.TargetTransform.position + (normalized * num2); + __instance.RotateTowardsTarget(__instance._targetPos, __instance._turnSpeed, __instance._quickTurnSpeed); + if (__instance._turningInPlace) + { + break; + } + + __instance.MoveTowardsTarget(__instance._targetPos, __instance._chaseSpeed, __instance._acceleration); + break; + + case AnglerfishController.AnglerState.Consuming: + __instance.ApplyDrag(1f); + break; + + case AnglerfishController.AnglerState.Stunned: + __instance.ApplyDrag(0.5f); + break; + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.OnImpact))] + public static bool OnImpact(AnglerfishController __instance, + ImpactData impact) + { + var qsbAngler = QSBWorldSync.GetWorldFromUnity(__instance); + if (qsbAngler == null || qsbAngler.TransformSync == null) + { + return false; + } + + var attachedOwRigidbody = impact.otherCollider.GetAttachedOWRigidbody(); + if ((attachedOwRigidbody.CompareTag("Player") || attachedOwRigidbody.CompareTag("Ship")) + && __instance._currentState != AnglerfishController.AnglerState.Consuming + && __instance._currentState != AnglerfishController.AnglerState.Stunned) + { + qsbAngler.TargetTransform = attachedOwRigidbody.transform; + __instance.ChangeState(AnglerfishController.AnglerState.Chasing); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.OnClosestAudibleNoise))] + public static bool OnClosestAudibleNoise(AnglerfishController __instance, + NoiseMaker noiseMaker) + { + var qsbAngler = QSBWorldSync.GetWorldFromUnity(__instance); + if (qsbAngler == null || qsbAngler.TransformSync == null) + { + return false; + } + + if (__instance._currentState is AnglerfishController.AnglerState.Consuming + or AnglerfishController.AnglerState.Stunned) + { + return false; + } + + if ((noiseMaker.GetNoiseOrigin() - __instance.transform.position).sqrMagnitude < __instance._pursueDistance * (double)__instance._pursueDistance) + { + if (!(qsbAngler.TargetTransform != noiseMaker.GetAttachedBody().transform)) + { + return false; + } + + qsbAngler.TargetTransform = noiseMaker.GetAttachedBody().transform; + if (__instance._currentState == AnglerfishController.AnglerState.Chasing) + { + return false; + } + + __instance.ChangeState(AnglerfishController.AnglerState.Chasing); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + } + else + { + if (__instance._currentState is not AnglerfishController.AnglerState.Lurking + and not AnglerfishController.AnglerState.Investigating) + { + return false; + } + + __instance._localDisturbancePos = __instance._brambleBody.transform.InverseTransformPoint(noiseMaker.GetNoiseOrigin()); + if (__instance._currentState == AnglerfishController.AnglerState.Investigating) + { + return false; + } + + __instance.ChangeState(AnglerfishController.AnglerState.Investigating); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.OnCaughtObject))] + public static bool OnCaughtObject(AnglerfishController __instance, + OWRigidbody caughtBody) + { + var qsbAngler = QSBWorldSync.GetWorldFromUnity(__instance); + + if (__instance._currentState == AnglerfishController.AnglerState.Consuming) + { + if (qsbAngler.TargetTransform.CompareTag("Player") || !caughtBody.CompareTag("Player")) + { + return false; + } + + Locator.GetDeathManager().KillPlayer(DeathType.Digestion); + } + else + { + if (!caughtBody.CompareTag("Player") && !caughtBody.CompareTag("Ship")) + { + return false; + } + + qsbAngler.TargetTransform = caughtBody.transform; + __instance._consumeStartTime = Time.time; + __instance.ChangeState(AnglerfishController.AnglerState.Consuming); + QSBEventManager.FireEvent(EventNames.QSBAnglerChangeState, qsbAngler); + } + + return false; + } + } +} diff --git a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs new file mode 100644 index 00000000..297524da --- /dev/null +++ b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs @@ -0,0 +1,83 @@ +using QSB.Anglerfish.WorldObjects; +using QSB.Syncs.Unsectored.Rigidbodies; +using QSB.WorldSync; +using QuantumUNET.Transport; +using System.Collections.Generic; +using UnityEngine; + +namespace QSB.Anglerfish.TransformSync +{ + public class AnglerTransformSync : UnsectoredRigidbodySync + { + public override bool IsReady => QSBCore.WorldObjectsReady; + public override bool UseInterpolation => false; + + private QSBAngler _qsbAngler; + private static readonly List _instances = new(); + + protected override OWRigidbody GetRigidbody() + => _qsbAngler.AttachedObject._anglerBody; + + public override void Start() + { + _instances.Add(this); + base.Start(); + } + + protected override void OnDestroy() + { + _instances.Remove(this); + base.OnDestroy(); + } + + public override float GetNetworkSendInterval() => 1; + + protected override void Init() + { + _qsbAngler = QSBWorldSync.GetWorldFromId(_instances.IndexOf(this)); + _qsbAngler.TransformSync = this; + + base.Init(); + SetReferenceTransform(_qsbAngler.AttachedObject._brambleBody.transform); + } + + private bool _shouldUpdate; + + public override void DeserializeTransform(QNetworkReader reader, bool initialState) + { + base.DeserializeTransform(reader, initialState); + _shouldUpdate = true; + } + + protected override bool UpdateTransform() + { + if (HasAuthority) + { + return base.UpdateTransform(); + } + + if (!_shouldUpdate) + { + return false; + } + + _shouldUpdate = false; + return base.UpdateTransform(); + } + + protected override void OnRenderObject() + { + base.OnRenderObject(); + + if (!QSBCore.WorldObjectsReady + || !QSBCore.ShowLinesInDebug + || !IsReady + || ReferenceTransform == null) + { + return; + } + + Popcron.Gizmos.Line(AttachedObject.transform.position, _qsbAngler.AttachedObject.GetTargetPosition(), Color.white); + } + } +} diff --git a/QSB/Anglerfish/WorldObjects/QSBAngler.cs b/QSB/Anglerfish/WorldObjects/QSBAngler.cs new file mode 100644 index 00000000..007c02c2 --- /dev/null +++ b/QSB/Anglerfish/WorldObjects/QSBAngler.cs @@ -0,0 +1,69 @@ +using QSB.Anglerfish.TransformSync; +using QSB.Utility; +using QSB.WorldSync; +using QuantumUNET; +using System.Linq; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace QSB.Anglerfish.WorldObjects +{ + public class QSBAngler : WorldObject + { + public AnglerTransformSync TransformSync; + public Transform TargetTransform; + public Vector3 TargetVelocity { get; private set; } + + private Vector3 _lastTargetPosition; + + public override void Init(AnglerfishController attachedObject, int id) + { + ObjectId = id; + AttachedObject = attachedObject; + + if (QSBCore.IsHost) + { + Object.Instantiate(QSBNetworkManager.Instance.AnglerPrefab).SpawnWithServerAuthority(); + } + } + + public override void OnRemoval() + { + if (QSBCore.IsHost) + { + QNetworkServer.Destroy(TransformSync.gameObject); + } + } + + public void TransferAuthority(uint id) + { + var conn = QNetworkServer.connections.First(x => x.GetPlayerId() == id); + var identity = TransformSync.NetIdentity; + + if (identity.ClientAuthorityOwner == conn) + { + return; + } + + if (identity.ClientAuthorityOwner != null) + { + identity.RemoveClientAuthority(identity.ClientAuthorityOwner); + } + + identity.AssignClientAuthority(conn); + + DebugLog.DebugWrite($"angler {ObjectId} - transferred authority to {id}"); + } + + public void FixedUpdate() + { + if (TargetTransform == null) + { + return; + } + + TargetVelocity = TargetTransform.position - _lastTargetPosition; + _lastTargetPosition = TargetTransform.position; + } + } +} diff --git a/QSB/Animation/NPC/CharacterAnimManager.cs b/QSB/Animation/NPC/CharacterAnimManager.cs index 59a60c08..24291324 100644 --- a/QSB/Animation/NPC/CharacterAnimManager.cs +++ b/QSB/Animation/NPC/CharacterAnimManager.cs @@ -1,7 +1,6 @@ using QSB.Animation.NPC.WorldObjects; using QSB.WorldSync; using System.Linq; -using UnityEngine; namespace QSB.Animation.NPC { @@ -11,10 +10,12 @@ namespace QSB.Animation.NPC { QSBWorldSync.Init(); QSBWorldSync.Init(); + QSBWorldSync.Init(); + QSBWorldSync.Init(); //MOVE : this is the wrong place to put this... move it to Conversations? QSBWorldSync.OldDialogueTrees.Clear(); - QSBWorldSync.OldDialogueTrees = Resources.FindObjectsOfTypeAll().ToList(); + QSBWorldSync.OldDialogueTrees = QSBWorldSync.GetUnityObjects().ToList(); } } } diff --git a/QSB/Animation/NPC/Events/NpcAnimationEvent.cs b/QSB/Animation/NPC/Events/NpcAnimationEvent.cs index 46108968..2316e2fa 100644 --- a/QSB/Animation/NPC/Events/NpcAnimationEvent.cs +++ b/QSB/Animation/NPC/Events/NpcAnimationEvent.cs @@ -13,7 +13,7 @@ namespace QSB.Animation.NPC.Events private void Handler(AnimationEvent animEvent, int index) => SendEvent(CreateMessage(animEvent, index)); - private NpcAnimationMessage CreateMessage(AnimationEvent animEvent, int index) => new NpcAnimationMessage + private NpcAnimationMessage CreateMessage(AnimationEvent animEvent, int index) => new() { AboutId = LocalPlayerId, AnimationEvent = animEvent, diff --git a/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs b/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs index fffa8883..b4427279 100644 --- a/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs +++ b/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs @@ -8,7 +8,6 @@ using QSB.Player; using QSB.Utility; using QSB.WorldSync; using System.Linq; -using System.Reflection; using UnityEngine; namespace QSB.Animation.NPC.Patches @@ -24,7 +23,6 @@ namespace QSB.Animation.NPC.Patches CharacterAnimController __instance, float ___headTrackingWeight, bool ___lookOnlyWhenTalking, - bool ____playerInHeadZone, bool ____inConversation, ref float ____currentLookWeight, ref Vector3 ____currentLookTarget, @@ -39,7 +37,7 @@ namespace QSB.Animation.NPC.Patches var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree); var player = QSBPlayerManager.GetPlayer(playerId); - var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); // OPTIMIZE : maybe cache this somewhere... or assess how slow this is + var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); // OPTIMIZE : maybe cache this somewhere... or assess how slow this is PlayerInfo playerToUse = null; if (____inConversation) @@ -100,8 +98,8 @@ namespace QSB.Animation.NPC.Patches [HarmonyPatch(typeof(CharacterAnimController), nameof(CharacterAnimController.OnZoneExit))] public static bool HeadZoneExit(CharacterAnimController __instance) { - var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); - QSBEventManager.FireEvent(EventNames.QSBExitHeadZone, qsbObj.ObjectId); + var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); + QSBEventManager.FireEvent(EventNames.QSBExitNonNomaiHeadZone, qsbObj.ObjectId); return false; } @@ -109,21 +107,19 @@ namespace QSB.Animation.NPC.Patches [HarmonyPatch(typeof(CharacterAnimController), nameof(CharacterAnimController.OnZoneEntry))] public static bool HeadZoneEntry(CharacterAnimController __instance) { - var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); - QSBEventManager.FireEvent(EventNames.QSBEnterHeadZone, qsbObj.ObjectId); + var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); + QSBEventManager.FireEvent(EventNames.QSBEnterNonNomaiHeadZone, qsbObj.ObjectId); return false; } [HarmonyPrefix] [HarmonyPatch(typeof(FacePlayerWhenTalking), nameof(FacePlayerWhenTalking.OnStartConversation))] - public static bool OnStartConversation( - FacePlayerWhenTalking __instance, - CharacterDialogueTree ____dialogueTree) + public static bool OnStartConversation(FacePlayerWhenTalking __instance) { - var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree); + var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(__instance._dialogueTree); if (playerId == uint.MaxValue) { - DebugLog.ToConsole($"Error - No player talking to {____dialogueTree.name}!", MessageType.Error); + DebugLog.ToConsole($"Error - No player talking to {__instance._dialogueTree.name}!", MessageType.Error); return false; } @@ -134,7 +130,7 @@ namespace QSB.Animation.NPC.Patches var angle = Vector3.Angle(__instance.transform.forward, vector2) * Mathf.Sign(Vector3.Dot(vector2, __instance.transform.right)); var axis = __instance.transform.parent.InverseTransformDirection(__instance.transform.up); var lhs = Quaternion.AngleAxis(angle, axis); - __instance.GetType().GetMethod("FaceLocalRotation", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { lhs * __instance.transform.localRotation }); + __instance.FaceLocalRotation(lhs * __instance.transform.localRotation); return false; } @@ -173,22 +169,18 @@ namespace QSB.Animation.NPC.Patches [HarmonyPrefix] [HarmonyPatch(typeof(KidRockController), nameof(KidRockController.Update))] - public static bool UpdateReplacement( - KidRockController __instance, - bool ____throwingRock, - CharacterDialogueTree ____dialogueTree, - float ____nextThrowTime) + public static bool UpdateReplacement(KidRockController __instance) { if (!WorldObjectManager.AllReady) { return true; } - var qsbObj = QSBWorldSync.GetWorldObjects().First(x => x.GetDialogueTree() == ____dialogueTree); + var qsbObj = QSBWorldSync.GetWorldObjects().First(x => x.GetDialogueTree() == __instance._dialogueTree); - if (!____throwingRock && !qsbObj.InConversation() && Time.time > ____nextThrowTime) + if (!__instance._throwingRock && !qsbObj.InConversation() && Time.time > __instance._nextThrowTime) { - __instance.GetType().GetMethod("StartRockThrow", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null); + __instance.StartRockThrow(); } return false; diff --git a/QSB/Animation/NPC/Patches/SolanumPatches.cs b/QSB/Animation/NPC/Patches/SolanumPatches.cs new file mode 100644 index 00000000..30761ba6 --- /dev/null +++ b/QSB/Animation/NPC/Patches/SolanumPatches.cs @@ -0,0 +1,229 @@ +using HarmonyLib; +using QSB.Animation.NPC.WorldObjects; +using QSB.Events; +using QSB.Patches; +using QSB.Player; +using QSB.WorldSync; +using System.Linq; +using UnityEngine; + +namespace QSB.Animation.NPC.Patches +{ + [HarmonyPatch] + public class SolanumPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(SolanumAnimController), nameof(SolanumAnimController.LateUpdate))] + public static bool SolanumLateUpdateReplacement(SolanumAnimController __instance) + { + if (__instance._animatorStateEvents == null) + { + __instance._animatorStateEvents = __instance._animator.GetBehaviour(); + __instance._animatorStateEvents.OnEnterState += __instance.OnEnterAnimatorState; + } + + var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); + var playersInHeadZone = qsbObj.GetPlayersInHeadZone(); + + var targetCamera = playersInHeadZone == null || playersInHeadZone.Count == 0 + ? __instance._playerCameraTransform + : QSBPlayerManager.GetClosestPlayerToWorldPoint(playersInHeadZone, __instance.transform.position).CameraBody.transform; + + var targetValue = Quaternion.LookRotation(targetCamera.position - __instance._headBoneTransform.position, __instance.transform.up); + __instance._currentLookRotation = __instance._lookSpring.Update(__instance._currentLookRotation, targetValue, Time.deltaTime); + + var position = __instance._headBoneTransform.position + (__instance._currentLookRotation * Vector3.forward); + __instance._localLookPosition = __instance.transform.InverseTransformPoint(position); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiConversationManager), nameof(NomaiConversationManager.OnEnterWatchVolume))] + public static bool EnterWatchZone(NomaiConversationManager __instance) + { + var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance._solanumAnimController); + QSBEventManager.FireEvent(EventNames.QSBEnterNomaiHeadZone, qsbObj.ObjectId); + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiConversationManager), nameof(NomaiConversationManager.OnExitWatchVolume))] + public static bool ExitWatchZone(NomaiConversationManager __instance) + { + var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance._solanumAnimController); + QSBEventManager.FireEvent(EventNames.QSBExitNomaiHeadZone, qsbObj.ObjectId); + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiConversationManager), nameof(NomaiConversationManager.Update))] + public static bool ReplacementUpdate(NomaiConversationManager __instance) + { + var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance._solanumAnimController); + __instance._playerInWatchVolume = qsbObj.GetPlayersInHeadZone().Any(); + + if (!__instance._initialized) + { + __instance.InitializeNomaiText(); + } + + //var heldItem = Locator.GetToolModeSwapper().GetItemCarryTool().GetHeldItem(); + //var holdingConversationStone = heldItem != null && heldItem is NomaiConversationStone; + var holdingConversationStone = QSBPlayerManager.GetPlayerCarryItems().Any(x => x.Item2 != null && x.Item2.GetItemType() == ItemType.ConversationStone); + + switch (__instance._state) + { + case NomaiConversationManager.State.WatchingSky: + if (__instance._playerInWatchVolume) + { + __instance._state = NomaiConversationManager.State.WatchingPlayer; + __instance._solanumAnimController.StartWatchingPlayer(); + } + + break; + + case NomaiConversationManager.State.WatchingPlayer: + if (!__instance._solanumAnimController.isPerformingAction) + { + // player left watch zone + if (!__instance._playerInWatchVolume) + { + __instance._state = NomaiConversationManager.State.WatchingSky; + __instance._solanumAnimController.StopWatchingPlayer(); + } + else if (__instance._dialogueComplete) + { + // create conversation stones + if (__instance._dialogueComplete && !__instance._conversationStonesCreated) + { + __instance._stoneCreationTimer -= Time.deltaTime; + if (__instance._stoneCreationTimer <= 0f) + { + __instance._state = NomaiConversationManager.State.CreatingStones; + __instance._solanumAnimController.PlayCreateWordStones(); + } + } + else if (__instance._conversationStonesCreated && !__instance._cairnRaised) + { + if (!holdingConversationStone) + { + __instance._stoneGestureTimer -= Time.deltaTime; + if (__instance._stoneGestureTimer <= 0f) + { + __instance._solanumAnimController.PlayGestureToWordStones(); + __instance._stoneGestureTimer = UnityEngine.Random.Range(8f, 16f); + } + } + // raise cairns + else if (__instance._solanumAnimController.IsPlayerLooking()) + { + __instance._state = NomaiConversationManager.State.RaisingCairns; + __instance._solanumAnimController.PlayRaiseCairns(); + __instance._cairnAnimator.SetTrigger("Raise"); + __instance._cairnCollision.SetActivation(true); + } + } + else if (__instance._activeResponseText == null && __instance._hasValidSocketedStonePair) + { + __instance._activeResponseText = __instance._pendingResponseText; + __instance._pendingResponseText = null; + __instance._state = NomaiConversationManager.State.WritingResponse; + __instance._solanumAnimController.StartWritingMessage(); + } + else if (__instance._activeResponseText != null && (!__instance._hasValidSocketedStonePair || __instance._pendingResponseText != null)) + { + __instance._state = NomaiConversationManager.State.ErasingResponse; + __instance._solanumAnimController.StartWritingMessage(); + } + else if (!holdingConversationStone) + { + if (__instance._playerWasHoldingStone) + { + __instance.ResetStoneGestureTimer(); + } + + __instance._stoneGestureTimer -= Time.deltaTime; + if (__instance._stoneGestureTimer < 0f) + { + __instance._solanumAnimController.PlayGestureToWordStones(); + __instance.ResetStoneGestureTimer(); + } + } + else + { + if (!__instance._playerWasHoldingStone) + { + __instance.ResetCairnGestureTimer(); + } + + __instance._cairnGestureTimer -= Time.deltaTime; + if (__instance._cairnGestureTimer < 0f) + { + __instance._solanumAnimController.PlayGestureToCairns(); + __instance.ResetCairnGestureTimer(); + } + } + } + } + + break; + + case NomaiConversationManager.State.CreatingStones: + if (!__instance._solanumAnimController.isPerformingAction) + { + __instance._state = NomaiConversationManager.State.WatchingPlayer; + __instance._conversationStonesCreated = true; + } + + break; + + case NomaiConversationManager.State.RaisingCairns: + if (!__instance._solanumAnimController.isPerformingAction) + { + __instance._state = NomaiConversationManager.State.WatchingPlayer; + __instance._cairnRaised = true; + __instance._stoneSocketATrigger.SetActivation(true); + __instance._stoneSocketBTrigger.SetActivation(true); + } + + break; + + case NomaiConversationManager.State.ErasingResponse: + if (!__instance._solanumAnimController.isStartingWrite && !__instance._activeResponseText.IsAnimationPlaying()) + { + __instance._activeResponseText = null; + if (__instance._pendingResponseText == null) + { + __instance._state = NomaiConversationManager.State.WatchingPlayer; + __instance._solanumAnimController.StopWritingMessage(false); + } + else + { + __instance._activeResponseText = __instance._pendingResponseText; + __instance._pendingResponseText = null; + __instance._state = NomaiConversationManager.State.WritingResponse; + __instance._activeResponseText.Show(); + } + } + + break; + + case NomaiConversationManager.State.WritingResponse: + if (!__instance._solanumAnimController.isStartingWrite && !__instance._activeResponseText.IsAnimationPlaying()) + { + __instance._state = NomaiConversationManager.State.WatchingPlayer; + __instance._solanumAnimController.StopWritingMessage(true); + } + + break; + } + + __instance._playerWasHoldingStone = holdingConversationStone; + + return false; + } + } +} diff --git a/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs b/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs new file mode 100644 index 00000000..04a9fe85 --- /dev/null +++ b/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs @@ -0,0 +1,164 @@ +using HarmonyLib; +using QSB.Patches; +using System; +using System.Linq; +using UnityEngine; + +namespace QSB.Animation.NPC.Patches +{ + [HarmonyPatch(typeof(TravelerController))] + public class TravelerControllerPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(TravelerController.OnStartConversation))] + public static bool OnStartConversation(TravelerController __instance) + { + __instance._talking = true; + + if (__instance is GabbroTravelerController gabbro) + { + if (gabbro._animator.enabled) + { + gabbro._animator.CrossFadeInFixedTime("Gabbro_Talking", 1.8f); + gabbro._hammockAnimator.CrossFadeInFixedTime("GabbroHammock_Talking", 1.8f); + } + + Locator.GetTravelerAudioManager().StopTravelerAudio(gabbro.name); + } + else + { + if (__instance._animator != null && __instance._animator.enabled) + { + __instance._playingAnimID = __instance._animator.IsInTransition(0) + ? __instance._animator.GetNextAnimatorStateInfo(0).fullPathHash + : __instance._animator.GetCurrentAnimatorStateInfo(0).fullPathHash; + + __instance._animator.SetTrigger("Talking"); + } + + Locator.GetTravelerAudioManager().StopTravelerAudio(__instance.name); + + if (__instance is ChertTravelerController chert) + { + chert._moodWeight = (float)chert._mood; + } + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(TravelerController.OnEndConversation))] + public static bool OnEndConversation(TravelerController __instance) + { + if (__instance is GabbroTravelerController gabbro) + { + if (gabbro._animator.enabled) + { + gabbro._animator.CrossFadeInFixedTime("Gabbro_Playing", gabbro._delayToRestartAudio, -1, -gabbro._delayToRestartAudio); + gabbro._hammockAnimator.CrossFadeInFixedTime("GabbroHammock_Playing", gabbro._delayToRestartAudio, -1, -gabbro._delayToRestartAudio); + } + + Locator.GetTravelerAudioManager().PlayTravelerAudio(gabbro.name, gabbro._delayToRestartAudio); + if (DialogueConditionManager.SharedInstance.GetConditionState("MAP_PROMPT_REMINDER") || DialogueConditionManager.SharedInstance.GetConditionState("MAP_PROMPT_ATTENTION")) + { + var conditionState = DialogueConditionManager.SharedInstance.GetConditionState("MAP_PROMPT_ATTENTION"); + DialogueConditionManager.SharedInstance.SetConditionState("MAP_PROMPT_REMINDER"); + DialogueConditionManager.SharedInstance.SetConditionState("MAP_PROMPT_ATTENTION"); + GlobalMessenger.FireEvent("TriggerMapPromptReminder", conditionState); + } + } + else + { + if (__instance._animator != null && __instance._animator.enabled) + { + if (__instance._delayToRestartAudio > 0f) + { + __instance._animator.CrossFadeInFixedTime(__instance._playingAnimID, __instance._delayToRestartAudio, -1, -__instance._delayToRestartAudio); + } + else + { + __instance._animator.SetTrigger("Playing"); + } + } + + Locator.GetTravelerAudioManager().PlayTravelerAudio(__instance.name, __instance._delayToRestartAudio); + } + + __instance._talking = false; + + return false; + } + } + + internal static class TravelerAudioManagerExtensions + { + /// bad, but works great + private static SignalName TravelerToSignal(string name) + { + if (name.Contains("Esker")) + { + return SignalName.Traveler_Esker; + } + + if (name.Contains("Chert")) + { + return SignalName.Traveler_Chert; + } + + if (name.Contains("Riebeck")) + { + return SignalName.Traveler_Riebeck; + } + + if (name.Contains("Gabbro")) + { + return SignalName.Traveler_Gabbro; + } + + if (name.Contains("Feldspar")) + { + return SignalName.Traveler_Feldspar; + } + + if (name.Contains("Nomai")) + { + return SignalName.Traveler_Nomai; + } + + if (name.Contains("Prisoner")) + { + return SignalName.Traveler_Prisoner; + } + + throw new ArgumentOutOfRangeException(nameof(name), name, null); + } + + internal static void StopTravelerAudio(this TravelerAudioManager manager, string name) + { + var signalName = TravelerToSignal(name); + var audioSignal = manager._signals.First(x => x.GetName() == signalName); + + audioSignal.GetOWAudioSource().FadeOut(0.5f); + } + + internal static void PlayTravelerAudio(this TravelerAudioManager manager, string name, float audioDelay) + { + var signalName = TravelerToSignal(name); + var audioSignal = manager._signals.First(x => x.GetName() == signalName); + + manager._playAfterDelay = false; + manager._playAudioTime = Time.time + audioDelay; + QSBCore.UnityEvents.RunWhen(() => Time.time >= manager._playAudioTime, () => + { + if (!audioSignal.IsOnlyAudibleToScope() || audioSignal.GetOWAudioSource().isPlaying) + { + audioSignal.GetOWAudioSource().FadeIn(0.5f); + audioSignal.GetOWAudioSource().timeSamples = 0; + } + }); + } + } +} diff --git a/QSB/Animation/NPC/WorldObjects/QSBCharacterAnimController.cs b/QSB/Animation/NPC/WorldObjects/QSBCharacterAnimController.cs index 56f4b6bd..9144e966 100644 --- a/QSB/Animation/NPC/WorldObjects/QSBCharacterAnimController.cs +++ b/QSB/Animation/NPC/WorldObjects/QSBCharacterAnimController.cs @@ -1,12 +1,11 @@ -using OWML.Utils; -using QSB.Player; +using QSB.Player; using System.Collections.Generic; namespace QSB.Animation.NPC.WorldObjects { internal class QSBCharacterAnimController : NpcAnimController { - private readonly List _playersInHeadZone = new List(); + private readonly List _playersInHeadZone = new(); public List GetPlayersInHeadZone() => _playersInHeadZone; @@ -32,9 +31,9 @@ namespace QSB.Animation.NPC.WorldObjects } public override CharacterDialogueTree GetDialogueTree() - => AttachedObject.GetValue("_dialogueTree"); + => AttachedObject._dialogueTree; public override bool InConversation() - => AttachedObject.GetValue("_inConversation"); + => AttachedObject._inConversation; } } diff --git a/QSB/Animation/NPC/WorldObjects/QSBSolanumAnimController.cs b/QSB/Animation/NPC/WorldObjects/QSBSolanumAnimController.cs new file mode 100644 index 00000000..3505f973 --- /dev/null +++ b/QSB/Animation/NPC/WorldObjects/QSBSolanumAnimController.cs @@ -0,0 +1,40 @@ +using QSB.Player; +using QSB.WorldSync; +using System.Collections.Generic; + +namespace QSB.Animation.NPC.WorldObjects +{ + internal class QSBSolanumAnimController : WorldObject + { + private readonly List _playersInHeadZone = new(); + + public override void Init(SolanumAnimController controller, int id) + { + ObjectId = id; + AttachedObject = controller; + } + + public List GetPlayersInHeadZone() + => _playersInHeadZone; + + public void AddPlayerToHeadZone(PlayerInfo player) + { + if (_playersInHeadZone.Contains(player)) + { + return; + } + + _playersInHeadZone.Add(player); + } + + public void RemovePlayerFromHeadZone(PlayerInfo player) + { + if (!_playersInHeadZone.Contains(player)) + { + return; + } + + _playersInHeadZone.Remove(player); + } + } +} diff --git a/QSB/Animation/NPC/WorldObjects/QSBSolanumController.cs b/QSB/Animation/NPC/WorldObjects/QSBSolanumController.cs new file mode 100644 index 00000000..945fbc6b --- /dev/null +++ b/QSB/Animation/NPC/WorldObjects/QSBSolanumController.cs @@ -0,0 +1,11 @@ +namespace QSB.Animation.NPC.WorldObjects +{ + internal class QSBSolanumController : NpcAnimController + { + public override CharacterDialogueTree GetDialogueTree() + => AttachedObject._characterDialogueTree; + + public override bool InConversation() + => AttachedObject._solanumAnimController._animator.GetBool("ListeningToPlayer"); + } +} diff --git a/QSB/Animation/NPC/WorldObjects/QSBTravelerController.cs b/QSB/Animation/NPC/WorldObjects/QSBTravelerController.cs index 7c8927e7..52700584 100644 --- a/QSB/Animation/NPC/WorldObjects/QSBTravelerController.cs +++ b/QSB/Animation/NPC/WorldObjects/QSBTravelerController.cs @@ -1,13 +1,11 @@ -using OWML.Utils; - -namespace QSB.Animation.NPC.WorldObjects +namespace QSB.Animation.NPC.WorldObjects { internal class QSBTravelerController : NpcAnimController { public override CharacterDialogueTree GetDialogueTree() - => AttachedObject.GetValue("_dialogueSystem"); + => AttachedObject._dialogueSystem; public override bool InConversation() - => AttachedObject.GetValue("_talking"); + => AttachedObject._talking; } } diff --git a/QSB/Animation/Player/AnimationSync.cs b/QSB/Animation/Player/AnimationSync.cs index 53204e38..d6ef7908 100644 --- a/QSB/Animation/Player/AnimationSync.cs +++ b/QSB/Animation/Player/AnimationSync.cs @@ -155,7 +155,7 @@ namespace QSB.Animation.Player public void SetSuitState(bool state) { - if (!Player.PlayerStates.IsReady) + if (!Player.IsReady) { return; } @@ -225,7 +225,7 @@ namespace QSB.Animation.Player InvisibleAnimator.runtimeAnimatorController = controller; VisibleAnimator.runtimeAnimatorController = controller; - if (type != AnimationType.PlayerSuited && type != AnimationType.PlayerUnsuited) + if (type is not AnimationType.PlayerSuited and not AnimationType.PlayerUnsuited) { VisibleAnimator.SetTrigger("Playing"); InvisibleAnimator.SetTrigger("Playing"); diff --git a/QSB/Animation/Player/AnimatorMirror.cs b/QSB/Animation/Player/AnimatorMirror.cs index 08299aa3..b324413b 100644 --- a/QSB/Animation/Player/AnimatorMirror.cs +++ b/QSB/Animation/Player/AnimatorMirror.cs @@ -13,7 +13,7 @@ namespace QSB.Animation.Player private Animator _from; private Animator _to; - private readonly Dictionary _floatParams = new Dictionary(); + private readonly Dictionary _floatParams = new(); public void Init(Animator from, Animator to) { diff --git a/QSB/Animation/Player/CrouchSync.cs b/QSB/Animation/Player/CrouchSync.cs index 9cf9cb66..dabcf039 100644 --- a/QSB/Animation/Player/CrouchSync.cs +++ b/QSB/Animation/Player/CrouchSync.cs @@ -1,4 +1,6 @@ -using QuantumUNET; +using QSB.Utility; +using QSB.Utility.VariableSync; +using QuantumUNET; using UnityEngine; using UnityEngine.Networking; @@ -14,13 +16,15 @@ namespace QSB.Animation.Player private PlayerCharacterController _playerController; private Animator _bodyAnim; - [SyncVar] - private float _crouchValue; + public FloatVariableSyncer CrouchVariableSyncer; + public float CrouchValue = 0f; public void Init(PlayerCharacterController playerController, Animator bodyAnim) { _playerController = playerController; _bodyAnim = bodyAnim; + + CrouchVariableSyncer.Init(() => CrouchValue, val => CrouchValue = val); } public void Update() @@ -42,7 +46,7 @@ namespace QSB.Animation.Player } var jumpChargeFraction = _playerController.GetJumpCrouchFraction(); - _crouchValue = jumpChargeFraction; + CrouchVariableSyncer.ValueToSync.Value = jumpChargeFraction; } private void SyncRemoteCrouch() @@ -52,7 +56,7 @@ namespace QSB.Animation.Player return; } - CrouchParam.Target = _crouchValue; + CrouchParam.Target = CrouchValue; CrouchParam.Smooth(CrouchSmoothTime); var jumpChargeFraction = CrouchParam.Current; _bodyAnim.SetLayerWeight(CrouchLayerIndex, jumpChargeFraction); diff --git a/QSB/Animation/Player/Events/AnimationTriggerEvent.cs b/QSB/Animation/Player/Events/AnimationTriggerEvent.cs index 4a99cd32..8a6709bf 100644 --- a/QSB/Animation/Player/Events/AnimationTriggerEvent.cs +++ b/QSB/Animation/Player/Events/AnimationTriggerEvent.cs @@ -12,7 +12,7 @@ namespace QSB.Animation.Player.Events private void Handler(uint attachedNetId, string name) => SendEvent(CreateMessage(attachedNetId, name)); - private AnimationTriggerMessage CreateMessage(uint attachedNetId, string name) => new AnimationTriggerMessage + private AnimationTriggerMessage CreateMessage(uint attachedNetId, string name) => new() { AboutId = LocalPlayerId, AttachedNetId = attachedNetId, @@ -22,7 +22,7 @@ namespace QSB.Animation.Player.Events public override void OnReceiveRemote(bool server, AnimationTriggerMessage message) { var animationSync = QSBPlayerManager.GetSyncObject(message.AttachedNetId); - if (!QSBCore.WorldObjectsReady || animationSync != null) + if (!QSBCore.WorldObjectsReady || animationSync == null) { return; } diff --git a/QSB/Animation/Player/Events/ChangeAnimTypeEvent.cs b/QSB/Animation/Player/Events/ChangeAnimTypeEvent.cs index d7ec029d..56709c2a 100644 --- a/QSB/Animation/Player/Events/ChangeAnimTypeEvent.cs +++ b/QSB/Animation/Player/Events/ChangeAnimTypeEvent.cs @@ -14,7 +14,7 @@ namespace QSB.Animation.Player.Events private void Handler(uint player, AnimationType type) => SendEvent(CreateMessage(player, type)); - private EnumMessage CreateMessage(uint player, AnimationType type) => new EnumMessage + private EnumMessage CreateMessage(uint player, AnimationType type) => new() { AboutId = player, EnumValue = type @@ -22,7 +22,7 @@ namespace QSB.Animation.Player.Events public override void OnReceiveRemote(bool server, EnumMessage message) { - if (!QSBCore.WorldObjectsReady || !QSBPlayerManager.GetPlayer(message.AboutId).PlayerStates.IsReady) + if (!QSBCore.WorldObjectsReady || !QSBPlayerManager.GetPlayer(message.AboutId).IsReady) { return; } diff --git a/QSB/Animation/Player/Events/PlayerSuitEvent.cs b/QSB/Animation/Player/Events/PlayerSuitEvent.cs index 87f2dd1f..29e5ce95 100644 --- a/QSB/Animation/Player/Events/PlayerSuitEvent.cs +++ b/QSB/Animation/Player/Events/PlayerSuitEvent.cs @@ -23,7 +23,7 @@ namespace QSB.Animation.Player.Events private void HandleSuitUp() => SendEvent(CreateMessage(true)); private void HandleSuitDown() => SendEvent(CreateMessage(false)); - private ToggleMessage CreateMessage(bool value) => new ToggleMessage + private ToggleMessage CreateMessage(bool value) => new() { AboutId = LocalPlayerId, ToggleValue = value @@ -32,9 +32,9 @@ namespace QSB.Animation.Player.Events public override void OnReceiveRemote(bool server, ToggleMessage message) { var player = QSBPlayerManager.GetPlayer(message.AboutId); - player.PlayerStates.SuitedUp = message.ToggleValue; + player.SuitedUp = message.ToggleValue; - if (!QSBCore.WorldObjectsReady || !player.PlayerStates.IsReady) + if (!QSBCore.WorldObjectsReady || !player.IsReady) { return; } @@ -46,7 +46,7 @@ namespace QSB.Animation.Player.Events public override void OnReceiveLocal(bool server, ToggleMessage message) { - QSBPlayerManager.LocalPlayer.PlayerStates.SuitedUp = message.ToggleValue; + QSBPlayerManager.LocalPlayer.SuitedUp = message.ToggleValue; var animator = QSBPlayerManager.LocalPlayer.AnimationSync; var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited; animator.CurrentType = type; diff --git a/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs b/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs index 94b3d5b4..d15be2c0 100644 --- a/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs +++ b/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs @@ -1,23 +1,27 @@ -using QuantumUNET; +using QSB.Utility.VariableSync; +using QuantumUNET; using UnityEngine; -using UnityEngine.Networking; namespace QSB.Animation.Player.Thrusters { public class JetpackAccelerationSync : QNetworkBehaviour { - [SyncVar] - private Vector3 _localAcceleration; - [SyncVar] - private bool _isThrusting; + public Vector3VariableSyncer AccelerationVariableSyncer; + public BoolVariableSyncer ThrustingVariableSyncer; + public Vector3 LocalAcceleration => AccelerationVariableSyncer.ValueToSync.Value; + public bool IsThrusting => ThrustingVariableSyncer.ValueToSync.Value; + private Vector3 _localAcceleration; + private bool _isThrusting; private ThrusterModel _thrusterModel; - public Vector3 LocalAcceleration => _localAcceleration; - public bool IsThrusting => _isThrusting; - public void Init(ThrusterModel model) - => _thrusterModel = model; + { + _thrusterModel = model; + + AccelerationVariableSyncer.Init(() => _localAcceleration, val => _localAcceleration = val); + ThrustingVariableSyncer.Init(() => _isThrusting, val => _isThrusting = val); + } public void Update() { @@ -31,8 +35,8 @@ namespace QSB.Animation.Player.Thrusters { if (_thrusterModel != null) { - _localAcceleration = _thrusterModel.GetLocalAcceleration(); - _isThrusting = _thrusterModel.IsTranslationalThrusterFiring(); + AccelerationVariableSyncer.ValueToSync.Value = _thrusterModel.GetLocalAcceleration(); + ThrustingVariableSyncer.ValueToSync.Value = _thrusterModel.IsTranslationalThrusterFiring(); } } } diff --git a/QSB/Animation/Player/Thrusters/RemoteThrusterFlameController.cs b/QSB/Animation/Player/Thrusters/RemoteThrusterFlameController.cs index cd51091e..956373f3 100644 --- a/QSB/Animation/Player/Thrusters/RemoteThrusterFlameController.cs +++ b/QSB/Animation/Player/Thrusters/RemoteThrusterFlameController.cs @@ -8,7 +8,7 @@ namespace QSB.Animation.Player.Thrusters private Thruster _thruster; private Light _light; private AnimationCurve _scaleByThrust = AnimationCurve.Linear(0f, 0f, 1f, 1f); - private DampedSpring _scaleSpring = new DampedSpring(); + private DampedSpring _scaleSpring = new(); private float _belowMaxThrustScalar = 1f; private MeshRenderer _thrusterRenderer; private Vector3 _thrusterFilter; @@ -82,5 +82,16 @@ namespace QSB.Animation.Player.Thrusters } private float GetThrustFraction() => Vector3.Dot(_attachedPlayer.JetpackAcceleration.LocalAcceleration, _thrusterFilter); + + private void OnRenderObject() + { + if (!QSBCore.WorldObjectsReady || !QSBCore.ShowLinesInDebug) + { + return; + } + + Popcron.Gizmos.Sphere(_light.transform.position, 0.05f, Color.yellow, 4); + Popcron.Gizmos.Line(_light.transform.position, _light.transform.parent.position, Color.yellow); + } } } diff --git a/QSB/Animation/Player/Thrusters/ThrusterManager.cs b/QSB/Animation/Player/Thrusters/ThrusterManager.cs index 65c4fe78..e8870a03 100644 --- a/QSB/Animation/Player/Thrusters/ThrusterManager.cs +++ b/QSB/Animation/Player/Thrusters/ThrusterManager.cs @@ -47,10 +47,18 @@ namespace QSB.Animation.Player.Thrusters var gameObject = controller.gameObject; var oldThruster = controller.GetValue("_thruster"); var oldLight = controller.GetValue("_light"); + var localPos = oldThruster switch + { + Thruster.Up_RightThruster or Thruster.Up_LeftThruster => new Vector3(0, 0, 3), + Thruster.Down_RightThruster or Thruster.Down_LeftThruster => new Vector3(0, 0, 7), + _ => new Vector3(0, 0, 5), + }; + oldLight.transform.localPosition = localPos; + var oldAnimCurve = controller.GetValue("_scaleByThrust"); var oldScaleSpring = controller.GetValue("_scaleSpring"); var oldScalar = controller.GetValue("_belowMaxThrustScalar"); - var oldBase = controller.GetValue("_baseLightRadius"); + var oldBase = oldLight.range; Object.Destroy(controller); var newObj = gameObject.AddComponent(); newObj.InitFromOld(oldThruster, oldLight, oldAnimCurve, oldScaleSpring, oldScalar, oldBase, player); diff --git a/QSB/AssetBundles/conversation b/QSB/AssetBundles/conversation new file mode 100644 index 00000000..dc830635 Binary files /dev/null and b/QSB/AssetBundles/conversation differ diff --git a/AssetBundles/conversation.manifest b/QSB/AssetBundles/conversation.manifest similarity index 75% rename from AssetBundles/conversation.manifest rename to QSB/AssetBundles/conversation.manifest index 40c3a960..5f486847 100644 --- a/AssetBundles/conversation.manifest +++ b/QSB/AssetBundles/conversation.manifest @@ -1,12 +1,12 @@ ManifestFileVersion: 0 -CRC: 3328595786 +CRC: 2681871399 Hashes: AssetFileHash: serializedVersion: 2 - Hash: b1b55f9f86f72ed72608b36f0729af6d + Hash: d9191ca383ce2fbef699ba7106af389e TypeTreeHash: serializedVersion: 2 - Hash: 50a27bfc3e679077929938a6fa57f4db + Hash: a0ed95779b7375b06978e51f19fbfba7 HashAppended: 0 ClassTypes: - Class: 1 @@ -25,6 +25,10 @@ ClassTypes: Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} - Class: 114 Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3} +- Class: 114 + Script: {fileID: 1015169618, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: 602583937, guid: 27687deae413b90448366870cb0de502, type: 3} - Class: 115 Script: {instanceID: 0} - Class: 128 @@ -39,6 +43,6 @@ ClassTypes: Script: {instanceID: 0} SerializeReferenceClassIdentifiers: [] Assets: -- Assets/DialogueBubble.prefab +- Assets/Prefabs/DialogueBubble.prefab - Assets/GameAssets/Texture2D/UI_DialogueBox_d.png Dependencies: [] diff --git a/QSB/AssetBundles/debug b/QSB/AssetBundles/debug new file mode 100644 index 00000000..77921aed Binary files /dev/null and b/QSB/AssetBundles/debug differ diff --git a/QSB/AssetBundles/debug.manifest b/QSB/AssetBundles/debug.manifest new file mode 100644 index 00000000..dafb9acb --- /dev/null +++ b/QSB/AssetBundles/debug.manifest @@ -0,0 +1,32 @@ +ManifestFileVersion: 0 +CRC: 1531115438 +Hashes: + AssetFileHash: + serializedVersion: 2 + Hash: 289361968514e20b1d351d2d2fda5b6e + TypeTreeHash: + serializedVersion: 2 + Hash: ae2cf77de671e115b4e55d2b65767202 +HashAppended: 0 +ClassTypes: +- Class: 1 + Script: {instanceID: 0} +- Class: 4 + Script: {instanceID: 0} +- Class: 21 + Script: {instanceID: 0} +- Class: 23 + Script: {instanceID: 0} +- Class: 33 + Script: {instanceID: 0} +- Class: 43 + Script: {instanceID: 0} +- Class: 48 + Script: {instanceID: 0} +SerializeReferenceClassIdentifiers: [] +Assets: +- Assets/Prefabs/Cube.prefab +- Assets/Prefabs/Capsule.prefab +- Assets/Materials/DebugVis.mat +- Assets/Prefabs/Sphere.prefab +Dependencies: [] diff --git a/QSB/AssetBundles/instruments b/QSB/AssetBundles/instruments new file mode 100644 index 00000000..14517dd5 Binary files /dev/null and b/QSB/AssetBundles/instruments differ diff --git a/QSB/AssetBundles/instruments.manifest b/QSB/AssetBundles/instruments.manifest new file mode 100644 index 00000000..10973aa7 --- /dev/null +++ b/QSB/AssetBundles/instruments.manifest @@ -0,0 +1,68 @@ +ManifestFileVersion: 0 +CRC: 443713126 +Hashes: + AssetFileHash: + serializedVersion: 2 + Hash: 7d0ca7d72c1b77d3f455afb9deb14138 + TypeTreeHash: + serializedVersion: 2 + Hash: a1e72967751de663a1cbd29bd1e98be5 +HashAppended: 0 +ClassTypes: +- Class: 21 + Script: {instanceID: 0} +- Class: 28 + Script: {instanceID: 0} +- Class: 43 + Script: {instanceID: 0} +- Class: 48 + Script: {instanceID: 0} +- Class: 74 + Script: {instanceID: 0} +- Class: 90 + Script: {instanceID: 0} +- Class: 91 + Script: {instanceID: 0} +SerializeReferenceClassIdentifiers: [] +Assets: +- Assets/GameAssets/Texture2D/Traveller_HEA_Chert_ao.png +- Assets/GameAssets/AnimationClip/Riebeck_Playing.anim +- Assets/GameAssets/Avatar/Traveller_HEA_Chert_ANIM_Chatter_ChipperAvatar.asset +- Assets/GameAssets/AnimationClip/Chert_Drum_Panicked.anim +- Assets/GameAssets/Material/Traveller_HEA_Riebeck_mat.mat +- Assets/GameAssets/AnimatorController/Traveller_Chert.controller +- Assets/GameAssets/AnimationClip/Chert_Chatter_Chipper.anim +- Assets/GameAssets/AnimationClip/Chert_Drum_Chipper.anim +- Assets/GameAssets/Mesh/NewDrum_polySurface2.asset +- Assets/GameAssets/AnimationClip/Playing_banjo.anim +- Assets/GameAssets/Texture2D/Traveller_HEA_Riebeck_n.png +- Assets/GameAssets/Avatar/Traveller_HEA_Riebeck_ANIM_TalkingAvatar.asset +- Assets/GameAssets/Texture2D/Structure_HEA_VillageCabin_n.png +- Assets/GameAssets/AnimationClip/Chert_Chatter_Nervous.anim +- Assets/GameAssets/Mesh/Chert_DrumStick_Geo1.asset +- Assets/GameAssets/Material/Structure_HEA_VillageMetal_mat.mat +- Assets/GameAssets/Texture2D/Structure_HEA_VillageCabin_d.png +- Assets/GameAssets/Material/Structure_HEA_VillageCabin_mat.mat +- Assets/GameAssets/Texture2D/Traveller_HEA_Chert_d.png +- Assets/GameAssets/Texture2D/Traveller_HEA_Riebeck_Banjo_n.png +- Assets/GameAssets/AnimationClip/Playing_to_idle.anim +- Assets/GameAssets/Texture2D/Traveller_HEA_Chert_n.png +- Assets/GameAssets/Texture2D/Traveller_HEA_Riebeck_s.png +- Assets/GameAssets/AnimationClip/Chert_Chatter_Panicked.anim +- Assets/GameAssets/Material/Traveller_HEA_Riebeck_Banjo_mat.mat +- Assets/GameAssets/AnimationClip/Chert_Dream.anim +- Assets/GameAssets/AnimationClip/Riebeck_Talking.anim +- Assets/GameAssets/Texture2D/Traveller_HEA_Riebeck_Banjo_d.png +- Assets/GameAssets/AnimationClip/Riebeck_DreamIdle.anim +- Assets/GameAssets/Texture2D/Traveller_HEA_Riebeck_Banjo_ao.png +- Assets/GameAssets/Texture2D/Traveller_HEA_Chert_s.png +- Assets/GameAssets/Texture2D/Structure_HEA_VillageMetal_n.png +- Assets/GameAssets/Texture2D/Traveller_HEA_Riebeck_d.png +- Assets/GameAssets/AnimatorController/Traveller_Riebeck.controller +- Assets/GameAssets/Texture2D/Structure_HEA_VillageMetal_s.png +- Assets/GameAssets/Texture2D/Traveller_HEA_Riebeck_ao.png +- Assets/GameAssets/Texture2D/Structure_HEA_VillageMetal_d.png +- Assets/GameAssets/Texture2D/Traveller_HEA_Riebeck_Banjo_s.png +- Assets/GameAssets/Material/Traveller_HEA_Chert_mat.mat +- Assets/GameAssets/Texture2D/Structure_HEA_VillageCabin_s.png +Dependencies: [] diff --git a/QSB/AssetBundles/network b/QSB/AssetBundles/network new file mode 100644 index 00000000..8de1b060 Binary files /dev/null and b/QSB/AssetBundles/network differ diff --git a/QSB/AssetBundles/network.manifest b/QSB/AssetBundles/network.manifest new file mode 100644 index 00000000..2b01cb6a --- /dev/null +++ b/QSB/AssetBundles/network.manifest @@ -0,0 +1,55 @@ +ManifestFileVersion: 0 +CRC: 1923832523 +Hashes: + AssetFileHash: + serializedVersion: 2 + Hash: 4fc717bd6085672c7fc1dafa5359e292 + TypeTreeHash: + serializedVersion: 2 + Hash: 9036f53e57d0e71c74f56622ad045de9 +HashAppended: 0 +ClassTypes: +- Class: 1 + Script: {instanceID: 0} +- Class: 4 + Script: {instanceID: 0} +- Class: 114 + Script: {fileID: -1208705890, guid: 8929207a0d76fd54a8a2a820c652720f, type: 3} +- Class: 114 + Script: {fileID: 1142416158, guid: 8929207a0d76fd54a8a2a820c652720f, type: 3} +- Class: 114 + Script: {fileID: 519208029, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: -790547616, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: 916105004, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: -1309757293, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: 78926581, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: -1381557116, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: -1937550126, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: -749020886, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: -2281650, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: 2036222940, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: -1164351254, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: 806682216, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 114 + Script: {fileID: 677635994, guid: 27687deae413b90448366870cb0de502, type: 3} +- Class: 115 + Script: {instanceID: 0} +SerializeReferenceClassIdentifiers: [] +Assets: +- Assets/Prefabs/NetworkProbe.prefab +- Assets/Prefabs/NETWORK_Player_Body.prefab +- Assets/Prefabs/NetworkOrb.prefab +- Assets/Prefabs/NetworkAngler.prefab +- Assets/Prefabs/NetworkShip.prefab +Dependencies: [] diff --git a/QSB/CampfireSync/Events/CampfireStateEvent.cs b/QSB/CampfireSync/Events/CampfireStateEvent.cs index e0bc3df8..1bfb13fa 100644 --- a/QSB/CampfireSync/Events/CampfireStateEvent.cs +++ b/QSB/CampfireSync/Events/CampfireStateEvent.cs @@ -14,7 +14,7 @@ namespace QSB.CampfireSync.Events private void Handler(int objId, Campfire.State state) => SendEvent(CreateMessage(objId, state)); - private EnumWorldObjectMessage CreateMessage(int objId, Campfire.State state) => new EnumWorldObjectMessage + private EnumWorldObjectMessage CreateMessage(int objId, Campfire.State state) => new() { AboutId = LocalPlayerId, ObjectId = objId, diff --git a/QSB/CampfireSync/Patches/CampfirePatches.cs b/QSB/CampfireSync/Patches/CampfirePatches.cs index 5dc7f0e0..3a0c8bc7 100644 --- a/QSB/CampfireSync/Patches/CampfirePatches.cs +++ b/QSB/CampfireSync/Patches/CampfirePatches.cs @@ -15,7 +15,7 @@ namespace QSB.CampfireSync.Patches [HarmonyPatch(typeof(Campfire), nameof(Campfire.OnPressInteract))] public static bool LightCampfireEvent(Campfire __instance) { - var qsbCampfire = QSBWorldSync.GetWorldFromUnity(__instance); + var qsbCampfire = QSBWorldSync.GetWorldFromUnity(__instance); if (__instance._state == Campfire.State.LIT) { qsbCampfire.StartRoasting(); diff --git a/QSB/ClientServerStateSync/ClientStateManager.cs b/QSB/ClientServerStateSync/ClientStateManager.cs index 2e1d1d11..c9b88e7e 100644 --- a/QSB/ClientServerStateSync/ClientStateManager.cs +++ b/QSB/ClientServerStateSync/ClientStateManager.cs @@ -29,7 +29,6 @@ namespace QSB.ClientServerStateSync return; } - DebugLog.DebugWrite($"CHANGE CLIENT STATE FROM {QSBPlayerManager.LocalPlayer.State} to {newState}"); QSBPlayerManager.LocalPlayer.State = newState; OnChangeState?.Invoke(newState); } @@ -46,31 +45,30 @@ namespace QSB.ClientServerStateSync switch (newScene) { case OWScene.TitleScreen: - DebugLog.DebugWrite($"SERVER LOAD TITLESCREEN"); newState = ClientState.InTitleScreen; break; case OWScene.Credits_Fast: - DebugLog.DebugWrite($"SERVER LOAD SHORT CREDITS"); newState = ClientState.WatchingShortCredits; break; case OWScene.Credits_Final: case OWScene.PostCreditsScene: - DebugLog.DebugWrite($"SERVER LOAD LONG CREDITS"); newState = ClientState.WatchingLongCredits; break; case OWScene.SolarSystem: if (oldScene == OWScene.SolarSystem) { // reloading scene - DebugLog.DebugWrite($"SERVER RELOAD SOLARSYSTEM"); newState = ClientState.WaitingForOthersToReadyInSolarSystem; } else { // loading in from title screen - DebugLog.DebugWrite($"SERVER LOAD SOLARSYSTEM"); newState = ClientState.AliveInSolarSystem; } + + break; + case OWScene.EyeOfTheUniverse: + newState = ClientState.AliveInEye; break; default: newState = ClientState.NotLoaded; @@ -82,22 +80,18 @@ namespace QSB.ClientServerStateSync switch (newScene) { case OWScene.TitleScreen: - DebugLog.DebugWrite($"CLIENT LOAD TITLESCREEN"); newState = ClientState.InTitleScreen; break; case OWScene.Credits_Fast: - DebugLog.DebugWrite($"CLIENT LOAD SHORT CREDITS"); newState = ClientState.WatchingShortCredits; break; case OWScene.Credits_Final: case OWScene.PostCreditsScene: - DebugLog.DebugWrite($"CLIENT LOAD LONG CREDITS"); newState = ClientState.WatchingLongCredits; break; case OWScene.SolarSystem: if (serverState == ServerState.WaitingForAllPlayersToDie) { - DebugLog.DebugWrite($"SEVER IN DEATH PHASE - WAIT"); newState = ClientState.WaitingForOthersToReadyInSolarSystem; break; } @@ -105,13 +99,11 @@ namespace QSB.ClientServerStateSync if (oldScene == OWScene.SolarSystem) { // reloading scene - DebugLog.DebugWrite($"CLIENT RELOAD SOLARSYSTEM"); newState = ClientState.WaitingForOthersToReadyInSolarSystem; } else { // loading in from title screen - DebugLog.DebugWrite($"CLIENT LOAD SOLARSYSTEM"); if (serverState == ServerState.WaitingForAllPlayersToReady) { newState = ClientState.WaitingForOthersToReadyInSolarSystem; @@ -121,6 +113,10 @@ namespace QSB.ClientServerStateSync newState = ClientState.AliveInSolarSystem; } } + + break; + case OWScene.EyeOfTheUniverse: + newState = ClientState.WaitingForOthersToReadyInSolarSystem; break; default: newState = ClientState.NotLoaded; @@ -165,32 +161,17 @@ namespace QSB.ClientServerStateSync private ClientState ForceGetCurrentState() { - DebugLog.DebugWrite($"ForceGetCurrentState"); var currentScene = LoadManager.GetCurrentScene(); - var lastScene = LoadManager.GetPreviousScene(); - switch (currentScene) + return currentScene switch { - case OWScene.TitleScreen: - DebugLog.DebugWrite($"- TitleScreen"); - return ClientState.InTitleScreen; - case OWScene.Credits_Fast: - DebugLog.DebugWrite($"- Short Credits"); - return ClientState.WatchingShortCredits; - case OWScene.Credits_Final: - case OWScene.PostCreditsScene: - DebugLog.DebugWrite($"- Long Credits"); - return ClientState.WatchingLongCredits; - case OWScene.SolarSystem: - DebugLog.DebugWrite($"- SolarSystem"); - return ClientState.AliveInSolarSystem; - case OWScene.EyeOfTheUniverse: - DebugLog.DebugWrite($"- Eye"); - return ClientState.AliveInEye; - default: - DebugLog.DebugWrite($"- Not Loaded"); - return ClientState.NotLoaded; - } + OWScene.TitleScreen => ClientState.InTitleScreen, + OWScene.Credits_Fast => ClientState.WatchingShortCredits, + OWScene.Credits_Final or OWScene.PostCreditsScene => ClientState.WatchingLongCredits, + OWScene.SolarSystem => ClientState.AliveInSolarSystem, + OWScene.EyeOfTheUniverse => ClientState.AliveInEye, + _ => ClientState.NotLoaded, + }; } } } diff --git a/QSB/ClientServerStateSync/Events/ClientStateEvent.cs b/QSB/ClientServerStateSync/Events/ClientStateEvent.cs index b664a3e1..aa3b8126 100644 --- a/QSB/ClientServerStateSync/Events/ClientStateEvent.cs +++ b/QSB/ClientServerStateSync/Events/ClientStateEvent.cs @@ -17,7 +17,7 @@ namespace QSB.ClientServerStateSync.Events private void Handler(ClientState state) => SendEvent(CreateMessage(state)); - private EnumMessage CreateMessage(ClientState state) => new EnumMessage + private EnumMessage CreateMessage(ClientState state) => new() { AboutId = LocalPlayerId, EnumValue = state diff --git a/QSB/ClientServerStateSync/Events/ServerStateEvent.cs b/QSB/ClientServerStateSync/Events/ServerStateEvent.cs index c0cabdef..170ea063 100644 --- a/QSB/ClientServerStateSync/Events/ServerStateEvent.cs +++ b/QSB/ClientServerStateSync/Events/ServerStateEvent.cs @@ -15,7 +15,7 @@ namespace QSB.ClientServerStateSync.Events private void Handler(ServerState state) => SendEvent(CreateMessage(state)); - private EnumMessage CreateMessage(ServerState state) => new EnumMessage + private EnumMessage CreateMessage(ServerState state) => new() { AboutId = LocalPlayerId, EnumValue = state diff --git a/QSB/ClientServerStateSync/ServerStateManager.cs b/QSB/ClientServerStateSync/ServerStateManager.cs index 42e93e1b..173614c3 100644 --- a/QSB/ClientServerStateSync/ServerStateManager.cs +++ b/QSB/ClientServerStateSync/ServerStateManager.cs @@ -54,17 +54,14 @@ namespace QSB.ClientServerStateSync case OWScene.Credits_Fast: case OWScene.Credits_Final: case OWScene.PostCreditsScene: - DebugLog.DebugWrite($"SERVER LOAD CREDITS"); QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.Credits); break; case OWScene.TitleScreen: - DebugLog.DebugWrite($"SERVER LOAD TITLE SCREEN"); QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.NotLoaded); break; case OWScene.SolarSystem: - DebugLog.DebugWrite($"SERVER LOAD SOLARSYSTEM"); if (oldScene == OWScene.SolarSystem) { QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.WaitingForAllPlayersToReady); @@ -77,7 +74,6 @@ namespace QSB.ClientServerStateSync break; case OWScene.EyeOfTheUniverse: - DebugLog.DebugWrite($"EYE"); QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.WaitingForAllPlayersToReady); break; @@ -98,21 +94,15 @@ namespace QSB.ClientServerStateSync private ServerState ForceGetCurrentState() { - DebugLog.DebugWrite($"ForceGetCurrentState"); - var currentScene = LoadManager.GetCurrentScene(); - var lastScene = LoadManager.GetPreviousScene(); switch (currentScene) { case OWScene.SolarSystem: - DebugLog.DebugWrite($"- SolarSystem"); return ServerState.InSolarSystem; case OWScene.EyeOfTheUniverse: - DebugLog.DebugWrite($"- Eye"); return ServerState.InEye; default: - DebugLog.DebugWrite($"- Not Loaded"); return ServerState.NotLoaded; } } @@ -132,12 +122,27 @@ namespace QSB.ClientServerStateSync if (_currentState == ServerState.WaitingForAllPlayersToReady) { - if (QSBPlayerManager.PlayerList.All(x => x.State == ClientState.WaitingForOthersToReadyInSolarSystem) - || QSBPlayerManager.PlayerList.All(x => x.State == ClientState.AliveInSolarSystem)) + if (QSBPlayerManager.PlayerList.All(x + => x.State is ClientState.WaitingForOthersToReadyInSolarSystem + or ClientState.AliveInSolarSystem + or ClientState.AliveInEye)) { DebugLog.DebugWrite($"All ready!!"); QSBEventManager.FireEvent(EventNames.QSBStartLoop); - QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.InSolarSystem); + if (QSBSceneManager.CurrentScene == OWScene.SolarSystem) + { + QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.InSolarSystem); + } + else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) + { + QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.InEye); + } + else + { + DebugLog.ToConsole($"Error - All players were ready in non-universe scene!?", OWML.Common.MessageType.Error); + QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.NotLoaded); + } + _blockNextCheck = true; } } diff --git a/QSB/ConversationSync/CameraFacingBillboard.cs b/QSB/ConversationSync/CameraFacingBillboard.cs index 74b0630c..55e3ce0d 100644 --- a/QSB/ConversationSync/CameraFacingBillboard.cs +++ b/QSB/ConversationSync/CameraFacingBillboard.cs @@ -22,7 +22,7 @@ public class CameraFacingBillboard : MonoBehaviour UpdateRotation(); } - void LateUpdate() + private void LateUpdate() => UpdateRotation(); private void UpdateRotation() diff --git a/QSB/ConversationSync/ConversationManager.cs b/QSB/ConversationSync/ConversationManager.cs index ba18f6c3..2304d018 100644 --- a/QSB/ConversationSync/ConversationManager.cs +++ b/QSB/ConversationSync/ConversationManager.cs @@ -21,7 +21,7 @@ namespace QSB.ConversationSync { Instance = this; - _boxPrefab = QSBCore.ConversationAssetBundle.LoadAsset("assets/dialoguebubble.prefab"); + _boxPrefab = QSBCore.ConversationAssetBundle.LoadAsset("assets/Prefabs/dialoguebubble.prefab"); var font = (Font)Resources.Load(@"fonts\english - latin\HVD Fonts - BrandonGrotesque-Bold_Dynamic"); if (font == null) @@ -118,9 +118,7 @@ namespace QSB.ConversationSync newBox.transform.SetParent(parent); newBox.transform.localPosition = new Vector3(0, vertOffset, 0); newBox.transform.rotation = parent.rotation; - newBox.AddComponent(); newBox.GetComponent().text = text; - newBox.AddComponent(); newBox.SetActive(true); return newBox; } diff --git a/QSB/ConversationSync/Events/ConversationEvent.cs b/QSB/ConversationSync/Events/ConversationEvent.cs index d60a1d76..c9073432 100644 --- a/QSB/ConversationSync/Events/ConversationEvent.cs +++ b/QSB/ConversationSync/Events/ConversationEvent.cs @@ -14,7 +14,7 @@ namespace QSB.ConversationSync.Events private void Handler(uint id, string message, ConversationType type) => SendEvent(CreateMessage(id, message, type)); - private ConversationMessage CreateMessage(uint id, string message, ConversationType type) => new ConversationMessage + private ConversationMessage CreateMessage(uint id, string message, ConversationType type) => new() { AboutId = LocalPlayerId, ObjectId = (int)id, diff --git a/QSB/ConversationSync/Events/ConversationStartEndEvent.cs b/QSB/ConversationSync/Events/ConversationStartEndEvent.cs index 83fbc3c1..32dc8178 100644 --- a/QSB/ConversationSync/Events/ConversationStartEndEvent.cs +++ b/QSB/ConversationSync/Events/ConversationStartEndEvent.cs @@ -15,7 +15,7 @@ namespace QSB.ConversationSync.Events private void Handler(int objId, uint playerId, bool state) => SendEvent(CreateMessage(objId, playerId, state)); - private ConversationStartEndMessage CreateMessage(int objId, uint playerId, bool state) => new ConversationStartEndMessage + private ConversationStartEndMessage CreateMessage(int objId, uint playerId, bool state) => new() { AboutId = LocalPlayerId, TreeId = objId, diff --git a/QSB/ConversationSync/Events/DialogueConditionEvent.cs b/QSB/ConversationSync/Events/DialogueConditionEvent.cs index c1380ff4..c97e3cf5 100644 --- a/QSB/ConversationSync/Events/DialogueConditionEvent.cs +++ b/QSB/ConversationSync/Events/DialogueConditionEvent.cs @@ -12,7 +12,7 @@ namespace QSB.ConversationSync.Events private void Handler(string name, bool state) => SendEvent(CreateMessage(name, state)); - private DialogueConditionMessage CreateMessage(string name, bool state) => new DialogueConditionMessage + private DialogueConditionMessage CreateMessage(string name, bool state) => new() { AboutId = LocalPlayerId, ConditionName = name, diff --git a/QSB/DeathSync/Events/EndLoopEvent.cs b/QSB/DeathSync/Events/EndLoopEvent.cs index 0208c4ea..17af3ffb 100644 --- a/QSB/DeathSync/Events/EndLoopEvent.cs +++ b/QSB/DeathSync/Events/EndLoopEvent.cs @@ -1,6 +1,7 @@ using QSB.ClientServerStateSync; using QSB.Events; using QSB.Messaging; +using QSB.Patches; using QSB.Utility; namespace QSB.DeathSync.Events @@ -14,7 +15,7 @@ namespace QSB.DeathSync.Events private void Handler(EndLoopReason type) => SendEvent(CreateMessage(type)); - private EnumMessage CreateMessage(EndLoopReason type) => new EnumMessage + private EnumMessage CreateMessage(EndLoopReason type) => new() { AboutId = LocalPlayerId, EnumValue = type @@ -29,6 +30,8 @@ namespace QSB.DeathSync.Events switch (message.EnumValue) { case EndLoopReason.AllPlayersDead: + QSBPatchManager.DoUnpatchType(QSBPatchTypes.RespawnTime); + Locator.GetDeathManager().KillPlayer(DeathType.TimeLoop); if (QSBCore.IsHost) { diff --git a/QSB/DeathSync/Events/PlayerDeathEvent.cs b/QSB/DeathSync/Events/PlayerDeathEvent.cs index 00234ade..0cf756c4 100644 --- a/QSB/DeathSync/Events/PlayerDeathEvent.cs +++ b/QSB/DeathSync/Events/PlayerDeathEvent.cs @@ -1,6 +1,7 @@ using QSB.ClientServerStateSync; using QSB.Events; using QSB.Player; +using QSB.RespawnSync; using QSB.Utility; namespace QSB.DeathSync.Events @@ -14,7 +15,7 @@ namespace QSB.DeathSync.Events private void Handler(DeathType type) => SendEvent(CreateMessage(type)); - private PlayerDeathMessage CreateMessage(DeathType type) => new PlayerDeathMessage + private PlayerDeathMessage CreateMessage(DeathType type) => new() { AboutId = LocalPlayerId, EnumValue = type, diff --git a/QSB/DeathSync/Events/StartLoopEvent.cs b/QSB/DeathSync/Events/StartLoopEvent.cs index 243f2e8a..4911070c 100644 --- a/QSB/DeathSync/Events/StartLoopEvent.cs +++ b/QSB/DeathSync/Events/StartLoopEvent.cs @@ -14,7 +14,7 @@ namespace QSB.DeathSync.Events private void Handler() => SendEvent(CreateMessage()); - private PlayerMessage CreateMessage() => new PlayerMessage + private PlayerMessage CreateMessage() => new() { AboutId = LocalPlayerId }; @@ -25,7 +25,19 @@ namespace QSB.DeathSync.Events public override void OnReceiveRemote(bool server, PlayerMessage message) { DebugLog.DebugWrite($" ~~~ LOOP START ~~~"); - QSBEventManager.FireEvent(EventNames.QSBClientState, ClientState.AliveInSolarSystem); + if (QSBSceneManager.CurrentScene == OWScene.SolarSystem) + { + QSBEventManager.FireEvent(EventNames.QSBClientState, ClientState.AliveInSolarSystem); + } + else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) + { + QSBEventManager.FireEvent(EventNames.QSBClientState, ClientState.AliveInEye); + } + else + { + DebugLog.ToConsole($"Error - Got StartLoop event when not in universe!", OWML.Common.MessageType.Error); + QSBEventManager.FireEvent(EventNames.QSBClientState, ClientState.NotLoaded); + } } } } diff --git a/QSB/DeathSync/Necronomicon.cs b/QSB/DeathSync/Necronomicon.cs index 163d878a..3cb96b36 100644 --- a/QSB/DeathSync/Necronomicon.cs +++ b/QSB/DeathSync/Necronomicon.cs @@ -5,14 +5,19 @@ namespace QSB.DeathSync { public static class Necronomicon { - private static readonly Dictionary Darkhold = new Dictionary + private static readonly Dictionary Darkhold = new() { - { DeathType.Default, new[] // Running out of health + { + DeathType.Default, + new[] // Running out of health { "{0} died", "{0} was killed" - } }, - { DeathType.Impact, new[] // Hitting the ground/wall/object + } + }, + { + DeathType.Impact, + new[] // Hitting the ground/wall/object { "{0} forgot to use retro-rockets", "{0} bonked into the ground too hard", @@ -22,8 +27,11 @@ namespace QSB.DeathSync "{0} was killed", "{0} died due to impact", "{0} impacted the ground too hard" - } }, - { DeathType.Asphyxiation, new[] // Running out of oxygen + } + }, + { + DeathType.Asphyxiation, + new[] // Running out of oxygen { "{0} forgot to breathe", "{0} asphyxiated", @@ -33,14 +41,20 @@ namespace QSB.DeathSync "{0} ran out of air", "{0} ran out of oxygen", "{0} didn't need air anyway" - } }, - { DeathType.Energy, new[] // Electricity, sun, etc. + } + }, + { + DeathType.Energy, + new[] // Electricity, sun, etc. { "{0} was cooked", "{0} died", "{0} was killed" - } }, - { DeathType.Supernova, new[] // Supernova + } + }, + { + DeathType.Supernova, + new[] // Supernova { "{0} ran out of time", "{0} burnt up", @@ -52,8 +66,11 @@ namespace QSB.DeathSync "{0} became cosmic marshmallow", "{0} photosynthesized too much", "{0} died due to the supernova" - } }, - { DeathType.Digestion, new[] // Anglerfish + } + }, + { + DeathType.Digestion, + new[] // Anglerfish { "{0} was eaten", "{0} found a fish", @@ -61,14 +78,21 @@ namespace QSB.DeathSync "{0} messed with the wrong fish", "{0} was digested", "{0} died due to digestion" - } }, - { DeathType.BigBang, new[] // End of the game + } + }, { + DeathType.BigBang, + new[] // End of the game + { + // TODO : maybe don't show these? "{0} sacrificed themself for the universe", "{0} knows the true meaning of sacrifice", "{0} won at the cost of their life" - } }, - { DeathType.Crushed, new[] // Crushed in sand + } + }, + { + DeathType.Crushed, + new[] // Crushed in sand { "{0} went through the tunnel too slow", "{0} didn't make it out in time", @@ -78,18 +102,20 @@ namespace QSB.DeathSync "{0} went swimming in the sand", "{0} underestimated the danger of sand", "{0} died due to being crushed" - } }, - { DeathType.Meditation, new[] // Meditation + } + }, { - "{0} broke QSB. this is a bug, you should never see this" - } }, - { DeathType.TimeLoop, new[] // Escaping the supernova + DeathType.TimeLoop, + new[] // Escaping the supernova { "{0} ran out of time", "{0} lost track of time", "{0} watched the sun go kaboom" - } }, - { DeathType.Lava, new[] // Lava + } + }, + { + DeathType.Lava, + new[] // Lava { "{0} died in lava", "{0} was melted", @@ -99,17 +125,47 @@ namespace QSB.DeathSync "{0} became one with the glowing gooey rock", "{0} died due to lava", "{0} got burnt in the lava" - } }, - { DeathType.BlackHole, new[] // ATP core black hole + } + }, + { + DeathType.BlackHole, + new[] // ATP core black hole { "{0} should visit the Ash Twin Project again", "{0} waited inside the Ash Twin Project", "{0} chased their memories" - } } + } + }, + { + DeathType.DreamExplosion, + new[] // using the prototype + { + "{0} exploded", + "{0} was an early adopter", + "{0} went kaboom", + "{0} was fried", + "{0} died due to explosion", + "{0} used the wrong artifact" + } + }, + { + DeathType.CrushedByElevator, + new[] // elevator-induced pancakeness + { + "{0} was crushed", + "{0} was squished", + "{0} was crushed by an elevator", + "{0} stood under an elevator", + "{0} became a flat-hearther", + "{0} was squished by an elevator" + } + }, }; - public static string GetPhrase(DeathType deathType, int index) => - Darkhold[deathType][index]; + public static string GetPhrase(DeathType deathType, int index) + => !Darkhold.ContainsKey(deathType) + ? Darkhold[DeathType.Default][index] + : Darkhold[deathType][index]; public static int GetRandomIndex(DeathType deathType) => new Random().Next(0, Darkhold[deathType].Length); diff --git a/QSB/DeathSync/Patches/DeathPatches.cs b/QSB/DeathSync/Patches/DeathPatches.cs index 28c9ddfe..9a768393 100644 --- a/QSB/DeathSync/Patches/DeathPatches.cs +++ b/QSB/DeathSync/Patches/DeathPatches.cs @@ -209,10 +209,7 @@ namespace QSB.DeathSync.Patches [HarmonyPostfix] [HarmonyPatch(typeof(DeathManager), nameof(DeathManager.KillPlayer))] - public static void DeathManager_KillPlayer_Postfix(DeathType deathType) - { - QSBEventManager.FireEvent(EventNames.QSBPlayerDeath, deathType); - } + public static void DeathManager_KillPlayer_Postfix(DeathType deathType) => QSBEventManager.FireEvent(EventNames.QSBPlayerDeath, deathType); [HarmonyPostfix] [HarmonyPatch(typeof(ShipDamageController), nameof(ShipDamageController.Awake))] diff --git a/QSB/DeathSync/Patches/RespawnPatches.cs b/QSB/DeathSync/Patches/RespawnPatches.cs deleted file mode 100644 index 00bddc16..00000000 --- a/QSB/DeathSync/Patches/RespawnPatches.cs +++ /dev/null @@ -1,166 +0,0 @@ -using HarmonyLib; -using OWML.Utils; -using QSB.Patches; - -namespace QSB.DeathSync.Patches -{ - [HarmonyPatch] - internal class RespawnPatches : QSBPatch - { - public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - - [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerRecoveryPoint), nameof(PlayerRecoveryPoint.OnGainFocus))] - public static bool PlayerRecoveryPoint_OnGainFocus( - PlayerResources ____playerResources, - bool ____refuelsPlayer, - bool ____healsPlayer, - SingleInteractionVolume ____interactVolume - ) - { - if (____playerResources == null) - { - ____playerResources = Locator.GetPlayerTransform().GetComponent(); - } - - var isAtFullHealth = ____playerResources.GetHealthFraction() == 1f; - var isAtFullFuel = ____playerResources.GetFuelFraction() == 1f; - var canBeRefueled = false; - var canBeHealed = false; - - if (!isAtFullFuel && ____refuelsPlayer) - { - canBeRefueled = true; - } - - if (!isAtFullHealth && ____healsPlayer) - { - canBeHealed = true; - } - - var showRespawnPrompt = false; - - var uitextType = UITextType.None; - if (canBeHealed && canBeRefueled) - { - // Heal and refuel - uitextType = UITextType.RefillPrompt_0; - - ____interactVolume.SetKeyCommandVisible(true); - } - else if (canBeHealed) - { - // Heal - uitextType = UITextType.RefillPrompt_2; - - ____interactVolume.SetKeyCommandVisible(true); - } - else if (canBeRefueled) - { - // Refuel - uitextType = UITextType.RefillPrompt_4; - ____interactVolume.SetKeyCommandVisible(true); - } - else if (RespawnManager.Instance.RespawnNeeded) - { - showRespawnPrompt = true; - } - else if (____refuelsPlayer && ____healsPlayer) - { - // Fuel and health full - uitextType = UITextType.RefillPrompt_7; - ____interactVolume.SetKeyCommandVisible(false); - } - else if (____refuelsPlayer) - { - // Fuel full - uitextType = UITextType.RefillPrompt_8; - ____interactVolume.SetKeyCommandVisible(false); - } - else if (____healsPlayer) - { - // Health full - uitextType = UITextType.RefillPrompt_9; - ____interactVolume.SetKeyCommandVisible(false); - } - - if (showRespawnPrompt) - { - ____interactVolume.GetValue("_screenPrompt").SetText($" Respawn Player"); - ____interactVolume.GetValue("_noCommandIconPrompt").SetText("Respawn Player"); - } - - if (uitextType != UITextType.None) - { - ____interactVolume.ChangePrompt(uitextType); - } - - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerRecoveryPoint), nameof(PlayerRecoveryPoint.OnPressInteract))] - public static bool PlayerRecoveryPoint_OnPressInteract( - PlayerRecoveryPoint __instance, - PlayerResources ____playerResources, - ref bool ____recovering, - bool ____refuelsPlayer, - bool ____healsPlayer, - PlayerAudioController ____playerAudioController, - SingleInteractionVolume ____interactVolume - ) - { - var playerNeedsRefueling = ____playerResources.GetFuelFraction() != 1f; - var playerNeedsHealing = ____playerResources.GetHealthFraction() != 1f; - var canBeInteractedWith = false; - - if (playerNeedsRefueling && ____refuelsPlayer) - { - canBeInteractedWith = true; - } - - if (playerNeedsHealing && ____healsPlayer) - { - canBeInteractedWith = true; - } - - if (RespawnManager.Instance.RespawnNeeded) - { - canBeInteractedWith = true; - } - - if (canBeInteractedWith) - { - if (RespawnManager.Instance.RespawnNeeded && !playerNeedsRefueling && !playerNeedsHealing) - { - RespawnManager.Instance.RespawnSomePlayer(); - return false; - } - - ____playerResources.StartRefillResources(____refuelsPlayer, ____healsPlayer); - - if (____playerAudioController != null) - { - if (playerNeedsRefueling && ____refuelsPlayer) - { - ____playerAudioController.PlayRefuel(); - } - - if (playerNeedsHealing && ____healsPlayer) - { - ____playerAudioController.PlayMedkit(); - } - } - - ____recovering = true; - __instance.enabled = true; - } - else - { - ____interactVolume.ResetInteraction(); - } - - return false; - } - } -} diff --git a/QSB/DeathSync/RespawnOnDeath.cs b/QSB/DeathSync/RespawnOnDeath.cs index df5bc325..cc1ff8a5 100644 --- a/QSB/DeathSync/RespawnOnDeath.cs +++ b/QSB/DeathSync/RespawnOnDeath.cs @@ -3,7 +3,9 @@ using OWML.Utils; using QSB.Events; using QSB.Player; using QSB.Player.TransformSync; +using QSB.RespawnSync; using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; @@ -75,7 +77,7 @@ namespace QSB.DeathSync } else { - var allAstroobjects = Resources.FindObjectsOfTypeAll().Where(x => x.GetAstroObjectName() != AstroObject.Name.None && x.GetAstroObjectType() != AstroObject.Type.Satellite); + var allAstroobjects = QSBWorldSync.GetUnityObjects().Where(x => x.GetAstroObjectName() != AstroObject.Name.None && x.GetAstroObjectType() != AstroObject.Type.Satellite); var ordered = allAstroobjects.OrderBy(x => Vector3.SqrMagnitude(x.transform.position)); DeathClosestAstroObject = ordered.First().transform; } @@ -138,4 +140,4 @@ namespace QSB.DeathSync && spawnPoint.IsShipSpawn() == false); } } -} \ No newline at end of file +} diff --git a/QSB/EchoesOfTheEye/AirlockSync/AirlockManager.cs b/QSB/EchoesOfTheEye/AirlockSync/AirlockManager.cs new file mode 100644 index 00000000..a2fa5f5e --- /dev/null +++ b/QSB/EchoesOfTheEye/AirlockSync/AirlockManager.cs @@ -0,0 +1,10 @@ +using QSB.EchoesOfTheEye.AirlockSync.WorldObjects; +using QSB.WorldSync; + +namespace QSB.EchoesOfTheEye.AirlockSync +{ + internal class AirlockManager : WorldObjectManager + { + protected override void RebuildWorldObjects(OWScene scene) => QSBWorldSync.Init(); + } +} diff --git a/QSB/EchoesOfTheEye/AirlockSync/WorldObjects/QSBGhostAirlock.cs b/QSB/EchoesOfTheEye/AirlockSync/WorldObjects/QSBGhostAirlock.cs new file mode 100644 index 00000000..67b73576 --- /dev/null +++ b/QSB/EchoesOfTheEye/AirlockSync/WorldObjects/QSBGhostAirlock.cs @@ -0,0 +1,13 @@ +using QSB.WorldSync; + +namespace QSB.EchoesOfTheEye.AirlockSync.WorldObjects +{ + internal class QSBGhostAirlock : WorldObject + { + public override void Init(GhostAirlock airlock, int id) + { + ObjectId = id; + AttachedObject = airlock; + } + } +} diff --git a/QSB/EchoesOfTheEye/LightSensorSync/LightSensorManager.cs b/QSB/EchoesOfTheEye/LightSensorSync/LightSensorManager.cs new file mode 100644 index 00000000..0ffd4f8a --- /dev/null +++ b/QSB/EchoesOfTheEye/LightSensorSync/LightSensorManager.cs @@ -0,0 +1,10 @@ +using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects; +using QSB.WorldSync; + +namespace QSB.EchoesOfTheEye.LightSensorSync +{ + internal class LightSensorManager : WorldObjectManager + { + protected override void RebuildWorldObjects(OWScene scene) => QSBWorldSync.Init(); + } +} diff --git a/QSB/EchoesOfTheEye/LightSensorSync/Patches/LightSensorPatches.cs b/QSB/EchoesOfTheEye/LightSensorSync/Patches/LightSensorPatches.cs new file mode 100644 index 00000000..41ec66de --- /dev/null +++ b/QSB/EchoesOfTheEye/LightSensorSync/Patches/LightSensorPatches.cs @@ -0,0 +1,149 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Player; +using QSB.Tools.FlashlightTool; +using System.Linq; +using UnityEngine; + +namespace QSB.EchoesOfTheEye.LightSensorSync.Patches +{ + [HarmonyPatch] + internal class LightSensorPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(SingleLightSensor), nameof(SingleLightSensor.UpdateIllumination))] + public static bool UpdateIlluminationReplacement(SingleLightSensor __instance) + { + __instance._illuminated = false; + if (__instance._illuminatingDreamLanternList != null) + { + __instance._illuminatingDreamLanternList.Clear(); + } + + var vector = __instance.transform.TransformPoint(__instance._localSensorOffset); + var sensorWorldDir = Vector3.zero; + if (__instance._directionalSensor) + { + sensorWorldDir = __instance.transform.TransformDirection(__instance._localDirection).normalized; + } + + if (__instance._lightSources == null) + { + return false; + } + + for (var i = 0; i < __instance._lightSources.Count; i++) + { + var source = __instance._lightSources[i]; + + if ((__instance._lightSourceMask & source.GetLightSourceType()) == source.GetLightSourceType() + && source.CheckIlluminationAtPoint(vector, __instance._sensorRadius, __instance._maxDistance)) + { + var lightSourceType = source.GetLightSourceType(); + switch (lightSourceType) + { + case LightSourceType.UNDEFINED: + { + var owlight = source as OWLight2; + var occludableLight = owlight.GetLight().shadows != LightShadows.None + && owlight.GetLight().shadowStrength > 0.5f; + + if (owlight.CheckIlluminationAtPoint(vector, __instance._sensorRadius, __instance._maxDistance) + && !__instance.CheckOcclusion(owlight.transform.position, vector, sensorWorldDir, occludableLight)) + { + __instance._illuminated = true; + } + + break; + } + case LightSourceType.FLASHLIGHT: + { + if (source is Flashlight && (source as Flashlight) == Locator.GetFlashlight()) + { + var position = Locator.GetPlayerCamera().transform.position; + var to = __instance.transform.position - position; + if (Vector3.Angle(Locator.GetPlayerCamera().transform.forward, to) <= __instance._maxSpotHalfAngle + && !__instance.CheckOcclusion(position, vector, sensorWorldDir, true)) + { + __instance._illuminated = true; + } + } + else + { + var player = QSBPlayerManager.PlayerList.First(x => x.FlashLight == (QSBFlashlight)source); + + var position = player.Camera.transform.position; + var to = __instance.transform.position - position; + if (Vector3.Angle(player.Camera.transform.forward, to) <= __instance._maxSpotHalfAngle + && !__instance.CheckOcclusion(position, vector, sensorWorldDir, true)) + { + __instance._illuminated = true; + } + } + + break; + } + case LightSourceType.PROBE: + { + var probe = Locator.GetProbe(); + if (probe != null + && probe.IsLaunched() + && !probe.IsRetrieving() + && probe.CheckIlluminationAtPoint(vector, __instance._sensorRadius, __instance._maxDistance) + && !__instance.CheckOcclusion(probe.GetLightSourcePosition(), vector, sensorWorldDir, true)) + { + __instance._illuminated = true; + } + + break; + } + case LightSourceType.FLASHLIGHT | LightSourceType.PROBE: + case LightSourceType.FLASHLIGHT | LightSourceType.DREAM_LANTERN: + case LightSourceType.PROBE | LightSourceType.DREAM_LANTERN: + case LightSourceType.FLASHLIGHT | LightSourceType.PROBE | LightSourceType.DREAM_LANTERN: + break; + case LightSourceType.DREAM_LANTERN: + { + var dreamLanternController = __instance._lightSources[i] as DreamLanternController; + if (dreamLanternController.IsLit() + && dreamLanternController.IsFocused(__instance._lanternFocusThreshold) + && dreamLanternController.CheckIlluminationAtPoint(vector, __instance._sensorRadius, __instance._maxDistance) + && !__instance.CheckOcclusion(dreamLanternController.GetLightPosition(), vector, sensorWorldDir, true)) + { + __instance._illuminatingDreamLanternList.Add(dreamLanternController); + __instance._illuminated = true; + } + + break; + } + case LightSourceType.SIMPLE_LANTERN: + foreach (var owlight in __instance._lightSources[i].GetLights()) + { + var occludableLight = owlight.GetLight().shadows != LightShadows.None + && owlight.GetLight().shadowStrength > 0.5f; + var maxDistance = Mathf.Min(__instance._maxSimpleLanternDistance, __instance._maxDistance); + if (owlight.CheckIlluminationAtPoint(vector, __instance._sensorRadius, maxDistance) && !__instance.CheckOcclusion(owlight.transform.position, vector, sensorWorldDir, occludableLight)) + { + __instance._illuminated = true; + break; + } + } + + break; + default: + if (lightSourceType == LightSourceType.VOLUME_ONLY) + { + __instance._illuminated = true; + } + + break; + } + } + } + + return false; + } + } +} diff --git a/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBSingleLightSensor.cs b/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBSingleLightSensor.cs new file mode 100644 index 00000000..089e67d3 --- /dev/null +++ b/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBSingleLightSensor.cs @@ -0,0 +1,13 @@ +using QSB.WorldSync; + +namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects +{ + internal class QSBSingleLightSensor : WorldObject + { + public override void Init(SingleLightSensor sensor, int id) + { + ObjectId = id; + AttachedObject = sensor; + } + } +} diff --git a/QSB/ElevatorSync/Events/ElevatorEvent.cs b/QSB/ElevatorSync/Events/ElevatorEvent.cs index 5328676a..84f037e4 100644 --- a/QSB/ElevatorSync/Events/ElevatorEvent.cs +++ b/QSB/ElevatorSync/Events/ElevatorEvent.cs @@ -14,7 +14,7 @@ namespace QSB.ElevatorSync.Events private void Handler(int id, bool isGoingUp) => SendEvent(CreateMessage(id, isGoingUp)); - private BoolWorldObjectMessage CreateMessage(int id, bool isGoingUp) => new BoolWorldObjectMessage + private BoolWorldObjectMessage CreateMessage(int id, bool isGoingUp) => new() { State = isGoingUp, ObjectId = id diff --git a/QSB/ElevatorSync/Patches/ElevatorPatches.cs b/QSB/ElevatorSync/Patches/ElevatorPatches.cs index 2e12063a..1b218863 100644 --- a/QSB/ElevatorSync/Patches/ElevatorPatches.cs +++ b/QSB/ElevatorSync/Patches/ElevatorPatches.cs @@ -17,7 +17,7 @@ namespace QSB.ElevatorSync.Patches public static void Elevator_StartLift(Elevator __instance) { var isGoingUp = __instance.GetValue("_goingToTheEnd"); - var id = QSBWorldSync.GetIdFromUnity(__instance); + var id = QSBWorldSync.GetIdFromUnity(__instance); QSBEventManager.FireEvent(EventNames.QSBStartLift, id, isGoingUp); } } diff --git a/QSB/ElevatorSync/WorldObjects/QSBElevator.cs b/QSB/ElevatorSync/WorldObjects/QSBElevator.cs index 9358ae02..f322af7a 100644 --- a/QSB/ElevatorSync/WorldObjects/QSBElevator.cs +++ b/QSB/ElevatorSync/WorldObjects/QSBElevator.cs @@ -1,5 +1,4 @@ -using OWML.Utils; -using QSB.WorldSync; +using QSB.WorldSync; using UnityEngine; namespace QSB.ElevatorSync.WorldObjects @@ -12,42 +11,65 @@ namespace QSB.ElevatorSync.WorldObjects private SingleInteractionVolume _interactVolume; private OWAudioSource _owAudioSourceOneShot; private OWAudioSource _owAudioSourceLP; + private OWTriggerVolume _elevatorTrigger; public override void Init(Elevator elevator, int id) { AttachedObject = elevator; ObjectId = id; - QSBCore.UnityEvents.RunWhen(() => AttachedObject.GetValue("_interactVolume") != null, InitValues); + QSBCore.UnityEvents.RunWhen(() => AttachedObject._interactVolume != null, InitValues); } private void InitValues() { - _startLocalPos = AttachedObject.GetValue("_startLocalPos"); - _endLocalPos = AttachedObject.GetValue("_endLocalPos"); - _interactVolume = AttachedObject.GetValue("_interactVolume"); - _owAudioSourceOneShot = AttachedObject.GetValue("_owAudioSourceOneShot"); - _owAudioSourceLP = AttachedObject.GetValue("_owAudioSourceLP"); + _startLocalPos = AttachedObject._startLocalPos; + _endLocalPos = AttachedObject._endLocalPos; + _interactVolume = AttachedObject._interactVolume; + _owAudioSourceOneShot = AttachedObject._owAudioSourceOneShot; + _owAudioSourceLP = AttachedObject._owAudioSourceLP; + + var boxShape = AttachedObject.gameObject.AddComponent(); + boxShape.center = new Vector3(0, 1.75f, 0.25f); + boxShape.size = new Vector3(3, 3.5f, 3); + + _elevatorTrigger = AttachedObject.gameObject.GetAddComponent(); } public void RemoteCall(bool isGoingUp) { - SetDirection(isGoingUp); - RemoteStartLift(); + if (_elevatorTrigger.IsTrackingObject(Locator.GetPlayerDetector())) + { + SetDirection(isGoingUp); + + AttachedObject._attachPoint.AttachPlayer(); + + if (Locator.GetPlayerSuit().IsWearingSuit(true) && Locator.GetPlayerSuit().IsTrainingSuit()) + { + Locator.GetPlayerSuit().RemoveSuit(false); + } + + RemoteStartLift(); + } + else + { + SetDirection(isGoingUp); + RemoteStartLift(); + } } private void SetDirection(bool isGoingUp) { - var targetPos = isGoingUp ? _endLocalPos : _startLocalPos; - AttachedObject.SetValue("_goingToTheEnd", isGoingUp); - AttachedObject.SetValue("_targetLocalPos", targetPos); _interactVolume.transform.Rotate(0f, 180f, 0f); + var targetPos = isGoingUp ? _endLocalPos : _startLocalPos; + AttachedObject._targetLocalPos = targetPos; + AttachedObject._goingToTheEnd = isGoingUp; } private void RemoteStartLift() { AttachedObject.enabled = true; - AttachedObject.SetValue("_initLocalPos", AttachedObject.transform.localPosition); - AttachedObject.SetValue("_initLiftTime", Time.time); + AttachedObject._initLocalPos = AttachedObject.transform.localPosition; + AttachedObject._initLiftTime = Time.time; _owAudioSourceOneShot.PlayOneShot(AudioType.TH_LiftActivate); _owAudioSourceLP.FadeIn(0.5f); _interactVolume.DisableInteraction(); diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index 168d66c4..c5b946e2 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -62,8 +62,8 @@ public static string QSBCampfireState = "QSBCampfireState"; public static string QSBMarshmallowEvent = "QSBMarshmallowEvent"; public static string QSBAnimTrigger = "QSBAnimTrigger"; - public static string QSBEnterHeadZone = "QSBEnterHeadZone"; - public static string QSBExitHeadZone = "QSBExitHeadZone"; + public static string QSBEnterNonNomaiHeadZone = "QSBEnterNonNomaiHeadZone"; + public static string QSBExitNonNomaiHeadZone = "QSBExitNonNomaiHeadZone"; public static string QSBNpcAnimEvent = "QSBNpcAnimEvent"; public static string QSBHatchState = "QSBHatchState"; public static string QSBEnableFunnel = "QSBEnableFunnel"; @@ -87,5 +87,17 @@ public static string QSBServerState = "QSBServerState"; public static string QSBClientState = "QSBClientState"; public static string QSBDebugEvent = "QSBDebugEvent"; + public static string QSBEnterNomaiHeadZone = "QSBEnterNomaiHeadZone"; + public static string QSBExitNomaiHeadZone = "QSBExitNomaiHeadZone"; + public static string QSBEnterSatelliteCamera = "QSBEnterSatelliteCamera"; + public static string QSBExitSatelliteCamera = "QSBExitSatelliteCamera"; + public static string QSBSatelliteSnapshot = "QSBSatelliteSnapshot"; + public static string QSBAnglerChangeState = "QSBAnglerChangeState"; + public static string QSBMeteorPreLaunch = "QSBMeteorPreLaunch"; + public static string QSBMeteorLaunch = "QSBMeteorLaunch"; + public static string QSBMeteorSpecialImpact = "QSBMeteorSpecialImpact"; + public static string QSBFragmentDamage = "QSBFragmentDamage"; + public static string QSBFragmentResync = "QSBFragmentResync"; + public static string QSBLearnLaunchCodes = "QSBLearnLaunchCodes"; } -} \ No newline at end of file +} diff --git a/QSB/Events/EventType.cs b/QSB/Events/EventType.cs index be7a01f7..119011e3 100644 --- a/QSB/Events/EventType.cs +++ b/QSB/Events/EventType.cs @@ -3,9 +3,13 @@ public enum EventType { /* - * MISC. + * MISC. */ DebugEvent, + SatelliteProjector, + SatelliteProjectorSnapshot, + LaunchCodes, + VariableSync, /* * SERVER EVENTS @@ -131,6 +135,14 @@ RetrieveProbe, PlayerRetrieveProbe, LaunchProbe, - PlayerLaunchProbe + PlayerLaunchProbe, + + AnglerChangeState, + + MeteorPreLaunch, + MeteorLaunch, + MeteorSpecialImpact, + FragmentDamage, + FragmentResync } -} \ No newline at end of file +} diff --git a/QSB/Events/IQSBEvent.cs b/QSB/Events/IQSBEvent.cs index 63ad403b..ddac051f 100644 --- a/QSB/Events/IQSBEvent.cs +++ b/QSB/Events/IQSBEvent.cs @@ -2,6 +2,8 @@ { public interface IQSBEvent { + EventType Type { get; } + void SetupListener(); void CloseListener(); } diff --git a/QSB/Events/QSBEvent.cs b/QSB/Events/QSBEvent.cs index 18fe3523..f3663a30 100644 --- a/QSB/Events/QSBEvent.cs +++ b/QSB/Events/QSBEvent.cs @@ -1,6 +1,8 @@ using OWML.Common; +using QSB.ClientServerStateSync; using QSB.Messaging; using QSB.Player; +using QSB.Player.Events; using QSB.Player.TransformSync; using QSB.Utility; using QuantumUNET.Components; @@ -75,10 +77,24 @@ namespace QSB.Events if (PlayerTransformSync.LocalInstance == null || PlayerTransformSync.LocalInstance.GetComponent() == null) { - DebugLog.ToConsole($"Warning - Tried to handle message of type <{message.GetType().Name}> before localplayer was established.", MessageType.Warning); + DebugLog.ToConsole($"Warning - Tried to handle message of type <{GetType().Name}> before localplayer was established.", MessageType.Warning); return; } + if (QSBPlayerManager.PlayerExists(message.FromId)) + { + var player = QSBPlayerManager.GetPlayer(message.FromId); + + if (!player.IsReady + && player.PlayerId != LocalPlayerId + && (player.State is ClientState.AliveInSolarSystem or ClientState.AliveInEye or ClientState.DeadInSolarSystem) + && (message is not PlayerInformationEvent or PlayerReadyEvent)) + { + DebugLog.ToConsole($"Warning - Got message from player {message.FromId}, but they were not ready. Asking for state resync, just in case.", MessageType.Warning); + QSBEventManager.FireEvent(EventNames.QSBRequestStateResync); + } + } + try { if (message.FromId == QSBPlayerManager.LocalPlayerId || @@ -92,7 +108,7 @@ namespace QSB.Events } catch (Exception ex) { - DebugLog.ToConsole($"Error - Exception handling message {message.GetType().Name} : {ex}", MessageType.Error); + DebugLog.ToConsole($"Error - Exception handling message {GetType().Name} : {ex}", MessageType.Error); } } } diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index 68029535..1ac362da 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -1,4 +1,5 @@ using OWML.Common; +using QSB.Anglerfish.Events; using QSB.Animation.NPC.Events; using QSB.Animation.Player.Events; using QSB.CampfireSync.Events; @@ -6,26 +7,33 @@ using QSB.ClientServerStateSync.Events; using QSB.ConversationSync.Events; using QSB.DeathSync.Events; using QSB.ElevatorSync.Events; -using QSB.FrequencySync.Events; using QSB.GeyserSync.Events; using QSB.ItemSync.Events; using QSB.LogSync.Events; +using QSB.MeteorSync.Events; using QSB.OrbSync.Events; using QSB.Player.Events; -using QSB.ProbeSync.Events; using QSB.QuantumSync.Events; +using QSB.RespawnSync.Events; using QSB.RoastingSync.Events; +using QSB.SatelliteSync.Events; using QSB.ShipSync.Events; using QSB.ShipSync.Events.Component; using QSB.ShipSync.Events.Hull; using QSB.StatueSync.Events; using QSB.TimeSync.Events; -using QSB.Tools.Events; +using QSB.Tools.FlashlightTool.Events; using QSB.Tools.ProbeLauncherTool.Events; -using QSB.TranslationSync.Events; +using QSB.Tools.ProbeTool.Events; +using QSB.Tools.SignalscopeTool.Events; +using QSB.Tools.SignalscopeTool.FrequencySync.Events; +using QSB.Tools.TranslatorTool.Events; +using QSB.Tools.TranslatorTool.TranslationSync.Events; using QSB.Utility; using QSB.Utility.Events; using System.Collections.Generic; +using System.Linq; +using System.Text; namespace QSB.Events { @@ -33,7 +41,7 @@ namespace QSB.Events { public static bool Ready { get; private set; } - private static List _eventList = new List(); + private static List _eventList = new(); public static void Init() { @@ -69,6 +77,9 @@ namespace QSB.Events new ServerStateEvent(), new ClientStateEvent(), new DebugEvent(), + new SatelliteProjectorEvent(), + new SatelliteProjectorSnapshotEvent(), + new LaunchCodesEvent(), // World Objects new ElevatorEvent(), new GeyserEvent(), @@ -86,6 +97,12 @@ namespace QSB.Events new MoveToCarryEvent(), new StartStatueEvent(), new CampfireStateEvent(), + new AnglerChangeStateEvent(), + new MeteorPreLaunchEvent(), + new MeteorLaunchEvent(), + new MeteorSpecialImpactEvent(), + new FragmentDamageEvent(), + new FragmentResyncEvent(), // Conversation/dialogue/exploration new ConversationEvent(), new ConversationStartEndEvent(), @@ -115,6 +132,26 @@ namespace QSB.Events _eventList.ForEach(ev => ev.SetupListener()); + var duplicates = _eventList + .GroupBy(qsbEvent => qsbEvent.Type) + .Where(group => group.Count() > 1); + + if (duplicates.Count() != 0) + { + var totalSb = new StringBuilder(); + foreach (var group in duplicates) + { + totalSb.Append($"{group.Key}\r\n"); + foreach (var qsbEvent in group) + { + totalSb.Append($"- {qsbEvent.GetType().Name}\r\n"); + } + } + + DebugLog.ToConsole($"Error - These QSBEvents handle the same EventType!\r\n{totalSb}", MessageType.Error); + return; + } + Ready = true; DebugLog.DebugWrite("Event Manager ready.", MessageType.Success); @@ -203,4 +240,4 @@ namespace QSB.Events GlobalMessenger.FireEvent(eventName, arg1, arg2, arg3, arg4, arg5, arg6); } } -} \ No newline at end of file +} diff --git a/QSB/GeyserSync/Events/GeyserEvent.cs b/QSB/GeyserSync/Events/GeyserEvent.cs index 13ac1e02..d13a50c6 100644 --- a/QSB/GeyserSync/Events/GeyserEvent.cs +++ b/QSB/GeyserSync/Events/GeyserEvent.cs @@ -14,7 +14,7 @@ namespace QSB.GeyserSync.Events private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state)); - private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage + private BoolWorldObjectMessage CreateMessage(int id, bool state) => new() { AboutId = LocalPlayerId, ObjectId = id, diff --git a/QSB/ItemSync/Events/DropItemEvent.cs b/QSB/ItemSync/Events/DropItemEvent.cs index f2db3153..4ecc5e00 100644 --- a/QSB/ItemSync/Events/DropItemEvent.cs +++ b/QSB/ItemSync/Events/DropItemEvent.cs @@ -1,5 +1,6 @@ using QSB.Events; -using QSB.ItemSync.WorldObjects; +using QSB.ItemSync.WorldObjects.Items; +using QSB.Player; using QSB.Utility; using QSB.WorldSync; using UnityEngine; @@ -19,7 +20,7 @@ namespace QSB.ItemSync.Events private void Handler(int objectId, Vector3 position, Vector3 normal, Sector sector) => SendEvent(CreateMessage(objectId, position, normal, sector)); - private DropItemMessage CreateMessage(int objectId, Vector3 position, Vector3 normal, Sector sector) => new DropItemMessage + private DropItemMessage CreateMessage(int objectId, Vector3 position, Vector3 normal, Sector sector) => new() { ObjectId = objectId, Position = position, @@ -31,6 +32,9 @@ namespace QSB.ItemSync.Events { var worldObject = QSBWorldSync.GetWorldFromId(message.ObjectId); worldObject.DropItem(message.Position, message.Normal, message.Sector); + + var player = QSBPlayerManager.GetPlayer(message.FromId); + player.HeldItem = worldObject; } } } diff --git a/QSB/ItemSync/Events/DropItemMessage.cs b/QSB/ItemSync/Events/DropItemMessage.cs index 18f1c465..2771cc32 100644 --- a/QSB/ItemSync/Events/DropItemMessage.cs +++ b/QSB/ItemSync/Events/DropItemMessage.cs @@ -29,7 +29,7 @@ namespace QSB.ItemSync.Events writer.Write(ObjectId); writer.Write(Position); writer.Write(Normal); - var qsbSector = QSBWorldSync.GetWorldFromUnity(Sector); + var qsbSector = QSBWorldSync.GetWorldFromUnity(Sector); writer.Write(qsbSector.ObjectId); } } diff --git a/QSB/ItemSync/Events/MoveToCarryEvent.cs b/QSB/ItemSync/Events/MoveToCarryEvent.cs index 450db0ca..f799c5c8 100644 --- a/QSB/ItemSync/Events/MoveToCarryEvent.cs +++ b/QSB/ItemSync/Events/MoveToCarryEvent.cs @@ -1,9 +1,8 @@ using QSB.Events; -using QSB.ItemSync.WorldObjects; +using QSB.ItemSync.WorldObjects.Items; using QSB.Player; using QSB.WorldSync; using QSB.WorldSync.Events; -using UnityEngine; namespace QSB.ItemSync.Events { @@ -20,7 +19,7 @@ namespace QSB.ItemSync.Events private void Handler(int itemId) => SendEvent(CreateMessage(itemId)); - private WorldObjectMessage CreateMessage(int itemid) => new WorldObjectMessage + private WorldObjectMessage CreateMessage(int itemid) => new() { AboutId = QSBPlayerManager.LocalPlayerId, ObjectId = itemid @@ -31,26 +30,21 @@ namespace QSB.ItemSync.Events var player = QSBPlayerManager.GetPlayer(message.AboutId); var itemObject = QSBWorldSync.GetWorldFromId(message.ObjectId); var itemType = itemObject.GetItemType(); - Transform itemSocket = null; - switch (itemType) + + player.HeldItem = itemObject; + var itemSocket = itemType switch { - case ItemType.Scroll: - itemSocket = player.ScrollSocket; - break; - case ItemType.SharedStone: - itemSocket = player.SharedStoneSocket; - break; - case ItemType.WarpCore: - itemSocket = ((QSBWarpCoreItem)itemObject).IsVesselCoreType() - ? player.VesselCoreSocket - : player.WarpCoreSocket; - break; - default: - itemSocket = player.ItemSocket; - break; - - } - + ItemType.Scroll => player.ScrollSocket, + ItemType.SharedStone => player.SharedStoneSocket, + ItemType.WarpCore => ((QSBWarpCoreItem)itemObject).IsVesselCoreType() + ? player.VesselCoreSocket + : player.WarpCoreSocket, + ItemType.Lantern => player.SimpleLanternSocket, + ItemType.DreamLantern => player.DreamLanternSocket, + ItemType.SlideReel => player.SlideReelSocket, + ItemType.VisionTorch => player.VisionTorchSocket, + _ => player.ItemSocket, + }; itemObject.PickUpItem(itemSocket, message.AboutId); } } diff --git a/QSB/ItemSync/Events/SocketItemEvent.cs b/QSB/ItemSync/Events/SocketItemEvent.cs index 2e66f015..088ab528 100644 --- a/QSB/ItemSync/Events/SocketItemEvent.cs +++ b/QSB/ItemSync/Events/SocketItemEvent.cs @@ -1,5 +1,6 @@ using QSB.Events; -using QSB.ItemSync.WorldObjects; +using QSB.ItemSync.WorldObjects.Items; +using QSB.ItemSync.WorldObjects.Sockets; using QSB.Player; using QSB.Utility; using QSB.WorldSync; @@ -19,7 +20,7 @@ namespace QSB.ItemSync.Events private void Handler(int socketId, int itemId, SocketEventType type) => SendEvent(CreateMessage(socketId, itemId, type)); - private SocketItemMessage CreateMessage(int socketId, int itemId, SocketEventType type) => new SocketItemMessage + private SocketItemMessage CreateMessage(int socketId, int itemId, SocketEventType type) => new() { AboutId = QSBPlayerManager.LocalPlayerId, SocketId = socketId, @@ -31,6 +32,8 @@ namespace QSB.ItemSync.Events { var socketWorldObject = QSBWorldSync.GetWorldFromId(message.SocketId); var itemWorldObject = QSBWorldSync.GetWorldFromId(message.ItemId); + var player = QSBPlayerManager.GetPlayer(message.FromId); + player.HeldItem = null; switch (message.SocketType) { case SocketEventType.Socket: diff --git a/QSB/ItemSync/ItemManager.cs b/QSB/ItemSync/ItemManager.cs index 97c304e2..55f43a26 100644 --- a/QSB/ItemSync/ItemManager.cs +++ b/QSB/ItemSync/ItemManager.cs @@ -1,5 +1,6 @@ using OWML.Common; -using QSB.ItemSync.WorldObjects; +using QSB.ItemSync.WorldObjects.Items; +using QSB.ItemSync.WorldObjects.Sockets; using QSB.Utility; using QSB.WorldSync; @@ -10,80 +11,22 @@ namespace QSB.ItemSync protected override void RebuildWorldObjects(OWScene scene) { DebugLog.DebugWrite("Rebuilding OWItems...", MessageType.Info); - QSBWorldSync.Init(); + + // Items QSBWorldSync.Init(); - QSBWorldSync.Init(); QSBWorldSync.Init(); - QSBWorldSync.Init(); QSBWorldSync.Init(); - QSBWorldSync.Init(); QSBWorldSync.Init(); - } + QSBWorldSync.Init(); + QSBWorldSync.Init(); - public static IQSBOWItem GetObject(OWItem unityObject) - { - if (unityObject == null) - { - DebugLog.ToConsole($"Error - Trying to run GetObject (Item) with null unity object!", MessageType.Error); - return default; - } - - IQSBOWItem worldObj = null; - if (unityObject.GetType() == typeof(ScrollItem)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((ScrollItem)unityObject); - } - else if (unityObject.GetType() == typeof(SharedStone)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((SharedStone)unityObject); - } - else if (unityObject.GetType() == typeof(WarpCoreItem)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((WarpCoreItem)unityObject); - } - else if (unityObject.GetType() == typeof(NomaiConversationStone)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((NomaiConversationStone)unityObject); - } - else - { - DebugLog.ToConsole($"Warning - couldn't work out type of OWItem {unityObject.name}.", MessageType.Warning); - } - - return worldObj; - } - - public static IQSBOWItemSocket GetObject(OWItemSocket unityObject) - { - if (unityObject == null) - { - DebugLog.ToConsole($"Error - Trying to run GetObject (Socket) with null unity object!", MessageType.Error); - return default; - } - - IQSBOWItemSocket worldObj = null; - if (unityObject.GetType() == typeof(ScrollSocket)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((ScrollSocket)unityObject); - } - else if (unityObject.GetType() == typeof(SharedStoneSocket)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((SharedStoneSocket)unityObject); - } - else if (unityObject.GetType() == typeof(WarpCoreSocket)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((WarpCoreSocket)unityObject); - } - else if (unityObject.GetType() == typeof(NomaiConversationStone)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((NomaiConversationStoneSocket)unityObject); - } - else - { - DebugLog.ToConsole($"Warning - couldn't work out type of OWItemSocket {unityObject.name}.", MessageType.Warning); - } - - return worldObj; + // Sockets + QSBWorldSync.Init(); + QSBWorldSync.Init(); + QSBWorldSync.Init(); + QSBWorldSync.Init(); + QSBWorldSync.Init(); + QSBWorldSync.Init(); } } } diff --git a/QSB/ItemSync/Patches/ItemPatches.cs b/QSB/ItemSync/Patches/ItemPatches.cs index d515a122..f9d6edeb 100644 --- a/QSB/ItemSync/Patches/ItemPatches.cs +++ b/QSB/ItemSync/Patches/ItemPatches.cs @@ -1,7 +1,10 @@ using HarmonyLib; using OWML.Common; using QSB.Events; +using QSB.ItemSync.WorldObjects.Items; +using QSB.ItemSync.WorldObjects.Sockets; using QSB.Patches; +using QSB.Player; using QSB.Utility; using QSB.WorldSync; using UnityEngine; @@ -17,7 +20,9 @@ namespace QSB.ItemSync.Patches [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.MoveItemToCarrySocket))] public static bool ItemTool_MoveItemToCarrySocket(OWItem item) { - var itemId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(item)); + var qsbObj = (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(item); + var itemId = QSBWorldSync.GetIdFromTypeSubset(qsbObj); + QSBPlayerManager.LocalPlayer.HeldItem = qsbObj; QSBEventManager.FireEvent(EventNames.QSBMoveToCarry, itemId); return true; } @@ -26,8 +31,10 @@ namespace QSB.ItemSync.Patches [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.SocketItem))] public static bool ItemTool_SocketItem(OWItem ____heldItem, OWItemSocket socket) { - var socketId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(socket)); - var itemId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(____heldItem)); + var qsbObj = (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(____heldItem); + var socketId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(socket)); + var itemId = QSBWorldSync.GetIdFromTypeSubset(qsbObj); + QSBPlayerManager.LocalPlayer.HeldItem = null; QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, itemId, SocketEventType.Socket); return true; } @@ -36,7 +43,9 @@ namespace QSB.ItemSync.Patches [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.StartUnsocketItem))] public static bool ItemTool_StartUnsocketItem(OWItemSocket socket) { - var socketId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(socket)); + var item = (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(socket.GetSocketedItem()); + QSBPlayerManager.LocalPlayer.HeldItem = item; + var socketId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(socket)); QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, 0, SocketEventType.StartUnsocket); return true; } @@ -45,7 +54,7 @@ namespace QSB.ItemSync.Patches [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.CompleteUnsocketItem))] public static bool ItemTool_CompleteUnsocketItem(OWItem ____heldItem) { - var itemId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(____heldItem)); + var itemId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItem)QSBWorldSync.GetWorldFromUnity(____heldItem)); QSBEventManager.FireEvent(EventNames.QSBSocketItem, 0, itemId, SocketEventType.CompleteUnsocket); return true; } @@ -70,7 +79,7 @@ namespace QSB.ItemSync.Patches sector = sectorGroup.GetSector(); if (sector == null && sectorGroup is SectorCullGroup) { - SectorProxy controllingProxy = (sectorGroup as SectorCullGroup).GetControllingProxy(); + var controllingProxy = (sectorGroup as SectorCullGroup).GetControllingProxy(); if (controllingProxy != null) { sector = controllingProxy.GetSector(); @@ -81,9 +90,10 @@ namespace QSB.ItemSync.Patches var parent = (customDropTarget == null) ? targetRigidbody.transform : customDropTarget.GetItemDropTargetTransform(hit.collider.gameObject); - var objectId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(____heldItem)); + var objectId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItem)QSBWorldSync.GetWorldFromUnity(____heldItem)); ____heldItem.DropItem(hit.point, hit.normal, parent, sector, customDropTarget); ____heldItem = null; + QSBPlayerManager.LocalPlayer.HeldItem = null; Locator.GetToolModeSwapper().UnequipTool(); var parentSector = parent.GetComponentInChildren(); if (parentSector != null) diff --git a/QSB/ItemSync/WorldObjects/IQSBOWItem.cs b/QSB/ItemSync/WorldObjects/Items/IQSBOWItem.cs similarity index 91% rename from QSB/ItemSync/WorldObjects/IQSBOWItem.cs rename to QSB/ItemSync/WorldObjects/Items/IQSBOWItem.cs index 90651be4..4fc184e0 100644 --- a/QSB/ItemSync/WorldObjects/IQSBOWItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/IQSBOWItem.cs @@ -1,7 +1,7 @@ using QSB.WorldSync; using UnityEngine; -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Items { public interface IQSBOWItem : IWorldObjectTypeSubset { diff --git a/QSB/ItemSync/WorldObjects/QSBNomaiConversationStone.cs b/QSB/ItemSync/WorldObjects/Items/QSBNomaiConversationStone.cs similarity index 85% rename from QSB/ItemSync/WorldObjects/QSBNomaiConversationStone.cs rename to QSB/ItemSync/WorldObjects/Items/QSBNomaiConversationStone.cs index 6230ce1a..97a2798e 100644 --- a/QSB/ItemSync/WorldObjects/QSBNomaiConversationStone.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBNomaiConversationStone.cs @@ -1,4 +1,4 @@ -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Items { internal class QSBNomaiConversationStone : QSBOWItem { diff --git a/QSB/ItemSync/WorldObjects/QSBOWItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs similarity index 77% rename from QSB/ItemSync/WorldObjects/QSBOWItem.cs rename to QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs index acca3daa..9de0c8d8 100644 --- a/QSB/ItemSync/WorldObjects/QSBOWItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs @@ -1,10 +1,11 @@ -using OWML.Utils; +using QSB.ItemSync.WorldObjects.Sockets; using QSB.Player; using QSB.SectorSync.WorldObjects; +using QSB.Utility; using QSB.WorldSync; using UnityEngine; -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Items { internal class QSBOWItem : WorldObject, IQSBOWItem where T : OWItem @@ -18,13 +19,25 @@ namespace QSB.ItemSync.WorldObjects public override void Init(T attachedObject, int id) { + if (attachedObject == null) + { + DebugLog.ToConsole($"Error - AttachedObject is null! Type:{GetType().Name}", OWML.Common.MessageType.Error); + return; + } + InitialParent = attachedObject.transform.parent; InitialPosition = attachedObject.transform.localPosition; InitialRotation = attachedObject.transform.localRotation; - InitialSector = QSBWorldSync.GetWorldFromUnity(attachedObject.GetSector()); - if (InitialParent.GetComponent() != null) + InitialSector = QSBWorldSync.GetWorldFromUnity(attachedObject.GetSector()); + + if (InitialParent == null) { - var qsbObj = ItemManager.GetObject(InitialParent.GetComponent()); + DebugLog.ToConsole($"Warning - InitialParent of {attachedObject.name} is null!", OWML.Common.MessageType.Warning); + } + + if (InitialParent?.GetComponent() != null) + { + var qsbObj = (IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(InitialParent.GetComponent()); InitialSocket = qsbObj; } @@ -76,10 +89,10 @@ namespace QSB.ItemSync.WorldObjects { AttachedObject.transform.SetParent(sector.transform); AttachedObject.transform.localScale = Vector3.one; - var localDropNormal = AttachedObject.GetValue("_localDropNormal"); + var localDropNormal = AttachedObject._localDropNormal; var lhs = Quaternion.FromToRotation(AttachedObject.transform.TransformDirection(localDropNormal), normal); AttachedObject.transform.rotation = lhs * AttachedObject.transform.rotation; - var localDropOffset = AttachedObject.GetValue("_localDropOffset"); + var localDropOffset = AttachedObject._localDropOffset; AttachedObject.transform.position = sector.transform.TransformPoint(position) + AttachedObject.transform.TransformDirection(localDropOffset); AttachedObject.SetSector(sector); AttachedObject.SetColliderActivation(true); diff --git a/QSB/ItemSync/WorldObjects/QSBScrollItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBScrollItem.cs similarity index 93% rename from QSB/ItemSync/WorldObjects/QSBScrollItem.cs rename to QSB/ItemSync/WorldObjects/Items/QSBScrollItem.cs index e8cc6aaf..425f980c 100644 --- a/QSB/ItemSync/WorldObjects/QSBScrollItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBScrollItem.cs @@ -1,4 +1,4 @@ -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Items { internal class QSBScrollItem : QSBOWItem { diff --git a/QSB/ItemSync/WorldObjects/QSBSharedStone.cs b/QSB/ItemSync/WorldObjects/Items/QSBSharedStone.cs similarity index 93% rename from QSB/ItemSync/WorldObjects/QSBSharedStone.cs rename to QSB/ItemSync/WorldObjects/Items/QSBSharedStone.cs index 4a0ed717..fe2830f4 100644 --- a/QSB/ItemSync/WorldObjects/QSBSharedStone.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBSharedStone.cs @@ -1,4 +1,4 @@ -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Items { internal class QSBSharedStone : QSBOWItem { diff --git a/QSB/ItemSync/WorldObjects/Items/QSBSimpleLanternItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBSimpleLanternItem.cs new file mode 100644 index 00000000..12bf9c7b --- /dev/null +++ b/QSB/ItemSync/WorldObjects/Items/QSBSimpleLanternItem.cs @@ -0,0 +1,21 @@ +namespace QSB.ItemSync.WorldObjects.Items +{ + internal class QSBSimpleLanternItem : QSBOWItem + { + public override void Init(SimpleLanternItem attachedObject, int id) + { + ObjectId = id; + AttachedObject = attachedObject; + base.Init(attachedObject, id); + } + + public override void PlaySocketAnimation() + => AttachedObject.PlaySocketAnimation(); + + public override void PlayUnsocketAnimation() + => AttachedObject.PlayUnsocketAnimation(); + + public override void OnCompleteUnsocket() + => AttachedObject.OnCompleteUnsocket(); + } +} diff --git a/QSB/ItemSync/WorldObjects/Items/QSBSlideReelItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBSlideReelItem.cs new file mode 100644 index 00000000..41735ea0 --- /dev/null +++ b/QSB/ItemSync/WorldObjects/Items/QSBSlideReelItem.cs @@ -0,0 +1,21 @@ +namespace QSB.ItemSync.WorldObjects.Items +{ + internal class QSBSlideReelItem : QSBOWItem + { + public override void Init(SlideReelItem attachedObject, int id) + { + ObjectId = id; + AttachedObject = attachedObject; + base.Init(attachedObject, id); + } + + public override void PlaySocketAnimation() + => AttachedObject.PlaySocketAnimation(); + + public override void PlayUnsocketAnimation() + => AttachedObject.PlayUnsocketAnimation(); + + public override void OnCompleteUnsocket() + => AttachedObject.OnCompleteUnsocket(); + } +} diff --git a/QSB/ItemSync/WorldObjects/QSBWarpCoreItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBWarpCoreItem.cs similarity index 87% rename from QSB/ItemSync/WorldObjects/QSBWarpCoreItem.cs rename to QSB/ItemSync/WorldObjects/Items/QSBWarpCoreItem.cs index 88e31da7..3be29380 100644 --- a/QSB/ItemSync/WorldObjects/QSBWarpCoreItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBWarpCoreItem.cs @@ -1,4 +1,4 @@ -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Items { internal class QSBWarpCoreItem : QSBOWItem { diff --git a/QSB/ItemSync/WorldObjects/IQSBOWItemSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/IQSBOWItemSocket.cs similarity index 66% rename from QSB/ItemSync/WorldObjects/IQSBOWItemSocket.cs rename to QSB/ItemSync/WorldObjects/Sockets/IQSBOWItemSocket.cs index 8d42f9bc..a1cc6887 100644 --- a/QSB/ItemSync/WorldObjects/IQSBOWItemSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/IQSBOWItemSocket.cs @@ -1,6 +1,7 @@ -using QSB.WorldSync; +using QSB.ItemSync.WorldObjects.Items; +using QSB.WorldSync; -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Sockets { public interface IQSBOWItemSocket : IWorldObjectTypeSubset { diff --git a/QSB/ItemSync/WorldObjects/QSBNomaiConversationStoneSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBNomaiConversationStoneSocket.cs similarity index 85% rename from QSB/ItemSync/WorldObjects/QSBNomaiConversationStoneSocket.cs rename to QSB/ItemSync/WorldObjects/Sockets/QSBNomaiConversationStoneSocket.cs index f193246b..bc48b86e 100644 --- a/QSB/ItemSync/WorldObjects/QSBNomaiConversationStoneSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBNomaiConversationStoneSocket.cs @@ -1,4 +1,4 @@ -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Sockets { internal class QSBNomaiConversationStoneSocket : QSBOWItemSocket { diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs new file mode 100644 index 00000000..7ca06e54 --- /dev/null +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs @@ -0,0 +1,27 @@ +using QSB.ItemSync.WorldObjects.Items; +using QSB.WorldSync; + +namespace QSB.ItemSync.WorldObjects.Sockets +{ + internal class QSBOWItemDoubleSocket : WorldObject, IQSBOWItemSocket + where T : OWItemSocket + { + public override void Init(T attachedObject, int id) { } + + public virtual bool AcceptsItem(IQSBOWItem item) + { + var itemType = item.GetItemType(); + var acceptableType = AttachedObject._acceptableType; + return (itemType & acceptableType) == itemType; + } + + public virtual bool IsSocketOccupied() + => AttachedObject.IsSocketOccupied(); + + public virtual bool PlaceIntoSocket(IQSBOWItem item) + => AttachedObject.PlaceIntoSocket((OWItem)(item as IWorldObject).ReturnObject()); + + public virtual IQSBOWItem RemoveFromSocket() + => (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(AttachedObject.RemoveFromSocket()); + } +} diff --git a/QSB/ItemSync/WorldObjects/QSBOWItemSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs similarity index 72% rename from QSB/ItemSync/WorldObjects/QSBOWItemSocket.cs rename to QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs index bd8321cb..545e8ca1 100644 --- a/QSB/ItemSync/WorldObjects/QSBOWItemSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs @@ -1,7 +1,7 @@ -using OWML.Utils; +using QSB.ItemSync.WorldObjects.Items; using QSB.WorldSync; -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Sockets { internal class QSBOWItemSocket : WorldObject, IQSBOWItemSocket where T : OWItemSocket @@ -11,7 +11,7 @@ namespace QSB.ItemSync.WorldObjects public virtual bool AcceptsItem(IQSBOWItem item) { var itemType = item.GetItemType(); - var acceptableType = AttachedObject.GetValue("_acceptableType"); + var acceptableType = AttachedObject._acceptableType; return (itemType & acceptableType) == itemType; } @@ -22,6 +22,6 @@ namespace QSB.ItemSync.WorldObjects => AttachedObject.PlaceIntoSocket((OWItem)(item as IWorldObject).ReturnObject()); public virtual IQSBOWItem RemoveFromSocket() - => ItemManager.GetObject(AttachedObject.RemoveFromSocket()); + => (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(AttachedObject.RemoveFromSocket()); } } diff --git a/QSB/ItemSync/WorldObjects/QSBScrollSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBScrollSocket.cs similarity index 83% rename from QSB/ItemSync/WorldObjects/QSBScrollSocket.cs rename to QSB/ItemSync/WorldObjects/Sockets/QSBScrollSocket.cs index bdf15f89..79755b9d 100644 --- a/QSB/ItemSync/WorldObjects/QSBScrollSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBScrollSocket.cs @@ -1,4 +1,4 @@ -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Sockets { internal class QSBScrollSocket : QSBOWItemSocket { diff --git a/QSB/ItemSync/WorldObjects/QSBSharedStoneSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBSharedStoneSocket.cs similarity index 84% rename from QSB/ItemSync/WorldObjects/QSBSharedStoneSocket.cs rename to QSB/ItemSync/WorldObjects/Sockets/QSBSharedStoneSocket.cs index 3c8341ce..357b3a0b 100644 --- a/QSB/ItemSync/WorldObjects/QSBSharedStoneSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBSharedStoneSocket.cs @@ -1,4 +1,4 @@ -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Sockets { internal class QSBSharedStoneSocket : QSBOWItemSocket { diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBSlideProjectorSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBSlideProjectorSocket.cs new file mode 100644 index 00000000..6d353c95 --- /dev/null +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBSlideProjectorSocket.cs @@ -0,0 +1,12 @@ +namespace QSB.ItemSync.WorldObjects.Sockets +{ + internal class QSBSlideProjectorSocket : QSBOWItemDoubleSocket + { + public override void Init(SlideProjectorSocket attachedObject, int id) + { + ObjectId = id; + AttachedObject = attachedObject; + base.Init(attachedObject, id); + } + } +} diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBSlideReelSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBSlideReelSocket.cs new file mode 100644 index 00000000..72ed11e3 --- /dev/null +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBSlideReelSocket.cs @@ -0,0 +1,12 @@ +namespace QSB.ItemSync.WorldObjects.Sockets +{ + internal class QSBSlideReelSocket : QSBOWItemSocket + { + public override void Init(SlideReelSocket attachedObject, int id) + { + ObjectId = id; + AttachedObject = attachedObject; + base.Init(attachedObject, id); + } + } +} diff --git a/QSB/ItemSync/WorldObjects/QSBWarpCoreSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBWarpCoreSocket.cs similarity index 83% rename from QSB/ItemSync/WorldObjects/QSBWarpCoreSocket.cs rename to QSB/ItemSync/WorldObjects/Sockets/QSBWarpCoreSocket.cs index 1c55e986..5afa4e20 100644 --- a/QSB/ItemSync/WorldObjects/QSBWarpCoreSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBWarpCoreSocket.cs @@ -1,4 +1,4 @@ -namespace QSB.ItemSync.WorldObjects +namespace QSB.ItemSync.WorldObjects.Sockets { internal class QSBWarpCoreSocket : QSBOWItemSocket { diff --git a/QSB/LogSync/Events/RevealFactEvent.cs b/QSB/LogSync/Events/RevealFactEvent.cs index 3c93efb2..2fd1c43f 100644 --- a/QSB/LogSync/Events/RevealFactEvent.cs +++ b/QSB/LogSync/Events/RevealFactEvent.cs @@ -12,7 +12,7 @@ namespace QSB.LogSync.Events private void Handler(string id, bool saveGame, bool showNotification) => SendEvent(CreateMessage(id, saveGame, showNotification)); - private RevealFactMessage CreateMessage(string id, bool saveGame, bool showNotification) => new RevealFactMessage + private RevealFactMessage CreateMessage(string id, bool saveGame, bool showNotification) => new() { AboutId = LocalPlayerId, FactId = id, diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index b2077ad5..7ac927ca 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -1,11 +1,12 @@ using QSB.Player; +using System.Linq; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; namespace QSB.Menus { - class MenuManager : MonoBehaviour + internal class MenuManager : MonoBehaviour { public static MenuManager Instance; @@ -27,7 +28,7 @@ namespace QSB.Menus QSBNetworkManager.Instance.OnClientErrorThrown += OnClientError; } - void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isUniverse) + private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isUniverse) { if (isUniverse) { @@ -66,6 +67,7 @@ namespace QSB.Menus pauseCommandListener.RemovePauseCommandLock(); _addedPauseLock = false; } + OWTime.Unpause(OWTime.PauseType.System); OWInput.RestorePreviousInputs(); } @@ -91,7 +93,6 @@ namespace QSB.Menus DisconnectButton = MenuApi.PauseMenu_MakeSimpleButton("DISCONNECT"); DisconnectButton.onClick.AddListener(Disconnect); - if (QSBCore.IsInMultiplayer) { ClientButton.SetActive(false); @@ -134,6 +135,25 @@ namespace QSB.Menus } OnConnected(); + + if (QSBCore.SkipTitleScreen) + { + Application.runInBackground = true; + var titleScreenManager = FindObjectOfType(); + var titleScreenAnimation = titleScreenManager._cameraController; + const float small = 1 / 1000f; + titleScreenAnimation._gamepadSplash = false; + titleScreenAnimation._introPan = false; + titleScreenAnimation._fadeDuration = small; + titleScreenAnimation.Start(); + var titleAnimationController = titleScreenManager._gfxController; + titleAnimationController._logoFadeDelay = small; + titleAnimationController._logoFadeDuration = small; + titleAnimationController._echoesFadeDelay = small; + titleAnimationController._optionsFadeDelay = small; + titleAnimationController._optionsFadeDuration = small; + titleAnimationController._optionsFadeSpacing = small; + } } private void Disconnect() @@ -155,7 +175,7 @@ namespace QSB.Menus private void Connect() { - QSBNetworkManager.Instance.networkAddress = (PopupMenu as PopupInputMenu).GetInputText(); + QSBNetworkManager.Instance.networkAddress = string.Concat((PopupMenu as PopupInputMenu).GetInputText().Where(c => !char.IsWhiteSpace(c))); QSBNetworkManager.Instance.StartClient(); DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent().text = "CONNECTING... (STOP)"; DisconnectButton.gameObject.SetActive(true); @@ -174,26 +194,14 @@ namespace QSB.Menus public void OnKicked(KickReason reason) { - string text; - switch (reason) + var text = reason switch { - case KickReason.QSBVersionNotMatching: - text = "Server refused connection as QSB version does not match."; - break; - case KickReason.GameVersionNotMatching: - text = "Server refused connection as Outer Wilds version does not match."; - break; - case KickReason.GamePlatformNotMatching: - text = "Server refused connection as Outer Wilds platform does not match. (Steam/Epic)"; - break; - case KickReason.None: - text = "Kicked from server. No reason given."; - break; - default: - text = $"Kicked from server. KickReason:{reason}"; - break; - } - + KickReason.QSBVersionNotMatching => "Server refused connection as QSB version does not match.", + KickReason.GameVersionNotMatching => "Server refused connection as Outer Wilds version does not match.", + KickReason.GamePlatformNotMatching => "Server refused connection as Outer Wilds platform does not match. (Steam/Epic)", + KickReason.None => "Kicked from server. No reason given.", + _ => $"Kicked from server. KickReason:{reason}", + }; OpenInfoPopup(text, "OK"); DisconnectButton.gameObject.SetActive(false); @@ -208,17 +216,11 @@ namespace QSB.Menus return; } - string text; - switch (error) + var text = error switch { - case NetworkError.Timeout: - text = "Client disconnected with error!\r\nConnection timed out."; - break; - default: - text = $"Client disconnected with error!\r\nNetworkError:{error}"; - break; - } - + NetworkError.Timeout => "Client disconnected with error!\r\nConnection timed out.", + _ => $"Client disconnected with error!\r\nNetworkError:{error}", + }; OpenInfoPopup(text, "OK"); DisconnectButton.gameObject.SetActive(false); @@ -251,4 +253,4 @@ namespace QSB.Menus OpenInfoPopup(text, "OK"); } } -} \ No newline at end of file +} diff --git a/QSB/MeteorSync/Events/FragmentDamageEvent.cs b/QSB/MeteorSync/Events/FragmentDamageEvent.cs new file mode 100644 index 00000000..4b830cbd --- /dev/null +++ b/QSB/MeteorSync/Events/FragmentDamageEvent.cs @@ -0,0 +1,37 @@ +using QSB.Events; +using QSB.MeteorSync.WorldObjects; +using QSB.WorldSync; + +namespace QSB.MeteorSync.Events +{ + public class FragmentDamageEvent : QSBEvent + { + public override EventType Type => EventType.FragmentDamage; + + public override void SetupListener() + => GlobalMessenger.AddListener(EventNames.QSBFragmentDamage, Handler); + + public override void CloseListener() + => GlobalMessenger.RemoveListener(EventNames.QSBFragmentDamage, Handler); + + private void Handler(QSBFragment qsbFragment, float damage) => + SendEvent(CreateMessage(qsbFragment, damage)); + + private FragmentDamageMessage CreateMessage(QSBFragment qsbFragment, float damage) => new() + { + ObjectId = qsbFragment.ObjectId, + Damage = damage + }; + + public override void OnReceiveRemote(bool isHost, FragmentDamageMessage message) + { + if (!MeteorManager.Ready) + { + return; + } + + var qsbFragment = QSBWorldSync.GetWorldFromId(message.ObjectId); + qsbFragment.AddDamage(message.Damage); + } + } +} diff --git a/QSB/MeteorSync/Events/FragmentDamageMessage.cs b/QSB/MeteorSync/Events/FragmentDamageMessage.cs new file mode 100644 index 00000000..4ee08897 --- /dev/null +++ b/QSB/MeteorSync/Events/FragmentDamageMessage.cs @@ -0,0 +1,22 @@ +using QSB.WorldSync.Events; +using QuantumUNET.Transport; + +namespace QSB.MeteorSync.Events +{ + public class FragmentDamageMessage : WorldObjectMessage + { + public float Damage; + + public override void Deserialize(QNetworkReader reader) + { + base.Deserialize(reader); + Damage = reader.ReadSingle(); + } + + public override void Serialize(QNetworkWriter writer) + { + base.Serialize(writer); + writer.Write(Damage); + } + } +} diff --git a/QSB/MeteorSync/Events/FragmentResyncEvent.cs b/QSB/MeteorSync/Events/FragmentResyncEvent.cs new file mode 100644 index 00000000..c79a6829 --- /dev/null +++ b/QSB/MeteorSync/Events/FragmentResyncEvent.cs @@ -0,0 +1,122 @@ +using OWML.Common; +using QSB.Events; +using QSB.MeteorSync.WorldObjects; +using QSB.Syncs; +using QSB.Utility; +using QSB.WorldSync; + +namespace QSB.MeteorSync.Events +{ + /// called when we request a resync on client join + /// pain + public class FragmentResyncEvent : QSBEvent + { + public override EventType Type => EventType.FragmentResync; + + public override void SetupListener() + => GlobalMessenger.AddListener(EventNames.QSBFragmentResync, Handler); + + public override void CloseListener() + => GlobalMessenger.RemoveListener(EventNames.QSBFragmentResync, Handler); + + private void Handler(QSBFragment qsbFragment) => SendEvent(CreateMessage(qsbFragment)); + + private FragmentResyncMessage CreateMessage(QSBFragment qsbFragment) + { + var msg = new FragmentResyncMessage + { + ObjectId = qsbFragment.ObjectId, + Integrity = qsbFragment.AttachedObject._integrity, + OrigIntegrity = qsbFragment.AttachedObject._origIntegrity, + LeashLength = qsbFragment.LeashLength, + IsDetached = qsbFragment.IsDetached + }; + + if (msg.IsDetached) + { + msg.IsThruWhiteHole = qsbFragment.IsThruWhiteHole; + + var body = qsbFragment.Body; + var refBody = qsbFragment.RefBody; + var pos = body.GetPosition(); + msg.Pos = refBody.transform.EncodePos(pos); + msg.Rot = refBody.transform.EncodeRot(body.GetRotation()); + msg.Vel = refBody.EncodeVel(body.GetVelocity(), pos); + msg.AngVel = refBody.EncodeAngVel(body.GetAngularVelocity()); + } + + return msg; + } + + public override void OnReceiveRemote(bool isHost, FragmentResyncMessage msg) + { + if (!MeteorManager.Ready) + { + return; + } + + var qsbFragment = QSBWorldSync.GetWorldFromId(msg.ObjectId); + qsbFragment.AttachedObject._integrity = msg.Integrity; + qsbFragment.AttachedObject._origIntegrity = msg.OrigIntegrity; + qsbFragment.LeashLength = msg.LeashLength; + qsbFragment.AttachedObject.CallOnTakeDamage(); + + if (msg.IsDetached) + { + // the detach is delayed, so wait until that happens + QSBCore.UnityEvents.RunWhen(() => qsbFragment.IsDetached, () => + { + var body = qsbFragment.Body; + + if (msg.IsThruWhiteHole && !qsbFragment.IsThruWhiteHole) + { + var whiteHoleVolume = MeteorManager.WhiteHoleVolume; + var attachedFluidDetector = body.GetAttachedFluidDetector(); + var attachedForceDetector = body.GetAttachedForceDetector(); + if (attachedFluidDetector is not null and ConstantFluidDetector constantFluidDetector) + { + constantFluidDetector.SetDetectableFluid(whiteHoleVolume._fluidVolume); + } + + if (attachedForceDetector is not null and ConstantForceDetector constantForceDetector) + { + constantForceDetector.ClearAllFields(); + } + + qsbFragment.DetachableFragment.ChangeFragmentSector(whiteHoleVolume._whiteHoleSector, + whiteHoleVolume._whiteHoleProxyShadowSuperGroup); + + qsbFragment.DetachableFragment.EndWarpScaling(); + body.gameObject.AddComponent().Init(whiteHoleVolume._whiteHoleBody, qsbFragment.LeashLength); + whiteHoleVolume._ejectedBodyList.Add(body); + } + else if (!msg.IsThruWhiteHole && qsbFragment.IsThruWhiteHole) + { + // should only happen if client is way too far ahead and they try to connect. we fail here. + DebugLog.ToConsole($"{qsbFragment.LogName} is thru white hole, but msg is not. fuck", MessageType.Error); + return; + } + + if (qsbFragment.IsThruWhiteHole) + { + var debrisLeash = body.GetComponent(); + debrisLeash._deccelerating = false; + debrisLeash.enabled = true; + } + + var refBody = qsbFragment.RefBody; + var pos = refBody.transform.DecodePos(msg.Pos); + body.SetPosition(pos); + body.SetRotation(refBody.transform.DecodeRot(msg.Rot)); + body.SetVelocity(refBody.DecodeVel(msg.Vel, pos)); + body.SetAngularVelocity(refBody.DecodeAngVel(msg.AngVel)); + }); + } + else if (!msg.IsDetached && qsbFragment.IsDetached) + { + // should only happen if client is way too far ahead and they try to connect. we fail here. + DebugLog.ToConsole($"{qsbFragment.LogName} is detached, but msg is not. fuck", MessageType.Error); + } + } + } +} diff --git a/QSB/MeteorSync/Events/FragmentResyncMessage.cs b/QSB/MeteorSync/Events/FragmentResyncMessage.cs new file mode 100644 index 00000000..4971452f --- /dev/null +++ b/QSB/MeteorSync/Events/FragmentResyncMessage.cs @@ -0,0 +1,54 @@ +using QSB.WorldSync.Events; +using QuantumUNET.Transport; +using UnityEngine; + +namespace QSB.MeteorSync.Events +{ + public class FragmentResyncMessage : WorldObjectMessage + { + public float Integrity; + public float OrigIntegrity; + public float LeashLength; + public bool IsDetached; + + public bool IsThruWhiteHole; + public Vector3 Pos; + public Quaternion Rot; + public Vector3 Vel; + public Vector3 AngVel; + + public override void Deserialize(QNetworkReader reader) + { + base.Deserialize(reader); + Integrity = reader.ReadSingle(); + OrigIntegrity = reader.ReadSingle(); + LeashLength = reader.ReadSingle(); + IsDetached = reader.ReadBoolean(); + if (IsDetached) + { + IsThruWhiteHole = reader.ReadBoolean(); + Pos = reader.ReadVector3(); + Rot = reader.ReadQuaternion(); + Vel = reader.ReadVector3(); + AngVel = reader.ReadVector3(); + } + } + + public override void Serialize(QNetworkWriter writer) + { + base.Serialize(writer); + writer.Write(Integrity); + writer.Write(OrigIntegrity); + writer.Write(LeashLength); + writer.Write(IsDetached); + if (IsDetached) + { + writer.Write(IsThruWhiteHole); + writer.Write(Pos); + writer.Write(Rot); + writer.Write(Vel); + writer.Write(AngVel); + } + } + } +} diff --git a/QSB/MeteorSync/Events/MeteorLaunchEvent.cs b/QSB/MeteorSync/Events/MeteorLaunchEvent.cs new file mode 100644 index 00000000..6ab9fe82 --- /dev/null +++ b/QSB/MeteorSync/Events/MeteorLaunchEvent.cs @@ -0,0 +1,38 @@ +using QSB.Events; +using QSB.MeteorSync.WorldObjects; +using QSB.WorldSync; + +namespace QSB.MeteorSync.Events +{ + public class MeteorLaunchEvent : QSBEvent + { + public override EventType Type => EventType.MeteorLaunch; + + public override void SetupListener() + => GlobalMessenger.AddListener(EventNames.QSBMeteorLaunch, Handler); + + public override void CloseListener() + => GlobalMessenger.RemoveListener(EventNames.QSBMeteorLaunch, Handler); + + private void Handler(QSBMeteorLauncher qsbMeteorLauncher) => + SendEvent(CreateMessage(qsbMeteorLauncher)); + + private MeteorLaunchMessage CreateMessage(QSBMeteorLauncher qsbMeteorLauncher) => new() + { + ObjectId = qsbMeteorLauncher.ObjectId, + MeteorId = qsbMeteorLauncher.MeteorId, + LaunchSpeed = qsbMeteorLauncher.LaunchSpeed, + }; + + public override void OnReceiveRemote(bool isHost, MeteorLaunchMessage message) + { + if (!MeteorManager.Ready) + { + return; + } + + var qsbMeteorLauncher = QSBWorldSync.GetWorldFromId(message.ObjectId); + qsbMeteorLauncher.LaunchMeteor(message.MeteorId, message.LaunchSpeed); + } + } +} diff --git a/QSB/MeteorSync/Events/MeteorLaunchMessage.cs b/QSB/MeteorSync/Events/MeteorLaunchMessage.cs new file mode 100644 index 00000000..68698ad8 --- /dev/null +++ b/QSB/MeteorSync/Events/MeteorLaunchMessage.cs @@ -0,0 +1,25 @@ +using QSB.WorldSync.Events; +using QuantumUNET.Transport; + +namespace QSB.MeteorSync.Events +{ + public class MeteorLaunchMessage : WorldObjectMessage + { + public int MeteorId; + public float LaunchSpeed; + + public override void Deserialize(QNetworkReader reader) + { + base.Deserialize(reader); + MeteorId = reader.ReadInt32(); + LaunchSpeed = reader.ReadSingle(); + } + + public override void Serialize(QNetworkWriter writer) + { + base.Serialize(writer); + writer.Write(MeteorId); + writer.Write(LaunchSpeed); + } + } +} diff --git a/QSB/MeteorSync/Events/MeteorPreLaunchEvent.cs b/QSB/MeteorSync/Events/MeteorPreLaunchEvent.cs new file mode 100644 index 00000000..b56b87a8 --- /dev/null +++ b/QSB/MeteorSync/Events/MeteorPreLaunchEvent.cs @@ -0,0 +1,36 @@ +using QSB.Events; +using QSB.MeteorSync.WorldObjects; +using QSB.WorldSync; +using QSB.WorldSync.Events; + +namespace QSB.MeteorSync.Events +{ + public class MeteorPreLaunchEvent : QSBEvent + { + public override EventType Type => EventType.MeteorPreLaunch; + + public override void SetupListener() + => GlobalMessenger.AddListener(EventNames.QSBMeteorPreLaunch, Handler); + + public override void CloseListener() + => GlobalMessenger.RemoveListener(EventNames.QSBMeteorPreLaunch, Handler); + + private void Handler(QSBMeteorLauncher qsbMeteorLauncher) => SendEvent(CreateMessage(qsbMeteorLauncher)); + + private WorldObjectMessage CreateMessage(QSBMeteorLauncher qsbMeteorLauncher) => new() + { + ObjectId = qsbMeteorLauncher.ObjectId + }; + + public override void OnReceiveRemote(bool isHost, WorldObjectMessage message) + { + if (!MeteorManager.Ready) + { + return; + } + + var qsbMeteorLauncher = QSBWorldSync.GetWorldFromId(message.ObjectId); + qsbMeteorLauncher.PreLaunchMeteor(); + } + } +} diff --git a/QSB/MeteorSync/Events/MeteorSpecialImpactEvent.cs b/QSB/MeteorSync/Events/MeteorSpecialImpactEvent.cs new file mode 100644 index 00000000..f2433ae9 --- /dev/null +++ b/QSB/MeteorSync/Events/MeteorSpecialImpactEvent.cs @@ -0,0 +1,36 @@ +using QSB.Events; +using QSB.MeteorSync.WorldObjects; +using QSB.WorldSync; +using QSB.WorldSync.Events; + +namespace QSB.MeteorSync.Events +{ + public class MeteorSpecialImpactEvent : QSBEvent + { + public override EventType Type => EventType.MeteorSpecialImpact; + + public override void SetupListener() + => GlobalMessenger.AddListener(EventNames.QSBMeteorSpecialImpact, Handler); + + public override void CloseListener() + => GlobalMessenger.RemoveListener(EventNames.QSBMeteorSpecialImpact, Handler); + + private void Handler(QSBMeteor qsbMeteor) => SendEvent(CreateMessage(qsbMeteor)); + + private WorldObjectMessage CreateMessage(QSBMeteor qsbMeteor) => new() + { + ObjectId = qsbMeteor.ObjectId + }; + + public override void OnReceiveRemote(bool isHost, WorldObjectMessage message) + { + if (!MeteorManager.Ready) + { + return; + } + + var qsbMeteor = QSBWorldSync.GetWorldFromId(message.ObjectId); + qsbMeteor.SpecialImpact(); + } + } +} diff --git a/QSB/MeteorSync/MeteorManager.cs b/QSB/MeteorSync/MeteorManager.cs new file mode 100644 index 00000000..4d8594d6 --- /dev/null +++ b/QSB/MeteorSync/MeteorManager.cs @@ -0,0 +1,27 @@ +using QSB.MeteorSync.WorldObjects; +using QSB.WorldSync; +using System.Linq; + +namespace QSB.MeteorSync +{ + public class MeteorManager : WorldObjectManager + { + public static bool Ready => AllReady && _ready; + private static bool _ready; + public static WhiteHoleVolume WhiteHoleVolume; + + protected override void RebuildWorldObjects(OWScene scene) + { + _ready = false; + // wait for all late initializers (which includes meteor launchers) to finish + QSBCore.UnityEvents.RunWhen(() => LateInitializerManager.s_lateInitializers.Count == 0, () => + { + WhiteHoleVolume = QSBWorldSync.GetUnityObjects().First(); + QSBWorldSync.Init(); + QSBWorldSync.Init(); + QSBWorldSync.Init(); + _ready = true; + }); + } + } +} diff --git a/QSB/MeteorSync/Patches/MeteorClientPatches.cs b/QSB/MeteorSync/Patches/MeteorClientPatches.cs new file mode 100644 index 00000000..9c80e5fe --- /dev/null +++ b/QSB/MeteorSync/Patches/MeteorClientPatches.cs @@ -0,0 +1,188 @@ +using HarmonyLib; +using OWML.Common; +using QSB.Events; +using QSB.MeteorSync.WorldObjects; +using QSB.Patches; +using QSB.Utility; +using QSB.WorldSync; +using UnityEngine; + +namespace QSB.MeteorSync.Patches +{ + public class MeteorClientPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnNonServerClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(MeteorLauncher), nameof(MeteorLauncher.FixedUpdate))] + public static bool FixedUpdate(MeteorLauncher __instance) + => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(MeteorLauncher), nameof(MeteorLauncher.LaunchMeteor))] + public static bool LaunchMeteor(MeteorLauncher __instance) + { + var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity(__instance); + + MeteorController meteorController = null; + QSBMeteor qsbMeteor; + + bool MeteorMatches(MeteorController x) + { + qsbMeteor = QSBWorldSync.GetWorldFromUnity(x); + return qsbMeteor.ObjectId == qsbMeteorLauncher.MeteorId; + } + + if (__instance._meteorPool != null) + { + meteorController = __instance._meteorPool.Find(MeteorMatches); + if (meteorController != null) + { + meteorController.Initialize(__instance.transform, __instance._detectableField, __instance._detectableFluid); + } + } + else if (__instance._dynamicMeteorPool != null) + { + meteorController = __instance._dynamicMeteorPool.Find(MeteorMatches); + if (meteorController != null) + { + meteorController.Initialize(__instance.transform, null, null); + } + } + + if (meteorController != null) + { + var linearVelocity = __instance._parentBody.GetPointVelocity(__instance.transform.position) + (__instance.transform.TransformDirection(__instance._launchDirection) * qsbMeteorLauncher.LaunchSpeed); + var angularVelocity = __instance.transform.forward * 2f; + meteorController.Launch(null, __instance.transform.position, __instance.transform.rotation, linearVelocity, angularVelocity); + if (__instance._audioSector.ContainsOccupant(DynamicOccupant.Player)) + { + __instance._launchSource.pitch = Random.Range(0.4f, 0.6f); + __instance._launchSource.PlayOneShot(AudioType.BH_MeteorLaunch); + } + } + else + { + DebugLog.ToConsole($"{qsbMeteorLauncher.LogName} - could not find meteor {qsbMeteorLauncher.MeteorId} in pool", MessageType.Warning); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Impact))] + public static bool Impact(MeteorController __instance, + GameObject hitObject, Vector3 impactPoint, Vector3 impactVel) + { + __instance._intactRenderer.enabled = false; + __instance._impactLight.enabled = true; + __instance._impactLight.intensity = __instance._impactLightCurve.Evaluate(0f); + var rotation = Quaternion.LookRotation(impactVel); + foreach (var particleSystem in __instance._impactParticles) + { + particleSystem.transform.rotation = rotation; + particleSystem.Play(); + } + + __instance._impactSource.PlayOneShot(AudioType.BH_MeteorImpact); + foreach (var owCollider in __instance._owColliders) + { + owCollider.SetActivation(false); + } + + __instance._owRigidbody.MakeKinematic(); + __instance.transform.SetParent(hitObject.GetAttachedOWRigidbody().transform); + FragmentSurfaceProxy.UntrackMeteor(__instance); + FragmentCollisionProxy.UntrackMeteor(__instance); + __instance._ignoringCollisions = false; + __instance._hasImpacted = true; + __instance._impactTime = Time.time; + + var qsbMeteor = QSBWorldSync.GetWorldFromUnity(__instance); + if (QSBMeteor.IsSpecialImpact(hitObject)) + { + QSBEventManager.FireEvent(EventNames.QSBMeteorSpecialImpact, qsbMeteor); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(DetachableFragment), nameof(DetachableFragment.Detach))] + public static void Detach_Prefix(DetachableFragment __instance, out FragmentIntegrity __state) => + // this gets set to null in Detach, so store it here and and then restore it in postfix + __state = __instance._fragmentIntegrity; + + [HarmonyPostfix] + [HarmonyPatch(typeof(DetachableFragment), nameof(DetachableFragment.Detach))] + public static void Detach_Postfix(DetachableFragment __instance, FragmentIntegrity __state) => + __instance._fragmentIntegrity = __state; + + [HarmonyPrefix] + [HarmonyPatch(typeof(DebrisLeash), nameof(DebrisLeash.MoveByDistance))] + public static bool MoveByDistance(DebrisLeash __instance, + float distance) + { + if (__instance._detachableFragment == null || __instance._detachableFragment._fragmentIntegrity == null) + { + return true; + } + + var qsbFragment = QSBWorldSync.GetWorldFromUnity(__instance._detachableFragment._fragmentIntegrity); + + if (__instance.enabled) + { + var vector = __instance._attachedBody.GetPosition() - __instance._anchorBody.GetPosition(); + var d = Mathf.Min(distance, qsbFragment.LeashLength - vector.magnitude); + __instance._attachedBody.SetPosition(__instance._anchorBody.GetPosition() + (vector.normalized * d)); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(DebrisLeash), nameof(DebrisLeash.FixedUpdate))] + public static bool FixedUpdate(DebrisLeash __instance) + { + if (__instance._detachableFragment == null || __instance._detachableFragment._fragmentIntegrity == null) + { + return true; + } + + var qsbFragment = QSBWorldSync.GetWorldFromUnity(__instance._detachableFragment._fragmentIntegrity); + + if (!__instance._deccelerating) + { + var num = Vector3.Distance(__instance._attachedBody.GetPosition(), __instance._anchorBody.GetPosition()); + var num2 = Mathf.Pow(__instance._attachedBody.GetVelocity().magnitude, 2f) / (2f * __instance._deccel); + var vector = __instance._attachedBody.GetVelocity() - __instance._anchorBody.GetVelocity(); + if (num >= qsbFragment.LeashLength - num2 && vector.magnitude > 0.1f) + { + __instance._deccelerating = true; + return false; + } + } + else + { + var vector2 = __instance._attachedBody.GetVelocity() - __instance._anchorBody.GetVelocity(); + var velocityChange = -vector2.normalized * Mathf.Min(__instance._deccel * Time.deltaTime, vector2.magnitude); + if (velocityChange.magnitude < 0.01f) + { + __instance._attachedBody.SetVelocity(__instance._anchorBody.GetVelocity()); + __instance._deccelerating = false; + if (__instance._detachableFragment != null) + { + __instance._detachableFragment.ComeToRest(__instance._anchorBody); + } + + __instance.enabled = false; + return false; + } + + __instance._attachedBody.AddVelocityChange(velocityChange); + } + + return false; + } + } +} diff --git a/QSB/MeteorSync/Patches/MeteorServerPatches.cs b/QSB/MeteorSync/Patches/MeteorServerPatches.cs new file mode 100644 index 00000000..929fccf3 --- /dev/null +++ b/QSB/MeteorSync/Patches/MeteorServerPatches.cs @@ -0,0 +1,237 @@ +using HarmonyLib; +using QSB.Events; +using QSB.MeteorSync.WorldObjects; +using QSB.Patches; +using QSB.WorldSync; +using UnityEngine; + +namespace QSB.MeteorSync.Patches +{ + public class MeteorServerPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(MeteorLauncher), nameof(MeteorLauncher.FixedUpdate))] + public static bool FixedUpdate(MeteorLauncher __instance) + { + if (__instance._launchedMeteors != null) + { + for (var i = __instance._launchedMeteors.Count - 1; i >= 0; i--) + { + if (__instance._launchedMeteors[i] == null) + { + __instance._launchedMeteors.QuickRemoveAt(i); + } + else if (__instance._launchedMeteors[i].isSuspended) + { + __instance._meteorPool.Add(__instance._launchedMeteors[i]); + __instance._launchedMeteors.QuickRemoveAt(i); + } + } + } + + if (__instance._launchedDynamicMeteors != null) + { + for (var j = __instance._launchedDynamicMeteors.Count - 1; j >= 0; j--) + { + if (__instance._launchedDynamicMeteors[j] == null) + { + __instance._launchedDynamicMeteors.QuickRemoveAt(j); + } + else if (__instance._launchedDynamicMeteors[j].isSuspended) + { + __instance._dynamicMeteorPool.Add(__instance._launchedDynamicMeteors[j]); + __instance._launchedDynamicMeteors.QuickRemoveAt(j); + } + } + } + + if (__instance._initialized && Time.time > __instance._lastLaunchTime + __instance._launchDelay) + { + if (!__instance._areParticlesPlaying) + { + __instance._areParticlesPlaying = true; + foreach (var particleSystem in __instance._launchParticles) + { + particleSystem.Play(); + } + + var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity(__instance); + QSBEventManager.FireEvent(EventNames.QSBMeteorPreLaunch, qsbMeteorLauncher); + } + + if (Time.time > __instance._lastLaunchTime + __instance._launchDelay + 2.3f) + { + __instance.LaunchMeteor(); + __instance._lastLaunchTime = Time.time; + __instance._launchDelay = Random.Range(__instance._minInterval, __instance._maxInterval); + __instance._areParticlesPlaying = false; + foreach (var particleSystem in __instance._launchParticles) + { + particleSystem.Stop(); + } + } + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(MeteorLauncher), nameof(MeteorLauncher.LaunchMeteor))] + public static bool LaunchMeteor(MeteorLauncher __instance) + { + var flag = __instance._dynamicMeteorPool != null && (__instance._meteorPool == null || Random.value < __instance._dynamicProbability); + MeteorController meteorController = null; + if (!flag) + { + if (__instance._meteorPool.Count == 0) + { + Debug.LogWarning("MeteorLauncher is out of Meteors!", __instance); + } + else + { + meteorController = __instance._meteorPool[__instance._meteorPool.Count - 1]; + meteorController.Initialize(__instance.transform, __instance._detectableField, __instance._detectableFluid); + __instance._meteorPool.QuickRemoveAt(__instance._meteorPool.Count - 1); + __instance._launchedMeteors.Add(meteorController); + } + } + else + { + if (__instance._dynamicMeteorPool.Count == 0) + { + Debug.LogWarning("MeteorLauncher is out of Dynamic Meteors!", __instance); + } + else + { + meteorController = __instance._dynamicMeteorPool[__instance._dynamicMeteorPool.Count - 1]; + meteorController.Initialize(__instance.transform, null, null); + __instance._dynamicMeteorPool.QuickRemoveAt(__instance._dynamicMeteorPool.Count - 1); + __instance._launchedDynamicMeteors.Add(meteorController); + } + } + + if (meteorController != null) + { + var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity(__instance); + var qsbMeteor = QSBWorldSync.GetWorldFromUnity(meteorController); + + qsbMeteorLauncher.MeteorId = qsbMeteor.ObjectId; + qsbMeteorLauncher.LaunchSpeed = Random.Range(__instance._minLaunchSpeed, __instance._maxLaunchSpeed); + + var linearVelocity = __instance._parentBody.GetPointVelocity(__instance.transform.position) + (__instance.transform.TransformDirection(__instance._launchDirection) * qsbMeteorLauncher.LaunchSpeed); + var angularVelocity = __instance.transform.forward * 2f; + meteorController.Launch(null, __instance.transform.position, __instance.transform.rotation, linearVelocity, angularVelocity); + if (__instance._audioSector.ContainsOccupant(DynamicOccupant.Player)) + { + __instance._launchSource.pitch = Random.Range(0.4f, 0.6f); + __instance._launchSource.PlayOneShot(AudioType.BH_MeteorLaunch); + } + + QSBEventManager.FireEvent(EventNames.QSBMeteorLaunch, qsbMeteorLauncher); + } + + return false; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Impact))] + public static void Impact(MeteorController __instance, + GameObject hitObject, Vector3 impactPoint, Vector3 impactVel) + { + var qsbMeteor = QSBWorldSync.GetWorldFromUnity(__instance); + if (QSBMeteor.IsSpecialImpact(hitObject)) + { + QSBEventManager.FireEvent(EventNames.QSBMeteorSpecialImpact, qsbMeteor); + } + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(FragmentIntegrity), nameof(FragmentIntegrity.AddDamage))] + public static void AddDamage(FragmentIntegrity __instance, + float damage) + { + var qsbFragment = QSBWorldSync.GetWorldFromUnity(__instance); + QSBEventManager.FireEvent(EventNames.QSBFragmentDamage, qsbFragment, damage); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(DetachableFragment), nameof(DetachableFragment.Detach))] + public static void Detach_Prefix(DetachableFragment __instance, out FragmentIntegrity __state) => + // this gets set to null in Detach, so store it here and and then restore it in postfix + __state = __instance._fragmentIntegrity; + + [HarmonyPostfix] + [HarmonyPatch(typeof(DetachableFragment), nameof(DetachableFragment.Detach))] + public static void Detach_Postfix(DetachableFragment __instance, FragmentIntegrity __state) => + __instance._fragmentIntegrity = __state; + + [HarmonyPrefix] + [HarmonyPatch(typeof(DebrisLeash), nameof(DebrisLeash.MoveByDistance))] + public static bool MoveByDistance(DebrisLeash __instance, + float distance) + { + if (__instance._detachableFragment == null || __instance._detachableFragment._fragmentIntegrity == null) + { + return true; + } + + var qsbFragment = QSBWorldSync.GetWorldFromUnity(__instance._detachableFragment._fragmentIntegrity); + + if (__instance.enabled) + { + var vector = __instance._attachedBody.GetPosition() - __instance._anchorBody.GetPosition(); + var d = Mathf.Min(distance, qsbFragment.LeashLength - vector.magnitude); + __instance._attachedBody.SetPosition(__instance._anchorBody.GetPosition() + (vector.normalized * d)); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(DebrisLeash), nameof(DebrisLeash.FixedUpdate))] + public static bool FixedUpdate(DebrisLeash __instance) + { + if (__instance._detachableFragment == null || __instance._detachableFragment._fragmentIntegrity == null) + { + return true; + } + + var qsbFragment = QSBWorldSync.GetWorldFromUnity(__instance._detachableFragment._fragmentIntegrity); + + if (!__instance._deccelerating) + { + var num = Vector3.Distance(__instance._attachedBody.GetPosition(), __instance._anchorBody.GetPosition()); + var num2 = Mathf.Pow(__instance._attachedBody.GetVelocity().magnitude, 2f) / (2f * __instance._deccel); + var vector = __instance._attachedBody.GetVelocity() - __instance._anchorBody.GetVelocity(); + if (num >= qsbFragment.LeashLength - num2 && vector.magnitude > 0.1f) + { + __instance._deccelerating = true; + return false; + } + } + else + { + var vector2 = __instance._attachedBody.GetVelocity() - __instance._anchorBody.GetVelocity(); + var velocityChange = -vector2.normalized * Mathf.Min(__instance._deccel * Time.deltaTime, vector2.magnitude); + if (velocityChange.magnitude < 0.01f) + { + __instance._attachedBody.SetVelocity(__instance._anchorBody.GetVelocity()); + __instance._deccelerating = false; + if (__instance._detachableFragment != null) + { + __instance._detachableFragment.ComeToRest(__instance._anchorBody); + } + + __instance.enabled = false; + return false; + } + + __instance._attachedBody.AddVelocityChange(velocityChange); + } + + return false; + } + } +} diff --git a/QSB/MeteorSync/WorldObjects/QSBFragment.cs b/QSB/MeteorSync/WorldObjects/QSBFragment.cs new file mode 100644 index 00000000..bb95c0a6 --- /dev/null +++ b/QSB/MeteorSync/WorldObjects/QSBFragment.cs @@ -0,0 +1,38 @@ +using QSB.WorldSync; +using UnityEngine; + +namespace QSB.MeteorSync.WorldObjects +{ + public class QSBFragment : WorldObject + { + public override void Init(FragmentIntegrity attachedObject, int id) + { + ObjectId = id; + AttachedObject = attachedObject; + DetachableFragment = AttachedObject.GetComponent(); + + if (QSBCore.IsHost) + { + LeashLength = Random.Range(MeteorManager.WhiteHoleVolume._debrisDistMin, MeteorManager.WhiteHoleVolume._debrisDistMax); + // QSBCore.UnityEvents.FireOnNextUpdate(() => + // { + // AttachedObject._integrity = 0; + // AttachedObject.CallOnTakeDamage(); + // }); + } + } + + public DetachableFragment DetachableFragment; + public bool IsDetached => DetachableFragment != null && DetachableFragment._isDetached; + public bool IsThruWhiteHole => IsDetached && DetachableFragment._sector != null && + DetachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector; + public OWRigidbody RefBody => IsThruWhiteHole ? MeteorManager.WhiteHoleVolume._whiteHoleBody : Locator._brittleHollow._owRigidbody; + public OWRigidbody Body => IsDetached ? AttachedObject.transform.parent.parent.GetAttachedOWRigidbody() : null; + + /// what the leash length will be when we eventually detach and fall thru white hole + public float LeashLength; + + public void AddDamage(float damage) + => AttachedObject.AddDamage(damage); + } +} diff --git a/QSB/MeteorSync/WorldObjects/QSBMeteor.cs b/QSB/MeteorSync/WorldObjects/QSBMeteor.cs new file mode 100644 index 00000000..f3214007 --- /dev/null +++ b/QSB/MeteorSync/WorldObjects/QSBMeteor.cs @@ -0,0 +1,41 @@ +using QSB.WorldSync; +using UnityEngine; + +namespace QSB.MeteorSync.WorldObjects +{ + public class QSBMeteor : WorldObject + { + public override void Init(MeteorController attachedObject, int id) + { + ObjectId = id; + AttachedObject = attachedObject; + } + + public static bool IsSpecialImpact(GameObject go) => + go == Locator.GetPlayerCollider().gameObject || go == Locator.GetProbe()._anchor._collider.gameObject; + + public void SpecialImpact() + { + AttachedObject._intactRenderer.enabled = false; + AttachedObject._impactLight.enabled = true; + AttachedObject._impactLight.intensity = AttachedObject._impactLightCurve.Evaluate(0f); + foreach (var particleSystem in AttachedObject._impactParticles) + { + particleSystem.Play(); + } + + AttachedObject._impactSource.PlayOneShot(AudioType.BH_MeteorImpact); + foreach (var owCollider in AttachedObject._owColliders) + { + owCollider.SetActivation(false); + } + + AttachedObject._owRigidbody.MakeKinematic(); + FragmentSurfaceProxy.UntrackMeteor(AttachedObject); + FragmentCollisionProxy.UntrackMeteor(AttachedObject); + AttachedObject._ignoringCollisions = false; + AttachedObject._hasImpacted = true; + AttachedObject._impactTime = Time.time; + } + } +} diff --git a/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs b/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs new file mode 100644 index 00000000..a2321a5b --- /dev/null +++ b/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs @@ -0,0 +1,36 @@ +using QSB.WorldSync; + +namespace QSB.MeteorSync.WorldObjects +{ + public class QSBMeteorLauncher : WorldObject + { + public override void Init(MeteorLauncher attachedObject, int id) + { + ObjectId = id; + AttachedObject = attachedObject; + } + + public int MeteorId; + public float LaunchSpeed; + + public void PreLaunchMeteor() + { + foreach (var particleSystem in AttachedObject._launchParticles) + { + particleSystem.Play(); + } + } + + public void LaunchMeteor(int meteorId, float launchSpeed) + { + MeteorId = meteorId; + LaunchSpeed = launchSpeed; + + AttachedObject.LaunchMeteor(); + foreach (var particleSystem in AttachedObject._launchParticles) + { + particleSystem.Stop(); + } + } + } +} diff --git a/QSB/OrbSync/Events/OrbSlotEvent.cs b/QSB/OrbSync/Events/OrbSlotEvent.cs index 15b6bc81..d3b2e21e 100644 --- a/QSB/OrbSync/Events/OrbSlotEvent.cs +++ b/QSB/OrbSync/Events/OrbSlotEvent.cs @@ -13,7 +13,7 @@ namespace QSB.OrbSync.Events private void Handler(int slotId, int orbId, bool slotState) => SendEvent(CreateMessage(slotId, orbId, slotState)); - private OrbSlotMessage CreateMessage(int slotId, int orbId, bool slotState) => new OrbSlotMessage + private OrbSlotMessage CreateMessage(int slotId, int orbId, bool slotState) => new() { AboutId = LocalPlayerId, SlotId = slotId, diff --git a/QSB/OrbSync/Events/OrbUserEvent.cs b/QSB/OrbSync/Events/OrbUserEvent.cs index 77f8c1a9..1387be75 100644 --- a/QSB/OrbSync/Events/OrbUserEvent.cs +++ b/QSB/OrbSync/Events/OrbUserEvent.cs @@ -19,7 +19,7 @@ namespace QSB.OrbSync.Events private void Handler(int id) => SendEvent(CreateMessage(id)); - private WorldObjectMessage CreateMessage(int id) => new WorldObjectMessage + private WorldObjectMessage CreateMessage(int id) => new() { AboutId = LocalPlayerId, ObjectId = id diff --git a/QSB/OrbSync/OrbManager.cs b/QSB/OrbSync/OrbManager.cs index 50c842fb..b25a315a 100644 --- a/QSB/OrbSync/OrbManager.cs +++ b/QSB/OrbSync/OrbManager.cs @@ -12,7 +12,7 @@ namespace QSB.OrbSync { public class OrbManager : WorldObjectManager { - private List _orbs = new List(); + private List _orbs = new(); protected override void RebuildWorldObjects(OWScene scene) { @@ -25,7 +25,7 @@ namespace QSB.OrbSync { QSBWorldSync.OldOrbList.Clear(); NomaiOrbTransformSync.OrbTransformSyncs.Clear(); - QSBWorldSync.OldOrbList = Resources.FindObjectsOfTypeAll().ToList(); + QSBWorldSync.OldOrbList = QSBWorldSync.GetUnityObjects().ToList(); if (QSBCore.IsHost) { _orbs.ForEach(x => QNetworkServer.Destroy(x)); @@ -41,4 +41,4 @@ namespace QSB.OrbSync DebugLog.DebugWrite($"Finished orb build with {QSBWorldSync.OldOrbList.Count} orbs.", MessageType.Success); } } -} \ No newline at end of file +} diff --git a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs index a2060a79..f955aeb4 100644 --- a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs +++ b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs @@ -9,7 +9,7 @@ namespace QSB.OrbSync.TransformSync { internal class NomaiOrbTransformSync : UnsectoredTransformSync { - public static List OrbTransformSyncs = new List(); + public static List OrbTransformSyncs = new(); private int _index => OrbTransformSyncs.IndexOf(this); @@ -39,7 +39,7 @@ namespace QSB.OrbSync.TransformSync var originalParent = AttachedObject.GetAttachedOWRigidbody().GetOrigParent(); if (originalParent == Locator.GetRootTransform()) { - DebugLog.DebugWrite($"{_logName} with AttachedObject {AttachedObject.name} had it's original parent as SolarSystemRoot - Disabling..."); + DebugLog.DebugWrite($"{LogName} with AttachedObject {AttachedObject.name} had it's original parent as SolarSystemRoot - Disabling..."); enabled = false; OrbTransformSyncs[_index] = null; } diff --git a/QSB/Patches/QSBPatch.cs b/QSB/Patches/QSBPatch.cs index bf1f7af5..1841ab15 100644 --- a/QSB/Patches/QSBPatch.cs +++ b/QSB/Patches/QSBPatch.cs @@ -6,9 +6,6 @@ namespace QSB.Patches { public abstract QSBPatchTypes Type { get; } - public void DoPatches(Harmony instance) - { - instance.PatchAll(GetType()); - } + public void DoPatches(Harmony instance) => instance.PatchAll(GetType()); } } \ No newline at end of file diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index c0bb40f6..009b450b 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -1,27 +1,30 @@ using HarmonyLib; using OWML.Common; -using OWML.Utils; +using QSB.Anglerfish.Patches; using QSB.Animation.NPC.Patches; using QSB.Animation.Patches; using QSB.CampfireSync.Patches; using QSB.ConversationSync.Patches; using QSB.DeathSync.Patches; +using QSB.EchoesOfTheEye.LightSensorSync.Patches; using QSB.ElevatorSync.Patches; -using QSB.FrequencySync.Patches; using QSB.GeyserSync.Patches; using QSB.Inputs.Patches; using QSB.ItemSync.Patches; using QSB.LogSync.Patches; +using QSB.MeteorSync.Patches; using QSB.OrbSync.Patches; using QSB.Player.Patches; using QSB.PoolSync.Patches; using QSB.QuantumSync.Patches; using QSB.RoastingSync.Patches; +using QSB.SatelliteSync.Patches; using QSB.ShipSync.Patches; using QSB.StatueSync.Patches; using QSB.TimeSync.Patches; using QSB.Tools.ProbeLauncherTool.Patches; -using QSB.TranslationSync.Patches; +using QSB.Tools.SignalscopeTool.FrequencySync.Patches; +using QSB.Tools.TranslatorTool.TranslationSync.Patches; using QSB.Utility; using System; using System.Collections.Generic; @@ -34,9 +37,10 @@ namespace QSB.Patches public static event Action OnPatchType; public static event Action OnUnpatchType; - private static List _patchList = new List(); + private static List _patchList = new(); + private static List _patchedTypes = new(); - public static Dictionary TypeToInstance = new Dictionary(); + public static Dictionary TypeToInstance = new(); public static void Init() { @@ -66,8 +70,14 @@ namespace QSB.Patches new InputPatches(), new TimePatches(), new MapPatches(), - new RespawnPatches(), - new LauncherPatches() + new LauncherPatches(), + new SolanumPatches(), + new SatelliteProjectorPatches(), + new LightSensorPatches(), + new AnglerPatches(), + new MeteorClientPatches(), + new MeteorServerPatches(), + new TravelerControllerPatches() }; TypeToInstance = new Dictionary @@ -83,6 +93,12 @@ namespace QSB.Patches public static void DoPatchType(QSBPatchTypes type) { + if (_patchedTypes.Contains(type)) + { + DebugLog.ToConsole($"Warning - Tried to patch type {type}, when it has already been patched!", MessageType.Warning); + return; + } + OnPatchType?.SafeInvoke(type); //DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); foreach (var patch in _patchList.Where(x => x.Type == type)) @@ -91,6 +107,7 @@ namespace QSB.Patches try { patch.DoPatches(TypeToInstance[type]); + _patchedTypes.Add(type); } catch (Exception ex) { @@ -101,9 +118,16 @@ namespace QSB.Patches public static void DoUnpatchType(QSBPatchTypes type) { + if (!_patchedTypes.Contains(type)) + { + DebugLog.ToConsole($"Warning - Tried to unpatch type {type}, when it is either unpatched or was never patched.", MessageType.Warning); + return; + } + OnUnpatchType?.SafeInvoke(type); //DebugLog.DebugWrite($"Unpatch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); TypeToInstance[type].UnpatchSelf(); + _patchedTypes.Remove(type); } } -} \ No newline at end of file +} diff --git a/QSB/Player/EnterLeaveType.cs b/QSB/Player/EnterLeaveType.cs index ef2bbf07..bd325137 100644 --- a/QSB/Player/EnterLeaveType.cs +++ b/QSB/Player/EnterLeaveType.cs @@ -8,9 +8,11 @@ ExitShrine = 3, EnterPlatform = 4, ExitPlatform = 5, - EnterHeadZone = 6, - ExitHeadZone = 7, + EnterNonNomaiHeadZone = 6, + ExitNonNomaiHeadZone = 7, EnterShip = 8, - ExitShip = 9 + ExitShip = 9, + EnterNomaiHeadZone = 10, + ExitNomaiHeadZone = 11 } } diff --git a/QSB/Player/Events/EnterLeaveEvent.cs b/QSB/Player/Events/EnterLeaveEvent.cs index ccd7c639..430ceec7 100644 --- a/QSB/Player/Events/EnterLeaveEvent.cs +++ b/QSB/Player/Events/EnterLeaveEvent.cs @@ -20,8 +20,10 @@ namespace QSB.Player.Events GlobalMessenger.AddListener(EventNames.QSBExitShrine, () => Handler(EnterLeaveType.ExitShrine)); GlobalMessenger.AddListener(EventNames.QSBEnterPlatform, (int id) => Handler(EnterLeaveType.EnterPlatform, id)); GlobalMessenger.AddListener(EventNames.QSBExitPlatform, (int id) => Handler(EnterLeaveType.ExitPlatform, id)); - GlobalMessenger.AddListener(EventNames.QSBEnterHeadZone, (int id) => Handler(EnterLeaveType.EnterHeadZone, id)); - GlobalMessenger.AddListener(EventNames.QSBExitHeadZone, (int id) => Handler(EnterLeaveType.ExitHeadZone, id)); + GlobalMessenger.AddListener(EventNames.QSBEnterNonNomaiHeadZone, (int id) => Handler(EnterLeaveType.EnterNonNomaiHeadZone, id)); + GlobalMessenger.AddListener(EventNames.QSBExitNonNomaiHeadZone, (int id) => Handler(EnterLeaveType.ExitNonNomaiHeadZone, id)); + GlobalMessenger.AddListener(EventNames.QSBEnterNomaiHeadZone, (int id) => Handler(EnterLeaveType.EnterNomaiHeadZone, id)); + GlobalMessenger.AddListener(EventNames.QSBExitNomaiHeadZone, (int id) => Handler(EnterLeaveType.ExitNomaiHeadZone, id)); GlobalMessenger.AddListener(EventNames.EnterShip, () => Handler(EnterLeaveType.EnterShip)); GlobalMessenger.AddListener(EventNames.ExitShip, () => Handler(EnterLeaveType.ExitShip)); } @@ -32,11 +34,17 @@ namespace QSB.Player.Events GlobalMessenger.RemoveListener(EventNames.ExitQuantumMoon, () => Handler(EnterLeaveType.ExitMoon)); GlobalMessenger.RemoveListener(EventNames.QSBEnterShrine, () => Handler(EnterLeaveType.EnterShrine)); GlobalMessenger.RemoveListener(EventNames.QSBExitShrine, () => Handler(EnterLeaveType.ExitShrine)); + GlobalMessenger.RemoveListener(EventNames.QSBEnterPlatform, (int id) => Handler(EnterLeaveType.EnterPlatform, id)); + GlobalMessenger.RemoveListener(EventNames.QSBExitPlatform, (int id) => Handler(EnterLeaveType.ExitPlatform, id)); + GlobalMessenger.RemoveListener(EventNames.QSBEnterNonNomaiHeadZone, (int id) => Handler(EnterLeaveType.EnterNonNomaiHeadZone, id)); + GlobalMessenger.RemoveListener(EventNames.QSBExitNonNomaiHeadZone, (int id) => Handler(EnterLeaveType.ExitNonNomaiHeadZone, id)); + GlobalMessenger.RemoveListener(EventNames.EnterShip, () => Handler(EnterLeaveType.EnterShip)); + GlobalMessenger.RemoveListener(EventNames.ExitShip, () => Handler(EnterLeaveType.ExitShip)); } private void Handler(EnterLeaveType type, int objectId = -1) => SendEvent(CreateMessage(type, objectId)); - private EnumWorldObjectMessage CreateMessage(EnterLeaveType type, int objectId) => new EnumWorldObjectMessage + private EnumWorldObjectMessage CreateMessage(EnterLeaveType type, int objectId) => new() { AboutId = LocalPlayerId, EnumValue = type, @@ -71,12 +79,18 @@ namespace QSB.Player.Events CustomNomaiRemoteCameraPlatform.CustomPlatformList[message.ObjectId] .OnRemotePlayerExit(message.AboutId); break; - case EnterLeaveType.EnterHeadZone: + case EnterLeaveType.EnterNonNomaiHeadZone: QSBWorldSync.GetWorldFromId(message.ObjectId).AddPlayerToHeadZone(player); break; - case EnterLeaveType.ExitHeadZone: + case EnterLeaveType.ExitNonNomaiHeadZone: QSBWorldSync.GetWorldFromId(message.ObjectId).RemovePlayerFromHeadZone(player); break; + case EnterLeaveType.EnterNomaiHeadZone: + QSBWorldSync.GetWorldFromId(message.ObjectId).AddPlayerToHeadZone(player); + break; + case EnterLeaveType.ExitNomaiHeadZone: + QSBWorldSync.GetWorldFromId(message.ObjectId).RemovePlayerFromHeadZone(player); + break; case EnterLeaveType.EnterShip: ShipManager.Instance.AddPlayerToShip(player); break; diff --git a/QSB/Player/Events/LaunchCodesEvent.cs b/QSB/Player/Events/LaunchCodesEvent.cs new file mode 100644 index 00000000..b305500f --- /dev/null +++ b/QSB/Player/Events/LaunchCodesEvent.cs @@ -0,0 +1,40 @@ +using QSB.Events; +using QSB.Messaging; + +namespace QSB.Player.Events +{ + internal class LaunchCodesEvent : QSBEvent + { + public override EventType Type => EventType.LaunchCodes; + + public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBLearnLaunchCodes, Handler); + public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBLearnLaunchCodes, Handler); + + private void Handler() => SendEvent(CreateMessage()); + + private PlayerMessage CreateMessage() => new() + { + AboutId = LocalPlayerId + }; + + public override void OnReceiveRemote(bool isHost, PlayerMessage message) + { + var flag = false; + if (!PlayerData._currentGameSave.PersistentConditionExists("LAUNCH_CODES_GIVEN")) + { + flag = true; + } + else if (PlayerData._currentGameSave.GetPersistentCondition("LAUNCH_CODES_GIVEN")) + { + flag = true; + } + + if (flag) + { + DialogueConditionManager.SharedInstance.SetConditionState("SCIENTIST_3", true); + PlayerData._currentGameSave.SetPersistentCondition("LAUNCH_CODES_GIVEN", true); + GlobalMessenger.FireEvent("LearnLaunchCodes"); + } + } + } +} diff --git a/QSB/Player/Events/PlayerEntangledEvent.cs b/QSB/Player/Events/PlayerEntangledEvent.cs index 047f6d9e..6e2ee698 100644 --- a/QSB/Player/Events/PlayerEntangledEvent.cs +++ b/QSB/Player/Events/PlayerEntangledEvent.cs @@ -14,7 +14,7 @@ namespace QSB.Player.Events private void Handler(int id) => SendEvent(CreateMessage(id)); - private WorldObjectMessage CreateMessage(int id) => new WorldObjectMessage + private WorldObjectMessage CreateMessage(int id) => new() { AboutId = LocalPlayerId, ObjectId = id diff --git a/QSB/Player/Events/PlayerInformationEvent.cs b/QSB/Player/Events/PlayerInformationEvent.cs index 89e0ba55..bd6c0c04 100644 --- a/QSB/Player/Events/PlayerInformationEvent.cs +++ b/QSB/Player/Events/PlayerInformationEvent.cs @@ -13,11 +13,17 @@ namespace QSB.Player.Events private void Handler() => SendEvent(CreateMessage(QSBPlayerManager.LocalPlayer)); - private PlayerInformationMessage CreateMessage(PlayerInfo player) => new PlayerInformationMessage + private PlayerInformationMessage CreateMessage(PlayerInfo player) => new() { AboutId = player.PlayerId, PlayerName = player.Name, - PlayerState = player.PlayerStates, + IsReady = player.IsReady, + FlashlightActive = player.FlashlightActive, + SuitedUp = player.SuitedUp, + ProbeLauncherEquipped = player.ProbeLauncherEquipped, + SignalscopeEquipped = player.SignalscopeEquipped, + TranslatorEquipped = player.TranslatorEquipped, + ProbeActive = player.ProbeActive, ClientState = player.State }; diff --git a/QSB/Player/Events/PlayerInformationMessage.cs b/QSB/Player/Events/PlayerInformationMessage.cs index 851a7b31..a088a33f 100644 --- a/QSB/Player/Events/PlayerInformationMessage.cs +++ b/QSB/Player/Events/PlayerInformationMessage.cs @@ -7,23 +7,26 @@ namespace QSB.Player.Events public class PlayerInformationMessage : PlayerMessage { public string PlayerName { get; set; } - public PlayerState PlayerState { get; set; } + public bool IsReady { get; set; } + public bool FlashlightActive { get; set; } + public bool SuitedUp { get; set; } + public bool ProbeLauncherEquipped { get; set; } + public bool SignalscopeEquipped { get; set; } + public bool TranslatorEquipped { get; set; } + public bool ProbeActive { get; set; } public ClientState ClientState { get; set; } public override void Deserialize(QNetworkReader reader) { base.Deserialize(reader); PlayerName = reader.ReadString(); - PlayerState = new PlayerState - { - IsReady = reader.ReadBoolean(), - FlashlightActive = reader.ReadBoolean(), - SuitedUp = reader.ReadBoolean(), - ProbeLauncherEquipped = reader.ReadBoolean(), - SignalscopeEquipped = reader.ReadBoolean(), - TranslatorEquipped = reader.ReadBoolean(), - ProbeActive = reader.ReadBoolean() - }; + IsReady = reader.ReadBoolean(); + FlashlightActive = reader.ReadBoolean(); + SuitedUp = reader.ReadBoolean(); + ProbeLauncherEquipped = reader.ReadBoolean(); + SignalscopeEquipped = reader.ReadBoolean(); + TranslatorEquipped = reader.ReadBoolean(); + ProbeActive = reader.ReadBoolean(); ClientState = (ClientState)reader.ReadInt32(); } @@ -31,13 +34,13 @@ namespace QSB.Player.Events { base.Serialize(writer); writer.Write(PlayerName); - writer.Write(PlayerState.IsReady); - writer.Write(PlayerState.FlashlightActive); - writer.Write(PlayerState.SuitedUp); - writer.Write(PlayerState.ProbeLauncherEquipped); - writer.Write(PlayerState.SignalscopeEquipped); - writer.Write(PlayerState.TranslatorEquipped); - writer.Write(PlayerState.ProbeActive); + writer.Write(IsReady); + writer.Write(FlashlightActive); + writer.Write(SuitedUp); + writer.Write(ProbeLauncherEquipped); + writer.Write(SignalscopeEquipped); + writer.Write(TranslatorEquipped); + writer.Write(ProbeActive); writer.Write((int)ClientState); } } diff --git a/QSB/Player/Events/PlayerJoinEvent.cs b/QSB/Player/Events/PlayerJoinEvent.cs index 7a3f0149..91a21d39 100644 --- a/QSB/Player/Events/PlayerJoinEvent.cs +++ b/QSB/Player/Events/PlayerJoinEvent.cs @@ -13,7 +13,7 @@ namespace QSB.Player.Events private void Handler(string name) => SendEvent(CreateMessage(name)); - private PlayerJoinMessage CreateMessage(string name) => new PlayerJoinMessage + private PlayerJoinMessage CreateMessage(string name) => new() { AboutId = LocalPlayerId, PlayerName = name, @@ -70,7 +70,7 @@ namespace QSB.Player.Events if (QSBSceneManager.IsInUniverse) { - QSBPlayerManager.LocalPlayer.PlayerStates.IsReady = true; + QSBPlayerManager.LocalPlayer.IsReady = true; QSBEventManager.FireEvent(EventNames.QSBPlayerReady, true); } } diff --git a/QSB/Player/Events/PlayerKickEvent.cs b/QSB/Player/Events/PlayerKickEvent.cs index ad4216d8..18cf0fd4 100644 --- a/QSB/Player/Events/PlayerKickEvent.cs +++ b/QSB/Player/Events/PlayerKickEvent.cs @@ -16,7 +16,7 @@ namespace QSB.Player.Events private void Handler(uint player, KickReason reason) => SendEvent(CreateMessage(player, reason)); - private EnumMessage CreateMessage(uint player, KickReason reason) => new EnumMessage + private EnumMessage CreateMessage(uint player, KickReason reason) => new() { AboutId = player, EnumValue = reason diff --git a/QSB/Player/Events/PlayerReadyEvent.cs b/QSB/Player/Events/PlayerReadyEvent.cs index 88b147b9..ef429883 100644 --- a/QSB/Player/Events/PlayerReadyEvent.cs +++ b/QSB/Player/Events/PlayerReadyEvent.cs @@ -14,7 +14,7 @@ namespace QSB.Player.Events private void Handler(bool ready) => SendEvent(CreateMessage(ready)); - private ToggleMessage CreateMessage(bool ready) => new ToggleMessage + private ToggleMessage CreateMessage(bool ready) => new() { AboutId = LocalPlayerId, ToggleValue = ready @@ -35,7 +35,7 @@ namespace QSB.Player.Events private static void HandleServer(ToggleMessage message) { DebugLog.DebugWrite($"[SERVER] Get ready event from {message.FromId}", MessageType.Success); - QSBPlayerManager.GetPlayer(message.AboutId).PlayerStates.IsReady = message.ToggleValue; + QSBPlayerManager.GetPlayer(message.AboutId).IsReady = message.ToggleValue; QSBEventManager.FireEvent(EventNames.QSBPlayerInformation); } diff --git a/QSB/Player/Events/RequestStateResyncEvent.cs b/QSB/Player/Events/RequestStateResyncEvent.cs index 9350e835..8496637a 100644 --- a/QSB/Player/Events/RequestStateResyncEvent.cs +++ b/QSB/Player/Events/RequestStateResyncEvent.cs @@ -3,9 +3,10 @@ using QSB.CampfireSync.WorldObjects; using QSB.ClientServerStateSync; using QSB.Events; using QSB.Messaging; +using QSB.MeteorSync.WorldObjects; using QSB.QuantumSync; -using QSB.TranslationSync; -using QSB.TranslationSync.WorldObjects; +using QSB.Tools.TranslatorTool.TranslationSync; +using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; using System.Linq; @@ -22,7 +23,7 @@ namespace QSB.Player.Events private void Handler() => SendEvent(CreateMessage()); - private PlayerMessage CreateMessage() => new PlayerMessage + private PlayerMessage CreateMessage() => new() { AboutId = LocalPlayerId }; @@ -79,6 +80,9 @@ namespace QSB.Player.Events QSBWorldSync.GetWorldObjects().ForEach(campfire => QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState())); + + QSBWorldSync.GetWorldObjects().ForEach(fragment + => QSBEventManager.FireEvent(EventNames.QSBFragmentResync, fragment)); } } } diff --git a/QSB/Player/Patches/PlayerPatches.cs b/QSB/Player/Patches/PlayerPatches.cs index 383ebaba..895ae5b0 100644 --- a/QSB/Player/Patches/PlayerPatches.cs +++ b/QSB/Player/Patches/PlayerPatches.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using QSB.Events; using QSB.Patches; namespace QSB.Player.Patches @@ -21,6 +22,32 @@ namespace QSB.Player.Patches [HarmonyPrefix] [HarmonyPatch(typeof(PauseMenuManager), nameof(PauseMenuManager.OnExitToMainMenu))] public static void PauseMenuManager_OnExitToMainMenu() - => QSBPlayerManager.LocalPlayer.PlayerStates.IsReady = false; + => QSBPlayerManager.LocalPlayer.IsReady = false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.LearnLaunchCodes))] + public static bool LearnLaunchCodes() + { + var flag = false; + if (!PlayerData._currentGameSave.PersistentConditionExists("LAUNCH_CODES_GIVEN")) + { + flag = true; + } + + else if (PlayerData._currentGameSave.GetPersistentCondition("LAUNCH_CODES_GIVEN")) + { + flag = true; + } + + if (flag) + { + DialogueConditionManager.SharedInstance.SetConditionState("SCIENTIST_3", true); + PlayerData._currentGameSave.SetPersistentCondition("LAUNCH_CODES_GIVEN", true); + GlobalMessenger.FireEvent("LearnLaunchCodes"); + QSBEventManager.FireEvent(EventNames.QSBLearnLaunchCodes); + } + + return false; + } } } diff --git a/QSB/Player/PlayerEntanglementWatcher.cs b/QSB/Player/PlayerEntanglementWatcher.cs index 77479a1a..8fa44700 100644 --- a/QSB/Player/PlayerEntanglementWatcher.cs +++ b/QSB/Player/PlayerEntanglementWatcher.cs @@ -27,7 +27,7 @@ namespace QSB.Player if (_previousCollidingQuantumObject != collidingQuantumObject) { var objectIndex = (collidingQuantumObject != null) - ? QSBWorldSync.GetIdFromTypeSubset(QuantumManager.GetObject(collidingQuantumObject)) + ? QSBWorldSync.GetIdFromTypeSubset((IQSBQuantumObject)QSBWorldSync.GetWorldFromUnity(collidingQuantumObject)) : -1; QSBEventManager.FireEvent( diff --git a/QSB/Player/PlayerHUDMarker.cs b/QSB/Player/PlayerHUDMarker.cs index 9835b3da..30f4d5a1 100644 --- a/QSB/Player/PlayerHUDMarker.cs +++ b/QSB/Player/PlayerHUDMarker.cs @@ -16,7 +16,7 @@ namespace QSB.Player _markerTarget = new GameObject().transform; _markerTarget.parent = transform; - _markerTarget.localPosition = Vector3.up * 2; + _markerTarget.localPosition = Vector3.up * 0.25f; } public void Init(PlayerInfo player) @@ -34,7 +34,7 @@ namespace QSB.Player Initialize(); } - if (!_isReady || !_player.PlayerStates.IsReady) + if (!_isReady || !_player.IsReady) { return; } diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index 9d8430a9..1b51d7a8 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -3,12 +3,15 @@ using QSB.Animation.Player; using QSB.Animation.Player.Thrusters; using QSB.CampfireSync.WorldObjects; using QSB.ClientServerStateSync; +using QSB.Events; +using QSB.ItemSync.WorldObjects.Items; using QSB.Player.TransformSync; -using QSB.ProbeSync; using QSB.QuantumSync; using QSB.RoastingSync; using QSB.Tools; +using QSB.Tools.FlashlightTool; using QSB.Tools.ProbeLauncherTool; +using QSB.Tools.ProbeTool; using QSB.Utility; using System.Linq; using UnityEngine; @@ -20,7 +23,6 @@ namespace QSB.Player public uint PlayerId { get; } public string Name { get; set; } public PlayerHUDMarker HudMarker { get; set; } - public PlayerState PlayerStates { get; set; } = new PlayerState(); public PlayerTransformSync TransformSync { get; set; } // Body Objects @@ -28,10 +30,11 @@ namespace QSB.Player { get { - if (_camera == null && PlayerStates.IsReady) + if (_camera == null && IsReady) { DebugLog.ToConsole($"Warning - {PlayerId}.Camera is null!", MessageType.Warning); } + return _camera; } set @@ -40,6 +43,7 @@ namespace QSB.Player { DebugLog.ToConsole($"Warning - Setting {PlayerId}.Camera to null.", MessageType.Warning); } + _camera = value; } } @@ -50,10 +54,11 @@ namespace QSB.Player { get { - if (_body == null && PlayerStates.IsReady) + if (_body == null && IsReady) { DebugLog.ToConsole($"Warning - {PlayerId}.Body is null!", MessageType.Warning); } + return _body; } set @@ -62,6 +67,7 @@ namespace QSB.Player { DebugLog.ToConsole($"Warning - Setting {PlayerId}.Body to null.", MessageType.Warning); } + _body = value; } } @@ -93,8 +99,13 @@ namespace QSB.Player public Transform SharedStoneSocket => CameraBody.transform.Find("REMOTE_SharedStoneSocket"); public Transform WarpCoreSocket => CameraBody.transform.Find("REMOTE_WarpCoreSocket"); public Transform VesselCoreSocket => CameraBody.transform.Find("REMOTE_VesselCoreSocket"); + public Transform SimpleLanternSocket => CameraBody.transform.Find("REMOTE_SimpleLanternSocket"); + public Transform DreamLanternSocket => CameraBody.transform.Find("REMOTE_DreamLanternSocket"); + public Transform SlideReelSocket => CameraBody.transform.Find("REMOTE_SlideReelSocket"); + public Transform VisionTorchSocket => CameraBody.transform.Find("REMOTE_VisionTorchSocket"); public QSBMarshmallow Marshmallow { get; set; } public QSBCampfire Campfire { get; set; } + public IQSBOWItem HeldItem { get; set; } // Conversation public int CurrentCharacterDialogueTreeId { get; set; } @@ -102,16 +113,23 @@ namespace QSB.Player // Animation public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject(PlayerId); - public bool PlayingInstrument => AnimationSync.CurrentType != AnimationType.PlayerSuited - && AnimationSync.CurrentType != AnimationType.PlayerUnsuited; + public bool PlayingInstrument => AnimationSync.CurrentType is not AnimationType.PlayerSuited + and not AnimationType.PlayerUnsuited; public JetpackAccelerationSync JetpackAcceleration { get; set; } // Misc + public bool IsReady { get; set; } public bool IsInMoon; // MOVE : move into PlayerStates? public bool IsInShrine; // MOVE : move into PlayerStates? public IQSBQuantumObject EntangledObject; public bool IsDead { get; set; } public ClientState State { get; set; } + public bool FlashlightActive { get; set; } + public bool SuitedUp { get; set; } + public bool ProbeLauncherEquipped { get; set; } + public bool SignalscopeEquipped { get; set; } + public bool TranslatorEquipped { get; set; } + public bool ProbeActive { get; set; } // Local only public PlayerProbeLauncher LocalProbeLauncher @@ -176,19 +194,35 @@ namespace QSB.Player CurrentCharacterDialogueTreeId = -1; } - public void UpdateStateObjects() + public void UpdateObjectsFromStates() { if (OWInput.GetInputMode() == InputMode.None) { return; } - FlashLight?.UpdateState(PlayerStates.FlashlightActive); - Translator?.ChangeEquipState(PlayerStates.TranslatorEquipped); - ProbeLauncher?.ChangeEquipState(PlayerStates.ProbeLauncherEquipped); - Signalscope?.ChangeEquipState(PlayerStates.SignalscopeEquipped); + FlashLight?.UpdateState(FlashlightActive); + Translator?.ChangeEquipState(TranslatorEquipped); + ProbeLauncher?.ChangeEquipState(ProbeLauncherEquipped); + Signalscope?.ChangeEquipState(SignalscopeEquipped); QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.GetSyncObject(PlayerId) != null, - () => QSBPlayerManager.GetSyncObject(PlayerId).SetSuitState(PlayerStates.SuitedUp)); + () => QSBPlayerManager.GetSyncObject(PlayerId).SetSuitState(SuitedUp)); + } + + public void UpdateStatesFromObjects() + { + if (Locator.GetFlashlight() == null || Locator.GetPlayerBody() == null) + { + FlashlightActive = false; + SuitedUp = false; + } + else + { + FlashlightActive = Locator.GetFlashlight()._flashlightOn; + SuitedUp = Locator.GetPlayerBody().GetComponent().IsWearingSuit(true); + } + + QSBEventManager.FireEvent(EventNames.QSBPlayerInformation); } private QSBTool GetToolByType(ToolType type) => CameraBody?.GetComponentsInChildren() diff --git a/QSB/Player/PlayerState.cs b/QSB/Player/PlayerState.cs deleted file mode 100644 index 0d0efb4a..00000000 --- a/QSB/Player/PlayerState.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace QSB.Player -{ - public class PlayerState - { - public bool IsReady { get; set; } - - public bool FlashlightActive { get; set; } - public bool SuitedUp { get; set; } - public bool ProbeLauncherEquipped { get; set; } - public bool SignalscopeEquipped { get; set; } - public bool TranslatorEquipped { get; set; } - public bool ProbeActive { get; set; } - } -} diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 377b1ef4..35fb95fb 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -1,7 +1,8 @@ using OWML.Common; +using QSB.ItemSync.WorldObjects.Items; using QSB.Player.Events; using QSB.Player.TransformSync; -using QSB.Tools; +using QSB.Tools.FlashlightTool; using QSB.Utility; using System; using System.Collections.Generic; @@ -40,11 +41,11 @@ namespace QSB.Player public static PlayerInfo LocalPlayer => GetPlayer(LocalPlayerId); public static List PlayerList { get; } = new List(); - private static readonly List PlayerSyncObjects = new List(); + private static readonly List PlayerSyncObjects = new(); public static PlayerInfo GetPlayer(uint id) { - if (id == uint.MaxValue || id == 0U) + if (id is uint.MaxValue or 0U) { return default; } @@ -61,7 +62,7 @@ namespace QSB.Player return default; } - DebugLog.DebugWrite($"Create Player : id<{id}> Stacktrace :\r\n{Environment.StackTrace}", MessageType.Info); + DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info); player = new PlayerInfo(id); PlayerList.Add(player); OnAddPlayer?.Invoke(id); @@ -70,7 +71,7 @@ namespace QSB.Player public static void RemovePlayer(uint id) { - DebugLog.DebugWrite($"Remove Player : id<{id}> Stacktrace :\r\n{Environment.StackTrace}", MessageType.Info); + DebugLog.DebugWrite($"Remove Player : id<{id}>", MessageType.Info); PlayerList.RemoveAll(x => x.PlayerId == id); } @@ -81,10 +82,16 @@ namespace QSB.Player { var player = GetPlayer(message.AboutId); player.Name = message.PlayerName; - player.PlayerStates = message.PlayerState; - if (LocalPlayer.PlayerStates.IsReady) + player.IsReady = message.IsReady; + player.FlashlightActive = message.FlashlightActive; + player.SuitedUp = message.SuitedUp; + player.ProbeLauncherEquipped = message.ProbeLauncherEquipped; + player.SignalscopeEquipped = message.SignalscopeEquipped; + player.TranslatorEquipped = message.TranslatorEquipped; + player.ProbeActive = message.ProbeActive; + if (LocalPlayer.IsReady) { - player.UpdateStateObjects(); + player.UpdateObjectsFromStates(); } player.State = message.ClientState; @@ -128,7 +135,7 @@ namespace QSB.Player } public static Tuple> GetPlayerFlashlights() - => new Tuple>(Locator.GetFlashlight(), PlayerList.Where(x => x.FlashLight != null).Select(x => x.FlashLight)); + => new(Locator.GetFlashlight(), PlayerList.Where(x => x.FlashLight != null).Select(x => x.FlashLight)); public static void ShowAllPlayers() => PlayerList.Where(x => x != LocalPlayer).ToList().ForEach(x => ChangePlayerVisibility(x.PlayerId, true)); @@ -139,6 +146,8 @@ namespace QSB.Player public static void ChangePlayerVisibility(uint playerId, bool visible) { var player = GetPlayer(playerId); + player.Visible = visible; + if (player.Body == null) { DebugLog.ToConsole($"Warning - Player {playerId} has a null player model!", MessageType.Warning); @@ -149,8 +158,6 @@ namespace QSB.Player { renderer.enabled = visible; } - - player.Visible = visible; } public static PlayerInfo GetClosestPlayerToWorldPoint(Vector3 worldPoint, bool includeLocalPlayer) => includeLocalPlayer @@ -171,7 +178,10 @@ namespace QSB.Player return null; } - return playerList.Where(x => x.PlayerStates.IsReady).OrderBy(x => Vector3.Distance(x.Body.transform.position, worldPoint)).FirstOrDefault(); + return playerList.Where(x => x.IsReady).OrderBy(x => Vector3.Distance(x.Body.transform.position, worldPoint)).FirstOrDefault(); } + + public static IEnumerable> GetPlayerCarryItems() + => PlayerList.Select(x => new Tuple(x, x.HeldItem)); } } \ No newline at end of file diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index 8d117c4e..174eb779 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -40,7 +40,7 @@ namespace QSB.Player.TransformSync protected Quaternion _roastingRotationVelocity; private Transform GetStickPivot() - => Resources.FindObjectsOfTypeAll().First().transform.Find("Stick_Root/Stick_Pivot"); + => QSBWorldSync.GetUnityObjects().First().transform.Find("Stick_Root/Stick_Pivot"); public override void OnStartLocalPlayer() => LocalInstance = this; @@ -60,12 +60,12 @@ namespace QSB.Player.TransformSync if (isInUniverse) { - Player.PlayerStates.IsReady = true; + Player.IsReady = true; QSBEventManager.FireEvent(EventNames.QSBPlayerReady, true); } else { - Player.PlayerStates.IsReady = false; + Player.IsReady = false; QSBEventManager.FireEvent(EventNames.QSBPlayerReady, false); } @@ -101,6 +101,8 @@ namespace QSB.Player.TransformSync Player.CameraBody = cameraBody.gameObject; _visibleCameraRoot = cameraBody; + PlayerToolsManager.InitLocal(); + // stick var pivot = GetStickPivot(); Player.RoastingStick = pivot.parent.gameObject; @@ -163,7 +165,7 @@ namespace QSB.Player.TransformSync * SET UP PLAYER CAMERA */ - PlayerToolsManager.Init(REMOTE_PlayerCamera.transform); + PlayerToolsManager.InitRemote(REMOTE_PlayerCamera.transform); var camera = REMOTE_PlayerCamera.AddComponent(); camera.enabled = false; @@ -248,11 +250,9 @@ namespace QSB.Player.TransformSync base.OnRenderObject(); if (!QSBCore.WorldObjectsReady - || !QSBCore.DebugMode || !QSBCore.ShowLinesInDebug || !IsReady - || ReferenceTransform == null - || _intermediaryTransform.GetReferenceTransform() == null) + || ReferenceTransform == null) { return; } @@ -275,4 +275,4 @@ namespace QSB.Player.TransformSync public override bool UseInterpolation => true; } -} \ No newline at end of file +} diff --git a/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs b/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs index d7ac3218..dd59607e 100644 --- a/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs +++ b/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs @@ -55,7 +55,7 @@ namespace QSB.PoolSync private bool _anyoneStillOnPlatform; private bool _wasLocalInBounds; private CameraState _cameraState; - private readonly Dictionary _playerToHologram = new Dictionary(); + private readonly Dictionary _playerToHologram = new(); private void Awake() { @@ -129,7 +129,7 @@ namespace QSB.PoolSync CustomPlatformList.Remove(this); } - if (_cameraState == CameraState.Connected || _cameraState == CameraState.Connecting_FadeIn || _cameraState == CameraState.Connecting_FadeOut) + if (_cameraState is CameraState.Connected or CameraState.Connecting_FadeIn or CameraState.Connecting_FadeOut) { DisconnectCamera(); SwitchToPlayerCamera(); @@ -231,7 +231,7 @@ namespace QSB.PoolSync _slavePlatform.UpdatePoolRenderer(); if (_slavePlatform._transitionFade == 1f) { - _slavePlatform._poolT = ((!(_slavePlatform._sharedStone == null)) ? 1f : 0f); + _slavePlatform._poolT = (!(_slavePlatform._sharedStone == null)) ? 1f : 0f; _slavePlatform._showPlayerRipples = false; _slavePlatform._activePlayerHolo = null; _slavePlatform.UpdatePoolRenderer(); @@ -550,7 +550,7 @@ namespace QSB.PoolSync } var cameraState = _cameraState; - if (cameraState != CameraState.Disconnected && cameraState != CameraState.Disconnecting_FadeOut) + if (cameraState is not CameraState.Disconnected and not CameraState.Disconnecting_FadeOut) { if (cameraState == CameraState.Disconnecting_FadeIn) { @@ -574,7 +574,7 @@ namespace QSB.PoolSync } var cameraState = _cameraState; - if (cameraState != CameraState.Connected && cameraState != CameraState.Connecting_FadeOut) + if (cameraState is not CameraState.Connected and not CameraState.Connecting_FadeOut) { if (cameraState == CameraState.Connecting_FadeIn) { diff --git a/QSB/PoolSync/PoolManager.cs b/QSB/PoolSync/PoolManager.cs index d5b93fe5..59edc022 100644 --- a/QSB/PoolSync/PoolManager.cs +++ b/QSB/PoolSync/PoolManager.cs @@ -1,5 +1,4 @@ using QSB.WorldSync; -using UnityEngine; namespace QSB.PoolSync { @@ -7,17 +6,17 @@ namespace QSB.PoolSync { protected override void RebuildWorldObjects(OWScene scene) { - foreach (var streaming in Resources.FindObjectsOfTypeAll()) + foreach (var streaming in QSBWorldSync.GetUnityObjects()) { streaming.gameObject.AddComponent(); } - foreach (var camera in Resources.FindObjectsOfTypeAll()) + foreach (var camera in QSBWorldSync.GetUnityObjects()) { camera.gameObject.AddComponent(); } - foreach (var platform in Resources.FindObjectsOfTypeAll()) + foreach (var platform in QSBWorldSync.GetUnityObjects()) { platform.gameObject.AddComponent(); } diff --git a/QSB/Properties/AssemblyInfo.cs b/QSB/Properties/AssemblyInfo.cs deleted file mode 100644 index e493bd04..00000000 --- a/QSB/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Quantum Space Buddies")] -[assembly: AssemblyDescription("Multiplayer mod for Outer Wilds")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Henry Pointer, Aleksander Waage, Ricardo Lopes")] -[assembly: AssemblyProduct("Quantum Space Buddies")] -[assembly: AssemblyCopyright("Copyright © Henry Pointer, Aleksander Waage, Ricardo Lopes 2020-2021")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("1f00090a-c697-4c55-b401-192f3cfb9dc2")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: NeutralResourcesLanguage("en-GB")] diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 294f9217..d352d868 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -1,340 +1,60 @@ - - - + - Debug - AnyCPU + Quantum Space Buddies + Multiplayer mod for Outer Wilds + Quantum Space Buddies + OnBuildSuccess {1F00090A-C697-4C55-B401-192F3CFB9DC2} - Library - Properties - QSB - QSB - v4.0 - 512 - true - - true full true - bin\Debug\ - DEBUG;TRACE - prompt - 4 - true pdbonly - true - bin\Release\ - TRACE - prompt - 4 - OnBuildSuccess + +:: copy output to unity project +copy /y "$(OutputPath)" $(UnityAssetsDir) +:: copy game assembly to unity project +copy /y "$(GameDir)\OuterWilds_Data\Managed\Assembly-CSharp.dll" $(UnityAssetsDir) +copy /y "$(GameDir)\OuterWilds_Data\Managed\Assembly-CSharp-firstpass.dll" $(UnityAssetsDir) +copy /y "$(GameDir)\OuterWilds_Data\Managed\Unity.InputSystem.dll" $(UnityAssetsDir) +copy /y "$(GameDir)\OuterWilds_Data\Managed\EOS-SDK.dll" $(UnityAssetsDir) +copy /y "$(GameDir)\OuterWilds_Data\Managed\UniSense.dll" $(UnityAssetsDir) + +:: copy owml files to unity project +copy /y "$(OwmlDir)\Autofac.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\Newtonsoft.Json.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\0Harmony.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\MonoMod.Utils.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\MonoMod.RuntimeDetour.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\Mono.Cecil.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\Mono.Cecil.Mdb.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\Mono.Cecil.Pdb.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\Mono.Cecil.Rocks.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\dnpatch.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\dnlib.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\Gameloop.Vdf.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\NAudio-Unity.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.Common.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.ModHelper.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.ModHelper.Assets.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.ModHelper.Events.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.ModHelper.Menus.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.ModHelper.Input.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.ModHelper.Interaction.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.Utils.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.Common.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.Logging.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.ModLoader.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.Patcher.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.GameFinder.dll" $(UnityAssetsDir) +copy /y "$(OwmlDir)\OWML.Abstractions.dll" $(UnityAssetsDir) + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Always @@ -343,107 +63,23 @@ - - $(GameDir)\OuterWilds_Data\Managed\publicized_assemblies\Assembly-CSharp_publicized.dll - - - $(GameDir)\OuterWilds_Data\Managed\Assembly-CSharp-firstpass.dll - - - $(GameDir)\OuterWilds_Data\Managed\netstandard.dll - - - ..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll - - + + ..\QSB\lib\UnityEngine.Networking.dll False - $(GameDir)\OuterWilds_Data\Managed\Unity.InputSystem.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.AnimationModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.AssetBundleModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.AudioModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.CoreModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.IMGUIModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.InputLegacyModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.InputModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.Networking.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.ParticleSystemModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.PhysicsModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.TextCoreModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.TextRenderingModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.UI.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.UIModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.UNETModule.dll + + + + - - {c8c53004-1508-4f86-a419-4292c188dc2a} - QuantumUNET - + + PreserveNewest + - + + Always + - - - 2.5.5 - - - 2.0.0 - - - - - md "$(OwmlDir)\Mods\$(ProjectName)" -md "$(OwmlDir)\Mods\$(ProjectName)\assets" -del "$(OwmlDir)\Mods\$(ProjectName)\config.json" - -copy /y "$(ProjectDir)\default-config.json" "$(OwmlDir)\Mods\$(ProjectName)" -copy /y "$(SolutionDir)\AssetBundles" "$(OwmlDir)\Mods\$(ProjectName)\assets" -copy /y "$(ProjectDir)\manifest.json" "$(OwmlDir)\Mods\$(ProjectName)" - -"$(SolutionDir)\QNetWeaver\bin\Debug\QNetWeaver.exe" "$(GameDir)\OuterWilds_Data\Managed\UnityEngine.CoreModule.dll" "$(OwmlDir)\Mods\$(ProjectName)\QuantumUNET.dll" "$(ProjectDir)\lib\UnityEngine.Networking.dll" "$(SolutionDir)\WeavedFiles" "$(TargetPath)" - -copy /y "$(SolutionDir)\WeavedFiles\QSB.dll" "$(OwmlDir)\Mods\$(ProjectName)" - -xcopy /y "$(ProjectDir)\lib" "$(OwmlDir)\Mods\$(ProjectName)" - - - - - - \ No newline at end of file diff --git a/QSB/QSB.csproj.user b/QSB/QSB.csproj.user deleted file mode 100644 index 7bf6c3df..00000000 --- a/QSB/QSB.csproj.user +++ /dev/null @@ -1,8 +0,0 @@ - - - - D:\EpicGames\OuterWilds - C:\Users\Henry\AppData\Roaming\OuterWildsModManager\OWML - ShowAllFiles - - diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index ef1c7bc0..8817793e 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -1,27 +1,32 @@ using OWML.Common; using OWML.ModHelper; using OWML.ModHelper.Input; +using QSB.Anglerfish; using QSB.Animation.NPC; using QSB.CampfireSync; using QSB.ConversationSync; -using QSB.DeathSync; +using QSB.EchoesOfTheEye.AirlockSync; +using QSB.EchoesOfTheEye.LightSensorSync; using QSB.ElevatorSync; using QSB.GeyserSync; using QSB.Inputs; using QSB.ItemSync; using QSB.Menus; +using QSB.MeteorSync; using QSB.OrbSync; using QSB.Patches; using QSB.Player; using QSB.Player.TransformSync; using QSB.PoolSync; using QSB.QuantumSync; +using QSB.RespawnSync; +using QSB.SatelliteSync; using QSB.SectorSync; using QSB.ShipSync; using QSB.StatueSync; using QSB.TimeSync; using QSB.Tools.ProbeLauncherTool; -using QSB.TranslationSync; +using QSB.Tools.TranslatorTool.TranslationSync; using QSB.Utility; using QSB.WorldSync; using QuantumUNET; @@ -31,10 +36,10 @@ using UnityEngine; /* Copyright (C) 2020 - 2021 - Henry Pointer (_nebula / misternebula), - Aleksander Waage (AmazingAlek), + Henry Pointer (_nebula / misternebula), + Aleksander Waage (AmazingAlek), Ricardo Lopes (Raicuparta) - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of @@ -55,8 +60,12 @@ namespace QSB public static IModUnityEvents UnityEvents => Helper.Events.Unity; public static string DefaultServerIP { get; private set; } public static int Port { get; private set; } - public static bool DebugMode { get; private set; } - public static bool ShowLinesInDebug { get; private set; } + public static bool DebugMode => DebugSettings.DebugMode; + public static bool ShowLinesInDebug => DebugMode && DebugSettings.DrawLines; + public static bool ShowQuantumVisibilityObjects => DebugMode && DebugSettings.ShowQuantumVisibilityObjects; + public static bool ShowQuantumDebugBoxes => DebugMode && DebugSettings.ShowQuantumDebugBoxes; + public static bool AvoidTimeSync => DebugMode && DebugSettings.AvoidTimeSync; + public static bool SkipTitleScreen => DebugMode && DebugSettings.SkipTitleScreen; public static AssetBundle NetworkAssetBundle { get; private set; } public static AssetBundle InstrumentAssetBundle { get; private set; } public static AssetBundle ConversationAssetBundle { get; private set; } @@ -71,6 +80,8 @@ namespace QSB : GamePlatform.Steam; public static IMenuAPI MenuApi { get; private set; } + private static DebugSettings DebugSettings { get; set; } = new DebugSettings(); + public void Awake() { var instance = TextTranslation.Get().m_table; @@ -85,10 +96,17 @@ namespace QSB MenuApi = ModHelper.Interaction.GetModApi("_nebula.MenuFramework"); - NetworkAssetBundle = Helper.Assets.LoadBundle("assets/network"); - InstrumentAssetBundle = Helper.Assets.LoadBundle("assets/instruments"); - ConversationAssetBundle = Helper.Assets.LoadBundle("assets/conversation"); - DebugAssetBundle = Helper.Assets.LoadBundle("assets/debug"); + NetworkAssetBundle = Helper.Assets.LoadBundle("AssetBundles/network"); + InstrumentAssetBundle = Helper.Assets.LoadBundle("AssetBundles/instruments"); + ConversationAssetBundle = Helper.Assets.LoadBundle("AssetBundles/conversation"); + DebugAssetBundle = Helper.Assets.LoadBundle("AssetBundles/debug"); + + DebugSettings = ModHelper.Storage.Load("debugsettings.json"); + + if (DebugSettings == null) + { + DebugSettings = new DebugSettings(); + } QSBPatchManager.Init(); @@ -102,6 +120,7 @@ namespace QSB gameObject.AddComponent(); gameObject.AddComponent(); gameObject.AddComponent(); + gameObject.AddComponent(); // WorldObject managers gameObject.AddComponent(); @@ -117,6 +136,10 @@ namespace QSB gameObject.AddComponent(); gameObject.AddComponent(); gameObject.AddComponent(); + gameObject.AddComponent(); + gameObject.AddComponent(); + gameObject.AddComponent(); + gameObject.AddComponent(); DebugBoxManager.Init(); @@ -157,9 +180,6 @@ namespace QSB { QSBNetworkManager.Instance.networkPort = Port; } - - DebugMode = config.GetSettingsValue("debugMode"); - ShowLinesInDebug = config.GetSettingsValue("showLinesInDebug"); } } } @@ -167,7 +187,7 @@ namespace QSB /* * _nebula's music thanks * I listen to music constantly while programming/working - here's my thanks to them for keeping me entertained :P - * + * * Wintergatan * HOME * C418 @@ -189,4 +209,4 @@ namespace QSB * Daft Punk * Natalie Holt * WMD - */ \ No newline at end of file + */ diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 65254a34..77f98ef2 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -1,18 +1,13 @@ using OWML.Common; using OWML.Utils; -using QSB.Animation.Player; -using QSB.Animation.Player.Thrusters; using QSB.ClientServerStateSync; using QSB.DeathSync; using QSB.Events; -using QSB.Instruments; using QSB.OrbSync.TransformSync; using QSB.Patches; using QSB.Player; using QSB.Player.TransformSync; using QSB.PoolSync; -using QSB.ProbeSync.TransformSync; -using QSB.ShipSync.TransformSync; using QSB.TimeSync; using QSB.Utility; using QSB.WorldSync; @@ -37,6 +32,7 @@ namespace QSB public bool IsReady { get; private set; } public GameObject OrbPrefab { get; private set; } public GameObject ShipPrefab { get; private set; } + public GameObject AnglerPrefab { get; private set; } public string PlayerName { get; private set; } private const int MaxConnections = 128; @@ -54,34 +50,20 @@ namespace QSB PlayerName = GetPlayerName(); _assetBundle = QSBCore.NetworkAssetBundle; - playerPrefab = _assetBundle.LoadAsset("assets/NETWORK_Player_Body.prefab"); - SetupNetworkId(playerPrefab, 1); - SetupNetworkTransform(playerPrefab); - playerPrefab.AddComponent(); - playerPrefab.AddComponent(); - playerPrefab.AddComponent(); - playerPrefab.AddComponent(); - playerPrefab.AddComponent(); - playerPrefab.AddComponent(); + playerPrefab = _assetBundle.LoadAsset("Assets/Prefabs/NETWORK_Player_Body.prefab"); - ShipPrefab = _assetBundle.LoadAsset("assets/networkship.prefab"); - SetupNetworkId(ShipPrefab, 2); - SetupNetworkTransform(ShipPrefab); - ShipPrefab.AddComponent(); + ShipPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkship.prefab"); spawnPrefabs.Add(ShipPrefab); - _probePrefab = _assetBundle.LoadAsset("assets/networkprobe.prefab"); - SetupNetworkId(_probePrefab, 3); - SetupNetworkTransform(_probePrefab); - _probePrefab.AddComponent(); + _probePrefab = _assetBundle.LoadAsset("assets/Prefabs/networkprobe.prefab"); spawnPrefabs.Add(_probePrefab); - OrbPrefab = _assetBundle.LoadAsset("assets/networkorb.prefab"); - SetupNetworkId(OrbPrefab, 4); - SetupNetworkTransform(OrbPrefab); - OrbPrefab.AddComponent(); + OrbPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkorb.prefab"); spawnPrefabs.Add(OrbPrefab); + AnglerPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkangler.prefab"); + spawnPrefabs.Add(AnglerPrefab); + ConfigureNetworkManager(); } @@ -102,29 +84,6 @@ namespace QSB } } - private void SetupNetworkId(GameObject go, int assetId) - { - var ident = go.AddComponent(); - ident.LocalPlayerAuthority = true; - var networkIdentity = go.GetComponent(); - ident.SetValue("m_AssetId", assetId); - ident.SetValue("m_SceneId", networkIdentity.GetComponent().sceneId); - } - - private void SetupNetworkTransform(GameObject go) - { - foreach (var item in go.GetComponents()) - { - var child = go.AddComponent(); - child.Target = item.target; - child.m_ChildIndex = item.childIndex; - Destroy(item); - } - - Destroy(go.GetComponent()); - Destroy(go.GetComponent()); - } - private void ConfigureNetworkManager() { networkAddress = QSBCore.DefaultServerIP; @@ -145,7 +104,7 @@ namespace QSB DebugLog.DebugWrite("OnStartServer", MessageType.Info); if (QSBWorldSync.OldDialogueTrees.Count == 0 && QSBSceneManager.IsInUniverse) { - QSBWorldSync.OldDialogueTrees = Resources.FindObjectsOfTypeAll().ToList(); + QSBWorldSync.OldDialogueTrees = QSBWorldSync.GetUnityObjects().ToList(); } } @@ -218,6 +177,11 @@ namespace QSB NomaiOrbTransformSync.OrbTransformSyncs.Clear(); QSBWorldSync.OldDialogueTrees.Clear(); + if (WakeUpSync.LocalInstance != null) + { + WakeUpSync.LocalInstance.OnDisconnect(); + } + if (_everConnected) { var specificType = QNetworkServer.active ? QSBPatchTypes.OnServerClientConnect : QSBPatchTypes.OnNonServerClientConnect; @@ -270,17 +234,17 @@ namespace QSB { QSBWorldSync.RemoveWorldObjects(); QSBWorldSync.RemoveWorldObjects(); - foreach (var platform in Resources.FindObjectsOfTypeAll()) + foreach (var platform in QSBWorldSync.GetUnityObjects()) { Destroy(platform); } - foreach (var camera in Resources.FindObjectsOfTypeAll()) + foreach (var camera in QSBWorldSync.GetUnityObjects()) { Destroy(camera); } - foreach (var streaming in Resources.FindObjectsOfTypeAll()) + foreach (var streaming in QSBWorldSync.GetUnityObjects()) { Destroy(streaming); } @@ -288,4 +252,4 @@ namespace QSB WorldObjectManager.SetNotReady(); } } -} \ No newline at end of file +} diff --git a/QSB/QSBSceneManager.cs b/QSB/QSBSceneManager.cs index e099d9e9..17377f0a 100644 --- a/QSB/QSBSceneManager.cs +++ b/QSB/QSBSceneManager.cs @@ -38,6 +38,6 @@ namespace QSB } private static bool InUniverse(OWScene scene) => - scene == OWScene.SolarSystem || scene == OWScene.EyeOfTheUniverse; + scene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse; } } \ No newline at end of file diff --git a/QSB/QuantumSync/Events/MoonStateChangeEvent.cs b/QSB/QuantumSync/Events/MoonStateChangeEvent.cs index 8b6919b0..44a73839 100644 --- a/QSB/QuantumSync/Events/MoonStateChangeEvent.cs +++ b/QSB/QuantumSync/Events/MoonStateChangeEvent.cs @@ -15,7 +15,7 @@ namespace QSB.QuantumSync.Events private void Handler(int stateIndex, Vector3 onUnitSphere, int orbitAngle) => SendEvent(CreateMessage(stateIndex, onUnitSphere, orbitAngle)); - private MoonStateChangeMessage CreateMessage(int stateIndex, Vector3 onUnitSphere, int orbitAngle) => new MoonStateChangeMessage + private MoonStateChangeMessage CreateMessage(int stateIndex, Vector3 onUnitSphere, int orbitAngle) => new() { AboutId = LocalPlayerId, StateIndex = stateIndex, diff --git a/QSB/QuantumSync/Events/MultiStateChangeEvent.cs b/QSB/QuantumSync/Events/MultiStateChangeEvent.cs index cc5ae231..22ff119a 100644 --- a/QSB/QuantumSync/Events/MultiStateChangeEvent.cs +++ b/QSB/QuantumSync/Events/MultiStateChangeEvent.cs @@ -15,7 +15,7 @@ namespace QSB.QuantumSync.Events private void Handler(int objid, int stateIndex) => SendEvent(CreateMessage(objid, stateIndex)); - private MultiStateChangeMessage CreateMessage(int objid, int stateIndex) => new MultiStateChangeMessage + private MultiStateChangeMessage CreateMessage(int objid, int stateIndex) => new() { AboutId = LocalPlayerId, ObjectId = objid, @@ -24,7 +24,7 @@ namespace QSB.QuantumSync.Events public override void OnReceiveLocal(bool server, MultiStateChangeMessage message) { - if (!QSBCore.DebugMode) + if (!QSBCore.ShowQuantumDebugBoxes) { return; } diff --git a/QSB/QuantumSync/Events/QuantumAuthorityEvent.cs b/QSB/QuantumSync/Events/QuantumAuthorityEvent.cs index ca14d361..5696779d 100644 --- a/QSB/QuantumSync/Events/QuantumAuthorityEvent.cs +++ b/QSB/QuantumSync/Events/QuantumAuthorityEvent.cs @@ -13,7 +13,7 @@ namespace QSB.QuantumSync.Events private void Handler(int objId, uint authorityOwner) => SendEvent(CreateMessage(objId, authorityOwner)); - private QuantumAuthorityMessage CreateMessage(int objId, uint authorityOwner) => new QuantumAuthorityMessage + private QuantumAuthorityMessage CreateMessage(int objId, uint authorityOwner) => new() { AboutId = LocalPlayerId, ObjectId = objId, diff --git a/QSB/QuantumSync/Events/QuantumShuffleEvent.cs b/QSB/QuantumSync/Events/QuantumShuffleEvent.cs index ba7d0454..9eb6f257 100644 --- a/QSB/QuantumSync/Events/QuantumShuffleEvent.cs +++ b/QSB/QuantumSync/Events/QuantumShuffleEvent.cs @@ -13,7 +13,7 @@ namespace QSB.QuantumSync.Events private void Handler(int objid, int[] indexArray) => SendEvent(CreateMessage(objid, indexArray)); - private QuantumShuffleMessage CreateMessage(int objid, int[] indexArray) => new QuantumShuffleMessage + private QuantumShuffleMessage CreateMessage(int objid, int[] indexArray) => new() { AboutId = LocalPlayerId, ObjectId = objid, diff --git a/QSB/QuantumSync/Events/SocketStateChangeEvent.cs b/QSB/QuantumSync/Events/SocketStateChangeEvent.cs index fae1d8a1..4130b420 100644 --- a/QSB/QuantumSync/Events/SocketStateChangeEvent.cs +++ b/QSB/QuantumSync/Events/SocketStateChangeEvent.cs @@ -16,7 +16,7 @@ namespace QSB.QuantumSync.Events private void Handler(int objid, int socketid, Quaternion localRotation) => SendEvent(CreateMessage(objid, socketid, localRotation)); - private SocketStateChangeMessage CreateMessage(int objid, int socketid, Quaternion localRotation) => new SocketStateChangeMessage + private SocketStateChangeMessage CreateMessage(int objid, int socketid, Quaternion localRotation) => new() { AboutId = LocalPlayerId, ObjectId = objid, diff --git a/QSB/QuantumSync/Patches/QuantumPatches.cs b/QSB/QuantumSync/Patches/QuantumPatches.cs index 0ebd1e96..72d0d4b8 100644 --- a/QSB/QuantumSync/Patches/QuantumPatches.cs +++ b/QSB/QuantumSync/Patches/QuantumPatches.cs @@ -40,7 +40,7 @@ namespace QSB.QuantumSync.Patches { if (WorldObjectManager.AllReady) { - var socketedWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); + var socketedWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); if (socketedWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId) { return false; @@ -154,8 +154,8 @@ namespace QSB.QuantumSync.Patches return; } - var objectWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); - var socketWorldObject = QSBWorldSync.GetWorldFromUnity(socket); + var objectWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); + var socketWorldObject = QSBWorldSync.GetWorldFromUnity(socket); if (objectWorldObject == null) { @@ -187,7 +187,7 @@ namespace QSB.QuantumSync.Patches QSBQuantumShuffleObject shuffleWorldObject = default; if (WorldObjectManager.AllReady) { - shuffleWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); + shuffleWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); if (shuffleWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId) { return false; @@ -230,7 +230,7 @@ namespace QSB.QuantumSync.Patches return true; } - var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); + var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); if (qsbObj.ControllingPlayer == 0) { return true; @@ -266,7 +266,7 @@ namespace QSB.QuantumSync.Patches return true; } - var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); + var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); if (qsbObj.ControllingPlayer == 0 && qsbObj.CurrentState == -1) { return true; @@ -291,7 +291,7 @@ namespace QSB.QuantumSync.Patches } var allMultiStates = QSBWorldSync.GetWorldObjects(); - var stateObject = QSBWorldSync.GetWorldFromUnity(__instance); + var stateObject = QSBWorldSync.GetWorldFromUnity(__instance); var owner = allMultiStates.FirstOrDefault(x => x.QuantumStates.Contains(stateObject)); if (owner == default) { @@ -363,7 +363,7 @@ namespace QSB.QuantumSync.Patches [HarmonyPatch(typeof(QuantumShrine), nameof(QuantumShrine.ChangeQuantumState))] public static bool QuantumShrine_ChangeQuantumState(QuantumShrine __instance) { - var shrineWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); + var shrineWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); var isInControl = shrineWorldObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId; return isInControl; } diff --git a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs b/QSB/QuantumSync/Patches/ServerQuantumPatches.cs index 1c664104..abf2c82f 100644 --- a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs +++ b/QSB/QuantumSync/Patches/ServerQuantumPatches.cs @@ -1,11 +1,8 @@ using HarmonyLib; -using OWML.Common; using QSB.Events; using QSB.Patches; using QSB.Player; -using QSB.Utility; using System.Linq; -using System.Reflection; using UnityEngine; namespace QSB.QuantumSync.Patches @@ -15,104 +12,62 @@ namespace QSB.QuantumSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect; + /* + * This patch used to be different, but that one completely broke Solanum's NomaiTextLines. + * I have no idea why, and I fixed it by just writing this patch again. + * The patches did the same thing. + * ¯\_(ツ)_/¯ + */ + [HarmonyPrefix] [HarmonyPatch(typeof(QuantumMoon), nameof(QuantumMoon.ChangeQuantumState))] - public static bool QuantumMoon_ChangeQuantumState( - QuantumMoon __instance, - ref bool __result, - bool skipInstantVisibilityCheck, - bool ____isPlayerInside, - bool ____hasSunCollapsed, - float ____playerWarpTime, - ref int ____stateIndex, - ref int ____collapseToIndex, - QuantumOrbit[] ____orbits, - float ____sphereCheckRadius, - VisibilityTracker ____visibilityTracker, - OWRigidbody ____moonBody, - ConstantForceDetector ____constantForceDetector, - ref bool ____useInitialMotion, - ref int ____lastStateIndex, - ref int[] ____stateSkipCounts, - AudioSignal ____quantumSignal, - ReferenceFrameVolume ____referenceFrameVolume, - GameObject[] ____deactivateAtEye - ) + public static bool ChangeQuantumState(QuantumMoon __instance, bool skipInstantVisibilityCheck, ref bool __result) { - if (!QSBCore.WorldObjectsReady) - { - return false; - } + var foundNewPosition = false; - var isVisibleOutput = QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, skipInstantVisibilityCheck); - //var moonVisible = isVisibleOutput.First; - var moonVisiblePlayers = isVisibleOutput.Item2; - var inMoonPlayers = QSBPlayerManager.PlayerList.Where(x => x.IsInMoon); - if (inMoonPlayers == null) - { - DebugLog.ToConsole($"Warning - inMoonPlayers is null.", MessageType.Warning); - return false; - } - - var inShrinePlayers = QSBPlayerManager.PlayerList.Where(x => x.IsInShrine); - if (inShrinePlayers == null) - { - DebugLog.ToConsole($"Warning - inShrinePlayers is null.", MessageType.Warning); - return false; - } - - //var outMoonPlayers = QSBPlayerManager.PlayerList.Where(x => !x.IsInMoon); - - var outShrinePlayers = QSBPlayerManager.PlayerList.Where(x => !x.IsInShrine); - if (outShrinePlayers == null) - { - DebugLog.ToConsole($"Warning - outShrinePlayers is null.", MessageType.Warning); - return false; - } - - if (QuantumManager.Shrine == null) - { - DebugLog.ToConsole($"Warning - QuantumManager.Shrine is null.", MessageType.Warning); - return false; - } - - var shrineLit = QuantumManager.Shrine.IsPlayerInDarkness(); + var playersInQuantumMoon = QSBPlayerManager.PlayerList.Where(x => x.IsInMoon); + var isVisibleOutput = QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)__instance._visibilityTracker, skipInstantVisibilityCheck); + var shrineLit = QuantumManager.Shrine != null && QuantumManager.Shrine.IsPlayerInDarkness(); + var playersInQuantumShrine = QSBPlayerManager.PlayerList.Where(x => x.IsInShrine); + var playersWhoCanSeeQuantumMoon = isVisibleOutput.Item2; + var playersNotInQuantumShrine = QSBPlayerManager.PlayerList.Where(x => !x.IsInShrine); // If any of the players in the moon are not in the shrine - if (inMoonPlayers.Any(x => !x.IsInShrine)) + if (playersInQuantumMoon.Any(x => !x.IsInShrine)) { __result = false; return false; } // If any of the players outside the shrine can see the moon - if (outShrinePlayers.Any(moonVisiblePlayers.Contains)) + if (playersNotInQuantumShrine.Any(playersWhoCanSeeQuantumMoon.Contains)) { __result = false; return false; } // If there are players in the shrine and the shrine is not lit - if (inShrinePlayers.Count() != 0 && !shrineLit) + if (playersInQuantumShrine.Count() != 0 && !shrineLit) { __result = false; return false; } - var flag = false; - if (____isPlayerInside && ____hasSunCollapsed) + var anyPlayerInQM = playersInQuantumMoon.Any(); + + if (anyPlayerInQM && __instance._hasSunCollapsed) { __result = false; return false; } - if (Time.time - ____playerWarpTime < 1f) + if (Time.time - __instance._playerWarpTime < 1f) { __result = false; return false; } - if (____stateIndex == 5 && ____isPlayerInside && !__instance.IsPlayerEntangled()) + if (__instance._stateIndex == 5 && anyPlayerInQM && !__instance.IsPlayerEntangled()) { __result = false; return false; @@ -120,101 +75,35 @@ namespace QSB.QuantumSync.Patches for (var i = 0; i < 10; i++) { - var stateIndex = (____collapseToIndex == -1) ? (int)__instance.GetType().GetMethod("GetRandomStateIndex", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) : ____collapseToIndex; - var orbitIndex = -1; - for (var j = 0; j < ____orbits.Length; j++) - { - if (____orbits[j].GetStateIndex() == stateIndex) - { - orbitIndex = j; - break; - } - } + FindStateAndOrbit(__instance, out var stateIndex, out var orbitIndex); - if (orbitIndex == -1) - { - DebugLog.ToConsole($"Error - QM failed to find orbit for state {stateIndex}", MessageType.Error); - } + GetTargetPosition(__instance, stateIndex, orbitIndex, out var orbitRadius, out var bodyToOrbit, out var targetPosition, out var onUnitSphere); - var orbitRadius = (orbitIndex == -1) ? 10000f : ____orbits[orbitIndex].GetOrbitRadius(); - var owRigidbody = (orbitIndex == -1) ? Locator.GetAstroObject(AstroObject.Name.Sun).GetOWRigidbody() : ____orbits[orbitIndex].GetAttachedOWRigidbody(); - var onUnitSphere = UnityEngine.Random.onUnitSphere; - if (stateIndex == 5) + if (!Physics.CheckSphere(targetPosition, __instance._sphereCheckRadius, OWLayerMask.physicalMask) || __instance._collapseToIndex != -1) { - onUnitSphere.y = 0f; - onUnitSphere.Normalize(); - } - - var position = (onUnitSphere * orbitRadius) + owRigidbody.GetWorldCenterOfMass(); - if (!Physics.CheckSphere(position, ____sphereCheckRadius, OWLayerMask.physicalMask) || ____collapseToIndex != -1) - { - ____visibilityTracker.transform.position = position; + __instance._visibilityTracker.transform.position = targetPosition; if (!Physics.autoSyncTransforms) { Physics.SyncTransforms(); } - if (__instance.IsPlayerEntangled() || !QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, skipInstantVisibilityCheck).Item1) + if (skipInstantVisibilityCheck || anyPlayerInQM || !__instance.CheckVisibilityInstantly()) { - ____moonBody.transform.position = position; - if (!Physics.autoSyncTransforms) - { - Physics.SyncTransforms(); - } - - ____visibilityTracker.transform.localPosition = Vector3.zero; - ____constantForceDetector.AddConstantVolume(owRigidbody.GetAttachedGravityVolume(), true, true); - var velocity = owRigidbody.GetVelocity(); - if (____useInitialMotion) - { - var initialMotion = owRigidbody.GetComponent(); - velocity = (initialMotion == null) ? Vector3.zero : initialMotion.GetInitVelocity(); - ____useInitialMotion = false; - } - - var orbitAngle = UnityEngine.Random.Range(0, 360); - ____moonBody.SetVelocity(OWPhysics.CalculateOrbitVelocity(owRigidbody, ____moonBody, orbitAngle) + velocity); - ____lastStateIndex = ____stateIndex; - ____stateIndex = stateIndex; - ____collapseToIndex = -1; - flag = true; - for (var k = 0; k < ____stateSkipCounts.Length; k++) - { - ____stateSkipCounts[k] = (k != ____stateIndex) ? (____stateSkipCounts[k] + 1) : 0; - } - - QSBEventManager.FireEvent(EventNames.QSBMoonStateChange, stateIndex, onUnitSphere, orbitAngle); + MoveMoon(__instance, targetPosition, bodyToOrbit, stateIndex, onUnitSphere, ref foundNewPosition); break; } - ____visibilityTracker.transform.localPosition = Vector3.zero; + __instance._visibilityTracker.transform.localPosition = Vector3.zero; } else { - DebugLog.ToConsole("Warning - Quantum moon orbit position occupied! Aborting collapse.", MessageType.Warning); + Debug.LogError("Quantum moon orbit position occupied! Aborting collapse."); } } - if (flag) + if (foundNewPosition) { - if (____isPlayerInside) - { - __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { ____stateIndex }); - } - else - { - __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { -1 }); - ____quantumSignal.SetSignalActivation(____stateIndex != 5, 2f); - } - - ____referenceFrameVolume.gameObject.SetActive(____stateIndex != 5); - ____moonBody.SetIsTargetable(____stateIndex != 5); - for (var l = 0; l < ____deactivateAtEye.Length; l++) - { - ____deactivateAtEye[l].SetActive(____stateIndex != 5); - } - - GlobalMessenger.FireEvent("QuantumMoonChangeState", ____moonBody); + DealWithNewPosition(__instance); __result = true; return false; } @@ -222,5 +111,110 @@ namespace QSB.QuantumSync.Patches __result = false; return false; } + + private static void GetTargetPosition(QuantumMoon __instance, int stateIndex, int orbitIndex, out float orbitRadius, out OWRigidbody bodyToOrbit, out Vector3 targetPosition, out Vector3 onUnitSphere) + { + orbitRadius = (orbitIndex != -1) + ? __instance._orbits[orbitIndex].GetOrbitRadius() + : 10000f; + + bodyToOrbit = (orbitIndex != -1) + ? __instance._orbits[orbitIndex].GetAttachedOWRigidbody() + : Locator.GetAstroObject(AstroObject.Name.Sun).GetOWRigidbody(); + + onUnitSphere = UnityEngine.Random.onUnitSphere; + + if (stateIndex == 5) + { + onUnitSphere.y = 0f; + onUnitSphere.Normalize(); + } + + targetPosition = (onUnitSphere * orbitRadius) + bodyToOrbit.GetWorldCenterOfMass(); + } + + private static void FindStateAndOrbit(QuantumMoon __instance, out int stateIndex, out int orbitIndex) + { + stateIndex = (__instance._collapseToIndex != -1) + ? __instance._collapseToIndex + : __instance.GetRandomStateIndex(); + orbitIndex = -1; + + for (var j = 0; j < __instance._orbits.Length; j++) + { + if (__instance._orbits[j].GetStateIndex() == stateIndex) + { + orbitIndex = j; + break; + } + } + + if (orbitIndex == -1) + { + Debug.LogError("QUANTUM MOON FAILED TO FIND ORBIT FOR STATE " + stateIndex); + } + } + + private static void MoveMoon(QuantumMoon __instance, Vector3 targetPosition, OWRigidbody bodyToOrbit, int stateIndex, Vector3 onUnitSphere, ref bool foundNewPosition) + { + __instance._moonBody.transform.position = targetPosition; + if (!Physics.autoSyncTransforms) + { + Physics.SyncTransforms(); + } + + __instance._visibilityTracker.transform.localPosition = Vector3.zero; + __instance._constantForceDetector.AddConstantVolume(bodyToOrbit.GetAttachedGravityVolume(), true, true); + var bodyVelocity = bodyToOrbit.GetVelocity(); + + if (__instance._useInitialMotion) + { + var component = bodyToOrbit.GetComponent(); + bodyVelocity = (component != null) + ? component.GetInitVelocity() + : Vector3.zero; + __instance._useInitialMotion = false; + } + + var orbitAngle = Random.Range(0, 360); + __instance._moonBody.SetVelocity(OWPhysics.CalculateOrbitVelocity(bodyToOrbit, __instance._moonBody, orbitAngle) + bodyVelocity); + __instance._useInitialMotion = false; + __instance._lastStateIndex = __instance._stateIndex; + __instance._stateIndex = stateIndex; + __instance._collapseToIndex = -1; + foundNewPosition = true; + + for (var k = 0; k < __instance._stateSkipCounts.Length; k++) + { + __instance._stateSkipCounts[k] = (k == __instance._stateIndex) + ? 0 + : (__instance._stateSkipCounts[k] + 1); + } + + QSBEventManager.FireEvent(EventNames.QSBMoonStateChange, stateIndex, onUnitSphere, orbitAngle); + } + + private static void DealWithNewPosition(QuantumMoon __instance) + { + if (__instance._isPlayerInside) + { + __instance.SetSurfaceState(__instance._stateIndex); + } + else + { + __instance.SetSurfaceState(-1); + __instance._quantumSignal.SetSignalActivation(__instance._stateIndex != 5, 2f); + } + + __instance._referenceFrameVolume.gameObject.SetActive(__instance._stateIndex != 5); + __instance._moonBody.SetIsTargetable(__instance._stateIndex != 5); + + for (var l = 0; l < __instance._deactivateAtEye.Length; l++) + { + __instance._deactivateAtEye[l].SetActive(__instance._stateIndex != 5); + } + + GlobalMessenger.FireEvent("QuantumMoonChangeState", __instance._moonBody); + } } } \ No newline at end of file diff --git a/QSB/QuantumSync/QuantumManager.cs b/QSB/QuantumSync/QuantumManager.cs index abf2bf20..7436452d 100644 --- a/QSB/QuantumSync/QuantumManager.cs +++ b/QSB/QuantumSync/QuantumManager.cs @@ -42,7 +42,7 @@ namespace QSB.QuantumSync QSBWorldSync.Init(); if (scene == OWScene.SolarSystem) { - Shrine = Resources.FindObjectsOfTypeAll().First(); + Shrine = QSBWorldSync.GetUnityObjects().First(); } } @@ -67,7 +67,7 @@ namespace QSB.QuantumSync public void OnRenderObject() { - if (!QSBCore.WorldObjectsReady || !QSBCore.DebugMode || !QSBCore.ShowLinesInDebug) + if (!QSBCore.WorldObjectsReady || !QSBCore.ShowLinesInDebug) { return; } @@ -76,6 +76,18 @@ namespace QSB.QuantumSync { Popcron.Gizmos.Sphere(Shrine.transform.position, 10f, Color.magenta); } + + foreach (var quantumObject in QSBWorldSync.GetWorldObjects()) + { + if (quantumObject.ControllingPlayer == 0) + { + continue; + } + + Popcron.Gizmos.Line((quantumObject as IWorldObject).ReturnObject().transform.position, + QSBPlayerManager.GetPlayer(quantumObject.ControllingPlayer).Body.transform.position, + Color.magenta); + } } public static Tuple> IsVisibleUsingCameraFrustum(ShapeVisibilityTracker tracker, bool ignoreLocalCamera) @@ -132,39 +144,8 @@ namespace QSB.QuantumSync return Enumerable.Empty(); } - var worldObj = GetObject(obj); + var worldObj = (IQSBQuantumObject)QSBWorldSync.GetWorldFromUnity(obj); return QSBPlayerManager.PlayerList.Where(x => x.EntangledObject == worldObj); } - - public static IQSBQuantumObject GetObject(QuantumObject unityObject) - { - IQSBQuantumObject worldObj = null; - if (unityObject.GetType() == typeof(SocketedQuantumObject) || unityObject.GetType() == typeof(QuantumShrine)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((SocketedQuantumObject)unityObject); - } - else if (unityObject.GetType() == typeof(MultiStateQuantumObject)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((MultiStateQuantumObject)unityObject); - } - else if (unityObject.GetType() == typeof(QuantumShuffleObject)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((QuantumShuffleObject)unityObject); - } - else if (unityObject.GetType() == typeof(QuantumMoon)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((QuantumMoon)unityObject); - } - else if (unityObject.GetType() == typeof(EyeProxyQuantumMoon)) - { - worldObj = QSBWorldSync.GetWorldFromUnity((EyeProxyQuantumMoon)unityObject); - } - else - { - DebugLog.ToConsole($"Warning - couldn't work out type of QuantumObject {unityObject.name}.", MessageType.Warning); - } - - return worldObj; - } } -} \ No newline at end of file +} diff --git a/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs b/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs index 9cb6d49e..6f21d9c0 100644 --- a/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs +++ b/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs @@ -1,4 +1,6 @@ -namespace QSB.QuantumSync.WorldObjects +using QSB.Player; + +namespace QSB.QuantumSync.WorldObjects { internal class QSBEyeProxyQuantumMoon : QSBQuantumObject { @@ -6,7 +8,7 @@ { ObjectId = id; AttachedObject = moonObject; - ControllingPlayer = 1u; + ControllingPlayer = QSBPlayerManager.LocalPlayerId; base.Init(moonObject, id); } } diff --git a/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs index 021fa8ea..f565af2c 100644 --- a/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs @@ -1,5 +1,4 @@ -using OWML.Utils; -using QSB.Utility; +using QSB.Utility; using QSB.WorldSync; using System.Collections.Generic; using System.Linq; @@ -27,7 +26,7 @@ namespace QSB.QuantumSync.WorldObjects ObjectId = id; AttachedObject = attachedObject; - if (QSBCore.DebugMode) + if (QSBCore.ShowQuantumDebugBoxes) { DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Multistate\r\nid:{id}\r\nstate:{CurrentState}").GetComponent(); } @@ -37,7 +36,7 @@ namespace QSB.QuantumSync.WorldObjects public override void PostInit() { - QuantumStates = AttachedObject._states.ToList().Select(x => QSBWorldSync.GetWorldFromUnity(x)).ToList(); + QuantumStates = AttachedObject._states.ToList().Select(x => QSBWorldSync.GetWorldFromUnity(x)).ToList(); if (QuantumStates.Any(x => x == null)) { @@ -54,7 +53,7 @@ namespace QSB.QuantumSync.WorldObjects QuantumStates[newStateIndex].SetVisible(true); AttachedObject._stateIndex = newStateIndex; - if (QSBCore.DebugMode) + if (QSBCore.ShowQuantumDebugBoxes) { DebugBoxText.text = $"Multistate\r\nid:{ObjectId}\r\nstate:{CurrentState}"; } diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs index 9765783e..1f1e64a9 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs @@ -1,4 +1,6 @@ -namespace QSB.QuantumSync.WorldObjects +using QSB.Player; + +namespace QSB.QuantumSync.WorldObjects { internal class QSBQuantumMoon : QSBQuantumObject { @@ -6,7 +8,7 @@ { ObjectId = id; AttachedObject = moonObject; - ControllingPlayer = 1u; + ControllingPlayer = QSBPlayerManager.LocalPlayerId; base.Init(moonObject, id); } } diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs index 38920856..e29b2835 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs @@ -31,9 +31,9 @@ namespace QSB.QuantumSync.WorldObjects public override void Init(T attachedObject, int id) { var debugBundle = QSBCore.DebugAssetBundle; - var sphere = debugBundle.LoadAsset("Assets/Sphere.prefab"); - var cube = debugBundle.LoadAsset("Assets/Cube.prefab"); - var capsule = debugBundle.LoadAsset("Assets/Capsule.prefab"); + var sphere = debugBundle.LoadAsset("Assets/Prefabs/Sphere.prefab"); + var cube = debugBundle.LoadAsset("Assets/Prefabs/Cube.prefab"); + var capsule = debugBundle.LoadAsset("Assets/Prefabs/Capsule.prefab"); if (cube == null) { @@ -64,7 +64,7 @@ namespace QSB.QuantumSync.WorldObjects shape.OnShapeDeactivated += (Shape s) => QSBCore.UnityEvents.FireOnNextUpdate(() => OnDisable(s)); - if (QSBCore.DebugMode) + if (QSBCore.ShowQuantumVisibilityObjects) { if (shape is BoxShape boxShape) { diff --git a/QSB/QuantumSync/WorldObjects/QSBSocketedQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBSocketedQuantumObject.cs index fe381047..621881c9 100644 --- a/QSB/QuantumSync/WorldObjects/QSBSocketedQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBSocketedQuantumObject.cs @@ -18,7 +18,7 @@ namespace QSB.QuantumSync.WorldObjects ObjectId = id; AttachedObject = quantumObject; base.Init(quantumObject, id); - if (QSBCore.DebugMode) + if (QSBCore.ShowQuantumDebugBoxes) { DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Socketed\r\nid:{ObjectId}").GetComponent(); } diff --git a/QSB/DeathSync/Events/PlayerRespawnEvent.cs b/QSB/RespawnSync/Events/PlayerRespawnEvent.cs similarity index 90% rename from QSB/DeathSync/Events/PlayerRespawnEvent.cs rename to QSB/RespawnSync/Events/PlayerRespawnEvent.cs index 83e7e44b..96f3924d 100644 --- a/QSB/DeathSync/Events/PlayerRespawnEvent.cs +++ b/QSB/RespawnSync/Events/PlayerRespawnEvent.cs @@ -3,7 +3,7 @@ using QSB.Events; using QSB.Messaging; using QSB.Player; -namespace QSB.DeathSync.Events +namespace QSB.RespawnSync.Events { internal class PlayerRespawnEvent : QSBEvent { @@ -17,7 +17,7 @@ namespace QSB.DeathSync.Events private void Handler(uint playerId) => SendEvent(CreateMessage(playerId)); - private PlayerMessage CreateMessage(uint playerId) => new PlayerMessage + private PlayerMessage CreateMessage(uint playerId) => new() { AboutId = playerId }; diff --git a/QSB/RespawnSync/RespawnHUDMarker.cs b/QSB/RespawnSync/RespawnHUDMarker.cs new file mode 100644 index 00000000..b5bab2d1 --- /dev/null +++ b/QSB/RespawnSync/RespawnHUDMarker.cs @@ -0,0 +1,47 @@ +using UnityEngine; + +namespace QSB.RespawnSync +{ + public class RespawnHUDMarker : HUDDistanceMarker + { + private bool _isReady; + + public override void InitCanvasMarker() + { + _markerRadius = 0.2f; + _markerTarget = transform; + _markerLabel = "RESPAWN PLAYER"; + _isReady = true; + + base.InitCanvasMarker(); + } + + private void Update() + { + if (!_isReady) + { + return; + } + + if (_canvasMarker != null) + { + var isVisible = _canvasMarker.IsVisible(); + + if (RespawnManager.Instance.RespawnNeeded != isVisible) + { + _isVisible = RespawnManager.Instance.RespawnNeeded; + _canvasMarker.SetVisibility(_isVisible); + } + } + + if (_isVisible && _canvasMarker != null) + { + var color = (Mathf.Sin(Time.unscaledTime * 10f) > 0f) + ? Color.white + : new Color(1f, 1f, 1f, 0.1f); + _canvasMarker._mainTextField.color = color; + _canvasMarker._offScreenIndicator._textField.color = color; + } + } + } +} diff --git a/QSB/DeathSync/RespawnManager.cs b/QSB/RespawnSync/RespawnManager.cs similarity index 55% rename from QSB/DeathSync/RespawnManager.cs rename to QSB/RespawnSync/RespawnManager.cs index 7b104e2e..5ead6164 100644 --- a/QSB/DeathSync/RespawnManager.cs +++ b/QSB/RespawnSync/RespawnManager.cs @@ -6,8 +6,9 @@ using QSB.Utility; using System.Collections.Generic; using System.Linq; using UnityEngine; +using UnityEngine.Networking; -namespace QSB.DeathSync +namespace QSB.RespawnSync { internal class RespawnManager : MonoBehaviour { @@ -15,25 +16,95 @@ namespace QSB.DeathSync public bool RespawnNeeded => _playersPendingRespawn.Count != 0; - private List _playersPendingRespawn = new List(); + private List _playersPendingRespawn = new(); private NotificationData _previousNotification; + private GameObject _owRecoveryPoint; + private GameObject _qsbRecoveryPoint; private void Start() { Instance = this; - QSBSceneManager.OnSceneLoaded += OnSceneLoaded; + QSBSceneManager.OnSceneLoaded += (OWScene old, OWScene newScene, bool inUniverse) + => QSBCore.UnityEvents.RunWhen( + () => Locator.GetMarkerManager() != null, + () => Init(newScene, inUniverse)); + QSBNetworkManager.Instance.OnClientConnected += OnConnected; + QSBNetworkManager.Instance.OnClientDisconnected += OnDisconnected; } - private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool inUniverse) + private void OnConnected() { + if (QSBSceneManager.IsInUniverse) + { + Init(QSBSceneManager.CurrentScene, true); + } + } + + private void OnDisconnected(NetworkError error) + { + _owRecoveryPoint?.SetActive(true); + _qsbRecoveryPoint?.SetActive(false); + } + + private void Init(OWScene newScene, bool inUniverse) + { + if (!QSBCore.IsInMultiplayer) + { + return; + } + QSBPlayerManager.ShowAllPlayers(); + QSBPlayerManager.LocalPlayer.UpdateStatesFromObjects(); QSBPlayerManager.PlayerList.ForEach(x => x.IsDead = false); _playersPendingRespawn.Clear(); + + if (newScene != OWScene.SolarSystem) + { + return; + } + + if (_owRecoveryPoint == null) + { + _owRecoveryPoint = GameObject.Find("Systems_Supplies/PlayerRecoveryPoint"); + } + + if (_owRecoveryPoint == null) + { + DebugLog.ToConsole($"Error - Couldn't find the ship's PlayerRecoveryPoint!", OWML.Common.MessageType.Error); + return; + } + + _owRecoveryPoint.SetActive(false); + + var Systems_Supplies = _owRecoveryPoint.gameObject.transform.parent; + + if (_qsbRecoveryPoint == null) + { + _qsbRecoveryPoint = new GameObject("QSBPlayerRecoveryPoint"); + _qsbRecoveryPoint.SetActive(false); + _qsbRecoveryPoint.transform.parent = Systems_Supplies; + _qsbRecoveryPoint.transform.localPosition = new Vector3(2.46f, 1.957f, 1.156f); + _qsbRecoveryPoint.transform.localRotation = Quaternion.Euler(0, 6.460001f, 0f); + _qsbRecoveryPoint.layer = 21; + + var boxCollider = _qsbRecoveryPoint.AddComponent(); + boxCollider.isTrigger = true; + boxCollider.size = new Vector3(1.3f, 1.01f, 0.47f); + + var multiInteract = _qsbRecoveryPoint.AddComponent(); + multiInteract._usableInShip = true; + multiInteract._interactRange = 1.5f; + + _qsbRecoveryPoint.AddComponent(); + + _qsbRecoveryPoint.AddComponent(); + } + + _qsbRecoveryPoint.SetActive(true); } public void TriggerRespawnMap() { - DebugLog.DebugWrite($"TRIGGER RESPAWN MAP"); QSBPatchManager.DoPatchType(QSBPatchTypes.RespawnTime); QSBCore.UnityEvents.FireOnNextUpdate(() => GlobalMessenger.FireEvent("TriggerObservatoryMap")); } diff --git a/QSB/RespawnSync/ShipRecoveryPoint.cs b/QSB/RespawnSync/ShipRecoveryPoint.cs new file mode 100644 index 00000000..4444364d --- /dev/null +++ b/QSB/RespawnSync/ShipRecoveryPoint.cs @@ -0,0 +1,211 @@ +using QSB.Utility; +using UnityEngine; + +namespace QSB.RespawnSync +{ + internal class ShipRecoveryPoint : MonoBehaviour + { + private MultipleInteractionVolume _interactVolume; + private PlayerResources _playerResources; + private PlayerAudioController _playerAudioController; + private bool _recovering; + private int _refillIndex; + private int _respawnIndex; + private bool _wearingSuit; + + private void Awake() + { + _interactVolume = this.GetRequiredComponent(); + _interactVolume.OnPressInteract += OnPressInteract; + _interactVolume.OnGainFocus += OnGainFocus; + + var respawnPlayerText = UIHelper.AddToUITable("Respawn Player"); + + _refillIndex = _interactVolume.AddInteraction(InputLibrary.interact, InputMode.Character, UITextType.None, true, true); + _respawnIndex = _interactVolume.AddInteraction(InputLibrary.interactSecondary, InputMode.Character, (UITextType)respawnPlayerText, true, true); + + GlobalMessenger.AddListener("SuitUp", new Callback(OnSuitUp)); + GlobalMessenger.AddListener("RemoveSuit", new Callback(OnRemoveSuit)); + } + + private void Start() + { + _playerResources = Locator.GetPlayerTransform().GetComponent(); + _playerAudioController = Locator.GetPlayerAudioController(); + } + + private void OnDestroy() + { + _interactVolume.OnPressInteract -= OnPressInteract; + _interactVolume.OnGainFocus -= OnGainFocus; + GlobalMessenger.RemoveListener("SuitUp", new Callback(OnSuitUp)); + GlobalMessenger.RemoveListener("RemoveSuit", new Callback(OnRemoveSuit)); + } + + private void OnSuitUp() + => _wearingSuit = true; + + private void OnRemoveSuit() + => _wearingSuit = false; + + private void OnGainFocus() + { + if (_playerResources == null) + { + _playerResources = Locator.GetPlayerTransform().GetComponent(); + } + + if (RespawnManager.Instance.RespawnNeeded) + { + _interactVolume.EnableSingleInteraction(true, _respawnIndex); + _interactVolume.SetKeyCommandVisible(true, _respawnIndex); + _interactVolume.GetInteractionAt(_respawnIndex).cachedScreenPrompt.SetDisplayState(ScreenPrompt.DisplayState.Attention); + } + else + { + _interactVolume.EnableSingleInteraction(false, _respawnIndex); + _interactVolume.SetKeyCommandVisible(false, _respawnIndex); + _interactVolume.GetInteractionAt(_respawnIndex).cachedScreenPrompt.SetDisplayState(ScreenPrompt.DisplayState.GrayedOut); + } + + var needsHealing = _playerResources.GetHealthFraction() != 1f; + var needsRefueling = _playerResources.GetFuelFraction() != 1f; + + UITextType uitextType; + bool keyCommandVisible; + if (needsHealing && needsRefueling) + { + uitextType = UITextType.RefillPrompt_0; + keyCommandVisible = true; + } + else if (needsHealing) + { + uitextType = UITextType.RefillPrompt_2; + keyCommandVisible = true; + } + else if (needsRefueling) + { + uitextType = UITextType.RefillPrompt_4; + keyCommandVisible = true; + } + else + { + uitextType = UITextType.RefillPrompt_7; + keyCommandVisible = false; + } + + if (uitextType != UITextType.None) + { + _interactVolume.ChangePrompt(uitextType, _refillIndex); + } + + if (_wearingSuit) + { + _interactVolume.EnableSingleInteraction(true, _refillIndex); + _interactVolume.SetKeyCommandVisible(keyCommandVisible, _refillIndex); + _interactVolume.GetInteractionAt(_refillIndex).cachedScreenPrompt.SetDisplayState(ScreenPrompt.DisplayState.Normal); + } + else + { + _interactVolume.EnableSingleInteraction(false, _refillIndex); + _interactVolume.SetKeyCommandVisible(false, _refillIndex); + _interactVolume.GetInteractionAt(_refillIndex).cachedScreenPrompt.SetDisplayState(ScreenPrompt.DisplayState.GrayedOut); + } + } + + private void OnPressInteract(IInputCommands inputCommand) + { + if (inputCommand == _interactVolume.GetInteractionAt(_refillIndex).inputCommand) + { + if (!_wearingSuit) + { + return; + } + + HandleRecovery(); + } + else if (inputCommand == _interactVolume.GetInteractionAt(_respawnIndex).inputCommand) + { + if (!RespawnManager.Instance.RespawnNeeded) + { + return; + } + + RespawnManager.Instance.RespawnSomePlayer(); + } + else + { + // the fuck???? + } + } + + private void HandleRecovery() + { + var needsRefueling = _playerResources.GetFuelFraction() != 1f; + var needsHealing = _playerResources.GetHealthFraction() != 1f; + var flag4 = false; + + if (needsRefueling) + { + flag4 = true; + } + + if (needsHealing) + { + flag4 = true; + } + + if (flag4) + { + _playerResources.StartRefillResources(true, true); + + if (_playerAudioController != null) + { + if (needsRefueling) + { + _playerAudioController.PlayRefuel(); + } + + if (needsHealing) + { + _playerAudioController.PlayMedkit(); + } + } + + _recovering = true; + enabled = true; + return; + } + + _interactVolume.ResetInteraction(); + } + + private void Update() + { + if (_recovering) + { + var doneRecovering = true; + if (_playerResources.GetFuelFraction() < 1f) + { + doneRecovering = false; + } + + if (_playerResources.GetHealthFraction() < 1f) + { + doneRecovering = false; + } + + if (doneRecovering) + { + _playerResources.StopRefillResources(); + _recovering = false; + } + } + + if (!_recovering) + { + enabled = false; + } + } + } +} diff --git a/QSB/RoastingSync/Events/EnterExitRoastingEvent.cs b/QSB/RoastingSync/Events/EnterExitRoastingEvent.cs index b9bdcfd3..99ceccbd 100644 --- a/QSB/RoastingSync/Events/EnterExitRoastingEvent.cs +++ b/QSB/RoastingSync/Events/EnterExitRoastingEvent.cs @@ -31,11 +31,11 @@ namespace QSB.RoastingSync.Events return; } - var qsbObj = QSBWorldSync.GetWorldFromUnity(campfire); + var qsbObj = QSBWorldSync.GetWorldFromUnity(campfire); SendEvent(CreateMessage(qsbObj.ObjectId, roasting)); } - private BoolWorldObjectMessage CreateMessage(int objectId, bool roasting) => new BoolWorldObjectMessage + private BoolWorldObjectMessage CreateMessage(int objectId, bool roasting) => new() { AboutId = LocalPlayerId, State = roasting, @@ -57,14 +57,9 @@ namespace QSB.RoastingSync.Events var player = QSBPlayerManager.GetPlayer(message.AboutId); player.RoastingStick.SetActive(message.State); - if (message.State) - { - player.Campfire = QSBWorldSync.GetWorldFromId(message.ObjectId); - } - else - { - player.Campfire = null; - } + player.Campfire = message.State + ? QSBWorldSync.GetWorldFromId(message.ObjectId) + : null; } } } diff --git a/QSB/RoastingSync/Events/MarshmallowEventEvent.cs b/QSB/RoastingSync/Events/MarshmallowEventEvent.cs index d9ce46f0..d422d636 100644 --- a/QSB/RoastingSync/Events/MarshmallowEventEvent.cs +++ b/QSB/RoastingSync/Events/MarshmallowEventEvent.cs @@ -3,6 +3,7 @@ using QSB.Events; using QSB.Messaging; using QSB.Player; using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; @@ -17,7 +18,7 @@ namespace QSB.RoastingSync.Events private void Handler(MarshmallowEventType type) => SendEvent(CreateMessage(type)); - private EnumMessage CreateMessage(MarshmallowEventType type) => new EnumMessage + private EnumMessage CreateMessage(MarshmallowEventType type) => new() { AboutId = LocalPlayerId, EnumValue = type @@ -66,7 +67,7 @@ namespace QSB.RoastingSync.Events var stick = player.RoastingStick; var stickTip = stick.transform.GetChild(0); - var mallowPrefab = Resources.FindObjectsOfTypeAll().First().GetValue("_mallowBodyPrefab"); + var mallowPrefab = QSBWorldSync.GetUnityObjects().First().GetValue("_mallowBodyPrefab"); var tossedMallow = Object.Instantiate(mallowPrefab, stickTip.position, stickTip.rotation); var rigidbody = tossedMallow.GetComponent(); diff --git a/QSB/SatelliteSync/Events/SatelliteProjectorEvent.cs b/QSB/SatelliteSync/Events/SatelliteProjectorEvent.cs new file mode 100644 index 00000000..c49cfa97 --- /dev/null +++ b/QSB/SatelliteSync/Events/SatelliteProjectorEvent.cs @@ -0,0 +1,42 @@ +using QSB.Events; +using QSB.Messaging; + +namespace QSB.SatelliteSync.Events +{ + internal class SatelliteProjectorEvent : QSBEvent + { + public override EventType Type => EventType.SatelliteProjector; + + public override void SetupListener() + { + GlobalMessenger.AddListener(EventNames.QSBEnterSatelliteCamera, () => Handler(true)); + GlobalMessenger.AddListener(EventNames.QSBExitSatelliteCamera, () => Handler(false)); + } + + public override void CloseListener() + { + GlobalMessenger.RemoveListener(EventNames.QSBEnterSatelliteCamera, () => Handler(true)); + GlobalMessenger.RemoveListener(EventNames.QSBExitSatelliteCamera, () => Handler(false)); + } + + private void Handler(bool usingProjector) => SendEvent(CreateMessage(usingProjector)); + + private BoolMessage CreateMessage(bool usingProjector) => new() + { + AboutId = LocalPlayerId, + Value = usingProjector + }; + + public override void OnReceiveRemote(bool isHost, BoolMessage message) + { + if (message.Value) + { + SatelliteProjectorManager.Instance.RemoteEnter(); + } + else + { + SatelliteProjectorManager.Instance.RemoteExit(); + } + } + } +} diff --git a/QSB/SatelliteSync/Events/SatelliteProjectorSnapshotEvent.cs b/QSB/SatelliteSync/Events/SatelliteProjectorSnapshotEvent.cs new file mode 100644 index 00000000..6c29f3d9 --- /dev/null +++ b/QSB/SatelliteSync/Events/SatelliteProjectorSnapshotEvent.cs @@ -0,0 +1,24 @@ +using QSB.Events; +using QSB.Messaging; + +namespace QSB.SatelliteSync.Events +{ + internal class SatelliteProjectorSnapshotEvent : QSBEvent + { + public override EventType Type => EventType.SatelliteProjectorSnapshot; + + public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBSatelliteSnapshot, (bool forward) => Handler(forward)); + + public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBSatelliteSnapshot, (bool forward) => Handler(forward)); + + private void Handler(bool forward) => SendEvent(CreateMessage(forward)); + + private BoolMessage CreateMessage(bool forward) => new() + { + AboutId = LocalPlayerId, + Value = forward + }; + + public override void OnReceiveRemote(bool isHost, BoolMessage message) => SatelliteProjectorManager.Instance.RemoteTakeSnapshot(message.Value); + } +} diff --git a/QSB/SatelliteSync/Patches/SatelliteProjectorPatches.cs b/QSB/SatelliteSync/Patches/SatelliteProjectorPatches.cs new file mode 100644 index 00000000..68bd873e --- /dev/null +++ b/QSB/SatelliteSync/Patches/SatelliteProjectorPatches.cs @@ -0,0 +1,62 @@ +using HarmonyLib; +using QSB.Events; +using QSB.Patches; +using UnityEngine; + +namespace QSB.SatelliteSync.Patches +{ + [HarmonyPatch] + internal class SatelliteProjectorPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.OnPressInteract))] + public static bool UseProjector() + { + QSBEventManager.FireEvent(EventNames.QSBEnterSatelliteCamera); + return true; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.TurnOffProjector))] + public static bool LeaveProjector() + { + QSBEventManager.FireEvent(EventNames.QSBExitSatelliteCamera); + return true; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.Update))] + public static bool UpdateReplacement(SatelliteSnapshotController __instance) + { + if (!OWInput.IsInputMode(InputMode.SatelliteCam)) + { + return false; + } + + if (OWInput.IsNewlyPressed(InputLibrary.toolActionPrimary, InputMode.All)) + { + QSBEventManager.FireEvent(EventNames.QSBSatelliteSnapshot, true); + __instance._satelliteCamera.transform.localEulerAngles = __instance._initCamLocalRot; + __instance.RenderSnapshot(); + return false; + } + + if (__instance._allowRearview && OWInput.IsNewlyPressed(InputLibrary.toolActionSecondary, InputMode.All)) + { + QSBEventManager.FireEvent(EventNames.QSBSatelliteSnapshot, false); + __instance._satelliteCamera.transform.localEulerAngles = __instance._initCamLocalRot + new Vector3(0f, 180f, 0f); + __instance.RenderSnapshot(); + return false; + } + + if (OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.All)) + { + __instance.TurnOffProjector(); + } + + return false; + } + } +} diff --git a/QSB/SatelliteSync/SatelliteProjectorManager.cs b/QSB/SatelliteSync/SatelliteProjectorManager.cs new file mode 100644 index 00000000..1cc126d9 --- /dev/null +++ b/QSB/SatelliteSync/SatelliteProjectorManager.cs @@ -0,0 +1,83 @@ +using QSB.WorldSync; +using System.Linq; +using UnityEngine; + +namespace QSB.SatelliteSync +{ + internal class SatelliteProjectorManager : MonoBehaviour + { + public static SatelliteProjectorManager Instance { get; private set; } + + public SatelliteSnapshotController Projector { get; private set; } + + public void Start() + { + Instance = this; + QSBSceneManager.OnUniverseSceneLoaded += OnSceneLoaded; + } + + public void OnDestroy() => QSBSceneManager.OnUniverseSceneLoaded -= OnSceneLoaded; + + private void OnSceneLoaded(OWScene oldScene, OWScene newScene) + { + if (newScene == OWScene.SolarSystem) + { + Projector = QSBWorldSync.GetUnityObjects().First(); + Projector._loopingSource.spatialBlend = 1f; + Projector._oneShotSource.spatialBlend = 1f; + } + } + + public void RemoteEnter() + { + Projector.enabled = true; + Projector._interactVolume.DisableInteraction(); + + if (Projector._showSplashTexture) + { + Projector._splashObject.SetActive(false); + Projector._diagramObject.SetActive(true); + Projector._projectionScreen.gameObject.SetActive(false); + } + + if (Projector._fadeLight != null) + { + Projector._fadeLight.StartFade(0f, 2f, 0f); + } + + var audioClip = Projector._oneShotSource.PlayOneShot(AudioType.TH_ProjectorActivate, 1f); + Projector._loopingSource.FadeIn(audioClip.length, false, false, 1f); + } + + public void RemoteExit() + { + Projector.enabled = false; + Projector._interactVolume.EnableInteraction(); + Projector._interactVolume.ResetInteraction(); + + if (Projector._showSplashTexture) + { + Projector._splashObject.SetActive(true); + Projector._diagramObject.SetActive(false); + Projector._projectionScreen.gameObject.SetActive(false); + } + + if (Projector._fadeLight != null) + { + Projector._fadeLight.StartFade(Projector._initLightIntensity, 2f, 0f); + } + + var audioClip = Projector._oneShotSource.PlayOneShot(AudioType.TH_ProjectorStop, 1f); + Projector._loopingSource.FadeOut(audioClip.length, OWAudioSource.FadeOutCompleteAction.STOP, 0f); + } + + public void RemoteTakeSnapshot(bool forward) + { + Projector._satelliteCamera.transform.localEulerAngles = forward + ? Projector._initCamLocalRot + : Projector._initCamLocalRot + new Vector3(0f, 180f, 0f); + + Projector.RenderSnapshot(); + } + } +} diff --git a/QSB/SectorSync/QSBSectorManager.cs b/QSB/SectorSync/QSBSectorManager.cs index 9dedaa14..6967cc40 100644 --- a/QSB/SectorSync/QSBSectorManager.cs +++ b/QSB/SectorSync/QSBSectorManager.cs @@ -13,12 +13,12 @@ namespace QSB.SectorSync { public static QSBSectorManager Instance { get; private set; } public bool IsReady { get; private set; } - public List FakeSectors = new List(); + public List FakeSectors = new(); private void OnEnable() => RepeatingManager.Repeatings.Add(this); private void OnDisable() => RepeatingManager.Repeatings.Remove(this); - public List SectoredSyncs = new List(); + public List SectoredSyncs = new(); public void Invoke() { diff --git a/QSB/SectorSync/SectorSync.cs b/QSB/SectorSync/SectorSync.cs index 2b998c98..ed1f9895 100644 --- a/QSB/SectorSync/SectorSync.cs +++ b/QSB/SectorSync/SectorSync.cs @@ -13,7 +13,7 @@ namespace QSB.SectorSync public class SectorSync : MonoBehaviour { public bool IsReady { get; private set; } - public List SectorList = new List(); + public List SectorList = new(); private OWRigidbody _attachedOWRigidbody; private SectorDetector _sectorDetector; @@ -78,7 +78,7 @@ namespace QSB.SectorSync private void AddSector(Sector sector) { - var worldObject = QSBWorldSync.GetWorldFromUnity(sector); + var worldObject = QSBWorldSync.GetWorldFromUnity(sector); if (worldObject == null) { DebugLog.ToConsole($"Error - Can't find QSBSector for sector {sector.name}!", MessageType.Error); @@ -95,7 +95,7 @@ namespace QSB.SectorSync private void RemoveSector(Sector sector) { - var worldObject = QSBWorldSync.GetWorldFromUnity(sector); + var worldObject = QSBWorldSync.GetWorldFromUnity(sector); if (worldObject == null) { DebugLog.ToConsole($"Error - Can't find QSBSector for sector {sector.name}!", MessageType.Error); diff --git a/QSB/SectorSync/WorldObjects/QSBSector.cs b/QSB/SectorSync/WorldObjects/QSBSector.cs index dbd76ccf..0a85a8e5 100644 --- a/QSB/SectorSync/WorldObjects/QSBSector.cs +++ b/QSB/SectorSync/WorldObjects/QSBSector.cs @@ -63,7 +63,7 @@ namespace QSB.SectorSync.WorldObjects return false; } - if (AttachedObject.name == "Sector_Shuttle" || AttachedObject.name == "Sector_NomaiShuttleInterior") + if (AttachedObject.name is "Sector_Shuttle" or "Sector_NomaiShuttleInterior") { if (QSBSceneManager.CurrentScene == OWScene.SolarSystem) { @@ -81,7 +81,7 @@ namespace QSB.SectorSync.WorldObjects } else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) { - var shuttleController = Resources.FindObjectsOfTypeAll().First(); + var shuttleController = QSBWorldSync.GetUnityObjects().First(); if (shuttleController == null) { DebugLog.ToConsole($"Warning - Expected to find a EyeShuttleController for {AttachedObject.name}!", MessageType.Warning); @@ -98,4 +98,4 @@ namespace QSB.SectorSync.WorldObjects return true; } } -} \ No newline at end of file +} diff --git a/QSB/ShipSync/Events/Component/ComponentDamagedEvent.cs b/QSB/ShipSync/Events/Component/ComponentDamagedEvent.cs index 28af746e..43f2811d 100644 --- a/QSB/ShipSync/Events/Component/ComponentDamagedEvent.cs +++ b/QSB/ShipSync/Events/Component/ComponentDamagedEvent.cs @@ -16,7 +16,7 @@ namespace QSB.ShipSync.Events.Component private WorldObjectMessage CreateMessage(ShipComponent hull) { - var worldObject = QSBWorldSync.GetWorldFromUnity(hull); + var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new WorldObjectMessage { AboutId = LocalPlayerId, diff --git a/QSB/ShipSync/Events/Component/ComponentRepairTickEvent.cs b/QSB/ShipSync/Events/Component/ComponentRepairTickEvent.cs index 5578fb88..e99ef887 100644 --- a/QSB/ShipSync/Events/Component/ComponentRepairTickEvent.cs +++ b/QSB/ShipSync/Events/Component/ComponentRepairTickEvent.cs @@ -15,7 +15,7 @@ namespace QSB.ShipSync.Events.Component private RepairTickMessage CreateMessage(ShipComponent hull, float repairFraction) { - var worldObject = QSBWorldSync.GetWorldFromUnity(hull); + var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new RepairTickMessage { AboutId = LocalPlayerId, diff --git a/QSB/ShipSync/Events/Component/ComponentRepairedEvent.cs b/QSB/ShipSync/Events/Component/ComponentRepairedEvent.cs index da0fa26b..9c98789d 100644 --- a/QSB/ShipSync/Events/Component/ComponentRepairedEvent.cs +++ b/QSB/ShipSync/Events/Component/ComponentRepairedEvent.cs @@ -16,7 +16,7 @@ namespace QSB.ShipSync.Events.Component private WorldObjectMessage CreateMessage(ShipComponent hull) { - var worldObject = QSBWorldSync.GetWorldFromUnity(hull); + var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new WorldObjectMessage { AboutId = LocalPlayerId, diff --git a/QSB/ShipSync/Events/FlyShipEvent.cs b/QSB/ShipSync/Events/FlyShipEvent.cs index da877e20..db4f9c56 100644 --- a/QSB/ShipSync/Events/FlyShipEvent.cs +++ b/QSB/ShipSync/Events/FlyShipEvent.cs @@ -28,7 +28,7 @@ namespace QSB.ShipSync.Events private void Handler(bool flying) => SendEvent(CreateMessage(flying)); - private BoolMessage CreateMessage(bool flying) => new BoolMessage + private BoolMessage CreateMessage(bool flying) => new() { AboutId = LocalPlayerId, Value = flying diff --git a/QSB/ShipSync/Events/FunnelEnableEvent.cs b/QSB/ShipSync/Events/FunnelEnableEvent.cs index ab177fa3..2a7e4789 100644 --- a/QSB/ShipSync/Events/FunnelEnableEvent.cs +++ b/QSB/ShipSync/Events/FunnelEnableEvent.cs @@ -15,7 +15,7 @@ namespace QSB.ShipSync.Events private void Handler() => SendEvent(CreateMessage()); - private PlayerMessage CreateMessage() => new PlayerMessage + private PlayerMessage CreateMessage() => new() { AboutId = LocalPlayerId }; diff --git a/QSB/ShipSync/Events/HatchEvent.cs b/QSB/ShipSync/Events/HatchEvent.cs index d1dcb503..8991b342 100644 --- a/QSB/ShipSync/Events/HatchEvent.cs +++ b/QSB/ShipSync/Events/HatchEvent.cs @@ -16,7 +16,7 @@ namespace QSB.ShipSync.Events private void Handler(bool open) => SendEvent(CreateMessage(open)); - private BoolMessage CreateMessage(bool open) => new BoolMessage + private BoolMessage CreateMessage(bool open) => new() { AboutId = LocalPlayerId, Value = open diff --git a/QSB/ShipSync/Events/Hull/HullChangeIntegrityEvent.cs b/QSB/ShipSync/Events/Hull/HullChangeIntegrityEvent.cs index cf5c1466..3b3c6158 100644 --- a/QSB/ShipSync/Events/Hull/HullChangeIntegrityEvent.cs +++ b/QSB/ShipSync/Events/Hull/HullChangeIntegrityEvent.cs @@ -15,7 +15,7 @@ namespace QSB.ShipSync.Events.Hull private HullChangeIntegrityMessage CreateMessage(ShipHull hull, float integrity) { - var worldObject = QSBWorldSync.GetWorldFromUnity(hull); + var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new HullChangeIntegrityMessage { AboutId = LocalPlayerId, diff --git a/QSB/ShipSync/Events/Hull/HullDamagedEvent.cs b/QSB/ShipSync/Events/Hull/HullDamagedEvent.cs index 2df78b8b..bebc0cbb 100644 --- a/QSB/ShipSync/Events/Hull/HullDamagedEvent.cs +++ b/QSB/ShipSync/Events/Hull/HullDamagedEvent.cs @@ -16,7 +16,7 @@ namespace QSB.ShipSync.Events.Hull private WorldObjectMessage CreateMessage(ShipHull hull) { - var worldObject = QSBWorldSync.GetWorldFromUnity(hull); + var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new WorldObjectMessage { AboutId = LocalPlayerId, diff --git a/QSB/ShipSync/Events/Hull/HullImpactEvent.cs b/QSB/ShipSync/Events/Hull/HullImpactEvent.cs index 8ed4e243..0455cc13 100644 --- a/QSB/ShipSync/Events/Hull/HullImpactEvent.cs +++ b/QSB/ShipSync/Events/Hull/HullImpactEvent.cs @@ -15,7 +15,7 @@ namespace QSB.ShipSync.Events.Hull private HullImpactMessage CreateMessage(ShipHull hull, ImpactData data, float damage) { - var worldObject = QSBWorldSync.GetWorldFromUnity(hull); + var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new HullImpactMessage { AboutId = LocalPlayerId, diff --git a/QSB/ShipSync/Events/Hull/HullRepairTickEvent.cs b/QSB/ShipSync/Events/Hull/HullRepairTickEvent.cs index 1ff86934..522f510e 100644 --- a/QSB/ShipSync/Events/Hull/HullRepairTickEvent.cs +++ b/QSB/ShipSync/Events/Hull/HullRepairTickEvent.cs @@ -15,7 +15,7 @@ namespace QSB.ShipSync.Events.Hull private RepairTickMessage CreateMessage(ShipHull hull, float repairFraction) { - var worldObject = QSBWorldSync.GetWorldFromUnity(hull); + var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new RepairTickMessage { AboutId = LocalPlayerId, diff --git a/QSB/ShipSync/Events/Hull/HullRepairedEvent.cs b/QSB/ShipSync/Events/Hull/HullRepairedEvent.cs index 2bc6e411..6f128ef0 100644 --- a/QSB/ShipSync/Events/Hull/HullRepairedEvent.cs +++ b/QSB/ShipSync/Events/Hull/HullRepairedEvent.cs @@ -16,7 +16,7 @@ namespace QSB.ShipSync.Events.Hull private WorldObjectMessage CreateMessage(ShipHull hull) { - var worldObject = QSBWorldSync.GetWorldFromUnity(hull); + var worldObject = QSBWorldSync.GetWorldFromUnity(hull); return new WorldObjectMessage { AboutId = LocalPlayerId, diff --git a/QSB/ShipSync/Patches/ShipPatches.cs b/QSB/ShipSync/Patches/ShipPatches.cs index 0d3c5c9a..2bc90fa0 100644 --- a/QSB/ShipSync/Patches/ShipPatches.cs +++ b/QSB/ShipSync/Patches/ShipPatches.cs @@ -55,10 +55,7 @@ namespace QSB.ShipSync.Patches [HarmonyReversePatch] [HarmonyPatch(typeof(SingleInteractionVolume), nameof(SingleInteractionVolume.UpdateInteractVolume))] - public static void SingleInteractionVolume_UpdateInteractVolume_Stub(object instance) - { - throw new NotImplementedException(); - } + public static void SingleInteractionVolume_UpdateInteractVolume_Stub(object instance) => throw new NotImplementedException(); [HarmonyPrefix] [HarmonyPatch(typeof(InteractZone), nameof(InteractZone.UpdateInteractVolume))] @@ -87,39 +84,33 @@ namespace QSB.ShipSync.Patches ? angle <= 80 : angle >= 280; - SingleInteractionVolume_UpdateInteractVolume_Stub(__instance as SingleInteractionVolume); + SingleInteractionVolume_UpdateInteractVolume_Stub(__instance); return false; } [HarmonyReversePatch] [HarmonyPatch(typeof(ShipComponent), nameof(ShipComponent.OnEnterShip))] - public static void ShipComponent_OnEnterShip_Stub(object instance) - { - throw new NotImplementedException(); - } + public static void ShipComponent_OnEnterShip_Stub(object instance) => throw new NotImplementedException(); [HarmonyPrefix] [HarmonyPatch(typeof(ShipElectricalComponent), nameof(ShipElectricalComponent.OnEnterShip))] public static bool ShipElectricalComponent_OnEnterShip(ShipElectricalComponent __instance) { - ShipComponent_OnEnterShip_Stub(__instance as ShipComponent); + ShipComponent_OnEnterShip_Stub(__instance); return false; } [HarmonyReversePatch] [HarmonyPatch(typeof(ShipComponent), nameof(ShipComponent.OnExitShip))] - public static void ShipComponent_OnExitShip_Stub(object instance) - { - throw new NotImplementedException(); - } + public static void ShipComponent_OnExitShip_Stub(object instance) => throw new NotImplementedException(); [HarmonyPrefix] [HarmonyPatch(typeof(ShipElectricalComponent), nameof(ShipElectricalComponent.OnExitShip))] public static bool ShipElectricalComponent_OnExitShip(ShipElectricalComponent __instance) { - ShipComponent_OnExitShip_Stub(__instance as ShipComponent); + ShipComponent_OnExitShip_Stub(__instance); return false; } @@ -233,7 +224,7 @@ namespace QSB.ShipSync.Patches return false; } - ____integrity = Mathf.Min(____integrity + Time.deltaTime / ____repairTime, 1f); + ____integrity = Mathf.Min(____integrity + (Time.deltaTime / ____repairTime), 1f); QSBEventManager.FireEvent(EventNames.QSBHullRepairTick, __instance, ____integrity); if (____integrity >= 1f) diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index d2b55251..31204387 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -37,7 +37,7 @@ namespace QSB.ShipSync } } - private List _playersInShip = new List(); + private List _playersInShip = new(); private uint _currentFlyer = uint.MaxValue; @@ -61,9 +61,9 @@ namespace QSB.ShipSync } HatchInteractZone = HatchController.GetComponent(); - ShipTractorBeam = Resources.FindObjectsOfTypeAll().First(); - CockpitController = Resources.FindObjectsOfTypeAll().First(); - ShipElectricalComponent = Resources.FindObjectsOfTypeAll().First(); + ShipTractorBeam = QSBWorldSync.GetUnityObjects().First(); + CockpitController = QSBWorldSync.GetUnityObjects().First(); + ShipElectricalComponent = QSBWorldSync.GetUnityObjects().First(); var sphereShape = HatchController.GetComponent(); sphereShape.radius = 2.5f; diff --git a/QSB/ShipSync/TransformSync/ShipTransformSync.cs b/QSB/ShipSync/TransformSync/ShipTransformSync.cs index 80359b87..9a6f232b 100644 --- a/QSB/ShipSync/TransformSync/ShipTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipTransformSync.cs @@ -1,6 +1,8 @@ using QSB.SectorSync; +using QSB.Syncs; using QSB.Syncs.Sectored.Rigidbodies; using QSB.WorldSync; +using UnityEngine; namespace QSB.ShipSync.TransformSync { @@ -33,11 +35,11 @@ namespace QSB.ShipSync.TransformSync return; } - var targetPos = _intermediaryTransform.GetTargetPosition_Unparented(); - var targetRot = _intermediaryTransform.GetTargetRotation_Unparented(); + var targetPos = ReferenceTransform.DecodePos(transform.position); + var targetRot = ReferenceTransform.DecodeRot(transform.rotation); - (AttachedObject as OWRigidbody).SetPosition(targetPos); - (AttachedObject as OWRigidbody).SetRotation(targetRot); + ((ShipBody)AttachedObject).SetPosition(targetPos); + ((ShipBody)AttachedObject).SetRotation(targetRot); } protected override bool UpdateTransform() @@ -68,18 +70,34 @@ namespace QSB.ShipSync.TransformSync return true; } - var targetPos = _intermediaryTransform.GetTargetPosition_Unparented(); + var targetPos = ReferenceTransform.DecodePos(transform.position); - var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().GetPointVelocity(targetPos) + _relativeVelocity; - var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().GetAngularVelocity() + _relativeAngularVelocity; + var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); + var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); - SetVelocity(AttachedObject as OWRigidbody, targetVelocity); - (AttachedObject as OWRigidbody).SetAngularVelocity(targetAngularVelocity); + SetVelocity((ShipBody)AttachedObject, targetVelocity); + ((ShipBody)AttachedObject).SetAngularVelocity(targetAngularVelocity); return true; } + /// use OWRigidbody version instead of ShipBody override + private void SetVelocity(OWRigidbody rigidbody, Vector3 newVelocity) + { + if (rigidbody.RunningKinematicSimulation()) + { + rigidbody._kinematicRigidbody.velocity = newVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameVelocity_Internal(); + } + else + { + rigidbody._rigidbody.velocity = newVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameVelocity_Internal(); + } + + rigidbody._lastVelocity = rigidbody._currentVelocity; + rigidbody._currentVelocity = newVelocity; + } + public override bool UseInterpolation => true; protected override float DistanceLeeway => 20f; } -} \ No newline at end of file +} diff --git a/QSB/StatueSync/Events/StartStatueEvent.cs b/QSB/StatueSync/Events/StartStatueEvent.cs index 75238b05..6f39404a 100644 --- a/QSB/StatueSync/Events/StartStatueEvent.cs +++ b/QSB/StatueSync/Events/StartStatueEvent.cs @@ -1,5 +1,6 @@ using QSB.ClientServerStateSync; using QSB.Events; +using QSB.Utility; using UnityEngine; namespace QSB.StatueSync.Events @@ -17,7 +18,7 @@ namespace QSB.StatueSync.Events private void Handler(Vector3 position, Quaternion rotation, float degrees) => SendEvent(CreateMessage(position, rotation, degrees)); - private StartStatueMessage CreateMessage(Vector3 position, Quaternion rotation, float degrees) => new StartStatueMessage + private StartStatueMessage CreateMessage(Vector3 position, Quaternion rotation, float degrees) => new() { AboutId = LocalPlayerId, PlayerPosition = position, @@ -27,6 +28,8 @@ namespace QSB.StatueSync.Events public override void OnReceiveLocal(bool server, StartStatueMessage message) { + DebugLog.DebugWrite($"OnReceiveLocal StartStatueEvent"); + if (!QSBCore.IsHost) { return; @@ -36,6 +39,9 @@ namespace QSB.StatueSync.Events } public override void OnReceiveRemote(bool server, StartStatueMessage message) - => StatueManager.Instance.BeginSequence(message.PlayerPosition, message.PlayerRotation, message.CameraDegrees); + { + DebugLog.DebugWrite($"OnReceiveRemote StartStatueEvent"); + StatueManager.Instance.BeginSequence(message.PlayerPosition, message.PlayerRotation, message.CameraDegrees); + } } } diff --git a/QSB/StatueSync/StatueManager.cs b/QSB/StatueSync/StatueManager.cs index c19718c4..6ee6ebee 100644 --- a/QSB/StatueSync/StatueManager.cs +++ b/QSB/StatueSync/StatueManager.cs @@ -12,14 +12,24 @@ namespace QSB.StatueSync private void Awake() { Instance = this; - QSBSceneManager.OnUniverseSceneLoaded += (OWScene oldScene, OWScene newScene) => QSBPlayerManager.ShowAllPlayers(); + QSBSceneManager.OnUniverseSceneLoaded += OnUniverseSceneLoaded; } private void OnDestroy() - => QSBSceneManager.OnUniverseSceneLoaded -= (OWScene oldScene, OWScene newScene) => QSBPlayerManager.ShowAllPlayers(); + => QSBSceneManager.OnUniverseSceneLoaded -= OnUniverseSceneLoaded; - public void BeginSequence(Vector3 position, Quaternion rotation, float cameraDegrees) - => StartCoroutine(BeginRemoteUplinkSequence(position, rotation, cameraDegrees)); + private void OnUniverseSceneLoaded(OWScene oldScene, OWScene newScene) + { + if (!QSBCore.IsInMultiplayer) + { + return; + } + + QSBPlayerManager.ShowAllPlayers(); + QSBPlayerManager.LocalPlayer.UpdateStatesFromObjects(); + } + + public void BeginSequence(Vector3 position, Quaternion rotation, float cameraDegrees) => StartCoroutine(BeginRemoteUplinkSequence(position, rotation, cameraDegrees)); private IEnumerator BeginRemoteUplinkSequence(Vector3 position, Quaternion rotation, float cameraDegrees) { diff --git a/QSB/Syncs/IntermediaryTransform.cs b/QSB/Syncs/IntermediaryTransform.cs deleted file mode 100644 index f4ec1ae8..00000000 --- a/QSB/Syncs/IntermediaryTransform.cs +++ /dev/null @@ -1,123 +0,0 @@ -using OWML.Common; -using QSB.Utility; -using System; -using UnityEngine; - -namespace QSB.Syncs -{ - public class IntermediaryTransform - { - private Transform _attachedTransform; - private Transform _referenceTransform; - - public IntermediaryTransform(Transform transform) - => _attachedTransform = transform; - - /// - /// Get the world position of this INVISIBLE transform. - /// - public Vector3 GetPosition() - => _attachedTransform.position; - - /// - /// Set the world position of this INVISIBLE transform. - /// - public void SetPosition(Vector3 worldPos) - => _attachedTransform.position = worldPos; - - /// - /// Get the world rotation of this INVISIBLE transform. - /// - public Quaternion GetRotation() - => _attachedTransform.rotation; - - /// - /// Set the world rotation of this INVISIBLE transform. - /// - public void SetRotation(Quaternion worldRot) - => _attachedTransform.rotation = worldRot; - - /// - /// Sets the reference transform - what transform this transform is syncing to. - /// - /// The new reference sector. - public void SetReferenceTransform(Transform transform) - => _referenceTransform = transform; - - /// - /// Returns the reference transform - what transform this transform is syncing to. - /// - public Transform GetReferenceTransform() - => _referenceTransform; - - /// - /// Sets the position of the INVISIBLE transform to be correct, according to the reference sector and the position of the VISIBLE transform. - /// - /// The world position of the VISIBLE transform. - public void EncodePosition(Vector3 worldPosition) - { - if (_referenceTransform == null) - { - DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error); - return; - } - - SetPosition(_referenceTransform.InverseTransformPoint(worldPosition)); - } - - /// - /// Sets the rotation of the INVISIBLE transform to be correct, according to the reference sector and the rotation of the VISIBLE transform. - /// - /// The world rotation of the VISIBLE transform. - public void EncodeRotation(Quaternion worldRotation) - { - if (_referenceTransform == null) - { - DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error); - return; - } - - SetRotation(_referenceTransform.InverseTransformRotation(worldRotation)); - } - - /// - /// Returns the local position the VISIBLE transform should be set to, from the INVISIBLE transform. - /// - public Vector3 GetTargetPosition_ParentedToReference() - => GetPosition(); - - /// - /// Returns the local rotation the VISIBLE transform should be set to, from the INVISIBLE transform. - /// - public Quaternion GetTargetRotation_ParentedToReference() - => GetRotation(); - - /// - /// Returns the world position the VISIBLE transform should be set to, from the INVISIBLE transform. - /// - public Vector3 GetTargetPosition_Unparented() - { - if (_referenceTransform == null) - { - DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error); - return Vector3.zero; - } - - return _referenceTransform.TransformPoint(GetPosition()); - } - - /// - /// Returns the world rotation the VISIBLE transform should be set to, from the INVISIBLE transform. - /// - public Quaternion GetTargetRotation_Unparented() - { - if (_referenceTransform == null) - { - DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error); - return Quaternion.identity; - } - - return _referenceTransform.TransformRotation(GetRotation()); - } - } -} diff --git a/QSB/Syncs/Sectored/BaseSectoredSync.cs b/QSB/Syncs/Sectored/BaseSectoredSync.cs index 36064dab..c25423c7 100644 --- a/QSB/Syncs/Sectored/BaseSectoredSync.cs +++ b/QSB/Syncs/Sectored/BaseSectoredSync.cs @@ -65,7 +65,7 @@ namespace QSB.Syncs.Sectored } else { - DebugLog.ToConsole($"Warning - {_logName}'s initial sector was null.", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - {LogName}'s initial sector was null.", OWML.Common.MessageType.Warning); } } @@ -75,7 +75,7 @@ namespace QSB.Syncs.Sectored { if (ReferenceSector != null && ReferenceSector.Transform != ReferenceTransform) { - DebugLog.ToConsole($"Warning - {_logName} : ReferenceSector.Transform was different to ReferenceTransform. Correcting...", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - {LogName} : ReferenceSector.Transform was different to ReferenceTransform. Correcting...", OWML.Common.MessageType.Warning); SetReferenceTransform(ReferenceSector.Transform); } @@ -112,16 +112,11 @@ namespace QSB.Syncs.Sectored public override void SerializeTransform(QNetworkWriter writer, bool initialState) { - if (_intermediaryTransform == null) - { - _intermediaryTransform = new IntermediaryTransform(transform); - } - if (!QSBPlayerManager.PlayerExists(PlayerId)) { writer.Write(-1); } - else if (!Player.PlayerStates.IsReady) + else if (!Player.IsReady) { writer.Write(-1); } @@ -148,7 +143,7 @@ namespace QSB.Syncs.Sectored sectorId = reader.ReadInt32(); if (initialState && sectorId != -1) { - DebugLog.DebugWrite($"{_logName} set waiting sector id:{sectorId}"); + DebugLog.DebugWrite($"{LogName} set waiting sector id:{sectorId}"); _sectorIdWaitingSlot = sectorId; } @@ -174,7 +169,7 @@ namespace QSB.Syncs.Sectored protected bool UpdateSectors() { - var referenceNull = ReferenceTransform == null || ReferenceSector == null || _intermediaryTransform.GetReferenceTransform() == null; + var referenceNull = ReferenceTransform == null || ReferenceSector == null; var sectorManagerReady = QSBSectorManager.Instance.IsReady; if (!sectorManagerReady) @@ -182,11 +177,11 @@ namespace QSB.Syncs.Sectored if (referenceNull && HasAuthority) { DebugLog.ToConsole($"Warning - Reference was null, but sector manager wasn't ready. " + - $"Transform:{ReferenceTransform == null}, Sector:{ReferenceSector == null}, Intermediary:{_intermediaryTransform.GetReferenceTransform() == null}", + $"Transform:{ReferenceTransform == null}, Sector:{ReferenceSector == null}", OWML.Common.MessageType.Warning); } - DebugLog.DebugWrite($"{_logName} : Sector Manager not ready."); + DebugLog.DebugWrite($"{LogName} : Sector Manager not ready."); return false; } diff --git a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs index dba1c782..a676c5d6 100644 --- a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs +++ b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs @@ -1,5 +1,4 @@ using OWML.Common; -using OWML.Utils; using QSB.Utility; using QuantumUNET.Transport; using UnityEngine; @@ -42,8 +41,8 @@ namespace QSB.Syncs.Sectored.Rigidbodies { base.SerializeTransform(writer, initialState); - var worldPos = _intermediaryTransform.GetPosition(); - var worldRot = _intermediaryTransform.GetRotation(); + var worldPos = transform.position; + var worldRot = transform.rotation; var relativeVelocity = _relativeVelocity; var relativeAngularVelocity = _relativeAngularVelocity; @@ -81,28 +80,23 @@ namespace QSB.Syncs.Sectored.Rigidbodies return; } - if (_intermediaryTransform == null) - { - _intermediaryTransform = new IntermediaryTransform(transform); - } - - _intermediaryTransform.SetPosition(pos); - _intermediaryTransform.SetRotation(rot); + transform.position = pos; + transform.rotation = rot; _relativeVelocity = relativeVelocity; _relativeAngularVelocity = relativeAngularVelocity; - if (_intermediaryTransform.GetPosition() == Vector3.zero) + if (transform.position == Vector3.zero) { - DebugLog.ToConsole($"Warning - {_logName} at (0,0,0)! - Given position was {pos}", MessageType.Warning); + DebugLog.ToConsole($"Warning - {LogName} at (0,0,0)! - Given position was {pos}", MessageType.Warning); } } protected void SetValuesToSync() { - _intermediaryTransform.EncodePosition(AttachedObject.transform.position); - _intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation); - _relativeVelocity = GetRelativeVelocity(); - _relativeAngularVelocity = (AttachedObject as OWRigidbody).GetRelativeAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody()); + transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); + _relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeVel(((OWRigidbody)AttachedObject).GetVelocity(), AttachedObject.transform.position); + _relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeAngVel(((OWRigidbody)AttachedObject).GetAngularVelocity()); } protected override bool UpdateTransform() @@ -118,16 +112,16 @@ namespace QSB.Syncs.Sectored.Rigidbodies return true; } - var targetPos = _intermediaryTransform.GetTargetPosition_Unparented(); - var targetRot = _intermediaryTransform.GetTargetRotation_Unparented(); + var targetPos = ReferenceTransform.DecodePos(transform.position); + var targetRot = ReferenceTransform.DecodeRot(transform.rotation); - if (targetPos == Vector3.zero || _intermediaryTransform.GetTargetPosition_ParentedToReference() == Vector3.zero) + if (targetPos == Vector3.zero || transform.position == Vector3.zero) { return false; } - Vector3 positionToSet = targetPos; - Quaternion rotationToSet = targetRot; + var positionToSet = targetPos; + var rotationToSet = targetRot; if (UseInterpolation) { @@ -136,17 +130,17 @@ namespace QSB.Syncs.Sectored.Rigidbodies } var hasMoved = CustomHasMoved( - _intermediaryTransform.GetTargetPosition_ParentedToReference(), + transform.position, _localPrevPosition, - _intermediaryTransform.GetTargetRotation_ParentedToReference(), + transform.rotation, _localPrevRotation, _relativeVelocity, _localPrevVelocity, _relativeAngularVelocity, _localPrevAngularVelocity); - _localPrevPosition = _intermediaryTransform.GetTargetPosition_ParentedToReference(); - _localPrevRotation = _intermediaryTransform.GetTargetRotation_ParentedToReference(); + _localPrevPosition = transform.position; + _localPrevRotation = transform.rotation; _localPrevVelocity = _relativeVelocity; _localPrevAngularVelocity = _relativeAngularVelocity; @@ -155,26 +149,23 @@ namespace QSB.Syncs.Sectored.Rigidbodies return true; } - //(AttachedObject as OWRigidbody).SetPosition(positionToSet); - //(AttachedObject as OWRigidbody).SetRotation(rotationToSet); + ((OWRigidbody)AttachedObject).MoveToPosition(positionToSet); + ((OWRigidbody)AttachedObject).MoveToRotation(rotationToSet); - (AttachedObject as OWRigidbody).MoveToPosition(positionToSet); - (AttachedObject as OWRigidbody).MoveToRotation(rotationToSet); + var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); + var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); - var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().GetPointVelocity(targetPos) + _relativeVelocity; - var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().GetAngularVelocity() + _relativeAngularVelocity; - - SetVelocity(AttachedObject as OWRigidbody, targetVelocity); - (AttachedObject as OWRigidbody).SetAngularVelocity(targetAngularVelocity); + ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); + ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); return true; } public override bool HasMoved() => CustomHasMoved( - _intermediaryTransform.GetPosition(), + transform.position, _prevPosition, - _intermediaryTransform.GetRotation(), + transform.rotation, _prevRotation, _relativeVelocity, _prevVelocity, @@ -218,54 +209,5 @@ namespace QSB.Syncs.Sectored.Rigidbodies return false; } - - // TODO : why? isn't owrigidbody.setvelocity the same...? :P - protected void SetVelocity(OWRigidbody rigidbody, Vector3 relativeVelocity) - { - var isRunningKinematic = rigidbody.RunningKinematicSimulation(); - var currentVelocity = rigidbody.GetValue("_currentVelocity"); - - if (isRunningKinematic) - { - var kinematicRigidbody = rigidbody.GetValue("_kinematicRigidbody"); - kinematicRigidbody.velocity = relativeVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameVelocity_Internal(); - } - else - { - var normalRigidbody = rigidbody.GetValue("_rigidbody"); - normalRigidbody.velocity = relativeVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameVelocity_Internal(); - } - - rigidbody.SetValue("_lastVelocity", currentVelocity); - rigidbody.SetValue("_currentVelocity", relativeVelocity); - } - - public float GetVelocityChangeMagnitude() - => (_relativeVelocity - _prevVelocity).magnitude; - - public Vector3 GetRelativeVelocity() - { - if (AttachedObject == null) - { - DebugLog.ToConsole($"Error - Trying to get relative velocity when AttachedObject is null.", MessageType.Error); - return Vector3.zero; - } - - if (ReferenceTransform == null) - { - DebugLog.ToConsole($"Error - Trying to get relative velocity when ReferenceTransform is null. ({AttachedObject.name})", MessageType.Error); - return Vector3.zero; - } - - var attachedRigid = ReferenceTransform.GetAttachedOWRigidbody(); - if (attachedRigid == null) - { - DebugLog.ToConsole($"Error - ReferenceTransform ({ReferenceTransform.name}) on {AttachedObject.name} has no attached OWRigidBody.", MessageType.Error); - return Vector3.zero; - } - - var pointVelocity = attachedRigid.GetPointVelocity(AttachedObject.transform.position); - return (AttachedObject as OWRigidbody).GetVelocity() - pointVelocity; - } } } diff --git a/QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs b/QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs index 55798988..d25e5ccd 100644 --- a/QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs +++ b/QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs @@ -19,8 +19,8 @@ namespace QSB.Syncs.Sectored.Transforms { base.SerializeTransform(writer, initialState); - var worldPos = _intermediaryTransform.GetPosition(); - var worldRot = _intermediaryTransform.GetRotation(); + var worldPos = transform.position; + var worldRot = transform.rotation; writer.Write(worldPos); SerializeRotation(writer, worldRot); _prevPosition = worldPos; @@ -46,17 +46,12 @@ namespace QSB.Syncs.Sectored.Transforms return; } - if (_intermediaryTransform == null) - { - _intermediaryTransform = new IntermediaryTransform(transform); - } + transform.position = pos; + transform.rotation = rot; - _intermediaryTransform.SetPosition(pos); - _intermediaryTransform.SetRotation(rot); - - if (_intermediaryTransform.GetPosition() == Vector3.zero) + if (transform.position == Vector3.zero) { - DebugLog.ToConsole($"Warning - {_logName} at (0,0,0)! - Given position was {pos}", MessageType.Warning); + DebugLog.ToConsole($"Warning - {LogName} at (0,0,0)! - Given position was {pos}", MessageType.Warning); } } @@ -71,21 +66,21 @@ namespace QSB.Syncs.Sectored.Transforms { if (ReferenceTransform != null) { - _intermediaryTransform.EncodePosition(AttachedObject.transform.position); - _intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation); + transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); } else { - _intermediaryTransform.SetPosition(Vector3.zero); - _intermediaryTransform.SetRotation(Quaternion.identity); + transform.position = Vector3.zero; + transform.rotation = Quaternion.identity; } return true; } - var targetPos = _intermediaryTransform.GetTargetPosition_ParentedToReference(); - var targetRot = _intermediaryTransform.GetTargetRotation_ParentedToReference(); - if (targetPos != Vector3.zero && _intermediaryTransform.GetTargetPosition_Unparented() != Vector3.zero) + var targetPos = transform.position; + var targetRot = transform.rotation; + if (targetPos != Vector3.zero && ReferenceTransform.DecodePos(transform.position) != Vector3.zero) { if (UseInterpolation) { diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 1c98238c..edb48a94 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -18,7 +18,7 @@ namespace QSB.Syncs public abstract class SyncBase : QNetworkTransform { - private static readonly Dictionary> _storedTransformSyncs = new Dictionary>(); + private static readonly Dictionary> _storedTransformSyncs = new(); public static T GetPlayers(PlayerInfo player) where T : SyncBase @@ -28,7 +28,7 @@ namespace QSB.Syncs if (wantedSync == default) { DebugLog.ToConsole($"Error - _storedTransformSyncs does not contain type:{typeof(T)} under player {player.PlayerId}. Attempting to find manually...", MessageType.Error); - var allSyncs = Resources.FindObjectsOfTypeAll(); + var allSyncs = QSBWorldSync.GetUnityObjects(); wantedSync = allSyncs.First(x => x.Player == player); if (wantedSync == default) { @@ -73,7 +73,7 @@ namespace QSB.Syncs public PlayerInfo Player => QSBPlayerManager.GetPlayer(PlayerId); private bool _baseIsReady => QSBPlayerManager.PlayerExists(PlayerId) && Player != null - && Player.PlayerStates.IsReady + && Player.IsReady && NetId.Value != uint.MaxValue && NetId.Value != 0U && WorldObjectManager.AllReady; @@ -86,13 +86,12 @@ namespace QSB.Syncs public Component AttachedObject { get; set; } public Transform ReferenceTransform { get; set; } - protected string _logName => $"{PlayerId}.{NetId.Value}:{GetType().Name}"; + public string LogName => $"{PlayerId}.{NetId.Value}:{GetType().Name}"; protected virtual float DistanceLeeway { get; } = 5f; private float _previousDistance; protected const float SmoothTime = 0.1f; protected Vector3 _positionSmoothVelocity; protected Quaternion _rotationSmoothVelocity; - protected IntermediaryTransform _intermediaryTransform; protected bool _isInitialized; protected abstract Component SetAttachedObject(); @@ -100,17 +99,16 @@ namespace QSB.Syncs public virtual void Start() { - var lowestBound = Resources.FindObjectsOfTypeAll() + var lowestBound = QSBWorldSync.GetUnityObjects() .Where(x => x.NetId.Value <= NetId.Value).OrderBy(x => x.NetId.Value).Last(); NetIdentity.SetRootIdentity(lowestBound.NetIdentity); DontDestroyOnLoad(gameObject); - _intermediaryTransform = new IntermediaryTransform(transform); QSBSceneManager.OnSceneLoaded += OnSceneLoaded; if (Player == null) { - DebugLog.ToConsole($"Error - Player in start of {_logName} was null!", MessageType.Error); + DebugLog.ToConsole($"Error - Player in start of {LogName} was null!", MessageType.Error); return; } @@ -148,7 +146,7 @@ namespace QSB.Syncs { if (!QSBSceneManager.IsInUniverse) { - DebugLog.ToConsole($"Error - {_logName} is being init-ed when not in the universe!", MessageType.Error); + DebugLog.ToConsole($"Error - {LogName} is being init-ed when not in the universe!", MessageType.Error); } // TODO : maybe make it's own option @@ -164,16 +162,23 @@ namespace QSB.Syncs _isInitialized = true; } - protected virtual void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse) - { - _isInitialized = false; - } + protected virtual void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse) => _isInitialized = false; public override void Update() { if (!_isInitialized && IsReady && _baseIsReady) { - Init(); + + try + { + Init(); + } + catch (Exception ex) + { + DebugLog.ToConsole($"Exception when initializing {name} : {ex}", MessageType.Error); + enabled = false; + } + base.Update(); return; } @@ -192,7 +197,7 @@ namespace QSB.Syncs if (AttachedObject == null) { - DebugLog.ToConsole($"Warning - AttachedObject {_logName} is null.", MessageType.Warning); + DebugLog.ToConsole($"Warning - AttachedObject {LogName} is null.", MessageType.Warning); _isInitialized = false; base.Update(); return; @@ -200,7 +205,7 @@ namespace QSB.Syncs if (ReferenceTransform != null && ReferenceTransform.position == Vector3.zero) { - DebugLog.ToConsole($"Warning - {_logName}'s ReferenceTransform is at (0,0,0). ReferenceTransform:{ReferenceTransform.name}, AttachedObject:{AttachedObject.name}", MessageType.Warning); + DebugLog.ToConsole($"Warning - {LogName}'s ReferenceTransform is at (0,0,0). ReferenceTransform:{ReferenceTransform.name}, AttachedObject:{AttachedObject.name}", MessageType.Warning); } if (!AttachedObject.gameObject.activeInHierarchy && !IgnoreDisabledAttachedObject) @@ -211,14 +216,7 @@ namespace QSB.Syncs if (ReferenceTransform == null && !IgnoreNullReferenceTransform) { - DebugLog.ToConsole($"Warning - {_logName}'s ReferenceTransform is null. AttachedObject:{AttachedObject.name}", MessageType.Warning); - base.Update(); - return; - } - - if (ReferenceTransform != _intermediaryTransform.GetReferenceTransform()) - { - DebugLog.ToConsole($"Warning - {_logName}'s ReferenceTransform does not match the reference transform set for the intermediary. ReferenceTransform null : {ReferenceTransform == null}, Intermediary reference null : {_intermediaryTransform.GetReferenceTransform() == null}"); + DebugLog.ToConsole($"Warning - {LogName}'s ReferenceTransform is null. AttachedObject:{AttachedObject.name}", MessageType.Warning); base.Update(); return; } @@ -227,7 +225,7 @@ namespace QSB.Syncs && !HasAuthority && AttachedObject.transform.parent != ReferenceTransform) { - DebugLog.ToConsole($"Warning : {_logName} : AttachedObject's parent is different to ReferenceTransform. Correcting...", MessageType.Warning); + DebugLog.ToConsole($"Warning : {LogName} : AttachedObject's parent is different to ReferenceTransform. Correcting...", MessageType.Warning); ReparentAttachedObject(ReferenceTransform); } @@ -254,37 +252,36 @@ namespace QSB.Syncs return Vector3.SmoothDamp(currentPosition, targetPosition, ref _positionSmoothVelocity, SmoothTime); } - public void SetReferenceTransform(Transform transform) + public void SetReferenceTransform(Transform referenceTransform) { - if (ReferenceTransform == transform) + if (ReferenceTransform == referenceTransform) { return; } - ReferenceTransform = transform; - _intermediaryTransform.SetReferenceTransform(transform); + ReferenceTransform = referenceTransform; if (ShouldReparentAttachedObject) { if (AttachedObject == null) { - DebugLog.ToConsole($"Warning - AttachedObject was null for {_logName} when trying to set reference transform to {transform?.name}. Waiting until not null...", MessageType.Warning); + DebugLog.ToConsole($"Warning - AttachedObject was null for {LogName} when trying to set reference transform to {referenceTransform?.name}. Waiting until not null...", MessageType.Warning); QSBCore.UnityEvents.RunWhen( () => AttachedObject != null, - () => ReparentAttachedObject(transform)); + () => ReparentAttachedObject(referenceTransform)); return; } if (!HasAuthority) { - ReparentAttachedObject(transform); + ReparentAttachedObject(referenceTransform); } } if (HasAuthority) { - _intermediaryTransform.EncodePosition(AttachedObject.transform.position); - _intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation); + transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); } } @@ -302,11 +299,9 @@ namespace QSB.Syncs protected virtual void OnRenderObject() { if (!QSBCore.WorldObjectsReady - || !QSBCore.DebugMode || !QSBCore.ShowLinesInDebug || !IsReady - || ReferenceTransform == null - || _intermediaryTransform.GetReferenceTransform() == null) + || ReferenceTransform == null) { return; } @@ -318,8 +313,8 @@ namespace QSB.Syncs * Cyan Line = Connection between Green/Yellow cube and reference transform */ - Popcron.Gizmos.Cube(_intermediaryTransform.GetTargetPosition_Unparented(), _intermediaryTransform.GetTargetRotation_Unparented(), Vector3.one / 4, Color.red); - Popcron.Gizmos.Line(_intermediaryTransform.GetTargetPosition_Unparented(), AttachedObject.transform.position, Color.red); + Popcron.Gizmos.Cube(ReferenceTransform.DecodePos(transform.position), ReferenceTransform.DecodeRot(transform.rotation), Vector3.one / 4, Color.red); + Popcron.Gizmos.Line(ReferenceTransform.DecodePos(transform.position), AttachedObject.transform.position, Color.red); var color = HasMoved() ? Color.green : Color.yellow; Popcron.Gizmos.Cube(AttachedObject.transform.position, AttachedObject.transform.rotation, Vector3.one / 4, color); Popcron.Gizmos.Cube(ReferenceTransform.position, ReferenceTransform.rotation, Vector3.one / 4, Color.magenta); diff --git a/QSB/Syncs/TransformSyncUtil.cs b/QSB/Syncs/TransformSyncUtil.cs new file mode 100644 index 00000000..8fb77cd2 --- /dev/null +++ b/QSB/Syncs/TransformSyncUtil.cs @@ -0,0 +1,19 @@ +using QSB.Utility; +using UnityEngine; + +namespace QSB.Syncs +{ + /// encode = absolute to relative + /// decode = relative to absolute + public static class TransformSyncUtil + { + public static Vector3 EncodePos(this Transform reference, Vector3 pos) => reference.InverseTransformPoint(pos); + public static Vector3 DecodePos(this Transform reference, Vector3 relPos) => reference.TransformPoint(relPos); + public static Quaternion EncodeRot(this Transform reference, Quaternion rot) => reference.InverseTransformRotation(rot); + public static Quaternion DecodeRot(this Transform reference, Quaternion relRot) => reference.TransformRotation(relRot); + public static Vector3 EncodeVel(this OWRigidbody reference, Vector3 vel, Vector3 pos) => vel - reference.GetPointVelocity(pos); + public static Vector3 DecodeVel(this OWRigidbody reference, Vector3 relVel, Vector3 pos) => relVel + reference.GetPointVelocity(pos); + public static Vector3 EncodeAngVel(this OWRigidbody reference, Vector3 angVel) => angVel - reference.GetAngularVelocity(); + public static Vector3 DecodeAngVel(this OWRigidbody reference, Vector3 relAngVel) => relAngVel + reference.GetAngularVelocity(); + } +} diff --git a/QSB/Syncs/Unsectored/BaseUnsectoredSync.cs b/QSB/Syncs/Unsectored/BaseUnsectoredSync.cs index ff200a0e..91d88648 100644 --- a/QSB/Syncs/Unsectored/BaseUnsectoredSync.cs +++ b/QSB/Syncs/Unsectored/BaseUnsectoredSync.cs @@ -8,12 +8,6 @@ namespace QSB.Syncs.Unsectored public override bool IgnoreNullReferenceTransform => false; public override bool ShouldReparentAttachedObject => false; - public override void SerializeTransform(QNetworkWriter writer, bool initialState) - { - if (_intermediaryTransform == null) - { - _intermediaryTransform = new IntermediaryTransform(transform); - } - } + public override void SerializeTransform(QNetworkWriter writer, bool initialState) { } } } diff --git a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs index 67290c2d..e4be3e0a 100644 --- a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs +++ b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs @@ -1,13 +1,202 @@ -using System; +using QSB.Utility; +using QuantumUNET.Transport; using UnityEngine; namespace QSB.Syncs.Unsectored.Rigidbodies { public abstract class UnsectoredRigidbodySync : BaseUnsectoredSync { + public const float PositionMovedThreshold = 0.05f; + public const float AngleRotatedThreshold = 0.05f; + public const float VelocityChangeThreshold = 0.05f; + public const float AngVelocityChangeThreshold = 0.05f; + + protected Vector3 _relativeVelocity; + protected Vector3 _relativeAngularVelocity; + protected Vector3 _prevVelocity; + protected Vector3 _prevAngularVelocity; + + /// + /// The previous position of the VISIBLE object, as if parented to the reference. + /// + protected Vector3 _localPrevPosition; + + /// + /// The previous rotation of the VISIBLE object, as if parented to the reference. + /// + protected Quaternion _localPrevRotation; + + protected Vector3 _localPrevVelocity; + protected Vector3 _localPrevAngularVelocity; protected abstract OWRigidbody GetRigidbody(); protected override Component SetAttachedObject() - => throw new NotImplementedException(); + => GetRigidbody(); + + public override void SerializeTransform(QNetworkWriter writer, bool initialState) + { + base.SerializeTransform(writer, initialState); + + var worldPos = transform.position; + var worldRot = transform.rotation; + var relativeVelocity = _relativeVelocity; + var relativeAngularVelocity = _relativeAngularVelocity; + + writer.Write(worldPos); + SerializeRotation(writer, worldRot); + writer.Write(relativeVelocity); + writer.Write(relativeAngularVelocity); + + _prevPosition = worldPos; + _prevRotation = worldRot; + _prevVelocity = relativeVelocity; + _prevAngularVelocity = relativeAngularVelocity; + } + + public override void DeserializeTransform(QNetworkReader reader, bool initialState) + { + if (!QSBCore.WorldObjectsReady) + { + reader.ReadVector3(); + DeserializeRotation(reader); + reader.ReadVector3(); + reader.ReadVector3(); + return; + } + + var pos = reader.ReadVector3(); + var rot = DeserializeRotation(reader); + var relativeVelocity = reader.ReadVector3(); + var relativeAngularVelocity = reader.ReadVector3(); + + if (HasAuthority) + { + return; + } + + transform.position = pos; + transform.rotation = rot; + _relativeVelocity = relativeVelocity; + _relativeAngularVelocity = relativeAngularVelocity; + + if (transform.position == Vector3.zero) + { + // DebugLog.ToConsole($"Warning - {_logName} at (0,0,0)! - Given position was {pos}", MessageType.Warning); + } + } + + protected void SetValuesToSync() + { + transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); + _relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeVel(((OWRigidbody)AttachedObject).GetVelocity(), AttachedObject.transform.position); + _relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeAngVel(((OWRigidbody)AttachedObject).GetAngularVelocity()); + } + + protected override bool UpdateTransform() + { + if (HasAuthority) + { + SetValuesToSync(); + return true; + } + + var targetPos = ReferenceTransform.DecodePos(transform.position); + var targetRot = ReferenceTransform.DecodeRot(transform.rotation); + + if (targetPos == Vector3.zero || transform.position == Vector3.zero) + { + return false; + } + + var positionToSet = targetPos; + var rotationToSet = targetRot; + + if (UseInterpolation) + { + positionToSet = SmartSmoothDamp(AttachedObject.transform.position, targetPos); + rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); + } + + var hasMoved = CustomHasMoved( + transform.position, + _localPrevPosition, + transform.rotation, + _localPrevRotation, + _relativeVelocity, + _localPrevVelocity, + _relativeAngularVelocity, + _localPrevAngularVelocity); + + _localPrevPosition = transform.position; + _localPrevRotation = transform.rotation; + _localPrevVelocity = _relativeVelocity; + _localPrevAngularVelocity = _relativeAngularVelocity; + + if (!hasMoved) + { + return true; + } + + ((OWRigidbody)AttachedObject).MoveToPosition(positionToSet); + ((OWRigidbody)AttachedObject).MoveToRotation(rotationToSet); + + var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); + var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); + + ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); + ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); + + return true; + } + + public override bool HasMoved() + => CustomHasMoved( + transform.position, + _prevPosition, + transform.rotation, + _prevRotation, + _relativeVelocity, + _prevVelocity, + _relativeAngularVelocity, + _prevAngularVelocity); + + // OPTIMIZE : optimize by using sqrMagnitude + private bool CustomHasMoved( + Vector3 newPosition, + Vector3 prevPosition, + Quaternion newRotation, + Quaternion prevRotation, + Vector3 newVelocity, + Vector3 prevVelocity, + Vector3 newAngVelocity, + Vector3 prevAngVelocity) + { + var displacementMagnitude = (newPosition - prevPosition).magnitude; + + if (displacementMagnitude > PositionMovedThreshold) + { + return true; + } + + if (Quaternion.Angle(newRotation, prevRotation) > AngleRotatedThreshold) + { + return true; + } + + var velocityChangeMagnitude = (newVelocity - prevVelocity).magnitude; + var angularVelocityChangeMagnitude = (newAngVelocity - prevAngVelocity).magnitude; + if (velocityChangeMagnitude > VelocityChangeThreshold) + { + return true; + } + + if (angularVelocityChangeMagnitude > AngVelocityChangeThreshold) + { + return true; + } + + return false; + } } } diff --git a/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs b/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs index 548ea602..2111b6fc 100644 --- a/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs +++ b/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs @@ -17,8 +17,8 @@ namespace QSB.Syncs.Unsectored.Transforms { base.SerializeTransform(writer, initialState); - var worldPos = _intermediaryTransform.GetPosition(); - var worldRot = _intermediaryTransform.GetRotation(); + var worldPos = transform.position; + var worldRot = transform.rotation; writer.Write(worldPos); SerializeRotation(writer, worldRot); _prevPosition = worldPos; @@ -42,15 +42,10 @@ namespace QSB.Syncs.Unsectored.Transforms return; } - if (_intermediaryTransform == null) - { - _intermediaryTransform = new IntermediaryTransform(transform); - } + transform.position = pos; + transform.rotation = rot; - _intermediaryTransform.SetPosition(pos); - _intermediaryTransform.SetRotation(rot); - - if (_intermediaryTransform.GetPosition() == Vector3.zero) + if (transform.position == Vector3.zero) { //DebugLog.ToConsole($"Warning - {_logName} at (0,0,0)! - Given position was {pos}", MessageType.Warning); } @@ -60,14 +55,14 @@ namespace QSB.Syncs.Unsectored.Transforms { if (HasAuthority) { - _intermediaryTransform.EncodePosition(AttachedObject.transform.position); - _intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation); + transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); return true; } - var targetPos = _intermediaryTransform.GetTargetPosition_Unparented(); - var targetRot = _intermediaryTransform.GetTargetRotation_Unparented(); - if (targetPos != Vector3.zero && _intermediaryTransform.GetTargetPosition_Unparented() != Vector3.zero) + var targetPos = ReferenceTransform.DecodePos(transform.position); + var targetRot = ReferenceTransform.DecodeRot(transform.rotation); + if (targetPos != Vector3.zero && ReferenceTransform.DecodePos(transform.position) != Vector3.zero) { if (UseInterpolation) { @@ -82,7 +77,7 @@ namespace QSB.Syncs.Unsectored.Transforms } else if (targetPos == Vector3.zero) { - DebugLog.ToConsole($"Warning - TargetPos for {_logName} was (0,0,0).", MessageType.Warning); + DebugLog.ToConsole($"Warning - TargetPos for {LogName} was (0,0,0).", MessageType.Warning); } return true; diff --git a/QSB/TimeSync/Events/ServerTimeEvent.cs b/QSB/TimeSync/Events/ServerTimeEvent.cs index cde7c7bc..ea42df74 100644 --- a/QSB/TimeSync/Events/ServerTimeEvent.cs +++ b/QSB/TimeSync/Events/ServerTimeEvent.cs @@ -11,7 +11,7 @@ namespace QSB.TimeSync.Events private void Handler(float time, int count) => SendEvent(CreateMessage(time, count)); - private ServerTimeMessage CreateMessage(float time, int count) => new ServerTimeMessage + private ServerTimeMessage CreateMessage(float time, int count) => new() { AboutId = LocalPlayerId, ServerTime = time, diff --git a/QSB/TimeSync/Patches/TimePatches.cs b/QSB/TimeSync/Patches/TimePatches.cs index 7b43dd11..4db5bc36 100644 --- a/QSB/TimeSync/Patches/TimePatches.cs +++ b/QSB/TimeSync/Patches/TimePatches.cs @@ -1,5 +1,6 @@ using HarmonyLib; using QSB.Patches; +using QSB.Utility; namespace QSB.TimeSync.Patches { @@ -11,8 +12,10 @@ namespace QSB.TimeSync.Patches [HarmonyPrefix] [HarmonyPatch(typeof(PlayerCameraEffectController), nameof(PlayerCameraEffectController.OnStartOfTimeLoop))] public static bool PlayerCameraEffectController_OnStartOfTimeLoop() - => false; - + { + DebugLog.DebugWrite($"OnStartOfTimeLoop"); + return false; + } [HarmonyPrefix] [HarmonyPatch(typeof(OWTime), nameof(OWTime.Pause))] public static bool StopPausing() diff --git a/QSB/TimeSync/TimeSyncUI.cs b/QSB/TimeSync/TimeSyncUI.cs index ba0d0ac2..4e079f8f 100644 --- a/QSB/TimeSync/TimeSyncUI.cs +++ b/QSB/TimeSync/TimeSyncUI.cs @@ -1,6 +1,8 @@ using OWML.Utils; using QSB.Utility; +using QSB.WorldSync; using System; +using System.Linq; using UnityEngine; using UnityEngine.UI; @@ -30,7 +32,7 @@ namespace QSB.TimeSync private void OnUniverseSceneLoad(OWScene oldScene, OWScene newScene) { _isSetUp = true; - var obj = Resources.FindObjectsOfTypeAll()[0]; + var obj = QSBWorldSync.GetUnityObjects().First(); _canvas = obj.GetValue("_canvas"); _text = obj.GetValue("_text"); _canvas.enabled = false; @@ -58,6 +60,7 @@ namespace QSB.TimeSync DebugLog.ToConsole("Error - Tried to start time sync UI when not in universe!", OWML.Common.MessageType.Error); return; } + _currentType = type; _currentReason = reason; _startTime = Time.timeSinceLevelLoad; @@ -126,4 +129,4 @@ namespace QSB.TimeSync _text.text = text; } } -} \ No newline at end of file +} diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index e3a8d806..c3ff6069 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -36,6 +36,22 @@ namespace QSB.TimeSync public override void OnStartLocalPlayer() => LocalInstance = this; + public void OnDisconnect() + { + OWTime.SetTimeScale(1f); + OWTime.SetMaxDeltaTime(0.06666667f); + OWTime.SetFixedTimestep(0.01666667f); + Locator.GetActiveCamera().enabled = true; + CurrentState = State.NotLoaded; + CurrentReason = null; + + Physics.SyncTransforms(); + SpinnerUI.Hide(); + TimeSyncUI.Stop(); + + QSBInputManager.Instance.SetInputsEnabled(true); + } + public void Start() { if (!IsLocalPlayer) @@ -105,7 +121,10 @@ namespace QSB.TimeSync } else { - WakeUpOrSleep(); + if (!QSBCore.SkipTitleScreen) + { + WakeUpOrSleep(); + } } } @@ -224,7 +243,7 @@ namespace QSB.TimeSync { UpdateServer(); } - else if (IsLocalPlayer) + else if (IsLocalPlayer && !QSBCore.AvoidTimeSync) { UpdateClient(); } @@ -234,6 +253,18 @@ namespace QSB.TimeSync { _serverTime = Time.timeSinceLevelLoad; + if (ServerStateManager.Instance == null) + { + DebugLog.ToConsole($"Warning - ServerStateManager.Instance is null!", MessageType.Warning); + return; + } + + if (QSBPlayerManager.LocalPlayer == null) + { + DebugLog.ToConsole($"Warning - LocalPlayer is null!", MessageType.Warning); + return; + } + var serverState = ServerStateManager.Instance.GetServerState(); var clientState = QSBPlayerManager.LocalPlayer.State; @@ -308,7 +339,7 @@ namespace QSB.TimeSync // Checks to pause/fastforward - if (clientState == ClientState.NotLoaded || clientState == ClientState.InTitleScreen) + if (clientState is ClientState.NotLoaded or ClientState.InTitleScreen) { return; } @@ -384,7 +415,7 @@ namespace QSB.TimeSync { var diff = GetTimeDifference(); - if (diff > PauseOrFastForwardThreshold || diff < -PauseOrFastForwardThreshold) + if (diff is > PauseOrFastForwardThreshold or < (-PauseOrFastForwardThreshold)) { WakeUpOrSleep(); return; diff --git a/QSB/Tools/Events/PlayerFlashlightEvent.cs b/QSB/Tools/FlashlightTool/Events/PlayerFlashlightEvent.cs similarity index 81% rename from QSB/Tools/Events/PlayerFlashlightEvent.cs rename to QSB/Tools/FlashlightTool/Events/PlayerFlashlightEvent.cs index 4c1c81d8..204ca6d2 100644 --- a/QSB/Tools/Events/PlayerFlashlightEvent.cs +++ b/QSB/Tools/FlashlightTool/Events/PlayerFlashlightEvent.cs @@ -2,7 +2,7 @@ using QSB.Messaging; using QSB.Player; -namespace QSB.Tools.Events +namespace QSB.Tools.FlashlightTool.Events { public class PlayerFlashlightEvent : QSBEvent { @@ -23,7 +23,7 @@ namespace QSB.Tools.Events private void HandleTurnOn() => SendEvent(CreateMessage(true)); private void HandleTurnOff() => SendEvent(CreateMessage(false)); - private ToggleMessage CreateMessage(bool value) => new ToggleMessage + private ToggleMessage CreateMessage(bool value) => new() { AboutId = LocalPlayerId, ToggleValue = value @@ -32,11 +32,11 @@ namespace QSB.Tools.Events public override void OnReceiveRemote(bool server, ToggleMessage message) { var player = QSBPlayerManager.GetPlayer(message.AboutId); - player.PlayerStates.FlashlightActive = message.ToggleValue; + player.FlashlightActive = message.ToggleValue; player.FlashLight?.UpdateState(message.ToggleValue); } public override void OnReceiveLocal(bool server, ToggleMessage message) => - QSBPlayerManager.LocalPlayer.PlayerStates.FlashlightActive = message.ToggleValue; + QSBPlayerManager.LocalPlayer.FlashlightActive = message.ToggleValue; } } \ No newline at end of file diff --git a/QSB/Tools/FlashlightTool/FlashlightCreator.cs b/QSB/Tools/FlashlightTool/FlashlightCreator.cs new file mode 100644 index 00000000..3478edf5 --- /dev/null +++ b/QSB/Tools/FlashlightTool/FlashlightCreator.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +namespace QSB.Tools.FlashlightTool +{ + internal static class FlashlightCreator + { + private static readonly Vector3 FlashlightOffset = new(0.7196316f, -0.2697681f, 0.3769455f); + + internal static void CreateFlashlight(Transform cameraBody) + { + var flashlightRoot = Object.Instantiate(GameObject.Find("FlashlightRoot")); + flashlightRoot.name = "REMOTE_FlashlightRoot"; + flashlightRoot.SetActive(false); + var oldComponent = flashlightRoot.GetComponent(); + var component = flashlightRoot.AddComponent(); + + component.Init(oldComponent); + oldComponent.enabled = false; + + flashlightRoot.transform.parent = cameraBody; + flashlightRoot.transform.localPosition = FlashlightOffset; + flashlightRoot.SetActive(true); + } + } +} diff --git a/QSB/Tools/QSBFlashlight.cs b/QSB/Tools/FlashlightTool/QSBFlashlight.cs similarity index 60% rename from QSB/Tools/QSBFlashlight.cs rename to QSB/Tools/FlashlightTool/QSBFlashlight.cs index b4d47e45..b3d73b59 100644 --- a/QSB/Tools/QSBFlashlight.cs +++ b/QSB/Tools/FlashlightTool/QSBFlashlight.cs @@ -1,31 +1,36 @@ -using OWML.Utils; -using UnityEngine; +using UnityEngine; -namespace QSB.Tools +namespace QSB.Tools.FlashlightTool { - public class QSBFlashlight : MonoBehaviour + public class QSBFlashlight : MonoBehaviour, ILightSource { private OWLight2[] _lights; + internal OWLight2 _illuminationCheckLight; private Transform _root; private Transform _basePivot; private Transform _wobblePivot; private Vector3 _baseForward; private Quaternion _baseRotation; + private LightSourceVolume _lightSourceVolume; public bool FlashlightOn; public void Start() { + _lightSourceVolume = this.GetRequiredComponentInChildren(); + _lightSourceVolume.LinkLightSource(this); + _lightSourceVolume.SetVolumeActivation(FlashlightOn); _baseForward = _basePivot.forward; _baseRotation = _basePivot.rotation; } public void Init(Flashlight oldComponent) { - _lights = oldComponent.GetValue("_lights"); - _root = oldComponent.GetValue("_root"); - _basePivot = oldComponent.GetValue("_basePivot"); - _wobblePivot = oldComponent.GetValue("_wobblePivot"); + _lights = oldComponent._lights; + _illuminationCheckLight = oldComponent._illuminationCheckLight; + _root = oldComponent._root; + _basePivot = oldComponent._basePivot; + _wobblePivot = oldComponent._wobblePivot; Destroy(oldComponent.GetComponent()); foreach (var light in _lights) @@ -37,6 +42,12 @@ namespace QSB.Tools FlashlightOn = false; } + public LightSourceType GetLightSourceType() + => LightSourceType.FLASHLIGHT; + + public OWLight2[] GetLights() + => _lights; + public void UpdateState(bool value) { if (value) @@ -58,7 +69,7 @@ namespace QSB.Tools foreach (var light in _lights) { - light.GetLight().enabled = true; + light.SetActivation(true); } FlashlightOn = true; @@ -66,6 +77,7 @@ namespace QSB.Tools _basePivot.rotation = rotation; _baseRotation = rotation; _baseForward = _basePivot.forward; + _lightSourceVolume.SetVolumeActivation(FlashlightOn); } private void TurnOff() @@ -77,15 +89,16 @@ namespace QSB.Tools foreach (var light in _lights) { - light.GetLight().enabled = false; + light.SetActivation(false); } FlashlightOn = false; + _lightSourceVolume.SetVolumeActivation(FlashlightOn); } - public bool CheckIlluminationAtPoint(Vector3 point, float buffer = 0f, float maxDistance = float.PositiveInfinity) + public bool CheckIlluminationAtPoint(Vector3 worldPoint, float buffer = 0f, float maxDistance = float.PositiveInfinity) => FlashlightOn - && _lights[1].CheckIlluminationAtPoint(point, buffer, maxDistance); + && _illuminationCheckLight.CheckIlluminationAtPoint(worldPoint, buffer, maxDistance); public void FixedUpdate() { @@ -97,19 +110,5 @@ namespace QSB.Tools _baseForward = _basePivot.forward; _wobblePivot.localRotation = OWUtilities.GetWobbleRotation(0.3f, 0.15f) * Quaternion.identity; } - - private void OnRenderObject() - { - if (!QSBCore.WorldObjectsReady || !QSBCore.DebugMode || !QSBCore.ShowLinesInDebug) - { - return; - } - - var light = _lights[1].GetLight(); - if (light.enabled) - { - Popcron.Gizmos.Cone(light.transform.position, light.transform.rotation, light.range, light.spotAngle, Color.yellow); - } - } } } \ No newline at end of file diff --git a/QSB/Tools/PlayerToolsManager.cs b/QSB/Tools/PlayerToolsManager.cs index 321e9c42..ac284566 100644 --- a/QSB/Tools/PlayerToolsManager.cs +++ b/QSB/Tools/PlayerToolsManager.cs @@ -1,184 +1,82 @@ -using OWML.Utils; -using QSB.Player; -using QSB.ProbeSync; +using QSB.Tools.FlashlightTool; using QSB.Tools.ProbeLauncherTool; +using QSB.Tools.SignalscopeTool; +using QSB.Tools.TranslatorTool; using QSB.Utility; +using System; using System.Linq; using UnityEngine; -using UnityEngine.PostProcessing; namespace QSB.Tools { public class PlayerToolsManager { - private static Transform _toolStowTransform; - private static Transform _toolHoldTransform; - private static Material Props_HEA_PlayerTool_mat; - private static Material Props_HEA_Lightbulb_mat; - private static Material Props_HEA_Lightbulb_OFF_mat; + public static Transform StowTransform; + public static Transform HoldTransform; - private static readonly Vector3 FlashlightOffset = new Vector3(0.7196316f, -0.2697681f, 0.3769455f); - private static readonly Vector3 ProbeLauncherOffset = new Vector3(0.5745087f, -0.26f, 0.4453125f); - private static readonly Vector3 SignalscopeScale = new Vector3(1.5f, 1.5f, 1.5f); - private static readonly Vector3 TranslatorScale = new Vector3(0.75f, 0.75f, 0.75f); + public static Material Props_HEA_PlayerTool_mat; + public static Material Props_HEA_Lightbulb_mat; + public static Material Props_HEA_Lightbulb_OFF_mat; + public static Material Structure_HEA_PlayerShip_Screens_mat; - public static void Init(Transform playerCamera) + public static void InitRemote(Transform playerCamera) { - CreateStowTransforms(playerCamera); - - Props_HEA_PlayerTool_mat = GameObject.Find("Props_HEA_ProbeLauncher_ProbeCamera/ProbeLauncherChassis").GetComponent().materials[0]; - Props_HEA_Lightbulb_OFF_mat = GameObject.Find("Props_HEA_Probe_Prelaunch").GetComponent().materials[1]; - if (QSBSceneManager.CurrentScene == OWScene.SolarSystem) + try { - Props_HEA_Lightbulb_mat = GameObject.Find("Props_HEA_Lantern (10)/Lantern_Lamp").GetComponent().materials[0]; - Props_HEA_Lightbulb_OFF_mat = GameObject.Find("NomaiResearchExhibit/Props_HEA_Probe_STATIC").GetComponent().materials[1]; + CreateStowTransforms(playerCamera); + + Props_HEA_PlayerTool_mat = GameObject.Find("Props_HEA_ProbeLauncher_ProbeCamera/ProbeLauncherChassis").GetComponent().materials[0]; + Props_HEA_Lightbulb_OFF_mat = GameObject.Find("Props_HEA_Probe_Prelaunch").GetComponent().materials[1]; + + if (QSBSceneManager.CurrentScene == OWScene.SolarSystem) + { + Structure_HEA_PlayerShip_Screens_mat = GameObject.Find("ProbeScreen (1)/ProbeScreenPivot/ProbeScreen").GetComponent().materials[2]; + Props_HEA_Lightbulb_mat = GameObject.Find("Props_HEA_Lantern (10)/Lantern_Lamp").GetComponent().materials[0]; + Props_HEA_Lightbulb_OFF_mat = GameObject.Find("NomaiResearchExhibit/Props_HEA_Probe_STATIC").GetComponent().materials[1]; + } + else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) + { + Props_HEA_Lightbulb_mat = GameObject.Find("lantern_lamp").GetComponent().materials[0]; + + // BUG : uhhhhh fuckin' uhhhhhhhh (find a material) + Props_HEA_Lightbulb_OFF_mat = null; + Structure_HEA_PlayerShip_Screens_mat = null; + } } - else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) + catch (Exception ex) { - Props_HEA_Lightbulb_mat = GameObject.Find("lantern_lamp").GetComponent().materials[0]; - - // BUG : uhhhhh fuckin' uhhhhhhhh (find a material) - Props_HEA_Lightbulb_OFF_mat = null; + DebugLog.ToConsole($"Error when trying to find materials : {ex}", OWML.Common.MessageType.Error); } - CreateFlashlight(playerCamera); - CreateSignalscope(playerCamera); - CreateProbeLauncher(playerCamera); - CreateTranslator(playerCamera); + FlashlightCreator.CreateFlashlight(playerCamera); + SignalscopeCreator.CreateSignalscope(playerCamera); + ProbeLauncherCreator.CreateProbeLauncher(playerCamera); + TranslatorCreator.CreateTranslator(playerCamera); } - public static void CreateProbe(Transform newProbe, PlayerInfo player) + public static void InitLocal() { - var qsbProbe = newProbe.gameObject.AddComponent(); - player.Probe = qsbProbe; - qsbProbe.SetOwner(player); + var flashlight = Locator.GetFlashlight(); + var spot = flashlight._illuminationCheckLight; + var lightLOD = spot.GetComponent(); - // Probe_Body - Object.Destroy(newProbe.GetComponent()); - Object.Destroy(newProbe.GetComponent()); - Object.Destroy(newProbe.GetComponent()); - Object.Destroy(newProbe.GetComponent()); - Object.Destroy(newProbe.GetComponent()); - Object.Destroy(newProbe.GetComponent()); - Object.Destroy(newProbe.GetComponent()); - Object.Destroy(newProbe.GetComponent()); - Object.Destroy(newProbe.GetComponent()); - Object.Destroy(newProbe.GetComponent()); - - // ProbeDetector - //Object.Destroy(newProbe.Find("ProbeDetector").gameObject); - var probeDetector = newProbe.Find("ProbeDetector").gameObject; - Object.Destroy(probeDetector.GetComponent()); - Object.Destroy(probeDetector.GetComponent()); - Object.Destroy(probeDetector.GetComponent()); - - // CameraPivot - var cameraPivot = newProbe.Find("CameraPivot"); - Object.Destroy(cameraPivot.GetComponent()); - - // TODO : Sync probe animations - - // CameraPivot/Geometry/Props_HEA_Probe_ANIM - var animRoot = cameraPivot.Find("Geometry").Find("Props_HEA_Probe_ANIM"); - Object.Destroy(animRoot.GetComponent()); - Object.Destroy(animRoot.GetComponent()); - - // TODO : Set up QSB cameras for these two cameras - that's why im not just destroying the GOs here - - // CameraPivot/ForwardCamera - var forwardCamera = cameraPivot.Find("ForwardCamera"); - Object.Destroy(forwardCamera.GetComponent()); - Object.Destroy(forwardCamera.GetComponent()); - Object.Destroy(forwardCamera.GetComponent()); - Object.Destroy(forwardCamera.GetComponent()); - Object.Destroy(forwardCamera.GetComponent()); - Object.Destroy(forwardCamera.GetComponent()); - var oldForwardSpotlight = forwardCamera.GetComponent(); - var newForwardSpotlight = forwardCamera.gameObject.AddComponent(); - newForwardSpotlight._id = oldForwardSpotlight.GetValue("_id"); - newForwardSpotlight._fadeInLength = oldForwardSpotlight.GetValue("_fadeInLength"); - newForwardSpotlight._intensity = 0.8f; - Object.Destroy(oldForwardSpotlight); - - // CameraPivot/RotatingCameraPivot/RotatingCamera - var rotatingCamera = cameraPivot.Find("RotatingCameraPivot").Find("RotatingCamera"); - Object.Destroy(rotatingCamera.GetComponent()); - Object.Destroy(rotatingCamera.GetComponent()); - Object.Destroy(rotatingCamera.GetComponent()); - Object.Destroy(rotatingCamera.GetComponent()); - Object.Destroy(rotatingCamera.GetComponent()); - Object.Destroy(rotatingCamera.GetComponent()); - - // ProbeEffects - var probeEffects = newProbe.Find("ProbeEffects"); - var oldEffects = probeEffects.GetComponent(); - var newEffects = probeEffects.gameObject.AddComponent(); - newEffects._flightLoopAudio = oldEffects.GetValue("_flightLoopAudio"); - newEffects._anchorAudio = oldEffects.GetValue("_anchorAudio"); - newEffects._anchorParticles = oldEffects.GetValue("_anchorParticles"); - Object.Destroy(oldEffects); - - Object.Destroy(probeEffects.Find("CloudsEffectBubble").gameObject); - Object.Destroy(probeEffects.Find("SandEffectBubble").gameObject); - Object.Destroy(probeEffects.Find("ProbeElectricityEffect").gameObject); - - // AmbientLight_Probe - var ambientLight = newProbe.Find("AmbientLight_Probe"); - var oldAmbLantern = ambientLight.GetComponent(); - var newAmbLantern = ambientLight.gameObject.AddComponent(); - newAmbLantern._fadeInDuration = oldAmbLantern.GetValue("_fadeInDuration"); - newAmbLantern._fadeInCurve = oldAmbLantern.GetValue("_fadeInCurve"); - newAmbLantern._fadeOutCurve = oldAmbLantern.GetValue("_fadeOutCurve"); - newAmbLantern._emissiveRenderer = oldAmbLantern.GetValue("_emissiveRenderer"); - newAmbLantern._originalRange = 60f; - Object.Destroy(oldAmbLantern); - - // Lantern - var lantern = newProbe.Find("Lantern"); - var oldLantern = lantern.GetComponent(); - var newLantern = lantern.gameObject.AddComponent(); - newLantern._fadeInDuration = oldLantern.GetValue("_fadeInDuration"); - newLantern._fadeInCurve = oldLantern.GetValue("_fadeInCurve"); - newLantern._fadeOutCurve = oldLantern.GetValue("_fadeOutCurve"); - newLantern._emissiveRenderer = oldLantern.GetValue("_emissiveRenderer"); - newLantern._originalRange = 35f; - Object.Destroy(oldLantern); - - // RearCamera - var rearCamera = newProbe.Find("RearCamera"); - Object.Destroy(rearCamera.GetComponent()); - Object.Destroy(rearCamera.GetComponent()); - Object.Destroy(rearCamera.GetComponent()); - Object.Destroy(rearCamera.GetComponent()); - Object.Destroy(rearCamera.GetComponent()); - Object.Destroy(rearCamera.GetComponent()); - var oldRearSpotlight = rearCamera.GetComponent(); - var newRearSpotlight = rearCamera.gameObject.AddComponent(); - newRearSpotlight._id = oldRearSpotlight.GetValue("_id"); - newRearSpotlight._fadeInLength = oldRearSpotlight.GetValue("_fadeInLength"); - newRearSpotlight._intensity = 0.8f; - Object.Destroy(oldRearSpotlight); - - // PlaneOffsetMarker_Probe - Object.Destroy(newProbe.Find("PlaneOffsetMarker_Probe").gameObject); - - newProbe.Find("RecallEffect").gameObject.GetComponent().enabled = true; - newProbe.Find("RecallEffect").gameObject.GetComponent().enabled = true; - newProbe.Find("RecallEffect").name = "RemoteProbeRecallEffect"; - - newProbe.gameObject.SetActive(true); + if (lightLOD != null) + { + UnityEngine.Object.Destroy(lightLOD); + spot.GetLight().shadows = LightShadows.Soft; + } } private static void CreateStowTransforms(Transform cameraBody) { var stow = new GameObject("REMOTE_ToolStowTransform"); - _toolStowTransform = stow.transform; + StowTransform = stow.transform; stow.transform.parent = cameraBody; stow.transform.localPosition = Vector3.zero; stow.transform.localRotation = Quaternion.Euler(45f, 0f, 0f); var hold = new GameObject("REMOTE_ToolHoldTransform"); - _toolHoldTransform = hold.transform; + HoldTransform = hold.transform; hold.transform.parent = cameraBody; hold.transform.localPosition = Vector3.zero; hold.transform.localRotation = Quaternion.Euler(0f, 0f, 0f); @@ -212,161 +110,33 @@ namespace QSB.Tools vesselCore.transform.localPosition = new Vector3(0.177f, -0.106f, 0.2f); vesselCore.transform.localRotation = Quaternion.Euler(3.142f, 14.827f, 12.094f); vesselCore.transform.localScale = new Vector3(0.27f, 0.27f, 0.27f); + + var simpleLantern = new GameObject("REMOTE_SimpleLanternSocket"); + simpleLantern.transform.parent = cameraBody; + simpleLantern.transform.localPosition = new Vector3(0.242997f, -0.18f, 0.2620007f); + simpleLantern.transform.localRotation = Quaternion.Euler(0f, 33f, 0f); + simpleLantern.transform.localScale = new Vector3(0.33f, 0.33f, 0.33f); + + var dreamLantern = new GameObject("REMOTE_DreamLanternSocket"); + dreamLantern.transform.parent = cameraBody; + dreamLantern.transform.localPosition = new Vector3(0.243f, -0.207f, 0.262f); + dreamLantern.transform.localRotation = Quaternion.Euler(0f, 0f, 0f); + dreamLantern.transform.localScale = new Vector3(0.33f, 0.33f, 0.33f); + + var slideReel = new GameObject("REMOTE_SlideReelSocket"); + slideReel.transform.parent = cameraBody; + slideReel.transform.localPosition = new Vector3(0.1353f, -0.0878f, 0.2878f); + slideReel.transform.localRotation = Quaternion.Euler(-145.532f, 6.589996f, -94.54901f); + slideReel.transform.localScale = new Vector3(0.3300001f, 0.33f, 0.3299999f); + + var visionTorch = new GameObject("REMOTE_VisionTorchSocket"); + visionTorch.transform.parent = cameraBody; + visionTorch.transform.localPosition = new Vector3(0.21f, -0.32f, 0.33f); + visionTorch.transform.localRotation = Quaternion.Euler(-4.5f, 0.03f, 9f); + visionTorch.transform.localScale = new Vector3(0.33f, 0.33f, 0.33f); } - private static void CreateFlashlight(Transform cameraBody) - { - var flashlightRoot = Object.Instantiate(GameObject.Find("FlashlightRoot")); - flashlightRoot.name = "REMOTE_FlashlightRoot"; - flashlightRoot.SetActive(false); - var oldComponent = flashlightRoot.GetComponent(); - var component = flashlightRoot.AddComponent(); - - component.Init(oldComponent); - oldComponent.enabled = false; - - flashlightRoot.transform.parent = cameraBody; - flashlightRoot.transform.localPosition = FlashlightOffset; - flashlightRoot.SetActive(true); - } - - private static void CreateSignalscope(Transform cameraBody) - { - var signalscopeRoot = Object.Instantiate(GameObject.Find("Signalscope")); - signalscopeRoot.name = "REMOTE_Signalscope"; - signalscopeRoot.SetActive(false); - - Object.Destroy(signalscopeRoot.GetComponent()); - Object.Destroy(signalscopeRoot.transform.Find("Props_HEA_Signalscope") - .Find("Props_HEA_Signalscope_Prepass").gameObject); - - var oldSignalscope = signalscopeRoot.GetComponent(); - var tool = signalscopeRoot.AddComponent(); - tool.MoveSpring = oldSignalscope.GetValue("_moveSpring"); - tool.StowTransform = _toolStowTransform; - tool.HoldTransform = _toolHoldTransform; - tool.ArrivalDegrees = 5f; - tool.Type = ToolType.Signalscope; - tool.ToolGameObject = signalscopeRoot.transform.Find("Props_HEA_Signalscope").gameObject; - oldSignalscope.enabled = false; - - GetRenderer(signalscopeRoot, "Props_HEA_Signalscope").material = Props_HEA_PlayerTool_mat; - - signalscopeRoot.transform.parent = cameraBody; - signalscopeRoot.transform.localPosition = Vector3.zero; - signalscopeRoot.transform.localScale = SignalscopeScale; - signalscopeRoot.SetActive(true); - } - - private static void CreateTranslator(Transform cameraBody) - { - var original = GameObject.Find("NomaiTranslatorProp"); - - var translatorRoot = original.InstantiateInactive(); - translatorRoot.name = "REMOTE_NomaiTranslatorProp"; - - var group = translatorRoot.transform.Find("TranslatorGroup"); - var model = group.Find("Props_HEA_Translator"); - - Object.Destroy(translatorRoot.GetComponent()); - Object.Destroy(group.Find("Canvas").gameObject); - Object.Destroy(group.Find("Lighting").gameObject); - Object.Destroy(group.Find("TranslatorBeams").gameObject); - Object.Destroy(model.Find("Props_HEA_Translator_Pivot_RotatingPart") - .Find("Props_HEA_Translator_RotatingPart") - .Find("Props_HEA_Translator_RotatingPart_Prepass").gameObject); - Object.Destroy(model.Find("Props_HEA_Translator_Prepass").gameObject); - - var oldTranslator = translatorRoot.GetComponent(); - var tool = translatorRoot.AddComponent(); - tool.MoveSpring = oldTranslator.GetValue("_moveSpring"); - tool.StowTransform = _toolStowTransform; - tool.HoldTransform = _toolHoldTransform; - tool.ArrivalDegrees = 5f; - tool.Type = ToolType.Translator; - tool.ToolGameObject = group.gameObject; - Object.Destroy(oldTranslator); - - GetRenderer(translatorRoot, "Props_HEA_Translator_Geo").material = Props_HEA_PlayerTool_mat; - GetRenderer(translatorRoot, "Props_HEA_Translator_RotatingPart").material = Props_HEA_PlayerTool_mat; - GetRenderer(translatorRoot, "Props_HEA_Translator_Button_L").material = Props_HEA_Lightbulb_mat; - GetRenderer(translatorRoot, "Props_HEA_Translator_Button_R").material = Props_HEA_Lightbulb_mat; - - translatorRoot.transform.parent = cameraBody; - translatorRoot.transform.localPosition = Vector3.zero; - translatorRoot.transform.localScale = TranslatorScale; - QSBCore.UnityEvents.FireOnNextUpdate(() => translatorRoot.SetActive(true)); - } - - private static void CreateProbeLauncher(Transform cameraBody) - { - var ProbeLauncher = GameObject.Find("PlayerCamera/ProbeLauncher"); - - // Create new ProbeLauncher - var REMOTE_ProbeLauncher = new GameObject("REMOTE_ProbeLauncher"); - REMOTE_ProbeLauncher.SetActive(false); - - // Copy children of ProbeLauncher - var Props_HEA_ProbeLauncher = ProbeLauncher.transform.Find("Props_HEA_ProbeLauncher"); - var REMOTE_Props_HEA_ProbeLauncher = Object.Instantiate(Props_HEA_ProbeLauncher, REMOTE_ProbeLauncher.transform, false); - - var LaunchParticleEffect_Underwater = ProbeLauncher.transform.Find("LaunchParticleEffect_Underwater"); - var REMOTE_LaunchParticleEffect_Underwater = Object.Instantiate(LaunchParticleEffect_Underwater, REMOTE_ProbeLauncher.transform, false); - - var LaunchParticleEffect = ProbeLauncher.transform.Find("LaunchParticleEffect"); - var REMOTE_LaunchParticleEffect = Object.Instantiate(LaunchParticleEffect, REMOTE_ProbeLauncher.transform, false); - - // Set up effects - var effects = REMOTE_ProbeLauncher.AddComponent(); - effects.SetValue("_launchParticles", REMOTE_LaunchParticleEffect.GetComponent()); - effects.SetValue("_underwaterLaunchParticles", REMOTE_LaunchParticleEffect_Underwater.GetComponent()); - effects.SetValue("_owAudioSource", ProbeLauncher.GetComponent().GetValue("_owAudioSource")); - - var recallEffect = REMOTE_Props_HEA_ProbeLauncher.Find("RecallEffect"); - - REMOTE_Props_HEA_ProbeLauncher.Find("PressureGauge_Arrow").GetComponent().material = Props_HEA_PlayerTool_mat; - REMOTE_Props_HEA_ProbeLauncher.Find("ProbeLauncherChassis").GetComponent().material = Props_HEA_PlayerTool_mat; - Object.Destroy(REMOTE_Props_HEA_ProbeLauncher.Find("Props_HEA_ProbeLauncher_Prepass").gameObject); - - var preLaunchProbe = REMOTE_Props_HEA_ProbeLauncher.Find("Props_HEA_Probe_Prelaunch"); - Object.Destroy(preLaunchProbe.Find("Props_HEA_Probe_Prelaunch_Prepass").gameObject); - - // fuck you unity - var materials = preLaunchProbe.GetComponent().materials; - materials[0] = Props_HEA_PlayerTool_mat; - materials[1] = Props_HEA_Lightbulb_OFF_mat; - preLaunchProbe.GetComponent().materials = materials; - - var tool = REMOTE_ProbeLauncher.AddComponent(); - var spring = new DampedSpringQuat - { - velocity = Vector4.zero, - settings = new DampedSpringSettings - { - springConstant = 50f, - dampingCoefficient = 8.485282f, - mass = 1 - } - }; - - tool.MoveSpring = spring; - tool.StowTransform = _toolStowTransform; - tool.HoldTransform = _toolHoldTransform; - tool.ArrivalDegrees = 5f; - tool.Type = ToolType.ProbeLauncher; - tool.ToolGameObject = REMOTE_Props_HEA_ProbeLauncher.gameObject; - tool.PreLaunchProbeProxy = preLaunchProbe.gameObject; - tool.ProbeRetrievalEffect = recallEffect.GetComponent(); - tool.Effects = effects; - - REMOTE_ProbeLauncher.transform.parent = cameraBody; - REMOTE_ProbeLauncher.transform.localPosition = ProbeLauncherOffset; - - //QSBCore.UnityEvents.FireInNUpdates(() => REMOTE_ProbeLauncher.SetActive(true), 5); - REMOTE_ProbeLauncher.SetActive(true); - } - - private static MeshRenderer GetRenderer(GameObject root, string gameObjectName) => + internal static MeshRenderer GetRenderer(GameObject root, string gameObjectName) => root.GetComponentsInChildren(true).First(x => x.name == gameObjectName); } } \ No newline at end of file diff --git a/QSB/Tools/ProbeLauncherTool/Events/EquipProbeLauncherEvent.cs b/QSB/Tools/ProbeLauncherTool/Events/EquipProbeLauncherEvent.cs index 378b60e3..4ed6606a 100644 --- a/QSB/Tools/ProbeLauncherTool/Events/EquipProbeLauncherEvent.cs +++ b/QSB/Tools/ProbeLauncherTool/Events/EquipProbeLauncherEvent.cs @@ -57,7 +57,7 @@ namespace QSB.Tools.ProbeLauncherTool.Events SendEvent(CreateMessage(false)); } - private ToggleMessage CreateMessage(bool value) => new ToggleMessage + private ToggleMessage CreateMessage(bool value) => new() { AboutId = LocalPlayerId, ToggleValue = value @@ -66,11 +66,11 @@ namespace QSB.Tools.ProbeLauncherTool.Events public override void OnReceiveRemote(bool server, ToggleMessage message) { var player = QSBPlayerManager.GetPlayer(message.AboutId); - player.PlayerStates.ProbeLauncherEquipped = message.ToggleValue; + player.ProbeLauncherEquipped = message.ToggleValue; player.ProbeLauncher?.ChangeEquipState(message.ToggleValue); } public override void OnReceiveLocal(bool server, ToggleMessage message) => - QSBPlayerManager.LocalPlayer.PlayerStates.ProbeLauncherEquipped = message.ToggleValue; + QSBPlayerManager.LocalPlayer.ProbeLauncherEquipped = message.ToggleValue; } } \ No newline at end of file diff --git a/QSB/Tools/ProbeLauncherTool/Events/LaunchProbeEvent.cs b/QSB/Tools/ProbeLauncherTool/Events/LaunchProbeEvent.cs index 6dd99eb8..af41dfb2 100644 --- a/QSB/Tools/ProbeLauncherTool/Events/LaunchProbeEvent.cs +++ b/QSB/Tools/ProbeLauncherTool/Events/LaunchProbeEvent.cs @@ -17,7 +17,7 @@ namespace QSB.Tools.ProbeLauncherTool.Events private void Handler(QSBProbeLauncher launcher) => SendEvent(CreateMessage(launcher)); - private BoolWorldObjectMessage CreateMessage(QSBProbeLauncher launcher) => new BoolWorldObjectMessage + private BoolWorldObjectMessage CreateMessage(QSBProbeLauncher launcher) => new() { AboutId = LocalPlayerId, ObjectId = launcher.ObjectId diff --git a/QSB/Tools/ProbeLauncherTool/Events/PlayerLaunchProbeEvent.cs b/QSB/Tools/ProbeLauncherTool/Events/PlayerLaunchProbeEvent.cs index 27c4a226..7af2d342 100644 --- a/QSB/Tools/ProbeLauncherTool/Events/PlayerLaunchProbeEvent.cs +++ b/QSB/Tools/ProbeLauncherTool/Events/PlayerLaunchProbeEvent.cs @@ -16,7 +16,7 @@ namespace QSB.Tools.ProbeLauncherTool.Events private void Handler() => SendEvent(CreateMessage()); - private PlayerMessage CreateMessage() => new PlayerMessage + private PlayerMessage CreateMessage() => new() { AboutId = LocalPlayerId }; diff --git a/QSB/Tools/ProbeLauncherTool/Events/PlayerRetrieveProbeEvent.cs b/QSB/Tools/ProbeLauncherTool/Events/PlayerRetrieveProbeEvent.cs index 92c5b5b9..d0a44229 100644 --- a/QSB/Tools/ProbeLauncherTool/Events/PlayerRetrieveProbeEvent.cs +++ b/QSB/Tools/ProbeLauncherTool/Events/PlayerRetrieveProbeEvent.cs @@ -16,7 +16,7 @@ namespace QSB.Tools.ProbeLauncherTool.Events private void Handler(bool playEffects) => SendEvent(CreateMessage(playEffects)); - private BoolMessage CreateMessage(bool playEffects) => new BoolMessage + private BoolMessage CreateMessage(bool playEffects) => new() { AboutId = LocalPlayerId, Value = playEffects diff --git a/QSB/Tools/ProbeLauncherTool/Events/RetrieveProbeEvent.cs b/QSB/Tools/ProbeLauncherTool/Events/RetrieveProbeEvent.cs index 493ea936..ab0dfdd8 100644 --- a/QSB/Tools/ProbeLauncherTool/Events/RetrieveProbeEvent.cs +++ b/QSB/Tools/ProbeLauncherTool/Events/RetrieveProbeEvent.cs @@ -17,7 +17,7 @@ namespace QSB.Tools.ProbeLauncherTool.Events private void Handler(QSBProbeLauncher launcher, bool playEffects) => SendEvent(CreateMessage(launcher, playEffects)); - private BoolWorldObjectMessage CreateMessage(QSBProbeLauncher launcher, bool playEffects) => new BoolWorldObjectMessage + private BoolWorldObjectMessage CreateMessage(QSBProbeLauncher launcher, bool playEffects) => new() { AboutId = LocalPlayerId, ObjectId = launcher.ObjectId, diff --git a/QSB/Tools/ProbeLauncherTool/Patches/LauncherPatches.cs b/QSB/Tools/ProbeLauncherTool/Patches/LauncherPatches.cs index f1427d25..ae9e0fcf 100644 --- a/QSB/Tools/ProbeLauncherTool/Patches/LauncherPatches.cs +++ b/QSB/Tools/ProbeLauncherTool/Patches/LauncherPatches.cs @@ -53,7 +53,7 @@ namespace QSB.Tools.ProbeLauncherTool.Patches if (__instance != QSBPlayerManager.LocalPlayer.LocalProbeLauncher) { - QSBEventManager.FireEvent(EventNames.QSBRetrieveProbe, QSBWorldSync.GetWorldFromUnity(__instance), playEffects); + QSBEventManager.FireEvent(EventNames.QSBRetrieveProbe, QSBWorldSync.GetWorldFromUnity(__instance), playEffects); } else { @@ -71,12 +71,20 @@ namespace QSB.Tools.ProbeLauncherTool.Patches // TODO : ehhhh idk about this. maybe copy each sound source so we have a 2d version (for local) and a 3d version (for remote)? // this would probably be a whole qsb version on it's own - [HarmonyPostfix] + [HarmonyPrefix] [HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayRetrievalClip))] - public static void ProbeLauncherEffects_PlayRetrievalClip(OWAudioSource ____owAudioSource) => ____owAudioSource.GetAudioSource().spatialBlend = 1f; + public static bool ProbeLauncherEffects_PlayRetrievalClip(OWAudioSource ____owAudioSource) + { + ____owAudioSource.GetAudioSource().spatialBlend = 1f; + return true; + } - [HarmonyPostfix] + [HarmonyPrefix] [HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayLaunchClip))] - public static void ProbeLauncherEffects_PlayLaunchClip(OWAudioSource ____owAudioSource) => ____owAudioSource.GetAudioSource().spatialBlend = 1f; + public static bool ProbeLauncherEffects_PlayLaunchClip(OWAudioSource ____owAudioSource) + { + ____owAudioSource.GetAudioSource().spatialBlend = 1f; + return true; + } } } diff --git a/QSB/Tools/ProbeLauncherTool/ProbeLauncherCreator.cs b/QSB/Tools/ProbeLauncherTool/ProbeLauncherCreator.cs new file mode 100644 index 00000000..c349b81d --- /dev/null +++ b/QSB/Tools/ProbeLauncherTool/ProbeLauncherCreator.cs @@ -0,0 +1,85 @@ +using UnityEngine; +using UnityEngine.Rendering; + +namespace QSB.Tools.ProbeLauncherTool +{ + internal static class ProbeLauncherCreator + { + private static readonly Vector3 ProbeLauncherOffset = new(0.5745087f, -0.26f, 0.4453125f); + + internal static void CreateProbeLauncher(Transform cameraBody) + { + var ProbeLauncher = GameObject.Find("PlayerCamera/ProbeLauncher"); + + // Create new ProbeLauncher + var REMOTE_ProbeLauncher = new GameObject("REMOTE_ProbeLauncher"); + REMOTE_ProbeLauncher.SetActive(false); + + // Copy children of ProbeLauncher + var Props_HEA_ProbeLauncher = ProbeLauncher.transform.Find("Props_HEA_ProbeLauncher"); + var REMOTE_Props_HEA_ProbeLauncher = Object.Instantiate(Props_HEA_ProbeLauncher, REMOTE_ProbeLauncher.transform, false); + + var LaunchParticleEffect_Underwater = ProbeLauncher.transform.Find("LaunchParticleEffect_Underwater"); + var REMOTE_LaunchParticleEffect_Underwater = Object.Instantiate(LaunchParticleEffect_Underwater, REMOTE_ProbeLauncher.transform, false); + + var LaunchParticleEffect = ProbeLauncher.transform.Find("LaunchParticleEffect"); + var REMOTE_LaunchParticleEffect = Object.Instantiate(LaunchParticleEffect, REMOTE_ProbeLauncher.transform, false); + + // Set up effects + var effects = REMOTE_ProbeLauncher.AddComponent(); + effects._launchParticles = REMOTE_LaunchParticleEffect.GetComponent(); + effects._underwaterLaunchParticles = REMOTE_LaunchParticleEffect_Underwater.GetComponent(); + effects._owAudioSource = ProbeLauncher.GetComponent()._owAudioSource; + + var recallEffect = REMOTE_Props_HEA_ProbeLauncher.Find("RecallEffect"); + + var arrow = REMOTE_Props_HEA_ProbeLauncher.Find("PressureGauge_Arrow"); + arrow.GetComponent().material = PlayerToolsManager.Props_HEA_PlayerTool_mat; + arrow.GetComponent().shadowCastingMode = ShadowCastingMode.On; + + var chassis = REMOTE_Props_HEA_ProbeLauncher.Find("ProbeLauncherChassis"); + chassis.GetComponent().material = PlayerToolsManager.Props_HEA_PlayerTool_mat; + chassis.GetComponent().shadowCastingMode = ShadowCastingMode.On; + Object.Destroy(REMOTE_Props_HEA_ProbeLauncher.Find("Props_HEA_ProbeLauncher_Prepass").gameObject); + + var preLaunchProbe = REMOTE_Props_HEA_ProbeLauncher.Find("Props_HEA_Probe_Prelaunch"); + Object.Destroy(preLaunchProbe.Find("Props_HEA_Probe_Prelaunch_Prepass").gameObject); + + // fuck you unity + var materials = preLaunchProbe.GetComponent().materials; + materials[0] = PlayerToolsManager.Props_HEA_PlayerTool_mat; + materials[1] = PlayerToolsManager.Props_HEA_Lightbulb_OFF_mat; + preLaunchProbe.GetComponent().materials = materials; + + preLaunchProbe.GetComponent().shadowCastingMode = ShadowCastingMode.On; + + var tool = REMOTE_ProbeLauncher.AddComponent(); + var spring = new DampedSpringQuat + { + velocity = Vector4.zero, + settings = new DampedSpringSettings + { + springConstant = 50f, + dampingCoefficient = 8.485282f, + mass = 1 + } + }; + + tool.MoveSpring = spring; + tool.StowTransform = PlayerToolsManager.StowTransform; + tool.HoldTransform = PlayerToolsManager.HoldTransform; + tool.ArrivalDegrees = 5f; + tool.Type = ToolType.ProbeLauncher; + tool.ToolGameObject = REMOTE_Props_HEA_ProbeLauncher.gameObject; + tool.PreLaunchProbeProxy = preLaunchProbe.gameObject; + tool.ProbeRetrievalEffect = recallEffect.GetComponent(); + tool.Effects = effects; + + REMOTE_ProbeLauncher.transform.parent = cameraBody; + REMOTE_ProbeLauncher.transform.localPosition = ProbeLauncherOffset; + + //QSBCore.UnityEvents.FireInNUpdates(() => REMOTE_ProbeLauncher.SetActive(true), 5); + REMOTE_ProbeLauncher.SetActive(true); + } + } +} diff --git a/QSB/ProbeSync/Events/PlayerProbeEvent.cs b/QSB/Tools/ProbeTool/Events/PlayerProbeEvent.cs similarity index 87% rename from QSB/ProbeSync/Events/PlayerProbeEvent.cs rename to QSB/Tools/ProbeTool/Events/PlayerProbeEvent.cs index 174645fa..28225ab1 100644 --- a/QSB/ProbeSync/Events/PlayerProbeEvent.cs +++ b/QSB/Tools/ProbeTool/Events/PlayerProbeEvent.cs @@ -2,7 +2,7 @@ using QSB.Messaging; using QSB.Player; -namespace QSB.ProbeSync.Events +namespace QSB.Tools.ProbeTool.Events { internal class PlayerProbeEvent : QSBEvent> { @@ -16,7 +16,7 @@ namespace QSB.ProbeSync.Events private void Handler(ProbeEvent probeEvent) => SendEvent(CreateMessage(probeEvent)); - private EnumMessage CreateMessage(ProbeEvent probeEvent) => new EnumMessage + private EnumMessage CreateMessage(ProbeEvent probeEvent) => new() { AboutId = LocalPlayerId, EnumValue = probeEvent @@ -25,7 +25,7 @@ namespace QSB.ProbeSync.Events public override void OnReceiveRemote(bool server, EnumMessage message) { var player = QSBPlayerManager.GetPlayer(message.AboutId); - if (!player.PlayerStates.IsReady || player.Probe == null) + if (!player.IsReady || player.Probe == null) { return; } diff --git a/QSB/ProbeSync/Events/ProbeStartRetrieveEvent.cs b/QSB/Tools/ProbeTool/Events/ProbeStartRetrieveEvent.cs similarity index 83% rename from QSB/ProbeSync/Events/ProbeStartRetrieveEvent.cs rename to QSB/Tools/ProbeTool/Events/ProbeStartRetrieveEvent.cs index 8f3f73e7..f5a39be4 100644 --- a/QSB/ProbeSync/Events/ProbeStartRetrieveEvent.cs +++ b/QSB/Tools/ProbeTool/Events/ProbeStartRetrieveEvent.cs @@ -2,7 +2,7 @@ using QSB.Messaging; using QSB.Player; -namespace QSB.ProbeSync.Events +namespace QSB.Tools.ProbeTool.Events { internal class ProbeStartRetrieveEvent : QSBEvent { @@ -16,7 +16,7 @@ namespace QSB.ProbeSync.Events private void Handler(float duration) => SendEvent(CreateMessage(duration)); - private FloatMessage CreateMessage(float duration) => new FloatMessage + private FloatMessage CreateMessage(float duration) => new() { AboutId = LocalPlayerId, Value = duration @@ -25,7 +25,7 @@ namespace QSB.ProbeSync.Events public override void OnReceiveRemote(bool server, FloatMessage message) { var player = QSBPlayerManager.GetPlayer(message.AboutId); - if (!player.PlayerStates.IsReady || player.Probe == null) + if (!player.IsReady || player.Probe == null) { return; } diff --git a/QSB/Tools/ProbeTool/ProbeCreator.cs b/QSB/Tools/ProbeTool/ProbeCreator.cs new file mode 100644 index 00000000..5ea7b9c9 --- /dev/null +++ b/QSB/Tools/ProbeTool/ProbeCreator.cs @@ -0,0 +1,131 @@ +using QSB.Player; +using UnityEngine; +using UnityEngine.PostProcessing; + +namespace QSB.Tools.ProbeTool +{ + internal static class ProbeCreator + { + public static void CreateProbe(Transform newProbe, PlayerInfo player) + { + var qsbProbe = newProbe.gameObject.AddComponent(); + player.Probe = qsbProbe; + qsbProbe.SetOwner(player); + + // Probe_Body + Object.Destroy(newProbe.GetComponent()); + Object.Destroy(newProbe.GetComponent()); + Object.Destroy(newProbe.GetComponent()); + Object.Destroy(newProbe.GetComponent()); + Object.Destroy(newProbe.GetComponent()); + Object.Destroy(newProbe.GetComponent()); + Object.Destroy(newProbe.GetComponent()); + Object.Destroy(newProbe.GetComponent()); + Object.Destroy(newProbe.GetComponent()); + Object.Destroy(newProbe.GetComponent()); + + // ProbeDetector + //Object.Destroy(newProbe.Find("ProbeDetector").gameObject); + var probeDetector = newProbe.Find("ProbeDetector").gameObject; + Object.Destroy(probeDetector.GetComponent()); + Object.Destroy(probeDetector.GetComponent()); + Object.Destroy(probeDetector.GetComponent()); + + // CameraPivot + var cameraPivot = newProbe.Find("CameraPivot"); + Object.Destroy(cameraPivot.GetComponent()); + + // TODO : Sync probe animations + + // CameraPivot/Geometry/Props_HEA_Probe_ANIM + var animRoot = cameraPivot.Find("Geometry").Find("Props_HEA_Probe_ANIM"); + Object.Destroy(animRoot.GetComponent()); + Object.Destroy(animRoot.GetComponent()); + + // TODO : Set up QSB cameras for these two cameras - that's why im not just destroying the GOs here + + // CameraPivot/ForwardCamera + var forwardCamera = cameraPivot.Find("ForwardCamera"); + Object.Destroy(forwardCamera.GetComponent()); + Object.Destroy(forwardCamera.GetComponent()); + Object.Destroy(forwardCamera.GetComponent()); + Object.Destroy(forwardCamera.GetComponent()); + Object.Destroy(forwardCamera.GetComponent()); + Object.Destroy(forwardCamera.GetComponent()); + var oldForwardSpotlight = forwardCamera.GetComponent(); + var newForwardSpotlight = forwardCamera.gameObject.AddComponent(); + newForwardSpotlight._id = oldForwardSpotlight._id; + newForwardSpotlight._fadeInLength = oldForwardSpotlight._fadeInLength; + newForwardSpotlight._intensity = 0.8f; + Object.Destroy(oldForwardSpotlight); + + // CameraPivot/RotatingCameraPivot/RotatingCamera + var rotatingCamera = cameraPivot.Find("RotatingCameraPivot").Find("RotatingCamera"); + Object.Destroy(rotatingCamera.GetComponent()); + Object.Destroy(rotatingCamera.GetComponent()); + Object.Destroy(rotatingCamera.GetComponent()); + Object.Destroy(rotatingCamera.GetComponent()); + Object.Destroy(rotatingCamera.GetComponent()); + Object.Destroy(rotatingCamera.GetComponent()); + + // ProbeEffects + var probeEffects = newProbe.Find("ProbeEffects"); + var oldEffects = probeEffects.GetComponent(); + var newEffects = probeEffects.gameObject.AddComponent(); + newEffects._flightLoopAudio = oldEffects._flightLoopAudio; + newEffects._anchorAudio = oldEffects._anchorAudio; + newEffects._anchorParticles = oldEffects._anchorParticles; + Object.Destroy(oldEffects); + + Object.Destroy(probeEffects.Find("CloudsEffectBubble").gameObject); + Object.Destroy(probeEffects.Find("SandEffectBubble").gameObject); + Object.Destroy(probeEffects.Find("ProbeElectricityEffect").gameObject); + + // AmbientLight_Probe + var ambientLight = newProbe.Find("AmbientLight_Probe"); + var oldAmbLantern = ambientLight.GetComponent(); + var newAmbLantern = ambientLight.gameObject.AddComponent(); + newAmbLantern._fadeInDuration = oldAmbLantern._fadeInDuration; + newAmbLantern._fadeInCurve = oldAmbLantern._fadeInCurve; + newAmbLantern._fadeOutCurve = oldAmbLantern._fadeOutCurve; + newAmbLantern._emissiveRenderer = oldAmbLantern._emissiveRenderer; + newAmbLantern._originalRange = 60f; + Object.Destroy(oldAmbLantern); + + // Lantern + var lantern = newProbe.Find("Lantern"); + var oldLantern = lantern.GetComponent(); + var newLantern = lantern.gameObject.AddComponent(); + newLantern._fadeInDuration = oldLantern._fadeInDuration; + newLantern._fadeInCurve = oldLantern._fadeInCurve; + newLantern._fadeOutCurve = oldLantern._fadeOutCurve; + newLantern._emissiveRenderer = oldLantern._emissiveRenderer; + newLantern._originalRange = 35f; + Object.Destroy(oldLantern); + + // RearCamera + var rearCamera = newProbe.Find("RearCamera"); + Object.Destroy(rearCamera.GetComponent()); + Object.Destroy(rearCamera.GetComponent()); + Object.Destroy(rearCamera.GetComponent()); + Object.Destroy(rearCamera.GetComponent()); + Object.Destroy(rearCamera.GetComponent()); + Object.Destroy(rearCamera.GetComponent()); + var oldRearSpotlight = rearCamera.GetComponent(); + var newRearSpotlight = rearCamera.gameObject.AddComponent(); + newRearSpotlight._id = oldRearSpotlight._id; + newRearSpotlight._fadeInLength = oldRearSpotlight._fadeInLength; + newRearSpotlight._intensity = 0.8f; + Object.Destroy(oldRearSpotlight); + + // PlaneOffsetMarker_Probe + Object.Destroy(newProbe.Find("PlaneOffsetMarker_Probe").gameObject); + + newProbe.Find("RecallEffect").gameObject.GetComponent().enabled = true; + newProbe.Find("RecallEffect").gameObject.GetComponent().enabled = true; + newProbe.Find("RecallEffect").name = "RemoteProbeRecallEffect"; + + newProbe.gameObject.SetActive(true); + } + } +} diff --git a/QSB/ProbeSync/ProbeEvent.cs b/QSB/Tools/ProbeTool/ProbeEvent.cs similarity index 78% rename from QSB/ProbeSync/ProbeEvent.cs rename to QSB/Tools/ProbeTool/ProbeEvent.cs index 42c02a53..9ba4833b 100644 --- a/QSB/ProbeSync/ProbeEvent.cs +++ b/QSB/Tools/ProbeTool/ProbeEvent.cs @@ -1,4 +1,4 @@ -namespace QSB.ProbeSync +namespace QSB.Tools.ProbeTool { public enum ProbeEvent { diff --git a/QSB/ProbeSync/ProbeListener.cs b/QSB/Tools/ProbeTool/ProbeListener.cs similarity index 98% rename from QSB/ProbeSync/ProbeListener.cs rename to QSB/Tools/ProbeTool/ProbeListener.cs index 003236b9..cca659dd 100644 --- a/QSB/ProbeSync/ProbeListener.cs +++ b/QSB/Tools/ProbeTool/ProbeListener.cs @@ -1,7 +1,7 @@ using QSB.Events; using UnityEngine; -namespace QSB.ProbeSync +namespace QSB.Tools.ProbeTool { internal class ProbeListener : MonoBehaviour { diff --git a/QSB/ProbeSync/QSBProbe.cs b/QSB/Tools/ProbeTool/QSBProbe.cs similarity index 99% rename from QSB/ProbeSync/QSBProbe.cs rename to QSB/Tools/ProbeTool/QSBProbe.cs index 198645fb..5ce1457b 100644 --- a/QSB/ProbeSync/QSBProbe.cs +++ b/QSB/Tools/ProbeTool/QSBProbe.cs @@ -2,7 +2,7 @@ using QSB.Utility; using UnityEngine; -namespace QSB.ProbeSync +namespace QSB.Tools.ProbeTool { public class QSBProbe : MonoBehaviour { diff --git a/QSB/ProbeSync/QSBProbeEffects.cs b/QSB/Tools/ProbeTool/QSBProbeEffects.cs similarity index 90% rename from QSB/ProbeSync/QSBProbeEffects.cs rename to QSB/Tools/ProbeTool/QSBProbeEffects.cs index 86fbdb1e..2d549084 100644 --- a/QSB/ProbeSync/QSBProbeEffects.cs +++ b/QSB/Tools/ProbeTool/QSBProbeEffects.cs @@ -1,8 +1,9 @@ using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; -namespace QSB.ProbeSync +namespace QSB.Tools.ProbeTool { internal class QSBProbeEffects : MonoBehaviour { @@ -14,7 +15,7 @@ namespace QSB.ProbeSync private void Awake() { - _probe = Resources.FindObjectsOfTypeAll().First(x => gameObject.transform.IsChildOf(x.transform)); + _probe = QSBWorldSync.GetUnityObjects().First(x => gameObject.transform.IsChildOf(x.transform)); if (_probe == null) { DebugLog.ToConsole($"Error - Couldn't find QSBProbe!", OWML.Common.MessageType.Error); diff --git a/QSB/ProbeSync/QSBProbeLantern.cs b/QSB/Tools/ProbeTool/QSBProbeLantern.cs similarity index 94% rename from QSB/ProbeSync/QSBProbeLantern.cs rename to QSB/Tools/ProbeTool/QSBProbeLantern.cs index f17914e0..a76275a6 100644 --- a/QSB/ProbeSync/QSBProbeLantern.cs +++ b/QSB/Tools/ProbeTool/QSBProbeLantern.cs @@ -1,8 +1,9 @@ using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; -namespace QSB.ProbeSync +namespace QSB.Tools.ProbeTool { internal class QSBProbeLantern : MonoBehaviour { @@ -22,7 +23,7 @@ namespace QSB.ProbeSync private void Awake() { - _probe = Resources.FindObjectsOfTypeAll().First(x => gameObject.transform.IsChildOf(x.transform)); + _probe = QSBWorldSync.GetUnityObjects().First(x => gameObject.transform.IsChildOf(x.transform)); if (_probe == null) { DebugLog.ToConsole($"Error - Couldn't find QSBProbe!", OWML.Common.MessageType.Error); diff --git a/QSB/ProbeSync/QSBProbeSpotlight.cs b/QSB/Tools/ProbeTool/QSBProbeSpotlight.cs similarity index 90% rename from QSB/ProbeSync/QSBProbeSpotlight.cs rename to QSB/Tools/ProbeTool/QSBProbeSpotlight.cs index 1e1de58b..013b74fd 100644 --- a/QSB/ProbeSync/QSBProbeSpotlight.cs +++ b/QSB/Tools/ProbeTool/QSBProbeSpotlight.cs @@ -1,8 +1,9 @@ using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; -namespace QSB.ProbeSync +namespace QSB.Tools.ProbeTool { internal class QSBProbeSpotlight : MonoBehaviour { @@ -16,7 +17,7 @@ namespace QSB.ProbeSync private void Awake() { - _probe = Resources.FindObjectsOfTypeAll().First(x => gameObject.transform.IsChildOf(x.transform)); + _probe = QSBWorldSync.GetUnityObjects().First(x => gameObject.transform.IsChildOf(x.transform)); if (_probe == null) { DebugLog.ToConsole($"Error - Couldn't find QSBProbe!", OWML.Common.MessageType.Error); diff --git a/QSB/ProbeSync/TransformSync/PlayerProbeSync.cs b/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs similarity index 88% rename from QSB/ProbeSync/TransformSync/PlayerProbeSync.cs rename to QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs index 96d95f0c..7db9e5ae 100644 --- a/QSB/ProbeSync/TransformSync/PlayerProbeSync.cs +++ b/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs @@ -1,14 +1,14 @@ using OWML.Common; using OWML.Utils; using QSB.SectorSync; +using QSB.Syncs; using QSB.Syncs.Sectored.Transforms; -using QSB.Tools; using QSB.Tools.ProbeLauncherTool; using QSB.Utility; using QSB.WorldSync; using UnityEngine; -namespace QSB.ProbeSync.TransformSync +namespace QSB.Tools.ProbeTool.TransformSync { public class PlayerProbeSync : SectoredTransformSync { @@ -58,7 +58,7 @@ namespace QSB.ProbeSync.TransformSync body.name = "RemoteProbeTransform"; - PlayerToolsManager.CreateProbe(body, Player); + ProbeCreator.CreateProbe(body, Player); Player.ProbeBody = body.gameObject; @@ -90,13 +90,13 @@ namespace QSB.ProbeSync.TransformSync if (ReferenceTransform != null) { - _intermediaryTransform.EncodePosition(AttachedObject.transform.position); - _intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation); + transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); } else { - _intermediaryTransform.SetPosition(Vector3.zero); - _intermediaryTransform.SetRotation(Quaternion.identity); + transform.position = Vector3.zero; + transform.rotation = Quaternion.identity; } var currentReferenceSector = ReferenceSector; @@ -114,4 +114,4 @@ namespace QSB.ProbeSync.TransformSync public override bool IsReady => Locator.GetProbe() != null; } -} \ No newline at end of file +} diff --git a/QSB/Tools/QSBTool.cs b/QSB/Tools/QSBTool.cs index 08d15018..1a001d99 100644 --- a/QSB/Tools/QSBTool.cs +++ b/QSB/Tools/QSBTool.cs @@ -31,8 +31,8 @@ namespace QSB.Tools set => _arrivalDegrees = value; } - public void OnEnable() => ToolGameObject?.SetActive(true); - public void OnDisable() => ToolGameObject?.SetActive(false); + public virtual void OnEnable() => ToolGameObject?.SetActive(true); + public virtual void OnDisable() => ToolGameObject?.SetActive(false); public void ChangeEquipState(bool equipState) { diff --git a/QSB/Tools/Events/PlayerSignalscopeEvent.cs b/QSB/Tools/SignalscopeTool/Events/PlayerSignalscopeEvent.cs similarity index 81% rename from QSB/Tools/Events/PlayerSignalscopeEvent.cs rename to QSB/Tools/SignalscopeTool/Events/PlayerSignalscopeEvent.cs index e1d08ee2..166dd357 100644 --- a/QSB/Tools/Events/PlayerSignalscopeEvent.cs +++ b/QSB/Tools/SignalscopeTool/Events/PlayerSignalscopeEvent.cs @@ -2,7 +2,7 @@ using QSB.Messaging; using QSB.Player; -namespace QSB.Tools.Events +namespace QSB.Tools.SignalscopeTool.Events { public class PlayerSignalscopeEvent : QSBEvent { @@ -23,7 +23,7 @@ namespace QSB.Tools.Events private void HandleEquip(Signalscope var) => SendEvent(CreateMessage(true)); private void HandleUnequip() => SendEvent(CreateMessage(false)); - private ToggleMessage CreateMessage(bool value) => new ToggleMessage + private ToggleMessage CreateMessage(bool value) => new() { AboutId = LocalPlayerId, ToggleValue = value @@ -32,11 +32,11 @@ namespace QSB.Tools.Events public override void OnReceiveRemote(bool server, ToggleMessage message) { var player = QSBPlayerManager.GetPlayer(message.AboutId); - player.PlayerStates.SignalscopeEquipped = message.ToggleValue; + player.SignalscopeEquipped = message.ToggleValue; player.Signalscope?.ChangeEquipState(message.ToggleValue); } public override void OnReceiveLocal(bool server, ToggleMessage message) => - QSBPlayerManager.LocalPlayer.PlayerStates.SignalscopeEquipped = message.ToggleValue; + QSBPlayerManager.LocalPlayer.SignalscopeEquipped = message.ToggleValue; } } \ No newline at end of file diff --git a/QSB/FrequencySync/Events/IdentifyFrequencyEvent.cs b/QSB/Tools/SignalscopeTool/FrequencySync/Events/IdentifyFrequencyEvent.cs similarity index 93% rename from QSB/FrequencySync/Events/IdentifyFrequencyEvent.cs rename to QSB/Tools/SignalscopeTool/FrequencySync/Events/IdentifyFrequencyEvent.cs index da96f4b5..0248b72d 100644 --- a/QSB/FrequencySync/Events/IdentifyFrequencyEvent.cs +++ b/QSB/Tools/SignalscopeTool/FrequencySync/Events/IdentifyFrequencyEvent.cs @@ -2,7 +2,7 @@ using QSB.Messaging; using QSB.Player; -namespace QSB.FrequencySync.Events +namespace QSB.Tools.SignalscopeTool.FrequencySync.Events { public class IdentifyFrequencyEvent : QSBEvent> { @@ -13,7 +13,7 @@ namespace QSB.FrequencySync.Events private void Handler(SignalFrequency frequency) => SendEvent(CreateMessage(frequency)); - private EnumMessage CreateMessage(SignalFrequency frequency) => new EnumMessage + private EnumMessage CreateMessage(SignalFrequency frequency) => new() { AboutId = QSBPlayerManager.LocalPlayerId, EnumValue = frequency diff --git a/QSB/FrequencySync/Events/IdentifySignalEvent.cs b/QSB/Tools/SignalscopeTool/FrequencySync/Events/IdentifySignalEvent.cs similarity index 94% rename from QSB/FrequencySync/Events/IdentifySignalEvent.cs rename to QSB/Tools/SignalscopeTool/FrequencySync/Events/IdentifySignalEvent.cs index 622e48ab..95dbfbfe 100644 --- a/QSB/FrequencySync/Events/IdentifySignalEvent.cs +++ b/QSB/Tools/SignalscopeTool/FrequencySync/Events/IdentifySignalEvent.cs @@ -2,7 +2,7 @@ using QSB.Messaging; using QSB.Player; -namespace QSB.FrequencySync.Events +namespace QSB.Tools.SignalscopeTool.FrequencySync.Events { public class IdentifySignalEvent : QSBEvent> { @@ -13,7 +13,7 @@ namespace QSB.FrequencySync.Events private void Handler(SignalName name) => SendEvent(CreateMessage(name)); - private EnumMessage CreateMessage(SignalName name) => new EnumMessage + private EnumMessage CreateMessage(SignalName name) => new() { AboutId = QSBPlayerManager.LocalPlayerId, EnumValue = name diff --git a/QSB/FrequencySync/Patches/FrequencyPatches.cs b/QSB/Tools/SignalscopeTool/FrequencySync/Patches/FrequencyPatches.cs similarity index 73% rename from QSB/FrequencySync/Patches/FrequencyPatches.cs rename to QSB/Tools/SignalscopeTool/FrequencySync/Patches/FrequencyPatches.cs index a7ad6a5a..9a6ac156 100644 --- a/QSB/FrequencySync/Patches/FrequencyPatches.cs +++ b/QSB/Tools/SignalscopeTool/FrequencySync/Patches/FrequencyPatches.cs @@ -2,7 +2,7 @@ using QSB.Events; using QSB.Patches; -namespace QSB.FrequencySync.Patches +namespace QSB.Tools.SignalscopeTool.FrequencySync.Patches { [HarmonyPatch] public class FrequencyPatches : QSBPatch @@ -11,12 +11,12 @@ namespace QSB.FrequencySync.Patches [HarmonyPostfix] [HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.IdentifyFrequency))] - static void IdentifyFrequencyEvent(SignalFrequency ____frequency) + public static void IdentifyFrequencyEvent(SignalFrequency ____frequency) => QSBEventManager.FireEvent(EventNames.QSBIdentifyFrequency, ____frequency); [HarmonyPostfix] [HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.IdentifySignal))] - static void IdentifySignalEvent(SignalName ____name) + public static void IdentifySignalEvent(SignalName ____name) => QSBEventManager.FireEvent(EventNames.QSBIdentifySignal, ____name); } } diff --git a/QSB/Tools/SignalscopeTool/SignalscopeCreator.cs b/QSB/Tools/SignalscopeTool/SignalscopeCreator.cs new file mode 100644 index 00000000..2db6adc2 --- /dev/null +++ b/QSB/Tools/SignalscopeTool/SignalscopeCreator.cs @@ -0,0 +1,40 @@ +using UnityEngine; +using UnityEngine.Rendering; + +namespace QSB.Tools.SignalscopeTool +{ + internal static class SignalscopeCreator + { + private static readonly Vector3 SignalscopeScale = new(1.5f, 1.5f, 1.5f); + + internal static void CreateSignalscope(Transform cameraBody) + { + var signalscopeRoot = Object.Instantiate(GameObject.Find("Signalscope")); + signalscopeRoot.name = "REMOTE_Signalscope"; + signalscopeRoot.SetActive(false); + + var Props_HEA_Signalscope = signalscopeRoot.transform.Find("Props_HEA_Signalscope"); + + Object.Destroy(signalscopeRoot.GetComponent()); + Object.Destroy(Props_HEA_Signalscope.Find("Props_HEA_Signalscope_Prepass").gameObject); + + var oldSignalscope = signalscopeRoot.GetComponent(); + var tool = signalscopeRoot.AddComponent(); + tool.MoveSpring = oldSignalscope._moveSpring; + tool.StowTransform = PlayerToolsManager.StowTransform; + tool.HoldTransform = PlayerToolsManager.HoldTransform; + tool.ArrivalDegrees = 5f; + tool.Type = ToolType.Signalscope; + tool.ToolGameObject = Props_HEA_Signalscope.gameObject; + oldSignalscope.enabled = false; + + Props_HEA_Signalscope.GetComponent().material = PlayerToolsManager.Props_HEA_PlayerTool_mat; + Props_HEA_Signalscope.GetComponent().shadowCastingMode = ShadowCastingMode.On; + + signalscopeRoot.transform.parent = cameraBody; + signalscopeRoot.transform.localPosition = Vector3.zero; + signalscopeRoot.transform.localScale = SignalscopeScale; + signalscopeRoot.SetActive(true); + } + } +} diff --git a/QSB/Tools/Events/PlayerTranslatorEvent.cs b/QSB/Tools/TranslatorTool/Events/PlayerTranslatorEvent.cs similarity index 81% rename from QSB/Tools/Events/PlayerTranslatorEvent.cs rename to QSB/Tools/TranslatorTool/Events/PlayerTranslatorEvent.cs index f5cd7235..53b5788d 100644 --- a/QSB/Tools/Events/PlayerTranslatorEvent.cs +++ b/QSB/Tools/TranslatorTool/Events/PlayerTranslatorEvent.cs @@ -2,7 +2,7 @@ using QSB.Messaging; using QSB.Player; -namespace QSB.Tools.Events +namespace QSB.Tools.TranslatorTool.Events { public class PlayerTranslatorEvent : QSBEvent { @@ -23,7 +23,7 @@ namespace QSB.Tools.Events private void HandleEquip() => SendEvent(CreateMessage(true)); private void HandleUnequip() => SendEvent(CreateMessage(false)); - private ToggleMessage CreateMessage(bool value) => new ToggleMessage + private ToggleMessage CreateMessage(bool value) => new() { AboutId = LocalPlayerId, ToggleValue = value @@ -32,11 +32,11 @@ namespace QSB.Tools.Events public override void OnReceiveRemote(bool server, ToggleMessage message) { var player = QSBPlayerManager.GetPlayer(message.AboutId); - player.PlayerStates.TranslatorEquipped = message.ToggleValue; + player.TranslatorEquipped = message.ToggleValue; player.Translator?.ChangeEquipState(message.ToggleValue); } public override void OnReceiveLocal(bool server, ToggleMessage message) => - QSBPlayerManager.LocalPlayer.PlayerStates.TranslatorEquipped = message.ToggleValue; + QSBPlayerManager.LocalPlayer.TranslatorEquipped = message.ToggleValue; } } \ No newline at end of file diff --git a/QSB/Tools/TranslatorTool/QSBNomaiTranslator.cs b/QSB/Tools/TranslatorTool/QSBNomaiTranslator.cs new file mode 100644 index 00000000..c534047a --- /dev/null +++ b/QSB/Tools/TranslatorTool/QSBNomaiTranslator.cs @@ -0,0 +1,156 @@ +using UnityEngine; + +namespace QSB.Tools.TranslatorTool +{ + internal class QSBNomaiTranslator : QSBTool + { + public static float distToClosestTextCenter = 1f; + + public const float MAX_INTERACT_RANGE = 25f; + + public Transform RaycastTransform; + private Collider _lastHitCollider; + private QSBNomaiTranslatorProp _translatorProp; + private NomaiText _currentNomaiText; + private NomaiTextLine _lastHighlightedTextLine; + private bool _lastLineWasTranslated; + private bool _lastLineLocked; + private float _lastLineDist; + + private void Awake() + { + _lastHitCollider = null; + _translatorProp = this.GetRequiredComponentInChildren(); + _currentNomaiText = null; + } + + public override void OnDisable() + => _translatorProp.OnFinishUnequipAnimation(); + + public override void EquipTool() + { + base.EquipTool(); + _translatorProp.OnEquipTool(); + } + + public override void UnequipTool() + { + base.UnequipTool(); + _translatorProp.OnUnequipTool(); + } + + public override void Update() + { + base.Update(); + if (!_isEquipped) + { + return; + } + + distToClosestTextCenter = 1f; + var tooCloseToTarget = false; + var num = float.MaxValue; + if (Physics.Raycast(RaycastTransform.position, RaycastTransform.forward, out var raycastHit, 25f, OWLayerMask.blockableInteractMask)) + { + _lastHitCollider = raycastHit.collider; + _currentNomaiText = _lastHitCollider.GetComponent(); + + if (_currentNomaiText != null && !_currentNomaiText.CheckAllowFocus(raycastHit.distance, RaycastTransform.forward)) + { + _currentNomaiText = null; + } + + num = raycastHit.distance; + } + else + { + _lastHitCollider = null; + _currentNomaiText = null; + } + + if (_currentNomaiText != null) + { + tooCloseToTarget = num < _currentNomaiText.GetMinimumReadableDistance(); + + if (_currentNomaiText is NomaiWallText) + { + var nomaiTextLine = (_currentNomaiText as NomaiWallText).GetClosestTextLineByCenter(raycastHit.point); + if (_lastLineLocked) + { + var distToCenter = _lastHighlightedTextLine.GetDistToCenter(raycastHit.point); + if (distToCenter > _lastLineDist + 0.1f) + { + _lastHighlightedTextLine = nomaiTextLine; + _lastLineWasTranslated = nomaiTextLine != null && nomaiTextLine.IsTranslated(); + _lastLineLocked = false; + } + else + { + nomaiTextLine = _lastHighlightedTextLine; + } + + if (distToCenter < _lastLineDist) + { + _lastLineDist = distToCenter; + } + } + else if (_lastHighlightedTextLine != null && _lastHighlightedTextLine.IsTranslated() && !_lastLineWasTranslated) + { + _lastLineWasTranslated = true; + _lastLineDist = _lastHighlightedTextLine.GetDistToCenter(raycastHit.point); + _lastLineLocked = true; + } + else + { + _lastHighlightedTextLine = nomaiTextLine; + _lastLineWasTranslated = nomaiTextLine != null && nomaiTextLine.IsTranslated(); + } + + if (nomaiTextLine && !nomaiTextLine.IsHidden() && nomaiTextLine.IsActive()) + { + distToClosestTextCenter = Vector3.Distance(raycastHit.point, nomaiTextLine.GetWorldCenter()); + _translatorProp.SetNomaiTextLine(nomaiTextLine); + } + else + { + _translatorProp.ClearNomaiTextLine(); + _lastHighlightedTextLine = null; + _lastLineWasTranslated = false; + _lastLineLocked = false; + } + } + else if (_currentNomaiText is NomaiComputer) + { + var closestRing = (_currentNomaiText as NomaiComputer).GetClosestRing(raycastHit.point, out var num2); + if (closestRing) + { + distToClosestTextCenter = Mathf.Min(num2 * 2f, 1f); + _translatorProp.SetNomaiComputerRing(closestRing); + } + } + else if (_currentNomaiText is NomaiVesselComputer) + { + var closestRing2 = (_currentNomaiText as NomaiVesselComputer).GetClosestRing(raycastHit.point, out var num3); + if (closestRing2) + { + distToClosestTextCenter = Mathf.Min(num3 * 2f, 1f); + _translatorProp.SetNomaiVesselComputerRing(closestRing2); + } + } + else if (_currentNomaiText is GhostWallText) + { + var ghostWallText = _currentNomaiText as GhostWallText; + _translatorProp.SetNomaiTextLine(ghostWallText.GetTextLine()); + } + } + else + { + _translatorProp.ClearNomaiTextLine(); + _translatorProp.ClearNomaiComputerRing(); + _translatorProp.ClearNomaiVesselComputerRing(); + } + + _translatorProp.SetTooCloseToTarget(tooCloseToTarget); + } + } +} diff --git a/QSB/Tools/TranslatorTool/QSBNomaiTranslatorProp.cs b/QSB/Tools/TranslatorTool/QSBNomaiTranslatorProp.cs new file mode 100644 index 00000000..50b1c22f --- /dev/null +++ b/QSB/Tools/TranslatorTool/QSBNomaiTranslatorProp.cs @@ -0,0 +1,179 @@ +using UnityEngine; + +namespace QSB.Tools.TranslatorTool +{ + internal class QSBNomaiTranslatorProp : MonoBehaviour + { + private static MaterialPropertyBlock s_matPropBlock; + private static int s_propID_EmissionColor; + + public GameObject TranslatorProp; + public MeshRenderer _leftPageArrowRenderer; + public MeshRenderer _rightPageArrowRenderer; + public Color _baseEmissionColor; + + private TranslatorTargetBeam _targetBeam; + private QSBTranslatorScanBeam[] _scanBeams; + private bool _isTranslating; + + private void Awake() + { + _targetBeam = transform.GetComponentInChildren(); + + if (s_matPropBlock == null) + { + s_matPropBlock = new MaterialPropertyBlock(); + s_propID_EmissionColor = Shader.PropertyToID("_EmissionColor"); + } + + TurnOffArrowEmission(); + + TranslatorProp.SetActive(false); + } + + private void Start() + { + _scanBeams = transform.GetComponentsInChildren(); + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].enabled = false; + } + + enabled = false; + } + + private void TurnOffArrowEmission() + { + if (_leftPageArrowRenderer != null) + { + SetMaterialEmissionEnabled(_leftPageArrowRenderer, false); + } + + if (_rightPageArrowRenderer != null) + { + SetMaterialEmissionEnabled(_rightPageArrowRenderer, false); + } + } + + private void SetMaterialEmissionEnabled(MeshRenderer emissiveRenderer, bool emissionEnabled) + { + if (emissionEnabled) + { + s_matPropBlock.SetColor(s_propID_EmissionColor, _baseEmissionColor * 1f); + emissiveRenderer.SetPropertyBlock(s_matPropBlock); + return; + } + + s_matPropBlock.SetColor(s_propID_EmissionColor, _baseEmissionColor * 0f); + emissiveRenderer.SetPropertyBlock(s_matPropBlock); + } + + public void OnEquipTool() + { + enabled = true; + if (_targetBeam) + { + _targetBeam.Activate(); + } + + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].enabled = true; + } + + TranslatorProp.SetActive(true); + } + + public void OnUnequipTool() + { + enabled = false; + StopTranslating(); + TurnOffArrowEmission(); + } + + public void OnFinishUnequipAnimation() + { + if (_targetBeam) + { + _targetBeam.Deactivate(); + } + + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].enabled = false; + } + + TranslatorProp.SetActive(false); + } + + public void SetTooCloseToTarget(bool value) + { + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].SetTooCloseToTarget(value); + } + } + + public void SetNomaiTextLine(NomaiTextLine line) + { + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].SetNomaiTextLine(line); + _scanBeams[i].SetNomaiComputerRing(null); + _scanBeams[i].SetNomaiVesselComputerRing(null); + } + } + + public void ClearNomaiTextLine() + { + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].SetNomaiTextLine(null); + } + } + + public void SetNomaiComputerRing(NomaiComputerRing ring) + { + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].SetNomaiTextLine(null); + _scanBeams[i].SetNomaiComputerRing(ring); + _scanBeams[i].SetNomaiVesselComputerRing(null); + } + } + + public void ClearNomaiComputerRing() + { + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].SetNomaiComputerRing(null); + } + } + + public void SetNomaiVesselComputerRing(NomaiVesselComputerRing ring) + { + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].SetNomaiTextLine(null); + _scanBeams[i].SetNomaiComputerRing(null); + _scanBeams[i].SetNomaiVesselComputerRing(ring); + } + } + + public void ClearNomaiVesselComputerRing() + { + for (var i = 0; i < _scanBeams.Length; i++) + { + _scanBeams[i].SetNomaiVesselComputerRing(null); + } + } + + private void StopTranslating() + { + if (_isTranslating) + { + _isTranslating = false; + } + } + } +} diff --git a/QSB/Tools/TranslatorTool/QSBTranslatorScanBeam.cs b/QSB/Tools/TranslatorTool/QSBTranslatorScanBeam.cs new file mode 100644 index 00000000..e4d0b9f1 --- /dev/null +++ b/QSB/Tools/TranslatorTool/QSBTranslatorScanBeam.cs @@ -0,0 +1,230 @@ +using UnityEngine; + +namespace QSB.Tools.TranslatorTool +{ + internal class QSBTranslatorScanBeam : MonoBehaviour + { + public Renderer _projectorRenderer; + public Renderer _lightVolumeRenderer; + private const float _focusedBeamWidth = 0.25f; + private const float _maxBeamWidth = 1f; + private const float _maxBeamLength = 10f; + private const float _scanOffset = 0f; + private const float _switchLength = 0.33f; + private const float _fadeLength = 0.66f; + + public float _scanSpeed = 1f; + public readonly Color _baseProjectorColor = new(0.3545942f, 2.206932f, 4.594794f, 1f); + public readonly Color _baseLightColor = new(0.1301365f, 0.2158605f, 0.6239606f, 1f); + public Quaternion _baseRotation; + + private bool _tooCloseToTarget; + private NomaiTextLine _nomaiTextLine; + private NomaiComputerRing _nomaiComputerRing; + private NomaiVesselComputerRing _nomaiVesselComputerRing; + private float _scanTime; + private float _switchTime; + private Quaternion _prevRotation; + private Vector3 _prevScale; + private float _fade; + + private void Awake() + { + _tooCloseToTarget = false; + _prevRotation = Quaternion.identity; + _prevScale = new Vector3(_maxBeamWidth, _maxBeamWidth, _maxBeamLength); + _fade = 0f; + + if (_projectorRenderer != null) + { + _projectorRenderer.material.SetAlpha(0f); + _projectorRenderer.enabled = false; + } + + if (_lightVolumeRenderer != null) + { + _lightVolumeRenderer.material.SetAlpha(0f); + _lightVolumeRenderer.enabled = false; + } + } + + private void OnDisable() + { + _tooCloseToTarget = false; + _nomaiTextLine = null; + _prevRotation = Quaternion.identity; + _prevScale = new Vector3(_maxBeamWidth, _maxBeamWidth, _maxBeamLength); + _fade = 0f; + if (_projectorRenderer != null) + { + _projectorRenderer.material.SetAlpha(0f); + _projectorRenderer.enabled = false; + } + + if (_lightVolumeRenderer != null) + { + _lightVolumeRenderer.material.SetAlpha(0f); + _lightVolumeRenderer.enabled = false; + } + + transform.localRotation = _baseRotation; + transform.localScale = _prevScale; + } + + public bool IsSwitching() + => _switchTime < 1f; + + private void OnRenderObject() + { + if (!QSBCore.WorldObjectsReady || !QSBCore.ShowLinesInDebug) + { + return; + } + + Popcron.Gizmos.Line(transform.position, transform.position + transform.forward); + } + + private void Update() + { + if (_nomaiTextLine != null && !_tooCloseToTarget) + { + _switchTime = Mathf.MoveTowards(_switchTime, 1f, Time.deltaTime / _switchLength); + var smoothedSwitchTime = Mathf.SmoothStep(0f, 1f, _switchTime); + _scanTime += Time.deltaTime * _scanSpeed; + var num = (Mathf.Cos(_scanTime + _scanOffset) * 0.5f) + 0.5f; + var pointAlongLine = _nomaiTextLine.GetPointAlongLine(num); + var rhs = _nomaiTextLine.GetPointAlongLine(num + 0.1f) - _nomaiTextLine.GetPointAlongLine(num - 0.1f); + var vector = pointAlongLine - transform.position; + var upwards = Vector3.Cross(vector, rhs); + var distance = Vector3.Distance(transform.position, pointAlongLine); + var q = Quaternion.LookRotation(vector, upwards); + var scanningRotation = transform.parent.InverseTransformRotation(q); + transform.localRotation = Quaternion.Lerp(_prevRotation, scanningRotation, smoothedSwitchTime); + transform.localScale = Vector3.Lerp(_prevScale, new Vector3(_focusedBeamWidth, _focusedBeamWidth, 1f + distance), smoothedSwitchTime); + } + else if (_nomaiComputerRing != null && !_tooCloseToTarget) + { + _switchTime = Mathf.MoveTowards(_switchTime, 1f, Time.deltaTime / _switchLength); + var t2 = Mathf.SmoothStep(0f, 1f, _switchTime); + _scanTime += Time.deltaTime * _scanSpeed; + var t3 = (Mathf.Cos(_scanTime + _scanOffset) * 0.5f) + 0.5f; + t3 = Mathf.Lerp(0.25f, 0.75f, t3); + var pointOnRing = _nomaiComputerRing.GetPointOnRing(t3, transform.position); + var forward = pointOnRing - transform.position; + var up = _nomaiComputerRing.transform.up; + var num3 = Vector3.Distance(transform.position, pointOnRing); + var q2 = Quaternion.LookRotation(forward, up); + var b2 = transform.parent.InverseTransformRotation(q2); + transform.localRotation = Quaternion.Lerp(_prevRotation, b2, t2); + transform.localScale = Vector3.Lerp(_prevScale, new Vector3(_focusedBeamWidth, _focusedBeamWidth, 1f + num3), t2); + } + else if (_nomaiVesselComputerRing != null && !_tooCloseToTarget) + { + _switchTime = Mathf.MoveTowards(_switchTime, 1f, Time.deltaTime / _switchLength); + var smoothedSwitchTime = Mathf.SmoothStep(0f, 1f, _switchTime); + + _scanTime += Time.deltaTime * _scanSpeed; + var t5 = (Mathf.Cos(_scanTime + _scanOffset) * 0.5f) + 0.5f; + t5 = Mathf.Lerp(0.25f, 0.75f, t5); + var pointOnRing2 = _nomaiVesselComputerRing.GetPointOnRing(t5, transform.position); + var forward2 = pointOnRing2 - transform.position; + var up2 = _nomaiVesselComputerRing.transform.up; + var num4 = Vector3.Distance(transform.position, pointOnRing2); + var q3 = Quaternion.LookRotation(forward2, up2); + var b3 = transform.parent.InverseTransformRotation(q3); + transform.localRotation = Quaternion.Lerp(_prevRotation, b3, smoothedSwitchTime); + transform.localScale = Vector3.Lerp(_prevScale, new Vector3(_focusedBeamWidth, _focusedBeamWidth, 1f + num4), smoothedSwitchTime); + } + else + { + _switchTime = Mathf.MoveTowards(_switchTime, 1f, Time.deltaTime / _fadeLength); + var t6 = Mathf.SmoothStep(0f, 1f, _switchTime * (2f - _switchTime)); + transform.localRotation = Quaternion.Lerp(_prevRotation, _baseRotation, _switchTime); + transform.localScale = Vector3.Lerp(_prevScale, new Vector3(_maxBeamWidth, _maxBeamWidth, _maxBeamLength), t6); + } + + var flag = !_tooCloseToTarget && (_nomaiTextLine != null || _nomaiComputerRing != null || _nomaiVesselComputerRing != null); + + _fade = Mathf.MoveTowards( + _fade, + flag + ? 1f + : 0f, + Time.deltaTime / _fadeLength * (_tooCloseToTarget + ? 3f + : 1f)); + + if (_projectorRenderer != null) + { + var shouldBeOn = _fade > 0f; + if (_projectorRenderer.enabled != shouldBeOn) + { + _projectorRenderer.enabled = shouldBeOn; + } + + if (_projectorRenderer.enabled) + { + _projectorRenderer.material.SetAlpha(_fade * _fade * _baseProjectorColor.a); + } + } + + if (_lightVolumeRenderer != null) + { + var shouldBeOn = _fade > 0f; + if (_lightVolumeRenderer.enabled != shouldBeOn) + { + _lightVolumeRenderer.enabled = shouldBeOn; + } + + if (_lightVolumeRenderer.enabled) + { + _lightVolumeRenderer.material.SetAlpha(_fade * _fade * _baseLightColor.a); + } + } + } + + public void SetTooCloseToTarget(bool tooClose) + { + if (_tooCloseToTarget != tooClose) + { + _tooCloseToTarget = tooClose; + _switchTime = 0f; + _prevRotation = transform.localRotation; + _prevScale = transform.localScale; + } + } + + public void SetNomaiTextLine(NomaiTextLine line) + { + if (_nomaiTextLine != line) + { + _switchTime = 0f; + _nomaiTextLine = line; + _prevRotation = transform.localRotation; + _prevScale = transform.localScale; + } + } + + public void SetNomaiComputerRing(NomaiComputerRing ring) + { + if (_nomaiComputerRing != ring) + { + _switchTime = 0f; + _nomaiComputerRing = ring; + _prevRotation = transform.localRotation; + _prevScale = transform.localScale; + } + } + + public void SetNomaiVesselComputerRing(NomaiVesselComputerRing ring) + { + if (_nomaiVesselComputerRing != ring) + { + _switchTime = 0f; + _nomaiVesselComputerRing = ring; + _prevRotation = transform.localRotation; + _prevScale = transform.localScale; + } + } + } +} diff --git a/QSB/TranslationSync/Events/SetAsTranslatedEvent.cs b/QSB/Tools/TranslatorTool/TranslationSync/Events/SetAsTranslatedEvent.cs similarity index 91% rename from QSB/TranslationSync/Events/SetAsTranslatedEvent.cs rename to QSB/Tools/TranslatorTool/TranslationSync/Events/SetAsTranslatedEvent.cs index ce613f3c..f959646a 100644 --- a/QSB/TranslationSync/Events/SetAsTranslatedEvent.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/Events/SetAsTranslatedEvent.cs @@ -1,8 +1,8 @@ using QSB.Events; -using QSB.TranslationSync.WorldObjects; +using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects; using QSB.WorldSync; -namespace QSB.TranslationSync.Events +namespace QSB.Tools.TranslatorTool.TranslationSync.Events { public class SetAsTranslatedEvent : QSBEvent { @@ -13,7 +13,7 @@ namespace QSB.TranslationSync.Events private void Handler(NomaiTextType type, int objId, int textId) => SendEvent(CreateMessage(type, objId, textId)); - private SetAsTranslatedMessage CreateMessage(NomaiTextType type, int objId, int textId) => new SetAsTranslatedMessage + private SetAsTranslatedMessage CreateMessage(NomaiTextType type, int objId, int textId) => new() { AboutId = LocalPlayerId, ObjectId = objId, diff --git a/QSB/TranslationSync/Events/SetAsTranslatedMessage.cs b/QSB/Tools/TranslatorTool/TranslationSync/Events/SetAsTranslatedMessage.cs similarity index 88% rename from QSB/TranslationSync/Events/SetAsTranslatedMessage.cs rename to QSB/Tools/TranslatorTool/TranslationSync/Events/SetAsTranslatedMessage.cs index c6777c72..e27aad02 100644 --- a/QSB/TranslationSync/Events/SetAsTranslatedMessage.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/Events/SetAsTranslatedMessage.cs @@ -1,7 +1,7 @@ using QSB.WorldSync.Events; using QuantumUNET.Transport; -namespace QSB.TranslationSync.Events +namespace QSB.Tools.TranslatorTool.TranslationSync.Events { public class SetAsTranslatedMessage : EnumWorldObjectMessage { diff --git a/QSB/TranslationSync/NomaiTextType.cs b/QSB/Tools/TranslatorTool/TranslationSync/NomaiTextType.cs similarity index 62% rename from QSB/TranslationSync/NomaiTextType.cs rename to QSB/Tools/TranslatorTool/TranslationSync/NomaiTextType.cs index c5cd6f08..2ca81183 100644 --- a/QSB/TranslationSync/NomaiTextType.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/NomaiTextType.cs @@ -1,4 +1,4 @@ -namespace QSB.TranslationSync +namespace QSB.Tools.TranslatorTool.TranslationSync { public enum NomaiTextType { diff --git a/QSB/TranslationSync/Patches/SpiralPatches.cs b/QSB/Tools/TranslatorTool/TranslationSync/Patches/SpiralPatches.cs similarity index 81% rename from QSB/TranslationSync/Patches/SpiralPatches.cs rename to QSB/Tools/TranslatorTool/TranslationSync/Patches/SpiralPatches.cs index 788366b0..242bb1e5 100644 --- a/QSB/TranslationSync/Patches/SpiralPatches.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/Patches/SpiralPatches.cs @@ -1,10 +1,10 @@ using HarmonyLib; using QSB.Events; using QSB.Patches; -using QSB.TranslationSync.WorldObjects; +using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects; using QSB.WorldSync; -namespace QSB.TranslationSync.Patches +namespace QSB.Tools.TranslatorTool.TranslationSync.Patches { [HarmonyPatch] internal class SpiralPatches : QSBPatch @@ -23,7 +23,7 @@ namespace QSB.TranslationSync.Patches QSBEventManager.FireEvent( EventNames.QSBTextTranslated, NomaiTextType.WallText, - QSBWorldSync.GetIdFromUnity(__instance), + QSBWorldSync.GetIdFromUnity(__instance), id); return true; } @@ -40,7 +40,7 @@ namespace QSB.TranslationSync.Patches QSBEventManager.FireEvent( EventNames.QSBTextTranslated, NomaiTextType.Computer, - QSBWorldSync.GetIdFromUnity(__instance), + QSBWorldSync.GetIdFromUnity(__instance), id); return true; } @@ -57,7 +57,7 @@ namespace QSB.TranslationSync.Patches QSBEventManager.FireEvent( EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, - QSBWorldSync.GetIdFromUnity(__instance), + QSBWorldSync.GetIdFromUnity(__instance), id); return true; } diff --git a/QSB/TranslationSync/SpiralManager.cs b/QSB/Tools/TranslatorTool/TranslationSync/SpiralManager.cs similarity index 73% rename from QSB/TranslationSync/SpiralManager.cs rename to QSB/Tools/TranslatorTool/TranslationSync/SpiralManager.cs index 9bf51bf9..c5c24f7a 100644 --- a/QSB/TranslationSync/SpiralManager.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/SpiralManager.cs @@ -1,7 +1,7 @@ -using QSB.TranslationSync.WorldObjects; +using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects; using QSB.WorldSync; -namespace QSB.TranslationSync +namespace QSB.Tools.TranslatorTool.TranslationSync { internal class SpiralManager : WorldObjectManager { diff --git a/QSB/TranslationSync/WorldObjects/QSBComputer.cs b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBComputer.cs similarity index 93% rename from QSB/TranslationSync/WorldObjects/QSBComputer.cs rename to QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBComputer.cs index 1fb64046..7f645870 100644 --- a/QSB/TranslationSync/WorldObjects/QSBComputer.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBComputer.cs @@ -2,7 +2,7 @@ using QSB.WorldSync; using System.Collections.Generic; -namespace QSB.TranslationSync.WorldObjects +namespace QSB.Tools.TranslatorTool.TranslationSync.WorldObjects { internal class QSBComputer : WorldObject { diff --git a/QSB/TranslationSync/WorldObjects/QSBVesselComputer.cs b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBVesselComputer.cs similarity index 91% rename from QSB/TranslationSync/WorldObjects/QSBVesselComputer.cs rename to QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBVesselComputer.cs index d0e56dc4..e50b64fd 100644 --- a/QSB/TranslationSync/WorldObjects/QSBVesselComputer.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBVesselComputer.cs @@ -3,7 +3,7 @@ using QSB.WorldSync; using System.Collections.Generic; using System.Linq; -namespace QSB.TranslationSync.WorldObjects +namespace QSB.Tools.TranslatorTool.TranslationSync.WorldObjects { internal class QSBVesselComputer : WorldObject { diff --git a/QSB/TranslationSync/WorldObjects/QSBWallText.cs b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBWallText.cs similarity index 73% rename from QSB/TranslationSync/WorldObjects/QSBWallText.cs rename to QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBWallText.cs index 55b4c614..249ffc04 100644 --- a/QSB/TranslationSync/WorldObjects/QSBWallText.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBWallText.cs @@ -1,9 +1,8 @@ -using OWML.Utils; -using QSB.WorldSync; +using QSB.WorldSync; using System.Collections.Generic; using System.Linq; -namespace QSB.TranslationSync.WorldObjects +namespace QSB.Tools.TranslatorTool.TranslationSync.WorldObjects { internal class QSBWallText : WorldObject { @@ -25,7 +24,7 @@ namespace QSB.TranslationSync.WorldObjects public IEnumerable GetTranslatedIds() { - var dict = AttachedObject.GetValue>>("_idToNodeDict"); + var dict = AttachedObject._idToNodeDict; return dict.Keys.Where(key => AttachedObject.IsTranslated(key)); } } diff --git a/QSB/Tools/TranslatorTool/TranslatorCreator.cs b/QSB/Tools/TranslatorTool/TranslatorCreator.cs new file mode 100644 index 00000000..7fea6a20 --- /dev/null +++ b/QSB/Tools/TranslatorTool/TranslatorCreator.cs @@ -0,0 +1,74 @@ +using QSB.Utility; +using UnityEngine; +using UnityEngine.Rendering; + +namespace QSB.Tools.TranslatorTool +{ + internal static class TranslatorCreator + { + private static readonly Vector3 TranslatorScale = new(0.75f, 0.75f, 0.75f); + + internal static void CreateTranslator(Transform cameraBody) + { + var NomaiTranslatorProp = GameObject.Find("NomaiTranslatorProp"); + + var REMOTE_NomaiTranslatorProp = NomaiTranslatorProp.InstantiateInactive(); + REMOTE_NomaiTranslatorProp.name = "REMOTE_NomaiTranslatorProp"; + + var REMOTE_TranslatorGroup = REMOTE_NomaiTranslatorProp.transform.Find("TranslatorGroup"); + var REMOTE_Props_HEA_Translator = REMOTE_TranslatorGroup.Find("Props_HEA_Translator"); + + Object.Destroy(REMOTE_TranslatorGroup.Find("Canvas").gameObject); + Object.Destroy(REMOTE_Props_HEA_Translator.Find("Props_HEA_Translator_Pivot_RotatingPart") + .Find("Props_HEA_Translator_RotatingPart") + .Find("Props_HEA_Translator_RotatingPart_Prepass").gameObject); + Object.Destroy(REMOTE_Props_HEA_Translator.Find("Props_HEA_Translator_Prepass").gameObject); + + foreach (Transform scanBeam in REMOTE_TranslatorGroup.Find("TranslatorBeams")) + { + var oldBeam = scanBeam.GetComponent(); + var newBeam = scanBeam.gameObject.AddComponent(); + newBeam._projectorRenderer = oldBeam._projectorRenderer; + newBeam._lightVolumeRenderer = oldBeam._lightVolumeRenderer; + newBeam._scanSpeed = oldBeam._scanSpeed; + newBeam._baseRotation = oldBeam._baseRotation; + Object.Destroy(oldBeam); + } + + var oldProp = REMOTE_NomaiTranslatorProp.GetComponent(); + var newProp = REMOTE_NomaiTranslatorProp.AddComponent(); + newProp.TranslatorProp = REMOTE_TranslatorGroup.gameObject; + newProp._leftPageArrowRenderer = oldProp._leftPageArrowRenderer; + newProp._rightPageArrowRenderer = oldProp._rightPageArrowRenderer; + newProp._baseEmissionColor = oldProp._baseEmissionColor; + Object.Destroy(oldProp); + + var oldTranslator = REMOTE_NomaiTranslatorProp.GetComponent(); + var tool = REMOTE_NomaiTranslatorProp.AddComponent(); + tool.MoveSpring = oldTranslator._moveSpring; + tool.StowTransform = PlayerToolsManager.StowTransform; + tool.HoldTransform = PlayerToolsManager.HoldTransform; + tool.ArrivalDegrees = 5f; + tool.Type = ToolType.Translator; + tool.ToolGameObject = REMOTE_TranslatorGroup.gameObject; + tool.RaycastTransform = cameraBody; + Object.Destroy(oldTranslator); + + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Screen").material = PlayerToolsManager.Structure_HEA_PlayerShip_Screens_mat; + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Screen").shadowCastingMode = ShadowCastingMode.On; + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Geo").material = PlayerToolsManager.Props_HEA_PlayerTool_mat; + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Geo").shadowCastingMode = ShadowCastingMode.On; + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_RotatingPart").material = PlayerToolsManager.Props_HEA_PlayerTool_mat; + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_RotatingPart").shadowCastingMode = ShadowCastingMode.On; + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Button_L").material = PlayerToolsManager.Props_HEA_Lightbulb_mat; + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Button_L").shadowCastingMode = ShadowCastingMode.On; + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Button_R").material = PlayerToolsManager.Props_HEA_Lightbulb_mat; + PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Button_R").shadowCastingMode = ShadowCastingMode.On; + + REMOTE_NomaiTranslatorProp.transform.parent = cameraBody; + REMOTE_NomaiTranslatorProp.transform.localPosition = Vector3.zero; + REMOTE_NomaiTranslatorProp.transform.localScale = TranslatorScale; + QSBCore.UnityEvents.FireInNUpdates(() => REMOTE_NomaiTranslatorProp.SetActive(true), 5); + } + } +} diff --git a/QSB/Utility/DebugActions.cs b/QSB/Utility/DebugActions.cs index 6b66861c..7c19eefe 100644 --- a/QSB/Utility/DebugActions.cs +++ b/QSB/Utility/DebugActions.cs @@ -1,7 +1,9 @@ using OWML.Utils; using QSB.Events; +using QSB.Player; using QSB.ShipSync; using QSB.Utility.Events; +using System.Linq; using UnityEngine; using UnityEngine.InputSystem; @@ -62,6 +64,27 @@ namespace QSB.Utility PlayerData.SaveWarpedToTheEye(60); LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, true, LoadManager.FadeType.ToWhite); } + + if (Keyboard.current[Key.Numpad1].wasPressedThisFrame) + { + var otherPlayer = QSBPlayerManager.PlayerList.FirstOrDefault(x => x.PlayerId != QSBPlayerManager.LocalPlayerId); + if (otherPlayer != null && otherPlayer.Body != null) + { + var playerBody = Locator.GetPlayerBody(); + playerBody.WarpToPositionRotation(otherPlayer.Body.transform.position, otherPlayer.Body.transform.rotation); + var parentBody = otherPlayer.Body.GetAttachedOWRigidbody(true); + if (parentBody != null) + { + playerBody.SetVelocity(parentBody.GetVelocity()); + playerBody.SetAngularVelocity(parentBody.GetAngularVelocity()); + } + else + { + playerBody.SetVelocity(Vector3.zero); + playerBody.SetAngularVelocity(Vector3.zero); + } + } + } } } -} \ No newline at end of file +} diff --git a/QSB/Utility/DebugBoxManager.cs b/QSB/Utility/DebugBoxManager.cs index 8d2481c6..53df477e 100644 --- a/QSB/Utility/DebugBoxManager.cs +++ b/QSB/Utility/DebugBoxManager.cs @@ -10,7 +10,7 @@ namespace QSB.Utility public static void Init() { - _boxPrefab = QSBCore.ConversationAssetBundle.LoadAsset("assets/dialoguebubble.prefab"); + _boxPrefab = QSBCore.ConversationAssetBundle.LoadAsset("assets/Prefabs/dialoguebubble.prefab"); var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold"); if (font == null) { @@ -28,9 +28,7 @@ namespace QSB.Utility newBox.transform.SetParent(parent); newBox.transform.localPosition = new Vector3(0, vertOffset, 0); newBox.transform.rotation = parent.rotation; - newBox.AddComponent(); newBox.GetComponent().text = text; - newBox.AddComponent(); newBox.SetActive(true); return newBox; } diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index d09d0baf..488533fe 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -1,10 +1,13 @@ -using OWML.Utils; -using QSB.ClientServerStateSync; +using QSB.ClientServerStateSync; using QSB.OrbSync.TransformSync; using QSB.Player; -using QSB.ProbeSync.TransformSync; -using QSB.Syncs; +using QSB.QuantumSync; +using QSB.ShipSync; +using QSB.ShipSync.TransformSync; +using QSB.ShipSync.WorldObjects; using QSB.TimeSync; +using QSB.WorldSync; +using System.Linq; using UnityEngine; namespace QSB.Utility @@ -12,12 +15,59 @@ namespace QSB.Utility internal class DebugGUI : MonoBehaviour { private const float _debugLineSpacing = 8f; + private const float FixedWidth = 200f; + private const float Column1 = 20f; + private float column1Offset = 10f; + private const float Column2 = Column1 + FixedWidth; + private float column2Offset = 10f; + private const float Column3 = Column2 + FixedWidth; + private float column3Offset = 10f; + private const float Column4 = Column3 + FixedWidth; + private float column4Offset = 10f; - private GUIStyle guiStyle = new GUIStyle() + private GUIStyle guiStyle = new() { fontSize = 9 }; + private void WriteLine(int collumnID, string text) + { + var currentOffset = 0f; + var x = 0f; + switch (collumnID) + { + case 1: + x = Column1; + currentOffset = column1Offset; + column1Offset += _debugLineSpacing; + break; + case 2: + x = Column2; + currentOffset = column2Offset; + column2Offset += _debugLineSpacing; + break; + case 3: + x = Column3; + currentOffset = column3Offset; + column3Offset += _debugLineSpacing; + break; + case 4: + x = Column4; + currentOffset = column4Offset; + column4Offset += _debugLineSpacing; + break; + } + + GUI.Label(new Rect(x, currentOffset, FixedWidth, 20f), text, guiStyle); + } + + private void WriteLine(int collumnID, string text, Color color) + { + guiStyle.normal.textColor = color; + WriteLine(collumnID, text); + guiStyle.normal.textColor = Color.white; + } + public void OnGUI() { if (!QSBCore.DebugMode) @@ -28,89 +78,148 @@ namespace QSB.Utility guiStyle.normal.textColor = Color.white; GUI.contentColor = Color.white; - var offset = 10f; - GUI.Label(new Rect(220, 10, 200f, 20f), $"FPS : {Mathf.Round(1f / Time.smoothDeltaTime)}", guiStyle); - offset += _debugLineSpacing; - GUI.Label(new Rect(220, offset, 200f, 20f), $"HasWokenUp : {QSBCore.WorldObjectsReady}", guiStyle); - offset += _debugLineSpacing; + column1Offset = 10f; + column2Offset = 10f; + column3Offset = 10f; + column4Offset = 10f; + + #region Column1 - Server data + WriteLine(1, $"FPS : {Mathf.Round(1f / Time.smoothDeltaTime)}"); + WriteLine(1, $"HasWokenUp : {QSBCore.WorldObjectsReady}"); if (WakeUpSync.LocalInstance != null) { - GUI.Label(new Rect(220, offset, 200f, 20f), $"Server State : {ServerStateManager.Instance.GetServerState()}", guiStyle); - offset += _debugLineSpacing; + WriteLine(1, $"Server State : {ServerStateManager.Instance.GetServerState()}"); var currentState = WakeUpSync.LocalInstance.CurrentState; - GUI.Label(new Rect(220, offset, 200f, 20f), $"WakeUpSync State : {currentState}", guiStyle); - offset += _debugLineSpacing; + WriteLine(1, $"WakeUpSync State : {currentState}"); var reason = WakeUpSync.LocalInstance.CurrentReason; if (currentState == WakeUpSync.State.FastForwarding && reason != null) { - - GUI.Label(new Rect(220, offset, 200f, 20f), $"Reason : {(FastForwardReason)reason}", guiStyle); - offset += _debugLineSpacing; + WriteLine(1, $"Reason : {(FastForwardReason)reason}"); } else if (currentState == WakeUpSync.State.Pausing && reason != null) { - GUI.Label(new Rect(220, offset, 200f, 20f), $"Reason : {(PauseReason)reason}", guiStyle); - offset += _debugLineSpacing; + WriteLine(1, $"Reason : {(PauseReason)reason}"); } else if (currentState != WakeUpSync.State.Loaded && currentState != WakeUpSync.State.NotLoaded && reason == null) { - GUI.Label(new Rect(220, offset, 200f, 20f), $"Reason : NULL", guiStyle); - offset += _debugLineSpacing; + WriteLine(1, $"Reason : NULL", Color.red); } - offset += _debugLineSpacing; - GUI.Label(new Rect(220, offset, 200f, 20f), $"Time Difference : {WakeUpSync.LocalInstance.GetTimeDifference()}", guiStyle); - offset += _debugLineSpacing; - GUI.Label(new Rect(220, offset, 200f, 20f), $"Timescale : {OWTime.GetTimeScale()}", guiStyle); - offset += _debugLineSpacing; - } - var offset2 = 10f; - GUI.Label(new Rect(420, offset2, 200f, 20f), $"OrbList count : {NomaiOrbTransformSync.OrbTransformSyncs.Count}", guiStyle); - offset2 += _debugLineSpacing; - GUI.Label(new Rect(420, offset2, 200f, 20f), $"Player data :", guiStyle); - offset2 += _debugLineSpacing; + WriteLine(1, $"Time Difference : {WakeUpSync.LocalInstance.GetTimeDifference()}"); + WriteLine(1, $"Timescale : {OWTime.GetTimeScale()}"); + WriteLine(1, $"Time Remaining : {Mathf.Floor(TimeLoop.GetSecondsRemaining() / 60f)}:{Mathf.Round(TimeLoop.GetSecondsRemaining() % 60f * 100f / 100f)}"); + WriteLine(1, $"Loop Count : {TimeLoop.GetLoopCount()}"); + } + #endregion + + #region Column2 - Player data + WriteLine(2, $"OrbList count : {NomaiOrbTransformSync.OrbTransformSyncs.Count}"); + WriteLine(2, $"Player data :"); foreach (var player in QSBPlayerManager.PlayerList) { - GUI.Label(new Rect(420, offset2, 400f, 20f), $"{player.PlayerId}.{player.Name}", guiStyle); - offset2 += _debugLineSpacing; - GUI.Label(new Rect(420, offset2, 400f, 20f), $"State : {player.State}", guiStyle); - offset2 += _debugLineSpacing; - GUI.Label(new Rect(420, offset2, 400f, 20f), $"Dead : {player.IsDead}", guiStyle); - offset2 += _debugLineSpacing; - GUI.Label(new Rect(420, offset2, 400f, 20f), $"Visible : {player.Visible}", guiStyle); - offset2 += _debugLineSpacing; + if (player == null) + { + WriteLine(2, $"NULL PLAYER", Color.red); + continue; + } - if (player.PlayerStates.IsReady && QSBCore.WorldObjectsReady) + WriteLine(2, $"{player.PlayerId}.{player.Name}"); + WriteLine(2, $"State : {player.State}"); + WriteLine(2, $"Dead : {player.IsDead}"); + WriteLine(2, $"Visible : {player.Visible}"); + WriteLine(2, $"Ready : {player.IsReady}"); + WriteLine(2, $"Suited Up : {player.SuitedUp}"); + + if (player.IsReady && QSBCore.WorldObjectsReady) { var networkTransform = player.TransformSync; var referenceSector = networkTransform.ReferenceSector; var referenceTransform = networkTransform.ReferenceTransform; var parent = networkTransform.AttachedObject?.transform.parent; - var intermediary = networkTransform.GetValue("_intermediaryTransform"); - var interTransform = intermediary.GetReferenceTransform(); - GUI.Label(new Rect(420, offset2, 400f, 20f), $" - L.Pos : {networkTransform.transform.localPosition}", guiStyle); - offset2 += _debugLineSpacing; - GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Ref. Sector : {(referenceSector == null ? "NULL" : referenceSector.Name)}", guiStyle); - offset2 += _debugLineSpacing; - GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Ref. Transform : {(referenceTransform == null ? "NULL" : referenceTransform.name)}", guiStyle); - offset2 += _debugLineSpacing; - GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Inter. Ref. Transform : {(interTransform == null ? "NULL" : interTransform.name)}", guiStyle); - offset2 += _debugLineSpacing; - GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Parent : {(parent == null ? "NULL" : parent.name)}", guiStyle); - offset2 += _debugLineSpacing; - - /* - var probeSync = SyncBase.GetPlayers(player); - if (probeSync != default) - { - var probeSector = probeSync.ReferenceSector; - GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Probe Sector : {(probeSector == null ? "NULL" : probeSector.Name)}", guiStyle); - offset2 += _debugLineSpacing; - } - */ + WriteLine(2, $" - Ref. Sector : {(referenceSector == null ? "NULL" : referenceSector.Name)}", referenceSector == null ? Color.red : Color.white); + WriteLine(2, $" - Ref. Transform : {(referenceTransform == null ? "NULL" : referenceTransform.name)}", referenceTransform == null ? Color.red : Color.white); + WriteLine(2, $" - Parent : {(parent == null ? "NULL" : parent.name)}", parent == null ? Color.red : Color.white); } } + #endregion + + #region Column3 - Ship data + + WriteLine(3, $"Current Flyer : {ShipManager.Instance.CurrentFlyer}"); + if (ShipTransformSync.LocalInstance != null) + { + var instance = ShipTransformSync.LocalInstance; + if (QSBCore.IsHost) + { + WriteLine(3, $"Current Owner : {instance.NetIdentity.ClientAuthorityOwner.GetPlayerId()}"); + } + + var sector = instance.ReferenceSector; + WriteLine(3, $"Ref. Sector : {(sector != null ? sector.Name : "NULL")}", sector == null ? Color.red : Color.white); + var transform = instance.ReferenceTransform; + WriteLine(3, $"Ref. Transform : {(transform != null ? transform.name : "NULL")}", transform == null ? Color.red : Color.white); + } + else + { + WriteLine(3, $"ShipTransformSync.LocalInstance is null.", Color.red); + } + + WriteLine(3, $"QSBShipComponent"); + foreach (var component in QSBWorldSync.GetWorldObjects()) + { + var attachedObject = component.AttachedObject; + if (attachedObject == null) + { + WriteLine(3, $"- {component.ObjectId} NULL ATTACHEDOBJECT", Color.red); + } + else + { + WriteLine(3, $"- {component.AttachedObject.name} RepairFraction:{component.AttachedObject._repairFraction}"); + } + } + + WriteLine(3, $"QSBShipHull"); + foreach (var hull in QSBWorldSync.GetWorldObjects()) + { + var attachedObject = hull.AttachedObject; + if (attachedObject == null) + { + WriteLine(3, $"- {hull.ObjectId} NULL ATTACHEDOBJECT", Color.red); + } + else + { + WriteLine(3, $"- {hull.AttachedObject.name}, Integrity:{hull.AttachedObject.integrity}"); + } + } + #endregion + + #region Column4 - Quantum Object Possesion + foreach (var player in QSBPlayerManager.PlayerList) + { + if (player == null) + { + WriteLine(4, $"- NULL PLAYER", Color.red); + continue; + } + + WriteLine(4, $"- {player.PlayerId}.{player.Name}"); + var allQuantumObjects = QSBWorldSync.GetWorldObjects(); + var ownedQuantumObjects = allQuantumObjects.Where(x => x.ControllingPlayer == player.PlayerId); + + foreach (var quantumObject in ownedQuantumObjects) + { + if (quantumObject is not IWorldObject qsbObj) + { + WriteLine(4, $"NULL QSBOBJ", Color.red); + } + else + { + WriteLine(4, $"{qsbObj.Name} ({qsbObj.ObjectId})"); + } + } + } + #endregion } } -} \ No newline at end of file +} diff --git a/QSB/Utility/DebugSettings.cs b/QSB/Utility/DebugSettings.cs new file mode 100644 index 00000000..690b4051 --- /dev/null +++ b/QSB/Utility/DebugSettings.cs @@ -0,0 +1,25 @@ +using Newtonsoft.Json; + +namespace QSB.Utility +{ + public class DebugSettings + { + [JsonProperty("debugMode")] + public bool DebugMode { get; set; } = false; + + [JsonProperty("drawLines")] + public bool DrawLines { get; set; } = false; + + [JsonProperty("showQuantumVisibilityObjects")] + public bool ShowQuantumVisibilityObjects { get; set; } = false; + + [JsonProperty("showQuantumDebugBoxes")] + public bool ShowQuantumDebugBoxes { get; set; } = false; + + [JsonProperty("avoidTimeSync")] + public bool AvoidTimeSync { get; set; } = false; + + [JsonProperty("skipTitleScreen")] + public bool SkipTitleScreen { get; set; } = false; + } +} diff --git a/QSB/Utility/Events/DebugEvent.cs b/QSB/Utility/Events/DebugEvent.cs index 0cde719a..5900fc7c 100644 --- a/QSB/Utility/Events/DebugEvent.cs +++ b/QSB/Utility/Events/DebugEvent.cs @@ -12,16 +12,13 @@ namespace QSB.Utility.Events private void Handler(DebugEventEnum type) => SendEvent(CreateMessage(type)); - private EnumMessage CreateMessage(DebugEventEnum type) => new EnumMessage + private EnumMessage CreateMessage(DebugEventEnum type) => new() { AboutId = LocalPlayerId, EnumValue = type }; - public override void OnReceiveLocal(bool isHost, EnumMessage message) - { - OnReceiveRemote(isHost, message); - } + public override void OnReceiveLocal(bool isHost, EnumMessage message) => OnReceiveRemote(isHost, message); public override void OnReceiveRemote(bool isHost, EnumMessage message) { diff --git a/QSB/Utility/Extensions.cs b/QSB/Utility/Extensions.cs index 5f5433d4..aa0adb50 100644 --- a/QSB/Utility/Extensions.cs +++ b/QSB/Utility/Extensions.cs @@ -118,9 +118,9 @@ namespace QSB.Utility public static void RaiseEvent(this T instance, string eventName, params object[] args) { - if (!(typeof(T) + if (typeof(T) .GetField(eventName, Flags)? - .GetValue(instance) is MulticastDelegate multiDelegate)) + .GetValue(instance) is not MulticastDelegate multiDelegate) { return; } diff --git a/QSB/Utility/GlobalMessenger4Args.cs b/QSB/Utility/GlobalMessenger4Args.cs index 0f71dd7c..ffa849ac 100644 --- a/QSB/Utility/GlobalMessenger4Args.cs +++ b/QSB/Utility/GlobalMessenger4Args.cs @@ -74,8 +74,8 @@ namespace QSB.Utility private class EventData { - public List> Callbacks = new List>(); - public List> Temp = new List>(); + public List> Callbacks = new(); + public List> Temp = new(); public bool IsInvoking; } } diff --git a/QSB/Utility/GlobalMessenger5Args.cs b/QSB/Utility/GlobalMessenger5Args.cs index 31a7e6f1..00752f13 100644 --- a/QSB/Utility/GlobalMessenger5Args.cs +++ b/QSB/Utility/GlobalMessenger5Args.cs @@ -74,8 +74,8 @@ namespace QSB.Utility private class EventData { - public List> Callbacks = new List>(); - public List> Temp = new List>(); + public List> Callbacks = new(); + public List> Temp = new(); public bool IsInvoking; } } diff --git a/QSB/Utility/GlobalMessenger6Args.cs b/QSB/Utility/GlobalMessenger6Args.cs index 3caebcaa..e7448e27 100644 --- a/QSB/Utility/GlobalMessenger6Args.cs +++ b/QSB/Utility/GlobalMessenger6Args.cs @@ -74,8 +74,8 @@ namespace QSB.Utility private class EventData { - public List> Callbacks = new List>(); - public List> Temp = new List>(); + public List> Callbacks = new(); + public List> Temp = new(); public bool IsInvoking; } } diff --git a/QSB/Utility/Popcron.Gizmos/Drawer.cs b/QSB/Utility/Popcron.Gizmos/Drawer.cs index 0c9e5419..baa16119 100644 --- a/QSB/Utility/Popcron.Gizmos/Drawer.cs +++ b/QSB/Utility/Popcron.Gizmos/Drawer.cs @@ -32,14 +32,9 @@ namespace Popcron }; } - if (typeToDrawer.TryGetValue(typeof(T), out var drawer)) - { - return drawer; - } - else - { - return null; - } + return typeToDrawer.TryGetValue(typeof(T), out var drawer) + ? drawer + : null; } } } diff --git a/QSB/Utility/Popcron.Gizmos/Drawers/PolygonDrawer.cs b/QSB/Utility/Popcron.Gizmos/Drawers/PolygonDrawer.cs index 2238221b..7a29425b 100644 --- a/QSB/Utility/Popcron.Gizmos/Drawers/PolygonDrawer.cs +++ b/QSB/Utility/Popcron.Gizmos/Drawers/PolygonDrawer.cs @@ -22,12 +22,12 @@ namespace Popcron for (var i = 0; i < points; i++) { - var cx = Mathf.Cos(Mathf.Deg2Rad * step * i + offset) * radius; - var cy = Mathf.Sin(Mathf.Deg2Rad * step * i + offset) * radius; + var cx = Mathf.Cos((Mathf.Deg2Rad * step * i) + offset) * radius; + var cy = Mathf.Sin((Mathf.Deg2Rad * step * i) + offset) * radius; var current = new Vector3(cx, cy); - var nx = Mathf.Cos(Mathf.Deg2Rad * step * (i + 1) + offset) * radius; - var ny = Mathf.Sin(Mathf.Deg2Rad * step * (i + 1) + offset) * radius; + var nx = Mathf.Cos((Mathf.Deg2Rad * step * (i + 1)) + offset) * radius; + var ny = Mathf.Sin((Mathf.Deg2Rad * step * (i + 1)) + offset) * radius; var next = new Vector3(nx, ny); buffer[i * 2] = position + (rotation * current); diff --git a/QSB/Utility/Popcron.Gizmos/Element.cs b/QSB/Utility/Popcron.Gizmos/Element.cs index a3e396e6..3883ecdc 100644 --- a/QSB/Utility/Popcron.Gizmos/Element.cs +++ b/QSB/Utility/Popcron.Gizmos/Element.cs @@ -6,6 +6,5 @@ namespace Popcron { public Vector3[] points = { }; public Color color = Color.white; - public bool dashed = false; } } \ No newline at end of file diff --git a/QSB/Utility/Popcron.Gizmos/Gizmos.cs b/QSB/Utility/Popcron.Gizmos/Gizmos.cs index 449b4c83..8afc111b 100644 --- a/QSB/Utility/Popcron.Gizmos/Gizmos.cs +++ b/QSB/Utility/Popcron.Gizmos/Gizmos.cs @@ -111,7 +111,7 @@ namespace Popcron } } - public static void Draw(Color? color, bool dashed, params object[] args) where T : Drawer + public static void Draw(Color? color, params object[] args) where T : Drawer { var drawer = Drawer.Get(); if (drawer != null) @@ -121,78 +121,78 @@ namespace Popcron //copy from buffer and add to the queue var array = new Vector3[points]; Array.Copy(buffer, array, points); - GizmosInstance.Submit(array, color, dashed); + GizmosInstance.Submit(array, color); } } - public static void Lines(Vector3[] lines, Color? color = null, bool dashed = false) - => GizmosInstance.Submit(lines, color, dashed); + public static void Lines(Vector3[] lines, Color? color = null) + => GizmosInstance.Submit(lines, color); - public static void Line(Vector3 a, Vector3 b, Color? color = null, bool dashed = false) - => Draw(color, dashed, a, b); + public static void Line(Vector3 a, Vector3 b, Color? color = null) + => Draw(color, a, b); - public static void Square(Vector2 position, Vector2 size, Color? color = null, bool dashed = false) - => Square(position, Quaternion.identity, size, color, dashed); + public static void Square(Vector2 position, Vector2 size, Color? color = null) + => Square(position, Quaternion.identity, size, color); - public static void Square(Vector2 position, float diameter, Color? color = null, bool dashed = false) - => Square(position, Quaternion.identity, Vector2.one * diameter, color, dashed); + public static void Square(Vector2 position, float diameter, Color? color = null) + => Square(position, Quaternion.identity, Vector2.one * diameter, color); - public static void Square(Vector2 position, Quaternion rotation, Vector2 size, Color? color = null, bool dashed = false) - => Draw(color, dashed, position, rotation, size); + public static void Square(Vector2 position, Quaternion rotation, Vector2 size, Color? color = null) + => Draw(color, position, rotation, size); - public static void Cube(Vector3 position, Quaternion rotation, Vector3 size, Color? color = null, bool dashed = false) - => Draw(color, dashed, position, rotation, size); + public static void Cube(Vector3 position, Quaternion rotation, Vector3 size, Color? color = null) + => Draw(color, position, rotation, size); - public static void Rect(Rect rect, Camera camera, Color? color = null, bool dashed = false) + public static void Rect(Rect rect, Camera camera, Color? color = null) { rect.y = Screen.height - rect.y; Vector2 corner = camera.ScreenToWorldPoint(new Vector2(rect.x, rect.y - rect.height)); - Draw(color, dashed, corner + (rect.size * 0.5f), Quaternion.identity, rect.size); + Draw(color, corner + (rect.size * 0.5f), Quaternion.identity, rect.size); } - public static void Bounds(Bounds bounds, Color? color = null, bool dashed = false) - => Draw(color, dashed, bounds.center, Quaternion.identity, bounds.size); + public static void Bounds(Bounds bounds, Color? color = null) + => Draw(color, bounds.center, Quaternion.identity, bounds.size); - public static void Cone(Vector3 position, Quaternion rotation, float length, float angle, Color? color = null, bool dashed = false, int pointsCount = 16) + public static void Cone(Vector3 position, Quaternion rotation, float length, float angle, Color? color = null, int pointsCount = 16) { //draw the end of the cone var endAngle = Mathf.Tan(angle * 0.5f * Mathf.Deg2Rad) * length; var forward = rotation * Vector3.forward; var endPosition = position + (forward * length); var offset = 0f; - Draw(color, dashed, endPosition, pointsCount, endAngle, offset, rotation); + Draw(color, endPosition, pointsCount, endAngle, offset, rotation); //draw the 4 lines for (var i = 0; i < 4; i++) { var a = i * 90f * Mathf.Deg2Rad; var point = rotation * new Vector3(Mathf.Cos(a), Mathf.Sin(a)) * endAngle; - Line(position, position + point + (forward * length), color, dashed); + Line(position, position + point + (forward * length), color); } } - public static void Sphere(Vector3 position, float radius, Color? color = null, bool dashed = false, int pointsCount = 16) + public static void Sphere(Vector3 position, float radius, Color? color = null, int pointsCount = 16) { var offset = 0f; - Draw(color, dashed, position, pointsCount, radius, offset, Quaternion.Euler(0f, 0f, 0f)); - Draw(color, dashed, position, pointsCount, radius, offset, Quaternion.Euler(90f, 0f, 0f)); - Draw(color, dashed, position, pointsCount, radius, offset, Quaternion.Euler(0f, 90f, 90f)); + Draw(color, position, pointsCount, radius, offset, Quaternion.Euler(0f, 0f, 0f)); + Draw(color, position, pointsCount, radius, offset, Quaternion.Euler(90f, 0f, 0f)); + Draw(color, position, pointsCount, radius, offset, Quaternion.Euler(0f, 90f, 90f)); } - public static void Circle(Vector3 position, float radius, Camera camera, Color? color = null, bool dashed = false, int pointsCount = 16) + public static void Circle(Vector3 position, float radius, Camera camera, Color? color = null, int pointsCount = 16) { var offset = 0f; var rotation = Quaternion.LookRotation(position - camera.transform.position); - Draw(color, dashed, position, pointsCount, radius, offset, rotation); + Draw(color, position, pointsCount, radius, offset, rotation); } - public static void Circle(Vector3 position, float radius, Quaternion rotation, Color? color = null, bool dashed = false, int pointsCount = 16) + public static void Circle(Vector3 position, float radius, Quaternion rotation, Color? color = null, int pointsCount = 16) { var offset = 0f; - Draw(color, dashed, position, pointsCount, radius, offset, rotation); + Draw(color, position, pointsCount, radius, offset, rotation); } - public static void Frustum(OWCamera camera, Color? color = null, bool dashed = false) - => Draw(color, dashed, camera); + public static void Frustum(OWCamera camera, Color? color = null) + => Draw(color, camera); } } diff --git a/QSB/Utility/Popcron.Gizmos/GizmosInstance.cs b/QSB/Utility/Popcron.Gizmos/GizmosInstance.cs index 65bff7f5..97369924 100644 --- a/QSB/Utility/Popcron.Gizmos/GizmosInstance.cs +++ b/QSB/Utility/Popcron.Gizmos/GizmosInstance.cs @@ -83,8 +83,9 @@ namespace Popcron //none were found, create a new one if (!instance) { - instance = new GameObject(typeof(GizmosInstance).FullName).AddComponent(); - instance.gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; + //instance = new GameObject(typeof(GizmosInstance).FullName).AddComponent(); + //instance.gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; + instance = Locator.GetPlayerCamera().gameObject.AddComponent(); } } @@ -96,7 +97,7 @@ namespace Popcron /// /// Submits an array of points to draw into the queue. /// - internal static void Submit(Vector3[] points, Color? color, bool dashed) + internal static void Submit(Vector3[] points, Color? color) { var inst = GetOrCreate(); @@ -122,7 +123,6 @@ namespace Popcron inst.queue[inst.queueIndex].color = color ?? Color.white; inst.queue[inst.queueIndex].points = points; - inst.queue[inst.queueIndex].dashed = dashed; inst.queueIndex++; } @@ -135,17 +135,13 @@ namespace Popcron { queue[i] = new Element(); } - - Camera.onPostRender += OnRendered; } - private void OnDisable() => Camera.onPostRender -= OnRendered; - private void Update() => //always render something Gizmos.Line(default, default); - private void OnRendered(Camera camera) + private void OnPostRender() { Material.SetPass(0); @@ -155,8 +151,6 @@ namespace Popcron GL.MultMatrix(Matrix4x4.identity); GL.Begin(GL.LINES); - var alt = CurrentTime % 1 > 0.5f; - var dashGap = Mathf.Clamp(Gizmos.DashGap, 0.01f, 32f); var points = new List(); //draw le elements @@ -171,44 +165,7 @@ namespace Popcron var element = queue[e]; points.Clear(); - if (element.dashed) - { - //subdivide - for (var i = 0; i < element.points.Length - 1; i++) - { - var pointA = element.points[i]; - var pointB = element.points[i + 1]; - var direction = pointB - pointA; - if (direction.sqrMagnitude > dashGap * dashGap * 2f) - { - var magnitude = direction.magnitude; - var amount = Mathf.RoundToInt(magnitude / dashGap); - direction /= magnitude; - - for (var p = 0; p < amount - 1; p++) - { - if (p % 2 == (alt ? 1 : 0)) - { - var startLerp = p / (amount - 1f); - var endLerp = (p + 1) / (amount - 1f); - var start = Vector3.Lerp(pointA, pointB, startLerp); - var end = Vector3.Lerp(pointA, pointB, endLerp); - points.Add(start); - points.Add(end); - } - } - } - else - { - points.Add(pointA); - points.Add(pointB); - } - } - } - else - { - points.AddRange(element.points); - } + points.AddRange(element.points); GL.Color(element.color); for (var i = 0; i < points.Count; i++) diff --git a/QSB/Utility/RepeatingManager.cs b/QSB/Utility/RepeatingManager.cs index b79e21cf..54703c8e 100644 --- a/QSB/Utility/RepeatingManager.cs +++ b/QSB/Utility/RepeatingManager.cs @@ -5,7 +5,7 @@ namespace QSB.Utility { internal class RepeatingManager : MonoBehaviour { - public static List Repeatings = new List(); + public static List Repeatings = new(); private const float TimeInterval = 0.4f; private float _checkTimer = TimeInterval; diff --git a/QSB/Utility/UIHelper.cs b/QSB/Utility/UIHelper.cs new file mode 100644 index 00000000..fd669ac3 --- /dev/null +++ b/QSB/Utility/UIHelper.cs @@ -0,0 +1,14 @@ +using System.Linq; + +namespace QSB.Utility +{ + internal static class UIHelper + { + public static int AddToUITable(string text) + { + var instance = UnityEngine.Object.FindObjectOfType().m_table; + instance.Insert_UI(instance.theUITable.Keys.Max() + 1, text); + return instance.theUITable.Keys.Max(); + } + } +} diff --git a/QSB/Utility/VariableSync/BaseVariableSyncer.cs b/QSB/Utility/VariableSync/BaseVariableSyncer.cs new file mode 100644 index 00000000..6e881405 --- /dev/null +++ b/QSB/Utility/VariableSync/BaseVariableSyncer.cs @@ -0,0 +1,114 @@ +using QuantumUNET; +using QuantumUNET.Messages; +using QuantumUNET.Transport; +using System.Linq; +using UnityEngine; +using UnityEngine.Networking; + +namespace QSB.Utility.VariableSync +{ + public abstract class BaseVariableSyncer : QNetworkBehaviour + { + private float _lastClientSendTime; + private QNetworkWriter _writer; + private int _index; + protected bool _ready; + + public abstract void WriteData(QNetworkWriter writer); + public abstract void ReadData(QNetworkReader writer); + + public virtual void Awake() + { + QNetworkServer.instance.m_SimpleServerSimple.RegisterHandlerSafe((short)QSB.Events.EventType.VariableSync, HandleVariable); + + if (LocalPlayerAuthority) + { + _writer = new QNetworkWriter(); + } + } + + public virtual void Start() + => _index = GetComponents().ToList().IndexOf(this); + + public override bool OnSerialize(QNetworkWriter writer, bool initialState) + { + if (!initialState) + { + if (SyncVarDirtyBits == 0U) + { + writer.WritePackedUInt32(0U); + return false; + } + + writer.WritePackedUInt32(1U); + } + + WriteData(writer); + return true; + } + + public override void OnDeserialize(QNetworkReader reader, bool initialState) + { + if (!IsServer || !QNetworkServer.localClientActive) + { + if (!initialState && reader.ReadPackedUInt32() == 0U) + { + return; + } + + ReadData(reader); + } + } + + private void FixedUpdate() + { + if (!IsServer || SyncVarDirtyBits != 0U || !QNetworkServer.active || !_ready) + { + return; + } + + if (GetNetworkSendInterval() != 0f) + { + SetDirtyBit(1U); + } + } + + public virtual void Update() + { + if (!HasAuthority || !LocalPlayerAuthority || QNetworkServer.active || !_ready) + { + return; + } + + if (Time.time - _lastClientSendTime > GetNetworkSendInterval()) + { + SendVariable(); + _lastClientSendTime = Time.time; + } + } + + [Client] + private void SendVariable() + { + // TODO - this sends a message, even when the value hasnt changed! this is really bad! + if (QClientScene.readyConnection != null) + { + _writer.StartMessage((short)QSB.Events.EventType.VariableSync); + _writer.Write(NetId); + _writer.Write(_index); + WriteData(_writer); + _writer.FinishMessage(); + QClientScene.readyConnection.SendWriter(_writer, GetNetworkChannel()); + } + } + + public static void HandleVariable(QNetworkMessage netMsg) + { + var networkInstanceId = netMsg.Reader.ReadNetworkId(); + var index = netMsg.Reader.ReadInt32(); + var gameObject = QNetworkServer.FindLocalObject(networkInstanceId); + var components = gameObject.GetComponents(); + components[index].ReadData(netMsg.Reader); + } + } +} diff --git a/QSB/Utility/VariableSync/BoolVariableSyncer.cs b/QSB/Utility/VariableSync/BoolVariableSyncer.cs new file mode 100644 index 00000000..58040b6b --- /dev/null +++ b/QSB/Utility/VariableSync/BoolVariableSyncer.cs @@ -0,0 +1,26 @@ +using QuantumUNET.Transport; +using System; + +namespace QSB.Utility.VariableSync +{ + public class BoolVariableSyncer : BaseVariableSyncer + { + public VariableReference ValueToSync { get; private set; } = new(); + + public void Init(Func getter, Action setter) + { + ValueToSync.Getter = getter; + ValueToSync.Setter = setter; + _ready = true; + } + + public void OnDestroy() + => _ready = false; + + public override void WriteData(QNetworkWriter writer) + => writer.Write(ValueToSync.Value); + + public override void ReadData(QNetworkReader writer) + => ValueToSync.Value = writer.ReadBoolean(); + } +} diff --git a/QSB/Utility/VariableSync/FloatVariableSyncer.cs b/QSB/Utility/VariableSync/FloatVariableSyncer.cs new file mode 100644 index 00000000..37cbe735 --- /dev/null +++ b/QSB/Utility/VariableSync/FloatVariableSyncer.cs @@ -0,0 +1,26 @@ +using QuantumUNET.Transport; +using System; + +namespace QSB.Utility.VariableSync +{ + public class FloatVariableSyncer : BaseVariableSyncer + { + public VariableReference ValueToSync { get; private set; } = new(); + + public void Init(Func getter, Action setter) + { + ValueToSync.Getter = getter; + ValueToSync.Setter = setter; + _ready = true; + } + + public void OnDestroy() + => _ready = false; + + public override void WriteData(QNetworkWriter writer) + => writer.Write(ValueToSync.Value); + + public override void ReadData(QNetworkReader writer) + => ValueToSync.Value = writer.ReadSingle(); + } +} diff --git a/QSB/Utility/VariableSync/VariableReference.cs b/QSB/Utility/VariableSync/VariableReference.cs new file mode 100644 index 00000000..cf2f6006 --- /dev/null +++ b/QSB/Utility/VariableSync/VariableReference.cs @@ -0,0 +1,46 @@ +using QSB.Player; +using QSB.Player.TransformSync; +using System; + +namespace QSB.Utility.VariableSync +{ + public class VariableReference + { + public Func Getter; + public Action Setter; + + public T Value + { + get + { + if (Getter != null) + { + return Getter(); + } + else + { + if (PlayerTransformSync.LocalInstance != null && QSBPlayerManager.LocalPlayer.IsReady) + { + DebugLog.ToConsole($"Warning - Getter is null!", OWML.Common.MessageType.Warning); + } + + return default; + } + } + set + { + if (Setter != null) + { + Setter(value); + } + else + { + if (PlayerTransformSync.LocalInstance != null && QSBPlayerManager.LocalPlayer.IsReady) + { + DebugLog.ToConsole($"Warning - Setter is null!", OWML.Common.MessageType.Warning); + } + } + } + } + } +} diff --git a/QSB/Utility/VariableSync/Vector3VariableSyncer.cs b/QSB/Utility/VariableSync/Vector3VariableSyncer.cs new file mode 100644 index 00000000..bc91b37b --- /dev/null +++ b/QSB/Utility/VariableSync/Vector3VariableSyncer.cs @@ -0,0 +1,27 @@ +using QuantumUNET.Transport; +using System; +using UnityEngine; + +namespace QSB.Utility.VariableSync +{ + public class Vector3VariableSyncer : BaseVariableSyncer + { + public VariableReference ValueToSync { get; private set; } = new(); + + public void Init(Func getter, Action setter) + { + ValueToSync.Getter = getter; + ValueToSync.Setter = setter; + _ready = true; + } + + public void OnDestroy() + => _ready = false; + + public override void WriteData(QNetworkWriter writer) + => writer.Write(ValueToSync.Value); + + public override void ReadData(QNetworkReader writer) + => ValueToSync.Value = writer.ReadVector3(); + } +} diff --git a/QSB/Utility/ZOverride.cs b/QSB/Utility/ZOverride.cs index 7109dbc4..19c93bb0 100644 --- a/QSB/Utility/ZOverride.cs +++ b/QSB/Utility/ZOverride.cs @@ -9,7 +9,7 @@ namespace QSB.Utility private const string shaderTestMode = "unity_GUIZTestMode"; private readonly UnityEngine.Rendering.CompareFunction desiredUIComparison = UnityEngine.Rendering.CompareFunction.Always; private Graphic[] uiElementsToApplyTo; - private readonly Dictionary materialMappings = new Dictionary(); + private readonly Dictionary materialMappings = new(); protected virtual void Start() { diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index a73c9df3..7f28ddb5 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -4,7 +4,6 @@ using QSB.OrbSync.WorldObjects; using QSB.Utility; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using UnityEngine; @@ -17,8 +16,8 @@ namespace QSB.WorldSync public static Dictionary DialogueConditions { get; } = new Dictionary(); public static List ShipLogFacts { get; } = new List(); - private static readonly List WorldObjects = new List(); - private static readonly Dictionary WorldObjectsToUnityObjects = new Dictionary(); + private static readonly List WorldObjects = new(); + private static readonly Dictionary WorldObjectsToUnityObjects = new(); public static IEnumerable GetWorldObjects() => WorldObjects.OfType(); @@ -34,9 +33,7 @@ namespace QSB.WorldSync return GetWorldObjects().ToList()[id]; } - public static TWorldObject GetWorldFromUnity(TUnityObject unityObject) - where TWorldObject : WorldObject - where TUnityObject : MonoBehaviour + public static IWorldObject GetWorldFromUnity(MonoBehaviour unityObject) { if (!WorldObjectManager.AllReady) { @@ -45,37 +42,73 @@ namespace QSB.WorldSync if (unityObject == null) { - DebugLog.ToConsole($"Error - Trying to run GetWorldFromUnity with a null unity object! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{typeof(TUnityObject).Name}", MessageType.Error); + DebugLog.ToConsole($"Error - Trying to run GetWorldFromUnity with a null unity object! TUnityObject:NULL", MessageType.Error); return default; } if (!QSBCore.IsInMultiplayer) { - DebugLog.ToConsole($"Warning - Trying to run GetWorldFromUnity while not in multiplayer! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{typeof(TUnityObject).Name}", MessageType.Warning); + DebugLog.ToConsole($"Warning - Trying to run GetWorldFromUnity while not in multiplayer! TUnityObject:{unityObject.GetType().Name}", MessageType.Warning); return default; } if (!WorldObjectsToUnityObjects.ContainsKey(unityObject)) { - DebugLog.ToConsole($"Error - WorldObjectsToUnityObjects does not contain \"{unityObject.name}\"! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{typeof(TUnityObject).Name}", MessageType.Error); + DebugLog.ToConsole($"Error - WorldObjectsToUnityObjects does not contain \"{unityObject.name}\"! TUnityObject:{unityObject.GetType().Name}", MessageType.Error); return default; } - var returnObject = WorldObjectsToUnityObjects[unityObject] as TWorldObject; + var returnObject = WorldObjectsToUnityObjects[unityObject]; - if (returnObject == default || returnObject == null) + if (returnObject == null) { - DebugLog.ToConsole($"Error - World object for unity object {unityObject.name} is null! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{typeof(TUnityObject).Name}", MessageType.Error); + DebugLog.ToConsole($"Error - World object for unity object {unityObject.name} is null! TUnityObject:{unityObject.GetType().Name}", MessageType.Error); return default; } return returnObject; } - public static int GetIdFromUnity(TUnityObject unityObject) - where TWorldObject : WorldObject - where TUnityObject : MonoBehaviour - => GetWorldFromUnity(unityObject).ObjectId; + public static TWorldObject GetWorldFromUnity(MonoBehaviour unityObject) + where TWorldObject : IWorldObject + { + if (!WorldObjectManager.AllReady) + { + return default; + } + + if (unityObject == null) + { + DebugLog.ToConsole($"Error - Trying to run GetWorldFromUnity with a null unity object! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:NULL", MessageType.Error); + return default; + } + + if (!QSBCore.IsInMultiplayer) + { + DebugLog.ToConsole($"Warning - Trying to run GetWorldFromUnity while not in multiplayer! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{unityObject.GetType().Name}", MessageType.Warning); + return default; + } + + if (!WorldObjectsToUnityObjects.ContainsKey(unityObject)) + { + DebugLog.ToConsole($"Error - WorldObjectsToUnityObjects does not contain \"{unityObject.name}\"! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{unityObject.GetType().Name}", MessageType.Error); + return default; + } + + var returnObject = (TWorldObject)WorldObjectsToUnityObjects[unityObject]; + + if (returnObject == null) + { + DebugLog.ToConsole($"Error - World object for unity object {unityObject.name} is null! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{unityObject.GetType().Name}", MessageType.Error); + return default; + } + + return returnObject; + } + + public static int GetIdFromUnity(MonoBehaviour unityObject) + where TWorldObject : IWorldObject + => GetWorldFromUnity(unityObject).ObjectId; public static int GetIdFromTypeSubset(TTypeSubset typeSubset) { @@ -119,12 +152,17 @@ namespace QSB.WorldSync WorldObjects.RemoveAll(x => x is TWorldObject); } - public static List Init() + public static IEnumerable GetUnityObjects() + where TUnityObject : MonoBehaviour + => Resources.FindObjectsOfTypeAll() + .Where(x => x.gameObject.scene.name != null); + + public static void Init() where TWorldObject : WorldObject where TUnityObject : MonoBehaviour { RemoveWorldObjects(); - var list = Resources.FindObjectsOfTypeAll().ToList(); + var list = GetUnityObjects().ToList(); //DebugLog.DebugWrite($"{typeof(TWorldObject).Name} init : {list.Count} instances.", MessageType.Info); for (var id = 0; id < list.Count; id++) { @@ -132,8 +170,6 @@ namespace QSB.WorldSync obj.Init(list[id], id); WorldObjectsToUnityObjects.Add(list[id], obj); } - - return list; } private static TWorldObject CreateWorldObject() @@ -210,4 +246,4 @@ namespace QSB.WorldSync }); } } -} \ No newline at end of file +} diff --git a/QSB/WorldSync/WorldObject.cs b/QSB/WorldSync/WorldObject.cs index 8c765d12..680c4e27 100644 --- a/QSB/WorldSync/WorldObject.cs +++ b/QSB/WorldSync/WorldObject.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using QSB.Player; +using UnityEngine; namespace QSB.WorldSync { @@ -8,10 +9,11 @@ namespace QSB.WorldSync public int ObjectId { get; protected set; } public T AttachedObject { get; protected set; } public string Name => AttachedObject == null ? "" : AttachedObject.name; + public string LogName => $"{QSBPlayerManager.LocalPlayerId}.{ObjectId}:{GetType().Name}"; public abstract void Init(T attachedObject, int id); public virtual void PostInit() { } public virtual void OnRemoval() { } public MonoBehaviour ReturnObject() => AttachedObject; } -} \ No newline at end of file +} diff --git a/QSB/WorldSync/WorldObjectManager.cs b/QSB/WorldSync/WorldObjectManager.cs index f5fbfb36..f619787b 100644 --- a/QSB/WorldSync/WorldObjectManager.cs +++ b/QSB/WorldSync/WorldObjectManager.cs @@ -8,7 +8,7 @@ namespace QSB.WorldSync { public abstract class WorldObjectManager : MonoBehaviour { - private static readonly List _managers = new List(); + private static readonly List _managers = new(); public static bool AllReady { get; private set; } @@ -44,13 +44,13 @@ namespace QSB.WorldSync return; } - if (QSBPlayerManager.LocalPlayer.PlayerStates.IsReady) + if (QSBPlayerManager.LocalPlayer.IsReady) { DoRebuild(scene); return; } - QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayer.PlayerStates.IsReady, () => DoRebuild(scene)); + QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayer.IsReady, () => DoRebuild(scene)); } private static void DoRebuild(OWScene scene) @@ -79,7 +79,7 @@ namespace QSB.WorldSync worldObject.PostInit(); } } - + protected abstract void RebuildWorldObjects(OWScene scene); } } diff --git a/QSB/app.config b/QSB/app.config deleted file mode 100644 index 2a4bf252..00000000 --- a/QSB/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/QSB/debugsettings.json b/QSB/debugsettings.json new file mode 100644 index 00000000..2ec19b85 --- /dev/null +++ b/QSB/debugsettings.json @@ -0,0 +1,8 @@ +{ + "debugMode": true, + "drawLines": true, + "showQuantumVisibilityObjects": false, + "showQuantumDebugBoxes": false, + "avoidTimeSync": true, + "skipTitleScreen": true +} \ No newline at end of file diff --git a/QSB/default-config.json b/QSB/default-config.json index ffe88285..c56d3d74 100644 --- a/QSB/default-config.json +++ b/QSB/default-config.json @@ -2,8 +2,6 @@ "enabled": true, "settings": { "defaultServerIP": "localhost", - "port": 7777, - "debugMode": false, - "showLinesInDebug": false + "port": 7777 } } \ No newline at end of file diff --git a/QSB/manifest.json b/QSB/manifest.json index 9d5f6878..79522f80 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -2,13 +2,12 @@ "filename": "QSB.dll", "author": "Nebula, Alek, & Rai", "name": "Quantum Space Buddies", - "description": "Adds online multiplayer to the game.", "warning": { "title": "Follow these steps before playing multiplayer :", "body": "- Disable *all* other mods. (Can heavily affect performance)\n- Make sure you are not running any other network-intensive applications.\n- Make sure you have forwarded/opened the correct ports. (See the GitHub readme.)" }, "uniqueName": "Raicuparta.QuantumSpaceBuddies", - "version": "0.12.2", + "version": "0.13.0", "owmlVersion": "2.1.0", "dependencies": [ "_nebula.MenuFramework" ] -} \ No newline at end of file +} diff --git a/QSBTests/PatchTests.cs b/QSBTests/PatchTests.cs index 26ece311..29d3ebdd 100644 --- a/QSBTests/PatchTests.cs +++ b/QSBTests/PatchTests.cs @@ -1,36 +1,41 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using QSB.Patches; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; namespace QSBTests { [TestClass] public class PatchTests { - //[TestMethod] - //public void CheckUnreferencedPatches() - //{ - // var qsbAssembly = Assembly.Load("QSB"); - // var allPatchTypes = qsbAssembly - // .GetTypes() - // .Where(x => typeof(QSBPatch).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); + [TestMethod] + public void CheckUnreferencedPatches() + { + var qsbAssembly = Assembly.Load("QSB"); + var allPatchTypes = qsbAssembly + .GetTypes() + .Where(x => typeof(QSBPatch).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); - // QSBPatchManager.Init(); - // var patchInstances = (List)typeof(QSBPatchManager) - // .GetField("_patchList", BindingFlags.NonPublic | BindingFlags.Static) - // .GetValue(typeof(QSBPatchManager)); + QSBPatchManager.Init(); + var patchInstances = (List)typeof(QSBPatchManager) + .GetField("_patchList", BindingFlags.NonPublic | BindingFlags.Static) + .GetValue(typeof(QSBPatchManager)); - // var failedTypes = new List(); - // foreach (var type in allPatchTypes) - // { - // if (!patchInstances.Any(x => x.GetType() == type)) - // { - // failedTypes.Add(type); - // } - // } + var failedTypes = new List(); + foreach (var type in allPatchTypes) + { + if (!patchInstances.Any(x => x.GetType() == type)) + { + failedTypes.Add(type); + } + } - // if (failedTypes.Count > 0) - // { - // Assert.Fail(string.Join(", ", failedTypes.Select(x => x.Name))); - // } - //} + if (failedTypes.Count > 0) + { + Assert.Fail(string.Join(", ", failedTypes.Select(x => x.Name))); + } + } } } diff --git a/QSBTests/Properties/AssemblyInfo.cs b/QSBTests/Properties/AssemblyInfo.cs deleted file mode 100644 index 52d585f2..00000000 --- a/QSBTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("QSBTests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("QSBTests")] -[assembly: AssemblyCopyright("Copyright © 2021")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("2fe8256c-0cb6-48f1-a4c0-5fa18a1846a3")] - -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/QSBTests/QSBTests.csproj b/QSBTests/QSBTests.csproj index 273e4303..ad94ca53 100644 --- a/QSBTests/QSBTests.csproj +++ b/QSBTests/QSBTests.csproj @@ -1,83 +1,30 @@ - - - - + - Debug - AnyCPU + QSBTests + QSBTests {2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3} - Library - Properties - QSBTests - QSBTests - v4.7.2 - 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages False UnitTest - - + dotnet test QSBTests.dll + bin\$(Configuration)\ - true full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - $(GameDir)\OuterWilds_Data\Managed\Assembly-CSharp.dll - - - ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - - - ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - - - - - - - - - - - - - - - - {1F00090A-C697-4C55-B401-192F3CFB9DC2} - QSB - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - dotnet test "$(SolutionDir)\QSBTests\$(OutDir)\QSBTests.dll" - + + + + + + + + + \ No newline at end of file diff --git a/QSBTests/QSBTests.csproj.user b/QSBTests/QSBTests.csproj.user deleted file mode 100644 index 3f79bad7..00000000 --- a/QSBTests/QSBTests.csproj.user +++ /dev/null @@ -1,8 +0,0 @@ - - - - D:\SteamLibrary\steamapps\common\Outer Wilds - C:\Users\Henry\AppData\Roaming\OuterWildsModManager\OWML - ShowAllFiles - - \ No newline at end of file diff --git a/QSBTests/app.config b/QSBTests/app.config deleted file mode 100644 index 2a4bf252..00000000 --- a/QSBTests/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/QSBTests/packages.config b/QSBTests/packages.config deleted file mode 100644 index 2f7c5a18..00000000 --- a/QSBTests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/QuantumUNET/Components/QNetworkAnimator.cs b/QuantumUNET/Components/QNetworkAnimator.cs index 81098030..5b4fb046 100644 --- a/QuantumUNET/Components/QNetworkAnimator.cs +++ b/QuantumUNET/Components/QNetworkAnimator.cs @@ -6,9 +6,9 @@ namespace QuantumUNET.Components { public class QNetworkAnimator : QNetworkBehaviour { - private static readonly QAnimationMessage AnimationMessage = new QAnimationMessage(); - private static readonly QAnimationParametersMessage ParametersMessage = new QAnimationParametersMessage(); - private static readonly QAnimationTriggerMessage TriggersMessage = new QAnimationTriggerMessage(); + private static readonly QAnimationMessage AnimationMessage = new(); + private static readonly QAnimationParametersMessage ParametersMessage = new(); + private static readonly QAnimationTriggerMessage TriggersMessage = new(); private Animator m_Animator; private uint m_ParameterSendBits; diff --git a/QuantumUNET/Components/QNetworkIdentity.cs b/QuantumUNET/Components/QNetworkIdentity.cs index 040e5905..08c4097f 100644 --- a/QuantumUNET/Components/QNetworkIdentity.cs +++ b/QuantumUNET/Components/QNetworkIdentity.cs @@ -99,22 +99,7 @@ namespace QuantumUNET.Components } public ReadOnlyCollection Observers - { - get - { - ReadOnlyCollection result; - if (m_Observers == null) - { - result = null; - } - else - { - result = new ReadOnlyCollection(m_Observers); - } - - return result; - } - } + => m_Observers == null ? null : new ReadOnlyCollection(m_Observers); internal static NetworkInstanceId GetNextNetworkId() { @@ -187,14 +172,7 @@ namespace QuantumUNET.Components if (!m_IsServer) { m_IsServer = true; - if (m_LocalPlayerAuthority) - { - HasAuthority = false; - } - else - { - HasAuthority = true; - } + HasAuthority = !m_LocalPlayerAuthority; m_Observers = new List(); m_ObserverConnections = new HashSet(); @@ -841,7 +819,7 @@ namespace QuantumUNET.Components private static uint s_NextNetworkId = 1U; - private static readonly QNetworkWriter s_UpdateWriter = new QNetworkWriter(); + private static readonly QNetworkWriter s_UpdateWriter = new(); public static ClientAuthorityCallback clientAuthorityCallback; diff --git a/QuantumUNET/Components/QNetworkManager.cs b/QuantumUNET/Components/QNetworkManager.cs index 73a6c6d1..5196e6d5 100644 --- a/QuantumUNET/Components/QNetworkManager.cs +++ b/QuantumUNET/Components/QNetworkManager.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; -using UnityEngine.SceneManagement; namespace QuantumUNET.Components { @@ -34,9 +33,9 @@ namespace QuantumUNET.Components private GlobalConfig m_GlobalConfig; private readonly int m_MaxBufferedPackets = 16; private readonly bool m_AllowFragmentation = true; - private static readonly QAddPlayerMessage s_AddPlayerMessage = new QAddPlayerMessage(); - private static readonly QRemovePlayerMessage s_RemovePlayerMessage = new QRemovePlayerMessage(); - private static readonly QErrorMessage s_ErrorMessage = new QErrorMessage(); + private static readonly QAddPlayerMessage s_AddPlayerMessage = new(); + private static readonly QRemovePlayerMessage s_RemovePlayerMessage = new(); + private static readonly QErrorMessage s_ErrorMessage = new(); private static AsyncOperation s_LoadingSceneAsync; private static QNetworkConnection s_ClientReadyConnection; private static string s_Address; @@ -449,7 +448,6 @@ namespace QuantumUNET.Components { QLog.Log("NetworkManager:OnClientConnectInternal"); netMsg.Connection.SetMaxDelay(maxDelay); - var name = SceneManager.GetSceneAt(0).name; clientLoadedScene = false; OnClientConnect(netMsg.Connection); } diff --git a/QuantumUNET/Components/QNetworkTransform.cs b/QuantumUNET/Components/QNetworkTransform.cs index 622d78a7..21cb794c 100644 --- a/QuantumUNET/Components/QNetworkTransform.cs +++ b/QuantumUNET/Components/QNetworkTransform.cs @@ -206,4 +206,4 @@ namespace QuantumUNET.Components public override float GetNetworkSendInterval() => SendInterval; } -} \ No newline at end of file +} diff --git a/QuantumUNET/Messages/QMsgType.cs b/QuantumUNET/Messages/QMsgType.cs index bbe5ae91..e3e3b367 100644 --- a/QuantumUNET/Messages/QMsgType.cs +++ b/QuantumUNET/Messages/QMsgType.cs @@ -5,7 +5,7 @@ public static string MsgTypeToString(short value) { string result; - if (value < 0 || value > 48) + if (value is < 0 or > 48) { result = string.Empty; } diff --git a/QuantumUNET/Properties/AssemblyInfo.cs b/QuantumUNET/Properties/AssemblyInfo.cs deleted file mode 100644 index ea4d460c..00000000 --- a/QuantumUNET/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("QuantumUNET")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("HP Inc.")] -[assembly: AssemblyProduct("QuantumUNET")] -[assembly: AssemblyCopyright("Copyright © HP Inc. 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("c8c53004-1508-4f86-a419-4292c188dc2a")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/QuantumUNET/QClientScene.cs b/QuantumUNET/QClientScene.cs index 7ae26289..02cf7148 100644 --- a/QuantumUNET/QClientScene.cs +++ b/QuantumUNET/QClientScene.cs @@ -246,7 +246,7 @@ namespace QuantumUNET { if (!networkIdentity.gameObject.activeSelf) { - if (networkIdentity.gameObject.hideFlags != HideFlags.NotEditable && networkIdentity.gameObject.hideFlags != HideFlags.HideAndDontSave) + if (networkIdentity.gameObject.hideFlags is not HideFlags.NotEditable and not HideFlags.HideAndDontSave) { if (!networkIdentity.SceneId.IsEmpty()) { @@ -656,25 +656,25 @@ namespace QuantumUNET private static bool s_IsSpawnFinished; - private static readonly QNetworkScene s_NetworkScene = new QNetworkScene(); + private static readonly QNetworkScene s_NetworkScene = new(); - private static readonly QObjectSpawnSceneMessage s_ObjectSpawnSceneMessage = new QObjectSpawnSceneMessage(); + private static readonly QObjectSpawnSceneMessage s_ObjectSpawnSceneMessage = new(); - private static readonly QObjectSpawnFinishedMessage s_ObjectSpawnFinishedMessage = new QObjectSpawnFinishedMessage(); + private static readonly QObjectSpawnFinishedMessage s_ObjectSpawnFinishedMessage = new(); - private static readonly QObjectDestroyMessage s_ObjectDestroyMessage = new QObjectDestroyMessage(); + private static readonly QObjectDestroyMessage s_ObjectDestroyMessage = new(); - private static readonly QObjectSpawnMessage s_ObjectSpawnMessage = new QObjectSpawnMessage(); + private static readonly QObjectSpawnMessage s_ObjectSpawnMessage = new(); - private static readonly QOwnerMessage s_OwnerMessage = new QOwnerMessage(); + private static readonly QOwnerMessage s_OwnerMessage = new(); - private static readonly QClientAuthorityMessage s_ClientAuthorityMessage = new QClientAuthorityMessage(); + private static readonly QClientAuthorityMessage s_ClientAuthorityMessage = new(); public const int ReconnectIdInvalid = -1; public const int ReconnectIdHost = 0; - private static List s_PendingOwnerIds = new List(); + private static List s_PendingOwnerIds = new(); private struct PendingOwner { diff --git a/QuantumUNET/QLocalClient.cs b/QuantumUNET/QLocalClient.cs index f9fb0322..63882036 100644 --- a/QuantumUNET/QLocalClient.cs +++ b/QuantumUNET/QLocalClient.cs @@ -130,9 +130,9 @@ namespace QuantumUNET private const int k_InitialFreeMessagePoolSize = 64; - private List m_InternalMsgs = new List(); + private List m_InternalMsgs = new(); - private readonly List m_InternalMsgs2 = new List(); + private readonly List m_InternalMsgs2 = new(); private Stack m_FreeMessages; @@ -140,7 +140,7 @@ namespace QuantumUNET private bool m_Connected; - private readonly QNetworkMessage s_InternalMessage = new QNetworkMessage(); + private readonly QNetworkMessage s_InternalMessage = new(); private struct InternalMsg { diff --git a/QuantumUNET/QNetworkBehaviour.cs b/QuantumUNET/QNetworkBehaviour.cs index 10e383ae..d3db0580 100644 --- a/QuantumUNET/QNetworkBehaviour.cs +++ b/QuantumUNET/QNetworkBehaviour.cs @@ -573,7 +573,7 @@ namespace QuantumUNET private float m_LastSendTime; private QNetworkIdentity m_MyView; - private static readonly Dictionary s_CmdHandlerDelegates = new Dictionary(); + private static readonly Dictionary s_CmdHandlerDelegates = new(); public delegate void CmdDelegate(QNetworkBehaviour obj, QNetworkReader reader); diff --git a/QuantumUNET/QNetworkClient.cs b/QuantumUNET/QNetworkClient.cs index 2bae1a80..4338e843 100644 --- a/QuantumUNET/QNetworkClient.cs +++ b/QuantumUNET/QNetworkClient.cs @@ -56,8 +56,8 @@ namespace QuantumUNET private int m_HostPort; private int m_ClientConnectionId = -1; private int m_StatResetTime; - private static readonly QCRCMessage s_CRCMessage = new QCRCMessage(); - private readonly QNetworkMessageHandlers m_MessageHandlers = new QNetworkMessageHandlers(); + private static readonly QCRCMessage s_CRCMessage = new(); + private readonly QNetworkMessageHandlers m_MessageHandlers = new(); protected QNetworkConnection m_Connection; private readonly byte[] m_MsgBuffer; private readonly NetworkReader m_MsgReader; @@ -102,7 +102,7 @@ namespace QuantumUNET } private static bool IsValidIpV6(string address) => - address.All(c => c == ':' || (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); + address.All(c => c is ':' or (>= '0' and <= '9') or (>= 'a' and <= 'f') or (>= 'A' and <= 'F')); public void Connect(string serverIp, int serverPort) { diff --git a/QuantumUNET/QNetworkConnection.cs b/QuantumUNET/QNetworkConnection.cs index a7cbfaa2..8ac69664 100644 --- a/QuantumUNET/QNetworkConnection.cs +++ b/QuantumUNET/QNetworkConnection.cs @@ -44,7 +44,7 @@ namespace QuantumUNET { var channelQOS = hostTopology.DefaultConfig.Channels[i]; var bufferSize = packetSize; - if (channelQOS.QOS == QosType.ReliableFragmented || channelQOS.QOS == QosType.UnreliableFragmented) + if (channelQOS.QOS is QosType.ReliableFragmented or QosType.UnreliableFragmented) { bufferSize = hostTopology.DefaultConfig.FragmentSize * 128; } @@ -91,9 +91,9 @@ namespace QuantumUNET m_Disposed = true; } - private static bool IsSequencedQoS(QosType qos) => qos == QosType.ReliableSequenced || qos == QosType.UnreliableSequenced; + private static bool IsSequencedQoS(QosType qos) => qos is QosType.ReliableSequenced or QosType.UnreliableSequenced; - private static bool IsReliableQoS(QosType qos) => qos == QosType.Reliable || qos == QosType.ReliableFragmented || qos == QosType.ReliableSequenced || qos == QosType.ReliableStateUpdate; + private static bool IsReliableQoS(QosType qos) => qos is QosType.Reliable or QosType.ReliableFragmented or QosType.ReliableSequenced or QosType.ReliableStateUpdate; public bool SetChannelOption(int channelId, ChannelOption option, int value) => m_Channels != null && channelId >= 0 && channelId < m_Channels.Length && m_Channels[channelId].SetOption(option, value); @@ -397,13 +397,13 @@ namespace QuantumUNET internal static void OnFragment(QNetworkMessage netMsg) => netMsg.Connection.HandleFragment(netMsg.Reader, netMsg.ChannelId); private QChannelBuffer[] m_Channels; - private readonly QNetworkMessage m_NetMsg = new QNetworkMessage(); + private readonly QNetworkMessage m_NetMsg = new(); private QNetworkWriter m_Writer; private Dictionary m_MessageHandlersDict; private QNetworkMessageHandlers m_MessageHandlers; - private readonly QNetworkMessage m_MessageInfo = new QNetworkMessage(); + private readonly QNetworkMessage m_MessageInfo = new(); private const int k_MaxMessageLogSize = 150; public int hostId = -1; diff --git a/QuantumUNET/QNetworkMessageHandlers.cs b/QuantumUNET/QNetworkMessageHandlers.cs index 57da6c75..1d98a4a1 100644 --- a/QuantumUNET/QNetworkMessageHandlers.cs +++ b/QuantumUNET/QNetworkMessageHandlers.cs @@ -6,7 +6,7 @@ namespace QuantumUNET { internal class QNetworkMessageHandlers { - private readonly Dictionary _msgHandlers = new Dictionary(); + private readonly Dictionary _msgHandlers = new(); internal void RegisterHandlerSafe(short msgType, QNetworkMessageDelegate handler) { diff --git a/QuantumUNET/QNetworkServer.cs b/QuantumUNET/QNetworkServer.cs index 951216cc..b2c901dc 100644 --- a/QuantumUNET/QNetworkServer.cs +++ b/QuantumUNET/QNetworkServer.cs @@ -38,7 +38,7 @@ namespace QuantumUNET public static bool dontListen { get; set; } - internal static QNetworkServer instance + public static QNetworkServer instance { get { @@ -1340,7 +1340,7 @@ namespace QuantumUNET private bool m_LocalClientActive; - private readonly List m_LocalConnectionsFakeList = new List(); + private readonly List m_LocalConnectionsFakeList = new(); private QULocalConnectionToClient m_LocalConnection; @@ -1348,7 +1348,7 @@ namespace QuantumUNET private readonly HashSet m_ExternalConnections; - private readonly ServerSimpleWrapper m_SimpleServerSimple; + public readonly ServerSimpleWrapper m_SimpleServerSimple; private float m_MaxDelay = 0.1f; @@ -1360,9 +1360,9 @@ namespace QuantumUNET internal static ushort maxPacketSize; - private static readonly QRemovePlayerMessage s_RemovePlayerMessage = new QRemovePlayerMessage(); + private static readonly QRemovePlayerMessage s_RemovePlayerMessage = new(); - private class ServerSimpleWrapper : QNetworkServerSimple + public class ServerSimpleWrapper : QNetworkServerSimple { public ServerSimpleWrapper(QNetworkServer server) => m_Server = server; diff --git a/QuantumUNET/QNetworkServerSimple.cs b/QuantumUNET/QNetworkServerSimple.cs index e3a44be9..905c9d7b 100644 --- a/QuantumUNET/QNetworkServerSimple.cs +++ b/QuantumUNET/QNetworkServerSimple.cs @@ -106,7 +106,7 @@ namespace QuantumUNET serverHostId = -1; } - internal void RegisterHandlerSafe(short msgType, QNetworkMessageDelegate handler) + public void RegisterHandlerSafe(short msgType, QNetworkMessageDelegate handler) => m_MessageHandlers.RegisterHandlerSafe(msgType, handler); public void RegisterHandler(short msgType, QNetworkMessageDelegate handler) @@ -361,7 +361,7 @@ namespace QuantumUNET private bool m_Initialized; private int m_RelaySlotId = -1; - private readonly List m_Connections = new List(); - private readonly QNetworkMessageHandlers m_MessageHandlers = new QNetworkMessageHandlers(); + private readonly List m_Connections = new(); + private readonly QNetworkMessageHandlers m_MessageHandlers = new(); } } \ No newline at end of file diff --git a/QuantumUNET/QuantumUNET.csproj b/QuantumUNET/QuantumUNET.csproj index 74f0f29a..d6bfcaa0 100644 --- a/QuantumUNET/QuantumUNET.csproj +++ b/QuantumUNET/QuantumUNET.csproj @@ -1,131 +1,22 @@ - - - + - Debug - AnyCPU + QuantumUNET + QuantumUNET {C8C53004-1508-4F86-A419-4292C188DC2A} - Library - Properties - QuantumUNET - QuantumUNET - v3.5 - 512 - true + OnBuildSuccess - true full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - OnBuildSuccess - - - + - - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.AnimationModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.CoreModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.IMGUIModule.dll - - - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.Networking.dll - - + + ..\QSB\lib\UnityEngine.Networking.dll False - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.PhysicsModule.dll - - - False - $(GameDir)\OuterWilds_Data\Managed\UnityEngine.UNETModule.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 9.0.1 - - - 1.2.0.1 - - - - - md "$(OwmlDir)\Mods\QSB" - -copy /y "$(TargetPath)" "$(OwmlDir)\Mods\QSB" - \ No newline at end of file diff --git a/QuantumUNET/QuantumUNET.csproj.user b/QuantumUNET/QuantumUNET.csproj.user deleted file mode 100644 index c8a11e84..00000000 --- a/QuantumUNET/QuantumUNET.csproj.user +++ /dev/null @@ -1,8 +0,0 @@ - - - - D:\EpicGames\OuterWilds - C:\Users\Henry\AppData\Roaming\OuterWildsModManager\OWML - ShowAllFiles - - \ No newline at end of file diff --git a/QuantumUNET/Transport/QChannelBuffer.cs b/QuantumUNET/Transport/QChannelBuffer.cs index 6b69327b..9e2a2258 100644 --- a/QuantumUNET/Transport/QChannelBuffer.cs +++ b/QuantumUNET/Transport/QChannelBuffer.cs @@ -33,11 +33,11 @@ namespace QuantumUNET.Transport private static List _freePackets; internal static int _pendingPacketCount; private float _lastBufferedMessageCountTimer = Time.realtimeSinceStartup; - private static readonly QNetworkWriter _sendWriter = new QNetworkWriter(); - private static readonly QNetworkWriter _fragmentWriter = new QNetworkWriter(); + private static readonly QNetworkWriter _sendWriter = new(); + private static readonly QNetworkWriter _fragmentWriter = new(); private const int _packetHeaderReserveSize = 100; private bool _disposed; - internal QNetBuffer _fragmentBuffer = new QNetBuffer(); + internal QNetBuffer _fragmentBuffer = new(); private bool _readingFragment; public QChannelBuffer(QNetworkConnection conn, int bufferSize, byte cid, bool isReliable, bool isSequenced) @@ -132,7 +132,7 @@ namespace QuantumUNET.Transport { result = false; } - else if (value < 0 || value >= 512) + else if (value is < 0 or >= 512) { Debug.LogError( $"Invalid MaxPendingBuffers for channel {_channelId}. Must be greater than zero and less than {512}"); diff --git a/QuantumUNET/Transport/QNetBuffer.cs b/QuantumUNET/Transport/QNetBuffer.cs index 309286a3..a07a80d1 100644 --- a/QuantumUNET/Transport/QNetBuffer.cs +++ b/QuantumUNET/Transport/QNetBuffer.cs @@ -39,7 +39,7 @@ namespace QuantumUNET.Transport Position += count; } - internal ArraySegment AsArraySegment() => new ArraySegment(m_Buffer, 0, (int)Position); + internal ArraySegment AsArraySegment() => new(m_Buffer, 0, (int)Position); public void WriteByte(byte value) { diff --git a/QuantumUNET/Transport/QNetworkReader.cs b/QuantumUNET/Transport/QNetworkReader.cs index b86ad950..ea2071b8 100644 --- a/QuantumUNET/Transport/QNetworkReader.cs +++ b/QuantumUNET/Transport/QNetworkReader.cs @@ -53,16 +53,16 @@ namespace QuantumUNET.Transport else { var b2 = ReadByte(); - if (b >= 241 && b <= 248) + if (b is >= 241 and <= 248) { - result = 240U + 256U * (uint)(b - 241) + b2; + result = 240U + (256U * (uint)(b - 241)) + b2; } else { var b3 = ReadByte(); if (b == 249) { - result = 2288U + 256U * b2 + b3; + result = 2288U + (256U * b2) + b3; } else { @@ -99,16 +99,16 @@ namespace QuantumUNET.Transport else { var b2 = ReadByte(); - if (b >= 241 && b <= 248) + if (b is >= 241 and <= 248) { - result = 240UL + 256UL * (b - 241UL) + b2; + result = 240UL + (256UL * (b - 241UL)) + b2; } else { var b3 = ReadByte(); if (b == 249) { - result = 2288UL + 256UL * b2 + b3; + result = 2288UL + (256UL * b2) + b3; } else { @@ -166,9 +166,9 @@ namespace QuantumUNET.Transport return result; } - public NetworkInstanceId ReadNetworkId() => new NetworkInstanceId(ReadPackedUInt32()); + public NetworkInstanceId ReadNetworkId() => new(ReadPackedUInt32()); - public NetworkSceneId ReadSceneId() => new NetworkSceneId(ReadPackedUInt32()); + public NetworkSceneId ReadSceneId() => new(ReadPackedUInt32()); public byte ReadByte() => m_buf.ReadByte(); @@ -245,7 +245,7 @@ namespace QuantumUNET.Transport } public decimal ReadDecimal() => - new decimal(new[] + new(new[] { ReadInt32(), ReadInt32(), @@ -319,25 +319,25 @@ namespace QuantumUNET.Transport return num == 0 ? new byte[0] : ReadBytes(num); } - public Vector2 ReadVector2() => new Vector2(ReadSingle(), ReadSingle()); + public Vector2 ReadVector2() => new(ReadSingle(), ReadSingle()); - public Vector3 ReadVector3() => new Vector3(ReadSingle(), ReadSingle(), ReadSingle()); + public Vector3 ReadVector3() => new(ReadSingle(), ReadSingle(), ReadSingle()); - public Vector4 ReadVector4() => new Vector4(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); + public Vector4 ReadVector4() => new(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); - public Color ReadColor() => new Color(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); + public Color ReadColor() => new(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); - public Color32 ReadColor32() => new Color32(ReadByte(), ReadByte(), ReadByte(), ReadByte()); + public Color32 ReadColor32() => new(ReadByte(), ReadByte(), ReadByte(), ReadByte()); - public Quaternion ReadQuaternion() => new Quaternion(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); + public Quaternion ReadQuaternion() => new(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); - public Rect ReadRect() => new Rect(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); + public Rect ReadRect() => new(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); - public Plane ReadPlane() => new Plane(ReadVector3(), ReadSingle()); + public Plane ReadPlane() => new(ReadVector3(), ReadSingle()); - public Ray ReadRay() => new Ray(ReadVector3(), ReadVector3()); + public Ray ReadRay() => new(ReadVector3(), ReadVector3()); - public Matrix4x4 ReadMatrix4x4() => new Matrix4x4 + public Matrix4x4 ReadMatrix4x4() => new() { m00 = ReadSingle(), m01 = ReadSingle(), diff --git a/QuantumUNET/Transport/QNetworkWriter.cs b/QuantumUNET/Transport/QNetworkWriter.cs index 875e6421..745687c2 100644 --- a/QuantumUNET/Transport/QNetworkWriter.cs +++ b/QuantumUNET/Transport/QNetworkWriter.cs @@ -50,7 +50,7 @@ namespace QuantumUNET.Transport } else if (value <= 2287U) { - Write((byte)((value - 240U) / 256U + 241U)); + Write((byte)(((value - 240U) / 256U) + 241U)); Write((byte)((value - 240U) % 256U)); } else if (value <= 67823U) @@ -84,7 +84,7 @@ namespace QuantumUNET.Transport } else if (value <= 2287UL) { - Write((byte)((value - 240UL) / 256UL + 241UL)); + Write((byte)(((value - 240UL) / 256UL) + 241UL)); Write((byte)((value - 240UL) % 256UL)); } else if (value <= 67823UL) diff --git a/README.md b/README.md index 8a16bd69..1dfb0fdd 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ QSB relies on exact orders of objects found using Resources.FindObjectsOfTypeAll | System / Mechanic | Synced? | | :---: | :---: | -| Anglerfish | No | -| Brittle Hollow fragments | No | +| Anglerfish | Yes | +| Brittle Hollow fragments | Yes | | Campfires | Yes | | Conversations with NPCs | Yes | | Discovering signals/frequencies | Yes | @@ -78,7 +78,7 @@ QSB relies on exact orders of objects found using Resources.FindObjectsOfTypeAll | Items | Yes | | Jellyfish | No | | Marshmallow roasting | Yes | -| Meteors | No | +| Meteors | Yes | | Museum statue | Yes | | NPC animations | Yes | | Nomai orbs | Yes | @@ -91,10 +91,10 @@ QSB relies on exact orders of objects found using Resources.FindObjectsOfTypeAll | Quantum objects | Yes | | Repairing ship parts | Yes | | Repairing "satellite" parts | No | -| Ship | Kinda of | +| Ship | Yes | | Ship log | Yes | -| Solanum | No | -| Timber Hearth satellite | No | +| Solanum | Yes | +| Timber Hearth satellite | Yes | | Tornadoes | No | QSB also changes some mechanics of the base game, to better fit a multiplayer experience. These include : @@ -137,19 +137,15 @@ Note - _nebula has no idea how Hamachi works and has never used it, so don't ask ## Playing as a client - Run the game. -- You'll see some new buttons on the top left. -- Replace `localhost` with the server's public IP address. -- Press "Connect". You can join servers in the menu or in-game, but it is recommended to join in the main menu. -- If you see "Stop", you are connected. -- If it stops at "Connecting to..." then you or the host has issues with their firewall/router/other. +- On the title/pause menu, select "MULTIPLAYER (CONNECT)". +- Enter the public IP address of the host. +- Hit connect, and pray. ## Playing as a host - Open port `7777` on your router. - Run the game. -- You'll see some new buttons on the top left. -- Press "Host". This can be done in-game or in the menu, but it is recommened to start servers in the menu. -- If you now see the "Stop" button, you are hosting. +- On the title/pause menu, select "MULTIPLAYER (HOST)". - Give your external IPv4 address to your clients ([like what you see here](http://whatismyip.host/)). ## Development Setup @@ -157,13 +153,13 @@ Note - _nebula has no idea how Hamachi works and has never used it, so don't ask - [Download the Outer Wilds Mod Manager](https://github.com/raicuparta/ow-mod-manager) and install it anywhere you like; - Install OWML using the Mod Manager - Clone QSB's source -- Open the file `QSB/QSB.csproj.user` in your favorite text editor +- Open the file `Directory.Build.targets` in your favorite text editor - Edit the entry `` to point to the directory where Outer Wilds is installed - Edit the entry `` to point to your OWML directory (it is installed inside the Mod Manager directory) -- Do the same for QuantumUNET/QuantumUNET.csproj.user - Open the project solution file `QSB.sln` in Visual Studio - If needed, right click `References` in the Solution Explorer > Manage NuGet Packages > Update OWML to fix missing references -- Run this to stop tracking QSB.csproj.user: ```git update-index --skip-worktree QSB/QSB.csproj.user``` + - Use [this](https://github.com/MrPurple6411/AssemblyPublicizer) to create `Assembly-CSharp_publicized.dll`, if you don't already have it +- Run this to stop tracking Director.Build.targets: ```git update-index --skip-worktree Directory.Build.targets``` To fix the references, right click "References" in the Solution Explorer > "Add Reference", and add all the missing DLLs (references with yellow warning icon). You can find these DLLs in the game's directory (`OuterWilds\OuterWilds_Data\Managed`); @@ -203,13 +199,22 @@ It is also recommended to lower all graphics settings to minimum, be in windowed ## Authors and Special Thanks +### Authors + - [\_nebula](https://github.com/misternebula) - Developer of v0.3 onwards - [AmazingAlek](https://github.com/amazingalek) - On-and-off developer and sometimes code tidy-er - [Raicuparta](https://github.com/Raicuparta) - Developer of v0.1 - v0.2 + +### Contributers + +- [ShoosGun](https://github.com/ShoosGun) +- [Chris Yeninas](https://github.com/PhantomGamers) + +### Special Thanks - Thanks to Logan Ver Hoef for help with the game code. - Thanks to all the people in the Outer Wilds Discord for helping in public tests. - Special thanks (and apologies) to all the people in the #modding channel, which I (_nebula) have been using as a virtual [rubber duck.](https://en.wikipedia.org/wiki/Rubber_duck_debugging) ## Help / Discuss development / Whatever -[Join the unofficial Outer Wilds Discord](https://discord.gg/Sftcc9Z), we have a nice `#modding` channel where you can discuss all types of things. +[Join the unofficial Outer Wilds Discord](https://discord.gg/Sftcc9Z), we have a nice `#modding-support` channel for any mod help, and a `#modding` channel to discuss modding! diff --git a/UnityEngine.Networking.dll b/UnityEngine.Networking.dll deleted file mode 100644 index 4db9ce9d..00000000 Binary files a/UnityEngine.Networking.dll and /dev/null differ diff --git a/UnityProject/.gitignore b/UnityProject/.gitignore deleted file mode 100644 index cf1bcb71..00000000 --- a/UnityProject/.gitignore +++ /dev/null @@ -1,63 +0,0 @@ -# This .gitignore file should be placed at the root of your Unity project directory -# -# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore -# -/[Ll]ibrary/ -/[Tt]emp/ -/[Oo]bj/ -/[Bb]uild/ -/[Bb]uilds/ -/[Ll]ogs/ -/[Uu]ser[Ss]ettings/ - -# MemoryCaptures can get excessive in size. -# They also could contain extremely sensitive data -/[Mm]emoryCaptures/ - -# Asset meta data should only be ignored when the corresponding asset is also ignored -!/[Aa]ssets/**/*.meta - -# Uncomment this line if you wish to ignore the asset store tools plugin -# /[Aa]ssets/AssetStoreTools* - -# Autogenerated Jetbrains Rider plugin -/[Aa]ssets/Plugins/Editor/JetBrains* - -# Visual Studio cache directory -.vs/ - -# Gradle cache directory -.gradle/ - -# Autogenerated VS/MD/Consulo solution and project files -ExportedObj/ -.consulo/ -*.csproj -*.unityproj -*.sln -*.suo -*.tmp -*.user -*.userprefs -*.pidb -*.booproj -*.svd -*.pdb -*.mdb -*.opendb -*.VC.db - -# Unity3D generated meta files -*.pidb.meta -*.pdb.meta -*.mdb.meta - -# Unity3D generated file on crash reports -sysinfo.txt - -# Builds -*.apk -*.unitypackage - -# Crashlytics generated file -crashlytics-build.properties diff --git a/UnityProject/Assets/Capsule.prefab b/UnityProject/Assets/Capsule.prefab deleted file mode 100644 index 4f6d7f89..00000000 --- a/UnityProject/Assets/Capsule.prefab +++ /dev/null @@ -1,81 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &158443016395961829 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 8824963426012170043} - - component: {fileID: 2763613722105978426} - - component: {fileID: 308561794084866108} - m_Layer: 0 - m_Name: Capsule - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &8824963426012170043 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 158443016395961829} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!33 &2763613722105978426 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 158443016395961829} - m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &308561794084866108 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 158443016395961829} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 3f581bc765fd2dd4e8e2a6f19d1c5a54, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 diff --git a/UnityProject/Assets/Capsule.prefab.meta b/UnityProject/Assets/Capsule.prefab.meta deleted file mode 100644 index 5b7cc6fc..00000000 --- a/UnityProject/Assets/Capsule.prefab.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 3c3ea1522189f70449edb225a0432847 -PrefabImporter: - externalObjects: {} - userData: - assetBundleName: debug - assetBundleVariant: diff --git a/UnityProject/Assets/Cube.prefab b/UnityProject/Assets/Cube.prefab deleted file mode 100644 index 035b5436..00000000 --- a/UnityProject/Assets/Cube.prefab +++ /dev/null @@ -1,81 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &2878217370054538106 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 3260343914971232886} - - component: {fileID: 7886282064430510966} - - component: {fileID: 5552009110269121987} - m_Layer: 0 - m_Name: Cube - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &3260343914971232886 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2878217370054538106} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!33 &7886282064430510966 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2878217370054538106} - m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &5552009110269121987 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2878217370054538106} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 3f581bc765fd2dd4e8e2a6f19d1c5a54, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 diff --git a/UnityProject/Assets/Cube.prefab.meta b/UnityProject/Assets/Cube.prefab.meta deleted file mode 100644 index 02418c16..00000000 --- a/UnityProject/Assets/Cube.prefab.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 80b35e10573debc4bb73dd392a3147c4 -PrefabImporter: - externalObjects: {} - userData: - assetBundleName: debug - assetBundleVariant: diff --git a/UnityProject/Assets/DebugVis.mat b/UnityProject/Assets/DebugVis.mat deleted file mode 100644 index 78da8673..00000000 --- a/UnityProject/Assets/DebugVis.mat +++ /dev/null @@ -1,77 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!21 &2100000 -Material: - serializedVersion: 6 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: DebugVis - m_Shader: {fileID: 4800000, guid: 9ec76f18fccbe654a850002455808200, type: 3} - m_ShaderKeywords: _ALPHAPREMULTIPLY_ON - m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _BumpMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailAlbedoMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailMask: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailNormalMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _EmissionMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MainTex: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MetallicGlossMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _OcclusionMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _ParallaxMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - m_Floats: - - _BumpScale: 1 - - _Cutoff: 0.172 - - _DetailNormalMapScale: 1 - - _DstBlend: 10 - - _GlossMapScale: 1 - - _Glossiness: 0 - - _GlossyReflections: 1 - - _Metallic: 0 - - _Mode: 3 - - _OcclusionStrength: 1 - - _Parallax: 0.02 - - _SmoothnessTextureChannel: 0 - - _SpecularHighlights: 1 - - _SrcBlend: 1 - - _UVSec: 0 - - _ZWrite: 0 - m_Colors: - - _Color: {r: 1, g: 0.51526886, b: 0, a: 0.05882353} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/UnityProject/Assets/DebugVis.mat.meta b/UnityProject/Assets/DebugVis.mat.meta deleted file mode 100644 index c606ccf6..00000000 --- a/UnityProject/Assets/DebugVis.mat.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 3f581bc765fd2dd4e8e2a6f19d1c5a54 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 2100000 - userData: - assetBundleName: debug - assetBundleVariant: diff --git a/UnityProject/Assets/DialogueBubble.prefab b/UnityProject/Assets/DialogueBubble.prefab deleted file mode 100644 index 17b9093a..00000000 --- a/UnityProject/Assets/DialogueBubble.prefab +++ /dev/null @@ -1,247 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &679228622185909741 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 5510779269599846461} - - component: {fileID: 130575080623899817} - - component: {fileID: 916729221779553788} - - component: {fileID: 4465360732322480311} - - component: {fileID: 2271490637008274700} - - component: {fileID: 6454923117947624182} - m_Layer: 0 - m_Name: DialogueBubble - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &5510779269599846461 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 679228622185909741} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0.00286, y: 0.00286, z: 1} - m_Children: - - {fileID: 1910662446065868499} - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 900, y: 0} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!222 &130575080623899817 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 679228622185909741} - m_CullTransparentMesh: 0 ---- !u!114 &916729221779553788 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 679228622185909741} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 2100000, guid: 4e6da33672306aa4f9e9fe70ddfd9d8b, type: 2} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 0 - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_FontData: - m_Font: {fileID: 12800000, guid: 1c803be2199fabd41b853684b5e45b6a, type: 3} - m_FontSize: 35 - m_FontStyle: 0 - m_BestFit: 0 - m_MinSize: 0 - m_MaxSize: 300 - m_Alignment: 4 - m_AlignByGeometry: 0 - m_RichText: 1 - m_HorizontalOverflow: 0 - m_VerticalOverflow: 1 - m_LineSpacing: 1 - m_Text: 'OOPSIE WOOPSIE!! - - This isn''t meant to appear. - - what - did i do wrong... - - Submit an error to the QSB Github with the - reproduction steps please! - - - Your humble servant, _nebula' ---- !u!223 &4465360732322480311 -Canvas: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 679228622185909741} - m_Enabled: 1 - serializedVersion: 3 - m_RenderMode: 2 - m_Camera: {fileID: 0} - m_PlaneDistance: 100 - m_PixelPerfect: 0 - m_ReceivesEvents: 1 - m_OverrideSorting: 0 - m_OverridePixelPerfect: 0 - m_SortingBucketNormalizedSize: 0 - m_AdditionalShaderChannelsFlag: 0 - m_SortingLayerID: 0 - m_SortingOrder: 0 - m_TargetDisplay: 0 ---- !u!114 &2271490637008274700 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 679228622185909741} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3} - m_Name: - m_EditorClassIdentifier: - m_HorizontalFit: 0 - m_VerticalFit: 2 ---- !u!114 &6454923117947624182 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 679228622185909741} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} - m_Name: - m_EditorClassIdentifier: - m_UiScaleMode: 0 - m_ReferencePixelsPerUnit: 100 - m_ScaleFactor: 1 - m_ReferenceResolution: {x: 800, y: 600} - m_ScreenMatchMode: 0 - m_MatchWidthOrHeight: 0 - m_PhysicalUnit: 3 - m_FallbackScreenDPI: 96 - m_DefaultSpriteDPI: 96 - m_DynamicPixelsPerUnit: 5 ---- !u!1 &8766783471207652418 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1910662446065868499} - - component: {fileID: 2884875585792430400} - - component: {fileID: 4192568564237117109} - - component: {fileID: 4513423881476039006} - m_Layer: 0 - m_Name: Background - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &1910662446065868499 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8766783471207652418} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 5510779269599846461} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -20, y: -20.000008} - m_SizeDelta: {x: 40, y: 40} - m_Pivot: {x: 0, y: 0} ---- !u!222 &2884875585792430400 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8766783471207652418} - m_CullTransparentMesh: 0 ---- !u!114 &4192568564237117109 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8766783471207652418} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 0, g: 0, b: 0, a: 0.72156864} - m_RaycastTarget: 1 - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_Sprite: {fileID: 21300000, guid: 5e9aeeea80dcad34ea121719721a5a45, type: 3} - m_Type: 1 - m_PreserveAspect: 0 - m_FillCenter: 1 - m_FillMethod: 4 - m_FillAmount: 1 - m_FillClockwise: 1 - m_FillOrigin: 0 - m_UseSpriteMesh: 0 - m_PixelsPerUnitMultiplier: 1 ---- !u!223 &4513423881476039006 -Canvas: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8766783471207652418} - m_Enabled: 1 - serializedVersion: 3 - m_RenderMode: 2 - m_Camera: {fileID: 0} - m_PlaneDistance: 100 - m_PixelPerfect: 0 - m_ReceivesEvents: 1 - m_OverrideSorting: 1 - m_OverridePixelPerfect: 1 - m_SortingBucketNormalizedSize: 0 - m_AdditionalShaderChannelsFlag: 0 - m_SortingLayerID: 0 - m_SortingOrder: -9999 - m_TargetDisplay: 0 diff --git a/UnityProject/Assets/DialogueBubble.prefab.meta b/UnityProject/Assets/DialogueBubble.prefab.meta deleted file mode 100644 index 20d50770..00000000 --- a/UnityProject/Assets/DialogueBubble.prefab.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 8a96f886e4fad144f8fb9a5e3c2712df -PrefabImporter: - externalObjects: {} - userData: - assetBundleName: conversation - assetBundleVariant: diff --git a/UnityProject/Assets/Editor.meta b/UnityProject/Assets/Editor.meta deleted file mode 100644 index fabe945a..00000000 --- a/UnityProject/Assets/Editor.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: da6b5401ddcc31b4f86ac45f7b0f3784 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/Editor/AssetBundles.cs b/UnityProject/Assets/Editor/AssetBundles.cs deleted file mode 100644 index 9111d40a..00000000 --- a/UnityProject/Assets/Editor/AssetBundles.cs +++ /dev/null @@ -1,15 +0,0 @@ -using UnityEditor; -using System.IO; - -public class CreateAssetBundles { - [MenuItem("Assets/Build AssetBundles")] - static void BuildAllAssetBundles () { - string assetBundleDirectory = "../AssetBundles"; - if (!Directory.Exists(assetBundleDirectory)) { - Directory.CreateDirectory(assetBundleDirectory); - } - BuildPipeline.BuildAssetBundles(assetBundleDirectory, - BuildAssetBundleOptions.None, - BuildTarget.StandaloneWindows); - } -} \ No newline at end of file diff --git a/UnityProject/Assets/Editor/AssetBundles.cs.meta b/UnityProject/Assets/Editor/AssetBundles.cs.meta deleted file mode 100644 index 31021c08..00000000 --- a/UnityProject/Assets/Editor/AssetBundles.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cc4391189d578fe4da7e00bdf6031562 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/Editor/EditorObjExporter.cs b/UnityProject/Assets/Editor/EditorObjExporter.cs deleted file mode 100644 index 18d33297..00000000 --- a/UnityProject/Assets/Editor/EditorObjExporter.cs +++ /dev/null @@ -1,308 +0,0 @@ -/* -Based on ObjExporter.cs, this "wrapper" lets you export to .OBJ directly from the editor menu. - -This should be put in your "Editor"-folder. Use by selecting the objects you want to export, and select -the appropriate menu item from "Custom->Export". Exported models are put in a folder called -"ExportedObj" in the root of your Unity-project. Textures should also be copied and placed in the -same folder. -N.B. there may be a bug so if the custom option doesn't come up refer to this thread http://answers.unity3d.com/questions/317951/how-to-use-editorobjexporter-obj-saving-script-fro.html - -Updated for Unity 5.3 -*/ - -using UnityEngine; -using UnityEditor; -using UnityEditor.SceneManagement; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System; - -struct ObjMaterial -{ - public string name; - public string textureName; -} - -public class EditorObjExporter : ScriptableObject -{ - private static int vertexOffset = 0; - private static int normalOffset = 0; - private static int uvOffset = 0; - - - //User should probably be able to change this. It is currently left as an excercise for - //the reader. - private static string targetFolder = "ExportedObj"; - - - private static string MeshToString(MeshFilter mf, Dictionary materialList) { - Mesh m = mf.sharedMesh; - Material mats = mf.GetComponent().material; - - StringBuilder sb = new StringBuilder(); - - sb.Append("g ").Append(mf.name).Append("\n"); - foreach (Vector3 lv in m.vertices) { - Vector3 wv = mf.transform.TransformPoint(lv); - - //This is sort of ugly - inverting x-component since we're in - //a different coordinate system than "everyone" is "used to". - sb.Append(string.Format("v {0} {1} {2}\n", -wv.x, wv.y, wv.z)); - } - sb.Append("\n"); - - foreach (Vector3 lv in m.normals) { - Vector3 wv = mf.transform.TransformDirection(lv); - - sb.Append(string.Format("vn {0} {1} {2}\n", -wv.x, wv.y, wv.z)); - } - sb.Append("\n"); - - foreach (Vector3 v in m.uv) { - sb.Append(string.Format("vt {0} {1}\n", v.x, v.y)); - } - - sb.Append("\n"); - sb.Append("usemtl ").Append(mats.name).Append("\n"); - sb.Append("usemap ").Append(mats.name).Append("\n"); - - //See if this material is already in the materiallist. - try { - ObjMaterial objMaterial = new ObjMaterial(); - - objMaterial.name = mats.name; - - if (mats.mainTexture) - objMaterial.textureName = AssetDatabase.GetAssetPath(mats.mainTexture); - else - objMaterial.textureName = null; - - materialList.Add(objMaterial.name, objMaterial); - } catch (ArgumentException) { - //Already in the dictionary - } - - - int[] triangles = m.GetTriangles(0); - for (int i = 0; i < triangles.Length; i += 3) { - //Because we inverted the x-component, we also needed to alter the triangle winding. - sb.Append(string.Format("f {1}/{1}/{1} {0}/{0}/{0} {2}/{2}/{2}\n", - triangles[i] + 1 + vertexOffset, triangles[i + 1] + 1 + normalOffset, triangles[i + 2] + 1 + uvOffset)); - } - - vertexOffset += m.vertices.Length; - normalOffset += m.normals.Length; - uvOffset += m.uv.Length; - - return sb.ToString(); - } - - private static void Clear() { - vertexOffset = 0; - normalOffset = 0; - uvOffset = 0; - } - - private static Dictionary PrepareFileWrite() { - Clear(); - - return new Dictionary(); - } - - private static void MaterialsToFile(Dictionary materialList, string folder, string filename) { - using (StreamWriter sw = new StreamWriter(folder + Path.PathSeparator + filename + ".mtl")) { - foreach (KeyValuePair kvp in materialList) { - sw.Write("\n"); - sw.Write("newmtl {0}\n", kvp.Key); - sw.Write("Ka 0.6 0.6 0.6\n"); - sw.Write("Kd 0.6 0.6 0.6\n"); - sw.Write("Ks 0.9 0.9 0.9\n"); - sw.Write("d 1.0\n"); - sw.Write("Ns 0.0\n"); - sw.Write("illum 2\n"); - - if (kvp.Value.textureName != null) { - string destinationFile = kvp.Value.textureName; - - - int stripIndex = destinationFile.LastIndexOf(Path.PathSeparator); - - if (stripIndex >= 0) - destinationFile = destinationFile.Substring(stripIndex + 1).Trim(); - - - string relativeFile = destinationFile; - - destinationFile = folder + Path.PathSeparator + destinationFile; - - Debug.Log("Copying texture from " + kvp.Value.textureName + " to " + destinationFile); - - try { - //Copy the source file - File.Copy(kvp.Value.textureName, destinationFile); - } catch { - - } - - - sw.Write("map_Kd {0}", relativeFile); - } - - sw.Write("\n\n\n"); - } - } - } - - private static void MeshToFile(MeshFilter mf, string folder, string filename) { - Dictionary materialList = PrepareFileWrite(); - - using (StreamWriter sw = new StreamWriter(folder + Path.PathSeparator + filename + ".obj")) { - sw.Write("mtllib ./" + filename + ".mtl\n"); - - sw.Write(MeshToString(mf, materialList)); - } - - MaterialsToFile(materialList, folder, filename); - } - - private static void MeshesToFile(MeshFilter[] mf, string folder, string filename) { - Dictionary materialList = PrepareFileWrite(); - - using (StreamWriter sw = new StreamWriter(folder + Path.PathSeparator + filename + ".obj")) { - sw.Write("mtllib ./" + filename + ".mtl\n"); - - for (int i = 0; i < mf.Length; i++) { - sw.Write(MeshToString(mf[i], materialList)); - } - } - - MaterialsToFile(materialList, folder, filename); - } - - private static bool CreateTargetFolder() { - try { - System.IO.Directory.CreateDirectory(targetFolder); - } catch { - EditorUtility.DisplayDialog("Error!", "Failed to create target folder!", ""); - return false; - } - - return true; - } - - [MenuItem("Custom/Export/Export all MeshFilters in selection to separate OBJs")] - static void ExportSelectionToSeparate() { - if (!CreateTargetFolder()) - return; - - Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab); - - if (selection.Length == 0) { - EditorUtility.DisplayDialog("No source object selected!", "Please select one or more target objects", ""); - return; - } - - int exportedObjects = 0; - - for (int i = 0; i < selection.Length; i++) { - Component[] meshfilter = selection[i].GetComponentsInChildren(typeof(MeshFilter)); - - for (int m = 0; m < meshfilter.Length; m++) { - exportedObjects++; - MeshToFile((MeshFilter)meshfilter[m], targetFolder, selection[i].name + "_" + i + "_" + m); - } - } - - if (exportedObjects > 0) - EditorUtility.DisplayDialog("Objects exported", "Exported " + exportedObjects + " objects", ""); - else - EditorUtility.DisplayDialog("Objects not exported", "Make sure at least some of your selected objects have mesh filters!", ""); - } - - [MenuItem("Custom/Export/Export whole selection to single OBJ")] - static void ExportWholeSelectionToSingle() { - if (!CreateTargetFolder()) - return; - - - Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab); - - if (selection.Length == 0) { - EditorUtility.DisplayDialog("No source object selected!", "Please select one or more target objects", ""); - return; - } - - int exportedObjects = 0; - - ArrayList mfList = new ArrayList(); - - for (int i = 0; i < selection.Length; i++) { - Component[] meshfilter = selection[i].GetComponentsInChildren(typeof(MeshFilter)); - - for (int m = 0; m < meshfilter.Length; m++) { - exportedObjects++; - mfList.Add(meshfilter[m]); - } - } - - if (exportedObjects > 0) { - MeshFilter[] mf = new MeshFilter[mfList.Count]; - - for (int i = 0; i < mfList.Count; i++) { - mf[i] = (MeshFilter)mfList[i]; - } - - string filename = EditorSceneManager.GetActiveScene().name + "_" + exportedObjects; - - int stripIndex = filename.LastIndexOf(Path.PathSeparator); - - if (stripIndex >= 0) - filename = filename.Substring(stripIndex + 1).Trim(); - - MeshesToFile(mf, targetFolder, filename); - - - EditorUtility.DisplayDialog("Objects exported", "Exported " + exportedObjects + " objects to " + filename, ""); - } else - EditorUtility.DisplayDialog("Objects not exported", "Make sure at least some of your selected objects have mesh filters!", ""); - } - - - - [MenuItem("Custom/Export/Export each selected to single OBJ")] - static void ExportEachSelectionToSingle() { - if (!CreateTargetFolder()) - return; - - Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab); - - if (selection.Length == 0) { - EditorUtility.DisplayDialog("No source object selected!", "Please select one or more target objects", ""); - return; - } - - int exportedObjects = 0; - - - for (int i = 0; i < selection.Length; i++) { - Component[] meshfilter = selection[i].GetComponentsInChildren(typeof(MeshFilter)); - - MeshFilter[] mf = new MeshFilter[meshfilter.Length]; - - for (int m = 0; m < meshfilter.Length; m++) { - exportedObjects++; - mf[m] = (MeshFilter)meshfilter[m]; - } - - MeshesToFile(mf, targetFolder, selection[i].name + "_" + i); - } - - if (exportedObjects > 0) { - EditorUtility.DisplayDialog("Objects exported", "Exported " + exportedObjects + " objects", ""); - } else - EditorUtility.DisplayDialog("Objects not exported", "Make sure at least some of your selected objects have mesh filters!", ""); - } - -} \ No newline at end of file diff --git a/UnityProject/Assets/Editor/EditorObjExporter.cs.meta b/UnityProject/Assets/Editor/EditorObjExporter.cs.meta deleted file mode 100644 index e80b7747..00000000 --- a/UnityProject/Assets/Editor/EditorObjExporter.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6676f81f069b9b347be1b9f0c1a32bf6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/GameAssets.meta b/UnityProject/Assets/GameAssets.meta deleted file mode 100644 index fe676201..00000000 --- a/UnityProject/Assets/GameAssets.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e2241e4bc9f9e994c9d743879f2f5fb2 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/LogCanvas.prefab b/UnityProject/Assets/LogCanvas.prefab deleted file mode 100644 index b40c2c8c..00000000 --- a/UnityProject/Assets/LogCanvas.prefab +++ /dev/null @@ -1,164 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1001 &100100000 -Prefab: - m_ObjectHideFlags: 1 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: [] - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 0} - m_RootGameObject: {fileID: 1903551149170608} - m_IsPrefabParent: 1 ---- !u!1 &1404529727000012 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 5 - m_Component: - - component: {fileID: 224538486460784708} - - component: {fileID: 222986556089560310} - - component: {fileID: 114038938687489096} - m_Layer: 5 - m_Name: Text - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!1 &1903551149170608 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 5 - m_Component: - - component: {fileID: 224105012127347782} - - component: {fileID: 223566299370351722} - - component: {fileID: 114338821582470422} - m_Layer: 5 - m_Name: LogCanvas - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &114038938687489096 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 1404529727000012} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 0 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, - Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - m_FontData: - m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} - m_FontSize: 14 - m_FontStyle: 0 - m_BestFit: 0 - m_MinSize: 10 - m_MaxSize: 40 - m_Alignment: 0 - m_AlignByGeometry: 0 - m_RichText: 1 - m_HorizontalOverflow: 0 - m_VerticalOverflow: 0 - m_LineSpacing: 1 - m_Text: ---- !u!114 &114338821582470422 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 1903551149170608} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3} - m_Name: - m_EditorClassIdentifier: - m_UiScaleMode: 0 - m_ReferencePixelsPerUnit: 100 - m_ScaleFactor: 1 - m_ReferenceResolution: {x: 800, y: 600} - m_ScreenMatchMode: 0 - m_MatchWidthOrHeight: 0 - m_PhysicalUnit: 3 - m_FallbackScreenDPI: 96 - m_DefaultSpriteDPI: 96 - m_DynamicPixelsPerUnit: 1 ---- !u!222 &222986556089560310 -CanvasRenderer: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 1404529727000012} ---- !u!223 &223566299370351722 -Canvas: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 1903551149170608} - m_Enabled: 1 - serializedVersion: 3 - m_RenderMode: 0 - m_Camera: {fileID: 0} - m_PlaneDistance: 100 - m_PixelPerfect: 0 - m_ReceivesEvents: 1 - m_OverrideSorting: 0 - m_OverridePixelPerfect: 0 - m_SortingBucketNormalizedSize: 0 - m_AdditionalShaderChannelsFlag: 0 - m_SortingLayerID: 0 - m_SortingOrder: -1 - m_TargetDisplay: 0 ---- !u!224 &224105012127347782 -RectTransform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 1903551149170608} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0, y: 0, z: 0} - m_Children: - - {fileID: 224538486460784708} - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} - m_Pivot: {x: 0, y: 0} ---- !u!224 &224538486460784708 -RectTransform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 1404529727000012} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 224105012127347782} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 0} - m_AnchoredPosition: {x: 0, y: 71} - m_SizeDelta: {x: -40, y: 100} - m_Pivot: {x: 0.5, y: 0.5} diff --git a/UnityProject/Assets/LogCanvas.prefab.meta b/UnityProject/Assets/LogCanvas.prefab.meta deleted file mode 100644 index ac93e5d7..00000000 --- a/UnityProject/Assets/LogCanvas.prefab.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: c78bde2c0a5608149a62a034ebe50c6c -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 100100000 - userData: - assetBundleName: debug - assetBundleVariant: diff --git a/UnityProject/Assets/NETWORK_Player_Body.prefab b/UnityProject/Assets/NETWORK_Player_Body.prefab deleted file mode 100644 index dcc96f86..00000000 --- a/UnityProject/Assets/NETWORK_Player_Body.prefab +++ /dev/null @@ -1,328 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &1063531587744832 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4537338579920700} - m_Layer: 0 - m_Name: NETWORK_Stick_Tip - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4537338579920700 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1063531587744832} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 4232815760244474} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1268162395208754 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4362517717386354} - m_Layer: 0 - m_Name: NETWORK_PlayerCamera - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4362517717386354 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1268162395208754} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0.8496093, z: 0.1500003} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 4311429169693626} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1491989937895418 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4232815760244474} - m_Layer: 0 - m_Name: NETWORK_Stick_Pivot - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4232815760244474 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1491989937895418} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 2} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: - - {fileID: 4537338579920700} - m_Father: {fileID: 4361850152643004} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1677454195273572 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4361850152643004} - m_Layer: 0 - m_Name: NETWORK_Stick_Root - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4361850152643004 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1677454195273572} - m_LocalRotation: {x: 0, y: -0.08715578, z: 0, w: 0.9961947} - m_LocalPosition: {x: 0.25, y: 0, z: 0.08} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: - - {fileID: 4232815760244474} - m_Father: {fileID: 4773365960669392} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: -10, z: 0} ---- !u!1 &1813708233350436 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4773365960669392} - m_Layer: 0 - m_Name: NETWORK_RoastingSystem - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4773365960669392 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1813708233350436} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0.4, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: - - {fileID: 4361850152643004} - m_Father: {fileID: 4311429169693626} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1994424166804230 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4311429169693626} - - component: {fileID: 114683588823772616} - - component: {fileID: 114047126095319432} - - component: {fileID: 114320751842596664} - - component: {fileID: 114492380483131480} - - component: {fileID: 114827007418351406} - - component: {fileID: 114340969760283228} - m_Layer: 0 - m_Name: NETWORK_Player_Body - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4311429169693626 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1994424166804230} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: - - {fileID: 4362517717386354} - - {fileID: 4773365960669392} - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &114683588823772616 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1994424166804230} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 372142912, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_SceneId: - m_Value: 0 - m_AssetId: - i0: 0 - i1: 0 - i2: 0 - i3: 0 - i4: 0 - i5: 0 - i6: 0 - i7: 0 - i8: 0 - i9: 0 - i10: 0 - i11: 0 - i12: 0 - i13: 0 - i14: 0 - i15: 1 - m_ServerOnly: 0 - m_LocalPlayerAuthority: 1 ---- !u!114 &114047126095319432 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1994424166804230} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1768714887, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_TransformSyncMode: 1 - m_SendInterval: 0.0625 - m_SyncRotationAxis: 7 - m_RotationSyncCompression: 0 - m_SyncSpin: 0 - m_MovementTheshold: 0.001 - m_VelocityThreshold: 0.0001 - m_SnapThreshold: 5 - m_InterpolateRotation: 1 - m_InterpolateMovement: 1 ---- !u!114 &114320751842596664 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1994424166804230} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1267208747, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Target: {fileID: 4362517717386354} - m_ChildIndex: 0 - m_SendInterval: 0.0625 - m_SyncRotationAxis: 7 - m_RotationSyncCompression: 0 - m_MovementThreshold: 0.001 - m_InterpolateRotation: 0 - m_InterpolateMovement: 0 ---- !u!114 &114492380483131480 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1994424166804230} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1267208747, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Target: {fileID: 4232815760244474} - m_ChildIndex: 1 - m_SendInterval: 0.0625 - m_SyncRotationAxis: 7 - m_RotationSyncCompression: 0 - m_MovementThreshold: 0.001 - m_InterpolateRotation: 0 - m_InterpolateMovement: 0 ---- !u!114 &114827007418351406 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1994424166804230} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1267208747, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Target: {fileID: 4537338579920700} - m_ChildIndex: 2 - m_SendInterval: 0.0625 - m_SyncRotationAxis: 7 - m_RotationSyncCompression: 0 - m_MovementThreshold: 0.001 - m_InterpolateRotation: 0 - m_InterpolateMovement: 0 ---- !u!114 &114340969760283228 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1994424166804230} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1267208747, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Target: {fileID: 4773365960669392} - m_ChildIndex: 3 - m_SendInterval: 0.0625 - m_SyncRotationAxis: 7 - m_RotationSyncCompression: 0 - m_MovementThreshold: 0.001 - m_InterpolateRotation: 0 - m_InterpolateMovement: 0 diff --git a/UnityProject/Assets/NETWORK_Player_Body.prefab.meta b/UnityProject/Assets/NETWORK_Player_Body.prefab.meta deleted file mode 100644 index 7c9061b8..00000000 --- a/UnityProject/Assets/NETWORK_Player_Body.prefab.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 14abb8162230eb14db68cbf0fecbe4ce -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 100100000 - userData: - assetBundleName: network - assetBundleVariant: diff --git a/UnityProject/Assets/NetworkOrb.prefab b/UnityProject/Assets/NetworkOrb.prefab deleted file mode 100644 index 0791274c..00000000 --- a/UnityProject/Assets/NetworkOrb.prefab +++ /dev/null @@ -1,89 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &1252242529042024 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4745039063230268} - - component: {fileID: 114872848302743272} - - component: {fileID: 114240702864939342} - m_Layer: 0 - m_Name: NetworkOrb - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4745039063230268 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1252242529042024} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &114872848302743272 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1252242529042024} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 372142912, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_SceneId: - m_Value: 0 - m_AssetId: - i0: 0 - i1: 0 - i2: 0 - i3: 0 - i4: 0 - i5: 0 - i6: 0 - i7: 0 - i8: 0 - i9: 0 - i10: 0 - i11: 0 - i12: 0 - i13: 0 - i14: 0 - i15: 0 - m_ServerOnly: 0 - m_LocalPlayerAuthority: 1 ---- !u!114 &114240702864939342 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1252242529042024} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1768714887, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_TransformSyncMode: 1 - m_SendInterval: 0.09090909 - m_SyncRotationAxis: 0 - m_RotationSyncCompression: 0 - m_SyncSpin: 0 - m_MovementTheshold: 0.001 - m_VelocityThreshold: 0.0001 - m_SnapThreshold: 5 - m_InterpolateRotation: 1 - m_InterpolateMovement: 1 diff --git a/UnityProject/Assets/NetworkOrb.prefab.meta b/UnityProject/Assets/NetworkOrb.prefab.meta deleted file mode 100644 index f594ab79..00000000 --- a/UnityProject/Assets/NetworkOrb.prefab.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 103655e7bf4462e419bf730cc420c2c5 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 100100000 - userData: - assetBundleName: network - assetBundleVariant: diff --git a/UnityProject/Assets/NetworkProbe.prefab b/UnityProject/Assets/NetworkProbe.prefab deleted file mode 100644 index 04e8c8c2..00000000 --- a/UnityProject/Assets/NetworkProbe.prefab +++ /dev/null @@ -1,89 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &1858162522537180 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4383151934826088} - - component: {fileID: 114893399387826744} - - component: {fileID: 114960003525639280} - m_Layer: 0 - m_Name: NetworkProbe - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4383151934826088 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1858162522537180} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &114893399387826744 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1858162522537180} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 372142912, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_SceneId: - m_Value: 0 - m_AssetId: - i0: 0 - i1: 0 - i2: 0 - i3: 0 - i4: 0 - i5: 0 - i6: 0 - i7: 0 - i8: 0 - i9: 0 - i10: 0 - i11: 0 - i12: 0 - i13: 0 - i14: 0 - i15: 0 - m_ServerOnly: 0 - m_LocalPlayerAuthority: 1 ---- !u!114 &114960003525639280 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1858162522537180} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1768714887, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_TransformSyncMode: 1 - m_SendInterval: 0.04761905 - m_SyncRotationAxis: 7 - m_RotationSyncCompression: 0 - m_SyncSpin: 0 - m_MovementTheshold: 0.001 - m_VelocityThreshold: 0.0001 - m_SnapThreshold: 5 - m_InterpolateRotation: 1 - m_InterpolateMovement: 1 diff --git a/UnityProject/Assets/NetworkProbe.prefab.meta b/UnityProject/Assets/NetworkProbe.prefab.meta deleted file mode 100644 index ccd77c18..00000000 --- a/UnityProject/Assets/NetworkProbe.prefab.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 3208aa06e4648cd48b97fe00badd1502 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 100100000 - userData: - assetBundleName: network - assetBundleVariant: diff --git a/UnityProject/Assets/NetworkShip.prefab b/UnityProject/Assets/NetworkShip.prefab deleted file mode 100644 index 75785cfa..00000000 --- a/UnityProject/Assets/NetworkShip.prefab +++ /dev/null @@ -1,89 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &1651223990902024 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4928834428794828} - - component: {fileID: 114173126939784982} - - component: {fileID: 114412165868198726} - m_Layer: 0 - m_Name: NetworkShip - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4928834428794828 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1651223990902024} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &114173126939784982 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1651223990902024} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 372142912, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_SceneId: - m_Value: 0 - m_AssetId: - i0: 0 - i1: 0 - i2: 0 - i3: 0 - i4: 0 - i5: 0 - i6: 0 - i7: 0 - i8: 0 - i9: 0 - i10: 0 - i11: 0 - i12: 0 - i13: 0 - i14: 0 - i15: 0 - m_ServerOnly: 0 - m_LocalPlayerAuthority: 0 ---- !u!114 &114412165868198726 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1651223990902024} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1768714887, guid: 93b08009869340045a8e7321508b6355, type: 3} - m_Name: - m_EditorClassIdentifier: - m_TransformSyncMode: 1 - m_SendInterval: 0.06666667 - m_SyncRotationAxis: 7 - m_RotationSyncCompression: 0 - m_SyncSpin: 0 - m_MovementTheshold: 0.001 - m_VelocityThreshold: 0.0001 - m_SnapThreshold: 5 - m_InterpolateRotation: 1 - m_InterpolateMovement: 1 diff --git a/UnityProject/Assets/NetworkShip.prefab.meta b/UnityProject/Assets/NetworkShip.prefab.meta deleted file mode 100644 index a5cddbc3..00000000 --- a/UnityProject/Assets/NetworkShip.prefab.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 8cc355df6d6769e44a37ba8059e4913d -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 100100000 - userData: - assetBundleName: network - assetBundleVariant: diff --git a/UnityProject/Assets/Resources.meta b/UnityProject/Assets/Resources.meta deleted file mode 100644 index 4e0fc546..00000000 --- a/UnityProject/Assets/Resources.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 6defefa8ffddeff4881a8fbdeaa56b0d -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/Resources/BillingMode.json b/UnityProject/Assets/Resources/BillingMode.json deleted file mode 100644 index 6f4bfb71..00000000 --- a/UnityProject/Assets/Resources/BillingMode.json +++ /dev/null @@ -1 +0,0 @@ -{"androidStore":"GooglePlay"} \ No newline at end of file diff --git a/UnityProject/Assets/Resources/BillingMode.json.meta b/UnityProject/Assets/Resources/BillingMode.json.meta deleted file mode 100644 index ba2a1232..00000000 --- a/UnityProject/Assets/Resources/BillingMode.json.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: a7ad16210ad1ba94187ddafb875b51cf -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/Scene.unity b/UnityProject/Assets/Scene.unity deleted file mode 100644 index 0dc010c8..00000000 --- a/UnityProject/Assets/Scene.unity +++ /dev/null @@ -1,261 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!29 &1 -OcclusionCullingSettings: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_OcclusionBakeSettings: - smallestOccluder: 5 - smallestHole: 0.25 - backfaceThreshold: 100 - m_SceneGUID: 00000000000000000000000000000000 - m_OcclusionCullingData: {fileID: 0} ---- !u!104 &2 -RenderSettings: - m_ObjectHideFlags: 0 - serializedVersion: 8 - m_Fog: 0 - m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} - m_FogMode: 3 - m_FogDensity: 0.01 - m_LinearFogStart: 0 - m_LinearFogEnd: 300 - m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} - m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} - m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} - m_AmbientIntensity: 1 - m_AmbientMode: 0 - m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} - m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} - m_HaloStrength: 0.5 - m_FlareStrength: 1 - m_FlareFadeSpeed: 3 - m_HaloTexture: {fileID: 0} - m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} - m_DefaultReflectionMode: 0 - m_DefaultReflectionResolution: 128 - m_ReflectionBounces: 1 - m_ReflectionIntensity: 1 - m_CustomReflection: {fileID: 0} - m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} ---- !u!157 &3 -LightmapSettings: - m_ObjectHideFlags: 0 - serializedVersion: 11 - m_GIWorkflowMode: 0 - m_GISettings: - serializedVersion: 2 - m_BounceScale: 1 - m_IndirectOutputScale: 1 - m_AlbedoBoost: 1 - m_TemporalCoherenceThreshold: 1 - m_EnvironmentLightingMode: 0 - m_EnableBakedLightmaps: 1 - m_EnableRealtimeLightmaps: 1 - m_LightmapEditorSettings: - serializedVersion: 9 - m_Resolution: 2 - m_BakeResolution: 40 - m_TextureWidth: 1024 - m_TextureHeight: 1024 - m_AO: 0 - m_AOMaxDistance: 1 - m_CompAOExponent: 1 - m_CompAOExponentDirect: 0 - m_Padding: 2 - m_LightmapParameters: {fileID: 0} - m_LightmapsBakeMode: 1 - m_TextureCompression: 1 - m_FinalGather: 0 - m_FinalGatherFiltering: 1 - m_FinalGatherRayCount: 256 - m_ReflectionCompression: 2 - m_MixedBakeMode: 2 - m_BakeBackend: 0 - m_PVRSampling: 1 - m_PVRDirectSampleCount: 32 - m_PVRSampleCount: 500 - m_PVRBounces: 2 - m_PVRFilterTypeDirect: 0 - m_PVRFilterTypeIndirect: 0 - m_PVRFilterTypeAO: 0 - m_PVRFilteringMode: 1 - m_PVRCulling: 1 - m_PVRFilteringGaussRadiusDirect: 1 - m_PVRFilteringGaussRadiusIndirect: 5 - m_PVRFilteringGaussRadiusAO: 2 - m_PVRFilteringAtrousPositionSigmaDirect: 0.5 - m_PVRFilteringAtrousPositionSigmaIndirect: 2 - m_PVRFilteringAtrousPositionSigmaAO: 1 - m_ShowResolutionOverlay: 1 - m_LightingDataAsset: {fileID: 0} - m_UseShadowmask: 1 ---- !u!196 &4 -NavMeshSettings: - serializedVersion: 2 - m_ObjectHideFlags: 0 - m_BuildSettings: - serializedVersion: 2 - agentTypeID: 0 - agentRadius: 0.5 - agentHeight: 2 - agentSlope: 45 - agentClimb: 0.4 - ledgeDropHeight: 0 - maxJumpAcrossDistance: 0 - minRegionArea: 2 - manualCellSize: 0 - cellSize: 0.16666667 - manualTileSize: 0 - tileSize: 256 - accuratePlacement: 0 - debug: - m_Flags: 0 - m_NavMeshData: {fileID: 0} ---- !u!1 &382150840 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 5 - m_Component: - - component: {fileID: 382150842} - - component: {fileID: 382150841} - m_Layer: 0 - m_Name: Directional Light - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!108 &382150841 -Light: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 382150840} - m_Enabled: 1 - serializedVersion: 8 - m_Type: 1 - m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} - m_Intensity: 1 - m_Range: 10 - m_SpotAngle: 30 - m_CookieSize: 10 - m_Shadows: - m_Type: 2 - m_Resolution: -1 - m_CustomResolution: -1 - m_Strength: 1 - m_Bias: 0.05 - m_NormalBias: 0.4 - m_NearPlane: 0.2 - m_Cookie: {fileID: 0} - m_DrawHalo: 0 - m_Flare: {fileID: 0} - m_RenderMode: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_Lightmapping: 4 - m_AreaSize: {x: 1, y: 1} - m_BounceIntensity: 1 - m_ColorTemperature: 6570 - m_UseColorTemperature: 0 - m_ShadowRadius: 0 - m_ShadowAngle: 0 ---- !u!4 &382150842 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 382150840} - m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} - m_LocalPosition: {x: 0, y: 3, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} ---- !u!1 &1385198596 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 5 - m_Component: - - component: {fileID: 1385198600} - - component: {fileID: 1385198599} - - component: {fileID: 1385198598} - - component: {fileID: 1385198597} - m_Layer: 0 - m_Name: Main Camera - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!81 &1385198597 -AudioListener: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1385198596} - m_Enabled: 1 ---- !u!124 &1385198598 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1385198596} - m_Enabled: 1 ---- !u!20 &1385198599 -Camera: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1385198596} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 1 - m_AllowMSAA: 1 - m_AllowDynamicResolution: 0 - m_ForceIntoRT: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 ---- !u!4 &1385198600 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1385198596} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -10} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/UnityProject/Assets/Scene.unity.meta b/UnityProject/Assets/Scene.unity.meta deleted file mode 100644 index 8f71e331..00000000 --- a/UnityProject/Assets/Scene.unity.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 8c97ccf64c95fbd47bed9271305a9477 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/Sphere.prefab b/UnityProject/Assets/Sphere.prefab deleted file mode 100644 index 631f758b..00000000 --- a/UnityProject/Assets/Sphere.prefab +++ /dev/null @@ -1,81 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &6988891241326536966 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1528378738054518666} - - component: {fileID: 6895832966541343269} - - component: {fileID: 1995909747615478316} - m_Layer: 0 - m_Name: Sphere - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1528378738054518666 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6988891241326536966} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!33 &6895832966541343269 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6988891241326536966} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &1995909747615478316 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6988891241326536966} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 3f581bc765fd2dd4e8e2a6f19d1c5a54, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 diff --git a/UnityProject/Assets/Sphere.prefab.meta b/UnityProject/Assets/Sphere.prefab.meta deleted file mode 100644 index 17c16850..00000000 --- a/UnityProject/Assets/Sphere.prefab.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: c23e96dc4c16238499a5a34dae13c90c -PrefabImporter: - externalObjects: {} - userData: - assetBundleName: debug - assetBundleVariant: diff --git a/UnityProject/Assets/UnityEngine.Networking.dll b/UnityProject/Assets/UnityEngine.Networking.dll deleted file mode 100644 index 4db9ce9d..00000000 Binary files a/UnityProject/Assets/UnityEngine.Networking.dll and /dev/null differ diff --git a/UnityProject/Assets/UnityEngine.Networking.dll.meta b/UnityProject/Assets/UnityEngine.Networking.dll.meta deleted file mode 100644 index 0f97562a..00000000 --- a/UnityProject/Assets/UnityEngine.Networking.dll.meta +++ /dev/null @@ -1,69 +0,0 @@ -fileFormatVersion: 2 -guid: 93b08009869340045a8e7321508b6355 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 0 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - : Any - second: - enabled: 0 - settings: - Exclude Editor: 0 - Exclude Linux64: 0 - Exclude OSXUniversal: 0 - Exclude Win: 0 - Exclude Win64: 0 - - first: - Any: - second: - enabled: 1 - settings: {} - - first: - Editor: Editor - second: - enabled: 1 - settings: - CPU: AnyCPU - DefaultValueInitialized: true - OS: AnyOS - - first: - Standalone: Linux64 - second: - enabled: 1 - settings: - CPU: AnyCPU - - first: - Standalone: OSXUniversal - second: - enabled: 1 - settings: - CPU: x86_64 - - first: - Standalone: Win - second: - enabled: 1 - settings: - CPU: x86 - - first: - Standalone: Win64 - second: - enabled: 1 - settings: - CPU: x86_64 - - first: - Windows Store Apps: WindowsStoreApps - second: - enabled: 0 - settings: - CPU: AnyCPU - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/UnlitColored.shader b/UnityProject/Assets/UnlitColored.shader deleted file mode 100644 index bee32967..00000000 --- a/UnityProject/Assets/UnlitColored.shader +++ /dev/null @@ -1,22 +0,0 @@ -Shader "Unlit/Transparent Colored" { - Properties { - _Color ("Main Color", Color) = (1,1,1,1) - _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} - } - - SubShader { - Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} - - ZWrite Off - Lighting Off - Cull Off - Fog { Mode Off } - - Blend SrcAlpha OneMinusSrcAlpha - - Pass { - Color [_Color] - SetTexture [_MainTex] { combine texture * primary } - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/UnlitColored.shader.meta b/UnityProject/Assets/UnlitColored.shader.meta deleted file mode 100644 index 46ed92e3..00000000 --- a/UnityProject/Assets/UnlitColored.shader.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 9ec76f18fccbe654a850002455808200 -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/ProjectSettings/AudioManager.asset b/UnityProject/ProjectSettings/AudioManager.asset deleted file mode 100644 index da611257..00000000 --- a/UnityProject/ProjectSettings/AudioManager.asset +++ /dev/null @@ -1,17 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!11 &1 -AudioManager: - m_ObjectHideFlags: 0 - m_Volume: 1 - Rolloff Scale: 1 - Doppler Factor: 1 - Default Speaker Mode: 2 - m_SampleRate: 0 - m_DSPBufferSize: 0 - m_VirtualVoiceCount: 512 - m_RealVoiceCount: 32 - m_SpatializerPlugin: - m_AmbisonicDecoderPlugin: - m_DisableAudio: 0 - m_VirtualizeEffects: 1 diff --git a/UnityProject/ProjectSettings/ClusterInputManager.asset b/UnityProject/ProjectSettings/ClusterInputManager.asset deleted file mode 100644 index e7886b26..00000000 --- a/UnityProject/ProjectSettings/ClusterInputManager.asset +++ /dev/null @@ -1,6 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!236 &1 -ClusterInputManager: - m_ObjectHideFlags: 0 - m_Inputs: [] diff --git a/UnityProject/ProjectSettings/DynamicsManager.asset b/UnityProject/ProjectSettings/DynamicsManager.asset deleted file mode 100644 index 78992f08..00000000 --- a/UnityProject/ProjectSettings/DynamicsManager.asset +++ /dev/null @@ -1,29 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!55 &1 -PhysicsManager: - m_ObjectHideFlags: 0 - serializedVersion: 7 - m_Gravity: {x: 0, y: -9.81, z: 0} - m_DefaultMaterial: {fileID: 0} - m_BounceThreshold: 2 - m_SleepThreshold: 0.005 - m_DefaultContactOffset: 0.01 - m_DefaultSolverIterations: 6 - m_DefaultSolverVelocityIterations: 1 - m_QueriesHitBackfaces: 0 - m_QueriesHitTriggers: 1 - m_EnableAdaptiveForce: 0 - m_ClothInterCollisionDistance: 0 - m_ClothInterCollisionStiffness: 0 - m_ContactsGeneration: 1 - m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - m_AutoSimulation: 1 - m_AutoSyncTransforms: 1 - m_ClothInterCollisionSettingsToggle: 0 - m_ContactPairsMode: 0 - m_BroadphaseType: 0 - m_WorldBounds: - m_Center: {x: 0, y: 0, z: 0} - m_Extent: {x: 250, y: 250, z: 250} - m_WorldSubdivisions: 8 diff --git a/UnityProject/ProjectSettings/EditorBuildSettings.asset b/UnityProject/ProjectSettings/EditorBuildSettings.asset deleted file mode 100644 index 7f7b6e80..00000000 --- a/UnityProject/ProjectSettings/EditorBuildSettings.asset +++ /dev/null @@ -1,13 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1045 &1 -EditorBuildSettings: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Scenes: - - enabled: 0 - path: Assets/Offline.unity - guid: cf8786fff2eaf7c4b85ff0945d112d2f - - enabled: 1 - path: Assets/Online.unity - guid: 77c702a1fdd299d488f462a24bc99ef0 diff --git a/UnityProject/ProjectSettings/EditorSettings.asset b/UnityProject/ProjectSettings/EditorSettings.asset deleted file mode 100644 index 7b426952..00000000 --- a/UnityProject/ProjectSettings/EditorSettings.asset +++ /dev/null @@ -1,21 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!159 &1 -EditorSettings: - m_ObjectHideFlags: 0 - serializedVersion: 7 - m_ExternalVersionControlSupport: Hidden Meta Files - m_SerializationMode: 2 - m_LineEndingsForNewScripts: 2 - m_DefaultBehaviorMode: 0 - m_SpritePackerMode: 0 - m_SpritePackerPaddingPower: 1 - m_EtcTextureCompressorBehavior: 1 - m_EtcTextureFastCompressor: 1 - m_EtcTextureNormalCompressor: 2 - m_EtcTextureBestCompressor: 4 - m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp - m_ProjectGenerationRootNamespace: - m_UserGeneratedProjectSuffix: - m_CollabEditorSettings: - inProgressEnabled: 1 diff --git a/UnityProject/ProjectSettings/GraphicsSettings.asset b/UnityProject/ProjectSettings/GraphicsSettings.asset deleted file mode 100644 index 6d5c553d..00000000 --- a/UnityProject/ProjectSettings/GraphicsSettings.asset +++ /dev/null @@ -1,66 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!30 &1 -GraphicsSettings: - m_ObjectHideFlags: 0 - serializedVersion: 13 - m_Deferred: - m_Mode: 1 - m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} - m_DeferredReflections: - m_Mode: 1 - m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} - m_ScreenSpaceShadows: - m_Mode: 1 - m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} - m_LegacyDeferred: - m_Mode: 1 - m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} - m_DepthNormals: - m_Mode: 1 - m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} - m_MotionVectors: - m_Mode: 1 - m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} - m_LightHalo: - m_Mode: 1 - m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} - m_LensFlare: - m_Mode: 1 - m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} - m_AlwaysIncludedShaders: - - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} - m_PreloadedShaders: [] - m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, - type: 0} - m_CustomRenderPipeline: {fileID: 0} - m_TransparencySortMode: 0 - m_TransparencySortAxis: {x: 0, y: 0, z: 1} - m_DefaultRenderingPath: 1 - m_DefaultMobileRenderingPath: 1 - m_TierSettings: [] - m_LightmapStripping: 0 - m_FogStripping: 0 - m_InstancingStripping: 0 - m_LightmapKeepPlain: 1 - m_LightmapKeepDirCombined: 1 - m_LightmapKeepDynamicPlain: 1 - m_LightmapKeepDynamicDirCombined: 1 - m_LightmapKeepShadowMask: 1 - m_LightmapKeepSubtractive: 1 - m_FogKeepLinear: 1 - m_FogKeepExp: 1 - m_FogKeepExp2: 1 - m_AlbedoSwatchInfos: [] - m_LightsUseLinearIntensity: 0 - m_LightsUseColorTemperature: 0 - m_LogWhenShaderIsCompiled: 0 - m_AllowEnlightenSupportForUpgradedProject: 1 diff --git a/UnityProject/ProjectSettings/InputManager.asset b/UnityProject/ProjectSettings/InputManager.asset deleted file mode 100644 index 17c8f538..00000000 --- a/UnityProject/ProjectSettings/InputManager.asset +++ /dev/null @@ -1,295 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!13 &1 -InputManager: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Axes: - - serializedVersion: 3 - m_Name: Horizontal - descriptiveName: - descriptiveNegativeName: - negativeButton: left - positiveButton: right - altNegativeButton: a - altPositiveButton: d - gravity: 3 - dead: 0.001 - sensitivity: 3 - snap: 1 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Vertical - descriptiveName: - descriptiveNegativeName: - negativeButton: down - positiveButton: up - altNegativeButton: s - altPositiveButton: w - gravity: 3 - dead: 0.001 - sensitivity: 3 - snap: 1 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire1 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: left ctrl - altNegativeButton: - altPositiveButton: mouse 0 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire2 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: left alt - altNegativeButton: - altPositiveButton: mouse 1 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire3 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: left shift - altNegativeButton: - altPositiveButton: mouse 2 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Jump - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: space - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Mouse X - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0 - sensitivity: 0.1 - snap: 0 - invert: 0 - type: 1 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Mouse Y - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0 - sensitivity: 0.1 - snap: 0 - invert: 0 - type: 1 - axis: 1 - joyNum: 0 - - serializedVersion: 3 - m_Name: Mouse ScrollWheel - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0 - sensitivity: 0.1 - snap: 0 - invert: 0 - type: 1 - axis: 2 - joyNum: 0 - - serializedVersion: 3 - m_Name: Horizontal - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0.19 - sensitivity: 1 - snap: 0 - invert: 0 - type: 2 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Vertical - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0.19 - sensitivity: 1 - snap: 0 - invert: 1 - type: 2 - axis: 1 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire1 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: joystick button 0 - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire2 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: joystick button 1 - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire3 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: joystick button 2 - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Jump - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: joystick button 3 - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Submit - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: return - altNegativeButton: - altPositiveButton: joystick button 0 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Submit - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: enter - altNegativeButton: - altPositiveButton: space - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Cancel - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: escape - altNegativeButton: - altPositiveButton: joystick button 1 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 diff --git a/UnityProject/ProjectSettings/NavMeshAreas.asset b/UnityProject/ProjectSettings/NavMeshAreas.asset deleted file mode 100644 index 3b0b7c3d..00000000 --- a/UnityProject/ProjectSettings/NavMeshAreas.asset +++ /dev/null @@ -1,91 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!126 &1 -NavMeshProjectSettings: - m_ObjectHideFlags: 0 - serializedVersion: 2 - areas: - - name: Walkable - cost: 1 - - name: Not Walkable - cost: 1 - - name: Jump - cost: 2 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - - name: - cost: 1 - m_LastAgentTypeID: -887442657 - m_Settings: - - serializedVersion: 2 - agentTypeID: 0 - agentRadius: 0.5 - agentHeight: 2 - agentSlope: 45 - agentClimb: 0.75 - ledgeDropHeight: 0 - maxJumpAcrossDistance: 0 - minRegionArea: 2 - manualCellSize: 0 - cellSize: 0.16666667 - manualTileSize: 0 - tileSize: 256 - accuratePlacement: 0 - debug: - m_Flags: 0 - m_SettingNames: - - Humanoid diff --git a/UnityProject/ProjectSettings/NetworkManager.asset b/UnityProject/ProjectSettings/NetworkManager.asset deleted file mode 100644 index 5dc6a831..00000000 --- a/UnityProject/ProjectSettings/NetworkManager.asset +++ /dev/null @@ -1,8 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!149 &1 -NetworkManager: - m_ObjectHideFlags: 0 - m_DebugLevel: 0 - m_Sendrate: 15 - m_AssetToPrefab: {} diff --git a/UnityProject/ProjectSettings/PackageManagerSettings.asset b/UnityProject/ProjectSettings/PackageManagerSettings.asset deleted file mode 100644 index 6920e3ad..00000000 --- a/UnityProject/ProjectSettings/PackageManagerSettings.asset +++ /dev/null @@ -1,38 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &1 -MonoBehaviour: - m_ObjectHideFlags: 61 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0} - m_Name: - m_EditorClassIdentifier: - m_ScopedRegistriesSettingsExpanded: 1 - oneTimeWarningShown: 0 - m_Registries: - - m_Id: main - m_Name: - m_Url: https://packages.unity.com - m_Scopes: [] - m_IsDefault: 1 - m_UserSelectedRegistryName: - m_UserAddingNewScopedRegistry: 0 - m_RegistryInfoDraft: - m_ErrorMessage: - m_Original: - m_Id: - m_Name: - m_Url: - m_Scopes: [] - m_IsDefault: 0 - m_Modified: 0 - m_Name: - m_Url: - m_Scopes: - - - m_SelectedScopeIndex: 0 diff --git a/UnityProject/ProjectSettings/Physics2DSettings.asset b/UnityProject/ProjectSettings/Physics2DSettings.asset deleted file mode 100644 index 132ee6bc..00000000 --- a/UnityProject/ProjectSettings/Physics2DSettings.asset +++ /dev/null @@ -1,37 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!19 &1 -Physics2DSettings: - m_ObjectHideFlags: 0 - serializedVersion: 3 - m_Gravity: {x: 0, y: -9.81} - m_DefaultMaterial: {fileID: 0} - m_VelocityIterations: 8 - m_PositionIterations: 3 - m_VelocityThreshold: 1 - m_MaxLinearCorrection: 0.2 - m_MaxAngularCorrection: 8 - m_MaxTranslationSpeed: 100 - m_MaxRotationSpeed: 360 - m_BaumgarteScale: 0.2 - m_BaumgarteTimeOfImpactScale: 0.75 - m_TimeToSleep: 0.5 - m_LinearSleepTolerance: 0.01 - m_AngularSleepTolerance: 2 - m_DefaultContactOffset: 0.01 - m_AutoSimulation: 1 - m_QueriesHitTriggers: 1 - m_QueriesStartInColliders: 1 - m_ChangeStopsCallbacks: 0 - m_CallbacksOnDisable: 1 - m_AutoSyncTransforms: 1 - m_AlwaysShowColliders: 0 - m_ShowColliderSleep: 1 - m_ShowColliderContacts: 0 - m_ShowColliderAABB: 0 - m_ContactArrowScale: 0.2 - m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} - m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} - m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} - m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} - m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/UnityProject/ProjectSettings/PresetManager.asset b/UnityProject/ProjectSettings/PresetManager.asset deleted file mode 100644 index 67a94dae..00000000 --- a/UnityProject/ProjectSettings/PresetManager.asset +++ /dev/null @@ -1,7 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1386491679 &1 -PresetManager: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_DefaultPresets: {} diff --git a/UnityProject/ProjectSettings/ProjectSettings.asset b/UnityProject/ProjectSettings/ProjectSettings.asset deleted file mode 100644 index e98f18d1..00000000 --- a/UnityProject/ProjectSettings/ProjectSettings.asset +++ /dev/null @@ -1,643 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!129 &1 -PlayerSettings: - m_ObjectHideFlags: 0 - serializedVersion: 15 - productGUID: 3a8eb374f996a2c418bdfa5a77cbf2f1 - AndroidProfiler: 0 - AndroidFilterTouchesWhenObscured: 0 - defaultScreenOrientation: 4 - targetDevice: 2 - useOnDemandResources: 0 - accelerometerFrequency: 60 - companyName: Raicuparta - productName: QSF - defaultCursor: {fileID: 0} - cursorHotspot: {x: 0, y: 0} - m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1} - m_ShowUnitySplashScreen: 1 - m_ShowUnitySplashLogo: 1 - m_SplashScreenOverlayOpacity: 1 - m_SplashScreenAnimation: 1 - m_SplashScreenLogoStyle: 1 - m_SplashScreenDrawMode: 0 - m_SplashScreenBackgroundAnimationZoom: 1 - m_SplashScreenLogoAnimationZoom: 1 - m_SplashScreenBackgroundLandscapeAspect: 1 - m_SplashScreenBackgroundPortraitAspect: 1 - m_SplashScreenBackgroundLandscapeUvs: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - m_SplashScreenBackgroundPortraitUvs: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - m_SplashScreenLogos: [] - m_VirtualRealitySplashScreen: {fileID: 0} - m_HolographicTrackingLossScreen: {fileID: 0} - defaultScreenWidth: 1024 - defaultScreenHeight: 768 - defaultScreenWidthWeb: 960 - defaultScreenHeightWeb: 600 - m_StereoRenderingPath: 0 - m_ActiveColorSpace: 0 - m_MTRendering: 1 - m_StackTraceTypes: 010000000100000001000000010000000100000001000000 - iosShowActivityIndicatorOnLoading: -1 - androidShowActivityIndicatorOnLoading: -1 - tizenShowActivityIndicatorOnLoading: -1 - displayResolutionDialog: 1 - iosAppInBackgroundBehavior: 0 - iosAllowHTTPDownload: 1 - allowedAutorotateToPortrait: 1 - allowedAutorotateToPortraitUpsideDown: 1 - allowedAutorotateToLandscapeRight: 1 - allowedAutorotateToLandscapeLeft: 1 - useOSAutorotation: 1 - use32BitDisplayBuffer: 1 - preserveFramebufferAlpha: 0 - disableDepthAndStencilBuffers: 0 - androidBlitType: 0 - defaultIsFullScreen: 1 - defaultIsNativeResolution: 1 - macRetinaSupport: 1 - runInBackground: 0 - captureSingleScreen: 0 - muteOtherAudioSources: 0 - Prepare IOS For Recording: 0 - Force IOS Speakers When Recording: 0 - deferSystemGesturesMode: 0 - hideHomeButton: 0 - submitAnalytics: 1 - usePlayerLog: 1 - bakeCollisionMeshes: 0 - forceSingleInstance: 0 - resizableWindow: 0 - useMacAppStoreValidation: 0 - macAppStoreCategory: public.app-category.games - gpuSkinning: 0 - graphicsJobs: 0 - xboxPIXTextureCapture: 0 - xboxEnableAvatar: 0 - xboxEnableKinect: 0 - xboxEnableKinectAutoTracking: 0 - xboxEnableFitness: 0 - visibleInBackground: 1 - allowFullscreenSwitch: 1 - graphicsJobMode: 0 - macFullscreenMode: 2 - d3d11FullscreenMode: 1 - xboxSpeechDB: 0 - xboxEnableHeadOrientation: 0 - xboxEnableGuest: 0 - xboxEnablePIXSampling: 0 - metalFramebufferOnly: 0 - n3dsDisableStereoscopicView: 0 - n3dsEnableSharedListOpt: 1 - n3dsEnableVSync: 0 - xboxOneResolution: 0 - xboxOneSResolution: 0 - xboxOneXResolution: 3 - xboxOneMonoLoggingLevel: 0 - xboxOneLoggingLevel: 1 - xboxOneDisableEsram: 0 - xboxOnePresentImmediateThreshold: 0 - videoMemoryForVertexBuffers: 0 - psp2PowerMode: 0 - psp2AcquireBGM: 1 - wiiUTVResolution: 0 - wiiUGamePadMSAA: 1 - wiiUSupportsNunchuk: 0 - wiiUSupportsClassicController: 0 - wiiUSupportsBalanceBoard: 0 - wiiUSupportsMotionPlus: 0 - wiiUSupportsProController: 0 - wiiUAllowScreenCapture: 1 - wiiUControllerCount: 0 - m_SupportedAspectRatios: - 4:3: 1 - 5:4: 1 - 16:10: 1 - 16:9: 1 - Others: 1 - bundleVersion: 1.0 - preloadedAssets: [] - metroInputSource: 0 - wsaTransparentSwapchain: 0 - m_HolographicPauseOnTrackingLoss: 1 - xboxOneDisableKinectGpuReservation: 0 - xboxOneEnable7thCore: 0 - vrSettings: - cardboard: - depthFormat: 0 - enableTransitionView: 0 - daydream: - depthFormat: 0 - useSustainedPerformanceMode: 0 - enableVideoLayer: 0 - useProtectedVideoMemory: 0 - minimumSupportedHeadTracking: 0 - maximumSupportedHeadTracking: 1 - hololens: - depthFormat: 1 - depthBufferSharingEnabled: 0 - oculus: - sharedDepthBuffer: 0 - dashSupport: 0 - v2Signing: 0 - protectGraphicsMemory: 0 - useHDRDisplay: 0 - m_ColorGamuts: 00000000 - targetPixelDensity: 30 - resolutionScalingMode: 0 - androidSupportedAspectRatio: 1 - androidMaxAspectRatio: 2.1 - applicationIdentifier: {} - buildNumber: {} - AndroidBundleVersionCode: 1 - AndroidMinSdkVersion: 16 - AndroidTargetSdkVersion: 0 - AndroidPreferredInstallLocation: 1 - aotOptions: - stripEngineCode: 1 - iPhoneStrippingLevel: 0 - iPhoneScriptCallOptimization: 0 - ForceInternetPermission: 0 - ForceSDCardPermission: 0 - CreateWallpaper: 0 - APKExpansionFiles: 0 - keepLoadedShadersAlive: 0 - StripUnusedMeshComponents: 0 - VertexChannelCompressionMask: - serializedVersion: 2 - m_Bits: 238 - iPhoneSdkVersion: 988 - iOSTargetOSVersionString: 7.0 - tvOSSdkVersion: 0 - tvOSRequireExtendedGameController: 0 - tvOSTargetOSVersionString: 9.0 - uIPrerenderedIcon: 0 - uIRequiresPersistentWiFi: 0 - uIRequiresFullScreen: 1 - uIStatusBarHidden: 1 - uIExitOnSuspend: 0 - uIStatusBarStyle: 0 - iPhoneSplashScreen: {fileID: 0} - iPhoneHighResSplashScreen: {fileID: 0} - iPhoneTallHighResSplashScreen: {fileID: 0} - iPhone47inSplashScreen: {fileID: 0} - iPhone55inPortraitSplashScreen: {fileID: 0} - iPhone55inLandscapeSplashScreen: {fileID: 0} - iPhone58inPortraitSplashScreen: {fileID: 0} - iPhone58inLandscapeSplashScreen: {fileID: 0} - iPadPortraitSplashScreen: {fileID: 0} - iPadHighResPortraitSplashScreen: {fileID: 0} - iPadLandscapeSplashScreen: {fileID: 0} - iPadHighResLandscapeSplashScreen: {fileID: 0} - appleTVSplashScreen: {fileID: 0} - appleTVSplashScreen2x: {fileID: 0} - tvOSSmallIconLayers: [] - tvOSSmallIconLayers2x: [] - tvOSLargeIconLayers: [] - tvOSTopShelfImageLayers: [] - tvOSTopShelfImageLayers2x: [] - tvOSTopShelfImageWideLayers: [] - tvOSTopShelfImageWideLayers2x: [] - iOSLaunchScreenType: 0 - iOSLaunchScreenPortrait: {fileID: 0} - iOSLaunchScreenLandscape: {fileID: 0} - iOSLaunchScreenBackgroundColor: - serializedVersion: 2 - rgba: 0 - iOSLaunchScreenFillPct: 100 - iOSLaunchScreenSize: 100 - iOSLaunchScreenCustomXibPath: - iOSLaunchScreeniPadType: 0 - iOSLaunchScreeniPadImage: {fileID: 0} - iOSLaunchScreeniPadBackgroundColor: - serializedVersion: 2 - rgba: 0 - iOSLaunchScreeniPadFillPct: 100 - iOSLaunchScreeniPadSize: 100 - iOSLaunchScreeniPadCustomXibPath: - iOSUseLaunchScreenStoryboard: 0 - iOSLaunchScreenCustomStoryboardPath: - iOSDeviceRequirements: [] - iOSURLSchemes: [] - iOSBackgroundModes: 0 - iOSMetalForceHardShadows: 0 - metalEditorSupport: 1 - metalAPIValidation: 1 - iOSRenderExtraFrameOnPause: 0 - appleDeveloperTeamID: - iOSManualSigningProvisioningProfileID: - tvOSManualSigningProvisioningProfileID: - appleEnableAutomaticSigning: 0 - clonedFromGUID: 00000000000000000000000000000000 - AndroidTargetArchitectures: 5 - AndroidSplashScreenScale: 0 - androidSplashScreen: {fileID: 0} - AndroidKeystoreName: - AndroidKeyaliasName: - AndroidTVCompatibility: 1 - AndroidIsGame: 1 - AndroidEnableTango: 0 - androidEnableBanner: 1 - androidUseLowAccuracyLocation: 0 - m_AndroidBanners: - - width: 320 - height: 180 - banner: {fileID: 0} - androidGamepadSupportLevel: 0 - resolutionDialogBanner: {fileID: 0} - m_BuildTargetIcons: [] - m_BuildTargetBatching: [] - m_BuildTargetGraphicsAPIs: [] - m_BuildTargetVRSettings: [] - m_BuildTargetEnableVuforiaSettings: [] - openGLRequireES31: 0 - openGLRequireES31AEP: 0 - m_TemplateCustomTags: {} - mobileMTRendering: - Android: 1 - iPhone: 1 - tvOS: 1 - m_BuildTargetGroupLightmapEncodingQuality: [] - wiiUTitleID: 0005000011000000 - wiiUGroupID: 00010000 - wiiUCommonSaveSize: 4096 - wiiUAccountSaveSize: 2048 - wiiUOlvAccessKey: 0 - wiiUTinCode: 0 - wiiUJoinGameId: 0 - wiiUJoinGameModeMask: 0000000000000000 - wiiUCommonBossSize: 0 - wiiUAccountBossSize: 0 - wiiUAddOnUniqueIDs: [] - wiiUMainThreadStackSize: 3072 - wiiULoaderThreadStackSize: 1024 - wiiUSystemHeapSize: 128 - wiiUTVStartupScreen: {fileID: 0} - wiiUGamePadStartupScreen: {fileID: 0} - wiiUDrcBufferDisabled: 0 - wiiUProfilerLibPath: - playModeTestRunnerEnabled: 0 - actionOnDotNetUnhandledException: 1 - enableInternalProfiler: 0 - logObjCUncaughtExceptions: 1 - enableCrashReportAPI: 0 - cameraUsageDescription: - locationUsageDescription: - microphoneUsageDescription: - switchNetLibKey: - switchSocketMemoryPoolSize: 6144 - switchSocketAllocatorPoolSize: 128 - switchSocketConcurrencyLimit: 14 - switchScreenResolutionBehavior: 2 - switchUseCPUProfiler: 0 - switchApplicationID: 0x01004b9000490000 - switchNSODependencies: - switchTitleNames_0: - switchTitleNames_1: - switchTitleNames_2: - switchTitleNames_3: - switchTitleNames_4: - switchTitleNames_5: - switchTitleNames_6: - switchTitleNames_7: - switchTitleNames_8: - switchTitleNames_9: - switchTitleNames_10: - switchTitleNames_11: - switchTitleNames_12: - switchTitleNames_13: - switchTitleNames_14: - switchPublisherNames_0: - switchPublisherNames_1: - switchPublisherNames_2: - switchPublisherNames_3: - switchPublisherNames_4: - switchPublisherNames_5: - switchPublisherNames_6: - switchPublisherNames_7: - switchPublisherNames_8: - switchPublisherNames_9: - switchPublisherNames_10: - switchPublisherNames_11: - switchPublisherNames_12: - switchPublisherNames_13: - switchPublisherNames_14: - switchIcons_0: {fileID: 0} - switchIcons_1: {fileID: 0} - switchIcons_2: {fileID: 0} - switchIcons_3: {fileID: 0} - switchIcons_4: {fileID: 0} - switchIcons_5: {fileID: 0} - switchIcons_6: {fileID: 0} - switchIcons_7: {fileID: 0} - switchIcons_8: {fileID: 0} - switchIcons_9: {fileID: 0} - switchIcons_10: {fileID: 0} - switchIcons_11: {fileID: 0} - switchIcons_12: {fileID: 0} - switchIcons_13: {fileID: 0} - switchIcons_14: {fileID: 0} - switchSmallIcons_0: {fileID: 0} - switchSmallIcons_1: {fileID: 0} - switchSmallIcons_2: {fileID: 0} - switchSmallIcons_3: {fileID: 0} - switchSmallIcons_4: {fileID: 0} - switchSmallIcons_5: {fileID: 0} - switchSmallIcons_6: {fileID: 0} - switchSmallIcons_7: {fileID: 0} - switchSmallIcons_8: {fileID: 0} - switchSmallIcons_9: {fileID: 0} - switchSmallIcons_10: {fileID: 0} - switchSmallIcons_11: {fileID: 0} - switchSmallIcons_12: {fileID: 0} - switchSmallIcons_13: {fileID: 0} - switchSmallIcons_14: {fileID: 0} - switchManualHTML: - switchAccessibleURLs: - switchLegalInformation: - switchMainThreadStackSize: 1048576 - switchPresenceGroupId: - switchLogoHandling: 0 - switchReleaseVersion: 0 - switchDisplayVersion: 1.0.0 - switchStartupUserAccount: 0 - switchTouchScreenUsage: 0 - switchSupportedLanguagesMask: 0 - switchLogoType: 0 - switchApplicationErrorCodeCategory: - switchUserAccountSaveDataSize: 0 - switchUserAccountSaveDataJournalSize: 0 - switchApplicationAttribute: 0 - switchCardSpecSize: -1 - switchCardSpecClock: -1 - switchRatingsMask: 0 - switchRatingsInt_0: 0 - switchRatingsInt_1: 0 - switchRatingsInt_2: 0 - switchRatingsInt_3: 0 - switchRatingsInt_4: 0 - switchRatingsInt_5: 0 - switchRatingsInt_6: 0 - switchRatingsInt_7: 0 - switchRatingsInt_8: 0 - switchRatingsInt_9: 0 - switchRatingsInt_10: 0 - switchRatingsInt_11: 0 - switchLocalCommunicationIds_0: - switchLocalCommunicationIds_1: - switchLocalCommunicationIds_2: - switchLocalCommunicationIds_3: - switchLocalCommunicationIds_4: - switchLocalCommunicationIds_5: - switchLocalCommunicationIds_6: - switchLocalCommunicationIds_7: - switchParentalControl: 0 - switchAllowsScreenshot: 1 - switchAllowsVideoCapturing: 1 - switchAllowsRuntimeAddOnContentInstall: 0 - switchDataLossConfirmation: 0 - switchUserAccountLockEnabled: 0 - switchSupportedNpadStyles: 3 - switchSocketConfigEnabled: 0 - switchTcpInitialSendBufferSize: 32 - switchTcpInitialReceiveBufferSize: 64 - switchTcpAutoSendBufferSizeMax: 256 - switchTcpAutoReceiveBufferSizeMax: 256 - switchUdpSendBufferSize: 9 - switchUdpReceiveBufferSize: 42 - switchSocketBufferEfficiency: 4 - switchSocketInitializeEnabled: 1 - switchNetworkInterfaceManagerInitializeEnabled: 1 - switchPlayerConnectionEnabled: 1 - ps4NPAgeRating: 12 - ps4NPTitleSecret: - ps4NPTrophyPackPath: - ps4ParentalLevel: 11 - ps4ContentID: ED1633-NPXX51362_00-0000000000000000 - ps4Category: 0 - ps4MasterVersion: 01.00 - ps4AppVersion: 01.00 - ps4AppType: 0 - ps4ParamSfxPath: - ps4VideoOutPixelFormat: 0 - ps4VideoOutInitialWidth: 1920 - ps4VideoOutBaseModeInitialWidth: 1920 - ps4VideoOutReprojectionRate: 60 - ps4PronunciationXMLPath: - ps4PronunciationSIGPath: - ps4BackgroundImagePath: - ps4StartupImagePath: - ps4StartupImagesFolder: - ps4IconImagesFolder: - ps4SaveDataImagePath: - ps4SdkOverride: - ps4BGMPath: - ps4ShareFilePath: - ps4ShareOverlayImagePath: - ps4PrivacyGuardImagePath: - ps4NPtitleDatPath: - ps4RemotePlayKeyAssignment: -1 - ps4RemotePlayKeyMappingDir: - ps4PlayTogetherPlayerCount: 0 - ps4EnterButtonAssignment: 1 - ps4ApplicationParam1: 0 - ps4ApplicationParam2: 0 - ps4ApplicationParam3: 0 - ps4ApplicationParam4: 0 - ps4DownloadDataSize: 0 - ps4GarlicHeapSize: 2048 - ps4ProGarlicHeapSize: 2560 - ps4Passcode: frAQBc8Wsa1xVPfvJcrgRYwTiizs2trQ - ps4pnSessions: 1 - ps4pnPresence: 1 - ps4pnFriends: 1 - ps4pnGameCustomData: 1 - playerPrefsSupport: 0 - restrictedAudioUsageRights: 0 - ps4UseResolutionFallback: 0 - ps4ReprojectionSupport: 0 - ps4UseAudio3dBackend: 0 - ps4SocialScreenEnabled: 0 - ps4ScriptOptimizationLevel: 0 - ps4Audio3dVirtualSpeakerCount: 14 - ps4attribCpuUsage: 0 - ps4PatchPkgPath: - ps4PatchLatestPkgPath: - ps4PatchChangeinfoPath: - ps4PatchDayOne: 0 - ps4attribUserManagement: 0 - ps4attribMoveSupport: 0 - ps4attrib3DSupport: 0 - ps4attribShareSupport: 0 - ps4attribExclusiveVR: 0 - ps4disableAutoHideSplash: 0 - ps4videoRecordingFeaturesUsed: 0 - ps4contentSearchFeaturesUsed: 0 - ps4attribEyeToEyeDistanceSettingVR: 0 - ps4IncludedModules: [] - monoEnv: - psp2Splashimage: {fileID: 0} - psp2NPTrophyPackPath: - psp2NPSupportGBMorGJP: 0 - psp2NPAgeRating: 12 - psp2NPTitleDatPath: - psp2NPCommsID: - psp2NPCommunicationsID: - psp2NPCommsPassphrase: - psp2NPCommsSig: - psp2ParamSfxPath: - psp2ManualPath: - psp2LiveAreaGatePath: - psp2LiveAreaBackroundPath: - psp2LiveAreaPath: - psp2LiveAreaTrialPath: - psp2PatchChangeInfoPath: - psp2PatchOriginalPackage: - psp2PackagePassword: F69AzBlax3CF3EDNhm3soLBPh71Yexui - psp2KeystoneFile: - psp2MemoryExpansionMode: 0 - psp2DRMType: 0 - psp2StorageType: 0 - psp2MediaCapacity: 0 - psp2DLCConfigPath: - psp2ThumbnailPath: - psp2BackgroundPath: - psp2SoundPath: - psp2TrophyCommId: - psp2TrophyPackagePath: - psp2PackagedResourcesPath: - psp2SaveDataQuota: 10240 - psp2ParentalLevel: 1 - psp2ShortTitle: Not Set - psp2ContentID: IV0000-ABCD12345_00-0123456789ABCDEF - psp2Category: 0 - psp2MasterVersion: 01.00 - psp2AppVersion: 01.00 - psp2TVBootMode: 0 - psp2EnterButtonAssignment: 2 - psp2TVDisableEmu: 0 - psp2AllowTwitterDialog: 1 - psp2Upgradable: 0 - psp2HealthWarning: 0 - psp2UseLibLocation: 0 - psp2InfoBarOnStartup: 0 - psp2InfoBarColor: 0 - psp2ScriptOptimizationLevel: 0 - psmSplashimage: {fileID: 0} - splashScreenBackgroundSourceLandscape: {fileID: 0} - splashScreenBackgroundSourcePortrait: {fileID: 0} - spritePackerPolicy: - webGLMemorySize: 256 - webGLExceptionSupport: 1 - webGLNameFilesAsHashes: 0 - webGLDataCaching: 0 - webGLDebugSymbols: 0 - webGLEmscriptenArgs: - webGLModulesDirectory: - webGLTemplate: APPLICATION:Default - webGLAnalyzeBuildSize: 0 - webGLUseEmbeddedResources: 0 - webGLUseWasm: 0 - webGLCompressionFormat: 1 - scriptingDefineSymbols: {} - platformArchitecture: {} - scriptingBackend: {} - incrementalIl2cppBuild: {} - additionalIl2CppArgs: - scriptingRuntimeVersion: 0 - apiCompatibilityLevelPerPlatform: {} - m_RenderingPath: 1 - m_MobileRenderingPath: 1 - metroPackageName: mp-test - metroPackageVersion: - metroCertificatePath: - metroCertificatePassword: - metroCertificateSubject: - metroCertificateIssuer: - metroCertificateNotAfter: 0000000000000000 - metroApplicationDescription: mp-test - wsaImages: {} - metroTileShortName: - metroCommandLineArgsFile: - metroTileShowName: 0 - metroMediumTileShowName: 0 - metroLargeTileShowName: 0 - metroWideTileShowName: 0 - metroDefaultTileSize: 1 - metroTileForegroundText: 2 - metroTileBackgroundColor: {r: 0.13333334, g: 0.17254902, b: 0.21568628, a: 0} - metroSplashScreenBackgroundColor: {r: 0.12941177, g: 0.17254902, b: 0.21568628, - a: 1} - metroSplashScreenUseBackgroundColor: 0 - platformCapabilities: {} - metroFTAName: - metroFTAFileTypes: [] - metroProtocolName: - metroCompilationOverrides: 1 - tizenProductDescription: - tizenProductURL: - tizenSigningProfileName: - tizenGPSPermissions: 0 - tizenMicrophonePermissions: 0 - tizenDeploymentTarget: - tizenDeploymentTargetType: -1 - tizenMinOSVersion: 1 - n3dsUseExtSaveData: 0 - n3dsCompressStaticMem: 1 - n3dsExtSaveDataNumber: 0x12345 - n3dsStackSize: 131072 - n3dsTargetPlatform: 2 - n3dsRegion: 7 - n3dsMediaSize: 0 - n3dsLogoStyle: 3 - n3dsTitle: GameName - n3dsProductCode: - n3dsApplicationId: 0xFF3FF - XboxOneProductId: - XboxOneUpdateKey: - XboxOneSandboxId: - XboxOneContentId: - XboxOneTitleId: - XboxOneSCId: - XboxOneGameOsOverridePath: - XboxOnePackagingOverridePath: - XboxOneAppManifestOverridePath: - XboxOnePackageEncryption: 0 - XboxOnePackageUpdateGranularity: 2 - XboxOneDescription: - XboxOneLanguage: - - enus - XboxOneCapability: [] - XboxOneGameRating: {} - XboxOneIsContentPackage: 0 - XboxOneEnableGPUVariability: 0 - XboxOneSockets: {} - XboxOneSplashScreen: {fileID: 0} - XboxOneAllowedProductIds: [] - XboxOnePersistentLocalStorageSize: 0 - XboxOneXTitleMemory: 8 - xboxOneScriptCompiler: 0 - vrEditorSettings: - daydream: - daydreamIconForeground: {fileID: 0} - daydreamIconBackground: {fileID: 0} - cloudServicesEnabled: {} - facebookSdkVersion: 7.9.4 - apiCompatibilityLevel: 2 - cloudProjectId: - projectName: - organizationId: - cloudEnabled: 0 - enableNativePlatformBackendsForNewInputSystem: 0 - disableOldInputManagerSupport: 0 diff --git a/UnityProject/ProjectSettings/ProjectVersion.txt b/UnityProject/ProjectSettings/ProjectVersion.txt deleted file mode 100644 index b6a81cb4..00000000 --- a/UnityProject/ProjectSettings/ProjectVersion.txt +++ /dev/null @@ -1,2 +0,0 @@ -m_EditorVersion: 2019.4.27f1 -m_EditorVersionWithRevision: 2019.4.27f1 (23dc10685eb4) diff --git a/UnityProject/ProjectSettings/QualitySettings.asset b/UnityProject/ProjectSettings/QualitySettings.asset deleted file mode 100644 index 05daac3c..00000000 --- a/UnityProject/ProjectSettings/QualitySettings.asset +++ /dev/null @@ -1,191 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!47 &1 -QualitySettings: - m_ObjectHideFlags: 0 - serializedVersion: 5 - m_CurrentQuality: 5 - m_QualitySettings: - - serializedVersion: 2 - name: Very Low - pixelLightCount: 0 - shadows: 0 - shadowResolution: 0 - shadowProjection: 1 - shadowCascades: 1 - shadowDistance: 15 - shadowNearPlaneOffset: 3 - shadowCascade2Split: 0.33333334 - shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} - shadowmaskMode: 0 - blendWeights: 1 - textureQuality: 1 - anisotropicTextures: 0 - antiAliasing: 0 - softParticles: 0 - softVegetation: 0 - realtimeReflectionProbes: 0 - billboardsFaceCameraPosition: 0 - vSyncCount: 0 - lodBias: 0.3 - maximumLODLevel: 0 - particleRaycastBudget: 4 - asyncUploadTimeSlice: 2 - asyncUploadBufferSize: 4 - resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] - - serializedVersion: 2 - name: Low - pixelLightCount: 0 - shadows: 0 - shadowResolution: 0 - shadowProjection: 1 - shadowCascades: 1 - shadowDistance: 20 - shadowNearPlaneOffset: 3 - shadowCascade2Split: 0.33333334 - shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} - shadowmaskMode: 0 - blendWeights: 2 - textureQuality: 0 - anisotropicTextures: 0 - antiAliasing: 0 - softParticles: 0 - softVegetation: 0 - realtimeReflectionProbes: 0 - billboardsFaceCameraPosition: 0 - vSyncCount: 0 - lodBias: 0.4 - maximumLODLevel: 0 - particleRaycastBudget: 16 - asyncUploadTimeSlice: 2 - asyncUploadBufferSize: 4 - resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] - - serializedVersion: 2 - name: Medium - pixelLightCount: 1 - shadows: 1 - shadowResolution: 0 - shadowProjection: 1 - shadowCascades: 1 - shadowDistance: 20 - shadowNearPlaneOffset: 3 - shadowCascade2Split: 0.33333334 - shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} - shadowmaskMode: 0 - blendWeights: 2 - textureQuality: 0 - anisotropicTextures: 1 - antiAliasing: 0 - softParticles: 0 - softVegetation: 0 - realtimeReflectionProbes: 0 - billboardsFaceCameraPosition: 0 - vSyncCount: 1 - lodBias: 0.7 - maximumLODLevel: 0 - particleRaycastBudget: 64 - asyncUploadTimeSlice: 2 - asyncUploadBufferSize: 4 - resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] - - serializedVersion: 2 - name: High - pixelLightCount: 2 - shadows: 2 - shadowResolution: 1 - shadowProjection: 1 - shadowCascades: 2 - shadowDistance: 40 - shadowNearPlaneOffset: 3 - shadowCascade2Split: 0.33333334 - shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} - shadowmaskMode: 1 - blendWeights: 2 - textureQuality: 0 - anisotropicTextures: 1 - antiAliasing: 0 - softParticles: 0 - softVegetation: 1 - realtimeReflectionProbes: 1 - billboardsFaceCameraPosition: 1 - vSyncCount: 1 - lodBias: 1 - maximumLODLevel: 0 - particleRaycastBudget: 256 - asyncUploadTimeSlice: 2 - asyncUploadBufferSize: 4 - resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] - - serializedVersion: 2 - name: Very High - pixelLightCount: 3 - shadows: 2 - shadowResolution: 2 - shadowProjection: 1 - shadowCascades: 2 - shadowDistance: 70 - shadowNearPlaneOffset: 3 - shadowCascade2Split: 0.33333334 - shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} - shadowmaskMode: 1 - blendWeights: 4 - textureQuality: 0 - anisotropicTextures: 2 - antiAliasing: 2 - softParticles: 1 - softVegetation: 1 - realtimeReflectionProbes: 1 - billboardsFaceCameraPosition: 1 - vSyncCount: 1 - lodBias: 1.5 - maximumLODLevel: 0 - particleRaycastBudget: 1024 - asyncUploadTimeSlice: 2 - asyncUploadBufferSize: 4 - resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] - - serializedVersion: 2 - name: Ultra - pixelLightCount: 4 - shadows: 2 - shadowResolution: 2 - shadowProjection: 1 - shadowCascades: 4 - shadowDistance: 150 - shadowNearPlaneOffset: 3 - shadowCascade2Split: 0.33333334 - shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} - shadowmaskMode: 1 - blendWeights: 4 - textureQuality: 0 - anisotropicTextures: 2 - antiAliasing: 2 - softParticles: 1 - softVegetation: 1 - realtimeReflectionProbes: 1 - billboardsFaceCameraPosition: 1 - vSyncCount: 1 - lodBias: 2 - maximumLODLevel: 0 - particleRaycastBudget: 4096 - asyncUploadTimeSlice: 2 - asyncUploadBufferSize: 4 - resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] - m_PerPlatformDefaultQuality: - Android: 2 - Nintendo 3DS: 5 - Nintendo Switch: 5 - PS4: 5 - PSM: 5 - PSP2: 2 - Standalone: 5 - Tizen: 2 - WebGL: 3 - WiiU: 5 - Windows Store Apps: 5 - XboxOne: 5 - iPhone: 2 - tvOS: 2 diff --git a/UnityProject/ProjectSettings/TagManager.asset b/UnityProject/ProjectSettings/TagManager.asset deleted file mode 100644 index 1c92a784..00000000 --- a/UnityProject/ProjectSettings/TagManager.asset +++ /dev/null @@ -1,43 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!78 &1 -TagManager: - serializedVersion: 2 - tags: [] - layers: - - Default - - TransparentFX - - Ignore Raycast - - - - Water - - UI - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - m_SortingLayers: - - name: Default - uniqueID: 0 - locked: 0 diff --git a/UnityProject/ProjectSettings/TimeManager.asset b/UnityProject/ProjectSettings/TimeManager.asset deleted file mode 100644 index 558a017e..00000000 --- a/UnityProject/ProjectSettings/TimeManager.asset +++ /dev/null @@ -1,9 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!5 &1 -TimeManager: - m_ObjectHideFlags: 0 - Fixed Timestep: 0.02 - Maximum Allowed Timestep: 0.33333334 - m_TimeScale: 1 - Maximum Particle Timestep: 0.03 diff --git a/UnityProject/ProjectSettings/UnityConnectSettings.asset b/UnityProject/ProjectSettings/UnityConnectSettings.asset deleted file mode 100644 index 1be46005..00000000 --- a/UnityProject/ProjectSettings/UnityConnectSettings.asset +++ /dev/null @@ -1,34 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!310 &1 -UnityConnectSettings: - m_ObjectHideFlags: 0 - m_Enabled: 1 - m_TestMode: 0 - m_TestEventUrl: - m_TestConfigUrl: - m_TestInitMode: 0 - CrashReportingSettings: - m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes - m_NativeEventUrl: https://perf-events.cloud.unity3d.com/symbolicate - m_Enabled: 0 - m_CaptureEditorExceptions: 1 - UnityPurchasingSettings: - m_Enabled: 0 - m_TestMode: 0 - UnityAnalyticsSettings: - m_Enabled: 0 - m_InitializeOnStartup: 1 - m_TestMode: 0 - m_TestEventUrl: - m_TestConfigUrl: - UnityAdsSettings: - m_Enabled: 0 - m_InitializeOnStartup: 1 - m_TestMode: 0 - m_IosGameId: - m_AndroidGameId: - m_GameIds: {} - m_GameId: - PerformanceReportingSettings: - m_Enabled: 0 diff --git a/UnityProject/ProjectSettings/VFXManager.asset b/UnityProject/ProjectSettings/VFXManager.asset deleted file mode 100644 index 3a95c98b..00000000 --- a/UnityProject/ProjectSettings/VFXManager.asset +++ /dev/null @@ -1,12 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!937362698 &1 -VFXManager: - m_ObjectHideFlags: 0 - m_IndirectShader: {fileID: 0} - m_CopyBufferShader: {fileID: 0} - m_SortShader: {fileID: 0} - m_StripUpdateShader: {fileID: 0} - m_RenderPipeSettingsPath: - m_FixedTimeStep: 0.016666668 - m_MaxDeltaTime: 0.05 diff --git a/UnityProject/ProjectSettings/XRSettings.asset b/UnityProject/ProjectSettings/XRSettings.asset deleted file mode 100644 index 482590c1..00000000 --- a/UnityProject/ProjectSettings/XRSettings.asset +++ /dev/null @@ -1,10 +0,0 @@ -{ - "m_SettingKeys": [ - "VR Device Disabled", - "VR Device User Alert" - ], - "m_SettingValues": [ - "False", - "False" - ] -} \ No newline at end of file diff --git a/UnityProject/README.md b/UnityProject/README.md deleted file mode 100644 index ef0ea3f8..00000000 --- a/UnityProject/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# QSB Helper Unity Project - -This Unity project is mainly used for generating asset bundles to be imported by QSB at runtime. It is a Unity 2017.4 project, since that's the version used by Outer Wilds. - -There's a "Build Assetbundles" option that generates the assetbundles in `UnityProject/Assets/AssetBundles`. - -Detailed instructions: - -* Create a new GameObject on the scene; -* Change the name of the GameObject on the inspector panel; -* Add models, behaviours, etc to that GameObject; -* Create a prefab from that GameObject by dragging it from the scene hierarchy to the assets panel (usually at the bottom); -* Select the newly created prefab; -* On the bottom right, select the AssetBundle for that prefab (either from an existing one, or create one); -* Save the scene (File -> Save Scenes); -* Select "Assets" -> "Build Assetbundles" from the top menu; -* The new asset bundles will be generated in `QSB/AssetBundles`; -* When you build QSB in Visual Studio, the asset bundle files will be copied to the mod folder.