protected override void InternalRefreshBackingDataHashSet()
        {
            try
            {
                if (m_rawDataHashSetResourceLock.Owned)
                {
                    return;
                }
                if (WorldManager.Instance.IsWorldSaving)
                {
                    return;
                }
                if (WorldManager.Instance.InternalGetResourceLock() == null)
                {
                    return;
                }
                if (WorldManager.Instance.InternalGetResourceLock().Owned)
                {
                    return;
                }

                m_rawDataHashSetResourceLock.AcquireExclusive();

                var rawValue = BaseObject.InvokeStaticMethod(InternalType, ObjectManagerGetEntityHashSet);
                if (rawValue == null)
                {
                    return;
                }

                //Create/Clear the hash set
                if (m_rawDataHashSet == null)
                {
                    m_rawDataHashSet = new HashSet <object>();
                }
                else
                {
                    m_rawDataHashSet.Clear();
                }

                //Only allow valid entities in the hash set
                foreach (var entry in UtilityFunctions.ConvertHashSet(rawValue))
                {
                    if (!IsValidEntity(entry))
                    {
                        continue;
                    }

                    m_rawDataHashSet.Add(entry);
                }

                m_rawDataHashSetResourceLock.ReleaseExclusive();
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
                m_rawDataHashSetResourceLock.ReleaseExclusive();
            }
        }
Esempio n. 2
0
        protected override void InternalRefreshBackingDataHashSet( )
        {
            try
            {
                if (!CanRefresh)
                {
                    return;
                }

                m_rawDataHashSetResourceLock.AcquireExclusive( );

                object rawValue = MyEntities.GetEntities( );
                if (rawValue == null)
                {
                    return;
                }

                //Create/Clear the hash set
                if (m_rawDataHashSet == null)
                {
                    m_rawDataHashSet = new HashSet <object>( );
                }
                else
                {
                    m_rawDataHashSet.Clear( );
                }

                //Only allow valid entities in the hash set
                foreach (object entry in UtilityFunctions.ConvertHashSet(rawValue))
                {
                    if (!IsValidEntity(entry))
                    {
                        continue;
                    }

                    m_rawDataHashSet.Add(entry);
                }

                m_rawDataHashSetResourceLock.ReleaseExclusive( );
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
                if (m_rawDataHashSetResourceLock.Owned)
                {
                    m_rawDataHashSetResourceLock.ReleaseExclusive( );
                }
            }
        }
        protected virtual void InternalRefreshBackingDataHashSet()
        {
            try
            {
                if (m_rawDataHashSetResourceLock.Owned)
                {
                    return;
                }
                if (WorldManager.Instance.IsWorldSaving)
                {
                    return;
                }
                if (WorldManager.Instance.InternalGetResourceLock() == null)
                {
                    return;
                }
                if (WorldManager.Instance.InternalGetResourceLock().Owned)
                {
                    return;
                }

                m_rawDataHashSetResourceLock.AcquireExclusive();

                if (m_backingObject == null)
                {
                    return;
                }
                var rawValue = BaseObject.InvokeEntityMethod(m_backingObject, m_backingSourceMethod);
                if (rawValue == null)
                {
                    return;
                }
                m_rawDataHashSet = UtilityFunctions.ConvertHashSet(rawValue);

                m_rawDataHashSetResourceLock.ReleaseExclusive();
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
                m_rawDataHashSetResourceLock.ReleaseExclusive();
            }
        }
Esempio n. 4
0
        internal static bool RegisterCustomPacketHandler(PacketRegistrationType registrationType, Type packetType, MethodInfo handler, Type baseNetManagerType)
        {
            try
            {
                if (m_registerPacketHandlerMethod == null)
                {
                    return(false);
                }
                if (m_registerPacketHandlerMethod2 == null)
                {
                    return(false);
                }
                if (m_registerPacketHandlerMethod3 == null)
                {
                    return(false);
                }
                if (packetType == null)
                {
                    return(false);
                }
                if (handler == null)
                {
                    return(false);
                }

                //Find the old packet handler
                Type             masterNetManagerType        = SandboxGameAssemblyWrapper.Instance.GetAssemblyType(NetworkManager.InternalNetManagerNamespace, NetworkManager.InternalNetManagerClass);
                FieldInfo        packetRegisteryHashSetField = masterNetManagerType.GetField("9858E5CD512FFA5633683B9551FA4C30", BindingFlags.NonPublic | BindingFlags.Static);
                Object           packetRegisteryHashSetRaw   = packetRegisteryHashSetField.GetValue(null);
                HashSet <Object> packetRegisteryHashSet      = UtilityFunctions.ConvertHashSet(packetRegisteryHashSetRaw);
                if (packetRegisteryHashSet.Count == 0)
                {
                    return(false);
                }
                Object        matchedHandler     = null;
                List <Object> matchedHandlerList = new List <object>();
                List <Type>   messageTypes       = new List <Type>();
                foreach (var entry in packetRegisteryHashSet)
                {
                    FieldInfo delegateField   = entry.GetType().GetField("C2AEC105AF9AB1EF82105555583139FC");
                    Type      fieldType       = delegateField.FieldType;
                    Type[]    genericArgs     = fieldType.GetGenericArguments();
                    Type[]    messageTypeArgs = genericArgs[1].GetGenericArguments();
                    Type      messageType     = messageTypeArgs[0];
                    if (messageType == packetType)
                    {
                        matchedHandler = entry;
                        matchedHandlerList.Add(entry);
                    }

                    messageTypes.Add(messageType);
                }

                if (matchedHandlerList.Count > 1)
                {
                    LogManager.APILog.WriteLine("Found more than 1 packet handler match for type '" + packetType.Name + "'");
                    return(false);
                }

                if (matchedHandler == null)
                {
                    return(false);
                }

                FieldInfo         field = matchedHandler.GetType().GetField("C2AEC105AF9AB1EF82105555583139FC", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object            value = field.GetValue(matchedHandler);
                FieldInfo         secondaryFlagsField = matchedHandler.GetType().GetField("655022D3B2BE47EBCBA675CCE8B784AD", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object            secondaryFlags      = secondaryFlagsField.GetValue(matchedHandler);
                MulticastDelegate action  = (MulticastDelegate)value;
                object            target  = action.Target;
                FieldInfo         field2  = target.GetType().GetField("F774FA5087F549F79181BD64E7B7FF30", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object            value2  = field2.GetValue(target);
                MulticastDelegate action2 = (MulticastDelegate)value2;
                object            target2 = action2.Target;

                string field3Name          = "";
                string flagsFieldName      = "";
                string serializerFieldName = "";
                switch (registrationType)
                {
                case PacketRegistrationType.Static:
                    field3Name          = "2919BD18904683E267BFC1B48709D971";
                    flagsFieldName      = "0723D9EDBE6B0BE979D08F70F06DA741";
                    serializerFieldName = "9F70C9F89F36D5FC6C1EB816AFF491A9";
                    break;

                case PacketRegistrationType.Instance:
                    field3Name          = "F6EE81B03BFA4E50FF9E5E08DA897D98";
                    flagsFieldName      = "A766151383CE73157E57B8ACCB430B04";
                    serializerFieldName = "501AE44AC35E909FEB7EAEE4264D3398";
                    break;

                case PacketRegistrationType.Timespan:
                    field3Name          = "B76A60C8C0680C4AD569366502B8CF47";
                    flagsFieldName      = "90FCC62CB555FB7216BD38667979B221";
                    serializerFieldName = "DB0C5A72269DAB99179543BE08EEADAB";
                    break;

                default:
                    return(false);
                }
                FieldInfo         field3  = target2.GetType().GetField(field3Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object            value3  = field3.GetValue(target2);
                MulticastDelegate action3 = (MulticastDelegate)value3;

                FieldInfo flagsField      = target2.GetType().GetField(flagsFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object    flagsValue      = flagsField.GetValue(target2);
                FieldInfo serializerField = target2.GetType().GetField(serializerFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object    serializerValue = serializerField.GetValue(target2);

                FieldInfo methodBaseField   = action3.GetType().GetField("_methodBase", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                FieldInfo methodPtrField    = action3.GetType().GetField("_methodPtr", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                FieldInfo methodPtrAuxField = action3.GetType().GetField("_methodPtrAux", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

                Delegate handlerAction = CreatePacketHandlerDelegate(registrationType, packetType, handler);

                //Remove the old handler from the registry
                MethodInfo removeMethod = packetRegisteryHashSetRaw.GetType().GetMethod("Remove");
                removeMethod.Invoke(packetRegisteryHashSetRaw, new object[] { matchedHandler });

                //Update the handler delegate with our new method info
                methodBaseField.SetValue(action3, handlerAction.Method);
                methodPtrField.SetValue(action3, methodPtrField.GetValue(handlerAction));
                methodPtrAuxField.SetValue(action3, methodPtrAuxField.GetValue(handlerAction));

                if (baseNetManagerType == null)
                {
                    baseNetManagerType = SandboxGameAssemblyWrapper.Instance.GetAssemblyType("", "48D79F8E3C8922F14D85F6D98237314C");
                }

                //Register the new packet handler
                MethodInfo registerMethod = null;
                switch (registrationType)
                {
                case PacketRegistrationType.Static:
                    registerMethod = m_registerPacketHandlerMethod.MakeGenericMethod(packetType);
                    registerMethod.Invoke(null, new object[] { action3, flagsValue, secondaryFlags, serializerValue });
                    break;

                case PacketRegistrationType.Instance:
                    registerMethod = m_registerPacketHandlerMethod2.MakeGenericMethod(baseNetManagerType, packetType);
                    registerMethod.Invoke(null, new object[] { action3, flagsValue, secondaryFlags, serializerValue });
                    break;

                case PacketRegistrationType.Timespan:
                    registerMethod = m_registerPacketHandlerMethod3.MakeGenericMethod(packetType);
                    registerMethod.Invoke(null, new object[] { action3, flagsValue, secondaryFlags, serializerValue });
                    break;

                default:
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
                return(false);
            }
        }