Skip to content

Commit c108fbc

Browse files
committed
Fix missing stringtables on dedicated
1 parent eff6b5c commit c108fbc

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

‎Game.Server/GameInterface.cs‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,49 @@ public static class GameInterface
3737
public const int MAX_MATERIAL_STRING_BITS = 10;
3838
public const int MAX_MATERIAL_STRINGS = 1 << MAX_MATERIAL_STRING_BITS;
3939

40+
public const int MAX_PARTICLESYSTEMS_STRING_BITS = 12;
41+
public const int MAX_PARTICLESYSTEMS_STRINGS = 1 << MAX_PARTICLESYSTEMS_STRING_BITS;
42+
43+
public const int MAX_VGUI_SCREEN_STRING_BITS = 8;
44+
public const int MAX_VGUI_SCREEN_STRINGS = 1 << MAX_VGUI_SCREEN_STRING_BITS;
45+
46+
public static INetworkStringTable? g_pStringTableParticleEffectNames;
4047
public static INetworkStringTable? g_pStringTableEffectDispatch;
48+
public static INetworkStringTable? g_pStringTableVguiScreen;
4149
public static INetworkStringTable? g_pStringTableClientSideChoreoScenes;
4250
public static INetworkStringTable? g_pStringTableMaterials;
4351

52+
public static void PrecacheParticleSystem(ReadOnlySpan<char> particleSystemName) {
53+
if (particleSystemName.IsStringEmpty)
54+
return;
55+
g_pStringTableParticleEffectNames?.AddString(true, particleSystemName);
56+
}
57+
58+
public static int GetParticleSystemIndex(ReadOnlySpan<char> particleSystemName) {
59+
if (particleSystemName.IsEmpty)
60+
return 0;
61+
62+
int index = g_pStringTableParticleEffectNames!.FindStringIndex(particleSystemName);
63+
if (index != INetworkStringTable.INVALID_STRING_INDEX)
64+
return index;
65+
66+
if (!particleSystemName.IsStringEmpty) {
67+
PrecacheParticleSystem(particleSystemName);
68+
index = g_pStringTableParticleEffectNames.FindStringIndex(particleSystemName);
69+
if (index != INetworkStringTable.INVALID_STRING_INDEX)
70+
return index;
71+
}
72+
73+
DevWarning($"Server: Missing precache for particle system \"{particleSystemName}\"!\n");
74+
return 0;
75+
}
76+
77+
public static ReadOnlySpan<char> GetParticleSystemNameFromIndex(int index) {
78+
if (index < g_pStringTableParticleEffectNames!.GetMaxStrings())
79+
return g_pStringTableParticleEffectNames.GetString(index);
80+
return "error";
81+
}
82+
4483
public static void PrecacheMaterial(ReadOnlySpan<char> materialName) {
4584
g_pStringTableMaterials!.AddString(true, materialName);
4685
}
@@ -260,9 +299,14 @@ public void BuildAdjacentMapList() {
260299
public void CreateNetworkStringTables() {
261300
// throw new NotImplementedException();
262301

302+
g_pStringTableParticleEffectNames = networkstringtable.CreateStringTable("ParticleEffectNames", MAX_PARTICLESYSTEMS_STRINGS);
263303
g_pStringTableEffectDispatch = networkstringtable.CreateStringTable("EffectDispatch", EffectData.MAX_EFFECT_DISPATCH_STRINGS);
264-
g_pStringTableClientSideChoreoScenes = networkstringtable.CreateStringTable("Scenes", MAX_CHOREO_SCENES_STRINGS);
304+
g_pStringTableVguiScreen = networkstringtable.CreateStringTable("VguiScreen", MAX_VGUI_SCREEN_STRINGS);
265305
g_pStringTableMaterials = networkstringtable.CreateStringTable("Materials", MAX_MATERIAL_STRINGS);
306+
g_pStringTableClientSideChoreoScenes = networkstringtable.CreateStringTable("Scenes", MAX_CHOREO_SCENES_STRINGS);
307+
308+
g_pStringTableMaterials!.AddString(true, "debug/debugempty");
309+
PrecacheParticleSystem("error");
266310

267311
GameRulesRegister.CreateNetworkStringTables_GameRules();
268312

@@ -445,7 +489,11 @@ public void GMOD_OnAllSoundsStoppedSV() {
445489
}
446490

447491
public void GMOD_OnStringTablesRemoved() {
448-
// todo: g_pStringTableParticleEffectNames, g_pStringTableEffectDispatch, g_pStringTableVguiScreen, g_pStringTableMaterials, g_pStringTableClientSideChoreoScenes = null
492+
g_pStringTableParticleEffectNames = null;
493+
g_pStringTableEffectDispatch = null;
494+
g_pStringTableVguiScreen = null;
495+
g_pStringTableMaterials = null;
496+
g_pStringTableClientSideChoreoScenes = null;
449497
GameRulesRegister.ResetNetworkStringTables_GameRules();
450498
#if GMOD_DLL
451499
Game.Server.GarrysMod.NetworkString.Reset();

‎Game.Shared/GarrysMod/LuaGlobalFunctions.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ static int WorldToLocal(ILuaInterface lua) {
171171
[LuaGlobal]
172172
static int PrecacheParticleSystem(ILuaInterface lua) {
173173
string name = lua.CheckString(1);
174+
#if GAME_DLL
175+
GameInterface.PrecacheParticleSystem(name);
176+
#else
174177
// PrecacheParticleSystem(name); // TODO!
178+
#endif
175179
return 0;
176180
}
177181

0 commit comments

Comments
 (0)