-
Notifications
You must be signed in to change notification settings - Fork 7
/
SMJS_EntKeyValues.cpp
64 lines (44 loc) · 1.91 KB
/
SMJS_EntKeyValues.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "SMJS_EntKeyValues.h"
#include "SMJS_Entity.h"
#include "SMJS_Plugin.h"
#include "modules/MEntities.h"
#include "SMJS_Interfaces.h"
#include <conio.h>
WRAPPED_CLS_CPP(SMJS_EntKeyValues, SMJS_BaseWrapped)
SMJS_EntKeyValues::SMJS_EntKeyValues(){
}
SMJS_EntKeyValues::~SMJS_EntKeyValues(){
}
void SMJS_EntKeyValues::OnWrapperAttached(SMJS_Plugin *plugin, v8::Persistent<v8::Value> wrapper){
SMJS_BaseWrapped::OnWrapperAttached(plugin, wrapper);
}
v8::Handle<v8::Value> SMJS_EntKeyValues::GetKeyValue(v8::Local<v8::String> prop, const v8::AccessorInfo &info){
Local<Value> _intfld = info.This()->GetInternalField(0);
SMJS_EntKeyValues *self = dynamic_cast<SMJS_EntKeyValues*>((SMJS_BaseWrapped*)Handle<External>::Cast(_intfld)->Value());
// This whole function is a workaround
unsigned char tmp[128];
tmp[0] = tmp[1] = tmp[2] = tmp[3] = 0;
v8::String::AsciiValue propStr(prop);
if(!serverTools->GetKeyValue(self->entWrapper->ent, *propStr, (char*)tmp, sizeof(tmp))){
return v8::Undefined();
}
if(tmp[1] != 0 && tmp[2] != 0 && tmp[3] != 0){
auto value = *((char**) tmp);
return v8::String::New(value);
}
return v8::Undefined();
}
v8::Handle<v8::Value> SMJS_EntKeyValues::SetKeyValue(v8::Local<v8::String> prop, v8::Local<v8::Value> value, const v8::AccessorInfo &info){
Local<Value> _intfld = info.This()->GetInternalField(0);
SMJS_EntKeyValues *self = dynamic_cast<SMJS_EntKeyValues*>((SMJS_BaseWrapped*)Handle<External>::Cast(_intfld)->Value());
v8::String::AsciiValue propStr(prop);
if(value->IsString()){
v8::String::AsciiValue valueStr(value->ToString());
serverTools->SetKeyValue(self->entWrapper->ent, *propStr, *valueStr);
return value;
}else if(value->IsNumber()){
serverTools->SetKeyValue(self->entWrapper->ent, *propStr, (float) value->NumberValue());
return value;
}
THROW("Entity KeyValues can only be strings or floats, for other types, vector for example, use: \"0.0 0.0 0.0\"");
}