Skip to content

Commit 14522d8

Browse files
committed
Just dumping the project here, have fun.
1 parent 37f1797 commit 14522d8

File tree

6 files changed

+273
-1
lines changed

6 files changed

+273
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
# StepmanSocketLights
2-
Lights data on socket for Stepmania/OpenITG/NotITG
2+
Lights data on UDP socket for StepMania/OpenITG/NotITG
3+
4+
Used Visual Studio 2017, should compile as-is.
5+
6+
Just drop the resulting `parallel_lights_io.dll` in the `Program` folder of StepMania.
7+
Remember to set `LightsDriver=Parallel` in `StepMania.ini`.
8+
9+
You also need a `socket_lights.txt` in the `Program` folder.
10+
Default values are:
11+
```
12+
127.0.0.1
13+
27015
14+
```
15+
16+
Packet contains three bytes followed by a null byte.
17+
The bits set on those three bytes are exactly the same as on the old parallel lights driver.

StepmanSocketLights.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26228.4
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "parallel_lights_io", "parallel_lights_io\parallel_lights_io.vcxproj", "{259C23B4-984C-44A2-8515-74D41AA581F6}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x86 = Debug|x86
11+
Release|x86 = Release|x86
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{259C23B4-984C-44A2-8515-74D41AA581F6}.Debug|x86.ActiveCfg = Release|Win32
15+
{259C23B4-984C-44A2-8515-74D41AA581F6}.Debug|x86.Build.0 = Release|Win32
16+
{259C23B4-984C-44A2-8515-74D41AA581F6}.Release|x86.ActiveCfg = Release|Win32
17+
{259C23B4-984C-44A2-8515-74D41AA581F6}.Release|x86.Build.0 = Release|Win32
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

parallel_lights_io/Main.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#define WIN32_LEAN_AND_MEAN
2+
#define _WINSOCK_DEPRECATED_NO_WARNINGS
3+
4+
#include "Main.h"
5+
#include <fstream>
6+
#include <string>
7+
8+
#include <Windows.h>
9+
#include <winsock2.h>
10+
#include <Ws2tcpip.h>
11+
#pragma comment(lib,"WS2_32")
12+
13+
14+
char Lights[4] = { 0,0,0,0 };
15+
bool socketAlive = false;
16+
bool dataChanged = false;
17+
SOCKET SendSocket = INVALID_SOCKET;
18+
sockaddr_in RecvAddr;
19+
20+
std::string ExePath() {
21+
char buffer[MAX_PATH];
22+
GetModuleFileName(NULL, buffer, MAX_PATH);
23+
std::string::size_type pos = std::string(buffer).find_last_of("\\/");
24+
return std::string(buffer).substr(0, pos);
25+
}
26+
27+
BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle,
28+
IN DWORD nReason,
29+
IN LPVOID Reserved)
30+
{
31+
if (nReason == DLL_PROCESS_ATTACH) {
32+
int iResult = 0;
33+
WSADATA wsaData;
34+
35+
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
36+
if (iResult != NO_ERROR) {
37+
MessageBox(NULL, "WSAStartup failed.", "Fuck.", MB_OK);
38+
return TRUE;
39+
}
40+
41+
42+
int port = 27015;
43+
44+
std::ifstream conf = std::ifstream(ExePath() + std::string("\\socket_lights.txt"));
45+
std::string adr = "127.0.0.1";
46+
std::string strPort;
47+
48+
if (conf.is_open()) {
49+
try {
50+
std::getline(conf, adr);
51+
std::getline(conf, strPort);
52+
port = std::stoi(strPort);
53+
}
54+
catch (...) {
55+
MessageBox(NULL, "socket_lights.txt bad format\nUsing defaults: \n127.0.0.1\n27015", "Bad config", MB_OK);
56+
adr = "127.0.0.1";
57+
port = 27015;
58+
}
59+
}
60+
else {
61+
MessageBox(NULL, "socket_lights.txt missing\nUsing defaults: \n127.0.0.1\n27015", "Missing config", MB_OK);
62+
}
63+
64+
SendSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
65+
66+
RecvAddr.sin_family = AF_INET;
67+
RecvAddr.sin_port = htons(port);
68+
RecvAddr.sin_addr.s_addr = inet_addr(adr.c_str());
69+
70+
if (SendSocket == INVALID_SOCKET) {
71+
MessageBox(NULL, "Socket failed to create.", "RIP", MB_OK);
72+
return TRUE;
73+
}
74+
socketAlive = true;
75+
}
76+
return TRUE;
77+
}
78+
79+
void dispatchLights() {
80+
if (!socketAlive) return;
81+
if (!dataChanged) return;
82+
int iResult = 0;
83+
sendto(SendSocket,
84+
(Lights), 3, 0, (SOCKADDR *)& RecvAddr, sizeof(RecvAddr));
85+
if (iResult == SOCKET_ERROR) {
86+
MessageBox(NULL, "Socket error! :(", "Aww", MB_OK);
87+
socketAlive = false;
88+
}
89+
dataChanged = false;
90+
}
91+
92+
short int WINAPI IsDriverInstalled(){
93+
#pragma EXPORT
94+
return (short int)1;
95+
}
96+
97+
char WINAPI PortIn(short int port){
98+
#pragma EXPORT
99+
return '\0';
100+
}
101+
102+
void WINAPI PortOut(short int port, char data)
103+
{
104+
#pragma EXPORT
105+
106+
switch (port) {
107+
case 0x378:
108+
dataChanged = (Lights[0] != data) || dataChanged;
109+
Lights[0] = data;
110+
break;
111+
case 0x278:
112+
dataChanged = (Lights[1] != data) || dataChanged;
113+
Lights[1] = data;
114+
break;
115+
case 0x3bc:
116+
dataChanged = (Lights[2] != data) || dataChanged;
117+
Lights[2] = data;
118+
default:
119+
dispatchLights();
120+
break;
121+
}
122+
}

parallel_lights_io/Main.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
#define EXPORT comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
3+
#include <Windows.h>
4+
5+
BOOLEAN WINAPI DllMain(IN HINSTANCE, IN DWORD, IN LPVOID);
6+
7+
short int WINAPI IsDriverInstalled();
8+
char WINAPI PortIn(short int);
9+
void WINAPI PortOut(short int, char);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<VCProjectVersion>15.0</VCProjectVersion>
15+
<ProjectGuid>{259C23B4-984C-44A2-8515-74D41AA581F6}</ProjectGuid>
16+
<RootNamespace>parallel_lights_io</RootNamespace>
17+
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
18+
<ProjectName>parallel_lights_io</ProjectName>
19+
</PropertyGroup>
20+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
21+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
22+
<ConfigurationType>Application</ConfigurationType>
23+
<UseDebugLibraries>true</UseDebugLibraries>
24+
<PlatformToolset>v141</PlatformToolset>
25+
<CharacterSet>MultiByte</CharacterSet>
26+
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
28+
<ConfigurationType>DynamicLibrary</ConfigurationType>
29+
<UseDebugLibraries>false</UseDebugLibraries>
30+
<PlatformToolset>v141</PlatformToolset>
31+
<WholeProgramOptimization>true</WholeProgramOptimization>
32+
<CharacterSet>MultiByte</CharacterSet>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
35+
<ImportGroup Label="ExtensionSettings">
36+
</ImportGroup>
37+
<ImportGroup Label="Shared">
38+
</ImportGroup>
39+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
40+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
41+
</ImportGroup>
42+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
43+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
44+
</ImportGroup>
45+
<PropertyGroup Label="UserMacros" />
46+
<PropertyGroup />
47+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
48+
<ClCompile>
49+
<WarningLevel>Level3</WarningLevel>
50+
<Optimization>Disabled</Optimization>
51+
<SDLCheck>true</SDLCheck>
52+
</ClCompile>
53+
</ItemDefinitionGroup>
54+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
55+
<ClCompile>
56+
<WarningLevel>Level3</WarningLevel>
57+
<Optimization>MaxSpeed</Optimization>
58+
<FunctionLevelLinking>true</FunctionLevelLinking>
59+
<IntrinsicFunctions>true</IntrinsicFunctions>
60+
<SDLCheck>true</SDLCheck>
61+
<CompileAs>CompileAsCpp</CompileAs>
62+
</ClCompile>
63+
<Link>
64+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
65+
<OptimizeReferences>true</OptimizeReferences>
66+
</Link>
67+
</ItemDefinitionGroup>
68+
<ItemGroup>
69+
<ClInclude Include="Main.h" />
70+
</ItemGroup>
71+
<ItemGroup>
72+
<ClCompile Include="Main.cpp" />
73+
</ItemGroup>
74+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
75+
<ImportGroup Label="ExtensionTargets">
76+
</ImportGroup>
77+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="Main.h">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClCompile Include="Main.cpp">
24+
<Filter>Source Files</Filter>
25+
</ClCompile>
26+
</ItemGroup>
27+
</Project>

0 commit comments

Comments
 (0)