Skip to content

Commit

Permalink
First Release
Browse files Browse the repository at this point in the history
Might have bugs iunno, has support for RPH1 and SHVDN.
  • Loading branch information
LucasRitter committed Jan 27, 2018
1 parent 0672987 commit bedbd76
Show file tree
Hide file tree
Showing 15 changed files with 724 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RPH1/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>
38 changes: 38 additions & 0 deletions RPH1/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SpotifyRage")]
[assembly: AssemblyDescription("A plugin for Rage Plugin Hook that enables the use of Spotify within Grand Theft Auto V.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SpotifyRage")]
[assembly: AssemblyCopyright("Copyright © Lucas Ritter, Spotify 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ab9168d5-9bdb-43ab-9a90-9eeddf83b099")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

[assembly: Rage.Attributes.Plugin("SpotifyRage", Author = "Lucas Ritter, Spotify", ShouldTickInPauseMenu = false)]
85 changes: 85 additions & 0 deletions RPH1/RPH1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AB9168D5-9BDB-43AB-9A90-9EEDDF83B099}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SpotifyRage</RootNamespace>
<AssemblyName>SpotifyRage</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Spotify.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\SpotifyWebHelperAPI.1.0.4\lib\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="RagePluginHookSDK">
<HintPath>E:\Games\Standalone\GTA\Vanilla\SDK\RagePluginHookSDK.dll</HintPath>
</Reference>
<Reference Include="SpotifyWebHelperAPI, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SpotifyWebHelperAPI.1.0.4\lib\SpotifyWebHelperAPI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Scaleform.cs" />
<Compile Include="Spotify.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="FodyWeavers.xml" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Spotify.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.2.0.0\build\netstandard1.4\Fody.targets" Condition="Exists('..\packages\Fody.2.0.0\build\netstandard1.4\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.2.0.0\build\netstandard1.4\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.0.0\build\netstandard1.4\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets'))" />
</Target>
<Import Project="..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" />
<PropertyGroup>
<PostBuildEvent>xcopy $(TargetPath) "E:\Games\Standalone\GTA\Vanilla\Plugins" /F /Y</PostBuildEvent>
</PropertyGroup>
</Project>
92 changes: 92 additions & 0 deletions RPH1/Scaleform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Rage.Native;

namespace SpotifyRage
{
class Scaleform
{
public int Handle { get; private set; }
public string ScaleformID { get; private set; }

public Scaleform(string scaleformId, bool forceLoad)
{
if (forceLoad)
Load(scaleformId);
}

public Scaleform(int handle, bool forceLoad = false)
{
this.Handle = handle;
}

public bool Load(string scaleformId)
{
// Request a Scaleform movie identifier from the game.
int handle = NativeFunction.Natives.RequestScaleformMovie<int>(scaleformId);

// If a handle was not given, cancel the load process.
if (handle == 0) return false;

// Set local values.
this.Handle = handle;
this.ScaleformID = scaleformId;

// Loading was successful, return true.
return true;
}

public void Render2D()
{
// Draw a Scaleform movie in Fullscreen with 255 on all RGBA values.
NativeFunction.Natives.x0DF606929C105BE1(this.Handle, 255, 255, 255, 255);
}

public void CallFunction (string function, params object[] arguments)
{
// Start calling the function.
NativeFunction.Natives.xF6E48914C7A8694E(this.Handle, function);

// Loop through all arguments.
foreach (object argument in arguments)
{
// Do type checking

// 32bit Integer
if (argument.GetType() == typeof(int))
{
// Call native GRAPHICS::_PUSH_SCALEFORM_MOVIE_METHOD_PARAMETER_INT
NativeFunction.Natives.xC3D0841A0CC546A6((int)argument);
}

else if (argument.GetType() == typeof(string))
{
// Call native GRAPHICS::_PUSH_SCALEFORM_MOVIE_METHOD_PARAMETER_STRING
NativeFunction.Natives.xBA7148484BD90365((string)argument);
}

}

// Pop the function over to the game.
NativeFunction.Natives.xC6796A8FFA375E53();
}

public void CallFunctionArray (string function, params string[] arguments)
{
string[] argArray = new string[] { "", "", "", "", "" };

for (int i = 0; i < 5; i++)
{
if (arguments.Length > i && arguments[i] != null)
{
argArray[i] = arguments[i];
}
}

// Call native GRAPHICS::_CALL_SCALEFORM_MOVIE_FUNCTION_STRING_PARAMS
NativeFunction.Natives.x51BC1ED3CC44E8F7(this.Handle, function,
argArray[0], argArray[1], argArray[2], argArray[3], argArray[4]);

// Pop the function over to the game.
NativeFunction.Natives.EndScaleformMovieMethod();
}
}
}
110 changes: 110 additions & 0 deletions RPH1/Spotify.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System;
using Rage;
using Rage.Native;
using SpotifyWebHelperAPI;

namespace SpotifyRage
{
public sealed class EntryPoint
{
public static int RadioStation { get; private set; } = 0;

private static ISpotifyWebHelperCommunicationService CommunicationService;
private static Scaleform DashboardScaleform;

private static bool DebugDraw = false;

public static void Main()
{
Game.Console.Print($"SpotifyRage is now starting..");

// Initialize a connection to the Spotify Web Helper application.
// TODO: Catch if the App is not running.
Game.Console.Print("Connecting to the Spotify Web Helper application.");
CommunicationService = SpotifyWebHelperApi.Create();

// Request Dashboard Scaleform Movie
DashboardScaleform = new Scaleform("dashboard", true);


// Update on every game tick.
Game.FrameRender += Update;

while (true)
GameFiber.Yield();
}

private static void Update(object sender, GraphicsEventArgs e)
{

if (Game.LocalPlayer.Character.IsInAnyVehicle(false))
{
if (NativeFunction.Natives.GetPlayerRadioStationIndex<int>() == RadioStation)
{
var status = CommunicationService.GetStatus();

// Disable radio in car.
NativeFunction.Natives.SetFrontendRadioActive(false);
NativeFunction.Natives.SetVehicleRadioLoud(Game.LocalPlayer.Character.CurrentVehicle, false);
NativeFunction.Natives.SetVehicleRadioEnabled(Game.LocalPlayer.Character.CurrentVehicle, false);

PushSpotifyInfo(status.Track.ArtistResource.Name, status.Track.TrackResource.Name, status.Playing);

if (DebugDraw)
DashboardScaleform.Render2D();
}

// Check if vehicle radio is disabled or if it is set to be loud.
if (!NativeFunction.Natives.x5F43D83FD6738741<bool>() || !NativeFunction.Natives.x032A116663A4D5AC<bool>(Game.LocalPlayer.Character.CurrentVehicle))
{
NativeFunction.Natives.SetFrontendRadioActive(true);
NativeFunction.Natives.SetVehicleRadioLoud(Game.LocalPlayer.Character.CurrentVehicle, true);
NativeFunction.Natives.SetVehicleRadioEnabled(Game.LocalPlayer.Character.CurrentVehicle, true);
}
}
}
#if DEBUG
[Rage.Attributes.ConsoleCommand()]
private static void Command_GetSpotifyInfo()
{
var status = CommunicationService.GetStatus();
Game.Console.Print($"Artist: {status.Track.ArtistResource.Name}, Track: {status.Track.TrackResource.Name}, Is Playing: {status.Playing}");
}

[Rage.Attributes.ConsoleCommand()]
private static void Command_SetTestInfo()
{
var status = CommunicationService.GetStatus();
Game.Console.Print($"Artist: {status.Track.ArtistResource.Name}, Track: {status.Track.TrackResource.Name}, Is Playing: {status.Playing}");
}

[Rage.Attributes.ConsoleCommand()]
private static void Command_GetDashboard()
{
Game.Console.Print(DashboardScaleform.Handle.ToString());
}

[Rage.Attributes.ConsoleCommand()]
private static void Command_DrawDebug(bool enabled)
{
DebugDraw = enabled;
}

#endif

private static void PushSpotifyInfo(string artist, string track, bool playing)
{
try
{
DashboardScaleform.CallFunction("SET_RADIO",
"", playing ? "Spotify" : "Spotify - Paused",
artist, track);
}
catch (Exception exception)
{
Game.Console.Print("Spotify fucked up, " + exception.ToString());
}

}
}
}
Binary file added RPH1/Spotify.ico
Binary file not shown.
7 changes: 7 additions & 0 deletions RPH1/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Costura.Fody" version="1.6.2" targetFramework="net462" developmentDependency="true" />
<package id="Fody" version="2.0.0" targetFramework="net462" developmentDependency="true" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net462" />
<package id="SpotifyWebHelperAPI" version="1.0.4" targetFramework="net462" />
</packages>
4 changes: 4 additions & 0 deletions SHVDN/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>
36 changes: 36 additions & 0 deletions SHVDN/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SpotifyRage")]
[assembly: AssemblyDescription("A plugin for ScriptHookV.Net that enables the use of Spotify within Grand Theft Auto V.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SpotifyRage")]
[assembly: AssemblyCopyright("Copyright © Lucas Ritter, Spotify 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("697e407f-5571-49ff-8e41-044c6550c12b")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit bedbd76

Please sign in to comment.