-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1bf3a27
Showing
16 changed files
with
556 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
bin/ | ||
obj/ | ||
/packages/ | ||
riderModule.iml | ||
/_ReSharper.Caches/ | ||
/DuskersModloader.sln.DotSettings.user | ||
/libs/ | ||
/Duskers-Assembly-CSharp/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] | ||
[assembly: AssemblyVersion("0.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# How to patch Assembly-CSharp-firstpass.dll | ||
|
||
* You will need to decompile the dll source using some kind of tool (I used rider's built in decompiler). | ||
* Drop all source here | ||
* Add the following code to Steamworks.SteamAPI Init method | ||
``` | ||
Debug.logger.Log("Trying to load Harmony and ModLoader."); | ||
try | ||
{ | ||
string managedPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
Assembly harmony = Assembly.LoadFrom(Path.Combine(managedPath, "0Harmony.dll")); | ||
Assembly modLoader = Assembly.LoadFrom(Path.Combine(managedPath, "ModLoader.dll")); | ||
Type modLoaderType = modLoader.GetType("ModLoader.Loader", true); | ||
MethodInfo startMethod = modLoaderType.GetMethod("Start", new Type[0]); | ||
startMethod.Invoke(null, new object[0]); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError("Unable to start modloader!"); | ||
Debug.LogException(e); | ||
} | ||
``` | ||
* Compile it. | ||
* Can't compile because `(LayerMask) -1` is invalid for some reason. | ||
* Remove it ignoring the consequences. | ||
* Try compiling again. | ||
* Now it compiled, replace the original file and drop the modloader and harmony dll together with it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModLoader", "ModLoader\ModLoader.csproj", "{65C06865-5AA3-42C9-B905-D7BEBEEADBFC}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Duskers-Assembly-CSharp", "Duskers-Assembly-CSharp\Duskers-Assembly-CSharp.csproj", "{146A110D-4903-4763-8E58-770EF2F57672}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mods", "Mods", "{CCF36A88-3EF1-4A0F-8C45-28FB5009A5BF}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleMod1", "ExampleMod1\ExampleMod1.csproj", "{0A0BA294-ABFE-4CCA-92E4-D99284AC8AD3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{65C06865-5AA3-42C9-B905-D7BEBEEADBFC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{65C06865-5AA3-42C9-B905-D7BEBEEADBFC}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{65C06865-5AA3-42C9-B905-D7BEBEEADBFC}.Debug|Any CPU.ActiveCfg = Release|Any CPU | ||
{65C06865-5AA3-42C9-B905-D7BEBEEADBFC}.Debug|Any CPU.Build.0 = Release|Any CPU | ||
{146A110D-4903-4763-8E58-770EF2F57672}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{146A110D-4903-4763-8E58-770EF2F57672}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{146A110D-4903-4763-8E58-770EF2F57672}.Debug|Any CPU.ActiveCfg = Release|Any CPU | ||
{146A110D-4903-4763-8E58-770EF2F57672}.Debug|Any CPU.Build.0 = Release|Any CPU | ||
{0A0BA294-ABFE-4CCA-92E4-D99284AC8AD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0A0BA294-ABFE-4CCA-92E4-D99284AC8AD3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0A0BA294-ABFE-4CCA-92E4-D99284AC8AD3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0A0BA294-ABFE-4CCA-92E4-D99284AC8AD3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{0A0BA294-ABFE-4CCA-92E4-D99284AC8AD3} = {CCF36A88-3EF1-4A0F-8C45-28FB5009A5BF} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{0A0BA294-ABFE-4CCA-92E4-D99284AC8AD3}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>ExampleMod1</RootNamespace> | ||
<AssemblyName>ExampleMod1</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<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' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<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.0.4.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\packages\Lib.Harmony.2.0.4\lib\net35\0Harmony.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\Assembly-CSharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"> | ||
<HintPath>..\libs\Mono.Posix.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Mono.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"> | ||
<HintPath>..\libs\Mono.Security.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<HintPath>..\libs\System.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<HintPath>..\libs\System.Configuration.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<HintPath>..\libs\System.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<HintPath>..\libs\System.Security.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<HintPath>..\libs\System.Xml.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\UnityEngine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\UnityEngine.Networking.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\UnityEngine.UI.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="MyExampleMod1.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\ModLoader\ModLoader.csproj"> | ||
<Project>{65c06865-5aa3-42c9-b905-d7bebeeadbfc}</Project> | ||
<Name>ModLoader</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using ModLoader.Modding; | ||
|
||
namespace ExampleMod1 | ||
{ | ||
public class MyExampleMod1 : IMod | ||
{ | ||
public void Load() | ||
{ | ||
CommandManager.Manager.AddCommand(new ExampleCommand()); | ||
} | ||
} | ||
|
||
public class ExampleCommand : BaseCommand | ||
{ | ||
public ExampleCommand() : base("example1", "") | ||
{ | ||
} | ||
|
||
public override bool Execute(ExecutedCommand command, bool partOfMultiCommand) | ||
{ | ||
ConsoleWindow3.SendConsoleResponse("An example command from ExampleMod1", ConsoleMessageType.SpecialInfo); | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Reflection; | ||
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("ExampleMod1")] | ||
[assembly: AssemblyDescription("Some example mod")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("ExampleMod1")] | ||
[assembly: AssemblyCopyright("Copyright © 2021")] | ||
[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("0A0BA294-ABFE-4CCA-92E4-D99284AC8AD3")] | ||
|
||
// 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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Xml; | ||
using HarmonyLib; | ||
using ModLoader.Modding; | ||
using UnityEngine; | ||
|
||
namespace ModLoader | ||
{ | ||
public class Loader | ||
{ | ||
public static readonly List<IMod> Mods = new List<IMod>(); | ||
|
||
//Called from Steamworks.SteamAPI#Init() method | ||
public static void Start() | ||
{ | ||
//Load our patches | ||
var harmony = new Harmony("com.juanmuscaria.ModLoader"); | ||
harmony.PatchAll(); | ||
|
||
//Start loading other mods | ||
var modFolder = GETModFolder(); | ||
Debug.Log("Searching '{}' for mods.".Replace("{}",modFolder.FullName)); | ||
|
||
foreach (var modFile in Directory.GetFiles(modFolder.FullName, "*.dll")) | ||
{ | ||
Debug.Log("Loading mod file:" + modFile); | ||
foreach (var type in Assembly.LoadFile(modFile).GetExportedTypes()) | ||
{ | ||
try | ||
{ | ||
if (!type.IsDefined(typeof(IMod), true) && | ||
!typeof(IMod).IsAssignableFrom(type)) continue; | ||
Debug.Log("Found '"+ type + "' in '" + modFile + "'"); | ||
var ctor = type.GetConstructor(Type.EmptyTypes); | ||
if (ctor != null) | ||
{ | ||
Mods.Add((IMod) ctor.Invoke(null)); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.LogError("Failed to load '"+ type + "' in '" + modFile + "'"); | ||
Debug.LogError(ex); | ||
} | ||
} | ||
} | ||
|
||
foreach (var mod in Mods) | ||
{ | ||
mod.Load(); | ||
} | ||
|
||
CommandManager.Manager.AddCommand(new ModloaderCommand()); | ||
} | ||
|
||
|
||
//Get the mod directory | ||
private static DirectoryInfo GETModFolder() | ||
{ | ||
var directoryInfo = new DirectoryInfo(Application.dataPath).Parent; | ||
if (directoryInfo != null) | ||
{ | ||
string path = directoryInfo.FullName; | ||
if (SystemInfo.operatingSystem.Contains("Windows")) | ||
{ | ||
path = path + "\\Mods"; | ||
} | ||
else //Assume linux | ||
{ | ||
path = path + "/Mods"; | ||
} | ||
|
||
return new DirectoryInfo(path); | ||
} | ||
|
||
throw new ModloaderException("Unable to determine the mod folder."); | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class ModloaderException : Exception | ||
{ | ||
public ModloaderException() { } | ||
public ModloaderException(string message) : base(message) { } | ||
public ModloaderException(string message, Exception inner) : base(message, inner) { } | ||
|
||
protected ModloaderException(System.Runtime.Serialization.SerializationInfo info, | ||
System.Runtime.Serialization.StreamingContext context) : base(info, context) { } | ||
} | ||
|
||
public class ModloaderCommand : BaseCommand | ||
{ | ||
public ModloaderCommand() : base("modloader", "modloader") | ||
{ | ||
} | ||
|
||
public override bool Execute(ExecutedCommand command, bool partOfMultiCommand) | ||
{ | ||
if (command.Arguments.Count == 0) | ||
{ | ||
ConsoleWindow3.SendConsoleResponse("Modloader v0.0.0 by juanmuscaria", ConsoleMessageType.SpecialInfo); | ||
ConsoleWindow3.SendConsoleResponse("Use modloader mods to list all installed mods", ConsoleMessageType.SpecialInfo); | ||
} | ||
else | ||
{ | ||
if (command.Arguments[0].ToLower().Equals("mods")) | ||
{ | ||
ConsoleWindow3.SendConsoleResponse("Modloader v0.0.0 by juanmuscaria", ConsoleMessageType.SpecialInfo); | ||
if (Loader.Mods.Count > 0) | ||
{ | ||
foreach (var mod in Loader.Mods) | ||
{ | ||
ConsoleWindow3.SendConsoleResponse("--------------------", ConsoleMessageType.SpecialInfo); | ||
ConsoleWindow3.SendConsoleResponse("Mod name: " + mod.GetType().Assembly.GetName().Name, ConsoleMessageType.SpecialInfo); | ||
ConsoleWindow3.SendConsoleResponse("Mod description: <still not implemented>" , ConsoleMessageType.SpecialInfo); | ||
ConsoleWindow3.SendConsoleResponse("Mod version: " + mod.GetType().Assembly.GetName().Version, ConsoleMessageType.SpecialInfo); | ||
} | ||
ConsoleWindow3.SendConsoleResponse("--------------------", ConsoleMessageType.SpecialInfo); | ||
} | ||
else | ||
{ | ||
ConsoleWindow3.SendConsoleResponse("You have no mod installed :(", ConsoleMessageType.Error); | ||
} | ||
} | ||
else | ||
{ | ||
ConsoleWindow3.SendConsoleResponse("Modloader v0.0.0 by juanmuscaria", ConsoleMessageType.SpecialInfo); | ||
ConsoleWindow3.SendConsoleResponse("Unknown subcommand " + command.Arguments[0].ToLower(), ConsoleMessageType.Error); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.