mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 13:47:58 +03:00
Fixed issue with case-sensitive variables.
normal/return commands are case-insensitive getter/setter commands are case-sensitive
This commit is contained in:
parent
48fc5a72b8
commit
3cd5acf3aa
4 changed files with 57 additions and 42 deletions
|
@ -541,7 +541,10 @@ void ScriptMaster::InitConstStrings(void)
|
|||
eventDef = en.CurrentValue();
|
||||
eventnum = (*en.CurrentKey())->eventnum;
|
||||
str command = eventDef->command.c_str();
|
||||
command.tolower();
|
||||
|
||||
if (eventDef->type == EV_NORMAL || eventDef->type == EV_RETURN) {
|
||||
command.tolower();
|
||||
}
|
||||
|
||||
name = AddString(command);
|
||||
|
||||
|
|
|
@ -399,8 +399,14 @@ int HashCode<command_t>(const command_t& key)
|
|||
const char *p;
|
||||
int hash = 0;
|
||||
|
||||
for (p = key.command; *p; p++) {
|
||||
hash = tolower(*p) + 31 * hash;
|
||||
if (key.type == EV_NORMAL || key.type == EV_RETURN) {
|
||||
for (p = key.command; *p; p++) {
|
||||
hash = tolower(*p) + 31 * hash;
|
||||
}
|
||||
} else {
|
||||
for (p = key.command; *p; p++) {
|
||||
hash = *p + 31 * hash;
|
||||
}
|
||||
}
|
||||
|
||||
return hash;
|
||||
|
@ -1424,7 +1430,6 @@ FindSetterEventNum
|
|||
*/
|
||||
unsigned int Event::FindSetterEventNum(str s)
|
||||
{
|
||||
s.tolower();
|
||||
return FindSetterEventNum(Director.AddString(s));
|
||||
}
|
||||
|
||||
|
@ -1435,7 +1440,6 @@ FindGetterEventNum
|
|||
*/
|
||||
unsigned int Event::FindGetterEventNum(str s)
|
||||
{
|
||||
s.tolower();
|
||||
return FindGetterEventNum(Director.AddString(s));
|
||||
}
|
||||
|
||||
|
@ -1452,8 +1456,10 @@ int Event::GetEventWithFlags(str name, int flags, uchar type)
|
|||
con_map<const_str, unsigned int> *cmdList;
|
||||
|
||||
if (type == EV_NORMAL) {
|
||||
name.tolower();
|
||||
cmdList = &normalCommandList;
|
||||
} else if (type == EV_RETURN) {
|
||||
name.tolower();
|
||||
cmdList = &returnCommandList;
|
||||
} else if (type == EV_GETTER) {
|
||||
cmdList = &getterCommandList;
|
||||
|
@ -1463,8 +1469,6 @@ int Event::GetEventWithFlags(str name, int flags, uchar type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
name.tolower();
|
||||
|
||||
index = cmdList->find(Director.GetString(name));
|
||||
|
||||
if (!index || !(GetEventFlags(*index) & flags)) {
|
||||
|
@ -4352,3 +4356,24 @@ command_t::command_t(const char *name, byte t)
|
|||
: command(name)
|
||||
, type(t)
|
||||
{}
|
||||
|
||||
bool operator==(const char* name, const command_t& command)
|
||||
{
|
||||
if (command.type == EV_NORMAL || command.type == EV_RETURN) {
|
||||
return !str::icmp(name, command.command);
|
||||
} else {
|
||||
return !str::cmp(name, command.command);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_SCRIPT_ENGINE
|
||||
bool operator==(const command_t& cmd1, const command_t& cmd2)
|
||||
{
|
||||
return (!str::icmp(cmd1.command, cmd2.command) && (cmd2.type == (uchar)-1 || cmd2.type == cmd1.type));
|
||||
}
|
||||
#else
|
||||
bool operator==(const command_t& cmd1, const command_t& cmd2)
|
||||
{
|
||||
return (!str::icmp(cmd1.command, cmd2.command));
|
||||
}
|
||||
#endif
|
|
@ -242,23 +242,6 @@ public:
|
|||
friend bool operator==(const command_t& cmd1, const command_t& cmd2);
|
||||
};
|
||||
|
||||
inline bool operator==(const char *name, const command_t& command)
|
||||
{
|
||||
return !str::icmp(name, command.command);
|
||||
}
|
||||
|
||||
#ifdef WITH_SCRIPT_ENGINE
|
||||
inline bool operator==(const command_t& cmd1, const command_t& cmd2)
|
||||
{
|
||||
return (!str::icmp(cmd1.command, cmd2.command) && (cmd2.type == (uchar)-1 || cmd2.type == cmd1.type));
|
||||
}
|
||||
#else
|
||||
inline bool operator==(const command_t& cmd1, const command_t& cmd2)
|
||||
{
|
||||
return (!str::icmp(cmd1.command, cmd2.command));
|
||||
}
|
||||
#endif
|
||||
|
||||
class Event : public Class
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -252,7 +252,7 @@ void ScriptCompiler::EmitAssignmentStatement(sval_t lhs, unsigned int sourcePos)
|
|||
unsigned int index;
|
||||
sval_t listener_val;
|
||||
const char *name = lhs.node[2].stringValue;
|
||||
str name_lowered;
|
||||
//str name_lowered;
|
||||
|
||||
if (lhs.node[0].type != ENUM_field) {
|
||||
if (lhs.node[0].type == ENUM_array_expr) {
|
||||
|
@ -265,10 +265,10 @@ void ScriptCompiler::EmitAssignmentStatement(sval_t lhs, unsigned int sourcePos)
|
|||
return;
|
||||
}
|
||||
|
||||
name_lowered = name;
|
||||
name_lowered.tolower();
|
||||
index = Director.AddString(name_lowered);
|
||||
eventnum = Event::FindSetterEventNum(name_lowered);
|
||||
//name_lowered = name;
|
||||
//name_lowered.tolower();
|
||||
index = Director.AddString(name);
|
||||
eventnum = Event::FindSetterEventNum(name);
|
||||
|
||||
listener_val = lhs.node[1];
|
||||
|
||||
|
@ -477,7 +477,8 @@ void ScriptCompiler::EmitField(sval_t listener_val, sval_t field_val, unsigned i
|
|||
unsigned int eventnum = 0;
|
||||
unsigned int index = -1;
|
||||
unsigned int prev_index;
|
||||
str name_lowered;
|
||||
const char* name;
|
||||
//str name_lowered;
|
||||
|
||||
/*
|
||||
if (field_val.node[0].stringValue) {
|
||||
|
@ -494,10 +495,11 @@ void ScriptCompiler::EmitField(sval_t listener_val, sval_t field_val, unsigned i
|
|||
}
|
||||
*/
|
||||
|
||||
name_lowered = field_val.stringValue;
|
||||
name_lowered.tolower();
|
||||
index = Director.AddString(name_lowered);
|
||||
eventnum = Event::FindGetterEventNum(name_lowered);
|
||||
name = field_val.stringValue;
|
||||
//name_lowered = name;
|
||||
//name_lowered.tolower();
|
||||
index = Director.AddString(name);
|
||||
eventnum = Event::FindGetterEventNum(name);
|
||||
|
||||
prev_index = GetOpcodeValue<unsigned int>(sizeof(unsigned int), sizeof(unsigned int));
|
||||
|
||||
|
@ -918,10 +920,10 @@ void ScriptCompiler::EmitParameter(sval_t lhs, unsigned int sourcePos)
|
|||
|
||||
sval_u listener_val = lhs.node[1];
|
||||
const char *name = lhs.node[2].stringValue;
|
||||
name_lowered = name;
|
||||
name_lowered.tolower();
|
||||
//name_lowered = name;
|
||||
//name_lowered.tolower();
|
||||
|
||||
int eventnum = Event::FindSetterEventNum(name_lowered);
|
||||
int eventnum = Event::FindSetterEventNum(name);
|
||||
|
||||
if (listener_val.node[0].type != ENUM_listener
|
||||
|| (eventnum && BuiltinWriteVariable(sourcePos, listener_val.node[1].byteValue, eventnum))) {
|
||||
|
@ -930,7 +932,7 @@ void ScriptCompiler::EmitParameter(sval_t lhs, unsigned int sourcePos)
|
|||
EmitOpcode(OP_STORE_PARAM, sourcePos);
|
||||
EmitOpcode(OP_LOAD_GAME_VAR + listener_val.node[1].byteValue, sourcePos);
|
||||
|
||||
unsigned int index = Director.AddString(name_lowered);
|
||||
unsigned int index = Director.AddString(name);
|
||||
EmitOpcodeValue(index, sizeof(unsigned int));
|
||||
}
|
||||
}
|
||||
|
@ -956,7 +958,8 @@ int ScriptCompiler::EmitParameterList(sval_t event_parameter_list)
|
|||
void ScriptCompiler::EmitRef(sval_t val, unsigned int sourcePos)
|
||||
{
|
||||
unsigned int index;
|
||||
str name_lowered;
|
||||
const char* name;
|
||||
//str name_lowered;
|
||||
|
||||
if (val.node[0].type != ENUM_field) {
|
||||
if (val.node[0].type == ENUM_array_expr) {
|
||||
|
@ -969,9 +972,10 @@ void ScriptCompiler::EmitRef(sval_t val, unsigned int sourcePos)
|
|||
return;
|
||||
}
|
||||
|
||||
name_lowered = val.node[2].stringValue;
|
||||
name_lowered.tolower();
|
||||
index = Director.AddString(name_lowered);
|
||||
name = val.node[2].stringValue;
|
||||
//name_lowered = name;
|
||||
//name_lowered.tolower();
|
||||
index = Director.AddString(name);
|
||||
|
||||
EmitValue(val.node[1]);
|
||||
EmitOpcode(OP_STORE_FIELD_REF, sourcePos);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue