Skip to content

Commit c7cd4eb

Browse files
committed
Port missing flagged commands and screenshot
1 parent 92b408e commit c7cd4eb

21 files changed

Lines changed: 657 additions & 18 deletions

File tree

‎Game.Client/C_Soundscape.cs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ public static class SoundscapeGlobals
2525
public static void Soundscape_OnStopAllSounds() => g_SoundscapeSystem.OnStopAllSounds();
2626
public static void Soundscape_Update(ref AudioParams audio) => g_SoundscapeSystem.UpdateAudioParams(ref audio);
2727
public static ConVar soundscape_fadetime = new("soundscape_fadetime", "3.0", FCvar.Cheat, "Time to crossfade sound effects between soundscapes");
28+
29+
[ConCommand(helpText: "Flushes the client side soundscapes", flags: FCvar.ServerCanExecute | FCvar.Cheat)]
30+
static void cl_soundscape_flush() {
31+
g_SoundscapeSystem.GetAudioParams(out AudioParams tmp);
32+
33+
g_SoundscapeSystem.Shutdown();
34+
g_SoundscapeSystem.Init();
35+
36+
Soundscape_Update(ref tmp);
37+
}
2838
}
2939

3040
public struct LoopingSound
@@ -206,7 +216,7 @@ public void UpdateAudioParams(ref AudioParams audio) {
206216
}
207217
}
208218

209-
public void GetAudioParams(out AudioParams outParams) => throw new NotImplementedException();
219+
public void GetAudioParams(out AudioParams outParams) => outParams = Params;
210220

211221
public int GetCurrentSoundscape() => throw new NotImplementedException();
212222

‎Game.Client/HLTVCamera.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Source.Common.Commands;
2+
3+
namespace Game.Client;
4+
5+
public static class HLTVCameraGlobals
6+
{
7+
public static readonly ConVar spec_autodirector = new("spec_autodirector", "1", FCvar.ClientDLL | FCvar.ClientCmdCanExecute, "Auto-director chooses best view modes while spectating");
8+
9+
// todo: C_HLTVCamera
10+
}

‎Game.Client/InJoystick.cs‎

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
using Source.Common.Commands;
2+
3+
namespace Game.Client;
4+
5+
public enum GameAxis
6+
{
7+
None = 0,
8+
Forward,
9+
Pitch,
10+
Side,
11+
Yaw,
12+
Max
13+
}
14+
15+
public enum JoystickAxis
16+
{
17+
X = 0,
18+
Y,
19+
Z,
20+
R,
21+
U,
22+
V,
23+
Max
24+
}
25+
26+
public struct JoyAxis
27+
{
28+
public uint AxisMap;
29+
public uint ControlMap;
30+
}
31+
32+
public partial class Input
33+
{
34+
const uint JOY_ABSOLUTE_AXIS = 0x00000000;
35+
const uint JOY_RELATIVE_AXIS = 0x00000010;
36+
37+
static readonly ConVar joy_name = new("joy_name", "joystick", FCvar.Archive);
38+
static readonly ConVar joy_advanced = new("joy_advanced", "1", FCvar.Archive);
39+
static readonly ConVar joy_advaxisx = new("joy_advaxisx", "4", FCvar.Archive);
40+
static readonly ConVar joy_advaxisy = new("joy_advaxisy", "2", FCvar.Archive);
41+
static readonly ConVar joy_advaxisz = new("joy_advaxisz", "0", FCvar.Archive);
42+
static readonly ConVar joy_advaxisr = new("joy_advaxisr", "1", FCvar.Archive);
43+
static readonly ConVar joy_advaxisu = new("joy_advaxisu", "3", FCvar.Archive);
44+
static readonly ConVar joy_advaxisv = new("joy_advaxisv", "0", FCvar.Archive);
45+
static readonly ConVar joy_movement_stick = new("joy_movement_stick", "0", FCvar.Archive | FCvar.ArchiveXbox, "Which stick controls movement (0 is left stick)", callback: joy_movement_stick_Callback);
46+
static readonly ConVar joy_xcontroller_cfg_loaded = new("joy_xcontroller_cfg_loaded", "0", FCvar.Archive, "If 0, the 360controller.cfg file will be executed on startup & option changes.");
47+
48+
// todo: the rest of in_joystick.cpp (Init_Joystick, JoyStickMove and their ConVars)
49+
50+
readonly JoyAxis[] Axes = new JoyAxis[(int)JoystickAxis.Max];
51+
static ConVarRef? joy_xcontroller_found;
52+
53+
static void joy_movement_stick_Callback(IConVar var, in ConVarChangeContext ctx) {
54+
engine.ClientCmd("joyadvancedupdate");
55+
}
56+
57+
static ReadOnlySpan<char> DescribeAxis(uint index) {
58+
switch ((GameAxis)index) {
59+
case GameAxis.Forward:
60+
return "Forward";
61+
case GameAxis.Pitch:
62+
return "Look";
63+
case GameAxis.Side:
64+
return "Side";
65+
case GameAxis.Yaw:
66+
return "Turn";
67+
case GameAxis.None:
68+
default:
69+
return "Unknown";
70+
}
71+
}
72+
73+
static void DescribeJoystickAxis(string axis, in JoyAxis mapping) {
74+
if (mapping.AxisMap == 0)
75+
Msg("%s: unmapped\n", axis);
76+
else
77+
Msg("%s: mapped to %s (%s)\n", axis, DescribeAxis(mapping.AxisMap).ToString(), mapping.ControlMap != 0 ? "relative" : "absolute");
78+
}
79+
80+
void SetJoystickAxis(JoystickAxis axis, string name, int value) {
81+
uint temp = unchecked((uint)value);
82+
Axes[(int)axis].AxisMap = temp & 0x0000000f;
83+
Axes[(int)axis].ControlMap = temp & JOY_RELATIVE_AXIS;
84+
85+
DescribeJoystickAxis(name, in Axes[(int)axis]);
86+
}
87+
88+
public void Joystick_Advanced() {
89+
for (int i = 0; i < (int)JoystickAxis.Max; i++) {
90+
Axes[i].AxisMap = (uint)GameAxis.None;
91+
Axes[i].ControlMap = JOY_ABSOLUTE_AXIS;
92+
}
93+
94+
if (!joy_advanced.GetBool()) {
95+
Axes[(int)JoystickAxis.X].AxisMap = (uint)GameAxis.Yaw;
96+
Axes[(int)JoystickAxis.Y].AxisMap = (uint)GameAxis.Forward;
97+
}
98+
else {
99+
if (stricmp(joy_name.GetString(), "joystick") != 0)
100+
Msg("Using joystick '%s' configuration\n", joy_name.GetString());
101+
102+
SetJoystickAxis(JoystickAxis.X, "JOY_AXIS_X", joy_movement_stick.GetBool() ? joy_advaxisu.GetInt() : joy_advaxisx.GetInt());
103+
SetJoystickAxis(JoystickAxis.Y, "JOY_AXIS_Y", joy_movement_stick.GetBool() ? joy_advaxisr.GetInt() : joy_advaxisy.GetInt());
104+
SetJoystickAxis(JoystickAxis.Z, "JOY_AXIS_Z", joy_advaxisz.GetInt());
105+
SetJoystickAxis(JoystickAxis.R, "JOY_AXIS_R", joy_movement_stick.GetBool() ? joy_advaxisy.GetInt() : joy_advaxisr.GetInt());
106+
SetJoystickAxis(JoystickAxis.U, "JOY_AXIS_U", joy_movement_stick.GetBool() ? joy_advaxisx.GetInt() : joy_advaxisu.GetInt());
107+
SetJoystickAxis(JoystickAxis.V, "JOY_AXIS_V", joy_advaxisv.GetInt());
108+
109+
Msg("Advanced Joystick settings initialized\n");
110+
}
111+
112+
ConVarRef found = joy_xcontroller_found ??= new("joy_xcontroller_found");
113+
if (found.IsValid() && found.GetBool() && in_joystick.GetBool()) {
114+
if (joy_xcontroller_cfg_loaded.GetInt() < 2) {
115+
engine.ClientCmd_Unrestricted("exec 360controller.cfg");
116+
#if LINUX
117+
engine.ClientCmd_Unrestricted("exec 360controller-linux.cfg");
118+
#endif
119+
joy_xcontroller_cfg_loaded.SetValue(2);
120+
}
121+
}
122+
else if (joy_xcontroller_cfg_loaded.GetInt() > 0) {
123+
engine.ClientCmd_Unrestricted("exec undo360controller.cfg");
124+
joy_xcontroller_cfg_loaded.SetValue(0);
125+
}
126+
}
127+
}

‎Game.Client/InMain.cs‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public partial class Input(ISurface Surface, IViewRender view, ThirdPersonManage
5151
readonly ConVar cl_backspeed = new("450", FCvar.Replicated | FCvar.Cheat);
5252
readonly ConVar lookspring = new("0", FCvar.Archive);
5353
readonly ConVar lookstrafe = new("0", FCvar.Archive);
54-
readonly ConVar in_joystick = new("0", FCvar.Archive);
54+
readonly ConVar in_joystick = new("joystick", "0", FCvar.Archive);
5555
readonly ConVar thirdperson_platformer = new("0", 0, "Player will aim in the direction they are moving.");
5656
readonly ConVar thirdperson_screenspace = new("0", 0, "Movement will be relative to the camera, eg: left means screen-left");
5757
readonly ConVar sv_noclipduringpause = new("0", FCvar.Replicated | FCvar.Cheat, "If cheats are enabled, then you can noclip with the game paused (for doing screenshots, etc.).");
@@ -86,6 +86,8 @@ public partial class Input(ISurface Surface, IViewRender view, ThirdPersonManage
8686
KeyButtonState in_score;
8787
KeyButtonState in_break;
8888
KeyButtonState in_zoom;
89+
KeyButtonState in_grenade1;
90+
KeyButtonState in_grenade2;
8991
KeyButtonState in_attack3;
9092
Handle<BaseCombatWeapon> SelectedWeapon = new();
9193

@@ -208,6 +210,8 @@ void IN_ScoreDown(in TokenizedCommand args) {
208210
[ConCommand(name: "+graph", flags: IN_COMMAND_FLAGS)] void IN_GraphDown(in TokenizedCommand args) => KeyDown(ref in_graph, args[1]);
209211
[ConCommand(name: "+break", flags: IN_COMMAND_FLAGS)] void IN_BreakDown(in TokenizedCommand args) => KeyDown(ref in_break, args[1]);
210212
[ConCommand(name: "+zoom", flags: IN_COMMAND_FLAGS)] void IN_ZoomDown(in TokenizedCommand args) => KeyDown(ref in_zoom, args[1]);
213+
[ConCommand(name: "+grenade1", flags: IN_COMMAND_FLAGS)] void IN_Grenade1Down(in TokenizedCommand args) => KeyDown(ref in_grenade1, args[1]);
214+
[ConCommand(name: "+grenade2", flags: IN_COMMAND_FLAGS)] void IN_Grenade2Down(in TokenizedCommand args) => KeyDown(ref in_grenade2, args[1]);
211215
[ConCommand(name: "+attack3")] void IN_Attack3Down(in TokenizedCommand args) => KeyDown(ref in_attack3, args[1]);
212216

213217

@@ -248,8 +252,20 @@ void IN_ScoreUp(in TokenizedCommand args) {
248252
[ConCommand(name: "-graph", flags: IN_COMMAND_FLAGS)] void IN_GraphUp(in TokenizedCommand args) => KeyUp(ref in_graph, args[1]);
249253
[ConCommand(name: "-break", flags: IN_COMMAND_FLAGS)] void IN_BreakUp(in TokenizedCommand args) => KeyUp(ref in_break, args[1]);
250254
[ConCommand(name: "-zoom", flags: IN_COMMAND_FLAGS)] void IN_ZoomUp(in TokenizedCommand args) => KeyUp(ref in_zoom, args[1]);
255+
[ConCommand(name: "-grenade1", flags: IN_COMMAND_FLAGS)] void IN_Grenade1Up(in TokenizedCommand args) => KeyUp(ref in_grenade1, args[1]);
256+
[ConCommand(name: "-grenade2", flags: IN_COMMAND_FLAGS)] void IN_Grenade2Up(in TokenizedCommand args) => KeyUp(ref in_grenade2, args[1]);
251257
[ConCommand(name: "-attack3")] void IN_Attack3Up(in TokenizedCommand args) => KeyUp(ref in_attack3, args[1]);
252258

259+
[ConCommand(flags: IN_COMMAND_FLAGS)]
260+
void force_centerview() {
261+
engine.GetViewAngles(out QAngle viewangles);
262+
viewangles[PITCH] = 0;
263+
engine.SetViewAngles(in viewangles);
264+
}
265+
266+
[ConCommand(flags: FCvar.ClientCmdCanExecute)]
267+
void joyadvancedupdate() => Joystick_Advanced();
268+
253269
Hud Hud = null!;
254270

255271
UserCmd[] Commands = new UserCmd[MULTIPLAYER_BACKUP];
@@ -783,6 +799,8 @@ public InButtons GetButtonBits(int resetState) {
783799
CalcButtonBits(ref bits, InButtons.Alt2, ClearInputState, ref in_alt2, resetState);
784800
CalcButtonBits(ref bits, InButtons.Score, ClearInputState, ref in_score, resetState);
785801
CalcButtonBits(ref bits, InButtons.Zoom, ClearInputState, ref in_zoom, resetState);
802+
CalcButtonBits(ref bits, InButtons.Grenade1, ClearInputState, ref in_grenade1, resetState);
803+
CalcButtonBits(ref bits, InButtons.Grenade2, ClearInputState, ref in_grenade2, resetState);
786804
CalcButtonBits(ref bits, InButtons.Attack3, ClearInputState, ref in_attack3, resetState);
787805

788806
// TODO: duck toggle

‎Game.Client/View.cs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ public void GetScreenFadeDistances(out float min, out float max) {
150150
min = max = 0;
151151
}
152152

153-
public IMaterial? GetScreenOverlayMaterial() {
154-
throw new NotImplementedException();
155-
}
153+
// todo: PerformScreenOverlay draws it
154+
readonly MaterialReference ScreenOverlayMaterial = new();
155+
156+
public IMaterial? GetScreenOverlayMaterial() => ScreenOverlayMaterial.Get();
156157

157158
public ref ViewSetup GetViewSetup() {
158159
return ref CurrentView;
@@ -980,9 +981,7 @@ public void SetCheapWaterStartDistance(float cheapWaterStartDistance) {
980981
CheapWaterStartDistance = cheapWaterStartDistance;
981982
}
982983

983-
public void SetScreenOverlayMaterial(IMaterial? pMaterial) {
984-
throw new NotImplementedException();
985-
}
984+
public void SetScreenOverlayMaterial(IMaterial? pMaterial) => ScreenOverlayMaterial.Init(pMaterial!);
986985

987986
public bool ShouldDrawBrushModels() {
988987
throw new NotImplementedException();

‎Game.Client/ViewDebug.cs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using Source.Common;
1+
using Source;
2+
using Source.Common;
23
using Source.Common.Commands;
4+
using Source.Common.MaterialSystem;
35

46
using System;
57
using System.Collections.Generic;
@@ -12,6 +14,25 @@ public static class DebugViewRender
1214
public static readonly ConVar cl_drawshadowtexture = new("cl_drawshadowtexture", "0", FCvar.Cheat);
1315
public static readonly ConVar cl_shadowtextureoverlaysize = new("cl_shadowtextureoverlaysize", "256", FCvar.Cheat);
1416

17+
[ConCommand(helpText: "Draw specified material as an overlay", flags: FCvar.Cheat | FCvar.ServerCanExecute)]
18+
static void r_screenoverlay(in TokenizedCommand args) {
19+
if (args.ArgC() == 2) {
20+
if (stricmp("off", args[1]) == 0 || stricmp("0", args[1]) == 0)
21+
view.SetScreenOverlayMaterial(null);
22+
else {
23+
IMaterial? material = materials.FindMaterial(args[1], MaterialDefines.TEXTURE_GROUP_OTHER, false);
24+
if (!material.IsErrorMaterial())
25+
view.SetScreenOverlayMaterial(material);
26+
else
27+
view.SetScreenOverlayMaterial(null);
28+
}
29+
}
30+
else {
31+
IMaterial? material = view.GetScreenOverlayMaterial();
32+
Warning("r_screenoverlay: %s\n", material != null ? material.GetName().ToString() : "off");
33+
}
34+
}
35+
1536
public static void Draw3DDebuggingInfo(in ViewSetup view) {
1637
render.Draw3DDebugOverlays();
1738
}

‎Game.Shared/SoundEmitterSystem.cs‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
using Source.Common;
1313
using Source.Common.Audio;
14+
using Source.Common.Commands;
1415
using Source.Common.SoundEmitterSystem;
1516

1617
using System;
@@ -347,6 +348,50 @@ public void EmitAmbientSound(int entindex, in Vector3 origin, ReadOnlySpan<char>
347348
public static class SoundEmitterSystemGlobals
348349
{
349350
public static readonly SoundEmitterSystem g_SoundEmitterSystem = new();
351+
352+
#if CLIENT_DLL
353+
[ConCommand("playgamesound", "Play a sound from the game sounds txt file", FCvar.ClientCmdCanExecute | FCvar.ServerCanExecute, autoCompleteMethod: nameof(GamesoundCompletion))]
354+
static void Playgamesound_f(in TokenizedCommand args) {
355+
C_BasePlayer? player = C_BasePlayer.GetLocalPlayer();
356+
if (player != null) {
357+
if (args.ArgC() > 2) {
358+
Vector3 position = player.EyePosition();
359+
player.GetVectors(out Vector3 forward, out _, out _);
360+
position += (float)atof(args[2]) * forward;
361+
PASAttenuationFilter filter = new(player);
362+
scoped EmitSound_t parms = new();
363+
parms.SoundName = args[1];
364+
parms.Origin = ref position;
365+
parms.Volume = 0.0f;
366+
parms.Pitch = 0;
367+
g_SoundEmitterSystem.EmitSound(filter, 0, ref parms);
368+
}
369+
else
370+
player.EmitSound(args[1]);
371+
}
372+
else
373+
Msg("Can't play until a game is started.\n");
374+
}
375+
376+
static IEnumerable<string> GamesoundCompletion(string partial) {
377+
const string cmdname = "playgamesound";
378+
const int COMMAND_COMPLETION_MAXITEMS = 64;
379+
string? substring = null;
380+
if (partial.Contains(cmdname, StringComparison.Ordinal) && partial.Length > cmdname.Length + 1)
381+
substring = partial[(cmdname.Length + 1)..];
382+
383+
int current = 0;
384+
for (int i = soundemitterbase.GetSoundCount() - 1; i >= 0 && current < COMMAND_COMPLETION_MAXITEMS; i--) {
385+
if (soundemitterbase.GetSoundName(i).IsEmpty)
386+
continue;
387+
388+
if (substring == null || soundemitterbase.GetSoundName(i).StartsWith(substring, StringComparison.OrdinalIgnoreCase)) {
389+
yield return $"{cmdname} {soundemitterbase.GetSoundName(i)}";
390+
current++;
391+
}
392+
}
393+
}
394+
#endif
350395
}
351396

352397
public partial class

0 commit comments

Comments
 (0)