Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions Game.Server/GameInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,49 @@ public static class GameInterface
public const int MAX_MATERIAL_STRING_BITS = 10;
public const int MAX_MATERIAL_STRINGS = 1 << MAX_MATERIAL_STRING_BITS;

public const int MAX_PARTICLESYSTEMS_STRING_BITS = 12;
public const int MAX_PARTICLESYSTEMS_STRINGS = 1 << MAX_PARTICLESYSTEMS_STRING_BITS;

public const int MAX_VGUI_SCREEN_STRING_BITS = 8;
public const int MAX_VGUI_SCREEN_STRINGS = 1 << MAX_VGUI_SCREEN_STRING_BITS;

public static INetworkStringTable? g_pStringTableParticleEffectNames;
public static INetworkStringTable? g_pStringTableEffectDispatch;
public static INetworkStringTable? g_pStringTableVguiScreen;
public static INetworkStringTable? g_pStringTableClientSideChoreoScenes;
public static INetworkStringTable? g_pStringTableMaterials;

public static void PrecacheParticleSystem(ReadOnlySpan<char> particleSystemName) {
if (particleSystemName.IsStringEmpty)
return;
g_pStringTableParticleEffectNames?.AddString(true, particleSystemName);
}

public static int GetParticleSystemIndex(ReadOnlySpan<char> particleSystemName) {
if (particleSystemName.IsEmpty)
return 0;

int index = g_pStringTableParticleEffectNames!.FindStringIndex(particleSystemName);
if (index != INetworkStringTable.INVALID_STRING_INDEX)
return index;

if (!particleSystemName.IsStringEmpty) {
PrecacheParticleSystem(particleSystemName);
index = g_pStringTableParticleEffectNames.FindStringIndex(particleSystemName);
if (index != INetworkStringTable.INVALID_STRING_INDEX)
return index;
}

DevWarning($"Server: Missing precache for particle system \"{particleSystemName}\"!\n");
return 0;
}

public static ReadOnlySpan<char> GetParticleSystemNameFromIndex(int index) {
if (index < g_pStringTableParticleEffectNames!.GetMaxStrings())
return g_pStringTableParticleEffectNames.GetString(index);
return "error";
}

public static void PrecacheMaterial(ReadOnlySpan<char> materialName) {
g_pStringTableMaterials!.AddString(true, materialName);
}
Expand Down Expand Up @@ -260,9 +299,14 @@ public void BuildAdjacentMapList() {
public void CreateNetworkStringTables() {
// throw new NotImplementedException();

g_pStringTableParticleEffectNames = networkstringtable.CreateStringTable("ParticleEffectNames", MAX_PARTICLESYSTEMS_STRINGS);
g_pStringTableEffectDispatch = networkstringtable.CreateStringTable("EffectDispatch", EffectData.MAX_EFFECT_DISPATCH_STRINGS);
g_pStringTableClientSideChoreoScenes = networkstringtable.CreateStringTable("Scenes", MAX_CHOREO_SCENES_STRINGS);
g_pStringTableVguiScreen = networkstringtable.CreateStringTable("VguiScreen", MAX_VGUI_SCREEN_STRINGS);
g_pStringTableMaterials = networkstringtable.CreateStringTable("Materials", MAX_MATERIAL_STRINGS);
g_pStringTableClientSideChoreoScenes = networkstringtable.CreateStringTable("Scenes", MAX_CHOREO_SCENES_STRINGS);

g_pStringTableMaterials!.AddString(true, "debug/debugempty");
PrecacheParticleSystem("error");

GameRulesRegister.CreateNetworkStringTables_GameRules();

Expand Down Expand Up @@ -445,7 +489,11 @@ public void GMOD_OnAllSoundsStoppedSV() {
}

public void GMOD_OnStringTablesRemoved() {
// todo: g_pStringTableParticleEffectNames, g_pStringTableEffectDispatch, g_pStringTableVguiScreen, g_pStringTableMaterials, g_pStringTableClientSideChoreoScenes = null
g_pStringTableParticleEffectNames = null;
g_pStringTableEffectDispatch = null;
g_pStringTableVguiScreen = null;
g_pStringTableMaterials = null;
g_pStringTableClientSideChoreoScenes = null;
GameRulesRegister.ResetNetworkStringTables_GameRules();
#if GMOD_DLL
Game.Server.GarrysMod.NetworkString.Reset();
Expand Down
4 changes: 4 additions & 0 deletions Game.Shared/GarrysMod/LuaGlobalFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ static int WorldToLocal(ILuaInterface lua) {
[LuaGlobal]
static int PrecacheParticleSystem(ILuaInterface lua) {
string name = lua.CheckString(1);
#if GAME_DLL
GameInterface.PrecacheParticleSystem(name);
#else
// PrecacheParticleSystem(name); // TODO!
#endif
return 0;
}

Expand Down
9 changes: 5 additions & 4 deletions Source.Common/Networking/NetMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,14 @@ public override string ToString() {
public class SVC_VoiceInit : NetMessage
{
public SVC_VoiceInit() : base(SVC.VoiceInit) { }
public SVC_VoiceInit(ReadOnlySpan<char> codec, int sampleRate) : base(SVC.VoiceInit) {
public SVC_VoiceInit(ReadOnlySpan<char> codec, int quality) : base(SVC.VoiceInit) {
VoiceCodec = codec.IsEmpty ? "" : new(codec.SliceNullTerminatedString());
SampleRate = sampleRate;
Quality = quality;
}
public override NetChannelGroup GetGroup() => NetChannelGroup.SignOn;

public string VoiceCodec = "";
public int Quality;
public int SampleRate;

public override bool ReadFromBuffer(bf_read buffer) {
Expand All @@ -513,6 +514,7 @@ public override bool ReadFromBuffer(bf_read buffer) {
VoiceCodec = "steam";

byte legacyQuality = buffer.ReadByte();
Quality = legacyQuality;
if (legacyQuality == 255) {
// v2 packet
SampleRate = buffer.ReadShort();
Expand Down Expand Up @@ -544,8 +546,7 @@ public override bool ReadFromBuffer(bf_read buffer) {
public override bool WriteToBuffer(bf_write buffer) {
buffer.WriteNetMessageType(this);
buffer.WriteString(VoiceCodec);
buffer.WriteByte( /* Legacy Quality Field */ 255);
buffer.WriteShort(SampleRate);
buffer.WriteByte(Quality);
return !buffer.Overflowed;
}
}
Expand Down
3 changes: 1 addition & 2 deletions Source.Engine/SV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ public static void WriteVoiceCodec(bf_write buf) {
// Only send in multiplayer. Otherwise, we don't want voice.

ReadOnlySpan<char> codec = sv.IsMultiplayer() ? sv_voicecodec.GetString() : null;
int sampleRate = !codec.IsEmpty ? Voice.GetDefaultSampleRate(codec) : 0;
SVC_VoiceInit voiceinit = new(codec, sampleRate);
SVC_VoiceInit voiceinit = new(codec, 5);
voiceinit.WriteToBuffer(buf);
}

Expand Down
Loading