Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sofheader.h"
- #include "print.h"
- #include <stdlib.h>
- #include <string.h>
- // StrStrI
- #include <Shlwapi.h>
- void * player_export = NULL;
- void createCommands(void)
- {
- orig_Cmd_AddCommand("test",(void*)test);
- orig_Cmd_AddCommand("sp_sv_sofree_help",(void*)Cmd_SofreeHelp);
- orig_Cmd_AddCommand("sp_sv_ent_spawn",(void*)Cmd_SpawnEntity_f);
- orig_Cmd_AddCommand("sp_sv_ent_freeall",(void*)Cmd_RemoveCustomEnts_f);
- orig_Cmd_AddCommand("sp_sv_ent_moveall",(void*)Cmd_MoveCustomEnts_f);
- //if sofplus
- // orig_Cmd_RemoveCommand("sp_sv_client_swap");
- // orig_Cmd_RemoveCommand("sp_sv_client_red");
- // orig_Cmd_RemoveCommand("sp_sv_client_blue");
- // orig_Cmd_AddCommand("sp_sv_client_blue",(void*)Cmd_Blue_f);
- // orig_Cmd_AddCommand("sp_sv_client_red",(void*)Cmd_Red_f);
- // orig_Cmd_AddCommand("sp_sv_client_swap",(void*)Cmd_Swap_f);
- orig_Cmd_AddCommand("sp_sv_sound_play",(void*)Cmd_PlaySound);
- orig_Cmd_AddCommand("sp_sv_sound_register",(void*)Cmd_RegisterSound);
- orig_Cmd_AddCommand("sp_sv_sound_remove",(void*)Cmd_RemoveSound);
- orig_Cmd_AddCommand("sp_sv_sound_list",(void*)Cmd_ListRegisteredSounds);
- orig_Cmd_AddCommand("sp_sv_sound_override",(void*)Cmd_OverrideSound);
- orig_Cmd_AddCommand("Cmd_TakePiss",(void*)Cmd_TakePiss);
- orig_Cmd_AddCommand("sp_sv_spackage_register",(void*)Cmd_SP_Register);
- orig_Cmd_AddCommand("sp_sv_spackage_print_id",(void*)Cmd_SP_Print);
- orig_Cmd_AddCommand("sp_sv_spackage_print_obit",(void*)Cmd_SP_Print_Obit);
- orig_Cmd_AddCommand("sp_sv_spackage_print_string",(void*)Cmd_SP_SPrint);
- orig_Cmd_AddCommand("Cmd_SP_GetStringText",(void*)Cmd_SP_GetStringText);
- orig_Cmd_AddCommand("sp_sv_script_load",(void*)Cmd_LoadScript);
- orig_Cmd_AddCommand("sp_sv_script_run",(void*)Cmd_RunScript);
- orig_Cmd_AddCommand("sp_sv_script_stop",(void*)Cmd_StopScript);
- orig_Cmd_AddCommand("sp_sv_player_move",(void*)Cmd_Go);
- orig_Cmd_AddCommand("sp_sv_player_paint",(void*)Cmd_PaintPlayers);
- orig_Cmd_AddCommand("sp_sv_player_weappaint",(void*)Cmd_PaintWeapons);
- orig_Cmd_AddCommand("sp_sv_player_collision",(void*)Cmd_PlayerCollision);
- orig_Cmd_AddCommand("sp_sv_player_pos",(void*)Cmd_PlayerPos);
- orig_Cmd_AddCommand("sp_sv_player_effect",(void*)Cmd_PlayerEffect);
- }
- void test(void)
- {
- // orig_Com_Printf("File exists result : %i\n",orig_FS_FileExists(orig_Cmd_Argv(1)));
- //edict_t * ent = get_ent_from_player_slot(0);
- // char config[3];
- // config[0] = 'r';
- // config[1] = 1;
- // config[2] = 0;
- // orig_PF_Configstring(CS_CTF_BLUE_STAT,config);
- edict_t * ent1 = get_ent_from_player_slot(0);
- edict_t * ent2 = get_ent_from_player_slot(1);
- // entity_state_t *est = (entity_state_t*)ent;
- // orig_Com_Printf("effects = %i\n",est->effects);
- // orig_Com_Printf("renderfx = %i\n",est->renderfx);
- // orig_Com_Printf("event = %i\n",est->event);
- // orig_Com_Printf("event2 = %i\n",est->event2);
- // orig_Com_Printf("event3 = %i\n",est->event3);
- // orig_Com_Printf("data = %i\n",est->data);
- // orig_Com_Printf("data2 = %i\n",est->data2);
- // orig_Com_Printf("data3 = %i\n",est->data3);
- // orig_Com_Printf("data3 = %i\n",est->data3);
- // orig_Com_Printf("effectData = %i\n",est->effectData[0]);
- // orig_Com_Printf("effectData1 = %i\n",est->effectData[1]);
- // orig_Com_Printf("effectData2 = %i\n",est->effectData[2]);
- // orig_Com_Printf("effectData3 = %i\n",est->effectData[3]);
- // unsigned int gclient = *(unsigned int*)((unsigned int)ent+EDICT_GCLIENT);
- // unsigned int inv = *(unsigned int*)((unsigned int)gclient+GCLIENT_INV);
- // clientinst = *(unsigned int*)((unsigned int)inv+(unsigned int)0x14C);
- // GhoulSetTint(1.0,0.0,0.0,1.0);
- // orig_sendRestartPrediction(ent);
- // clientinst = *(unsigned int*)((unsigned int)inv+(unsigned int)0x14C);
- // GhoulSetTint(1.0,0.0,0.0,1.0);
- // orig_PF_WriteByte(0xD);
- // orig_PF_WriteString("password ""\x08""echo lol\n""\x00\x08""echo lol");
- // orig_PF_Unicast(ent,1);
- orig_Com_Printf(P_PINK"one is : %08X\ntwo is : %08X\n",*(unsigned int*)(ent1+EDICT_SOLID),*(unsigned int*)(ent2+EDICT_SOLID));
- }
- #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 sp_sv_sofree_help to see this info again\n"
- "---------------------------------------------\n"
- "sp_sv_script_load\n"
- "sp_sv_script_run\n"
- "sp_sv_script_stop\n"
- "\n"
- "sp_sv_sound_list\n"
- "sp_sv_sound_play\n"
- "sp_sv_sound_register\n"
- "sp_sv_sound_remove\n"
- "sp_sv_sound_override\n"
- "\n"
- "sp_sv_player_move\n"
- "sp_sv_player_paint\n"
- "sp_sv_player_weappaint\n"
- "sp_sv_player_collision\n"
- "sp_sv_player_pos\n"
- "---------------------------------------------\n"
- "Use \"["HELP_BOLD"commandname"HELP_TEXT"] "HELP_BOLD"-h\""HELP_TEXT" to display information about a command\n"
- );
- }
- void Cmd_Swap_f(void)
- {
- int argc = orig_Cmd_Argc();
- if ( argc == 2 ) {
- if ( !strcmp(orig_Cmd_Argv(1),"*")) {
- for ( int i = 0; i < 16; i++ ) {
- unsigned int team = *(unsigned int*)(*(unsigned int*)GCLIENT_BASE + (i * SIZE_OF_GCLIENT) + GCLIENT_TEAM);
- if ( team == 2 ) {
- goBlue(i);
- } else if ( team == 1 ) {
- goRed(i);
- }
- }
- } else {
- int slot = atoi(orig_Cmd_Argv(1));
- if ( slot >=0 && slot < 16 )
- {
- unsigned int team = *(unsigned int*)(*(unsigned int*)GCLIENT_BASE + (slot * SIZE_OF_GCLIENT) + GCLIENT_TEAM);
- if ( team == 2 ) {
- goBlue(slot);
- } else if ( team == 1 ) {
- goRed(slot);
- }
- }
- }
- }
- }
- void Cmd_Blue_f(void)
- {
- int argc = orig_Cmd_Argc();
- if ( argc == 2 ) {
- if ( !strcmp(orig_Cmd_Argv(1),"*")) {
- for ( int i = 0; i < 16; i++ ) {
- goBlue(i);
- }
- } else {
- int slot = atoi(orig_Cmd_Argv(1));
- if ( slot >=0 && slot < 16 )
- {
- goBlue(slot);
- }
- }
- }
- }
- void Cmd_Red_f(void)
- {
- int argc = orig_Cmd_Argc();
- if ( argc == 2 ) {
- if ( !strcmp(orig_Cmd_Argv(1),"*")) {
- for ( int i = 0; i < 16; i++ ) {
- goRed(i);
- }
- } else {
- int slot = atoi(orig_Cmd_Argv(1));
- if ( slot >=0 && slot < 16 )
- {
- goRed(slot);
- }
- }
- }
- }
- void goRed(int who) {
- // orig_Com_Printf("yo momma's team is %i\n",*(unsigned int*)(*(unsigned int*)0x5015D6C4 + (slot * 0x600) + 0x324));
- // *(unsigned int*)(*(unsigned int*)0x5015D6C4 + (slot * 0x600) + 0x324) = 2;
- void * client_t = (void*)((*(unsigned int*)0x20396EEC) + ( who * 0xd2ac));
- char * cl_userinfo = (char*)((unsigned int)client_t + 0x4);
- orig_Info_SetValueForKey(cl_userinfo,"team_red_blue","1");
- orig_SV_UserinfoChanged(client_t);
- my_SV_UserinfoChanged(client_t);
- }
- void goBlue(int who) {
- void * client_t = (void*)((*(unsigned int*)0x20396EEC) + ( who * 0xd2ac));
- char * cl_userinfo = (char*)((unsigned int)client_t + 0x4);
- orig_Info_SetValueForKey(cl_userinfo,"team_red_blue","0");
- orig_SV_UserinfoChanged(client_t);
- my_SV_UserinfoChanged(client_t);
- }
- void * mem_edictpointers = NULL;
- int edict_count = 0;
- //mygimme [classname] [x] [y] [z] [pitch] [yaw]
- void Cmd_SpawnEntity_f(void)
- {
- edict_count++;
- orig_Com_Printf("added new eddict, count is now %i\n",edict_count);
- mem_edictpointers = realloc(mem_edictpointers,edict_count*4);
- orig_Com_Printf("you want to spawn : %s\n",orig_Cmd_Argv(1));
- unsigned int edict_addr = (unsigned int)orig_G_Spawn();
- *(unsigned int*)((unsigned int)mem_edictpointers+(edict_count-1)*4) = edict_addr;
- //classname
- *(char**)((int)edict_addr + 0x1B4) = orig_ED_NewString(orig_Cmd_Argv(1));
- //origin
- *(float*)(edict_addr + 0x4) = atof(orig_Cmd_Argv(2));
- *(float*)(edict_addr + 0x8) = atof(orig_Cmd_Argv(3));
- *(float*)(edict_addr + 0xC) = atof(orig_Cmd_Argv(4));
- //rotation
- *(float*)(edict_addr + 0x10) = atof(orig_Cmd_Argv(5));
- *(float*)(edict_addr + 0x14) = atof(orig_Cmd_Argv(6));
- orig_ED_CallSpawn((void*)edict_addr);
- }
- void Cmd_RemoveCustomEnts_f(void)
- {
- /*orig_G_FreeEdict((void*)*(unsigned int*)mem_edictpointers);
- edict_count = 0;
- free(mem_edictpointers);*/
- for ( int i=0 ; i < edict_count; i ++)
- {
- orig_Com_Printf("Removed %08X edict_t*\n",*(unsigned int*)((unsigned int)mem_edictpointers+i*4));
- orig_G_FreeEdict((void*)*(unsigned int*)((unsigned int)mem_edictpointers+i*4));
- }
- edict_count = 0;
- free(mem_edictpointers);
- mem_edictpointers = NULL;
- }
- void Cmd_MoveCustomEnts_f(void)
- {
- for ( int i=0 ; i < edict_count; i ++)
- {
- unsigned int edict = *(unsigned int*)((unsigned int)mem_edictpointers+i*4);
- *(float*)(edict + 0x4) += 50;
- }
- }
- void Cmd_ListRegisteredSounds(void)
- {
- if ( !strcmp(orig_Cmd_Argv(1) ,"-h" ) ) {
- orig_Com_Printf(
- "Lists all registered sounds\n"
- "See _sp_sv_sound_info_slots for how many sounds slots you have free\n"
- "----------------------------\n"
- "takes no arguments\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() > 2 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- int i;
- for (i=0 ; i<MAX_SOUNDS ; i++) {
- if ( *(unsigned char*)(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH) )
- {
- char line[65];
- // sprintf(line,"%s",(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH));
- strcpy(line,SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH);
- strcat(line,"\n");
- if ( orig_Cmd_Argc() == 2 ) {
- if ( StrStrI(line,orig_Cmd_Argv(1)) ) {
- orig_Com_Printf(line);
- }
- } else {
- orig_Com_Printf(line);
- }
- }
- }
- }
- void Cmd_CalcFreeSoundSlots(void)
- {
- int freeslots = 0;
- int i;
- for (i=0 ; i<MAX_SOUNDS ; i++) {
- if ( *(unsigned char*)(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH) == '\0' )
- {
- freeslots++;
- }
- }
- char num[8];
- orig_Cvar_Set("_sp_sv_sound_info_slots",itoa(freeslots,num,10));
- }
- //1: name of sound
- void Cmd_RegisterSound(void)
- {
- char * one = orig_Cmd_Argv(1);
- if ( !strcmp(one ,"-h" ) ) {
- orig_Com_Printf(
- "Registers a new soundfile\n"
- "Sound files live in your %%User%%/sound directory\n"
- "See _sp_sv_sound_info_slots for how many sounds slots you have free\n"
- "----------------------------\n"
- "arg1 -> name of soundfile eg. misc/talk.wav\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 2 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- int i;
- // sv_soundindex(orig_Cmd_Argv(1));
- char ver1[128];
- strcpy(ver1,one);
- replacechar(ver1,'\\','/');
- for (i=1 ; i<MAX_SOUNDS && *(unsigned char*)(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH) ; i++)
- if (!strcmp(SV_CONFIGSTRINGS+(CS_SOUNDS+i)*MAX_QPATH, ver1))
- return;
- // dont allow overflow condition
- if (i < MAX_SOUNDS) {
- orig_SV_FindIndex(ver1, CS_SOUNDS, MAX_SOUNDS, 1,"sound");
- }
- Cmd_CalcFreeSoundSlots();
- }
- void Cmd_RemoveSound(void)
- {
- char * one = orig_Cmd_Argv(1);
- if ( !strcmp(one,"-h" ) ) {
- orig_Com_Printf(
- "Unregisters a soundfile that is already registered\n"
- "Sound files live in your %%User%%/sound directory\n"
- "See _sp_sv_sound_info_slots for how many sounds slots you have free\n"
- "----------------------------\n"
- "arg1 -> name of soundfile eg. misc/talk.wav\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 2 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- char ver1[128];
- strcpy(ver1,one);
- replacechar(ver1,'\\','/');
- orig_SV_RemoveSound(ver1);
- Cmd_CalcFreeSoundSlots();
- }
- //(edict_t *entity, int channel, int sound_num, float volume, float attenuation, float timeofs)
- //1: name of sound
- //2:
- void Cmd_PlaySound(void)
- {
- char * one = orig_Cmd_Argv(1);
- if ( !strcmp(one,"-h" ) ) {
- orig_Com_Printf(
- "Plays a soundfile that has already been registered\n"
- "----------------------------\n"
- "arg1 -> name of soundfile eg. misc/talk.wav\n"
- "arg2 -> player slot to attach the sound to - must be specified\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 3 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- edict_t * ent = get_ent_from_player_slot(atoi(orig_Cmd_Argv(2)));
- if (!ent) {
- PrintOut(PRINT_BAD,0,"Invalid ent.\n");
- return;
- }
- char ver1[128];
- strcpy(ver1,one);
- replacechar(ver1,'\\','/');
- // create bool is false
- int index = orig_SV_FindIndex(ver1, CS_SOUNDS, MAX_SOUNDS, 0,"sound");
- // only if its in our configstring
- if (index)
- orig_PF_StartSound(ent,CHAN_AUTO, index ,0.6,ATTN_NORM,0);
- else
- PrintOut(PRINT_BAD,0,"Sound is not registered.\n");
- }
- unsigned int num_sound_overrides = 0;
- sound_overrides_t * sound_overrides = NULL;
- // sp_sv_sound_override "/enemy/dth/*" ""
- // sp_sv_sound_override "/impact/gore/*" ""
- // sp_sv_sound_override "/impact/player/*" ""
- void Cmd_OverrideSound(void)
- {
- char * one = orig_Cmd_Argv(1);
- if ( !strcmp(one,"-h" ) ) {
- orig_Com_Printf(
- "Plays a specific sound in place of a previous one\n"
- "----------------------------\n"
- "arg1 -> the known original sound - can end with a * to target many sounds\n"
- "arg2 -> your new sound - can be empty then will play no sound\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 3 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- sound_overrides_t * p = sound_overrides;
- if ( num_sound_overrides > 0 ) {
- while ( p->next != NULL )
- {
- p = sound_overrides->next;
- }
- p->next = malloc(sizeof(sound_overrides_s));
- p = p->next;
- } else
- {
- sound_overrides = malloc(sizeof(sound_overrides_s));
- p = sound_overrides;
- }
- num_sound_overrides++;
- p->next = NULL;
- strcpy(p->orig_sound,orig_Cmd_Argv(1));
- strcpy(p->new_sound,orig_Cmd_Argv(2));
- }
- void Cmd_TakePiss(void)
- {
- // orig_TakePiss(*(edict_t**)(cl + CLIENT_ENT))
- }
- // Register a string package
- void Cmd_SP_Register(void)
- {
- orig_SP_Register(orig_Cmd_Argv(1));
- }
- //typedef void (*SP_Print)(edict_t *ent, unsigned short ID, ...);
- // who,num
- void Cmd_SP_Print(void)
- {
- unsigned int ed_base = *(unsigned int*)EDICT_BASE;
- orig_SP_Print(ed_base + (atoi(orig_Cmd_Argv(1))+1)*SIZE_OF_EDICT,atoi(orig_Cmd_Argv(2)));
- }
- // typedef void (*SP_Print_Obit)(edict_t *ent, unsigned short ID, ...);
- // who,num
- void Cmd_SP_Print_Obit(void)
- {
- unsigned int ed_base = *(unsigned int*)EDICT_BASE;
- orig_SP_Print(ed_base + (atoi(orig_Cmd_Argv(1))+1)*SIZE_OF_EDICT,atoi(orig_Cmd_Argv(2)));
- }
- // typedef int (*SP_SPrint)(char *buffer, int buffer_size, unsigned short ID, ...);
- // who,msg,len
- void Cmd_SP_SPrint(void)
- {
- orig_SP_Print(orig_Cmd_Argv(2),atoi(orig_Cmd_Argv(3)),atoi(orig_Cmd_Argv(1)));
- }
- // typedef const char *(*SP_GetStringText)(unsigned short ID);
- void Cmd_SP_GetStringText(void)
- {
- char out[2048] = "echo ";
- strcat(out,orig_SP_GetStringText(atoi(orig_Cmd_Argv(1))));
- orig_Cbuf_AddText(out);
- }
- struct d_script_s
- {
- char name[64];
- // CScript pointer self
- void * handle;
- };
- struct d_script_s * dende_scripts[MAX_D_SCRIPTS] = {NULL};
- int d_script_pointer = 0;
- // they must have moved script_use into the class...
- // void script_use(edict_t *ent, edict_t *other, edict_t *activator)
- void Cmd_RunScript(void)
- {
- if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
- orig_Com_Printf(
- "Executes a DesignerScript file (.os), located in your %%User%%/ds/ directory\n"
- "DesignerScripts are .ds files compiled into .os files using sofds.exe\n"
- "eg. \"sp_sv_script_run elevator\" -notice no file extension\n"
- "----------------------------\n"
- "arg1 -> name of script\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 2 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- // void * cl = (void*)((*(unsigned int*)CLIENT_BASE) + ( (unsigned int)(atoi(orig_Cmd_Argv(1))) * SIZE_OF_CLIENT));
- // edict_t * entbleh = *(edict_t**)(cl + CLIENT_ENT);
- char scriptname[64];
- sprintf(scriptname,"ds/%s.os",orig_Cmd_Argv(1));
- if ( !orig_FS_FileExists(scriptname) ) {
- PrintOut(PRINT_BAD,false,"You are trying run a script that is unlikely to be loaded.\n");
- return;
- }
- unsigned int ed_base = *(unsigned int*)EDICT_BASE;
- //search for scriptname
- struct d_script_s * ds = NULL;
- for ( int i = 0 ; i < d_script_pointer; i++ ) {
- struct d_script_s * ds = dende_scripts[i];
- if ( !strcmp(scriptname,ds->name) ) {
- unsigned int * cond = (unsigned int)(ds->handle + CSCRIPT_SCRIPTCONDITION);
- if ( *cond != COND_COMPLETED && *cond != COND_READY )
- {
- PrintOut(PRINT_GOOD,false,"Seems like script %s is already running\n",scriptname);
- return;
- }
- // To allow many scripts to use one entity?
- //Link entity to script before run ?
- *(unsigned int*)(ed_base+EDICT_SCRIPT) = ds->handle;
- PrintOut(PRINT_GOOD,false,"Running script %s\n",scriptname);
- *(unsigned int*)(ds->handle + CSCRIPT_SCRIPTCONDITION) = COND_READY;
- orig_script_use(ed_base,ed_base,ed_base);
- return;
- }
- }
- /*
- asm volatile( "push %1;"//push scriptname
- "push %2;"//push owner
- "push %3;"//push owner
- "movl %0,%%ecx;"//new_mem->ecx
- "call *%4;"//call orig_script_use
- ::"m"(myscript),"m"(entbleh),"m"(entbleh),"m"(entbleh),"m"(orig_script_use):"%ecx");
- */
- }
- void Cmd_LoadScript(void)
- {
- if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
- orig_Com_Printf(
- "Loads a DesignerScript file (.os), located in your %%User%%/ds/ directory\n"
- "DesignerScripts are .ds files compiled into .os files using sofds.exe\n"
- "eg. \"sp_sv_script_load elevator\" -notice no file extension\n"
- "----------------------------\n"
- "arg1 -> name of script\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 2 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- void * newscript = orig_cplusplus_new(0x4b4);
- char scriptname[64];
- sprintf(scriptname,"ds/%s.os",orig_Cmd_Argv(1));
- if ( !orig_FS_FileExists(scriptname) ) {
- PrintOut(PRINT_BAD,false,"You are trying to load a non-existant file.\n");
- return;
- }
- struct d_script_s * ds = NULL;
- for ( int i = 0 ; i < d_script_pointer; i++ ) {
- struct d_script_s * ds = dende_scripts[i];
- if ( !strcmp(scriptname,ds->name) ) {
- PrintOut(PRINT_BAD,false,"Script %s is already loaded\n",scriptname);
- return;
- }
- }
- PrintOut(PRINT_GOOD,false,"Loading script %s\n",scriptname);
- // create the d_script
- ds = dende_scripts[d_script_pointer] = malloc(sizeof(struct d_script_s));
- d_script_pointer++;
- strcpy(ds->name,scriptname);
- ds->handle = newscript;
- //st.script = scriptname
- // *(unsigned int*)0x5015CC30 = &(scriptname[0]);
- //orig_SP_script_runner(owner);
- unsigned int ed_base = *(unsigned int*)EDICT_BASE;
- unsigned int worldspawn = ed_base;
- unsigned int p_to_string = &(scriptname[0]);
- asm volatile( "push %1;"//push scriptname
- "push %2;"//push owner
- "movl %0,%%ecx;"//new_mem->ecx
- "call *%3;"//call orig_CScript
- ::"m"(newscript),"m"(worldspawn),"m"(p_to_string),"m"(orig_CScript):"%ecx");
- // ent->script = newscript
- *(unsigned int*)(ed_base+EDICT_SCRIPT) = newscript;
- // append to list of scripts
- void * newListItem = orig_cplusplus_new(0xC);
- unsigned int esi = *(unsigned int*)0x5015C504;
- *(unsigned int*)newListItem = esi;
- unsigned int edi = *(unsigned int*)(esi+4 );
- *(unsigned int*)(newListItem+4) = edi;
- *(unsigned int*)(esi+4) = newListItem;
- *(unsigned int*)( *(unsigned int*)(newListItem+4) ) = newListItem;
- *(unsigned int*)(newListItem+8) = *(unsigned int*)(ed_base+EDICT_SCRIPT);
- *(unsigned int*)(0x5015C508) = *(unsigned int*)(0x5015C508) + 1;
- }
- void Cmd_StopScript(void)
- {
- if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
- orig_Com_Printf(
- "Stops excution of a DesignerScript file (.os), located in your %%User%%/ds/ directory\n"
- "DesignerScripts are .ds files compiled into .os files using sofds.exe\n"
- "eg. \"sp_sv_script_stop elevator\" -notice no file extension\n"
- "----------------------------\n"
- "arg1 -> name of script\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 2 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- char scriptname[64];
- sprintf(scriptname,"ds/%s.os",orig_Cmd_Argv(1));
- if ( !orig_FS_FileExists(scriptname) ) {
- PrintOut(PRINT_BAD,false,"You are trying stop a script that is unlikely to be loaded.\n");
- return;
- }
- struct d_script_s * ds = NULL;
- for ( int i = 0 ; i < d_script_pointer; i++ ) {
- struct d_script_s * ds = dende_scripts[i];
- if ( !strcmp(scriptname,ds->name) ) {
- PrintOut(PRINT_GOOD,false,"Stopping script %s\n",scriptname);
- *(unsigned int*)(ds->handle + CSCRIPT_SCRIPTCONDITION) = COND_COMPLETED;
- return;
- }
- }
- }
- void Cmd_Go(void)
- {
- if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
- orig_Com_Printf(
- "Teleports a player to specified x,y,z co-ordinate\n"
- "----------------------------\n"
- "arg1 -> valid slot id\n"
- "arg2 -> x position represent a number like 10.555\n"
- "arg3 -> y position represent a number like 10.555\n"
- "arg4 -> z position represent a number like 10.555\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 5 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- edict_t* ent = get_ent_from_player_slot(atoi(orig_Cmd_Argv(1)));
- if ( !ent ) {
- PrintOut(PRINT_BAD,false,"Invalid Ent\n");
- return;
- }
- float x = atof(orig_Cmd_Argv(2));
- float y = atof(orig_Cmd_Argv(3));
- float z = atof(orig_Cmd_Argv(4));
- vec3_t v = {x,y,z};
- VectorCopy(v, ent+EDICT_S_ORIGIN );
- }
- float player_tint[32][4];
- float player_wep_tint[32][4];
- void Cmd_PaintPlayers(void)
- {
- if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
- orig_Com_Printf(
- "Applies a coloured tint on a specific player\n"
- "----------------------------\n"
- "arg1 -> valid slot id\n"
- "arg2 -> red component between 0.0 and 1.0\n"
- "arg3 -> green component between 0.0 and 1.0\n"
- "arg4 -> blue component between 0.0 and 1.0\n"
- "arg5 -> opacity component between 0.0 and 1.0 , 1.0 being fully visible\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 6 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- unsigned int slot = atoi(orig_Cmd_Argv(1));
- edict_t* ent = get_ent_from_player_slot(slot);
- if ( !ent ) {
- PrintOut(PRINT_BAD,false,"Invalid Ent\n");
- return;
- }
- // PrintOut(PRINT_GOOD,false,"argc is : %i\n",orig_Cmd_Argc());
- float r = atof(orig_Cmd_Argv(2));
- float g = atof(orig_Cmd_Argv(3));
- float b = atof(orig_Cmd_Argv(4));
- float a = atof(orig_Cmd_Argv(5));
- player_tint[slot][0] = r;
- player_tint[slot][1] = g;
- player_tint[slot][2] = b;
- player_tint[slot][3] = a;
- clientinst = *(unsigned int*)(*(unsigned int*)(ent + EDICT_GCLIENT) + GCLIENT_S_BODY);
- if ( clientinst ) {
- GhoulSetTintOnAll(player_tint[slot][0],player_tint[slot][1],player_tint[slot][2],player_tint[slot][3]);
- }
- }
- unsigned int was_ghosted[32];
- void Cmd_PaintWeapons(void)
- {
- if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
- orig_Com_Printf(
- "Applies a coloured tint on a specific player's weapon\n"
- "----------------------------\n"
- "arg1 -> valid slot id\n"
- "arg2 -> red component between 0.0 and 1.0\n"
- "arg3 -> green component between 0.0 and 1.0\n"
- "arg4 -> blue component between 0.0 and 1.0\n"
- "arg5 -> opacity component between 0.0 and 1.0 , 1.0 being fully visible\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 6 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- unsigned int slot = atoi(orig_Cmd_Argv(1));
- edict_t* ent = get_ent_from_player_slot(slot);
- if ( !ent ) {
- PrintOut(PRINT_BAD,false,"Invalid Ent\n");
- return;
- }
- // PrintOut(PRINT_GOOD,false,"argc is : %i\n",orig_Cmd_Argc());
- float r = atof(orig_Cmd_Argv(2));
- float g = atof(orig_Cmd_Argv(3));
- float b = atof(orig_Cmd_Argv(4));
- float a = atof(orig_Cmd_Argv(5));
- player_wep_tint[slot][0] = r;
- player_wep_tint[slot][1] = g;
- player_wep_tint[slot][2] = b;
- player_wep_tint[slot][3] = a;
- void (*refreshWeapon)(void * inv) = 0x400052A0;
- // orig_Com_Printf("lol : %08X\n", player_export);
- int wp = 0;
- // weapons_t pistol = SFW_PISTOL1
- unsigned int gclient = *(unsigned int*)((unsigned int)ent+EDICT_GCLIENT);
- if ( gclient ) {
- unsigned int inv = *(unsigned int*)((unsigned int)gclient+GCLIENT_INV);
- if (inv) {
- sharedEdict_t sh;
- sh.inv=(void*)inv;
- sh.edict=ent;
- void ( __thiscall *SetOwner)(void * self,edict_t *own) = *(unsigned int*)((unsigned int)(*(unsigned int*)inv)+(unsigned int)0xF4);
- // // orig_Com_Printf("TAKE OUT YOUR KNIFE LIKE A MAN!\n");
- //(void*)orig_getViewModel(sh.inv);
- // orig_getViewModel = (getViewModel_type)();
- // orig_Com_Printf("lol %08X\n",orig_getViewModel);
- // orig_Com_Printf("lol %08X\n",*(unsigned int*)self);
- // clientinst = *(unsigned int*)((unsigned int)inv+(unsigned int)0x14C);
- // GhoulSetTint(1.0,0.0,0.0,1.0);
- //RebuildPredictedClientInv
- // void (*refreshWeapon)(void * inv) =*(unsigned int*)(0x5015D9B8 + 0x2C);
- SetOwner(inv,&sh);
- // requires owner
- // refreshWeapon(inv);
- orig_getCurWeapon = *(unsigned int*)((unsigned int)(*(unsigned int*)inv)+(unsigned int)0x5C);
- int curWeap = orig_getCurWeapon(inv);
- // orig_selectWeapon(inv,SFW_KNIFE);
- orig_selectWeapon(inv,curWeap);
- // orig_takeOutWeapon(inv,curWeap);
- clientinst = *(unsigned int*)((unsigned int)inv+(unsigned int)0x14C);
- if ( *(unsigned int*)(gclient + GCLIENT_GHOSTED) )
- GhoulSetTint(player_wep_tint[slot][0],player_wep_tint[slot][1],player_wep_tint[slot][2],0.4f);
- else
- GhoulSetTint(player_wep_tint[slot][0],player_wep_tint[slot][1],player_wep_tint[slot][2],player_wep_tint[slot][3]);
- orig_sendRestartPrediction(ent);
- // orig_ReliableWriteByteToClient(0x1E,slot);
- // orig_NetWrite = *(unsigned int*)((unsigned int)(*(unsigned int*)inv)+(unsigned int)0x138);
- // orig_NetWrite(inv,slot);
- // void * dmstandard = 0x5015C424;
- // void (__thiscall *clientRespawn)(void * self,edict_t * who) = 0x50074DA0;
- // clientRespawn(dmstandard,ent);
- // inven_c *W_NewInv(void)
- // {
- // return(new inven_c);
- // }
- // void W_KillInv(inven_c *inven)
- // {
- // delete(inven);
- // }
- // W_KillInv(ent);
- // ent.client->inv=pe->NewInv();
- }
- }
- }
- bool player_collision[32];
- void Cmd_PlayerCollision(void)
- {
- if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
- orig_Com_Printf(
- "Makes it so this player can be passed through by all other players\n"
- "----------------------------\n"
- "arg1 -> valid slot id\n"
- "arg2 -> 1 or 0 ... representing collision on or off\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 3 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- unsigned int slot = atoi(orig_Cmd_Argv(1));
- edict_t* ent = get_ent_from_player_slot(slot);
- if ( !ent ) {
- PrintOut(PRINT_BAD,false,"Invalid Ent\n");
- return;
- }
- int mode = atoi(orig_Cmd_Argv(2));
- if ( mode != 0 and mode != 1 )
- {
- PrintOut(PRINT_BAD,false,"Collision must be 1 or 0\n");
- }
- if ( mode == 1 ) {
- *(unsigned int*)(ent+EDICT_SOLID) = SOLID_BBOX;
- player_collision[slot] = true;
- } else {
- *(unsigned int*)(ent+EDICT_SOLID) = SOLID_TRIGGER;
- player_collision[slot] = false;
- }
- }
- void Cmd_PlayerPos(void)
- {
- if ( !strcmp(orig_Cmd_Argv(1),"-h" ) ) {
- orig_Com_Printf(
- "Gets the co-ordinates of the player and stores them in the 3 cvars you pass\n"
- "----------------------------\n"
- "arg1 -> valid slot id\n"
- "arg2 -> cvarname you want the x position to be stored in\n"
- "arg3 -> cvarname you want the y position to be stored in\n"
- "arg4 -> cvarname you want the z position to be stored in\n"
- );
- return;
- }
- if ( orig_Cmd_Argc() != 5 ) {
- PrintOut(PRINT_BAD,false,"[commandname] -h\n");
- return;
- }
- unsigned int slot = atoi(orig_Cmd_Argv(1));
- edict_t* ent = get_ent_from_player_slot(slot);
- if ( !ent ) {
- PrintOut(PRINT_BAD,false,"Invalid Ent\n");
- return;
- }
- cvar_t * cvar_x = findCvar(orig_Cmd_Argv(2));
- if ( !cvar_x ) {
- PrintOut(PRINT_BAD,false,"Cvar %s does not exist\n",orig_Cmd_Argv(2));
- return;
- }
- cvar_t * cvar_y = findCvar(orig_Cmd_Argv(3));
- if ( !cvar_x ) {
- PrintOut(PRINT_BAD,false,"Cvar %s does not exist\n",orig_Cmd_Argv(3));
- return;
- }
- cvar_t * cvar_z = findCvar(orig_Cmd_Argv(4));
- if ( !cvar_x ) {
- PrintOut(PRINT_BAD,false,"Cvar %s does not exist\n",orig_Cmd_Argv(4));
- return;
- }
- cvar_x->modified = true;
- cvar_y->modified = true;
- cvar_z->modified = true;
- orig_Z_Free(cvar_x->string);
- orig_Z_Free(cvar_y->string);
- orig_Z_Free(cvar_z->string);
- char floatstring[64];
- cvar_x->value = *(float*)(ent + EDICT_S_ORIGIN);
- sprintf(floatstring,"%f",cvar_x->value);
- cvar_x->string = orig_CopyString(floatstring);
- cvar_y->value = *(float*)(ent + EDICT_S_ORIGIN+4);
- sprintf(floatstring,"%f",cvar_y->value);
- cvar_y->string = orig_CopyString(floatstring);
- cvar_z->value = *(float*)(ent + EDICT_S_ORIGIN+8);
- sprintf(floatstring,"%f",cvar_z->value);
- cvar_z->string = orig_CopyString(floatstring);
- }
- void Cmd_PlayerEffect(void)
- {
- orig_FX_HandleDMMuzzleFlash()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement