Skip to content

Commit

Permalink
Stubs for weapon shooting, that lack a correct redscript trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
MeFisto94 committed Dec 25, 2023
1 parent 8827df1 commit a73e275
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 15 deletions.
1 change: 1 addition & 0 deletions client/red4ext/src/NetworkGameSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,6 @@ template bool NetworkGameSystem::EnqueueMessage(uint8_t channel_id, PlayerAction
template bool NetworkGameSystem::EnqueueMessage(uint8_t channel_id, PlayerSpawnCar msg);
template bool NetworkGameSystem::EnqueueMessage(uint8_t channel_id, PlayerUnmountCar msg);
template bool NetworkGameSystem::EnqueueMessage(uint8_t channel_id, PlayerEquipItem msg);
template bool NetworkGameSystem::EnqueueMessage(uint8_t channel_id, PlayerShoot msg);

#endif //NETWORKMANAGERCONTROLLER_H
18 changes: 5 additions & 13 deletions client/red4ext/src/PlayerActionTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,11 @@ void PlayerActionTracker::RecordPlayerAction(RED4ext::CName actionName, RED4ext:

void PlayerActionTracker::OnShoot(RED4ext::Handle<RED4ext::gameprojectileShootEvent> event)
{
SDK->logger->InfoF(PLUGIN, "OnShoot! range: %f", event->params.range);
// // TODO: This is the completely wrong event, we want the WeaponObject and finding out that it has been excecuted
// // even. There's scriptedPuppet->GetActiveWeapon()
// const auto player = Cyberverse::Utils::GetPlayer();
// const auto [X, Y, Z, W] = Cyberverse::Utils::Entity_GetWorldPosition(player);
//
// PlayerActionTracked tracked = {};
// tracked.action = eACTION_RANGED_ATTACK;
//
// tracked.worldTransform = {};
// tracked.worldTransform.x = X;
// tracked.worldTransform.y = Y;
// tracked.worldTransform.z = Z;
PlayerShoot player_shoot = {};
player_shoot.charge = event->params.charge;
player_shoot.startPoint = Vector3 { event->startPoint.X, event->startPoint.Y, event->startPoint.Z };
player_shoot.itemIdWeapon = // TODO: FILL
Red::GetGameSystem<NetworkGameSystem>()->EnqueueMessage(0, player_shoot);
}

void PlayerActionTracker::OnHit(RED4ext::Handle<RED4ext::GameObject> gameObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public enum EMessageTypeServerbound: ushort
PlayerSpawnCar = 4,
PlayerMountCar = 5, // TODO: Implement
PlayerUnmountCar = 6,
PlayerEquipItem = 7
PlayerEquipItem = 7,
PlayerShoot = 8
}
12 changes: 12 additions & 0 deletions server/Managed/NativeLayer/Protocol/Serverbound/PlayerShoot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Runtime.InteropServices;
using Cyberverse.Server.NativeLayer.Protocol.Common;

namespace Cyberverse.Server.NativeLayer.Protocol.Serverbound;

[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct PlayerShoot
{
public ulong itemIdWeapon;
public Vector3 startPoint;
public float charge;
}
9 changes: 9 additions & 0 deletions server/Managed/PacketHandling/PlayerPacketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class PlayerPacketHandler
private readonly TypedPacketHandler<PlayerSpawnCar> _playerSpawnCarHandler;
private readonly TypedPacketHandler<PlayerUnmountCar> _playerUnmountHandler;
private readonly TypedPacketHandler<PlayerEquipItem> _playerEquipHandler;
private readonly TypedPacketHandler<PlayerShoot> _playerShootHandler;
private EntityTracker? _tracker = null;
private PlayerService? _players = null;

Expand All @@ -29,6 +30,7 @@ public PlayerPacketHandler()
_playerSpawnCarHandler = new TypedPacketHandler<PlayerSpawnCar>(HandleSpawnCar);
_playerUnmountHandler = new TypedPacketHandler<PlayerUnmountCar>(HandleUnmountCar);
_playerEquipHandler = new TypedPacketHandler<PlayerEquipItem>(HandleEquip);
_playerShootHandler = new TypedPacketHandler<PlayerShoot>(HandleShoot);
}

protected void HandleJoinWorld(GameServer server, EMessageTypeServerbound messageType, byte channelId, uint connectionId, PlayerJoinWorld content)
Expand Down Expand Up @@ -178,6 +180,12 @@ private void HandleEquip(GameServer server, EMessageTypeServerbound messageType,
}
}

private void HandleShoot(GameServer server, EMessageTypeServerbound messageType, byte channelId,
uint connectionId, PlayerShoot content)
{
Logger.Warn($"Shots fired! {content.itemIdWeapon} at {content.startPoint}");
}

public void RegisterOnServer(GameServer server)
{
_tracker = server.EntityTracker; // TODO: Service registry or even using DI
Expand All @@ -188,5 +196,6 @@ public void RegisterOnServer(GameServer server)
server.AddPacketHandler(EMessageTypeServerbound.PlayerSpawnCar, _playerSpawnCarHandler.HandlePacket);
server.AddPacketHandler(EMessageTypeServerbound.PlayerUnmountCar, _playerUnmountHandler.HandlePacket);
server.AddPacketHandler(EMessageTypeServerbound.PlayerEquipItem, _playerEquipHandler.HandlePacket);
server.AddPacketHandler(EMessageTypeServerbound.PlayerShoot, _playerShootHandler.HandlePacket);
}
}
14 changes: 14 additions & 0 deletions server/Native/src/GameServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,20 @@ void GameServer::PollIncomingMessages()
}
break;

case ePlayerShoot:
{
PlayerShoot player_shoot = {};
if (zpp::bits::failure(in(player_shoot)))
{
fprintf(stderr, "Faulty packet: PlayerShoot\n");
pIncomingMsg->Release();
continue;
}

AddToRecvQueue(frame.message_type, pIncomingMsg->m_conn, frame.channel_id, player_shoot);
}
break;

default:
printf("Message Type: %d\n", frame.message_type);
break;
Expand Down
3 changes: 2 additions & 1 deletion shared/protocol/serverbound/EMessageTypeServerbound.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ enum EMessageTypeServerbound: uint16_t {
ePlayerSpawnCar = 4,
ePlayerMountCar = 5, // TODO: Implement
ePlayerUnmountCar = 6,
ePlayerEquipItem = 7
ePlayerEquipItem = 7,
ePlayerShoot = 8
};
13 changes: 13 additions & 0 deletions shared/protocol/serverbound/WorldPacketsServerBound.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ struct PlayerEquipItem {
frame.message_type = ePlayerEquipItem;
frame.channel_id = 0; // TODO
}
};

struct PlayerShoot {
// TODO: This should be the weaponId perspectively, not the TweakDBID
uint64_t itemIdWeapon;
Vector3 startPoint;
float charge;

inline static void FillMessageFrame(MessageFrame& frame)
{
frame.message_type = ePlayerShoot;
frame.channel_id = 0; // TODO
}
};

0 comments on commit a73e275

Please sign in to comment.