-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bit0r1n
committed
Aug 24, 2020
0 parents
commit 2f304f1
Showing
12 changed files
with
991 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Compiled module | ||
Release | ||
|
||
# Visual Studio folder | ||
.vs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include "GDAModule.h" | ||
#include "ws.hpp" | ||
#include "Settings.h" | ||
#include "imgui.h" | ||
#include "imguiex.h" | ||
#include "Util.h" | ||
|
||
using easywsclient::WebSocket; | ||
using namespace std; | ||
|
||
static char message[2048]; | ||
static int online = 0; | ||
static vector<string> messages; | ||
static bool _connection = false; | ||
static WebSocket* ws = nullptr; | ||
|
||
void pingServer() { | ||
if (ws && ws->getReadyState() == WebSocket::OPEN) { | ||
ws->sendPing(); | ||
} | ||
} | ||
|
||
CALLBACK_F(void, handle_message, const string& msg) { | ||
string str = msg.c_str(); | ||
if (str.find("online::") == 0) { | ||
str.erase(0, 8); | ||
online = std::stoi(str); | ||
return; | ||
} | ||
else if (str == "clearClient") { | ||
messages.clear(); | ||
return; | ||
} | ||
messages.push_back(msg); | ||
} | ||
|
||
void connectToChat() { | ||
if (_connection) { | ||
if (!ws || ws->getReadyState() != WebSocket::OPEN) { | ||
messages.push_back("[GDChat] Connecting.."); | ||
ws = WebSocket::from_url(moduleSettings._chatUrl); | ||
} | ||
else if (ws->getReadyState() != WebSocket::CLOSED) { | ||
ws->poll(); | ||
ws->dispatch(handle_message); | ||
} | ||
} | ||
} | ||
|
||
CALLBACK_F(void, update_ws) { | ||
Util::timer_start(pingServer, 20000); | ||
_connection = true; | ||
connectToChat(); | ||
Util::timer_start(connectToChat, 5000); | ||
} | ||
|
||
CALLBACK_F(void, OnModuleDraw, GDA_MODULE* pModule) { | ||
if (moduleSettings._show) { | ||
if (!moduleSettings._settingsLoaded) { | ||
moduleSettings._settingsLoaded = true; | ||
ImGui::SetNextWindowCollapsed(moduleSettings._collapsed, ImGuiCond_Once); | ||
ImGui::SetNextWindowPos(ImVec2(moduleSettings._pos.x, moduleSettings._pos.y), ImGuiCond_Once); | ||
ImGui::SetNextWindowSize(ImVec2(moduleSettings._size.x, moduleSettings._size.y), ImGuiCond_Once); | ||
} | ||
ImGui::SetNextWindowSizeConstraints(ImVec2(400, 300), ImVec2(400, 600)); | ||
|
||
if (ImGuiEx::BeginWithAStyle(moduleSettings._collapsed, pModule->getName(), &moduleSettings._show)) { | ||
ImGui::SetNextWindowContentWidth(moduleSettings._size.x / 0.9); | ||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f); | ||
if (ImGui::BeginChild("chat", ImVec2(0, moduleSettings._size.y - 60), true, ImGuiWindowFlags_None)) { | ||
if (messages.size() == 0) | ||
ImGui::TextDisabled("Chat is empty"); | ||
else for (int i = 0; i < messages.size(); ++i) { | ||
ImGuiEx::TextMulticolor(messages[i].c_str()); | ||
if (i != messages.size()) ImGui::Separator(); | ||
} | ||
} | ||
ImGui::EndChild(); | ||
ImGui::InputText("##inputchat", message, 2048); | ||
ImGui::SameLine(); | ||
if (ImGui::Button(" > ") || ImGuiEx::IsKeysReleased(VK_RETURN)) { | ||
if (ws != nullptr && ws->getReadyState() == WebSocket::OPEN) { | ||
if (strlen(message) > 0) { | ||
ws->send(message); | ||
memset(message, 0, 2048); | ||
} | ||
} | ||
} | ||
ImGui::SameLine(); | ||
if (ws != nullptr && ws->getReadyState() == WebSocket::OPEN) | ||
ImGuiEx::TextMulticolor("{32a852}Online: %d{}", online); | ||
else | ||
ImGuiEx::TextMulticolor("{cc0000}Offline{}"); | ||
} | ||
|
||
moduleSettings._collapsed = ImGui::IsWindowCollapsed(); | ||
auto& pos = ImGui::GetWindowPos(); | ||
moduleSettings._pos.x = pos.x; | ||
moduleSettings._pos.y = pos.y; | ||
auto& size = ImGui::GetWindowSize(); | ||
moduleSettings._size.x = size.x; | ||
moduleSettings._size.y = size.y; | ||
|
||
ImGui::End(); | ||
} | ||
} | ||
|
||
GDA_MODULE_CALLBACK(GDA_MODULE* pModule) { | ||
memset(message, 0, 2048); | ||
thread(&update_ws).detach(); | ||
|
||
pModule->setName("GDChat"); | ||
pModule->setAuthor("bit0r1n"); | ||
pModule->registerClickCallback(CALLBACK_L(void, GDA_MODULE * pModule) { | ||
if (moduleSettings._show ^= true) | ||
ImGui::SetNextWindowFocus(); | ||
}); | ||
pModule->registerDrawCallback(OnModuleDraw); | ||
pModule->setClickName(" open "); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# GD Chat | ||
Module for [GD Addon](https://github.com/Keenlos/GDAddonSDK) that creates real-time chat | ||
|
||
Used: | ||
* [GD Addon SDK](https://github.com/Keenlos/GDAddonSDK) | ||
* [easywsclient](https://github.com/dhbaird/easywsclient) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "Settings.h" | ||
|
||
#include "cocos2d_x/DS_Dictionary.h" | ||
|
||
ModuleSettings moduleSettings; | ||
|
||
ModuleSettings::ModuleSettings() { | ||
_settingsLoaded = false; | ||
|
||
_show = _collapsed = false; | ||
|
||
_pos = cocos2d::CCPoint(0, 0); | ||
|
||
_size = cocos2d::CCPoint(0, 0); | ||
|
||
_chatUrl = "WebSocket link"; | ||
|
||
this->load(); | ||
} | ||
|
||
ModuleSettings::~ModuleSettings() { | ||
this->save(); | ||
} | ||
|
||
void ModuleSettings::fixSettings() { } | ||
|
||
void ModuleSettings::save() { | ||
DS_Dictionary _dict; | ||
this->fixSettings(); | ||
_dict.setBoolForKey("show", _show); | ||
_dict.setBoolForKey("collapsed", _collapsed); | ||
_dict.setVec2ForKey("pos", _pos); | ||
_dict.setVec2ForKey("size", _size); | ||
_dict.setStringForKey("chatUrl", _chatUrl); | ||
|
||
_dict.saveRootSubDictToCompressedFile("GDChat.dat"); | ||
} | ||
|
||
void ModuleSettings::load() { | ||
DS_Dictionary _dict; | ||
_dict.loadRootSubDictFromCompressedFile("GDChat.dat"); | ||
|
||
_show = _dict.getBoolForKey("show"); | ||
_collapsed = _dict.getBoolForKey("collapsed"); | ||
_pos = _dict.getVec2ForKey("pos"); | ||
_size = _dict.getVec2ForKey("size"); | ||
_chatUrl = _dict.getStringForKey("chatUrl"); | ||
this->fixSettings(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "cocos2d_x/CCGeometry.h" | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
struct ModuleSettings | ||
{ | ||
bool _settingsLoaded; | ||
string _chatUrl; | ||
bool _show, _collapsed; | ||
cocos2d::CCPoint _pos, _size; | ||
ModuleSettings(); | ||
~ModuleSettings(); | ||
|
||
private: | ||
void fixSettings(); | ||
void save(); | ||
void load(); | ||
}; | ||
|
||
extern ModuleSettings moduleSettings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
#include <functional> | ||
#include <thread> | ||
class Util | ||
{ | ||
public: | ||
static void timer_start(std::function<void(void)> func, unsigned int interval) | ||
{ | ||
std::thread([func, interval]() { | ||
while (true) | ||
{ | ||
func(); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(interval)); | ||
} | ||
}).detach(); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27703.2042 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chat", "chat.vcxproj", "{D8BFE6C7-D233-4E9A-8DB3-459116F0CB3F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{D8BFE6C7-D233-4E9A-8DB3-459116F0CB3F}.Release|x86.ActiveCfg = Release|Win32 | ||
{D8BFE6C7-D233-4E9A-8DB3-459116F0CB3F}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {C3852A03-D542-4A49-A572-5F950A048DBD} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="GDAModule.cpp" /> | ||
<ClCompile Include="Settings.cpp" /> | ||
<ClCompile Include="ws.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="Settings.h" /> | ||
<ClInclude Include="Util.h" /> | ||
<ClInclude Include="ws.hpp" /> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>15.0</VCProjectVersion> | ||
<ProjectGuid>{D8BFE6C7-D233-4E9A-8DB3-459116F0CB3F}</ProjectGuid> | ||
<Keyword>Win32Proj</Keyword> | ||
<RootNamespace>chat</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<WholeProgramOptimization>false</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
<WarningLevel>Level1</WarningLevel> | ||
<PreprocessorDefinitions>WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN=1;NDEBUG;VC_EXTRALEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>false</ConformanceMode> | ||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\SDK_CPP\;$(ProjectDir)..\..\SDK_CPP\GDAPI;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||
<RuntimeTypeInfo>true</RuntimeTypeInfo> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<OpenMPSupport>false</OpenMPSupport> | ||
<EnableModules>false</EnableModules> | ||
<ExceptionHandling>false</ExceptionHandling> | ||
<LanguageStandard>stdcpp17</LanguageStandard> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<AdditionalDependencies>GDAddon.lib;opengl32.lib;libcocos2d.lib;libExtensions.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
<AdditionalLibraryDirectories>$(ProjectDir)..\..\SDK_CPP\lib\win32;$(ProjectDir)..\..\SDK_CPP\GDAPI\lib\win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
<OutputFile>$(ProjectDir)..\..\..\..\Addon\Modules\$(TargetName)$(TargetExt)</OutputFile> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Source Files"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Resource Files"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="GDAModule.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="Settings.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="ws.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="ws.hpp"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="Settings.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="Util.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<LocalDebuggerCommand>$(ProjectDir)..\..\..\..\GeometryDash.exe</LocalDebuggerCommand> | ||
<LocalDebuggerWorkingDirectory>$(ProjectDir)..\..\..\..\</LocalDebuggerWorkingDirectory> | ||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> | ||
<LocalDebuggerAmpDefaultAccelerator> </LocalDebuggerAmpDefaultAccelerator> | ||
</PropertyGroup> | ||
</Project> |
Oops, something went wrong.