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, });
private static bool HandleRunScriptChunkEvent(CNWSMessage message, NwPlayer?player) { int offset = 0; string scriptChunk = message.PeekMessageString(offset); offset += scriptChunk.Length + 4; uint oidTarget = message.PeekMessage <uint>(offset); if (oidTarget == NwObject.Invalid) { oidTarget = player?.ControlledCreature; } offset += sizeof(uint); bool wrapIntoMain = (message.PeekMessage <int>(offset) & 0x10).ToBool(); OnDebugRunScriptChunk eventData = ProcessEvent(new OnDebugRunScriptChunk { Player = player, ScriptChunk = scriptChunk, Target = (oidTarget & 0x7FFFFFFF).ToNwObject(), WrapIntoMain = wrapIntoMain, }); return(!eventData.Skip); }
private static bool HandleVisualEffectEvent(CNWSMessage message, NwPlayer?player) { int offset = 0; uint target = message.PeekMessage <uint>(offset) & 0x7FFFFFFF; offset += sizeof(uint); ushort visualEffect = message.PeekMessage <ushort>(offset); offset += sizeof(ushort); float duration = message.PeekMessage <float>(offset); offset += sizeof(float); Vector3 position = message.PeekMessage <Vector3>(offset); OnDebugPlayVisualEffect eventData = new OnDebugPlayVisualEffect { Player = player, TargetObject = target.ToNwObject(), Effect = NwGameTables.VisualEffectTable[visualEffect], Duration = TimeSpan.FromSeconds(duration), TargetPosition = position, }; return(!eventData.Skip); }
private static bool HandleGiveEvent <TEvent>(NwPlayer dungeonMaster, CNWSMessage message) where TEvent : DMGiveEvent, new() { int amount = message.PeekMessage <int>(0); NwGameObject target = (message.PeekMessage <uint>(4) & 0x7FFFFFFF).ToNwObject <NwGameObject>() !; TEvent eventData = ProcessEvent(new TEvent { DungeonMaster = dungeonMaster, Amount = amount, Target = target, }); return(!eventData.Skip); }
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()); } }
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() !, });
private static bool HandleChangeDifficultyEvent(NwPlayer dungeonMaster, CNWSMessage message) { GameDifficulty difficulty = (GameDifficulty)message.PeekMessage <int>(0); OnDMChangeDifficulty eventData = ProcessEvent(new OnDMChangeDifficulty { DungeonMaster = dungeonMaster, NewDifficulty = difficulty, }); return(!eventData.Skip); }
private static bool HandleDumpLocalsEvent(NwPlayer dungeonMaster, CNWSMessage message) { DumpLocalsType type = (DumpLocalsType)message.PeekMessage <int>(0); NwObject target = type switch { DumpLocalsType.DumpLocals => (message.PeekMessage <uint>(4) & 0x7FFFFFFF).ToNwObject() !, DumpLocalsType.DumpAreaLocals => dungeonMaster.ControlledCreature !.Area !, DumpLocalsType.DumpModuleLocals => NwModule.Instance, _ => throw new ArgumentOutOfRangeException(), }; OnDMDumpLocals eventData = ProcessEvent(new OnDMDumpLocals { DungeonMaster = dungeonMaster, Type = type, Target = target, }); return(!eventData.Skip); }
private static bool HandleGiveAlignmentEvent(NwPlayer dungeonMaster, CNWSMessage message, MessageDungeonMasterMinor alignmentType) { Alignment alignment = alignmentType switch { MessageDungeonMasterMinor.GiveGoodAlignment => Alignment.Good, MessageDungeonMasterMinor.GiveEvilAlignment => Alignment.Evil, MessageDungeonMasterMinor.GiveLawfulAlignment => Alignment.Lawful, MessageDungeonMasterMinor.GiveChaoticAlignment => Alignment.Chaotic, _ => throw new ArgumentOutOfRangeException(), }; int amount = message.PeekMessage <int>(0); NwGameObject target = (message.PeekMessage <uint>(4) & 0x7FFFFFFF).ToNwObject <NwGameObject>() !; OnDMGiveAlignment eventData = ProcessEvent(new OnDMGiveAlignment { DungeonMaster = dungeonMaster, Alignment = alignment, Amount = amount, Target = target, }); return(!eventData.Skip); }
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, });
private static bool HandleGiveItemEvent(void *pMessage, void *pPlayer, byte nMinor, int bGroup, NwPlayer dungeonMaster, CNWSMessage message) { NwGameObject target = (message.PeekMessage <uint>(0) & 0x7FFFFFFF).ToNwObject <NwGameObject>() !; uint itemId = LowLevel.ServerExoApp.GetObjectArray().m_nNextObjectArrayID[0]; OnDMGiveItemBefore beforeEventData = ProcessEvent(new OnDMGiveItemBefore { DungeonMaster = dungeonMaster, Target = target, }); bool skipped = beforeEventData.Skip || !Hook.CallOriginal(pMessage, pPlayer, nMinor, bGroup).ToBool(); if (!skipped) { ProcessEvent(new OnDMGiveItemAfter { DungeonMaster = dungeonMaster, Target = target, Item = itemId.ToNwObject <NwItem>() !, });
private static bool HandleRunScriptEvent(CNWSMessage message, NwPlayer?player) { int offset = 0; string scriptName = message.PeekMessageString(offset); offset += scriptName.Length + 4; uint oidTarget = player?.Player.SatisfiesBuild(8193, 14).ToBool() == true?message.PeekMessage <uint>(offset) : NwObject.Invalid; if (oidTarget == NwObject.Invalid) { oidTarget = player?.ControlledCreature; } OnDebugRunScript eventData = new OnDebugRunScript { Player = player, ScriptName = scriptName, Target = (oidTarget & 0x7FFFFFFF).ToNwObject(), }; return(!eventData.Skip); }