From eb84bb298d2b95aec7b2ae12cbf25ac64f25379a Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 6 Nov 2022 15:12:42 -0500 Subject: move to self host --- .../Udon/WrapperModules/ExternVRCInstantiate.cs | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 VRCSDK3Worlds/Assets/Udon/WrapperModules/ExternVRCInstantiate.cs (limited to 'VRCSDK3Worlds/Assets/Udon/WrapperModules/ExternVRCInstantiate.cs') diff --git a/VRCSDK3Worlds/Assets/Udon/WrapperModules/ExternVRCInstantiate.cs b/VRCSDK3Worlds/Assets/Udon/WrapperModules/ExternVRCInstantiate.cs new file mode 100644 index 00000000..70d22e78 --- /dev/null +++ b/VRCSDK3Worlds/Assets/Udon/WrapperModules/ExternVRCInstantiate.cs @@ -0,0 +1,76 @@ +#if !VRC_CLIENT +using System.Collections.Generic; +using UnityEngine; +using VRC.Udon; +using VRC.Udon.Common.Attributes; +using VRC.Udon.Common.Delegates; +using VRC.Udon.Common.Interfaces; +using VRC.Udon.Security.Interfaces; +using VRC.Udon.Wrapper.Modules; + +[assembly: UdonWrapperModule(typeof(ExternVRCInstantiate))] + +namespace VRC.Udon.Wrapper.Modules +{ + public class ExternVRCInstantiate : IUdonWrapperModule + { + public string Name => "VRCInstantiate"; + + private readonly Dictionary _parameterCounts; + private readonly Dictionary _functionDelegates; + private readonly IUdonSecurityBlacklist _blacklist; + + //Passing unused parameter for consistent construction + // ReSharper disable once UnusedParameter.Local + public ExternVRCInstantiate(IUdonComponentGetter componentGetter, IUdonSecurityBlacklist blacklist) + { + _blacklist = blacklist; + _parameterCounts = new Dictionary + { + {"__Instantiate__UnityEngineGameObject__UnityEngineGameObject", 2}, + }; + + _functionDelegates = new Dictionary + { + {"__Instantiate__UnityEngineGameObject__UnityEngineGameObject", __Instantiate__UnityEngineGameObject__UnityEngineGameObject} + }; + } + + public int GetExternFunctionParameterCount(string externFunctionSignature) + { + if(_parameterCounts.TryGetValue(externFunctionSignature, out int numParameters)) + { + return numParameters; + } + + throw new System.NotSupportedException($"Function '{externFunctionSignature}' is not implemented yet"); + } + + public UdonExternDelegate GetExternFunctionDelegate(string externFunctionSignature) + { + if(_functionDelegates.TryGetValue(externFunctionSignature, out UdonExternDelegate externDelegate)) + { + return externDelegate; + } + + throw new System.NotSupportedException($"Function '{externFunctionSignature}' is not implemented yet"); + } + + private void __Instantiate__UnityEngineGameObject__UnityEngineGameObject(IUdonHeap heap, uint[] parameterAddresses) + { + GameObject original = heap.GetHeapVariable(parameterAddresses[0]); + #if !UDON_DISABLE_SECURITY + _blacklist.FilterBlacklisted(ref original); + #endif + + GameObject clone = Object.Instantiate(original); + foreach(UdonBehaviour udonBehaviour in clone.GetComponentsInChildren(true)) + { + UdonManager.Instance.RegisterUdonBehaviour(udonBehaviour); + } + + heap.SetHeapVariable(parameterAddresses[1], clone); + } + } +} +#endif -- cgit v1.2.3-freya