Skip to content

Commit 24b99e1

Browse files
authoredApr 6, 2021
Add files via upload
1 parent 354f248 commit 24b99e1

37 files changed

+100204
-0
lines changed
 

‎AdRework.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29613.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdRework", "AdRework\AdRework.csproj", "{83962AE4-6551-4626-8894-E326105AC488}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{83962AE4-6551-4626-8894-E326105AC488}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{83962AE4-6551-4626-8894-E326105AC488}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{83962AE4-6551-4626-8894-E326105AC488}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{83962AE4-6551-4626-8894-E326105AC488}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {37CF698F-2DFF-483F-9C70-2E3EE2C2C39A}
24+
EndGlobalSection
25+
EndGlobal

‎AdRework/AdRework.csproj

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{83962AE4-6551-4626-8894-E326105AC488}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>AdRework</RootNamespace>
10+
<AssemblyName>AdRework</AssemblyName>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
<PublishUrl>publish\</PublishUrl>
16+
<Install>true</Install>
17+
<InstallFrom>Disk</InstallFrom>
18+
<UpdateEnabled>false</UpdateEnabled>
19+
<UpdateMode>Foreground</UpdateMode>
20+
<UpdateInterval>7</UpdateInterval>
21+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
22+
<UpdatePeriodically>false</UpdatePeriodically>
23+
<UpdateRequired>false</UpdateRequired>
24+
<MapFileExtensions>true</MapFileExtensions>
25+
<ApplicationRevision>0</ApplicationRevision>
26+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
27+
<IsWebBootstrapper>false</IsWebBootstrapper>
28+
<UseApplicationTrust>false</UseApplicationTrust>
29+
<BootstrapperEnabled>true</BootstrapperEnabled>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
32+
<PlatformTarget>AnyCPU</PlatformTarget>
33+
<DebugSymbols>true</DebugSymbols>
34+
<DebugType>full</DebugType>
35+
<Optimize>false</Optimize>
36+
<OutputPath>bin\Debug\</OutputPath>
37+
<DefineConstants>DEBUG;TRACE</DefineConstants>
38+
<ErrorReport>prompt</ErrorReport>
39+
<WarningLevel>4</WarningLevel>
40+
</PropertyGroup>
41+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
42+
<PlatformTarget>AnyCPU</PlatformTarget>
43+
<DebugType>pdbonly</DebugType>
44+
<Optimize>true</Optimize>
45+
<OutputPath>bin\Release\</OutputPath>
46+
<DefineConstants>TRACE</DefineConstants>
47+
<ErrorReport>prompt</ErrorReport>
48+
<WarningLevel>4</WarningLevel>
49+
</PropertyGroup>
50+
<PropertyGroup>
51+
<ApplicationIcon>Resources\AdRework.ico</ApplicationIcon>
52+
</PropertyGroup>
53+
<ItemGroup>
54+
<Reference Include="CSCore, Version=1.2.1.2, Culture=neutral, PublicKeyToken=5a08f2b6f4415dea, processorArchitecture=MSIL">
55+
<HintPath>..\packages\CSCore.1.2.1.2\lib\net35-client\CSCore.dll</HintPath>
56+
</Reference>
57+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
58+
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
59+
</Reference>
60+
<Reference Include="System" />
61+
<Reference Include="System.Core" />
62+
<Reference Include="System.Xml.Linq" />
63+
<Reference Include="System.Data.DataSetExtensions" />
64+
<Reference Include="Microsoft.CSharp" />
65+
<Reference Include="System.Data" />
66+
<Reference Include="System.Deployment" />
67+
<Reference Include="System.Drawing" />
68+
<Reference Include="System.Net.Http" />
69+
<Reference Include="System.Windows.Forms" />
70+
<Reference Include="System.Xml" />
71+
</ItemGroup>
72+
<ItemGroup>
73+
<Compile Include="Program.cs" />
74+
<Compile Include="Properties\AssemblyInfo.cs" />
75+
<EmbeddedResource Include="Properties\Resources.resx">
76+
<Generator>ResXFileCodeGenerator</Generator>
77+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
78+
<SubType>Designer</SubType>
79+
</EmbeddedResource>
80+
<Compile Include="Properties\Resources.Designer.cs">
81+
<AutoGen>True</AutoGen>
82+
<DependentUpon>Resources.resx</DependentUpon>
83+
<DesignTime>True</DesignTime>
84+
</Compile>
85+
<None Include="packages.config" />
86+
<None Include="Properties\Settings.settings">
87+
<Generator>SettingsSingleFileGenerator</Generator>
88+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
89+
</None>
90+
<Compile Include="Properties\Settings.Designer.cs">
91+
<AutoGen>True</AutoGen>
92+
<DependentUpon>Settings.settings</DependentUpon>
93+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
94+
</Compile>
95+
</ItemGroup>
96+
<ItemGroup>
97+
<None Include="App.config" />
98+
</ItemGroup>
99+
<ItemGroup>
100+
<COMReference Include="AxWMPLib">
101+
<Guid>{6BF52A50-394A-11D3-B153-00C04F79FAA6}</Guid>
102+
<VersionMajor>1</VersionMajor>
103+
<VersionMinor>0</VersionMinor>
104+
<Lcid>0</Lcid>
105+
<WrapperTool>aximp</WrapperTool>
106+
<Isolated>False</Isolated>
107+
</COMReference>
108+
<COMReference Include="WMPLib">
109+
<Guid>{6BF52A50-394A-11D3-B153-00C04F79FAA6}</Guid>
110+
<VersionMajor>1</VersionMajor>
111+
<VersionMinor>0</VersionMinor>
112+
<Lcid>0</Lcid>
113+
<WrapperTool>tlbimp</WrapperTool>
114+
<Isolated>False</Isolated>
115+
<EmbedInteropTypes>True</EmbedInteropTypes>
116+
</COMReference>
117+
</ItemGroup>
118+
<ItemGroup>
119+
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
120+
<Visible>False</Visible>
121+
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
122+
<Install>true</Install>
123+
</BootstrapperPackage>
124+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
125+
<Visible>False</Visible>
126+
<ProductName>.NET Framework 3.5 SP1</ProductName>
127+
<Install>false</Install>
128+
</BootstrapperPackage>
129+
</ItemGroup>
130+
<ItemGroup>
131+
<None Include="bin\Release\AxInterop.WMPLib.dll" />
132+
</ItemGroup>
133+
<ItemGroup>
134+
<None Include="bin\Release\CSCore.dll" />
135+
</ItemGroup>
136+
<ItemGroup>
137+
<None Include="bin\Release\Interop.WMPLib.dll" />
138+
</ItemGroup>
139+
<ItemGroup>
140+
<None Include="bin\Release\Newtonsoft.Json.dll" />
141+
</ItemGroup>
142+
<ItemGroup>
143+
<EmbeddedResource Include="Resources\AdRework.ico" />
144+
</ItemGroup>
145+
<ItemGroup>
146+
<EmbeddedResource Include="Resources\AxInterop.WMPLib.dll" />
147+
</ItemGroup>
148+
<ItemGroup>
149+
<EmbeddedResource Include="Resources\CSCore.dll" />
150+
</ItemGroup>
151+
<ItemGroup>
152+
<EmbeddedResource Include="Resources\Interop.WMPLib.dll" />
153+
</ItemGroup>
154+
<ItemGroup>
155+
<EmbeddedResource Include="Resources\Newtonsoft.Json.dll" />
156+
</ItemGroup>
157+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
158+
</Project>

‎AdRework/AdRework.csproj.user

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<PublishUrlHistory>publish\</PublishUrlHistory>
5+
<InstallUrlHistory />
6+
<SupportUrlHistory />
7+
<UpdateUrlHistory />
8+
<BootstrapperUrlHistory />
9+
<ErrorReportUrlHistory />
10+
<FallbackCulture>en-US</FallbackCulture>
11+
<VerifyUploadedFiles>false</VerifyUploadedFiles>
12+
</PropertyGroup>
13+
</Project>

‎AdRework/App.config

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>

‎AdRework/Program.cs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using CSCore.CoreAudioAPI;
2+
using Microsoft.Win32;
3+
using System;
4+
using System.Diagnostics;
5+
using System.Linq;
6+
using System.Runtime.InteropServices;
7+
using System.Threading;
8+
using Timer = System.Timers.Timer;
9+
10+
namespace AdRework {
11+
static class Program {
12+
[STAThread]
13+
static void Main() { AdReworkStart(); }
14+
15+
[DllImport("user32.dll", SetLastError = true)]
16+
private static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);
17+
private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow) {
18+
using (var enumerator = new MMDeviceEnumerator()) {
19+
using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia)) {
20+
Console.WriteLine("DefaultDevice: " + device.FriendlyName);
21+
var sessionManager = AudioSessionManager2.FromMMDevice(device);
22+
return sessionManager; }}}
23+
24+
public static void SetApplicationVolume(int ProcessId, float Volume) {
25+
using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render)) {
26+
using (var sessionEnumerator = sessionManager.GetSessionEnumerator()) {
27+
foreach (var session in sessionEnumerator) {
28+
using (var simpleVolume = session.QueryInterface<SimpleAudioVolume>())
29+
using (var sessionControl = session.QueryInterface<AudioSessionControl2>()) {
30+
if (sessionControl.ProcessID == ProcessId)
31+
simpleVolume.MasterVolume = Volume; }}}}}
32+
public static float GetApplicationVolume(int ProcessId) {
33+
using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render)) {
34+
using (var sessionEnumerator = sessionManager.GetSessionEnumerator()) {
35+
foreach (var session in sessionEnumerator) {
36+
using (var simpleVolume = session.QueryInterface<SimpleAudioVolume>())
37+
using (var sessionControl = session.QueryInterface<AudioSessionControl2>()) {
38+
if (sessionControl.ProcessID == ProcessId)
39+
return simpleVolume.MasterVolume; }}}} return 0; }
40+
41+
42+
private static bool AdManaged = false;
43+
private static void SkipAd() {
44+
if (AdManaged) return;
45+
if (Process.GetProcessesByName("Spotify").Length <= 0) { AdManaged = false; return; }
46+
47+
AdManaged = true;
48+
Process Spotify = Process.GetProcessesByName("Spotify").FirstOrDefault(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle));
49+
50+
const int VK_MEDIA_NEXT_TRACK = 0xB0;
51+
const int KEYEVENTF_EXTENDEDKEY = 0x001;
52+
const int KEYEVENTF_KEYUP = 0x002;
53+
54+
keybd_event(VK_MEDIA_NEXT_TRACK, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
55+
keybd_event(VK_MEDIA_NEXT_TRACK, 0, KEYEVENTF_KEYUP, IntPtr.Zero);
56+
Thread.Sleep(250); // attempt to skip ad after 250ms in the case it doesnt require you to wait 5 seconds
57+
58+
string trackInfo = GetSpotifyTrackInfo().ToLower();
59+
if (!(trackInfo.Replace(" ", "").StartsWith("advertisement") ||
60+
trackInfo.Replace(" ", "") == "advertisement" ||
61+
trackInfo == "spotify")) { Console.WriteLine("Instantly Skipped Ad."); Thread.Sleep(65); AdManaged = false; return; }
62+
63+
float originalVolume = GetApplicationVolume(Spotify.Id);
64+
65+
SetApplicationVolume(Spotify.Id, 0f);
66+
Thread.Sleep(5350); // wait for 5 seconds before skipping add (+ a few milliseconds to account for loading)
67+
68+
keybd_event(VK_MEDIA_NEXT_TRACK, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
69+
keybd_event(VK_MEDIA_NEXT_TRACK, 0, KEYEVENTF_KEYUP, IntPtr.Zero);
70+
71+
SetApplicationVolume(Spotify.Id, originalVolume);
72+
73+
Console.WriteLine("Skipped Ad After 5 Seconds.");
74+
Thread.Sleep(65); // wait for a few milliseconds before disabling ad management so spotify can register song skip and it isnt fired twice
75+
AdManaged = false; }
76+
77+
private static string GetSpotifyTrackInfo() {
78+
var proc = Process.GetProcessesByName("Spotify").FirstOrDefault(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle));
79+
80+
if (proc == null) return "Closed";
81+
if (string.Equals(proc.MainWindowTitle, "Spotify Free", StringComparison.InvariantCultureIgnoreCase)) return "Paused";
82+
return proc.MainWindowTitle; }
83+
84+
private static void AutoAntiAd(object sender, EventArgs e) {
85+
string trackInfo = GetSpotifyTrackInfo().ToLower();
86+
if (trackInfo.Replace(" ", "").StartsWith("advertisement") ||
87+
trackInfo.Replace(" ", "") == "advertisement" ||
88+
trackInfo == "spotify")
89+
if (!AdManaged) SkipAd(); }
90+
91+
private static void AdReworkStart() {
92+
93+
Process spotify = Process.GetProcessesByName("Spotify").FirstOrDefault(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle));
94+
Console.WriteLine(spotify.MainWindowTitle);
95+
IntPtr child = spotify.MainWindowHandle;
96+
Console.WriteLine(child.ToInt32());
97+
98+
Timer timer = new Timer(50); timer.Elapsed += AutoAntiAd; timer.AutoReset = true; timer.Start();
99+
100+
try { using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) {
101+
key.SetValue("AdRework", System.Reflection.Assembly.GetExecutingAssembly().Location); }} catch (Exception) {}
102+
Thread.Sleep(-1); }}}

‎AdRework/Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("AdRework")]
9+
[assembly: AssemblyDescription("Automatically and seamlessly skip spotify ads!")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("dmbk development")]
12+
[assembly: AssemblyProduct("AdRework")]
13+
[assembly: AssemblyCopyright("Copyright © 2021")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("83962ae4-6551-4626-8894-e326105ac488")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)
Please sign in to comment.