Пример #1
0
        private int OnSendServerToPlayerPlayerListAdd(void *pMessage, uint nPlayerId, void *pNewPlayer)
        {
            if (PlayerListNameType == OverrideNameType.Original)
            {
                return(sendServerToPlayerPlayerListAddHook.CallOriginal(pMessage, nPlayerId, pNewPlayer));
            }

            if (!ShowOverridesToDM && nPlayerId == PlayerIdConstants.AllGameMasters)
            {
                return(sendServerToPlayerPlayerListAddHook.CallOriginal(pMessage, nPlayerId, pNewPlayer));
            }

            NwPlayer?observer = NwPlayer.FromPlayerId(nPlayerId);
            NwPlayer?target   = CNWSPlayer.FromPointer(pNewPlayer).ToNwPlayer();

            if (target == null)
            {
                return(sendServerToPlayerPlayerListAddHook.CallOriginal(pMessage, nPlayerId, pNewPlayer));
            }

            PlayerNameOverride?nameOverride = GetPlayerNameOverride(target, observer);

            ApplyNameOverride(target, nameOverride, PlayerListNameType);
            int retVal = sendServerToPlayerPlayerListAddHook.CallOriginal(pMessage, nPlayerId, pNewPlayer);

            renameAddedToPlayerList.Add(target);
            RestoreNameOverride(target, nameOverride, PlayerListNameType);

            return(retVal);
        }
Пример #2
0
            private static unsafe int OnSendServerToPlayerCharList(void *pMessage, void *pPlayer)
            {
                CNWSPlayer player = CNWSPlayer.FromPointer(pPlayer);

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

                uint playerId = player.m_nPlayerID;

                CNetLayerPlayerInfo playerInfo = NetLayer.GetPlayerInfo(playerId);
                string ipAddress = NetLayer.GetPlayerAddress(playerId).ToString();

                OnClientConnect eventData = ProcessEvent(new OnClientConnect
                {
                    PlayerName     = playerInfo.m_sPlayerName.ToString(),
                    ClientVersion  = new Version(playerInfo.m_nBuildVersion, playerInfo.m_nPatchRevision),
                    ClientPlatform = (PlayerPlatform)playerInfo.m_nPlatformId,
                    CDKey          = playerInfo.m_lstKeys[0].sPublic.ToString(),
                    DM             = playerInfo.m_bGameMasterPrivileges.ToBool(),
                    IP             = ipAddress,
                });

                if (!eventData.BlockConnection)
                {
                    return(Hook.CallOriginal(pMessage, pPlayer));
                }

                string kickMessage = eventData.KickMessage ?? string.Empty;

                DelayDisconnectPlayer(playerId, kickMessage);
                return(Hook.CallOriginal(pMessage, pPlayer));
            }
Пример #3
0
        /// <summary>
        /// Converts the specified object ID value into a managed player object.
        /// </summary>
        /// <param name="objectId">The object ID to convert.</param>
        /// <param name="playerSearch">Methods to use to resolve the player.</param>
        /// <returns>The associated player for this object, otherwise null.</returns>
        public static unsafe NwPlayer?ToNwPlayer(this uint objectId, PlayerSearch playerSearch = PlayerSearch.All)
        {
            if (objectId == NwObject.Invalid)
            {
                return(null);
            }

            CNWSPlayer?player = null;

            if (playerSearch.HasFlag(PlayerSearch.Controlled))
            {
                player = LowLevel.ServerExoApp.GetClientObjectByObjectId(objectId);
            }

            if ((player == null || player.Pointer == IntPtr.Zero) && playerSearch.HasFlag(PlayerSearch.Login))
            {
                CExoLinkedListInternal players = LowLevel.ServerExoApp.m_pcExoAppInternal.m_pNWSPlayerList.m_pcExoLinkedListInternal;
                for (CExoLinkedListNode node = players.pHead; node != null; node = node.pNext)
                {
                    CNWSPlayer current = CNWSPlayer.FromPointer(node.pObject);
                    if (current.m_oidPCObject == objectId)
                    {
                        player = current;
                        break;
                    }
                }
            }

            return(player != null && player.Pointer != IntPtr.Zero ? new NwPlayer(player) : null);
        }
Пример #4
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());
            }
        }
Пример #5
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));
            }
        }
Пример #6
0
 private static void OnCreatureExamine(void *pMessage, void *pPlayer, uint oidCreature)
 {
     ProcessEvent(new OnExamineObject
     {
         ExaminedBy     = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer() !,
         ExaminedObject = oidCreature.ToNwObject <NwCreature>() !,
     });
Пример #7
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,
                });
Пример #8
0
 private static int OnSendServerToPlayerAreaClientArea(void *pMessage, void *pPlayer, void *pArea, float fX, float fY, float fZ, void *vNewOrientation, int bPlayerIsNewToModule)
 {
     ProcessEvent(new OnServerSendArea
     {
         Area   = CNWSArea.FromPointer(pArea).ToNwObject <NwArea>() !,
         Player = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer() !,
         IsPlayerNewToModule = bPlayerIsNewToModule.ToBool(),
     });
Пример #9
0
 private static void OnExamineTrap(void *pMessage, void *pPlayer, uint oidTrap, void *pCreature, int bSuccess)
 {
     ProcessEvent(new OnExamineTrap
     {
         ExaminedBy     = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer() !,
         ExaminedObject = oidTrap.ToNwObject <NwGameObject>() !,
         Success        = bSuccess.ToBool(),
     });
Пример #10
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() !,
                });
Пример #11
0
        private void OnWriteGameObjUpdateUpdateObject(void *pMessage, void *pPlayer, void *pAreaObject, void *pLastUpdateObject, uint nObjectUpdatesRequired, uint nObjectAppearanceUpdatesRequired)
        {
            CNWSObject areaObject = CNWSObject.FromPointer(pAreaObject);

            NwPlayer?          targetPlayer   = areaObject.m_idSelf.ToNwPlayer(PlayerSearch.Controlled);
            NwPlayer?          observerPlayer = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer();
            PlayerNameOverride?nameOverride   = GetPlayerNameOverride(targetPlayer, observerPlayer);

            ApplyNameOverride(targetPlayer, nameOverride, OverrideNameType.Original);
            writeGameObjUpdateUpdateObjectHook.CallOriginal(pMessage, pPlayer, pAreaObject, pLastUpdateObject, nObjectUpdatesRequired, nObjectAppearanceUpdatesRequired);
            RestoreNameOverride(targetPlayer, nameOverride, OverrideNameType.Original);
        }
Пример #12
0
        private int OnSendServerToPlayerExamineGuiCreatureData(void *pMessage, void *pPlayer, uint oidCreatureID)
        {
            NwPlayer?          targetPlayer   = oidCreatureID.ToNwPlayer(PlayerSearch.Controlled);
            NwPlayer?          observerPlayer = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer();
            PlayerNameOverride?nameOverride   = GetPlayerNameOverride(targetPlayer, observerPlayer);

            ApplyNameOverride(targetPlayer, nameOverride, OverrideNameType.Original);
            int retVal = sendServerToPlayerExamineGuiCreatureDataHook.CallOriginal(pMessage, pPlayer, oidCreatureID);

            RestoreNameOverride(targetPlayer, nameOverride, OverrideNameType.Original);
            return(retVal);
        }
Пример #13
0
        private void OnEatTURD(void *pPlayer, void *pTURD)
        {
            CNWSPlayer     player = CNWSPlayer.FromPointer(pPlayer);
            CNWSPlayerTURD turd   = CNWSPlayerTURD.FromPointer(pTURD);

            ICGameObject?playerObj = player.m_oidNWSObject.ToNwObject()?.Object;

            if (playerObj != null)
            {
                objectStorage[playerObj.Pointer] = GetObjectStorage(turd).Clone();
            }

            eatTURDHook.CallOriginal(pPlayer, pTURD);
        }
Пример #14
0
            private static int OnHandlePlayerToServerLevelUpMessage(void *pMessage, void *pPlayer, byte nMinor)
            {
                if (nMinor != (byte)MessageLevelUpMinor.Begin)
                {
                    return(Hook.CallOriginal(pMessage, pPlayer, nMinor));
                }

                OnClientLevelUpBegin eventData = new OnClientLevelUpBegin
                {
                    Player = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer() !,
                };

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

                return(eventData.Result.Value.ToInt());
            }
        }
Пример #15
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,
                });
Пример #16
0
        private int OnSendServerToPlayerPlayerListDelete(void *pMessage, uint nPlayerId, void *pNewPlayer)
        {
            if (PlayerListNameType == OverrideNameType.Original)
            {
                return(sendServerToPlayerPlayerListDeleteHook.CallOriginal(pMessage, nPlayerId, pNewPlayer));
            }

            if (!ShowOverridesToDM && nPlayerId == PlayerIdConstants.AllGameMasters)
            {
                return(sendServerToPlayerPlayerListDeleteHook.CallOriginal(pMessage, nPlayerId, pNewPlayer));
            }

            NwPlayer?newPlayer = CNWSPlayer.FromPointer(pNewPlayer).ToNwPlayer();

            if (newPlayer != null)
            {
                renameAddedToPlayerList.Remove(newPlayer);
            }

            return(sendServerToPlayerPlayerListDeleteHook.CallOriginal(pMessage, nPlayerId, pNewPlayer));
        }
Пример #17
0
        private void OnDropTURD(void *pPlayer)
        {
            dropTURDHook.CallOriginal(pPlayer);

            // Be very, very paranoid. Bad things happen when the TURD list doesn't exist
            // This can happen when you BootPC() the very first PC to connect to your sever
            //     https://github.com/nwnxee/unified/issues/319
            CExoLinkedListInternal turdList = NwModule.Instance.Module.m_lstTURDList.m_pcExoLinkedListInternal;
            CExoLinkedListNode     pHead;

            if (turdList != null && (pHead = turdList.pHead) != null && pHead.pObject != null)
            {
                CNWSPlayer     player = CNWSPlayer.FromPointer(pPlayer);
                CNWSPlayerTURD turd   = CNWSPlayerTURD.FromPointer(pHead.pObject);

                ICGameObject?playerObj = player.m_oidNWSObject.ToNwObject()?.Object;
                if (playerObj != null)
                {
                    objectStorage[turd.Pointer] = GetObjectStorage(playerObj).Clone();
                }
            }
        }
Пример #18
0
        private int OnSendServerToPlayerPlayerListAll(void *pMessage, void *pPlayer)
        {
            if (PlayerListNameType == OverrideNameType.Original)
            {
                return(sendServerToPlayerPlayerListAllHook.CallOriginal(pMessage, pPlayer));
            }

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

            if (observer == null)
            {
                return(sendServerToPlayerPlayerListAllHook.CallOriginal(pMessage, pPlayer));
            }

            Dictionary <NwPlayer, PlayerNameOverride> nameOverrides = GetOverridesForObserver(observer, true);

            ApplyObserverOverrides(nameOverrides, PlayerListNameType);
            int retVal = sendServerToPlayerPlayerListAllHook.CallOriginal(pMessage, pPlayer);

            RestoreObserverOverrides(nameOverrides, PlayerListNameType);

            return(retVal);
        }
Пример #19
0
 private static int OnSaveServerCharacter(void *pPlayer, int bBackupPlayer)
 {
     OnServerCharacterSave eventData = ProcessEvent(new OnServerCharacterSave
     {
         Player = CNWSPlayer.FromPointer(pPlayer).ToNwPlayer() !,
     });