Skip to content
This repository has been archived by the owner on Nov 17, 2024. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Revert "Update host.cpp"

This reverts commit e414c95d9bb732488085b43020ed98988cdb0a7b.

Reapply "Update host.cpp"

This reverts commit b9c986c136963ba00908a1e472b1d568dae68989.

Revert "Update host.cpp"

This reverts commit e414c95d9bb732488085b43020ed98988cdb0a7b.
  • Loading branch information
HIllya51 committed May 12, 2024
1 parent c6fb895 commit 9d24674
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion LunaHost/GUI/LunaHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ bool LunaHost::on_text_recv(TextThread& thread, std::wstring& output){
if(currentselect==thread.handle){
showtext(output,false);
}
output+=L'\n';
return true;
}
void LunaHost::on_thread_create(TextThread& thread){
Expand Down
7 changes: 1 addition & 6 deletions LunaHost/LunaHostDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ C_LUNA_API void Luna_Start(ProcessEvent Connect, ProcessEvent Disconnect, Thread
[=](TextThread &thread, std::wstring &output)
{
XXXX
if(Output(hookcode, name, thread.tp, output.c_str()))
{
output+=L'\n';
return true;
}
else return false;
return Output(hookcode, name, thread.tp, output.c_str());
},
[=](std::wstring &output)
{
Expand Down
23 changes: 13 additions & 10 deletions LunaHost/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ namespace
Host::ConsoleHandler OnConsole=0;
Host::HookInsertHandler HookInsert=0;
Host::EmbedCallback embedcallback=0;
bool CreateThread(const ThreadParam& tp, const HookParam& hp,std::optional<std::wstring> name){
auto thread = textThreadsByParams->find(tp);
if (thread == textThreadsByParams->end())
{
try { thread = textThreadsByParams->try_emplace(tp, tp, hp ,name ).first; }
catch (std::out_of_range) { return false; } // probably garbage data in pipe, try again
OnCreate(thread->second);
}
return true;
}
void RemoveThreads(std::function<bool(ThreadParam)> removeIf)
{
std::vector<TextThread*> threadsToRemove;
Expand Down Expand Up @@ -158,14 +168,9 @@ namespace
auto data=(TextOutput_T*)buffer;
auto length= bytesRead - sizeof(TextOutput_T);
auto tp = data->tp;
auto textThreadsByParams = ::textThreadsByParams.Acquire();
if(!CreateThread(tp,processRecordsByIds->at(tp.processId).GetHook(tp.addr).hp,{}))
continue;
auto thread = textThreadsByParams->find(tp);
if (thread == textThreadsByParams->end())
{
try { thread = textThreadsByParams->try_emplace(tp, tp, processRecordsByIds->at(tp.processId).GetHook(tp.addr).hp).first; }
catch (std::out_of_range) { continue; } // probably garbage data in pipe, try again
OnCreate(thread->second);
}
thread->second.hp.type=data->type;
thread->second.Push(data->data, length);

Expand Down Expand Up @@ -204,10 +209,8 @@ namespace Host
OnDestroy = [=](TextThread& thread) {thread.Stop(); {std::lock_guard _(syncmutex); Destroy(thread);} };
TextThread::Output = [=](auto &&...args){std::lock_guard _(syncmutex);return Output(args...);};

textThreadsByParams->try_emplace(console, console, HookParam{}, CONSOLE);

if(createconsole){
OnCreate(GetThread(console));
CreateThread(console,HookParam{},CONSOLE);
Host::AddConsoleOutput(ProjectHomePage);
}

Expand Down
2 changes: 1 addition & 1 deletion LunaHost/textthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void TextThread::Flush()
{
totalSize += sentence.size();
sentence.erase(std::remove(sentence.begin(), sentence.end(), 0), sentence.end());
if (Output(*this, sentence)) storage->append(sentence);
if (Output(*this, sentence)) storage->append(sentence+L"\n");
}

std::scoped_lock lock(bufferMutex);
Expand Down

0 comments on commit 9d24674

Please sign in to comment.