Example #1
0
            private static int OnHandlePartyMessage(void *pMessage, void *pPlayer, byte nMinor)
            {
                PartyEventType eventType = (PartyEventType)nMinor;

                if (!Enum.IsDefined(eventType))
                {
                    return(Hook.CallOriginal(pMessage, pPlayer, nMinor));
                }

                CNWSMessage message   = CNWSMessage.FromPointer(pMessage);
                uint        oidTarget = message.PeekMessage <uint>(0) & 0x7FFFFFFF;

                OnPartyEvent eventData = new OnPartyEvent
                {
                    EventType = eventType,
                    Player    = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer() !,
                    Target    = oidTarget.ToNwObject <NwCreature>() !,
                };

                eventData.Result = new Lazy <bool>(() => !eventData.PreventEvent && Hook.CallOriginal(pMessage, pPlayer, nMinor).ToBool());
                ProcessEvent(eventData);

                return(eventData.Result.Value.ToInt());
            }
        }
Example #2
0
        private static int OnHandlePlayerToServerCheatMessage(void *pMessage, void *pPlayer, byte nMinor)
        {
            CNWSMessage message = CNWSMessage.FromPointer(pMessage);

            if (message == null)
            {
                return(Hook.CallOriginal(pMessage, pPlayer, nMinor));
            }

            NwPlayer?player = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer();

            switch ((MessageCheatMinor)nMinor)
            {
            case MessageCheatMinor.RunScript:
                return(HandleRunScriptEvent(message, player) ? Hook.CallOriginal(pMessage, pPlayer, nMinor) : false.ToInt());

            case MessageCheatMinor.RunScriptChunk:
                return(HandleRunScriptChunkEvent(message, player) ? Hook.CallOriginal(pMessage, pPlayer, nMinor) : false.ToInt());

            case MessageCheatMinor.PlayVisualEffect:
                return(HandleVisualEffectEvent(message, player) ? Hook.CallOriginal(pMessage, pPlayer, nMinor) : false.ToInt());

            default:
                return(Hook.CallOriginal(pMessage, pPlayer, nMinor));
            }
        }
Example #3
0
            private static int OnHandleMapPinSetMapPinAtMessage(void *pMessage, void *pPlayer)
            {
                CNWSMessage message = CNWSMessage.FromPointer(pMessage);
                CNWSPlayer  player  = CNWSPlayer.FromPointer(pPlayer);

                if (player == null)
                {
                    return(Hook.CallOriginal(pMessage, pPlayer));
                }

                // Coordinates
                int   offset = 0;
                float x      = message.PeekMessage <float>(offset);

                offset += sizeof(float);
                float y = message.PeekMessage <float>(offset);

                offset += sizeof(float);
                float z = message.PeekMessage <float>(offset);

                offset += sizeof(float);

                // Note
                string note = message.PeekMessageString(offset);

                OnMapPinAddPin eventData = ProcessEvent(new OnMapPinAddPin
                {
                    Player   = player.ToNwPlayer() !,
                    Position = new Vector3(x, y, z),
                    Note     = note,
                });
Example #4
0
            private static void OnStartBarter(void *pMessage, void *pPlayer)
            {
                CNWSMessage message = CNWSMessage.FromPointer(pMessage);

                ProcessEvent(new OnBarterStart
                {
                    Initiator = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer() !,
                    Target    = (message.PeekMessage <uint>(0) & 0x7FFFFFFF).ToNwPlayer() !,
                });
Example #5
0
            private static int OnHandleMapPinDestroyMapPinMessage(void *pMessage, void *pPlayer)
            {
                CNWSMessage message = CNWSMessage.FromPointer(pMessage);
                CNWSPlayer  player  = CNWSPlayer.FromPointer(pPlayer);

                if (player == null)
                {
                    return(Hook.CallOriginal(pMessage, pPlayer));
                }

                // Id
                int id = message.PeekMessage <int>(0);

                OnMapPinDestroyPin eventData = ProcessEvent(new OnMapPinDestroyPin
                {
                    Player = player.ToNwPlayer() !,
                    Id     = id,
                });
Example #6
0
        private int OnSendServerToPlayerChatMessage(void *pMessage, ChatChannel nChatMessageType, uint oidSpeaker, void *sSpeakerMessage, uint nTellPlayerId, void *tellName)
        {
            if (!isEventHooked && !customHearingDistances)
            {
                return(sendServerToPlayerChatMessageHook.CallOriginal(pMessage, nChatMessageType, oidSpeaker, sSpeakerMessage, nTellPlayerId, tellName));
            }

            CNWSMessage message        = CNWSMessage.FromPointer(pMessage);
            CExoString  speakerMessage = CExoString.FromPointer(sSpeakerMessage);
            NwObject    speaker        = oidSpeaker.ToNwObject() !;

            bool skipMessage = ProcessEvent(nChatMessageType, speakerMessage.ToString(), speaker, NwPlayer.FromPlayerId(nTellPlayerId));

            if (skipMessage)
            {
                return(false.ToInt());
            }

            if (!customHearingDistances)
            {
                return(sendServerToPlayerChatMessageHook.CallOriginal(pMessage, nChatMessageType, oidSpeaker, sSpeakerMessage, nTellPlayerId, tellName));
            }

            CExoLinkedListInternal playerList = LowLevel.ServerExoApp.m_pcExoAppInternal.m_pNWSPlayerList.m_pcExoLinkedListInternal;

            if (playerList == null)
            {
                return(false.ToInt());
            }

            if (nChatMessageType == ChatChannel.PlayerShout && nwServer.ServerInfo.PlayOptions.DisallowShouting)
            {
                nChatMessageType = ChatChannel.PlayerTalk;
            }

            if (nChatMessageType != ChatChannel.PlayerTalk &&
                nChatMessageType != ChatChannel.PlayerWhisper &&
                nChatMessageType != ChatChannel.DmTalk &&
                nChatMessageType != ChatChannel.DmWhisper)
            {
                return(sendServerToPlayerChatMessageHook.CallOriginal(pMessage, nChatMessageType, oidSpeaker, sSpeakerMessage, nTellPlayerId, tellName));
            }

            NwGameObject?speakerGameObject = speaker as NwGameObject;
            NwArea?      speakerArea       = speakerGameObject?.Area;

            foreach (NwPlayer player in NwModule.Instance.Players)
            {
                NwCreature?controlledCreature = player.ControlledCreature;

                if (controlledCreature == null || speakerArea != null && speakerArea != controlledCreature.Area)
                {
                    continue;
                }

                float hearDistance = GetPlayerChatHearingDistance(player, nChatMessageType);
                if (speakerGameObject != null && controlledCreature.DistanceSquared(speakerGameObject) > hearDistance * hearDistance)
                {
                    continue;
                }

                switch (nChatMessageType)
                {
                case ChatChannel.PlayerTalk:
                    message.SendServerToPlayerChat_Talk(player.Player.m_nPlayerID, speaker, speakerMessage);
                    break;

                case ChatChannel.DmTalk:
                    message.SendServerToPlayerChat_DM_Talk(player.Player.m_nPlayerID, speaker, speakerMessage);
                    break;

                case ChatChannel.PlayerWhisper:
                    message.SendServerToPlayerChat_Whisper(player.Player.m_nPlayerID, speaker, speakerMessage);
                    break;

                case ChatChannel.DmWhisper:
                    message.SendServerToPlayerChat_DM_Whisper(player.Player.m_nPlayerID, speaker, speakerMessage);
                    break;
                }
            }

            return(true.ToInt());
        }