Skip to content

Commit

Permalink
Added debug print function like print3d, line, printstar
Browse files Browse the repository at this point in the history
  • Loading branch information
Beasty committed Feb 9, 2019
1 parent 905adc6 commit ebcae05
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 121 deletions.
24 changes: 24 additions & 0 deletions scriptdocumentation/script_functions_reference.md
Expand Up @@ -502,6 +502,30 @@ Usage example 1: `bot botLookAt(ent.origin); // Instant look at ent's origin`

Usage example 2: `bot botLookAt((0, 0, 0), 5.0); // Look at map center. Rotation will take 5.0 seconds.`

### Script Debug Functions
The following functions need the next yet unreleased client version. Also on clientside "set developer 1" has to be enabled.

print3d() and line() function will do something useful now. The duration parameter is internally multiplied by 10. All objects are shown for 10*duration client frames.


#### `printstar(<point>[, <starcolor>, <staralpha>, <duration>, <text>, <textcolor>, <textalpha>, <textscale>]);`

Will print a debug-star into the 3D space.

*point*: 3-dimensional origin (x, y, z) where to print.
*starcolor*: Color of the star (r, g, b) - optional
*staralpha*: Transparence of the star - optional
*duration*: 10 times number of clientframes this shows - optional, defaults to 10 frames
*text*: Optional text printed near star - optional
*textcolor*: Color of text - optional
*textalpha*: Transparence of the text - optional
*textscale*: Size of text - optional

Usage example 1: `printstar((0, 0, 200), (1, 0, 0), 1, 20); //Prints a red star at 0,0,200 for 200 clientframes
Usage example 2: `printstar((0, 0, 200), (1, 0, 0), 1, 5, "example", (0, 1, 0), 1, 0.5); //Prints a red star at 0,0,200 for 50 clientframes with text "example" with color green and textscale 0.5



## Appendix: All Known Script Functions

### Player Functions
Expand Down
105 changes: 0 additions & 105 deletions src/asmsource/_g_scr_main_mp.asm
Expand Up @@ -254,7 +254,6 @@
global println
global iprintln
global iprintlnbold
global GScr_print3d
global GScr_line
global GScr_SpawnPlane
global GScr_SpawnTurret
Expand Down Expand Up @@ -817,109 +816,6 @@ iprintlnbold:
ret
nop


;GScr_print3d()
GScr_print3d:
push ebp
mov ebp, esp
push edi
push esi
push ebx
sub esp, 0x6c
mov eax, 0x3f800000
mov [ebp-0x40], eax
mov [ebp-0x3c], eax
mov [ebp-0x38], eax
mov [ebp-0x34], eax
call Scr_GetNumParam
cmp eax, 0x6
ja GScr_print3d_10
jmp dword [eax*4+GScr_print3d_jumptab_0]
GScr_print3d_10:
mov dword [esp], _cstring_illegal_call_to_2
call Scr_Error
add esp, 0x6c
pop ebx
pop esi
pop edi
pop ebp
ret
GScr_print3d_60:
mov edi, 0x1
movss xmm0, dword [_float_1_00000000]
movss [ebp-0x4c], xmm0
GScr_print3d_20:
mov dword [esp], 0x1
call Scr_GetString
mov ebx, eax
lea esi, [ebp-0x24]
mov [esp+0x4], esi
mov dword [esp], 0x0
call Scr_GetVector
mov [esp+0x10], edi
mov [esp+0xc], ebx
movss xmm0, dword [ebp-0x4c]
movss [esp+0x8], xmm0
lea eax, [ebp-0x40]
mov [esp+0x4], eax
mov [esp], esi
call G_AddDebugString
add esp, 0x6c
pop ebx
pop esi
pop edi
pop ebp
ret
GScr_print3d_100:
mov dword [esp], 0x5
call Scr_GetInt
mov edi, eax
GScr_print3d_30:
mov dword [esp], 0x4
call Scr_GetFloat
fstp dword [ebp-0x4c]
GScr_print3d_40:
mov dword [esp], 0x3
call Scr_GetFloat
fstp dword [ebp-0x34]
GScr_print3d_50:
lea eax, [ebp-0x30]
mov [esp+0x4], eax
mov dword [esp], 0x2
call Scr_GetVector
mov eax, [ebp-0x30]
mov [ebp-0x40], eax
mov eax, [ebp-0x2c]
mov [ebp-0x3c], eax
mov eax, [ebp-0x28]
mov [ebp-0x38], eax
jmp GScr_print3d_20
GScr_print3d_90:
mov edi, 0x1
jmp GScr_print3d_30
GScr_print3d_80:
mov edi, 0x1
movss xmm0, dword [_float_1_00000000]
movss [ebp-0x4c], xmm0
jmp GScr_print3d_40
GScr_print3d_70:
mov edi, 0x1
movss xmm0, dword [_float_1_00000000]
movss [ebp-0x4c], xmm0
jmp GScr_print3d_50
nop
GScr_print3d_jumptab_0:
dd GScr_print3d_10
dd GScr_print3d_10
dd GScr_print3d_60
dd GScr_print3d_70
dd GScr_print3d_80
dd GScr_print3d_90
dd GScr_print3d_100


;GScr_line()
GScr_line:
push ebp
Expand Down Expand Up @@ -15195,7 +15091,6 @@ _cstring_: db 0ah,0
_cstring_c: db "%c",0
_cstring_game_message: db "Game Message",0
_cstring_s_s: db "%s ",22h,"%s",22h,0
_cstring_illegal_call_to_2: db "illegal call to print3d()",0
_cstring_illegal_call_to_3: db "illegal call to line()",0
_cstring_unable_to_spawn_: db "unable to spawn ",22h,"%s",22h," entity",0
_cstring_owner_entity_is_: db "Owner entity is not a player",0
Expand Down
66 changes: 66 additions & 0 deletions src/cl_dedicated.cpp
@@ -0,0 +1,66 @@
/*
===========================================================================
Copyright (C) 2010-2013 Ninja and TheKelm
This file is part of CoD4X18-Server source code.
CoD4X18-Server source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoD4X18-Server source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/

#include "q_shared.h"
#include "qcommon_io.h"
#include "qcommon.h"
#include "server.h"
#include "client_dedicated.h"
#include <string.h>


vec4_t MYNULLTEXTCOLOR = { 0, 0, 0, 0 };

extern "C"
{

void __cdecl CL_AddDebugLine(const float *start, const float *end, const float *color, int depthTest, int duration)
{
duration *= 10;
SV_SendServerCommand(NULL, "M l %f %f %f;%f %f %f;%f %f %f %f;%d;%d", start[0], start[1], start[2], end[0], end[1], end[2],
color[0], color[1], color[2], color[3], depthTest, duration);
}

void __cdecl CL_AddDebugStarWithText(const float *point, const float *starColor, const float *textColor, const char *string, float fontsize, int duration)
{
duration *= 10;
if(string == NULL){
string = "";
}
SV_SendServerCommand(NULL, "M S %f %f %f;%f %f %f %f;%f %f %f %f;%f;%d;%s", point[0], point[1], point[2],
starColor[0], starColor[1], starColor[2], starColor[3],
textColor[0], textColor[1], textColor[2], textColor[3], fontsize, duration, string);
}

void __cdecl CL_AddDebugStar(const float *point, const float *color, int duration)
{
CL_AddDebugStarWithText(point, color, MYNULLTEXTCOLOR, NULL, 1.0, duration);
}

void __cdecl CL_AddDebugString(const float *xyz, const float *color, float scale, const char *text, int duration)
{
duration *= 10;
SV_SendServerCommand(NULL, "M t %f %f %f;%f %f %f %f;%f;%d;%s", xyz[0], xyz[1], xyz[2],
color[0], color[1], color[2], color[3], scale, duration, text);
}

};

14 changes: 14 additions & 0 deletions src/client_dedicated.h
@@ -0,0 +1,14 @@
#pragma once

#ifdef __cplusplus
extern "C"{
#endif

void __cdecl CL_AddDebugLine(const float *start, const float *end, const float *color, int depthTest, int duration);
void __cdecl CL_AddDebugStarWithText(const float *point, const float *starColor, const float *textColor, const char *string, float fontsize, int duration);
void __cdecl CL_AddDebugStar(const float *point, const float *color, int duration);
void __cdecl CL_AddDebugString(const float *xyz, const float *color, float scale, const char *text, int duration);

#ifdef __cplusplus
};
#endif
14 changes: 0 additions & 14 deletions src/null_client.cpp
Expand Up @@ -259,20 +259,6 @@ void __cdecl CG_VisionSetMyChanges()
{
}

void __cdecl CL_AddDebugLine(const float *start, const float *end, const float *color, int depthTest, int duration)
{
}
void __cdecl CL_AddDebugStarWithText(const float *point, const float *starColor, const float *textColor, const char *string, float fontsize, int duration)
{
}

void __cdecl CL_AddDebugStar(const float *point, const float *color, int duration)
{
}

void __cdecl CL_AddDebugString(const float *xyz, const float *color, float scale, const char *text, int duration)
{
}

int SND_GetEntChannelCount(void)
{
Expand Down
100 changes: 100 additions & 0 deletions src/scr_vm_functions.c
Expand Up @@ -35,6 +35,7 @@
#include "sv_auth.h"
#include "cscr_stringlist.h"
#include "bg.h"
#include "client_dedicated.h"

#include "sapi.h"
#include <string.h>
Expand Down Expand Up @@ -3277,3 +3278,102 @@ void PlayerCmd_SetStance(scr_entref_t playerEntNum)
BGEvent event = stanceIdx == (unsigned short)scr_const.stand ? EV_STANCE_FORCE_STAND : stanceIdx == (unsigned short)scr_const.crouch ? EV_STANCE_FORCE_CROUCH : EV_STANCE_FORCE_PRONE;
BG_AddPredictableEventToPlayerstate(event, 0, cl);
}



void GScr_Print3D()
{
signed int duration;
vec3_t origin;
vec3_t rgb;
float scale;
vec4_t color;
const char *text;

duration = 1;
scale = 1.0;
color[0] = 1.0;
color[1] = 1.0;
color[2] = 1.0;
color[3] = 1.0;
switch ( Scr_GetNumParam( ) )
{
case 6u:
duration = Scr_GetInt(5u);
case 5u:
scale = Scr_GetFloat(4u);
case 4u:
color[3] = Scr_GetFloat(3u);
case 3u:
Scr_GetVector(2u, rgb);
VectorCopy(rgb, color);
case 2u:
text = Scr_GetString(1u);
Scr_GetVector(0, origin);
CL_AddDebugString(origin, color, scale, text, duration);
break;
default:
Scr_Error("illegal call to print3d()");
break;
}
}

//printstar(<point>, <starcolor>, <staralpha>, <duration>, <text>, <textcolor>, <textalpha>, <textscale>);

void GScr_PrintDebugStar()
{
signed int duration;
vec3_t point;
vec3_t rgb;
float scale;
vec4_t starColor, textColor;
const char *text;

duration = 1;
scale = 1.0;
text = NULL;
starColor[0] = 1.0;
starColor[1] = 1.0;
starColor[2] = 1.0;
starColor[3] = 1.0;

textColor[0] = 1.0;
textColor[1] = 1.0;
textColor[2] = 1.0;
textColor[3] = 1.0;

switch ( Scr_GetNumParam( ) )
{

case 8u:
scale = Scr_GetFloat(7u);

case 7u:
textColor[3] = Scr_GetFloat(6u);
case 6u:
Scr_GetVector(5u, rgb);
VectorCopy(rgb, textColor);


case 5u:
text = Scr_GetString(4u);

case 4u:
duration = Scr_GetInt(3u);

case 3u:
starColor[3] = Scr_GetFloat(2u);
case 2u:
Scr_GetVector(1u, rgb);
VectorCopy(rgb, starColor);

case 1u:
Scr_GetVector(0, point);
CL_AddDebugStarWithText(point, starColor, textColor, text, scale, duration);
break;
default:
Scr_Error("illegal call to printstar()");
break;
}
}

3 changes: 2 additions & 1 deletion src/scr_vm_functions.h
Expand Up @@ -131,7 +131,8 @@ void print();
void println();
void iprintln();
void iprintlnbold();
void GScr_print3d();
void GScr_Print3D();
void GScr_PrintDebugStar();
void GScr_line();
void Scr_GetEnt();
void Scr_GetEntArray();
Expand Down
3 changes: 2 additions & 1 deletion src/scr_vm_main.c
Expand Up @@ -57,7 +57,8 @@ void Scr_AddStockFunctions()
Scr_AddFunction("println", println, 1 );
Scr_AddFunction("iprintln", iprintln, 0 );
Scr_AddFunction("iprintlnbold", iprintlnbold, 0 );
Scr_AddFunction("print3d", GScr_print3d, 1 );
Scr_AddFunction("print3d", GScr_Print3D, 1 );
Scr_AddFunction("printstar", GScr_PrintDebugStar, 1 );
Scr_AddFunction("line", GScr_line, 1 );
Scr_AddFunction("getent", Scr_GetEnt, 0 );
Scr_AddFunction("getentarray", Scr_GetEntArray, 0 );
Expand Down

0 comments on commit ebcae05

Please sign in to comment.