From e7d3acc35d44f9a60779e1ac48cdd4a74f5d20e0 Mon Sep 17 00:00:00 2001 From: Conan Truong Date: Sun, 8 Dec 2024 10:51:34 -0800 Subject: [PATCH 1/3] Fixed crash on integer modulo with 0 --- source/GcLib/gstd/Script/ScriptFunction.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/GcLib/gstd/Script/ScriptFunction.cpp b/source/GcLib/gstd/Script/ScriptFunction.cpp index c4f75f38..c1cbd4f0 100644 --- a/source/GcLib/gstd/Script/ScriptFunction.cpp +++ b/source/GcLib/gstd/Script/ScriptFunction.cpp @@ -585,8 +585,12 @@ namespace gstd { else { if (_type_check_two_any(argv[0].get_type(), argv[1].get_type(), type_data::tk_float)) return value(script_type_manager::get_float_type(), _fmod2(argv[0].as_float(), argv[1].as_float())); - else - return value(script_type_manager::get_int_type(), _mod2(argv[0].as_int(), argv[1].as_int())); + else { + int64_t deno = argv[1].as_int(); + if (deno == 0) + throw std::string("Invalid operation: integer modulo by zero.\r\n"); + return value(script_type_manager::get_int_type(), _mod2(argv[0].as_int(), deno)); + } } } SCRIPT_DECLARE_OP(remainder_); From 23c148025868568136549887146ed58e27be2b7f Mon Sep 17 00:00:00 2001 From: Conan Truong Date: Sun, 8 Dec 2024 11:10:11 -0800 Subject: [PATCH 2/3] Fixed bugs regarding overloading variable with function --- source/GcLib/gstd/Script/Parser.cpp | 53 +++++++++++++++-------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/source/GcLib/gstd/Script/Parser.cpp b/source/GcLib/gstd/Script/Parser.cpp index 89022d60..f88e4a6f 100644 --- a/source/GcLib/gstd/Script/Parser.cpp +++ b/source/GcLib/gstd/Script/Parser.cpp @@ -189,17 +189,15 @@ parser::symbol* parser::scope_t::singular_insert(const std::string& name, const if (exists) { symbol* sPrev = &(itr.first->second); - //Check if the symbol can be overloaded - if (!sPrev->bAllowOverload && sPrev->level > 0) { - std::string error = ""; - if (!sPrev->bVariable) { //Scripter attempted to overload a default function - error = StringUtility::Format("\"%s\": Function cannot be overloaded.", - name.c_str()); - } - else { //Scripter duplicated parameter/variable name - error = StringUtility::Format("\"%s\": Duplicated parameter name.", - name.c_str()); - } + if (sPrev->bVariable) { //Scripter duplicated parameter/variable name + std::string error = StringUtility::Format("\"%s\": Duplicated parameter name.", + name.c_str()); + parser_assert(false, error); + } + else if (!sPrev->bAllowOverload && sPrev->level > 0) { + //Scripter attempted to overload a default function + std::string error = StringUtility::Format("\"%s\": Function cannot be overloaded.", + name.c_str()); parser_assert(false, error); } else { @@ -634,23 +632,28 @@ int parser::scan_current_scope(parser_state_t* state, int level, int initVar, co if (dup) { //Woohoo for detailed error messages. std::string typeSub; - switch (dup->sub->kind) { - case block_kind::bk_function: - typeSub = "function"; - break; - case block_kind::bk_microthread: - typeSub = "task"; - break; - case block_kind::bk_sub: - typeSub = "sub or an \'@\' block"; - break; - default: - typeSub = "block"; - break; + if (dup->bVariable) { + typeSub = "variable"; + } + else { + switch (dup->sub->kind) { + case block_kind::bk_function: + typeSub = "function"; + break; + case block_kind::bk_microthread: + typeSub = "task"; + break; + case block_kind::bk_sub: + typeSub = "sub or an \'@\' block"; + break; + default: + typeSub = "block"; + break; + } } std::string error; - if (dup->bAllowOverload && countArgs >= 0) { + if (dup->bVariable || (dup->bAllowOverload && countArgs >= 0)) { error = "A " + typeSub; error += StringUtility::Format(" of the same name was already defined " "in the current scope: \'%s\'\r\n", name.c_str()); From 2e1bf236a49b9605786dee6efc31aeb3de8cf67a Mon Sep 17 00:00:00 2001 From: Conan Truong Date: Sun, 8 Dec 2024 23:38:20 -0800 Subject: [PATCH 3/3] Fixed seek not working if sound is stopped and resume enabled --- source/GcLib/directx/DirectSound.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/GcLib/directx/DirectSound.cpp b/source/GcLib/directx/DirectSound.cpp index 9b95af98..59386764 100644 --- a/source/GcLib/directx/DirectSound.cpp +++ b/source/GcLib/directx/DirectSound.cpp @@ -737,7 +737,7 @@ SoundPlayer::SoundPlayer() { playStyle_.bLoop_ = false; playStyle_.timeLoopStart_ = 0; playStyle_.timeLoopEnd_ = 0; - playStyle_.timeStart_ = 0; + playStyle_.timeStart_ = -1; playStyle_.bResume_ = false; bDelete_ = false; @@ -1141,11 +1141,11 @@ bool SoundStreamingPlayer::Play() { SetFade(0); bStreamOver_ = false; - if (!bPause_ || !playStyle_.bResume_) { - this->Seek(playStyle_.timeStart_); + if (!bPause_ || !playStyle_.bResume_ || playStyle_.timeStart_ >= 0) { + this->Seek(playStyle_.timeStart_ >= 0 ? playStyle_.timeStart_ : 0); pDirectSoundBuffer_->SetCurrentPosition(0); } - playStyle_.timeStart_ = 0; + playStyle_.timeStart_ = -1; for (size_t iEvent = 0; iEvent < 3; ++iEvent) ::ResetEvent(hEvent_[iEvent]); @@ -1370,10 +1370,10 @@ bool SoundPlayerWave::Play() { if (playStyle_.bLoop_) dwFlags = DSBPLAY_LOOPING; - if (!bPause_ || !playStyle_.bResume_) { - this->Seek(playStyle_.timeStart_); + if (!bPause_ || !playStyle_.bResume_ || playStyle_.timeStart_ >= 0) { + this->Seek(playStyle_.timeStart_ >= 0 ? playStyle_.timeStart_ : 0); } - playStyle_.timeStart_ = 0; + playStyle_.timeStart_ = -1; HRESULT hr = pDirectSoundBuffer_->Play(0, 0, dwFlags); if (hr == DSERR_BUFFERLOST) {