Prepare function calls
This commit is contained in:
parent
3498944714
commit
a377e8562e
@ -28,6 +28,12 @@ namespace game
|
||||
short* scrVarGlob;
|
||||
char** scrMemTreePub;
|
||||
|
||||
unsigned int* scr_numParam;
|
||||
VariableValue** scr_stackPtr;
|
||||
|
||||
scr_call_t* scr_instanceFunctions;
|
||||
scr_call_t* scr_globalFunctions;
|
||||
|
||||
unsigned int* levelEntityId;
|
||||
|
||||
void AddRefToValue(VariableValue* value)
|
||||
@ -52,6 +58,18 @@ namespace game
|
||||
}
|
||||
}
|
||||
|
||||
void Scr_ClearOutParams()
|
||||
{
|
||||
const auto num_params = *scr_numParam;
|
||||
for (unsigned int i = num_params; i > 0; --i)
|
||||
{
|
||||
const auto value = (*scr_stackPtr)[i - 1];
|
||||
RemoveRefToValue(value.type, value.u);
|
||||
}
|
||||
|
||||
*scr_stackPtr -= num_params;
|
||||
}
|
||||
|
||||
scr_entref_t Scr_GetEntityIdRef(const unsigned int id)
|
||||
{
|
||||
static auto class_array = reinterpret_cast<DWORD*>(SELECT_VALUE(0x19AFC84, 0x1E72184, 0x1D3C804));
|
||||
@ -64,6 +82,18 @@ namespace game
|
||||
return result;
|
||||
}
|
||||
|
||||
scr_call_t Scr_GetFunc(const unsigned int index)
|
||||
{
|
||||
if (index > 0x1C7)
|
||||
{
|
||||
return scr_instanceFunctions[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return scr_globalFunctions[index];
|
||||
}
|
||||
}
|
||||
|
||||
const char* SL_ConvertToString(unsigned int stringValue)
|
||||
{
|
||||
if (!stringValue) return nullptr;
|
||||
@ -117,6 +147,12 @@ namespace game
|
||||
native::scrVarGlob = reinterpret_cast<short*>(SELECT_VALUE(0x19AFC80, 0x1E72180, 0x1D3C800));
|
||||
native::scrMemTreePub = reinterpret_cast<char**>(SELECT_VALUE(0x196FB00, 0x1E32000, 0x1C152A4));
|
||||
|
||||
native::scr_numParam = reinterpret_cast<unsigned int*>(SELECT_VALUE(0x1BF2598, 0x20B4A98, 0x1F5B098));
|
||||
native::scr_stackPtr = reinterpret_cast<native::VariableValue**>(SELECT_VALUE(0x1BF2590, 0x20B4A90, 0x1F5B090));
|
||||
|
||||
native::scr_instanceFunctions = reinterpret_cast<native::scr_call_t*>(SELECT_VALUE(0x184CDB0, 0x1D4F258, 0x1BF59C8));
|
||||
native::scr_globalFunctions = reinterpret_cast<native::scr_call_t*>(SELECT_VALUE(0x186C68C, 0x1D6EB34, 0x1C152A4));
|
||||
|
||||
native::levelEntityId = reinterpret_cast<unsigned int*>(SELECT_VALUE(0x1BCBCA4, 0x208E1A4, 0x1CD873C));
|
||||
}
|
||||
}
|
||||
|
@ -40,11 +40,19 @@ namespace game
|
||||
extern short* scrVarGlob;
|
||||
extern char** scrMemTreePub;
|
||||
|
||||
extern unsigned int* scr_numParam;
|
||||
extern VariableValue** scr_stackPtr;
|
||||
|
||||
extern scr_call_t* scr_instanceFunctions;
|
||||
extern scr_call_t* scr_globalFunctions;
|
||||
|
||||
extern unsigned int* levelEntityId;
|
||||
|
||||
void AddRefToValue(VariableValue* value);
|
||||
|
||||
void Scr_ClearOutParams();
|
||||
scr_entref_t Scr_GetEntityIdRef(unsigned int id);
|
||||
scr_call_t Scr_GetFunc(unsigned int index);
|
||||
|
||||
const char* SL_ConvertToString(unsigned int stringValue);
|
||||
}
|
||||
|
751
src/game/scripting/functions.cpp
Normal file
751
src/game/scripting/functions.cpp
Normal file
@ -0,0 +1,751 @@
|
||||
#include "std_include.hpp"
|
||||
#include "functions.hpp"
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace scripting
|
||||
{
|
||||
std::map<std::string, int> instance_function_map =
|
||||
{
|
||||
{"getviewmodel", 33457},
|
||||
{"fragbuttonpressed", 33458},
|
||||
{"secondaryoffhandbuttonpressed", 33459},
|
||||
{"getcurrentweaponclipammo", 33460},
|
||||
{"setvelocity", 33461},
|
||||
{"getplayerviewheight", 33462},
|
||||
{"enablemousesteer", 33545},
|
||||
{"getnormalizedmovement", 33463},
|
||||
{"getnormalizedcameramovement", 33486},
|
||||
{"giveweapon", 33487},
|
||||
{"takeweapon", 33488},
|
||||
{"takeallweapons", 33489},
|
||||
{"getcurrentweapon", 33490},
|
||||
{"getcurrentprimaryweapon", 33491},
|
||||
{"getcurrentoffhand", 33492},
|
||||
{"hasweapon", 33493},
|
||||
{"switchtoweapon", 33494},
|
||||
{"switchtoweaponimmediate", 33495},
|
||||
{"switchtooffhand", 33496},
|
||||
{"givestartammo", 33522},
|
||||
{"givemaxammo", 33523},
|
||||
{"getfractionstartammo", 33524},
|
||||
{"getfractionmaxammo", 33525},
|
||||
{"isdualwielding", 33526},
|
||||
{"isreloading", 33527},
|
||||
{"isswitchingweapon", 33528},
|
||||
{"setorigin", 33529},
|
||||
{"getvelocity", 33530},
|
||||
{"setplayerangles", 33531},
|
||||
{"getplayerangles", 33532},
|
||||
{"usebuttonpressed", 33533},
|
||||
{"attackbuttonpressed", 33534},
|
||||
{"adsbuttonpressed", 33535},
|
||||
{"meleebuttonpressed", 33536},
|
||||
{"playerads", 33537},
|
||||
{"isonground", 33538},
|
||||
{"isusingturret", 33539},
|
||||
{"setviewmodel", 33540},
|
||||
{"setoffhandprimaryclass", 33541},
|
||||
{"getoffhandprimaryclass", 33542},
|
||||
{"setoffhandsecondaryclass", 33497},
|
||||
{"getoffhandsecondaryclass", 33498},
|
||||
{"beginlocationselection", 33499},
|
||||
{"endlocationselection", 33500},
|
||||
{"disableweapons", 33501},
|
||||
{"enableweapons", 33502},
|
||||
{"disableoffhandweapons", 33503},
|
||||
{"enableoffhandweapons", 33504},
|
||||
{"disableweaponswitch", 33505},
|
||||
{"enableweaponswitch", 33506},
|
||||
{"openpopupmenu", 33507},
|
||||
{"openpopupmenunomouse", 33508},
|
||||
{"closepopupmenu", 33509},
|
||||
{"openmenu", 33510},
|
||||
{"closemenu", 33511},
|
||||
{"freezecontrols", 33513},
|
||||
{"disableusability", 33514},
|
||||
{"enableusability", 33515},
|
||||
{"setwhizbyspreads", 33516},
|
||||
{"setwhizbyradii", 33517},
|
||||
{"setreverb", 33518},
|
||||
{"deactivatereverb", 33519},
|
||||
{"setvolmod", 33520},
|
||||
{"setchannelvolume", 33521},
|
||||
{"setchannelvolumes", 33464},
|
||||
{"deactivatechannelvolumes", 33465},
|
||||
{"playlocalsound", 33466},
|
||||
{"stoplocalsound", 33467},
|
||||
{"setweaponammoclip", 33468},
|
||||
{"setweaponammostock", 33469},
|
||||
{"getweaponammoclip", 33470},
|
||||
{"getweaponammostock", 33471},
|
||||
{"anyammoforweaponmodes", 33472},
|
||||
{"setclientdvar", 33473},
|
||||
{"setclientdvars", 33474},
|
||||
{"allowads", 33475},
|
||||
{"allowjump", 33476},
|
||||
{"allowsprint", 33477},
|
||||
{"setspreadoverride", 33478},
|
||||
{"resetspreadoverride", 33479},
|
||||
{"setaimspreadmovementscale", 33480},
|
||||
{"setactionslot", 33481},
|
||||
{"setviewkickscale", 33482},
|
||||
{"getviewkickscale", 33483},
|
||||
{"getweaponslistall", 33484},
|
||||
{"getweaponslistprimaries", 33485},
|
||||
{"getweaponslistoffhands", 33430},
|
||||
{"getweaponslistitems", 33431},
|
||||
{"getweaponslistexclusives", 33432},
|
||||
{"getweaponslist", 33433},
|
||||
{"canplayerplacesentry", 33434},
|
||||
{"canplayerplacetank", 33435},
|
||||
{"visionsetnakedforplayer", 33436},
|
||||
{"visionsetnightforplayer", 33437},
|
||||
{"visionsetmissilecamforplayer", 33438},
|
||||
{"visionsetthermalforplayer", 33439},
|
||||
{"visionsetpainforplayer", 33440},
|
||||
{"setblurforplayer", 33441},
|
||||
{"getplayerweaponmodel", 33442},
|
||||
{"getplayerknifemodel", 33443},
|
||||
{"updateplayermodelwithweapons", 33444},
|
||||
{"notifyonplayercommand", 33445},
|
||||
{"canmantle", 33446},
|
||||
{"forcemantle", 33447},
|
||||
{"ismantling", 33448},
|
||||
{"playfx", 33449},
|
||||
{"recoilscaleon", 33450},
|
||||
{"recoilscaleoff", 33451},
|
||||
{"weaponlockstart", 33452},
|
||||
{"weaponlockfinalize", 33453},
|
||||
{"weaponlockfree", 33454},
|
||||
{"weaponlocktargettooclose", 33455},
|
||||
{"weaponlocknoclearance", 33390},
|
||||
{"visionsyncwithplayer", 33391},
|
||||
{"showhudsplash", 33392},
|
||||
{"setperk", 33393},
|
||||
{"hasperk", 33394},
|
||||
{"clearperks", 33395},
|
||||
{"unsetperk", 33396},
|
||||
{"noclip", 33397},
|
||||
{"ufo", 33398},
|
||||
|
||||
// playercmd #2
|
||||
{"pingplayer", 33308},
|
||||
{"buttonpressed", 33309},
|
||||
{"sayall", 33310},
|
||||
{"sayteam", 33311},
|
||||
{"showscoreboard", 33312},
|
||||
{"setspawnweapon", 33313},
|
||||
{"dropitem", 33314},
|
||||
{"dropscavengerbag", 33315},
|
||||
{"finishplayerdamage", 33340},
|
||||
{"suicide", 33341},
|
||||
{"closeingamemenu", 33342},
|
||||
{"iprintln", 33343},
|
||||
{"iprintlnbold", 33344},
|
||||
{"spawn", 33345},
|
||||
{"setentertime", 33346},
|
||||
{"cloneplayer", 33347},
|
||||
{"istalking", 33348},
|
||||
{"allowspectateteam", 33349},
|
||||
{"getguid", 33350},
|
||||
{"getxuid", 33382},
|
||||
{"ishost", 33383},
|
||||
{"getspectatingplayer", 33384},
|
||||
{"predictstreampos", 33385},
|
||||
{"updatescores", 33386},
|
||||
{"updatedmscores", 33387},
|
||||
{"setrank", 33388},
|
||||
{"setcardtitle", 33389},
|
||||
{"setcardicon", 33420},
|
||||
{"setcardnameplate", 33421},
|
||||
{"setcarddisplayslot", 33422},
|
||||
{"regweaponforfxremoval", 33423},
|
||||
{"laststandrevive", 33424},
|
||||
{"setspectatedefaults", 33425},
|
||||
{"getthirdpersoncrosshairoffset", 33426},
|
||||
{"disableweaponpickup", 33427},
|
||||
{"enableweaponpickup", 33428},
|
||||
|
||||
// HECmd
|
||||
{"settext", 32950},
|
||||
{"clearalltextafterhudelem", 32951},
|
||||
{"setshader", 32952},
|
||||
{"settargetent", 32953},
|
||||
{"cleartargetent", 32954},
|
||||
{"settimer", 32955},
|
||||
{"settimerup", 32956},
|
||||
{"settimerstatic", 32957},
|
||||
{"settenthstimer", 32958},
|
||||
{"settenthstimerup", 32959},
|
||||
{"settenthstimerstatic", 32960},
|
||||
{"setclock", 32961},
|
||||
{"setclockup", 32962},
|
||||
{"setvalue", 32963},
|
||||
{"setwaypoint", 32964},
|
||||
{"rotatingicon", 32965},
|
||||
{"secondaryarrow", 32891},
|
||||
{"setwaypointiconoffscreenonly", 32892},
|
||||
{"fadeovertime", 32893},
|
||||
{"scaleovertime", 32894},
|
||||
{"moveovertime", 32895},
|
||||
{"reset", 32896},
|
||||
{"destroy", 32897},
|
||||
{"setpulsefx", 32898},
|
||||
{"setplayernamestring", 32899},
|
||||
{"fadeovertime2", 33547},
|
||||
{"scaleovertime2", 33548},
|
||||
{"changefontscaleovertime", 32900},
|
||||
|
||||
// ScrCmd
|
||||
{"attach", 32791},
|
||||
{"attachshieldmodel", 32792},
|
||||
{"detach", 32804},
|
||||
{"detachshieldmodel", 32805},
|
||||
{"moveshieldmodel", 32806},
|
||||
{"detachall", 32807},
|
||||
{"getattachsize", 32808},
|
||||
{"getattachmodelname", 32809},
|
||||
{"getattachtagname", 32810},
|
||||
{"getattachignorecollision", 32835},
|
||||
{"hidepart", 32836},
|
||||
{"allinstances", 32837},
|
||||
{"hideallparts", 32838},
|
||||
{"showpart", 32839},
|
||||
{"showallparts", 32840},
|
||||
{"linkto", 32841},
|
||||
{"linktoblendtotag", 32842},
|
||||
{"unlink", 32843},
|
||||
{"islinked", 32867},
|
||||
{"enablelinkto", 32868},
|
||||
{"playerlinkto", 32885},
|
||||
{"playerlinktodelta", 32886},
|
||||
{"playerlinkweaponviewtodelta", 32887},
|
||||
{"playerlinktoabsolute", 32888},
|
||||
{"playerlinktoblend", 32889},
|
||||
{"playerlinkedoffsetenable", 32890},
|
||||
{"playerlinkedoffsetdisable", 32916},
|
||||
{"playerlinkedsetviewznear", 32917},
|
||||
{"playerlinkedsetusebaseangleforviewclamp", 32918},
|
||||
{"lerpviewangleclamp", 32919},
|
||||
{"setviewangleresistance", 32920},
|
||||
{"geteye", 32921},
|
||||
{"istouching", 32922},
|
||||
{"stoploopsound", 32923},
|
||||
{"stopsounds", 32924},
|
||||
{"playrumbleonentity", 32925},
|
||||
{"playrumblelooponentity", 32926},
|
||||
{"stoprumble", 32927},
|
||||
{"delete", 32928},
|
||||
{"setmodel", 32929},
|
||||
{"laseron", 32930},
|
||||
{"laseroff", 32931},
|
||||
{"laseraltviewon", 32932},
|
||||
{"laseraltviewoff", 32933},
|
||||
{"thermalvisionon", 32934},
|
||||
{"thermalvisionoff", 32935},
|
||||
{"thermaldrawenable", 32803},
|
||||
{"thermaldrawdisable", 32768},
|
||||
{"thermalvisionfofoverlayon", 32936},
|
||||
{"thermalvisionfofoverlayoff", 32937},
|
||||
{"autospotoverlayon", 32938},
|
||||
{"autospotoverlayoff", 32939},
|
||||
{"setcontents", 32940},
|
||||
{"makeusable", 32941},
|
||||
{"makeunusable", 32942},
|
||||
{"setcursorhint", 32966},
|
||||
{"sethintstring", 32967},
|
||||
{"forceusehinton", 32968},
|
||||
{"forceusehintoff", 32969},
|
||||
{"makesoft", 32970},
|
||||
{"makehard", 32971},
|
||||
{"willneverchange", 32972},
|
||||
{"startfiring", 32973},
|
||||
{"stopfiring", 32974},
|
||||
{"isfiringturret", 32975},
|
||||
{"startbarrelspin", 32976},
|
||||
{"stopbarrelspin", 32977},
|
||||
{"getbarrelspinrate", 32978},
|
||||
{"remotecontrolturret", 32979},
|
||||
{"remotecontrolturretoff", 32980},
|
||||
{"shootturret", 32981},
|
||||
{"getturretowner", 32982},
|
||||
{"setsentryowner", 33006},
|
||||
{"setsentrycarrier", 33007},
|
||||
{"setturretminimapvisible", 33008},
|
||||
{"settargetentity", 33009},
|
||||
{"snaptotargetentity", 33010},
|
||||
{"cleartargetentity", 33011},
|
||||
{"getturrettarget", 33012},
|
||||
{"setplayerspread", 33013},
|
||||
{"setaispread", 33014},
|
||||
{"setsuppressiontime", 33015},
|
||||
{"setconvergencetime", 33049},
|
||||
{"setconvergenceheightpercent", 33050},
|
||||
{"setturretteam", 33051},
|
||||
{"maketurretsolid", 33052},
|
||||
{"maketurretoperable", 33053},
|
||||
{"maketurretinoperable", 33054},
|
||||
{"setturretaccuracy", 33082},
|
||||
{"setrightarc", 33083},
|
||||
{"setleftarc", 33084},
|
||||
{"settoparc", 33085},
|
||||
{"setbottomarc", 33086},
|
||||
{"setautorotationdelay", 33087},
|
||||
{"setdefaultdroppitch", 33088},
|
||||
{"restoredefaultdroppitch", 33089},
|
||||
{"turretfiredisable", 33090},
|
||||
{"turretfireenable", 33121},
|
||||
{"setturretmodechangewait", 33122},
|
||||
{"usetriggerrequirelookat", 33123},
|
||||
{"getstance", 33124},
|
||||
{"setstance", 33125},
|
||||
{"itemweaponsetammo", 33126},
|
||||
{"getammocount", 33127},
|
||||
{"gettagorigin", 33128},
|
||||
{"gettagangles", 33129},
|
||||
{"shellshock", 33130},
|
||||
{"stunplayer", 33131},
|
||||
{"stopshellshock", 33132},
|
||||
{"fadeoutshellshock", 33133},
|
||||
{"setdepthoffield", 33134},
|
||||
{"setviewmodeldepthoffield", 33135},
|
||||
{"setmotionblurmovescale", 33136},
|
||||
{"setmotionblurturnscale", 33168},
|
||||
{"setmotionblurzoomscale", 33169},
|
||||
{"viewkick", 33170},
|
||||
{"localtoworldcoords", 33171},
|
||||
{"getentitynumber", 33172},
|
||||
{"getentityvelocity", 33173},
|
||||
{"enablegrenadetouchdamage", 33174},
|
||||
{"disablegrenadetouchdamage", 33175},
|
||||
{"enableaimassist", 33176},
|
||||
{"disableaimassist", 33207},
|
||||
{"radiusdamage", 33208},
|
||||
{"detonate", 33209},
|
||||
{"damageconetrace", 33210},
|
||||
{"sightconetrace", 33211},
|
||||
{"settargetent", 33212},
|
||||
{"settargetpos", 33213},
|
||||
{"cleartarget", 33214},
|
||||
{"setflightmodedirect", 33215},
|
||||
{"setflightmodetop", 33216},
|
||||
{"getlightintensity", 33217},
|
||||
{"setlightintensity", 33218},
|
||||
{"isragdoll", 33219},
|
||||
{"setmovespeedscale", 33220},
|
||||
{"cameralinkto", 33221},
|
||||
{"cameraunlink", 33222},
|
||||
{"controlslinkto", 33251},
|
||||
{"controlsunlink", 33252},
|
||||
{"makevehiclesolidcapsule", 33253},
|
||||
{"makevehiclesolidsphere", 33254},
|
||||
{"remotecontrolvehicle", 33256},
|
||||
{"remotecontrolvehicleoff", 33257},
|
||||
{"isfiringvehicleturret", 33258},
|
||||
{"drivevehicleandcontrolturret", 33259},
|
||||
{"drivevehicleandcontrolturretoff", 33260},
|
||||
{"getplayersetting", 33261},
|
||||
{"getlocalplayerprofiledata", 33262},
|
||||
{"setlocalplayerprofiledata", 33263},
|
||||
{"remotecamerasoundscapeon", 33264},
|
||||
{"remotecamerasoundscapeoff", 33265},
|
||||
{"radarjamon", 33266},
|
||||
{"radarjamoff", 33267},
|
||||
{"setmotiontrackervisible", 33268},
|
||||
{"getmotiontrackervisible", 33269},
|
||||
{"circle", 33270},
|
||||
{"getpointinbounds", 33271},
|
||||
{"transfermarkstonewscriptmodel", 33272},
|
||||
{"setwatersheeting", 33273},
|
||||
{"setweaponhudiconoverride", 33274},
|
||||
{"getweaponhudiconoverride", 33275},
|
||||
{"setempjammed", 33276},
|
||||
{"playersetexpfog", 33277},
|
||||
{"isitemunlocked", 33278},
|
||||
{"getplayerdata", 33279},
|
||||
{"setplayerdata", 33306},
|
||||
|
||||
// Vehicle stuff
|
||||
{"teleport", 0x824C},
|
||||
{"attachpath", 0x824D},
|
||||
{"getattachpos", 0x824E},
|
||||
{"startpath", 0x824F},
|
||||
{"setswitchnode", 0x8250},
|
||||
{"setwaitspeed", 0x8251},
|
||||
{"finishdamage", 0x8252},
|
||||
{"setspeed", 0x8253},
|
||||
{"setspeedimmediate", 0x8254},
|
||||
{"setwaitspeed", 0x8251},
|
||||
|
||||
{"setlookatent", 0x8237},
|
||||
{"clearlookatent", 0x8238},
|
||||
|
||||
{"setvehgoalpos", 33325},
|
||||
{"setturningability", 33381},
|
||||
|
||||
// some entity (script_model) stuff
|
||||
{"moveto", 33399},
|
||||
{"movex", 33400},
|
||||
{"movey", 33401},
|
||||
{"movez", 33402},
|
||||
{"movegravity", 33403},
|
||||
{"moveslide", 33404},
|
||||
{"stopmoveslide", 33405},
|
||||
{"rotateto", 33406},
|
||||
{"rotatepitch", 33407},
|
||||
{"rotateyaw", 33408},
|
||||
{"rotateroll", 33409},
|
||||
{"addpitch", 33410},
|
||||
{"addyaw", 33411},
|
||||
{"addroll", 33412},
|
||||
{"vibrate", 33413},
|
||||
{"rotatevelocity", 33414},
|
||||
{"solid", 33415},
|
||||
{"notsolid", 33416},
|
||||
{"setcandamage", 33417},
|
||||
{"setcanradiusdamage", 33418},
|
||||
{"physicslaunchclient", 33419},
|
||||
{"physicslaunchserver", 33351},
|
||||
{"physicslaunchserveritem", 33352},
|
||||
{"clonebrushmodeltoscriptmodel", 33353},
|
||||
{"scriptmodelplayanim", 33354},
|
||||
{"scriptmodelclearanim", 33355},
|
||||
|
||||
// varied ent/player script commands
|
||||
{"getorigin", 32910},
|
||||
{"useby", 32914},
|
||||
{"playsound", 32915},
|
||||
{"playsoundasmaster", 32878},
|
||||
{"playsoundtoteam", 32771},
|
||||
{"playsoundtoplayer", 32772},
|
||||
{"playloopsound", 32879},
|
||||
{"getnormalhealth", 32884},
|
||||
{"setnormalhealth", 32844},
|
||||
{"show", 32847},
|
||||
{"hide", 32848},
|
||||
{"playerhide", 32773},
|
||||
{"showtoplayer", 32774},
|
||||
{"enableplayeruse", 32775},
|
||||
{"disableplayeruse", 32776},
|
||||
{"setscriptmoverkillcam", 33546},
|
||||
{"makescrambler", 32777},
|
||||
{"makeportableradar", 32778},
|
||||
{"maketrophysystem", 32779},
|
||||
{"setmode", 32864},
|
||||
{"getmode", 32865},
|
||||
{"placespawnpoint", 32780},
|
||||
{"setteamfortrigger", 32781},
|
||||
{"clientclaimtrigger", 32782},
|
||||
{"clientreleasetrigger", 32783},
|
||||
{"releaseclaimedtrigger", 32784},
|
||||
{"isusingonlinedataoffline", 32785},
|
||||
{"getrestedtime", 32786},
|
||||
{"sendleaderboards", 32787},
|
||||
{"logstring", 32800},
|
||||
{"isonladder", 32788},
|
||||
{"startragdoll", 32798},
|
||||
{"getcorpseanim", 32789},
|
||||
{"playerforcedeathanim", 32790},
|
||||
{"startac130", 33543},
|
||||
{"stopac130", 33544},
|
||||
};
|
||||
|
||||
std::map<std::string, int> global_function_map =
|
||||
{
|
||||
// global stuff #1
|
||||
{"iprintln", 362},
|
||||
{"iprintlnbold", 363},
|
||||
{"logstring", 364},
|
||||
{"getent", 365},
|
||||
{"getentarray", 366},
|
||||
{"spawnplane", 367},
|
||||
{"spawnstruct", 368},
|
||||
{"spawnhelicopter", 369},
|
||||
{"isalive", 370},
|
||||
{"isspawner", 371},
|
||||
{"createattractorent", 372},
|
||||
{"createattractororigin", 373},
|
||||
{"createrepulsorent", 374},
|
||||
{"createrepulsororigin", 375},
|
||||
{"deleteattractor", 376},
|
||||
{"playsoundatpos", 377},
|
||||
{"newhudelem", 378},
|
||||
{"newclienthudelem", 379},
|
||||
{"newteamhudelem", 380},
|
||||
{"resettimeout", 381},
|
||||
{"precachefxteamthermal", 382},
|
||||
{"isplayer", 383},
|
||||
{"isplayernumber", 384},
|
||||
{"setsunlight", 57},
|
||||
{"resetsunlight", 58},
|
||||
{"setwinningplayer", 385},
|
||||
{"setwinningteam", 311},
|
||||
{"announcement", 312},
|
||||
{"clientannouncement", 313},
|
||||
{"getteamscore", 314},
|
||||
{"setteamscore", 315},
|
||||
{"setclientnamemode", 316},
|
||||
{"updateclientnames", 317},
|
||||
{"getteamplayersalive", 318},
|
||||
{"logprint", 319},
|
||||
{"worldentnumber", 320},
|
||||
{"obituary", 321},
|
||||
{"positionwouldtelefrag", 322},
|
||||
{"canspawn", 323},
|
||||
{"getstarttime", 324},
|
||||
{"precachestatusicon", 325},
|
||||
{"precacheminimapicon", 327},
|
||||
{"precachempanim", 328},
|
||||
{"restart", 329},
|
||||
{"exitlevel", 330},
|
||||
{"addtestclient", 331},
|
||||
{"makedvarserverinfo", 332},
|
||||
{"setarchive", 333},
|
||||
{"allclientsprint", 334},
|
||||
{"clientprint", 335},
|
||||
{"mapexists", 336},
|
||||
{"isvalidgametype", 337},
|
||||
{"matchend", 338},
|
||||
{"setplayerteamrank", 339},
|
||||
{"endparty", 340},
|
||||
{"setteamradar", 341},
|
||||
{"getteamradar", 342},
|
||||
{"setteamradarstrength", 343},
|
||||
{"getteamradarstrength", 344},
|
||||
{"getuavstrengthmin", 345},
|
||||
{"getuavstrengthmax", 262},
|
||||
{"getuavstrengthlevelneutral", 263},
|
||||
{"getuavstrengthlevelshowenemyfastsweep", 264},
|
||||
{"getuavstrengthlevelshowenemydirectional", 265},
|
||||
{"blockteamradar", 266},
|
||||
{"unblockteamradar", 267},
|
||||
{"isteamradarblocked", 268},
|
||||
{"getassignedteam", 269},
|
||||
{"setmatchdata", 270},
|
||||
{"getmatchdata", 271},
|
||||
{"sendmatchdata", 272},
|
||||
{"clearmatchdata", 273},
|
||||
{"setmatchdatadef", 274},
|
||||
{"setmatchclientip", 275},
|
||||
{"setmatchdataid", 276},
|
||||
{"setclientmatchdata", 277},
|
||||
{"getclientmatchdata", 278},
|
||||
{"setclientmatchdatadef", 279},
|
||||
{"sendclientmatchdata", 280},
|
||||
{"getbuildversion", 281},
|
||||
{"getbuildnumber", 282},
|
||||
{"getsystemtime", 283},
|
||||
{"getmatchrulesdata", 284},
|
||||
{"isusingmatchrulesdata", 285},
|
||||
{"kick", 286},
|
||||
{"issplitscreen", 287},
|
||||
{"setmapcenter", 288},
|
||||
{"setgameendtime", 289},
|
||||
{"visionsetnaked", 290},
|
||||
{"visionsetnight", 291},
|
||||
{"visionsetmissilecam", 292},
|
||||
{"visionsetthermal", 217},
|
||||
{"visionsetpain", 218},
|
||||
{"endlobby", 219},
|
||||
{"ambience", 220},
|
||||
{"getmapcustom", 221},
|
||||
{"updateskill", 222},
|
||||
{"spawnsighttrace", 223},
|
||||
|
||||
// global stuff #2
|
||||
{"setprintchannel", 14},
|
||||
{"print", 15},
|
||||
{"println", 16},
|
||||
{"print3d", 17},
|
||||
{"line", 18},
|
||||
{"spawnturret", 19},
|
||||
{"canspawnturret", 20},
|
||||
{"assert", 21},
|
||||
{"assertex", 38},
|
||||
{"assertmsg", 39},
|
||||
{"isdefined", 40},
|
||||
{"isstring", 41},
|
||||
{"setdvar", 42},
|
||||
{"setdynamicdvar", 43},
|
||||
{"setdvarifuninitialized", 44},
|
||||
{"setdevdvar", 45},
|
||||
{"setdevdvarifuninitialized", 46},
|
||||
{"getdvar", 47},
|
||||
{"getdvarint", 48},
|
||||
{"getdvarfloat", 49},
|
||||
{"getdvarvector", 50},
|
||||
{"gettime", 51},
|
||||
{"getentbynum", 52},
|
||||
{"getweaponmodel", 53},
|
||||
{"getweaponhidetags", 81},
|
||||
{"getanimlength", 82},
|
||||
{"animhasnotetrack", 83},
|
||||
{"getnotetracktimes", 84},
|
||||
{"spawn", 85},
|
||||
{"spawnloopsound", 86},
|
||||
{"bullettrace", 87},
|
||||
{"bullettracepassed", 88},
|
||||
{"sighttracepassed", 116},
|
||||
{"physicstrace", 117},
|
||||
{"physicstracenormal", 118},
|
||||
{"playerphysicstrace", 119},
|
||||
{"getgroundposition", 120},
|
||||
{"getmovedelta", 121},
|
||||
{"getangledelta", 122},
|
||||
{"getnorthyaw", 123},
|
||||
{"setnorthyaw", 150},
|
||||
{"setslowmotion", 151},
|
||||
{"randomint", 152},
|
||||
{"randomfloat", 153},
|
||||
{"randomintrange", 154},
|
||||
{"randomfloatrange", 155},
|
||||
{"sin", 156},
|
||||
{"cos", 157},
|
||||
{"tan", 158},
|
||||
{"asin", 159},
|
||||
{"acos", 160},
|
||||
{"atan", 161},
|
||||
{"int", 162},
|
||||
{"float", 163},
|
||||
{"abs", 164},
|
||||
{"min", 165},
|
||||
{"max", 198},
|
||||
{"floor", 199},
|
||||
{"ceil", 200},
|
||||
{"exp", 201},
|
||||
{"log", 202},
|
||||
{"sqrt", 203},
|
||||
{"squared", 204},
|
||||
{"clamp", 205},
|
||||
{"angleclamp", 206},
|
||||
{"angleclamp180", 207},
|
||||
{"vectorfromlinetopoint", 208},
|
||||
{"pointonsegmentnearesttopoint", 209},
|
||||
{"distance", 210},
|
||||
{"distance2d", 211},
|
||||
{"distancesquared", 212},
|
||||
{"length", 213},
|
||||
{"lengthsquared", 214},
|
||||
{"closer", 215},
|
||||
{"vectordot", 216},
|
||||
{"vectornormalize", 246},
|
||||
{"vectortoangles", 247},
|
||||
{"vectortoyaw", 248},
|
||||
{"vectorlerp", 249},
|
||||
{"anglestoup", 250},
|
||||
{"anglestoright", 251},
|
||||
{"anglestoforward", 252},
|
||||
{"combineangles", 253},
|
||||
{"transformmove", 254},
|
||||
{"issubstr", 255},
|
||||
{"isendstr", 256},
|
||||
{"getsubstr", 257},
|
||||
{"tolower", 258},
|
||||
{"strtok", 259},
|
||||
{"stricmp", 260},
|
||||
{"ambientplay", 261},
|
||||
{"ambientstop", 293},
|
||||
{"precachemodel", 294},
|
||||
{"precacheshellshock", 295},
|
||||
{"precacheitem", 296},
|
||||
{"precacheshader", 297},
|
||||
{"precachestring", 298},
|
||||
{"precachemenu", 299},
|
||||
{"precacherumble", 300},
|
||||
{"precachelocationselector", 301},
|
||||
{"precacheleaderboards", 302},
|
||||
{"precacheheadicon", 326},
|
||||
{"loadfx", 303},
|
||||
{"playfx", 304},
|
||||
{"playfxontag", 305},
|
||||
{"stopfxontag", 306},
|
||||
{"playloopedfx", 307},
|
||||
{"spawnfx", 308},
|
||||
{"triggerfx", 309},
|
||||
{"playfxontagforclients", 310},
|
||||
{"physicsexplosionsphere", 346},
|
||||
{"physicsexplosioncylinder", 347},
|
||||
{"physicsjolt", 348},
|
||||
{"physicsjitter", 349},
|
||||
{"setexpfog", 350},
|
||||
{"isexplosivedamagemod", 351},
|
||||
{"radiusdamage", 352},
|
||||
{"setplayerignoreradiusdamage", 353},
|
||||
{"glassradiusdamage", 354},
|
||||
{"earthquake", 355},
|
||||
{"getnumparts", 356},
|
||||
{"getpartname", 386},
|
||||
{"weaponfiretime", 387},
|
||||
{"weaponclipsize", 388},
|
||||
{"weaponisauto", 389},
|
||||
{"weaponissemiauto", 390},
|
||||
{"weaponisboltaction", 391},
|
||||
{"weaponinheritsperks", 392},
|
||||
{"weaponburstcount", 393},
|
||||
{"weapontype", 394},
|
||||
{"weaponclass", 395},
|
||||
{"weaponinventorytype", 437},
|
||||
{"weaponstartammo", 438},
|
||||
{"weaponmaxammo", 439},
|
||||
{"weaponaltweaponname", 440},
|
||||
{"isweaponcliponly", 441},
|
||||
{"isweapondetonationtimed", 442},
|
||||
{"weaponhasthermalscope", 443},
|
||||
{"getvehiclenode", 444},
|
||||
{"getvehiclenodearray", 445},
|
||||
{"getallvehiclenodes", 446},
|
||||
{"getnumvehicles", 447},
|
||||
{"precachevehicle", 448},
|
||||
{"spawnvehicle", 449},
|
||||
{"getarray", 450},
|
||||
{"getspawnerarray", 408},
|
||||
{"playrumbleonposition", 409},
|
||||
{"playrumblelooponposition", 410},
|
||||
{"stopallrumbles", 411},
|
||||
{"soundexists", 412},
|
||||
{"openfile", 413},
|
||||
{"closefile", 414},
|
||||
{"fprintln", 415},
|
||||
{"fprintfields", 416},
|
||||
{"freadln", 417},
|
||||
{"fgetarg", 418},
|
||||
{"setminimap", 419},
|
||||
{"setthermalbodymaterial", 420},
|
||||
{"getarraykeys", 421},
|
||||
{"getfirstarraykey", 422},
|
||||
{"getnextarraykey", 396},
|
||||
{"sortbydistance", 397},
|
||||
{"tablelookup", 398},
|
||||
{"tablelookupbyrow", 399},
|
||||
{"tablelookupistring", 400},
|
||||
{"tablelookupistringbyrow", 401},
|
||||
{"tablelookuprownum", 402},
|
||||
{"getmissileowner", 403},
|
||||
{"magicbullet", 404},
|
||||
{"getweaponflashtagname", 405},
|
||||
{"averagepoint", 406},
|
||||
{"averagenormal", 407},
|
||||
{"getglass", 423},
|
||||
{"getglassarray", 424},
|
||||
{"getglassorigin", 425},
|
||||
{"isglassdestroyed", 426},
|
||||
{"destroyglass", 427},
|
||||
{"deleteglass", 428},
|
||||
{"getentchannelscount", 429},
|
||||
|
||||
// objective
|
||||
{"objective_add", 431},
|
||||
{"objective_delete", 432},
|
||||
{"objective_state", 433},
|
||||
{"objective_icon", 434},
|
||||
{"objective_position", 435},
|
||||
{"objective_current", 436},
|
||||
{"objective_onentity", 357},
|
||||
{"objective_team", 358},
|
||||
{"objective_player", 359},
|
||||
{"objective_playerteam", 360},
|
||||
{"objective_playerenemyteam", 361},
|
||||
};
|
||||
}
|
||||
}
|
8
src/game/scripting/functions.hpp
Normal file
8
src/game/scripting/functions.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
namespace game
|
||||
{
|
||||
namespace scripting
|
||||
{
|
||||
extern std::map<std::string, int> instance_function_map;
|
||||
extern std::map<std::string, int> global_function_map;
|
||||
}
|
||||
}
|
@ -412,6 +412,8 @@ namespace game
|
||||
scr_entref_raw raw;
|
||||
};
|
||||
|
||||
typedef void(__cdecl * scr_call_t)(int entref);
|
||||
|
||||
enum scriptType_e
|
||||
{
|
||||
SCRIPT_NONE = 0,
|
||||
|
@ -77,7 +77,7 @@ void notification::vm_notify_stub(const unsigned int notify_id, const unsigned s
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
scheduler::error(e.what(), 5);
|
||||
scripting::propagate_scripting_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "utils/io.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "game/scripting/functions.hpp"
|
||||
|
||||
utils::hook scripting::start_hook_;
|
||||
utils::hook scripting::stop_hook_;
|
||||
@ -11,6 +12,10 @@ std::mutex scripting::mutex_;
|
||||
std::vector<std::function<void()>> scripting::start_callbacks_;
|
||||
std::vector<std::function<void()>> scripting::stop_callbacks_;
|
||||
|
||||
scripting::entity::entity() : environment_(nullptr), entity_id_(0)
|
||||
{
|
||||
}
|
||||
|
||||
scripting::entity::entity(scripting* environment, const unsigned int entity_id) : environment_(environment),
|
||||
entity_id_(entity_id)
|
||||
{
|
||||
@ -40,6 +45,11 @@ game::native::scr_entref_t scripting::entity::get_entity_reference() const
|
||||
return game::native::Scr_GetEntityIdRef(this->get_entity_id());
|
||||
}
|
||||
|
||||
void scripting::entity::call(const std::string& function, const std::vector<chaiscript::Boxed_Value>& arguments)
|
||||
{
|
||||
scripting::call(function, this->get_entity_id(), arguments);
|
||||
}
|
||||
|
||||
scripting::variable::variable(game::native::VariableValue value) : value_(value)
|
||||
{
|
||||
game::native::AddRefToValue(&value);
|
||||
@ -65,7 +75,7 @@ void scripting::post_start()
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
scheduler::error(e.what(), 5);
|
||||
propagate_scripting_error(e);
|
||||
}
|
||||
});
|
||||
on_stop([this]()
|
||||
@ -105,7 +115,14 @@ void scripting::initialize()
|
||||
{
|
||||
this->chai_ = std::make_unique<chaiscript::ChaiScript>();
|
||||
this->chai_->add(chaiscript::user_type<entity>(), "entity");
|
||||
this->chai_->add(chaiscript::constructor<entity()>(), "entity");
|
||||
this->chai_->add(chaiscript::constructor<entity(const entity&)>(), "entity");
|
||||
this->chai_->add(chaiscript::fun(&entity::on_notify), "onNotify");
|
||||
this->chai_->add(chaiscript::fun(&entity::call), "call");
|
||||
this->chai_->add(chaiscript::fun([](entity& lhs, const entity& rhs) -> entity&
|
||||
{
|
||||
return lhs = rhs;
|
||||
}), "=");
|
||||
|
||||
this->chai_->add(chaiscript::fun([](const std::string& string)
|
||||
{
|
||||
@ -208,6 +225,15 @@ void scripting::on_stop(const std::function<void()>& callback)
|
||||
stop_callbacks_.push_back(callback);
|
||||
}
|
||||
|
||||
void scripting::propagate_scripting_error(const std::exception& e)
|
||||
{
|
||||
printf("\n******* Script execution error *******\n");
|
||||
printf("%s\n", e.what());
|
||||
printf("**************************************\n\n");
|
||||
|
||||
scheduler::error("Script execution error\n(see console for actual details)\n", 5);
|
||||
}
|
||||
|
||||
void scripting::start_execution()
|
||||
{
|
||||
decltype(start_callbacks_) copy;
|
||||
@ -237,5 +263,40 @@ void scripting::stop_execution()
|
||||
}
|
||||
}
|
||||
|
||||
void scripting::call(const std::string& function, const unsigned int entity_id,
|
||||
const std::vector<chaiscript::Boxed_Value>& /*arguments*/)
|
||||
{
|
||||
const int function_index = find_function_index(function);
|
||||
if (function_index < 0)
|
||||
{
|
||||
throw std::runtime_error("No function found for name " + function);
|
||||
}
|
||||
|
||||
const game::native::scr_entref_t entity = function_index > 0x1C7
|
||||
? game::native::Scr_GetEntityIdRef(entity_id)
|
||||
: game::native::scr_entref_t{~0u};
|
||||
|
||||
const auto function_ptr = game::native::Scr_GetFunc(function_index);
|
||||
|
||||
function_ptr(entity.val);
|
||||
}
|
||||
|
||||
int scripting::find_function_index(const std::string& function)
|
||||
{
|
||||
auto function_entry = game::scripting::instance_function_map.find(function);
|
||||
if (function_entry != game::scripting::instance_function_map.end())
|
||||
{
|
||||
return function_entry->second;
|
||||
}
|
||||
|
||||
function_entry = game::scripting::global_function_map.find(function);
|
||||
if (function_entry != game::scripting::global_function_map.end())
|
||||
{
|
||||
return function_entry->second;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
REGISTER_MODULE(scripting)
|
||||
|
@ -10,6 +10,8 @@ public:
|
||||
class entity final
|
||||
{
|
||||
public:
|
||||
entity();
|
||||
entity(const entity& other) = default;
|
||||
entity(scripting* environment, unsigned int entity_id);
|
||||
|
||||
void on_notify(const std::string& event,
|
||||
@ -19,6 +21,8 @@ public:
|
||||
unsigned int get_entity_id() const;
|
||||
game::native::scr_entref_t get_entity_reference() const;
|
||||
|
||||
void call(const std::string& function, const std::vector<chaiscript::Boxed_Value>& arguments);
|
||||
|
||||
private:
|
||||
scripting* environment_;
|
||||
unsigned int entity_id_;
|
||||
@ -52,6 +56,8 @@ public:
|
||||
static void on_start(const std::function<void()>& callback);
|
||||
static void on_stop(const std::function<void()>& callback);
|
||||
|
||||
static void propagate_scripting_error(const std::exception& e);
|
||||
|
||||
private:
|
||||
std::unique_ptr<chaiscript::ChaiScript> chai_;
|
||||
utils::chain<event_listener> event_listeners_;
|
||||
@ -72,4 +78,7 @@ private:
|
||||
|
||||
static void start_execution();
|
||||
static void stop_execution();
|
||||
|
||||
static void call(const std::string& function, unsigned int entity_id, const std::vector<chaiscript::Boxed_Value>& arguments);
|
||||
static int find_function_index(const std::string& function);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user