Skip to content

Commit

Permalink
Mod ported into its own repository
Browse files Browse the repository at this point in the history
  • Loading branch information
REHERC committed Jul 23, 2021
1 parent 0f6bafd commit 16d221d
Show file tree
Hide file tree
Showing 27 changed files with 619 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
<SharedGUID>4e7d37c7-8afe-4f79-baf6-4ce82d05e091</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Mod.Template.Content</Import_RootNamespace>
<Import_RootNamespace>Distance.MenuUtilities.Content</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)Mod\mod.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)Mod\" />
<Content Include="$(MSBuildThisFileDirectory)Mod\mod.json" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Mod.Template.Content.projitems" Label="Shared" />
<Import Project="Distance.MenuUtilities.Content.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
12 changes: 12 additions & 0 deletions Distance.MenuUtilities.Content/Mod/mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"FriendlyName": "Menu Utilities",
"Description": "Extends the default distance menus with additional features.",
"Author": "Reherc",
"Contact": "Github: @REHERC",
"ModuleFileName": "Distance.MenuUtilities.dll",
"RequiredGSLs": [
"com.github.reherc/Centrifuge.Distance"
],
"SkipLoad": false,
"Priority": 10
}
6 changes: 3 additions & 3 deletions Mod.Template.sln → Distance.MenuUtilities.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Mod.Template.Content", "Mod.Template.Content\Mod.Template.Content.shproj", "{4E7D37C7-8AFE-4F79-BAF6-4CE82D05E091}"
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Distance.MenuUtilities.Content", "Distance.MenuUtilities.Content\Distance.MenuUtilities.Content.shproj", "{4E7D37C7-8AFE-4F79-BAF6-4CE82D05E091}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mod.Template", "Mod.Template\Mod.Template.csproj", "{7BCB2908-B003-45D9-BE68-50CBA5217603}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Distance.MenuUtilities", "Distance.MenuUtilities\Distance.MenuUtilities.csproj", "{7BCB2908-B003-45D9-BE68-50CBA5217603}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{08A1C9FA-7DC2-4A60-B9A6-AC0EB7132893}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -17,7 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Mod.Template.Content\Mod.Template.Content.projitems*{4e7d37c7-8afe-4f79-baf6-4ce82d05e091}*SharedItemsImports = 13
Distance.MenuUtilities.Content\Distance.MenuUtilities.Content.projitems*{4e7d37c7-8afe-4f79-baf6-4ce82d05e091}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
59 changes: 59 additions & 0 deletions Distance.MenuUtilities/ConfigurationLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Reactor.API.Configuration;
using System;
using UnityEngine;

namespace Distance.MenuUtilities
{
public class ConfigurationLogic : MonoBehaviour
{
#region Properties
public bool EnableDeletePlaylistButton
{
get => Get<bool>("EnableDeletePlaylistButton");
set => Set("EnableDeletePlaylistButton", value);
}

public bool EnableHexColorInput
{
get => Get<bool>("EnableHexColorInput");
set => Set("EnableHexColorInput", value);
}
#endregion

internal Settings Config;

public event Action<ConfigurationLogic> OnChanged;

private void Load()
{
Config = new Settings("Config");
}

public void Awake()
{
Load();

Get("EnableDeletePlaylistButton", true);
Get("EnableHexColorInput", true);

Save();
}

public T Get<T>(string key, T @default = default)
{
return Config.GetOrCreate(key, @default);
}

public void Set<T>(string key, T value)
{
Config[key] = value;
Save();
}

public void Save()
{
Config?.Save();
OnChanged?.Invoke(this);
}
}
}
125 changes: 125 additions & 0 deletions Distance.MenuUtilities/Distance.MenuUtilities.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0">
<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>{7BCB2908-B003-45D9-BE68-50CBA5217603}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Distance.MenuUtilities</RootNamespace>
<AssemblyName>Distance.MenuUtilities</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</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>
</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>
<ItemGroup>
<Reference Include="0Harmony, Version=2.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HarmonyX.2.5.1\lib\net35\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Centrifuge.Distance, Version=3.0.7868.41513, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\Centrifuge.Distance.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil, Version=0.10.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.10.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.10.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.10.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="MonoMod.RuntimeDetour, Version=21.7.8.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MonoMod.RuntimeDetour.21.7.8.3\lib\net35\MonoMod.RuntimeDetour.dll</HintPath>
</Reference>
<Reference Include="MonoMod.Utils, Version=21.7.8.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MonoMod.Utils.21.7.8.3\lib\net35\MonoMod.Utils.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=1.7.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Json.Net.Unity3D.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Reactor.API, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.Mod.SDK.3.2.0\lib\net35\Reactor.API.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\UnityEngine.Networking.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigurationLogic.cs" />
<Compile Include="Mod.cs" />
<Compile Include="Extensions\Assembly-CSharp\CustomizeCarColorsMenuLogic.cs" />
<Compile Include="Extensions\Assembly-CSharp\LevelPlaylist.cs" />
<Compile Include="Extensions\mscorlib\System\String.cs" />
<Compile Include="Harmony\Assembly-CSharp\CustomizeCarColorsMenuLogic\Awake.cs" />
<Compile Include="Harmony\Assembly-CSharp\CustomizeCarColorsMenuLogic\OnColorPickerPop.cs" />
<Compile Include="Harmony\Assembly-CSharp\CustomizeCarColorsMenuLogic\PickColorForType.cs" />
<Compile Include="Harmony\Assembly-CSharp\CustomizeCarColorsMenuLogic\UpdateColorPickerInput.cs" />
<Compile Include="Harmony\Assembly-CSharp\LevelGridGrid\PushGrid.cs" />
<Compile Include="Harmony\Assembly-CSharp\LevelGridGrid\Update.cs" />
<Compile Include="Harmony\Assembly-CSharp\LevelPlaylist\Load.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\Constants.cs" />
<Compile Include="Resources\Strings.cs" />
<Compile Include="Scripts\CustomizeMenuCompoundData.cs" />
<Compile Include="Scripts\LevelPlaylistCompoundData.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<!-- 15.0 is for VS2017, adjust if necessary -->
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<!-- This is what will cause the templates to be transformed when the project is built (default is false) -->
<TransformOnBuild>true</TransformOnBuild>
<!-- Set to true to force overwriting of read-only output files, e.g. if they're not checked out (default is false) -->
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<!-- Set to false to transform files even if the output appears to be up-to-date (default is true) -->
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets" />
<Import Project="$(SolutionDir)Tool.BuildTargets\Distance.Modding.props" />
<Import Project="$(SolutionDir)Tool.BuildTargets\Distance.Modding.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma warning disable RCS1110
using Distance.MenuUtilities.Scripts;
using System;

public static class CustomizeCarColorsMenuLogicExtensions
{
public static void SetThirdAction(this CustomizeCarColorsMenuLogic menu, string text, InputAction input, Action callback)
{
CustomizeMenuCompoundData data = menu.GetComponent<CustomizeMenuCompoundData>();

if (data)
{
data.OnButtonClick = callback;

menu.deleteButton_.GetComponentInChildren<UILabel>().text = text;
ControlsBasedUITexture texture = menu.deleteButton_.GetComponent<ControlsBasedUITexture>();

texture.inputAction_ = input;
texture.EvaluateLatestUsedDevice();
}
}

public static void SetThirdActionEnabled(this CustomizeCarColorsMenuLogic menu, bool value)
{
menu.deleteButton_.gameObject.SetActive(value);
menu.deleteButton_.enabled = value;
}
}
23 changes: 23 additions & 0 deletions Distance.MenuUtilities/Extensions/Assembly-CSharp/LevelPlaylist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma warning disable RCS1110
using Distance.MenuUtilities.Scripts;
using System;
using System.IO;
using UnityEngine;

public static class LevelPlaylistExtensions
{
public static bool IsResourcesPlaylist(this LevelPlaylist playlist)
{
LevelPlaylistCompoundData data = playlist.gameObject.GetComponent<LevelPlaylistCompoundData>();

if (!data)
{
return true;
}

string path = new FileInfo(data.FilePath).FullName.UniformPathName();
string resourcesPath = new DirectoryInfo(Path.Combine(Application.dataPath, "Resources")).FullName.UniformPathName();

return path.StartsWith(resourcesPath, StringComparison.InvariantCultureIgnoreCase);
}
}
16 changes: 16 additions & 0 deletions Distance.MenuUtilities/Extensions/mscorlib/System/String.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma warning disable RCS1110
using System.IO;

public static class StringExtensions
{
public static string UniformPathName(this string source)
{
string result = source.ToLowerInvariant();

result = result.Replace(Path.DirectorySeparatorChar, '/');
result = result.Replace(Path.AltDirectorySeparatorChar, '/');
result = result.Replace('\\', '/');

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Distance.MenuUtilities.Scripts;
using HarmonyLib;

namespace Distance.MenuUtilities.Harmony
{
[HarmonyPatch(typeof(CustomizeCarColorsMenuLogic), "Awake")]
internal static class CustomizeCarColorsMenuLogic__Awake
{
[HarmonyPostfix]
internal static void Postfix(CustomizeCarColorsMenuLogic __instance)
{
CustomizeMenuCompoundData data = __instance.gameObject.AddComponent<CustomizeMenuCompoundData>();
data.Menu = __instance;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Distance.MenuUtilities.Scripts;
using HarmonyLib;

namespace Distance.MenuUtilities.Harmony
{
[HarmonyPatch(typeof(CustomizeCarColorsMenuLogic), "OnColorPickerPop")]
internal static class CustomizeCarColorsMenuLogic__OnColorPickerPop
{
[HarmonyPostfix]
internal static void Postfix(CustomizeCarColorsMenuLogic __instance)
{
CustomizeMenuCompoundData data = __instance.GetComponent<CustomizeMenuCompoundData>();

if (data)
{
data.ColorType = ColorChanger.ColorType.Size_;

__instance.SetThirdActionEnabled(false);
__instance.SetThirdAction(string.Empty, InputAction.MenuDoNotUse, null);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Distance.MenuUtilities.Scripts;
using HarmonyLib;

namespace Distance.MenuUtilities.Harmony
{
[HarmonyPatch(typeof(CustomizeCarColorsMenuLogic), "PickColorForType")]
internal static class CustomizeCarColorsMenuLogic__PickColorForType
{
[HarmonyPostfix]
internal static void Postfix(CustomizeCarColorsMenuLogic __instance, ColorChanger.ColorType colorType)
{
CustomizeMenuCompoundData data = __instance.GetComponent<CustomizeMenuCompoundData>();

if (data && Mod.Instance.Config.EnableHexColorInput)
{
data.ColorType = colorType;

__instance.SetThirdActionEnabled(true);
__instance.SetThirdAction("EDIT", InternalResources.Constants.INPUT_EDIT_COLOR, data.EditHexClick);
}
}
}
}
Loading

0 comments on commit 16d221d

Please sign in to comment.