Skip to content

Commit 9a8696f

Browse files
committed
Updated lua funcs
1 parent 14308dd commit 9a8696f

4 files changed

Lines changed: 39 additions & 14 deletions

File tree

‎Game.Client/GarrysMod/LuaRender.cs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,13 @@ static int SetModelLighting(ILuaInterface lua) {
212212

213213
[LuaFunction]
214214
static int UpdateScreenEffectTexture(ILuaInterface lua) {
215-
int textureIndex = 0;
216-
if (lua.GetType(1) == LuaType.Number)
217-
textureIndex = (int)lua.GetNumber(1);
218-
ViewScene.UpdateScreenEffectTexture(textureIndex, 0, 0, ScreenWidth(), ScreenHeight(), false);
215+
uint textureIndex = 0;
216+
if (lua.GetType(1) == LuaType.Number) {
217+
textureIndex = (uint)lua.CheckNumber(1);
218+
if (textureIndex > 4)
219+
return 0;
220+
}
221+
ViewScene.UpdateScreenEffectTexture((int)textureIndex, 0, 0, ScreenWidth(), ScreenHeight(), false);
219222
return 0;
220223
}
221224
#endif

‎Game.Client/GarrysMod/LuaSurface.cs‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,10 @@ static int DrawPoly(ILuaInterface lua) {
388388
vertex.UnReference();
389389
}
390390

391-
surface.DrawTexturedPolygon(((Span<SurfaceVertex>)PolyVerts)[..count], true);
391+
if (count < 3)
392+
lua.ArgError(1, "table must contain at least three vertices");
393+
else
394+
surface.DrawTexturedPolygon(((Span<SurfaceVertex>)PolyVerts)[..count], true);
392395
vertices.UnReference();
393396
return 0;
394397
}
@@ -414,12 +417,16 @@ static int DrawCircle(ILuaInterface lua) {
414417
}
415418
[LuaFunction]
416419
static int DrawTexturedRectUV(ILuaInterface lua) {
417-
int x = (int)lua.GetNumber(1);
418-
int y = (int)lua.GetNumber(2);
419-
int w = (int)lua.GetNumber(3);
420-
int h = (int)lua.GetNumber(4);
420+
int x = (int)lua.CheckNumber(1);
421+
int y = (int)lua.CheckNumber(2);
422+
int w = (int)lua.CheckNumber(3);
423+
int h = (int)lua.CheckNumber(4);
421424
// TODO: poster cmd split scaling (?)
422-
surface.DrawTexturedSubRect(x, y, w + x, h + y, (float)lua.GetNumber(5), (float)lua.GetNumber(6), (float)lua.GetNumber(7), (float)lua.GetNumber(8));
425+
float v1 = (float)lua.CheckNumber(8);
426+
float u1 = (float)lua.CheckNumber(7);
427+
float v0 = (float)lua.CheckNumber(6);
428+
float u0 = (float)lua.CheckNumber(5);
429+
surface.DrawTexturedSubRect(x, y, w + x, h + y, u0, v0, u1, v1);
423430
return 0;
424431
}
425432

‎Game.Shared/GarrysMod/LuaEntity.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,13 +1315,22 @@ static int Entity__Activate(ILuaInterface lua) {
13151315
static int Entity__SetPos(ILuaInterface lua) {
13161316
BaseEntity ent = Get_Entity(1, false)!;
13171317
ref Vector3 pos = ref LuaVector.Get_Vector(2);
1318+
#if GAME_DLL
1319+
bool touchTriggers = false;
1320+
if (lua.GetType(3) != LuaType.Nil)
1321+
touchTriggers = lua.GetBool(3);
1322+
#endif
13181323
float max = MAX_COORD_FLOAT * 8;
13191324
if (!(-max < pos.X && pos.X < max && -max < pos.Y && pos.Y < max && -max < pos.Z && pos.Z < max)) {
13201325
Warning($"{ent.GetClassname()}[{ent.EntIndex()}]:SetPos( {pos.X:F6} {pos.Y:F6} {pos.Z:F6} ): Ignoring unreasonable position.\n");
13211326
return 0;
13221327
}
13231328

13241329
ent.SetAbsOrigin(pos);
1330+
#if GAME_DLL
1331+
if (touchTriggers && !IsQueuedForRemoval(ent) && !ent.IsMarkedForDeletion())
1332+
ent.PhysicsTouchTriggers();
1333+
#endif
13251334
if (ent.GetMoveType() == MoveType.None || ent.VPhysicsGetObject() == null || ent.IsRagdollProp() || ent.IsJeep())
13261335
return 0;
13271336
#if CLIENT_DLL

‎Game.Shared/GarrysMod/LuaNetworkedVars.cs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ static void TruncateString(ILuaObject value) {
155155
g_Lua.Pop(1);
156156
}
157157

158-
void CallProxy(LuaNetworkedVar var, uint handle, string name, ILuaObject value) {
158+
void CallProxy(LuaNetworkedVar var, uint handle, string name, ILuaObject oldValue) {
159159
if (g_Lua == null || !var.Proxy.isFunction())
160160
return;
161161

162162
var.Proxy.Push();
163163
LuaEntity.Push_Entity(EntityFromHandle(handle));
164164
g_Lua.PushString(name);
165+
oldValue.Push();
165166
var.Value.Push();
166-
value.Push();
167167
g_Lua.CallInternalNoReturns(4);
168168
}
169169

@@ -174,11 +174,16 @@ public void SetNetworkedVar(uint handle, string name, ILuaObject value) {
174174
return;
175175
}
176176

177+
LuaObject oldValue = new();
178+
oldValue.Set(var.Value);
179+
177180
TruncateString(value);
178181

179182
#if GAME_DLL
180-
if (g_Lua!.IsEqual(var.Value, value))
183+
if (g_Lua!.IsEqual(var.Value, value)) {
184+
oldValue.UnReference();
181185
return;
186+
}
182187

183188
var.Value.Set(value);
184189
var.NextUpdate = 0;
@@ -189,7 +194,8 @@ public void SetNetworkedVar(uint handle, string name, ILuaObject value) {
189194
var.Time = (float)gpGlobals.CurTime;
190195
#endif
191196

192-
CallProxy(var, handle, name, value);
197+
CallProxy(var, handle, name, oldValue);
198+
oldValue.UnReference();
193199
}
194200

195201
public void SetNetworkedVarProxy(uint handle, string name, ILuaObject func) {

0 commit comments

Comments
 (0)