Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 28.89 KB | None | 0 0
  1. #include "sofheader.h"
  2. #include "print.h"
  3.  
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. // StrStrI
  8. #include <Shlwapi.h>
  9.  
  10.  
  11. void * player_export = NULL;
  12.  
  13.  
  14. void createCommands(void)
  15. {
  16.     orig_Cmd_AddCommand("test",(void*)test);
  17.     orig_Cmd_AddCommand("sp_sv_sofree_help",(void*)Cmd_SofreeHelp);
  18.    
  19.     orig_Cmd_AddCommand("sp_sv_ent_spawn",(void*)Cmd_SpawnEntity_f);
  20.     orig_Cmd_AddCommand("sp_sv_ent_freeall",(void*)Cmd_RemoveCustomEnts_f);
  21.    
  22.     orig_Cmd_AddCommand("sp_sv_ent_moveall",(void*)Cmd_MoveCustomEnts_f);
  23.  
  24.  
  25.     //if sofplus
  26.     // orig_Cmd_RemoveCommand("sp_sv_client_swap");
  27.     // orig_Cmd_RemoveCommand("sp_sv_client_red");
  28.     // orig_Cmd_RemoveCommand("sp_sv_client_blue");
  29.  
  30.     // orig_Cmd_AddCommand("sp_sv_client_blue",(void*)Cmd_Blue_f);
  31.     // orig_Cmd_AddCommand("sp_sv_client_red",(void*)Cmd_Red_f);
  32.     // orig_Cmd_AddCommand("sp_sv_client_swap",(void*)Cmd_Swap_f);
  33.  
  34.  
  35.     orig_Cmd_AddCommand("sp_sv_sound_play",(void*)Cmd_PlaySound);
  36.     orig_Cmd_AddCommand("sp_sv_sound_register",(void*)Cmd_RegisterSound);
  37.     orig_Cmd_AddCommand("sp_sv_sound_remove",(void*)Cmd_RemoveSound);
  38.     orig_Cmd_AddCommand("sp_sv_sound_list",(void*)Cmd_ListRegisteredSounds);
  39.     orig_Cmd_AddCommand("sp_sv_sound_override",(void*)Cmd_OverrideSound);
  40.  
  41.     orig_Cmd_AddCommand("Cmd_TakePiss",(void*)Cmd_TakePiss);
  42.  
  43.     orig_Cmd_AddCommand("sp_sv_spackage_register",(void*)Cmd_SP_Register);
  44.     orig_Cmd_AddCommand("sp_sv_spackage_print_id",(void*)Cmd_SP_Print);
  45.     orig_Cmd_AddCommand("sp_sv_spackage_print_obit",(void*)Cmd_SP_Print_Obit);
  46.     orig_Cmd_AddCommand("sp_sv_spackage_print_string",(void*)Cmd_SP_SPrint);
  47.     orig_Cmd_AddCommand("Cmd_SP_GetStringText",(void*)Cmd_SP_GetStringText);
  48.  
  49.     orig_Cmd_AddCommand("sp_sv_script_load",(void*)Cmd_LoadScript);
  50.     orig_Cmd_AddCommand("sp_sv_script_run",(void*)Cmd_RunScript);
  51.     orig_Cmd_AddCommand("sp_sv_script_stop",(void*)Cmd_StopScript);
  52.  
  53.     orig_Cmd_AddCommand("sp_sv_player_move",(void*)Cmd_Go);
  54.     orig_Cmd_AddCommand("sp_sv_player_paint",(void*)Cmd_PaintPlayers);
  55.     orig_Cmd_AddCommand("sp_sv_player_weappaint",(void*)Cmd_PaintWeapons);
  56.     orig_Cmd_AddCommand("sp_sv_player_collision",(void*)Cmd_PlayerCollision);
  57.     orig_Cmd_AddCommand("sp_sv_player_pos",(void*)Cmd_PlayerPos);
  58.  
  59.     orig_Cmd_AddCommand("sp_sv_player_effect",(void*)Cmd_PlayerEffect);
  60. }
  61.  
  62.  
  63. void test(void)
  64. {
  65.     // orig_Com_Printf("File exists result : %i\n",orig_FS_FileExists(orig_Cmd_Argv(1)));
  66.  
  67.     //edict_t * ent = get_ent_from_player_slot(0);
  68.     // char config[3];
  69.     // config[0] = 'r';
  70.     // config[1] = 1;
  71.     // config[2] = 0;
  72.     // orig_PF_Configstring(CS_CTF_BLUE_STAT,config);
  73.  
  74.  
  75.     edict_t * ent1 = get_ent_from_player_slot(0);
  76.     edict_t * ent2 = get_ent_from_player_slot(1);
  77.     // entity_state_t *est = (entity_state_t*)ent;
  78.     // orig_Com_Printf("effects = %i\n",est->effects);
  79.  
  80.     // orig_Com_Printf("renderfx = %i\n",est->renderfx);
  81.     // orig_Com_Printf("event = %i\n",est->event);
  82.     // orig_Com_Printf("event2 = %i\n",est->event2);
  83.     // orig_Com_Printf("event3 = %i\n",est->event3);
  84.  
  85.     // orig_Com_Printf("data = %i\n",est->data);
  86.     // orig_Com_Printf("data2 = %i\n",est->data2);
  87.     // orig_Com_Printf("data3 = %i\n",est->data3);
  88.     // orig_Com_Printf("data3 = %i\n",est->data3);
  89.     // orig_Com_Printf("effectData = %i\n",est->effectData[0]);
  90.     // orig_Com_Printf("effectData1 = %i\n",est->effectData[1]);
  91.     // orig_Com_Printf("effectData2 = %i\n",est->effectData[2]);
  92.     // orig_Com_Printf("effectData3 = %i\n",est->effectData[3]);
  93.     // unsigned int gclient = *(unsigned int*)((unsigned int)ent+EDICT_GCLIENT);
  94.     // unsigned int inv = *(unsigned int*)((unsigned int)gclient+GCLIENT_INV);
  95.  
  96.     // clientinst = *(unsigned int*)((unsigned int)inv+(unsigned int)0x14C);
  97.     // GhoulSetTint(1.0,0.0,0.0,1.0);
  98.  
  99.     // orig_sendRestartPrediction(ent);
  100.  
  101.     // clientinst = *(unsigned int*)((unsigned int)inv+(unsigned int)0x14C);
  102.     // GhoulSetTint(1.0,0.0,0.0,1.0);
  103.  
  104.     // orig_PF_WriteByte(0xD);
  105.     // orig_PF_WriteString("password ""\x08""echo lol\n""\x00\x08""echo lol");
  106.     // orig_PF_Unicast(ent,1);
  107.  
  108.     orig_Com_Printf(P_PINK"one is : %08X\ntwo is : %08X\n",*(unsigned int*)(ent1+EDICT_SOLID),*(unsigned int*)(ent2+EDICT_SOLID));
  109. }
  110.  
  111.  
  112.  
  113. #define HELP_TEXT "\001"
  114. #define HELP_BOLD "\030"
  115. void Cmd_SofreeHelp(void)
  116. {
  117.     orig_Com_Printf(HELP_TEXT
  118.         "  SSSS          f f ff                    !! \n"
  119.         " S       o     f          E E E  E E E    !! \n"
  120.         "SS     o   o   f ff       E      E        !! \n"
  121.         "  SS  o     o  f    r r r E E E  E E E    !! \n"
  122.         "    S  o   o   f    r     E      E           \n"
  123.         "SSSS     o     f    r     E E E  E E E    !! \n"
  124.         "Type sp_sv_sofree_help to see this info again\n"
  125.         "---------------------------------------------\n"
  126.         "sp_sv_script_load\n"
  127.         "sp_sv_script_run\n"
  128.         "sp_sv_script_stop\n"
  129.         "\n"
  130.         "sp_sv_sound_list\n"
  131.         "sp_sv_sound_play\n"
  132.         "sp_sv_sound_register\n"
  133.         "sp_sv_sound_remove\n"
  134.         "sp_sv_sound_override\n"
  135.         "\n"
  136.         "sp_sv_player_move\n"
  137.         "sp_sv_player_paint\n"
  138.         "sp_sv_player_weappaint\n"
  139.         "sp_sv_player_collision\n"
  140.         "sp_sv_player_pos\n"
  141.         "---------------------------------------------\n"
  142.         "Use \"["HELP_BOLD"commandname"HELP_TEXT"] "HELP_BOLD"-h\""HELP_TEXT" to display information about a command\n"
  143.     );
  144. }
  145.  
  146. void Cmd_Swap_f(void)
  147. {
  148.     int argc = orig_Cmd_Argc();
  149.     if ( argc == 2 ) {
  150.         if ( !strcmp(orig_Cmd_Argv(1),"*")) {
  151.             for ( int i = 0; i < 16; i++ ) {
  152.                 unsigned int team = *(unsigned int*)(*(unsigned int*)GCLIENT_BASE + (i * SIZE_OF_GCLIENT) + GCLIENT_TEAM);
  153.                 if ( team == 2 ) {
  154.                     goBlue(i);
  155.                 } else if ( team == 1 ) {
  156.                     goRed(i);
  157.                 }
  158.             }
  159.         } else {
  160.             int slot = atoi(orig_Cmd_Argv(1));
  161.  
  162.             if ( slot >=0 && slot < 16 )
  163.             {
  164.                 unsigned int team = *(unsigned int*)(*(unsigned int*)GCLIENT_BASE + (slot * SIZE_OF_GCLIENT) + GCLIENT_TEAM);
  165.                 if ( team == 2 ) {
  166.                     goBlue(slot);
  167.                 } else if ( team == 1 ) {
  168.                     goRed(slot);
  169.                 }
  170.             }
  171.         }
  172.     }
  173. }
  174.  
  175. void Cmd_Blue_f(void)
  176. {
  177.    
  178.     int argc = orig_Cmd_Argc();
  179.     if ( argc == 2 ) {
  180.         if ( !strcmp(orig_Cmd_Argv(1),"*")) {
  181.             for ( int i = 0; i < 16; i++ ) {
  182.                 goBlue(i);
  183.             }
  184.         } else {
  185.             int slot = atoi(orig_Cmd_Argv(1));
  186.  
  187.             if ( slot >=0 && slot < 16 )
  188.             {
  189.                 goBlue(slot);
  190.             }
  191.         }
  192.        
  193.     }
  194.    
  195. }
  196.  
  197. void Cmd_Red_f(void)
  198. {
  199.    
  200.     int argc = orig_Cmd_Argc();
  201.     if ( argc == 2 ) {
  202.         if ( !strcmp(orig_Cmd_Argv(1),"*")) {
  203.             for ( int i = 0; i < 16; i++ ) {
  204.                 goRed(i);
  205.             }
  206.         } else {
  207.  
  208.             int slot = atoi(orig_Cmd_Argv(1));
  209.             if ( slot >=0 && slot < 16 )
  210.             {
  211.                 goRed(slot);
  212.             }
  213.         }
  214.     }
  215.    
  216.    
  217. }
  218.  
  219.  
  220. void goRed(int who) {
  221.     // orig_Com_Printf("yo momma's team is %i\n",*(unsigned int*)(*(unsigned int*)0x5015D6C4 + (slot * 0x600) + 0x324));
  222.     // *(unsigned int*)(*(unsigned int*)0x5015D6C4 + (slot * 0x600) + 0x324) = 2;
  223.     void * client_t = (void*)((*(unsigned int*)0x20396EEC) + ( who * 0xd2ac));
  224.     char * cl_userinfo = (char*)((unsigned int)client_t + 0x4);
  225.     orig_Info_SetValueForKey(cl_userinfo,"team_red_blue","1");
  226.     orig_SV_UserinfoChanged(client_t);
  227.     my_SV_UserinfoChanged(client_t);
  228. }
  229.  
  230. void goBlue(int who) {
  231.     void * client_t = (void*)((*(unsigned int*)0x20396EEC) + ( who * 0xd2ac));
  232.     char * cl_userinfo = (char*)((unsigned int)client_t + 0x4);
  233.     orig_Info_SetValueForKey(cl_userinfo,"team_red_blue","0");
  234.     orig_SV_UserinfoChanged(client_t);
  235.     my_SV_UserinfoChanged(client_t);
  236. }
  237.  
  238.  
  239. void * mem_edictpointers = NULL;
  240. int edict_count = 0;
  241. //mygimme [classname] [x] [y] [z] [pitch] [yaw]
  242. void Cmd_SpawnEntity_f(void)
  243. {
  244.     edict_count++;
  245.     orig_Com_Printf("added new eddict, count is now %i\n",edict_count);
  246.     mem_edictpointers = realloc(mem_edictpointers,edict_count*4);
  247.  
  248.     orig_Com_Printf("you want to spawn : %s\n",orig_Cmd_Argv(1));
  249.  
  250.     unsigned int edict_addr = (unsigned int)orig_G_Spawn();
  251.     *(unsigned int*)((unsigned int)mem_edictpointers+(edict_count-1)*4) = edict_addr;
  252.  
  253.     //classname
  254.     *(char**)((int)edict_addr + 0x1B4) = orig_ED_NewString(orig_Cmd_Argv(1));
  255.  
  256.     //origin
  257.     *(float*)(edict_addr + 0x4) = atof(orig_Cmd_Argv(2));
  258.     *(float*)(edict_addr + 0x8) = atof(orig_Cmd_Argv(3));
  259.     *(float*)(edict_addr + 0xC) = atof(orig_Cmd_Argv(4));
  260.  
  261.     //rotation
  262.     *(float*)(edict_addr + 0x10) = atof(orig_Cmd_Argv(5));
  263.     *(float*)(edict_addr + 0x14) = atof(orig_Cmd_Argv(6));
  264.  
  265.     orig_ED_CallSpawn((void*)edict_addr);
  266. }
  267.  
  268. void Cmd_RemoveCustomEnts_f(void)
  269. {
  270.    
  271.     /*orig_G_FreeEdict((void*)*(unsigned int*)mem_edictpointers);
  272.     edict_count = 0;
  273.     free(mem_edictpointers);*/
  274.     for ( int i=0 ; i < edict_count; i ++)
  275.     {
  276.         orig_Com_Printf("Removed %08X edict_t*\n",*(unsigned int*)((unsigned int)mem_edictpointers+i*4));
  277.         orig_G_FreeEdict((void*)*(unsigned int*)((unsigned int)mem_edictpointers+i*4));
  278.     }  
  279.     edict_count = 0;
  280.     free(mem_edictpointers);
  281.     mem_edictpointers = NULL;
  282. }
  283.  
  284. void Cmd_MoveCustomEnts_f(void)
  285. {
  286.  
  287.     for ( int i=0 ; i < edict_count; i ++)
  288.     {
  289.        
  290.         unsigned int edict = *(unsigned int*)((unsigned int)mem_edictpointers+i*4);
  291.         *(float*)(edict + 0x4) += 50;
  292.     }  
  293. }
  294.  
  295.  
  296.  
  297. void Cmd_ListRegisteredSounds(void)
  298. {
  299.     if ( !strcmp(orig_Cmd_Argv(1) ,"-h" ) ) {
  300.         orig_Com_Printf(
  301.             "Lists all registered sounds\n"
  302.             "See _sp_sv_sound_info_slots for how many sounds slots you have free\n"
  303.             "----------------------------\n"
  304.             "takes no arguments\n"
  305.         );
  306.         return;
  307.     }
  308.     if ( orig_Cmd_Argc() > 2 ) {
  309.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  310.         return;
  311.     }
  312.     int i;
  313.     for (i=0 ; i<MAX_SOUNDS ; i++) {
  314.         if ( *(unsigned char*)(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH) )
  315.         {
  316.             char line[65];
  317.             // sprintf(line,"%s",(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH));
  318.             strcpy(line,SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH);
  319.             strcat(line,"\n");
  320.             if ( orig_Cmd_Argc() ==  2 ) {
  321.                 if ( StrStrI(line,orig_Cmd_Argv(1)) ) {
  322.                     orig_Com_Printf(line);
  323.                 }
  324.             } else {
  325.                 orig_Com_Printf(line);
  326.             }
  327.            
  328.         }
  329.     }
  330. }
  331.  
  332.  
  333. void Cmd_CalcFreeSoundSlots(void)
  334. {
  335.     int freeslots = 0;
  336.     int i;
  337.     for (i=0 ; i<MAX_SOUNDS ; i++) {
  338.         if ( *(unsigned char*)(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH) == '\0' )
  339.         {
  340.             freeslots++;
  341.         }
  342.     }
  343.     char num[8];
  344.     orig_Cvar_Set("_sp_sv_sound_info_slots",itoa(freeslots,num,10));
  345. }
  346.  
  347. //1: name of sound
  348. void Cmd_RegisterSound(void)
  349. {
  350.     char * one = orig_Cmd_Argv(1);
  351.     if ( !strcmp(one ,"-h" ) ) {
  352.         orig_Com_Printf(
  353.             "Registers a new soundfile\n"
  354.             "Sound files live in your %%User%%/sound directory\n"
  355.             "See _sp_sv_sound_info_slots for how many sounds slots you have free\n"
  356.             "----------------------------\n"
  357.             "arg1 -> name of soundfile eg. misc/talk.wav\n"
  358.         );
  359.         return;
  360.     }
  361.     if ( orig_Cmd_Argc() != 2 ) {
  362.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  363.         return;
  364.     }
  365.  
  366.     int i;
  367.     // sv_soundindex(orig_Cmd_Argv(1));
  368.  
  369.     char ver1[128];
  370.     strcpy(ver1,one);
  371.     replacechar(ver1,'\\','/');
  372.     for (i=1 ; i<MAX_SOUNDS && *(unsigned char*)(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH) ; i++)
  373.         if (!strcmp(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH, ver1))
  374.             return;
  375.     // dont allow overflow condition
  376.     if (i < MAX_SOUNDS) {
  377.         orig_SV_FindIndex(ver1, CS_SOUNDS, MAX_SOUNDS, 1,"sound");
  378.     }
  379.     Cmd_CalcFreeSoundSlots();
  380. }
  381.  
  382. void Cmd_RemoveSound(void)
  383. {
  384.     char * one = orig_Cmd_Argv(1);
  385.     if ( !strcmp(one,"-h" ) ) {
  386.         orig_Com_Printf(
  387.             "Unregisters a soundfile that is already registered\n"
  388.             "Sound files live in your %%User%%/sound directory\n"
  389.             "See _sp_sv_sound_info_slots for how many sounds slots you have free\n"
  390.             "----------------------------\n"
  391.            
  392.             "arg1 -> name of soundfile eg. misc/talk.wav\n"
  393.         );
  394.         return;
  395.     }
  396.     if ( orig_Cmd_Argc() != 2 ) {
  397.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  398.         return;
  399.     }
  400.     char ver1[128];
  401.     strcpy(ver1,one);
  402.     replacechar(ver1,'\\','/');
  403.     orig_SV_RemoveSound(ver1);
  404.     Cmd_CalcFreeSoundSlots();
  405. }
  406.  
  407. //(edict_t *entity, int channel, int sound_num, float volume, float attenuation, float timeofs)
  408. //1: name of sound
  409. //2:  
  410. void Cmd_PlaySound(void)
  411. {
  412.     char * one = orig_Cmd_Argv(1);
  413.     if ( !strcmp(one,"-h" ) ) {
  414.         orig_Com_Printf(
  415.             "Plays a soundfile that has already been registered\n"
  416.             "----------------------------\n"
  417.             "arg1 -> name of soundfile eg. misc/talk.wav\n"
  418.             "arg2 -> player slot to attach the sound to - must be specified\n"
  419.         );
  420.         return;
  421.     }
  422.     if ( orig_Cmd_Argc() != 3 ) {
  423.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  424.         return;
  425.     }
  426.     edict_t * ent = get_ent_from_player_slot(atoi(orig_Cmd_Argv(2)));
  427.     if (!ent) {
  428.         PrintOut(PRINT_BAD,0,"Invalid ent.\n");
  429.         return;
  430.     }
  431.     char ver1[128];
  432.     strcpy(ver1,one);
  433.     replacechar(ver1,'\\','/');
  434.  
  435.     // create bool is false
  436.     int index = orig_SV_FindIndex(ver1, CS_SOUNDS, MAX_SOUNDS, 0,"sound");
  437.     // only if its in our configstring
  438.     if (index)
  439.         orig_PF_StartSound(ent,CHAN_AUTO, index ,0.6,ATTN_NORM,0);
  440.     else
  441.         PrintOut(PRINT_BAD,0,"Sound is not registered.\n");
  442.    
  443. }
  444.  
  445. unsigned int num_sound_overrides = 0;
  446. sound_overrides_t * sound_overrides = NULL;
  447.  
  448. // sp_sv_sound_override "/enemy/dth/*" ""
  449. // sp_sv_sound_override "/impact/gore/*" ""
  450. // sp_sv_sound_override "/impact/player/*" ""
  451. void Cmd_OverrideSound(void)
  452. {
  453.     char * one = orig_Cmd_Argv(1);
  454.     if ( !strcmp(one,"-h" ) ) {
  455.         orig_Com_Printf(
  456.             "Plays a specific sound in place of a previous one\n"
  457.             "----------------------------\n"
  458.             "arg1 -> the known original sound - can end with a * to target many sounds\n"
  459.             "arg2 -> your new sound - can be empty then will play no sound\n"
  460.         );
  461.         return;
  462.     }
  463.     if ( orig_Cmd_Argc() != 3 ) {
  464.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  465.         return;
  466.     }
  467.  
  468.     sound_overrides_t * p = sound_overrides;
  469.     if ( num_sound_overrides > 0 ) {
  470.         while ( p->next != NULL )
  471.         {
  472.             p = sound_overrides->next;
  473.         }
  474.         p->next = malloc(sizeof(sound_overrides_s));
  475.         p = p->next;
  476.     } else
  477.     {
  478.         sound_overrides = malloc(sizeof(sound_overrides_s));
  479.         p = sound_overrides;
  480.     }
  481.     num_sound_overrides++;
  482.     p->next = NULL;
  483.     strcpy(p->orig_sound,orig_Cmd_Argv(1));
  484.     strcpy(p->new_sound,orig_Cmd_Argv(2));
  485. }
  486.  
  487.  
  488. void Cmd_TakePiss(void)
  489. {  
  490.     // orig_TakePiss(*(edict_t**)(cl + CLIENT_ENT))
  491.  
  492. }
  493.  
  494.  
  495. // Register a string package
  496. void Cmd_SP_Register(void)
  497. {
  498.  
  499.     orig_SP_Register(orig_Cmd_Argv(1));
  500. }
  501. //typedef void (*SP_Print)(edict_t *ent, unsigned short ID, ...);
  502. // who,num
  503. void Cmd_SP_Print(void)
  504. {
  505.     unsigned int ed_base = *(unsigned int*)EDICT_BASE;
  506.     orig_SP_Print(ed_base + (atoi(orig_Cmd_Argv(1))+1)*SIZE_OF_EDICT,atoi(orig_Cmd_Argv(2)));
  507. }
  508. // typedef void (*SP_Print_Obit)(edict_t *ent, unsigned short ID, ...);
  509. // who,num
  510. void Cmd_SP_Print_Obit(void)
  511. {
  512.     unsigned int ed_base = *(unsigned int*)EDICT_BASE;
  513.     orig_SP_Print(ed_base + (atoi(orig_Cmd_Argv(1))+1)*SIZE_OF_EDICT,atoi(orig_Cmd_Argv(2)));
  514. }
  515. // typedef int (*SP_SPrint)(char *buffer, int buffer_size, unsigned short ID, ...);
  516.  
  517. // who,msg,len
  518. void Cmd_SP_SPrint(void)
  519. {
  520.     orig_SP_Print(orig_Cmd_Argv(2),atoi(orig_Cmd_Argv(3)),atoi(orig_Cmd_Argv(1)));
  521. }
  522. // typedef const char   *(*SP_GetStringText)(unsigned short ID);
  523. void Cmd_SP_GetStringText(void)
  524. {
  525.     char out[2048] = "echo ";
  526.     strcat(out,orig_SP_GetStringText(atoi(orig_Cmd_Argv(1))));
  527.     orig_Cbuf_AddText(out);
  528. }
  529.  
  530.  
  531. struct d_script_s
  532. {
  533.     char name[64];
  534.     // CScript pointer self
  535.     void * handle;
  536. };
  537.  
  538.  
  539. struct d_script_s * dende_scripts[MAX_D_SCRIPTS] = {NULL};
  540. int d_script_pointer = 0;
  541.  
  542.  
  543. // they must have moved script_use into the class...
  544. // void script_use(edict_t *ent, edict_t *other, edict_t *activator)
  545. void Cmd_RunScript(void)
  546. {
  547.    
  548.     if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
  549.         orig_Com_Printf(
  550.             "Executes a DesignerScript file (.os), located in your %%User%%/ds/ directory\n"
  551.             "DesignerScripts are .ds files compiled into .os files using sofds.exe\n"
  552.             "eg. \"sp_sv_script_run elevator\" -notice no file extension\n"
  553.             "----------------------------\n"
  554.             "arg1 -> name of script\n"
  555.         );
  556.         return;
  557.     }
  558.     if ( orig_Cmd_Argc() != 2 ) {
  559.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  560.         return;
  561.     }
  562.     // void * cl = (void*)((*(unsigned int*)CLIENT_BASE) + ( (unsigned int)(atoi(orig_Cmd_Argv(1))) * SIZE_OF_CLIENT));
  563.     // edict_t * entbleh = *(edict_t**)(cl + CLIENT_ENT);
  564.  
  565.     char scriptname[64];
  566.     sprintf(scriptname,"ds/%s.os",orig_Cmd_Argv(1));
  567.     if ( !orig_FS_FileExists(scriptname) ) {
  568.         PrintOut(PRINT_BAD,false,"You are trying run a script that is unlikely to be loaded.\n");
  569.         return;
  570.     }
  571.  
  572.     unsigned int ed_base = *(unsigned int*)EDICT_BASE;
  573.     //search for scriptname
  574.     struct d_script_s * ds = NULL;
  575.     for ( int i = 0 ; i < d_script_pointer; i++ ) {
  576.         struct d_script_s * ds = dende_scripts[i];
  577.         if ( !strcmp(scriptname,ds->name) ) {
  578.             unsigned int * cond = (unsigned int)(ds->handle + CSCRIPT_SCRIPTCONDITION);
  579.             if ( *cond != COND_COMPLETED && *cond != COND_READY )
  580.             {
  581.                 PrintOut(PRINT_GOOD,false,"Seems like script %s is already running\n",scriptname);
  582.                 return;
  583.             }
  584.  
  585.  
  586.             // To allow many scripts to use one entity?
  587.             //Link entity to script before run ?
  588.             *(unsigned int*)(ed_base+EDICT_SCRIPT) = ds->handle;
  589.  
  590.             PrintOut(PRINT_GOOD,false,"Running script %s\n",scriptname);
  591.             *(unsigned int*)(ds->handle + CSCRIPT_SCRIPTCONDITION) = COND_READY;
  592.             orig_script_use(ed_base,ed_base,ed_base);
  593.             return;
  594.         }
  595.     }
  596.  
  597.    
  598.  
  599. /*
  600.     asm volatile(   "push %1;"//push scriptname
  601.                     "push %2;"//push owner
  602.                     "push %3;"//push owner
  603.                     "movl %0,%%ecx;"//new_mem->ecx
  604.                     "call *%4;"//call orig_script_use
  605.                     ::"m"(myscript),"m"(entbleh),"m"(entbleh),"m"(entbleh),"m"(orig_script_use):"%ecx");
  606.  
  607. */
  608. }
  609.  
  610.  
  611.  
  612.  
  613. void Cmd_LoadScript(void)
  614. {  
  615.     if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
  616.         orig_Com_Printf(
  617.             "Loads a DesignerScript file (.os), located in your %%User%%/ds/ directory\n"
  618.             "DesignerScripts are .ds files compiled into .os files using sofds.exe\n"
  619.             "eg. \"sp_sv_script_load elevator\" -notice no file extension\n"
  620.             "----------------------------\n"
  621.             "arg1 -> name of script\n"
  622.         );
  623.         return;
  624.     }
  625.     if ( orig_Cmd_Argc() != 2 ) {
  626.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  627.         return;
  628.     }
  629.     void * newscript = orig_cplusplus_new(0x4b4);
  630.  
  631.     char scriptname[64];
  632.     sprintf(scriptname,"ds/%s.os",orig_Cmd_Argv(1));
  633.  
  634.     if ( !orig_FS_FileExists(scriptname) ) {
  635.         PrintOut(PRINT_BAD,false,"You are trying to load a non-existant file.\n");
  636.         return;
  637.     }
  638.  
  639.     struct d_script_s * ds = NULL;
  640.    
  641.     for ( int i = 0 ; i < d_script_pointer; i++ ) {
  642.         struct d_script_s * ds = dende_scripts[i];
  643.         if ( !strcmp(scriptname,ds->name) ) {
  644.             PrintOut(PRINT_BAD,false,"Script %s is already loaded\n",scriptname);
  645.             return;
  646.         }
  647.     }  
  648.  
  649.  
  650.     PrintOut(PRINT_GOOD,false,"Loading script %s\n",scriptname);
  651.  
  652.     // create the d_script
  653.     ds = dende_scripts[d_script_pointer] = malloc(sizeof(struct d_script_s));
  654.     d_script_pointer++;
  655.     strcpy(ds->name,scriptname);
  656.     ds->handle = newscript;
  657.  
  658.  
  659.     //st.script = scriptname
  660.     // *(unsigned int*)0x5015CC30 = &(scriptname[0]);
  661.     //orig_SP_script_runner(owner);
  662.    
  663.     unsigned int ed_base = *(unsigned int*)EDICT_BASE;
  664.     unsigned int worldspawn = ed_base;
  665.     unsigned int p_to_string = &(scriptname[0]);
  666.     asm volatile(   "push %1;"//push scriptname
  667.                     "push %2;"//push owner
  668.                     "movl %0,%%ecx;"//new_mem->ecx
  669.                     "call *%3;"//call orig_CScript
  670.                     ::"m"(newscript),"m"(worldspawn),"m"(p_to_string),"m"(orig_CScript):"%ecx");
  671.  
  672.     // ent->script = newscript
  673.     *(unsigned int*)(ed_base+EDICT_SCRIPT) = newscript;
  674.  
  675.     // append to list of scripts
  676.  
  677.     void * newListItem = orig_cplusplus_new(0xC);
  678.  
  679.     unsigned int esi = *(unsigned int*)0x5015C504;
  680.     *(unsigned int*)newListItem = esi;
  681.  
  682.     unsigned int edi = *(unsigned int*)(esi+4 );
  683.  
  684.     *(unsigned int*)(newListItem+4) = edi;
  685.  
  686.     *(unsigned int*)(esi+4) = newListItem;
  687.  
  688.     *(unsigned int*)( *(unsigned int*)(newListItem+4) ) = newListItem;
  689.  
  690.     *(unsigned int*)(newListItem+8) = *(unsigned int*)(ed_base+EDICT_SCRIPT);
  691.  
  692.     *(unsigned int*)(0x5015C508) = *(unsigned int*)(0x5015C508) + 1;
  693.  
  694. }
  695.  
  696.  
  697.  
  698. void Cmd_StopScript(void)
  699. {
  700.     if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
  701.         orig_Com_Printf(
  702.             "Stops excution of a DesignerScript file (.os), located in your %%User%%/ds/ directory\n"
  703.             "DesignerScripts are .ds files compiled into .os files using sofds.exe\n"
  704.             "eg. \"sp_sv_script_stop elevator\" -notice no file extension\n"
  705.             "----------------------------\n"
  706.             "arg1 -> name of script\n"
  707.         );
  708.         return;
  709.     }
  710.     if ( orig_Cmd_Argc() != 2 ) {
  711.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  712.         return;
  713.     }
  714.     char scriptname[64];
  715.     sprintf(scriptname,"ds/%s.os",orig_Cmd_Argv(1));
  716.     if ( !orig_FS_FileExists(scriptname) ) {
  717.         PrintOut(PRINT_BAD,false,"You are trying stop a script that is unlikely to be loaded.\n");
  718.         return;
  719.     }
  720.  
  721.     struct d_script_s * ds = NULL;
  722.     for ( int i = 0 ; i < d_script_pointer; i++ ) {
  723.         struct d_script_s * ds = dende_scripts[i];
  724.         if ( !strcmp(scriptname,ds->name) ) {
  725.             PrintOut(PRINT_GOOD,false,"Stopping script %s\n",scriptname);
  726.             *(unsigned int*)(ds->handle + CSCRIPT_SCRIPTCONDITION) = COND_COMPLETED;
  727.             return;
  728.         }
  729.     }
  730.  
  731. }
  732.  
  733.  
  734. void Cmd_Go(void)
  735. {
  736.     if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
  737.         orig_Com_Printf(
  738.             "Teleports a player to specified x,y,z co-ordinate\n"
  739.             "----------------------------\n"
  740.             "arg1 -> valid slot id\n"
  741.             "arg2 -> x position represent a number like 10.555\n"
  742.             "arg3 -> y position represent a number like 10.555\n"
  743.             "arg4 -> z position represent a number like 10.555\n"
  744.         );
  745.         return;
  746.     }
  747.     if ( orig_Cmd_Argc() != 5 ) {
  748.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  749.         return;
  750.     }
  751.     edict_t* ent = get_ent_from_player_slot(atoi(orig_Cmd_Argv(1)));
  752.     if ( !ent ) {
  753.         PrintOut(PRINT_BAD,false,"Invalid Ent\n");
  754.         return;
  755.     }
  756.    
  757.    
  758.     float x = atof(orig_Cmd_Argv(2));
  759.     float y = atof(orig_Cmd_Argv(3));
  760.     float z = atof(orig_Cmd_Argv(4));
  761.  
  762.     vec3_t v = {x,y,z};
  763.  
  764.     VectorCopy(v, ent+EDICT_S_ORIGIN );
  765. }
  766.  
  767.  
  768.  
  769. float player_tint[32][4];
  770. float player_wep_tint[32][4];
  771. void Cmd_PaintPlayers(void)
  772. {
  773.     if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
  774.         orig_Com_Printf(
  775.             "Applies a coloured tint on a specific player\n"
  776.             "----------------------------\n"
  777.             "arg1 -> valid slot id\n"
  778.             "arg2 -> red component between 0.0 and 1.0\n"
  779.             "arg3 -> green component between 0.0 and 1.0\n"
  780.             "arg4 -> blue component between 0.0 and 1.0\n"
  781.             "arg5 -> opacity component between 0.0 and 1.0 , 1.0 being fully visible\n"
  782.         );
  783.         return;
  784.     }
  785.     if ( orig_Cmd_Argc() != 6 ) {
  786.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  787.         return;
  788.     }
  789.     unsigned int slot = atoi(orig_Cmd_Argv(1));
  790.     edict_t* ent = get_ent_from_player_slot(slot);
  791.     if ( !ent ) {
  792.         PrintOut(PRINT_BAD,false,"Invalid Ent\n");
  793.         return;
  794.     }
  795.     // PrintOut(PRINT_GOOD,false,"argc is : %i\n",orig_Cmd_Argc());
  796.  
  797.     float r = atof(orig_Cmd_Argv(2));
  798.     float g = atof(orig_Cmd_Argv(3));
  799.     float b = atof(orig_Cmd_Argv(4));
  800.     float a = atof(orig_Cmd_Argv(5));
  801.     player_tint[slot][0] = r;
  802.     player_tint[slot][1] = g;
  803.     player_tint[slot][2] = b;
  804.     player_tint[slot][3] = a;
  805.     clientinst = *(unsigned int*)(*(unsigned int*)(ent + EDICT_GCLIENT) + GCLIENT_S_BODY);
  806.     if ( clientinst ) {
  807.         GhoulSetTintOnAll(player_tint[slot][0],player_tint[slot][1],player_tint[slot][2],player_tint[slot][3]);
  808.     }
  809. }
  810. unsigned int was_ghosted[32];
  811. void Cmd_PaintWeapons(void)
  812. {
  813.     if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
  814.         orig_Com_Printf(
  815.             "Applies a coloured tint on a specific player's weapon\n"
  816.             "----------------------------\n"
  817.             "arg1 -> valid slot id\n"
  818.             "arg2 -> red component between 0.0 and 1.0\n"
  819.             "arg3 -> green component between 0.0 and 1.0\n"
  820.             "arg4 -> blue component between 0.0 and 1.0\n"
  821.             "arg5 -> opacity component between 0.0 and 1.0 , 1.0 being fully visible\n"
  822.         );
  823.         return;
  824.     }
  825.     if ( orig_Cmd_Argc() != 6 ) {
  826.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  827.         return;
  828.     }
  829.     unsigned int slot = atoi(orig_Cmd_Argv(1));
  830.     edict_t* ent = get_ent_from_player_slot(slot);
  831.     if ( !ent ) {
  832.         PrintOut(PRINT_BAD,false,"Invalid Ent\n");
  833.         return;
  834.     }
  835.     // PrintOut(PRINT_GOOD,false,"argc is : %i\n",orig_Cmd_Argc());
  836.  
  837.     float r = atof(orig_Cmd_Argv(2));
  838.     float g = atof(orig_Cmd_Argv(3));
  839.     float b = atof(orig_Cmd_Argv(4));
  840.     float a = atof(orig_Cmd_Argv(5));
  841.     player_wep_tint[slot][0] = r;
  842.     player_wep_tint[slot][1] = g;
  843.     player_wep_tint[slot][2] = b;
  844.     player_wep_tint[slot][3] = a;
  845.  
  846.     void (*refreshWeapon)(void * inv) = 0x400052A0;
  847.  
  848.     // orig_Com_Printf("lol : %08X\n", player_export);
  849.  
  850.     int wp = 0;
  851.     // weapons_t pistol = SFW_PISTOL1
  852.     unsigned int gclient = *(unsigned int*)((unsigned int)ent+EDICT_GCLIENT);
  853.     if ( gclient ) {
  854.         unsigned int inv = *(unsigned int*)((unsigned int)gclient+GCLIENT_INV);
  855.         if (inv) {
  856.            
  857.        
  858.             sharedEdict_t sh;
  859.  
  860.             sh.inv=(void*)inv;
  861.             sh.edict=ent;
  862.             void ( __thiscall *SetOwner)(void * self,edict_t *own) = *(unsigned int*)((unsigned int)(*(unsigned int*)inv)+(unsigned int)0xF4);
  863.            
  864.         //      // orig_Com_Printf("TAKE OUT YOUR KNIFE LIKE A MAN!\n");
  865.            
  866.            
  867.  
  868.             //(void*)orig_getViewModel(sh.inv);
  869.             // orig_getViewModel = (getViewModel_type)();
  870.             // orig_Com_Printf("lol %08X\n",orig_getViewModel);
  871.             // orig_Com_Printf("lol %08X\n",*(unsigned int*)self);
  872.             // clientinst = *(unsigned int*)((unsigned int)inv+(unsigned int)0x14C);
  873.             // GhoulSetTint(1.0,0.0,0.0,1.0);
  874.  
  875.            
  876.             //RebuildPredictedClientInv
  877.            
  878.  
  879.             // void (*refreshWeapon)(void * inv) =*(unsigned int*)(0x5015D9B8 + 0x2C);
  880.             SetOwner(inv,&sh);
  881.             // requires owner
  882.             // refreshWeapon(inv);
  883.  
  884.             orig_getCurWeapon = *(unsigned int*)((unsigned int)(*(unsigned int*)inv)+(unsigned int)0x5C);
  885.             int curWeap = orig_getCurWeapon(inv);
  886.             // orig_selectWeapon(inv,SFW_KNIFE);
  887.             orig_selectWeapon(inv,curWeap);
  888.  
  889.             // orig_takeOutWeapon(inv,curWeap);
  890.  
  891.  
  892.             clientinst = *(unsigned int*)((unsigned int)inv+(unsigned int)0x14C);
  893.             if ( *(unsigned int*)(gclient + GCLIENT_GHOSTED) )
  894.                 GhoulSetTint(player_wep_tint[slot][0],player_wep_tint[slot][1],player_wep_tint[slot][2],0.4f);
  895.             else
  896.                 GhoulSetTint(player_wep_tint[slot][0],player_wep_tint[slot][1],player_wep_tint[slot][2],player_wep_tint[slot][3]);
  897.  
  898.             orig_sendRestartPrediction(ent);
  899.             // orig_ReliableWriteByteToClient(0x1E,slot);
  900.             // orig_NetWrite = *(unsigned int*)((unsigned int)(*(unsigned int*)inv)+(unsigned int)0x138);
  901.             // orig_NetWrite(inv,slot);
  902.  
  903.             // void * dmstandard = 0x5015C424;
  904.             // void (__thiscall *clientRespawn)(void * self,edict_t * who) = 0x50074DA0;
  905.             // clientRespawn(dmstandard,ent);
  906.            
  907.  
  908.             // inven_c *W_NewInv(void)
  909.             // {
  910.             //  return(new inven_c);
  911.             // }
  912.  
  913.             // void W_KillInv(inven_c *inven)
  914.             // {
  915.             //  delete(inven);
  916.             // }
  917.  
  918.             // W_KillInv(ent);
  919.  
  920.             // ent.client->inv=pe->NewInv();
  921.         }
  922.     }
  923.    
  924. }
  925.  
  926. bool player_collision[32];
  927. void Cmd_PlayerCollision(void)
  928. {
  929.     if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
  930.         orig_Com_Printf(
  931.             "Makes it so this player can be passed through by all other players\n"
  932.             "----------------------------\n"
  933.             "arg1 -> valid slot id\n"
  934.             "arg2 -> 1 or 0 ... representing collision on or off\n"
  935.         );
  936.         return;
  937.     }
  938.     if ( orig_Cmd_Argc() != 3 ) {
  939.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  940.         return;
  941.     }
  942.     unsigned int slot = atoi(orig_Cmd_Argv(1));
  943.     edict_t* ent = get_ent_from_player_slot(slot);
  944.     if ( !ent ) {
  945.         PrintOut(PRINT_BAD,false,"Invalid Ent\n");
  946.         return;
  947.     }
  948.     int mode = atoi(orig_Cmd_Argv(2));
  949.     if ( mode != 0 and mode != 1 )
  950.     {
  951.         PrintOut(PRINT_BAD,false,"Collision must be 1 or 0\n");
  952.     }
  953.  
  954.     if ( mode == 1 ) {
  955.         *(unsigned int*)(ent+EDICT_SOLID) = SOLID_BBOX;
  956.         player_collision[slot] = true;
  957.     } else {
  958.         *(unsigned int*)(ent+EDICT_SOLID) = SOLID_TRIGGER;
  959.         player_collision[slot] = false;
  960.     }
  961.  
  962. }
  963.  
  964.  
  965. void Cmd_PlayerPos(void)
  966. {
  967.     if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
  968.         orig_Com_Printf(
  969.             "Gets the co-ordinates of the player and stores them in the 3 cvars you pass\n"
  970.             "----------------------------\n"
  971.             "arg1 -> valid slot id\n"
  972.             "arg2 -> cvarname you want the x position to be stored in\n"
  973.             "arg3 -> cvarname you want the y position to be stored in\n"
  974.             "arg4 -> cvarname you want the z position to be stored in\n"
  975.         );
  976.         return;
  977.     }
  978.     if ( orig_Cmd_Argc() != 5 ) {
  979.         PrintOut(PRINT_BAD,false,"[commandname] -h\n");
  980.         return;
  981.     }
  982.     unsigned int slot = atoi(orig_Cmd_Argv(1));
  983.     edict_t* ent = get_ent_from_player_slot(slot);
  984.     if ( !ent ) {
  985.         PrintOut(PRINT_BAD,false,"Invalid Ent\n");
  986.         return;
  987.     }
  988.  
  989.    
  990.  
  991.     cvar_t * cvar_x = findCvar(orig_Cmd_Argv(2));
  992.     if ( !cvar_x ) {
  993.         PrintOut(PRINT_BAD,false,"Cvar %s does not exist\n",orig_Cmd_Argv(2));
  994.         return;
  995.     }
  996.     cvar_t * cvar_y = findCvar(orig_Cmd_Argv(3));
  997.     if ( !cvar_x ) {
  998.         PrintOut(PRINT_BAD,false,"Cvar %s does not exist\n",orig_Cmd_Argv(3));
  999.         return;
  1000.     }
  1001.     cvar_t * cvar_z = findCvar(orig_Cmd_Argv(4));
  1002.     if ( !cvar_x ) {
  1003.         PrintOut(PRINT_BAD,false,"Cvar %s does not exist\n",orig_Cmd_Argv(4));
  1004.         return;
  1005.     }
  1006.  
  1007.     cvar_x->modified = true;
  1008.     cvar_y->modified = true;
  1009.     cvar_z->modified = true;
  1010.  
  1011.     orig_Z_Free(cvar_x->string);
  1012.     orig_Z_Free(cvar_y->string);
  1013.     orig_Z_Free(cvar_z->string);
  1014.  
  1015.     char floatstring[64];
  1016.     cvar_x->value = *(float*)(ent + EDICT_S_ORIGIN);
  1017.     sprintf(floatstring,"%f",cvar_x->value);
  1018.     cvar_x->string = orig_CopyString(floatstring);
  1019.  
  1020.     cvar_y->value = *(float*)(ent + EDICT_S_ORIGIN+4);
  1021.     sprintf(floatstring,"%f",cvar_y->value);
  1022.     cvar_y->string = orig_CopyString(floatstring);
  1023.  
  1024.     cvar_z->value = *(float*)(ent + EDICT_S_ORIGIN+8);
  1025.     sprintf(floatstring,"%f",cvar_z->value);
  1026.     cvar_z->string = orig_CopyString(floatstring);
  1027.    
  1028. }
  1029.  
  1030.  
  1031. void Cmd_PlayerEffect(void)
  1032. {
  1033.     orig_FX_HandleDMMuzzleFlash()
  1034. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement