Skip to content

Commit

Permalink
Add mod to template.
Browse files Browse the repository at this point in the history
  • Loading branch information
PredatoryBalloon committed Jan 2, 2022
1 parent 9fef654 commit 1cc6f4f
Show file tree
Hide file tree
Showing 19 changed files with 502 additions and 205 deletions.
8 changes: 5 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SOLUTION=Mod.Template.sln
ARTIFACTS=Build/Distance Mod Template.zip
RELEASE_BODY=This release was automatically generated as part of a GitHub workflow. Please read the repository README for more info.
SOLUTION=Distance.TrackAttachToTrack.sln
ARTIFACTS=Build/Distance TrackAttachToTrack.zip
RELEASE_BODY=This release was automatically generated as part of a GitHub workflow. Please read the repository README for more info.


Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>4e7d37c7-8afe-4f79-baf6-4ce82d05e091</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Mod.Template.Content</Import_RootNamespace>
<Import_RootNamespace>Distance.TrackAttachToTrack.Content</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)Mod\mod.json">
Expand All @@ -16,4 +16,6 @@
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)Mod\" />
</ItemGroup>
</Project>
</Project>


Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<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.TrackAttachToTrack.Content.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
</Project>


12 changes: 12 additions & 0 deletions Distance.TrackAttachToTrack.Content/Mod/mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"FriendlyName": "TrackAttachToTrack",
"Author": "PB",
"Contact": "( .-.)",
"ModuleFileName": "Distance.TrackAttachToTrack.dll",
"Dependencies": [],
"SkipLoad": false,
"Priority": 10,
"RequiredGSLs": [
"com.github.reherc/Centrifuge.Distance"
]
}
11 changes: 7 additions & 4 deletions Mod.Template.sln → Distance.TrackAttachToTrack.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


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.TrackAttachToTrack.Content", "Distance.TrackAttachToTrack.Content\Distance.TrackAttachToTrack.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.TrackAttachToTrack", "Distance.TrackAttachToTrack\Distance.TrackAttachToTrack.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.TrackAttachToTrack.Content\Distance.TrackAttachToTrack.Content.projitems*{4e7d37c7-8afe-4f79-baf6-4ce82d05e091}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,3 +36,6 @@ Global
SolutionGuid = {E6970D48-CD23-4427-951B-448B144F30DA}
EndGlobalSection
EndGlobal



55 changes: 55 additions & 0 deletions Distance.TrackAttachToTrack/ConfigurationLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reactor.API.Configuration;
using System;
using UnityEngine;

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

internal Settings Config;

public event Action<ConfigurationLogic> OnChanged;

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

}

public void Awake()
{
Load();
Get("gta", false);
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{7BCB2908-B003-45D9-BE68-50CBA5217603}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mod.Template</RootNamespace>
<AssemblyName>Mod.Template</AssemblyName>
<RootNamespace>Distance.TrackAttachToTrack</RootNamespace>
<AssemblyName>Distance.TrackAttachToTrack</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
Expand Down Expand Up @@ -86,11 +86,15 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Mod.cs" />
<Compile Include="ConfigurationLogic.cs" />
<Compile Include="Entry.cs" />
<Compile Include="Harmony\Assembly-CSharp\AttachTrackToTrack\Run.cs" />
<Compile Include="Harmony\Assembly-CSharp\AttachTrackToTrack\TrackToTrackButton.cs" />
<Compile Include="Harmony\Assembly-CSharp\AttachTrackToTrack\TrackToTrackSButton.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Mod.Template.targets" />
<None Include="Distance.TrackAttachToTrack.targets" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ModName>Distance TrackAttachToTrack</ModName>
</PropertyGroup>
</Project>


74 changes: 74 additions & 0 deletions Distance.TrackAttachToTrack/Entry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Centrifuge.Distance.Game;
using Centrifuge.Distance.GUI.Controls;
using Centrifuge.Distance.GUI.Data;
using Events.MainMenu;
using Events.QuitLevelEditor;
using Reactor.API.Attributes;
using Reactor.API.Interfaces.Systems;
using Reactor.API.Logging;
using Reactor.API.Runtime.Patching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Distance.EditorAnnihilator
{
[ModEntryPoint("com.github.pred/Distance.TrackAttachToTrack")]
public class Mod : MonoBehaviour
{
public static Mod Instance;

public IManager Manager { get; set; }

public static Log Logger { get; private set; }

public static ConfigurationLogic Config { get; private set; }

public static bool ModEnabled { get; set; }

public void Initialize(IManager manager)
{
Instance = this;
Logger = LogManager.GetForCurrentAssembly();
Manager = manager;
Config = gameObject.AddComponent<ConfigurationLogic>();
//Events.MainMenu.Initialized.Subscribe(OnMainMenuInitialized);
//Events.QuitLevelEditor.Quit.Subscribe(OnMainMenuInitialized2);
//Events.MainMenu.Initialized.Unsubscribe(OnMainMenuInitialized);
//Events.MainMenu.Initialized.Broadcast(new Initialized.Data());
CreateSettingsMenu();
//GameObject lamp = new GameObject();
//Type lamptrans = System.Type.GetType("Transform");
//lamp.AddComponent(lamptrans);
RuntimePatcher.AutoPatch();
}

public void CreateSettingsMenu()
{
MenuTree settingsMenu;
settingsMenu = new MenuTree("menu.mod.TrackAttachToTrack", "TrackAttachToTrack Settings")
{
new CheckBox(MenuDisplayMode.MainMenu, "setting:enable_disable_trackgrouping", "ENABLE GROUPING TRACK ATTACHMENTS")
.WithGetter(() => Config.gta)
.WithSetter((x) => Config.gta = x)
.WithDescription("Normally, you can only group track attachments with the track they are attached to, but enabling this removes this restriction. The reason this is an option and not a default feature is that it can produce some weird effects under certain circumstances. Say you attach an object to a track, group that object, and then delete the track, and then ungroup the object. The object will then have a track attachment to a nonexistant track, which can cause the editor to freak out and crash under certain circumstances (Though you can remove it just fine if you don't try to do anything else with it first, like duplicating the object or something.).")
};

Menus.AddNew(MenuDisplayMode.Both, settingsMenu, "TrackAttachToTrack", "Settings for the TrackAttachToTrack mod.");
}

public static bool GTA => Config.gta;

private void OnMainMenuInitialized(Initialized.Data data)
{
Resource.CreateLevelEditorPrefabDirInfo();
}

private void OnMainMenuInitialized2(Quit.Data data)
{
Resource.CreateResourceList();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@


using System;

using System;
using System.Collections.Generic;
using System.Linq;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using HarmonyLib;
using LevelEditorTools;
using UnityEngine;
using LevelEditorActions;

namespace Distance.EditorAnnihilator.Harmony
{
[HarmonyPatch(typeof(GroupTool), "Run")]
internal static class GroupTool__Run
{
//__instance is the class you are patching, so you can call functions on it.
//If patching a function with paramaters, you can just add those paramaters as paramaters inside Postfix.
//If the function you're patching has a return type, you can modify the result value with the parameter 'ref [type of return value] __result'
[HarmonyPrefix]
internal static bool Prefix(ref bool __result, GroupTool __instance)
{
if(Mod.GTA)
{
LevelEditor levelEditor = G.Sys.LevelEditor_;
GameObject[] array = levelEditor.SelectedNonTrackNodeAndNonOnlyAllowOneObjects_.ToArray();
if (array.Length < 1)
{
LevelEditorTool.PrintErrorMessage("Requires at least 1 object to group.");
__result = false;
return false;
}
GroupAction groupAction = Group.CreateGroupAction(array, levelEditor.ActiveObject_);
GameObject gameObject = groupAction.GroupObjects().gameObject;
if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
{
levelEditor.ClearSelectedList();
levelEditor.SelectObject(gameObject);
groupAction.FinishAndAddToLevelEditorActions();
LevelEditorTool.PrintFormattedCountMessage("Grouped {0} object{1}.", array.Length);
__result = true;
return false;
}
Debug.LogError((object)"Grouping failed");
__result = false;
return false;
}
return true;
}
}
}
Loading

0 comments on commit 1cc6f4f

Please sign in to comment.