-
Notifications
You must be signed in to change notification settings - Fork 0
/
removing.cpp
4259 lines (3747 loc) · 104 KB
/
removing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Lua notes/considerations
There are eight basic types in Lua:
nil,
boolean,
number,
string,
function,
userdata,
thread,
and table.
The type nil has one single value, nil, whose main property is to be different from any other value; it often represents the absence of a useful value. The type boolean has two values, false and true. Both nil and false make a condition false; they are collectively called false values. Any other value makes a condition true.
Tables are passed by reference
Strings are immutable
L is passed to every function, its the Lua State
The arguments to the call are pushed in direct order; that is, the first argument is pushed first.
So when parsing arguments, walk up the stack from bot to top
A positive index represents an absolute stack position, starting at 1 as the bottom of the stack;
-1 is the top of the stack
It uses a stack system.
1 is bottom of stack
X is top of stack
-1 is also top of stack
-X is bottom of stack
You need to pop things off stack depending on which func you call.
I execute all lua scripts in sofplus/addons/lua directory on startup.
https://lucasklassmann.com/blog/2019-02-02-how-to-embeddeding-lua-in-c/
The loadfile returns a 'chunk' onto the stack.
A chunk is like a function , essentially.
You have to 'call' that chunk.. then all of the global names it defines will be created.
lua_pcall is popping its arguments off stack, if you eg pushed a function to it.
I'm clearing stack often with lua_settop(L,0).
You can find lua types in lua.h. You can check for nil return, if the global name does not exist.
lua_pop - pops N elements frmo the stack
If your function does an operation on 1st argument.
Return a new copy because its more convenient for the lua
programmer to do eg.: x = func(bla,bla2) than
before = bla
func(bla,bla2)
Timing is a big issue when it comes to understanding integration with console.
The quake 2 console is parsed before the game frame..
sofplus uses Cbuf_AddText , for callbacks, so all action is happening at beginning of frame.
Thus with data from previous frame, ( 100 msec ago)
To make lua functions be in sync with the sofplus functions, its important that it does not use
AddText, because it needs higher priority, (i think).
*/
#include <windows.h>
#include "sofheader.h"
#include <stdlib.h>
#include <string.h>
// StrStrI
#include <shlwapi.h>
#include <list>
//globals
void * gametype_self = 0x5015C4D8;
void * player_export = NULL;
short prev_sidemove[16];
byte prev_buttons[16];
// TODO USE THIS METHOD IN FUTURE.
/*
#define FOFS(x) (int)&(((edict_t *)0)->x)
#define STOFS(x) (int)&(((spawn_temp_t *)0)->x)
#define LLOFS(x) (int)&(((level_locals_t *)0)->x)
#define CLOFS(x) (int)&(((gclient_t *)0)->x)
*/
void InitFields(void);
void luaCreateFunc(char * name,int (*inFunc)(lua_State *L));
void luaCreateFunc(char * name,int (*inFunc)(lua_State *L))
{
lua_pushcfunction(L,inFunc);
lua_setglobal(L,name);
}
void luaLoadFiles(void)
{
char **file_list = NULL;
int file_list_len;
ListDirectoryContents("user-server\\sofplus\\addons\\lua",&file_list,&file_list_len);
orig_Com_Printf("There are %i entries\n",file_list_len);
/*
Run all .lua scripts in lua directory.
*/
for ( int i=0; i < file_list_len;i++)
{
char * filepath = *(file_list+i);
orig_Com_Printf("loading %s\n",filepath);
// LUA_MULTRET
if (luaL_loadfile(L, filepath) == LUA_OK) {
// state,Nargs,Nrets,messageHandler
if (lua_pcall(L, 0, LUA_MULTRET, 0) == LUA_OK) {
// if it returned anything to us.
lua_settop(L,0);
// lua_pop(L, lua_gettop(L));
}
} else {
orig_Com_Error(ERR_FATAL,"%s\n",lua_tostring(L, -1));
lua_settop(L,0);
}
}
}
void createCommands(void)
{
L = luaL_newstate();
luaL_openlibs(L);
InitFields();
/*
Creating the Custom LUA Api
Binds C functions to LUA Names
By pushing a function to the stack
Then setting a global 'name' for it.
*/
luaCreateFunc("sf_sv_console_write",sf_sv_console_write);
luaCreateFunc("sf_sv_ent_create",sf_sv_ent_create);
luaCreateFunc("sf_sv_ent_field_set",sf_sv_ent_field_set);
luaCreateFunc("sf_sv_ent_field_get",sf_sv_ent_field_get);
luaCreateFunc("sf_sv_ent_spawn",sf_sv_ent_spawn);
luaCreateFunc("sf_sv_ent_remove",sf_sv_ent_remove);
luaCreateFunc("sf_sv_ent_use",sf_sv_ent_use);
luaCreateFunc("sf_sv_ent_callback",sf_sv_ent_callback);
luaCreateFunc("sf_sv_ent_anim",sf_sv_ent_anim);
// redundant cos of table copy of lua
// luaCreateFunc("sf_sv_vector_copy",sf_sv_vector_copy);
luaCreateFunc("sf_sv_vector_create",sf_sv_vector_create);
luaCreateFunc("sf_sv_player_pos",sf_sv_player_pos);
luaCreateFunc("sf_sv_player_ent",sf_sv_player_ent);
luaCreateFunc("sf_sv_player_move",sf_sv_player_move);
luaCreateFunc("sf_sv_player_weap_lock",sf_sv_player_weap_lock);
luaCreateFunc("sf_sv_player_weap_current",sf_sv_player_weap_current);
luaCreateFunc("sf_sv_player_weap_switch",sf_sv_player_weap_switch);
luaCreateFunc("sf_sv_sound_register",sf_sv_sound_register);
luaCreateFunc("sf_sv_sound_play_ent",sf_sv_sound_play_ent);
luaCreateFunc("sf_sv_sound_play_origin",sf_sv_sound_play_origin);
luaLoadFiles();
orig_Cmd_AddCommand("sf_sv_sofree_help",(void*)Cmd_SofreeHelp);
orig_Cmd_AddCommand("sf_sv_lua_func_exec",(void*)sf_sv_lua_func_exec);
orig_Cmd_AddCommand("sf_sv_cmd_list",(void*)sf_sv_cmd_list);
//if sofplus
// orig_Cmcomd_RemoveCommand("sf_sv_client_swap");
// orig_Cmd_RemoveCommand("sf_sv_client_red");
// orig_Cmd_RemoveCommand("sf_sv_client_blue");
// orig_Cmd_AddCommand("sf_sv_client_blue",(void*)Cmd_Blue_f);
// orig_Cmd_AddCommand("sf_sv_client_red",(void*)Cmd_Red_f);
// orig_Cmd_AddCommand("sf_sv_client_swap",(void*)Cmd_Swap_f);
// orig_Cmd_AddCommand("Cmd_TakePiss",(void*)Cmd_TakePiss);
orig_Cmd_AddCommand("sf_sv_check_reso",(void*)sf_sv_check_reso);
orig_Cmd_AddCommand("sf_sv_save_reso",(void*)sf_sv_save_reso);
orig_Cmd_AddCommand("sf_sv_vector_grow",(void*)sf_sv_vector_grow);
orig_Cmd_AddCommand("sf_sv_vector_copy",(void*)sf_sv_vector_copy);
orig_Cmd_AddCommand("sf_sv_vector_create",(void*)sf_sv_vector_create);
// orig_Cmd_AddCommand("sf_sv_vector_add",(void*)sf_sv_vector_add);
// orig_Cmd_AddCommand("sf_sv_vector_subtract",(void*)sf_sv_vector_subtract);
// orig_Cmd_AddCommand("sf_sv_vector_scale",(void*)sf_sv_vector_scale);
// orig_Cmd_AddCommand("sf_sv_vector_normalize",(void*)sf_sv_vector_normalize);
// orig_Cmd_AddCommand("sf_sv_vector_length",(void*)sf_sv_vector_length);
// orig_Cmd_AddCommand("sf_sv_vector_dotproduct",(void*)sf_sv_vector_dotproduct);
orig_Cmd_AddCommand("sf_sv_print_cprintf",(void*)sf_sv_print_cprintf);
orig_Cmd_AddCommand("sf_sv_print_bprintf",(void*)sf_sv_print_bprintf);
orig_Cmd_AddCommand("sf_sv_print_centerprint",(void*)sf_sv_print_centerprint);
// failure - does not work
orig_Cmd_AddCommand("sf_sv_print_welcomeprint",(void*)sf_sv_print_welcomeprint);
orig_Cmd_AddCommand("sf_sv_print_cinprintf",(void*)sf_sv_print_cinprintf);
orig_Cmd_AddCommand("sf_sv_draw_string",(void*)sf_sv_draw_string);
orig_Cmd_AddCommand("sf_sv_draw_string2",(void*)sf_sv_draw_string2);
orig_Cmd_AddCommand("sf_sv_draw_altstring",(void*)sf_sv_draw_altstring);
orig_Cmd_AddCommand("sf_sv_draw_clear",(void*)sf_sv_draw_clear);
orig_Cmd_AddCommand("sf_sv_spackage_register",(void*)sf_sv_spackage_register);
orig_Cmd_AddCommand("sf_sv_spackage_print_id",(void*)sf_sv_spackage_print_id);
orig_Cmd_AddCommand("sf_sv_spackage_print_ref",(void*)sf_sv_spackage_print_ref);
orig_Cmd_AddCommand("sf_sv_spackage_print_obit",(void*)sf_sv_spackage_print_obit);
orig_Cmd_AddCommand("sf_sv_spackage_print_string",(void*)sf_sv_spackage_print_string);
orig_Cmd_AddCommand("sf_sv_spackage_list",(void*)sf_sv_spackage_list);
orig_Cmd_AddCommand("Cmd_SP_GetStringText",(void*)Cmd_SP_GetStringText);
orig_Cmd_AddCommand("sf_sv_sound_remove",(void*)sf_sv_sound_remove);
orig_Cmd_AddCommand("sf_sv_sound_register",(void*)sf_sv_sound_register);
orig_Cmd_AddCommand("sf_sv_sound_play_origin",(void*)sf_sv_sound_play_origin);
orig_Cmd_AddCommand("sf_sv_sound_play_ent",(void*)sf_sv_sound_play_ent);
orig_Cmd_AddCommand("sf_sv_sound_override",(void*)sf_sv_sound_override);
orig_Cmd_AddCommand("sf_sv_sound_list",(void*)sf_sv_sound_list);
orig_Cmd_AddCommand("sf_sv_script_unload",(void*)sf_sv_script_unload);
orig_Cmd_AddCommand("sf_sv_script_run",(void*)sf_sv_script_run);
orig_Cmd_AddCommand("sf_sv_script_load",(void*)sf_sv_script_load);
orig_Cmd_AddCommand("sf_sv_player_gravity",(void*)sf_sv_player_gravity);
orig_Cmd_AddCommand("sf_sv_player_pos",(void*)sf_sv_player_pos);
orig_Cmd_AddCommand("sf_sv_player_paint",(void*)sf_sv_player_paint);
orig_Cmd_AddCommand("sf_sv_player_move",(void*)sf_sv_player_move);
orig_Cmd_AddCommand("sf_sv_player_effect",(void*)sf_sv_player_effect);
orig_Cmd_AddCommand("sf_sv_player_ent",(void*)sf_sv_player_ent);
orig_Cmd_AddCommand("sf_sv_player_collision",(void*)sf_sv_player_collision);
orig_Cmd_AddCommand("sf_sv_player_anim",(void*)sf_sv_player_anim);
orig_Cmd_AddCommand("sf_sv_player_allow_attack",(void*)sf_sv_player_allow_attack);
orig_Cmd_AddCommand("sf_sv_player_allow_altattack",(void*)sf_sv_player_allow_altattack);
orig_Cmd_AddCommand("sf_sv_player_allow_walk",(void*)sf_sv_player_allow_walk);
orig_Cmd_AddCommand("sf_sv_player_weap_lock",(void*)sf_sv_player_weap_lock);
orig_Cmd_AddCommand("sf_sv_player_weap_switch",(void*)sf_sv_player_weap_switch);
orig_Cmd_AddCommand("sf_sv_player_weap_paint",(void*)sf_sv_player_weap_paint);
orig_Cmd_AddCommand("sf_sv_player_weap_current",(void*)sf_sv_player_weap_current);
orig_Cmd_AddCommand("sf_sv_effect_endpos",(void*)sf_sv_effect_endpos);
orig_Cmd_AddCommand("sf_sv_effect_start",(void*)sf_sv_effect_start);
orig_Cmd_AddCommand("sf_sv_effect_list",(void*)sf_sv_effect_list);
orig_Cmd_AddCommand("sf_sv_effect_register",(void*)sf_sv_effect_register);
orig_Cmd_AddCommand("sf_sv_ent_paint",(void*)sf_sv_ent_paint);
orig_Cmd_AddCommand("sf_sv_ent_vects",(void*)sf_sv_ent_vects);
orig_Cmd_AddCommand("sf_sv_ent_spawn",(void*)sf_sv_ent_spawn);
orig_Cmd_AddCommand("sf_sv_ent_remove",(void*)sf_sv_ent_remove);
orig_Cmd_AddCommand("sf_sv_ent_find",(void*)sf_sv_ent_find);
orig_Cmd_AddCommand("sf_sv_ent_create",(void*)sf_sv_ent_create);
orig_Cmd_AddCommand("sf_sv_ent_use",(void*)sf_sv_ent_use);
orig_Cmd_AddCommand("sf_sv_ent_anim",(void*)sf_sv_ent_anim);
orig_Cmd_AddCommand("sf_sv_ent_relink",(void*)sf_sv_ent_relink);
orig_Cmd_AddCommand("sf_sv_ent_model",(void*)sf_sv_ent_model);
orig_Cmd_AddCommand("sf_sv_ent_bolt",(void*)sf_sv_ent_bolt);
orig_Cmd_AddCommand("sf_sv_ent_tint",(void*)sf_sv_ent_tint);
orig_Cmd_AddCommand("sf_sv_ent_callback",(void*)sf_sv_ent_callback);
orig_Cmd_AddCommand("sf_sv_ent_field_get",(void*)sf_sv_ent_field_get);
orig_Cmd_AddCommand("sf_sv_ent_field_set",(void*)sf_sv_ent_field_set);
orig_Cmd_AddCommand("sf_sv_image_register",(void*)sf_sv_image_register);
orig_Cmd_AddCommand("sf_sv_image_list",(void*)sf_sv_image_list);
orig_Cmd_AddCommand("sf_sv_ghoul_scale",(void*)sf_sv_ghoul_scale);
orig_Cmd_AddCommand("sf_sv_ghoul_translate",(void*)sf_sv_ghoul_translate);
orig_Cmd_AddCommand("sf_sv_ghoul_register",(void*)sf_sv_ghoul_register);
orig_Cmd_AddCommand("sf_sv_ghoul_list",(void*)sf_sv_ghoul_list);
orig_Cmd_AddCommand("sf_sv_int_add",(void*)sf_sv_int_add);
orig_Cmd_AddCommand("sf_sv_mem_read_string",(void*)sf_sv_mem_read_string);
orig_Cmd_AddCommand("sf_sv_mem_read_short",(void*)sf_sv_mem_read_short);
orig_Cmd_AddCommand("sf_sv_jmp_at",(void*)sf_sv_jmp_at);
orig_Cmd_AddCommand("sf_sv_hook_at",(void*)sf_sv_hook_at);
orig_Cmd_AddCommand("sf_sv_mem_read_int",(void*)sf_sv_mem_read_int);
orig_Cmd_AddCommand("sf_sv_mem_read_float",(void*)sf_sv_mem_read_float);
orig_Cmd_AddCommand("sf_sv_mem_read_char",(void*)sf_sv_mem_read_char);
orig_Cmd_AddCommand("sf_sv_mem_write_char",(void*)sf_sv_mem_write_char);
orig_Cmd_AddCommand("sf_sv_mem_write_short",(void*)sf_sv_mem_write_short);
orig_Cmd_AddCommand("sf_sv_mem_write_float",(void*)sf_sv_mem_write_float);
orig_Cmd_AddCommand("sf_sv_mem_write_int",(void*)sf_sv_mem_write_int);
orig_Cmd_AddCommand("sf_sv_mem_write_string",(void*)sf_sv_mem_write_string);
orig_Cmd_AddCommand("sf_sv_configstring_set",(void*)sf_sv_configstring_set);
orig_Cmd_AddCommand("sf_sv_math_sin",(void*)sf_sv_math_sin);
orig_Cmd_AddCommand("sf_sv_math_asin",(void*)sf_sv_math_asin);
orig_Cmd_AddCommand("sf_sv_math_cos",(void*)sf_sv_math_cos);
orig_Cmd_AddCommand("sf_sv_math_acos",(void*)sf_sv_math_acos);
orig_Cmd_AddCommand("sf_sv_math_tan",(void*)sf_sv_math_tan);
orig_Cmd_AddCommand("sf_sv_math_atan",(void*)sf_sv_math_atan);
orig_Cmd_AddCommand("sf_sv_math_or",(void*)sf_sv_math_or);
orig_Cmd_AddCommand("sf_sv_math_and",(void*)sf_sv_math_and);
orig_Cmd_AddCommand("sf_sv_math_not",(void*)sf_sv_math_not);
}
/*
This is not a LuA func!.
input string of lua global func name to exec in lua
*/
void sf_sv_lua_func_exec(void)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
int args = orig_Cmd_Argc() - 1;
printf("%i\n",args);
assert(args==1);
lua_getglobal (L,orig_Cmd_Argv(1));
if (lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK)
orig_Com_Error(ERR_FATAL,"%s\n",lua_tostring(L, -1));
lua_settop(L,0);
}
/*__attribute__((always_inline))int LuaPopInt()
{
return (int)round(lua_tonumber(L,-1));
}*/
int sf_sv_console_write(lua_State *L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
int n = lua_gettop(L);
char * str = lua_tostring(L,-1);
orig_Cbuf_AddText(str);
}
int sf_sv_configstring_set(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
int index = lua_tointeger(L,1);
// index string
orig_PF_Configstring(index,lua_tostring(L,2));
return 0;
}
int reso2d[16][2];
bool show_score[16];
/*
3 arguments
playerslot Xreso Yreso
IN: Slot Id
IN: X Y
*/
//playerslot xvalue yvalue
int sf_sv_save_reso(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
int y = lua_tointeger(L,3);
int x = lua_tointeger(L,2);
int slot = lua_tointeger(L,1);
reso2d[slot][1] = x;
reso2d[slot][0] = y;
return 0;
}
//slot id cvar
//request cvar check to client before they have fully entered server
int sf_sv_check_reso(lua_State * L)
{
/*
3 arguments
playerslot Id cvarname
*/
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
int slot = lua_tointeger(L,1);
char * cId= lua_tostring(L,2);
char * cvar = lua_tostring(L,3);
char mycvarcheck[256];
//id cvar val
sprintf(mycvarcheck,"cmd ,check %s %s #%s\n",cId,cvar,cvar);
//cmd .check id cvar val
orig_PF_WriteByte((unsigned char)STUFFTEXT);
orig_PF_WriteString(mycvarcheck);
edict_t * ent = get_ent_from_player_slot(slot);
orig_PF_Unicast(ent,true);
return 0;
}
int sf_sv_cmd_list(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
cmd_function_t * cmd;
for ( cmd = *(unsigned int*)0x20241840; cmd ; cmd=cmd->next)
if (strstr (cmd->name,"sf_sv_") == cmd->name)
orig_Com_Printf("%s\n",cmd->name);
return 0;
}
void randomBoxCode(void)
{
cvar_t * testbla = orig_Cvar_Get("testbla","",NULL,NULL);
if ( strlen(testbla->string) ) {
vec3_t start = {-741,229,136};
vec3_t tmp;
// VectorCopy(ent->s.origin,start);
// orig_Com_Printf("your origin is : %f %f %f\n",ent->s.origin[0],ent->s.origin[1],ent->s.origin[2]);
int color = 0;
vec3_t mins = {0,0,0};
vec3_t maxs = {15,15,15};
int iter = testbla->value;
for ( int i = 0 ; i < iter; i++ ) {
tmp[1] = start[1] + 50 * i;
for ( int j = 0 ; j < iter; j++ ) {
tmp[0] = start[0] + 50 * j;
tmp[2] = start[2];
// orig_Com_Printf("your origin is : %f %f %f\n",tmp[0],tmp[1],tmp[2]);
// orig_Com_Printf("Calling debug_drawbox %f\n",start);
color = color % 12;
debug_drawbox2(NULL, tmp ,mins,maxs, color );
color++;
}
}
start[2] = 200;
// VectorCopy(ent->s.origin,start);
// orig_Com_Printf("your origin is : %f %f %f\n",ent->s.origin[0],ent->s.origin[1],ent->s.origin[2]);
color = 0;
iter = testbla->value;
for ( int i = 0 ; i < iter; i++ ) {
tmp[1] = start[1] + 50 * i;
for ( int j = 0 ; j < iter; j++ ) {
tmp[0] = start[0] + 50 * j;
tmp[2] = start[2];
// orig_Com_Printf("your origin is : %f %f %f\n",tmp[0],tmp[1],tmp[2]);
// orig_Com_Printf("Calling debug_drawbox %f\n",start);
color = color % 12;
debug_drawbox(NULL, tmp ,mins,maxs, color );
color++;
}
}
}
// edict_t * ent = get_ent_from_player_slot(0);
// if ( ent && ent->inuse) {
// }
}
#define HELP_TEXT "\001"
#define HELP_BOLD "\030"
void Cmd_SofreeHelp(void)
{
orig_Com_Printf(HELP_TEXT
" SSSS f f ff !! \n"
" S o f E E E E E E !! \n"
"SS o o f ff E E !! \n"
" SS o o f r r r E E E E E E !! \n"
" S o o f r E E \n"
"SSSS o f r E E E E E E !! \n"
"Type sf_sv_sofree_help to see this info again\n"
"---------------------------------------------\n"
"---------------------------------------------\n"
"Use \"["HELP_BOLD"commandname"HELP_TEXT"] "HELP_BOLD"-h\""HELP_TEXT" to display information about a command\n"
"---------------------------------------------\n"
"Type sf_sv_sofree_help to see this again.\n"
);
}
/*
#define PRINT_LOW 0 // pickup messages
#define PRINT_MEDIUM 1 // death messages
#define PRINT_HIGH 2 // critical messages
#define PRINT_CHAT 3 // chat messages
*/
int sf_sv_print_cprintf(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
edict_t * ent = get_ent_from_player_slot(lua_tonumber(L,1));
orig_cprintf(ent,PRINT_HIGH,lua_tostring(L,2));
return 0;
}
int sf_sv_print_bprintf(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
orig_bprintf(PRINT_HIGH,lua_tostring(L,-1));
return 0;
}
int sf_sv_print_centerprint(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
edict_t * ent = get_ent_from_player_slot(lua_tonumber(L,1));
orig_centerprintf(ent,lua_tostring(L,2));
return 0;
}
int sf_sv_print_welcomeprint(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
edict_t * ent = get_ent_from_player_slot(lua_tonumber(L,1));
orig_welcomeprint(ent);
return 0;
}
// ent,x,y,speed,text
int sf_sv_print_cinprintf(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
int slot = lua_tonumber(L,1);
int x = lua_tonumber(L,2);
int y = lua_tonumber(L,3);
int speed = lua_tonumber(L,4);
char * text = lua_tostring(L,5);
edict_t * ent = get_ent_from_player_slot(slot);
orig_cinprintf(ent,x,y,speed,text);
return 0;
}
//sf_sv_console_write
extern "C" void simpletest(lua_State * L) {
orig_Com_Printf("There is %i args passed\n",lua_gettop(L));
// char ** file_list;
// int file_list_len;
// ListDirectoryContents("user-server\\sofplus\\addons\\lua",file_list,&file_list_len);
// orig_Com_Printf("There are %i entries\n",file_list_len);
// for ( int i=0; i < file_list_len;i++)
// {
// char * filepath = *(file_list+i);
// orig_Com_Printf("file path : %s\n",filepath);
// }
return 0;
}
/*
Inputs:1
SlotID
returns entHandle as int
*/
/*
I think it should be called create here.
args: 3
returns a vector table.
*/
int sf_sv_vector_create(lua_State * L) {
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
vec3_t v = {
lua_tonumber(L,1),
lua_tonumber(L,2),
lua_tonumber(L,3)
};
luaPushVectorAsTable(v);
return 1;
}
int sf_sv_vector_copy(lua_State * L) {
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
// int c = orig_Cmd_Argc() - 1;
// if ( !strcmp(orig_Cmd_Argv(1) ,"-h" ) ) {
// orig_Com_Printf(
// "Copy a vector\n"
// "----------------------------\n"
// "arg1 -> cvarname for output vector\n"
// "arg2 -> cvarname vector to copy\n"
// );
// return;
// }
// if ( c != 2 ) {
// orig_Com_Printf("sf_sv_vector_copy -h\n");
// return;
// }
lua_Number z = lua_tonumber(L,3);
lua_Number y = lua_tonumber(L,2);
lua_Number x = lua_tonumber(L,1);
lua_pushnumber(L,x);
lua_pushnumber(L,y);
lua_pushnumber(L,z);
return 3;
}
/*
return vector.
in vec1, vec2
*/
int sf_sv_vector_add(lua_State * L) {
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
vec3_t vecA,vecB,vecC;
luaReadTableAsVector(1,vecA);
luaReadTableAsVector(2,vecB);
VectorAdd(vecA,vecB,vecC);
luaPushVectorAsTable(vecC);
return 1;
}
int sf_sv_vector_subtract(lua_State * L) {
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
vec3_t vecA,vecB,vecC;
luaReadTableAsVector(1,vecA);
luaReadTableAsVector(2,vecB);
VectorSubtract(vecA,vecB,vecC);
luaPushVectorAsTable(vecC);
return 1;
}
int sf_sv_vector_scale(lua_State * L) {
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
vec3_t vecA,vecC;
luaReadTableAsVector(1,vecA);
float scale = lua_tonumber(L,2);
VectorScale(vecA,scale,vecC);
luaPushVectorAsTable(vecC);
return 1;
}
int sf_sv_vector_normalize(lua_State * L) {
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
vec3_t vecA;
luaReadTableAsVector(1,vecA);
VectorNormalize(vecA);
luaPushVectorAsTable(vecA);
return 1;
}
int sf_sv_vector_length(lua_State * L) {
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
vec3_t vecA;
luaReadTableAsVector(1,vecA);
float length = VectorLength(vecA);
lua_pushnumber(L,length);
return 1;
}
int sf_sv_vector_dotproduct(lua_State * L) {
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
vec3_t vecA,vecB;
luaReadTableAsVector(1,vecA);
luaReadTableAsVector(2,vecB);
float length = DotProduct(vecA,vecB);
lua_pushnumber(L,length);
return 1;
}
int sf_sv_vector_grow(lua_State * L) {
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
vec3_t vecA,vecB,vecC;
luaReadTableAsVector(1,vecA);
luaReadTableAsVector(3,vecB);
float multiplier = lua_tonumber(L,2);
VectorMA(vecA,multiplier,vecB,vecC);
luaPushVectorAsTable(vecC);
return 1;
}
enum FIELD_TYPES {
TYPE_FLOAT,
TYPE_INT,
TYPE_VECTOR,
TYPE_VECTOR_2D,
TYPE_STRING,
TYPE_POINTER,
TYPE_SHORT,
TYPE_BYTE,
TYPE_SHORTVECTOR,
TYPE_SHORTVECTOR_2D
};
struct A_FIELD {
FIELD_TYPES type;
char name[64];
unsigned int offset;
unsigned int relOffset; //for gclient pointer
char info[256];
};
// TODO: spawnflags
// scale ?
int sf_sv_ent_field_set(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
int i=0;
// int c = orig_Cmd_Argc() - 1;
// if ( !strcmp(orig_Cmd_Argv(1) ,"-h" ) ) {
// orig_Com_Printf(
// "Set a specific field for a specified entity\n"
// "----------------------------\n"
// "arg1 -> enthandle\n"
// "arg2 -> fieldname\n"
// "arg3 -> value\n"
// );
// for (i=0; i< numfields; i++ ) {
// orig_Com_Printf("%s ",all_fields[i].name);
// if ( !(i % 3 ) ) orig_Com_Printf("\n");
// }
// orig_Com_Printf("\n");
// orig_Com_Printf("Get help on specific field with sf_sv_ent_field_set fieldname\n");
// return;
// }
// if ( c == 1 ) {
// for ( i=0; i< numfields; i++ ) {
// if ( !strcmp(orig_Cmd_Argv(1),all_fields[i].name) ) {
// // match
// orig_Com_Printf("%s\n",all_fields[i].info);
// return;
// }
// }
// orig_Com_Printf("Not a known field\n");
// return;
// }
// if ( c != 3 ) {
// orig_Com_Printf("sf_sv_ent_field_set -h\n");
// orig_Com_Printf("sf_sv_ent_field_set fieldname -h\n");
// return;
// }
char * value;
// if ( lua_isstring(L,3) )
value = lua_tostring(L,3);
char * field = lua_tostring(L,2);
edict_t * ent = lua_tointeger(L,1);
void * real_field = NULL;
for ( i = 0; i < numfields;i++ ) {
if ( !strcmp(all_fields[i].name,field) ) {
if ( all_fields[i].relOffset > 0 ) {
real_field = *(unsigned int*)((unsigned int)ent + all_fields[i].relOffset);
real_field = (void*)((unsigned int)real_field + all_fields[i].offset);
} else {
real_field = (void*)((unsigned int)ent + all_fields[i].offset);
}
char newname[64];
cvar_t * one,*two,*three;
vec3_t in_vect;
switch( all_fields[i].type) {
case TYPE_FLOAT:
*(float*)real_field = atof(value);
break;
case TYPE_INT:
*(int*)real_field = atoi(value);
break;
case TYPE_SHORT:
*(short*)real_field = atoi(value);
break;
case TYPE_SHORTVECTOR:
readCvarAsVector(value,in_vect);
*(short*)(real_field)= in_vect[0];
*(short*)(real_field + 2) = in_vect[1];
*(short*)(real_field + 4)= in_vect[2];
break;
case TYPE_SHORTVECTOR_2D:
readCvarAsVector(value,in_vect);
*(short*)(real_field)= in_vect[0];
*(short*)(real_field + 2) = in_vect[1];
break;
case TYPE_STRING:
*(char**)real_field = orig_CopyString(value);
break;
case TYPE_POINTER:
*(unsigned int*)real_field = atoi(value);
break;
case TYPE_BYTE:
*(unsigned char*)real_field = atoi(value);
break;
case TYPE_VECTOR:
// the input value is a table
luaReadTableAsVector(3,real_field);
break;
case TYPE_VECTOR_2D:
readCvarAsVector(value,in_vect);
*(float*)(real_field)=in_vect[0];
*(float*)(real_field + 4)=in_vect[1];
break;
default:
break;
}
return;
}
}
orig_Com_Printf("Not a known field\n");
return 0;
}
int sf_sv_ent_field_get(lua_State * L)
{
#ifdef SOFREE_DEBUG
printf(__FUNCTION__);
printf("\n");
#endif
int i = 0;
// int c = orig_Cmd_Argc() - 1;
// if ( !strcmp(orig_Cmd_Argv(1) ,"-h" ) ) {
// orig_Com_Printf(
// "Set a specific field for a specified entity\n"
// "----------------------------\n"
// "arg1 -> outcvar\n"
// "arg2 -> enthandle\n"
// "arg3 -> fieldname\n"
// );
// for (i=0; i< numfields; i++ ) {
// orig_Com_Printf("%s ",all_fields[i].name);
// if ( !(i % 3 ) ) orig_Com_Printf("\n");
// }
// orig_Com_Printf("\n");
// orig_Com_Printf("Get help on specific field with sf_sv_ent_field_get fieldname -h\n");
// return;
// }
// if ( c == 1 ) {
// for (i=0; i< numfields; i++ ) {
// if ( !strcmp(orig_Cmd_Argv(1),all_fields[i].name) ) {
// // match
// orig_Com_Printf("%s\n",all_fields[i].info);
// break;
// }
// }
// orig_Com_Printf("Not a known field\n");
// return;
// }
// if ( c != 3 ) {
// orig_Com_Printf("sf_sv_ent_field_get -h\n");
// orig_Com_Printf("sf_sv_ent_field_get fieldname -h\n");
// return;
// }
char * field = lua_tostring(L,2);
edict_t * ent = (edict_t*)lua_tointeger(L,1);
char * outcvar = NULL;
void * real_field = NULL;
for ( i = 0; i < numfields;i++ ) {
if ( !strcmp(all_fields[i].name,field) ) {
if ( all_fields[i].relOffset > 0 ) {
real_field = *(unsigned int*)((unsigned int)ent + all_fields[i].relOffset);
real_field = (void*)((unsigned int)real_field + all_fields[i].offset);
} else {
real_field = (void*)((unsigned int)ent + all_fields[i].offset);
}
// cvar_t * out_cvar = orig_Cvar_Get(outcvar,"",0,NULL);
char newname[64];
cvar_t * one,*two,*three;
switch( all_fields[i].type) {
case TYPE_FLOAT:
// setCvarFloat(out_cvar,*(float*)real_field);
break;
case TYPE_INT:
// setCvarInt(out_cvar,*(int*)real_field);
break;
case TYPE_SHORT:
// setCvarInt(out_cvar,*(short*)real_field);
break;
case TYPE_SHORTVECTOR:
// sprintf(newname,"%s%s",outcvar,"_1");
// one = orig_Cvar_Get(newname,"",0,NULL);
// sprintf(newname,"%s%s",outcvar,"_2");
// two = orig_Cvar_Get(newname,"",0,NULL);
// sprintf(newname,"%s%s",outcvar,"_3");
// three = orig_Cvar_Get(newname,"",0,NULL);
// setCvarInt(one,*(short*)real_field);
// setCvarInt(two,*(short*)(real_field+2));
// setCvarInt(three,*(short*)(real_field+4));