diff --git a/src/playsim/bots/b_bot.h b/src/playsim/bots/b_bot.h index 2125597ff..2f214bbd9 100644 --- a/src/playsim/bots/b_bot.h +++ b/src/playsim/bots/b_bot.h @@ -71,12 +71,12 @@ enum //Info given to bots when they're spawned. struct botinfo_t { - botinfo_t *next; + botinfo_t *next = nullptr; FString Name; FString Info; - botskill_t skill; - int inuse; - int lastteam; + botskill_t skill = {}; + int inuse = 0; + int lastteam = 0; }; struct BotInfoData diff --git a/src/playsim/bots/b_game.cpp b/src/playsim/bots/b_game.cpp index d770f278e..bec02d6bd 100644 --- a/src/playsim/bots/b_game.cpp +++ b/src/playsim/bots/b_game.cpp @@ -500,8 +500,6 @@ bool FCajunMaster::LoadBots () botinfo_t *newinfo = new botinfo_t; bool gotclass = false; - memset (newinfo, 0, sizeof(*newinfo)); - newinfo->Info = "\\autoaim\\0\\movebob\\.25"; for (;;) diff --git a/src/playsim/fragglescript/t_load.cpp b/src/playsim/fragglescript/t_load.cpp index 8d2b5d6d7..c341f4089 100644 --- a/src/playsim/fragglescript/t_load.cpp +++ b/src/playsim/fragglescript/t_load.cpp @@ -264,7 +264,8 @@ bool FScriptLoader::ParseInfo(MapData * map) } auto th = Level->CreateThinker(); - th->LevelScript->data = copystring(scriptsrc.GetChars()); + th->LevelScript->Data.Resize((unsigned)scriptsrc.Len() + 1); + memcpy(th->LevelScript->Data.Data(), scriptsrc.GetChars(), scriptsrc.Len() + 1); Level->FraggleScriptThinker = th; if (drownflag==-1) drownflag = (Level->maptype != MAPTYPE_DOOM || fsglobal); diff --git a/src/playsim/fragglescript/t_parse.cpp b/src/playsim/fragglescript/t_parse.cpp index 78bfc3aed..a0bd93102 100644 --- a/src/playsim/fragglescript/t_parse.cpp +++ b/src/playsim/fragglescript/t_parse.cpp @@ -709,10 +709,10 @@ void FParser::ErrorMessage(FString msg) int linenum = 0; // find the line number - if(Rover >= Script->data && Rover <= Script->data+Script->len) + if(Rover >= Script->Data.Data() && Rover <= Script->Data.Data() +Script->len) { char *temp; - for(temp = Script->data; tempData.Data(); tempstart_index; + return Data.Data() + sec->start_index; } //========================================================================== @@ -99,7 +99,7 @@ char *DFsScript::SectionStart(const DFsSection *sec) char *DFsScript::SectionEnd(const DFsSection *sec) { - return data + sec->end_index; + return Data.Data() + sec->end_index; } //========================================================================== @@ -110,7 +110,7 @@ char *DFsScript::SectionEnd(const DFsSection *sec) char *DFsScript::SectionLoop(const DFsSection *sec) { - return data + sec->loop_index; + return Data.Data() + sec->loop_index; } //========================================================================== @@ -335,8 +335,8 @@ char *DFsScript::ProcessFindChar(char *datap, char find) void DFsScript::DryRunScript(FLevelLocals *Level) { - char *end = data + len; - char *rover = data; + char *end = Data.Data() + len; + char *rover = Data.Data(); // allocate space for the tokens FParser parse(Level, this); @@ -389,8 +389,8 @@ void DFsScript::DryRunScript(FLevelLocals *Level) void DFsScript::Preprocess(FLevelLocals *Level) { - len = (int)strlen(data); - ProcessFindChar(data, 0); // fill in everything + len = (int)Data.Size() - 1; + ProcessFindChar(Data.Data(), 0); // fill in everything DryRunScript(Level); } diff --git a/src/playsim/fragglescript/t_script.cpp b/src/playsim/fragglescript/t_script.cpp index fd2cbcefc..435c68d31 100644 --- a/src/playsim/fragglescript/t_script.cpp +++ b/src/playsim/fragglescript/t_script.cpp @@ -127,7 +127,6 @@ DFsScript::DFsScript() for(i=0; i data+len) + if(position < Data.Data() || position > Data.Data() +len) { Printf("script %d: trying to continue from point outside script!\n", scriptnum); return; @@ -216,7 +201,7 @@ void DFsScript::ParseScript(char *position, DFraggleThinker *th) try { FParser parse(th->Level, this); - parse.Run(position, data, data + len); + parse.Run(position, Data.Data(), Data.Data() + len); } catch (CFraggleScriptError &err) { @@ -528,7 +513,7 @@ void DFraggleThinker::Tick() next = current->next; // save before freeing // continue the script - current->script->ParseScript (current->script->data + current->save_point, this); + current->script->ParseScript (current->script->Data.Data() + current->save_point, this); // free current->Destroy(); diff --git a/src/playsim/fragglescript/t_script.h b/src/playsim/fragglescript/t_script.h index f21300887..e3d7e9a08 100644 --- a/src/playsim/fragglescript/t_script.h +++ b/src/playsim/fragglescript/t_script.h @@ -303,7 +303,7 @@ class DFsScript : public DObject public: // script data - char *data; + TArray Data; int scriptnum; // this script's number int len; @@ -335,7 +335,6 @@ public: // true or false DFsScript(); - ~DFsScript(); void OnDestroy() override; void Serialize(FSerializer &ar); @@ -354,7 +353,7 @@ public: void ClearSections(); void ClearChildren(); - int MakeIndex(const char *p) { return int(p-data); } + int MakeIndex(const char *p) { return int(p-Data.Data()); } // preprocessor int section_hash(const char *b) { return MakeIndex(b) % SECTIONSLOTS; } diff --git a/src/playsim/fragglescript/t_spec.cpp b/src/playsim/fragglescript/t_spec.cpp index 5361c7c1e..e93732242 100644 --- a/src/playsim/fragglescript/t_spec.cpp +++ b/src/playsim/fragglescript/t_spec.cpp @@ -416,14 +416,14 @@ void FParser::spec_script() datasize = (Section->end_index - Section->start_index - 2); // alloc extra 10 for safety - newscript->data = (char *)malloc(datasize+10); + newscript->Data.Resize(datasize+1); // copy from parent newscript (levelscript) // ignore first char which is { - memcpy(newscript->data, Script->SectionStart(Section) + 1, datasize); + memcpy(newscript->Data.Data(), Script->SectionStart(Section) + 1, datasize); // tack on a 0 to end the string - newscript->data[datasize] = '\0'; + newscript->Data.Data()[datasize] = '\0'; newscript->scriptnum = scriptnum; newscript->parent = Script; // remember parent diff --git a/src/playsim/fragglescript/t_variable.cpp b/src/playsim/fragglescript/t_variable.cpp index c73bf14fc..cc2a558da 100644 --- a/src/playsim/fragglescript/t_variable.cpp +++ b/src/playsim/fragglescript/t_variable.cpp @@ -428,7 +428,7 @@ void DFsScript::ClearVariables(bool complete) char *DFsScript::LabelValue(const svalue_t &v) { - if (v.type == svt_label) return data + v.value.i; + if (v.type == svt_label) return Data.Data() + v.value.i; else return NULL; } diff --git a/src/serializer.cpp b/src/serializer.cpp index cd9b5b8f2..ee6571dff 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -1281,6 +1281,15 @@ FSerializer &Serialize(FSerializer &arc, const char *key, uint32_t &value, uint3 // //========================================================================== +FSerializer& Serialize(FSerializer& arc, const char* key, char& value, char* defval) +{ + int32_t vv = value; + int32_t vvd = defval ? *defval : value - 1; + Serialize(arc, key, vv, &vvd); + value = (int8_t)vv; + return arc; +} + FSerializer &Serialize(FSerializer &arc, const char *key, int8_t &value, int8_t *defval) { int32_t vv = value; diff --git a/src/serializer.h b/src/serializer.h index 71f8f76e1..432ee58bb 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -186,6 +186,7 @@ public: int mErrors = 0; }; +FSerializer& Serialize(FSerializer& arc, const char* key, char& value, char* defval); FSerializer &Serialize(FSerializer &arc, const char *key, bool &value, bool *defval); FSerializer &Serialize(FSerializer &arc, const char *key, int64_t &value, int64_t *defval); FSerializer &Serialize(FSerializer &arc, const char *key, uint64_t &value, uint64_t *defval);