Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove committed Dec 12, 2024
1 parent 89418fe commit 4cf4c15
Show file tree
Hide file tree
Showing 31 changed files with 541 additions and 52 deletions.
9 changes: 8 additions & 1 deletion misc/git-hooks/clang-format-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ const checks = [

// Check if the file belongs to one of the valid parent directories
return validDirs.some((dir) => file.includes(path.sep + dir + path.sep))
&& !file.endsWith(path.sep + "anyMessage.ts");
&& !file.endsWith(path.sep + "anyMessage.ts")
&& !file.endsWith(path.sep + "refrIdMessageBase.ts")
&& !file.endsWith(path.sep + "MessageBase.h")
&& !file.endsWith(path.sep + "MessageSerializerFactory.cpp")
&& !file.endsWith(path.sep + "MessageSerializerFactory.h")
&& !file.endsWith(path.sep + "Messages.h")
&& !file.endsWith(path.sep + "MinPacketId.h")
&& !file.endsWith(path.sep + "MsgType.h");
},
lint: (file) => {
const serverDir = "skymp5-server/cpp/messages";
Expand Down
17 changes: 11 additions & 6 deletions skymp5-client/src/services/messages/customPacketMessage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { MsgType } from "../../messages";

// export interface CustomPacketMessage {
// t: MsgType.CustomPacket,
// content: CustomPacketMessageContent
// }

// interface CustomPacketMessageContent {
// customPacketType: string,
// gameData: Record<string, unknown>
// }

export interface CustomPacketMessage {
t: MsgType.CustomPacket,
content: CustomPacketMessageContent
}

interface CustomPacketMessageContent {
customPacketType: string,
gameData: Record<string, unknown>
contentJsonDump: string
}
4 changes: 0 additions & 4 deletions skymp5-client/src/services/messages/customPacketMessage2.ts

This file was deleted.

1 change: 1 addition & 0 deletions skymp5-client/src/services/messages/putItemMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MsgType } from "../../messages";

export interface PutItemMessage extends Extra {
t: MsgType.PutItem,
baseId: number;
count: number;
target: number;
};
8 changes: 5 additions & 3 deletions skymp5-client/src/services/messages/spellCastMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { MsgType } from "../../messages";
// @ts-expect-error (TODO: Remove in 2.10.0)
import { ActorAnimationVariables } from 'skyrimPlatform';

export interface SpellCastMsgData {
caster: number
Expand All @@ -11,7 +9,11 @@ export interface SpellCastMsgData {
castingSource: number
aimAngle: number,
aimHeading: number,
actorAnimationVariables: ActorAnimationVariables
actorAnimationVariables: {
booleans: number[]
floats: number[]
integers: number[]
}
}

export interface SpellCastMessage {
Expand Down
1 change: 1 addition & 0 deletions skymp5-client/src/services/messages/takeItemMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MsgType } from "../../messages";

export interface TakeItemMessage extends Extra {
t: MsgType.TakeItem,
baseId: number;
count: number;
target: number;
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { MsgType } from "../../messages";
// @ts-expect-error (TODO: Remove in 2.10.0)
import { ActorAnimationVariables } from 'skyrimPlatform';

export interface UpdateAnimVariablesMessageMsgData {
actorRemoteId: number
actorAnimationVariables: ActorAnimationVariables
actorAnimationVariables: {
booleans: number[]
floats: number[]
integers: number[]
}
}

export interface UpdateAnimVariablesMessage {
Expand Down
11 changes: 8 additions & 3 deletions skymp5-client/src/services/messages/updateGameModeDataMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export interface GamemodeValuePair {
name: string;
content: string;
}

export interface UpdateGamemodeDataMessage {
type: "updateGamemodeData";
eventSources: Record<string, string>;
updateOwnerFunctions: Record<string, string>;
updateNeighborFunctions: Record<string, string>;
eventSources: GamemodeValuePair[];
updateOwnerFunctions: GamemodeValuePair[];
updateNeighborFunctions: GamemodeValuePair[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export class GamemodeEventSourceService extends ClientListener {
});
}

let eventNames = Object.keys(event.message.eventSources);
let eventSourcesRecord: Record<string, string | undefined> = {};
event.message.eventSources.forEach(pair => eventSourcesRecord[pair.name] = pair.content);

let eventNames = Object.keys(eventSourcesRecord);

let blockedEventSources = this.sp.settings["skymp5-client"]["blockedEventSources"];

Expand All @@ -50,7 +53,7 @@ export class GamemodeEventSourceService extends ClientListener {

eventNames.forEach((eventName) => {
try {
const fn = new Function('ctx', event.message.eventSources[eventName]);
const fn = new Function('ctx', eventSourcesRecord[eventName]!);
const ctx: GamemodeApiEventSourceCtx = {
refr: undefined,
value: undefined,
Expand Down
18 changes: 11 additions & 7 deletions skymp5-client/src/services/services/gamemodeUpdateService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FormModel } from "../../view/model";
import { ConnectionMessage } from "../events/connectionMessage";
import { CreateActorMessage } from "../messages/createActorMessage";
import { UpdateGamemodeDataMessage } from "../messages/updateGameModeDataMessage";
import { GamemodeValuePair, UpdateGamemodeDataMessage } from "../messages/updateGameModeDataMessage";
import { ClientListener, CombinedController, Sp } from "./clientListener";
import { RemoteServer } from "./remoteServer";
import { ObjectReference } from "skyrimPlatform";
Expand Down Expand Up @@ -109,11 +109,11 @@ export class GamemodeUpdateService extends ClientListener {

this.updateGamemodeUpdateFunctions(
'updateNeighborFunctions',
event.message.updateNeighborFunctions || {},
event.message.updateNeighborFunctions,
);
this.updateGamemodeUpdateFunctions(
'updateOwnerFunctions',
event.message.updateOwnerFunctions || {},
event.message.updateOwnerFunctions,
);
}

Expand Down Expand Up @@ -196,16 +196,20 @@ export class GamemodeUpdateService extends ClientListener {

private updateGamemodeUpdateFunctions(
storageVar: string,
functionSources: Record<string, string>,
functionSources: GamemodeValuePair[],
) {
this.sp.storage[storageVar] = JSON.parse(JSON.stringify(functionSources));
for (const propName of Object.keys(functionSources)) {
let functionSourcesRecord: Record<string, string | undefined> = {};
functionSources.forEach(pair => functionSourcesRecord[pair.name] = pair.content);

this.sp.storage[storageVar] = functionSourcesRecord;

for (const propName of Object.keys(functionSourcesRecord)) {
try {
(this.sp.storage[storageVar] as any)[propName] = new Function(
'ctx',
(this.sp.storage[storageVar] as any)[propName],
);
const emptyFunction = functionSources[propName] === '';
const emptyFunction = functionSourcesRecord[propName] === '';
if (emptyFunction) {
delete (this.sp.storage[storageVar] as any)[propName];
logTrace(this, storageVar, propName, 'Added empty');
Expand Down
18 changes: 15 additions & 3 deletions skymp5-client/src/services/services/magicSyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class MagicSyncService extends ClientListener {
return;
}

const animVariables = getAnimationVariablesFromActor(ac.getFormID());
const animVariables = this.getAnimationVariablesFromActorConverted(ac.getFormID());

this.controller.emitter.emit("sendMessage", {
message: { t: MsgType.UpdateAnimVariables, data: this.getUpdateAnimVariablesEventData(ac, animVariables) },
Expand Down Expand Up @@ -81,7 +81,7 @@ export class MagicSyncService extends ClientListener {

let msg: SpellCastMsgData = this.lastSpellCastEventMsg;
msg.interruptCast = true;
msg.actorAnimationVariables = getAnimationVariablesFromActor(remoteIdToLocalId(this.lastSpellCastEventMsg.caster));
msg.actorAnimationVariables = this.getAnimationVariablesFromActorConverted(remoteIdToLocalId(this.lastSpellCastEventMsg.caster));

this.controller.emitter.emit("sendMessage", {
message: { t: MsgType.SpellCast, data: msg },
Expand All @@ -106,11 +106,23 @@ export class MagicSyncService extends ClientListener {
aimAngle: e.aimAngle,
// @ts-expect-error (TODO: Remove in 2.10.0)
aimHeading: e.aimHeading,
actorAnimationVariables: getAnimationVariablesFromActor(e.caster.getFormID()),
actorAnimationVariables: this.getAnimationVariablesFromActorConverted(e.caster.getFormID()),
}
return spellCastData;
}

private getAnimationVariablesFromActorConverted(actorId: number) {
const animVars = getAnimationVariablesFromActor(actorId);
const booleans: ArrayBuffer = animVars.booleans;
const floats: ArrayBuffer = animVars.floats;
const integers: ArrayBuffer = animVars.integers;
return {
booleans: Array.from(new Uint8Array(booleans)),
floats: Array.from(new Uint8Array(floats)),
integers: Array.from(new Uint8Array(integers)),
}
}

private getUpdateAnimVariablesEventData(ac: Actor, animVariables: ActorAnimationVariables): UpdateAnimVariablesMessageMsgData {
const animVarsData: UpdateAnimVariablesMessageMsgData = {
actorRemoteId: localIdToRemoteId(ac.getFormID(), true),
Expand Down
12 changes: 6 additions & 6 deletions skymp5-client/src/services/services/remoteServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,9 @@ export class RemoteServer extends ClientListener {
if (!ac) return;

const actorAnimationVariables: ActorAnimationVariables = {
booleans: new Uint8Array(Object.values(msg.data.actorAnimationVariables.booleans)),
floats: new Uint8Array(Object.values(msg.data.actorAnimationVariables.floats)),
integers: new Uint8Array(Object.values(msg.data.actorAnimationVariables.integers))
booleans: new Uint8Array(msg.data.actorAnimationVariables.booleans),
floats: new Uint8Array(msg.data.actorAnimationVariables.floats),
integers: new Uint8Array(msg.data.actorAnimationVariables.integers)
};

if (msg.data.interruptCast) {
Expand All @@ -929,9 +929,9 @@ export class RemoteServer extends ClientListener {
if (!ac) return;

const actorAnimationVariables: ActorAnimationVariables = {
booleans: new Uint8Array(Object.values(msg.data.actorAnimationVariables.booleans)),
floats: new Uint8Array(Object.values(msg.data.actorAnimationVariables.floats)),
integers: new Uint8Array(Object.values(msg.data.actorAnimationVariables.integers))
booleans: new Uint8Array(msg.data.actorAnimationVariables.booleans),
floats: new Uint8Array(msg.data.actorAnimationVariables.floats),
integers: new Uint8Array(msg.data.actorAnimationVariables.integers)
};

const isApplyed = applyAnimationVariablesToActor(ac.getFormID(), actorAnimationVariables);
Expand Down
18 changes: 18 additions & 0 deletions skymp5-server/cpp/messages/CustomPacketMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "MessageBase.h"
#include "MsgType.h"
#include <type_traits>

struct CustomPacketMessage : public MessageBase<CustomPacketMessage>
{
static constexpr auto kMsgType =
std::integral_constant<char, static_cast<char>(MsgType::CustomPacket)>{};

template <class Archive>
void Serialize(Archive& archive)
{
archive.Serialize("t", kMsgType)
.Serialize("contentJsonDump", contentJsonDump);
}

std::string contentJsonDump;
};
18 changes: 18 additions & 0 deletions skymp5-server/cpp/messages/HostStartMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "MessageBase.h"
#include "MsgType.h"
#include <type_traits>

struct HostStartMessage : public MessageBase<HostStartMessage>
{
static constexpr auto kMsgType =
std::integral_constant<char, static_cast<char>(MsgType::HostStart)>{};

template <class Archive>
void Serialize(Archive& archive)
{
archive.Serialize("t", kMsgType).Serialize("target", target);
}

uint64_t target = 0;
};
18 changes: 18 additions & 0 deletions skymp5-server/cpp/messages/HostStopMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "MessageBase.h"
#include "MsgType.h"
#include <type_traits>

struct HostStopMessage : public MessageBase<HostStopMessage>
{
static constexpr auto kMsgType =
std::integral_constant<char, static_cast<char>(MsgType::HostStop)>{};

template <class Archive>
void Serialize(Archive& archive)
{
archive.Serialize("t", kMsgType).Serialize("target", target);
}

uint64_t target = 0;
};
32 changes: 31 additions & 1 deletion skymp5-server/cpp/messages/Messages.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
#pragma once
#include "ActivateMessage.h"
#include "ChangeValuesMessage.h"
#include "CustomPacketMessage.h"
#include "DeathStateContainerMessage.h"
#include "HostStartMessage.h"
#include "HostStopMessage.h"
#include "OnEquipMessage.h"
#include "OpenContainerMessage.h"
#include "PlayerBowShotMessage.h"
#include "PutItemMessage.h"
#include "SetInventoryMessage.h"
#include "SetRaceMenuOpenMessage.h"
#include "SpSnippetMessage.h"
#include "SpellCastMessage.h"
#include "TakeItemMessage.h"
#include "TeleportMessage.h"
#include "TeleportMessage2.h"
#include "UpdateAnimVariablesMessage.h"
#include "UpdateAnimationMessage.h"
#include "UpdateAppearanceMessage.h"
#include "UpdateEquipmentMessage.h"
#include "UpdateGameModeDataMessage.h"
#include "UpdateMovementMessage.h"
#include "UpdatePropertyMessage.h"

Expand All @@ -26,4 +41,19 @@
REGISTER_MESSAGE(TeleportMessage) \
REGISTER_MESSAGE(UpdatePropertyMessage) \
REGISTER_MESSAGE(OpenContainerMessage) \
REGISTER_MESSAGE(UpdateEquipmentMessage)
REGISTER_MESSAGE(UpdateEquipmentMessage) \
REGISTER_MESSAGE(CustomPacketMessage.h) \
REGISTER_MESSAGE(HostStartMessage.h) \
REGISTER_MESSAGE(HostStopMessage.h) \
REGISTER_MESSAGE(OnEquipMessage.h) \
REGISTER_MESSAGE(PlayerBowShotMessage.h) \
REGISTER_MESSAGE(PutItemMessage.h) \
REGISTER_MESSAGE(SetInventoryMessage.h) \
REGISTER_MESSAGE(SetRaceMenuOpenMessage.h) \
REGISTER_MESSAGE(SpellCastMessage.h) \
REGISTER_MESSAGE(SpSnippetMessage.h) \
REGISTER_MESSAGE(TakeItemMessage.h) \
REGISTER_MESSAGE(TeleportMessage2.h) \
REGISTER_MESSAGE(UpdateAnimVariablesMessage.h) \
REGISTER_MESSAGE(UpdateAppearanceMessage.h) \
REGISTER_MESSAGE(UpdateGameModeDataMessage.h)
10 changes: 9 additions & 1 deletion skymp5-server/cpp/messages/MsgType.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ enum class MsgType : uint8_t
UpdateAnimVariables = 24,

// ex-strings
DestroyActor = 100,
DestroyActor = 25,
HostStart = 26,
HostStop = 27,
SetInventory = 28,
SetRaceMenuOpen = 29,
SpellCast = 30,
SpSnippet = 31,
Teleport2 = 32,
UpdateGamemodeData = 33,

Max
};
18 changes: 18 additions & 0 deletions skymp5-server/cpp/messages/OnEquipMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "MessageBase.h"
#include "MsgType.h"
#include <type_traits>

struct OnEquipMessage : public MessageBase<OnEquipMessage>
{
static constexpr auto kMsgType =
std::integral_constant<char, static_cast<char>(MsgType::OnEquip)>{};

template <class Archive>
void Serialize(Archive& archive)
{
archive.Serialize("t", kMsgType).Serialize("baseId", baseId);
}

uint32_t baseId = 0;
};
1 change: 0 additions & 1 deletion skymp5-server/cpp/messages/OpenContainerMessage.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include "MessageBase.h"
#include "MsgType.h"
#include <array>
#include <type_traits>

struct OpenContainerMessage : public MessageBase<OpenContainerMessage>
Expand Down
Loading

0 comments on commit 4cf4c15

Please sign in to comment.