Skip to content

Commit

Permalink
Migrated to UMM and renamed the project.
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmuscaria committed Sep 5, 2021
0 parents commit 8c4c92e
Show file tree
Hide file tree
Showing 34 changed files with 1,467 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
/DuskersModloader.sln.DotSettings.user
/libs/
/.idea/
/Tainted/*
/.vs/
/DuskersSimpleModdingFramework.sln.DotSettings.user
96 changes: 96 additions & 0 deletions DSMFramework/DSMFramework.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?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>{65C06865-5AA3-42C9-B905-D7BEBEEADBFC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DSMFramework</RootNamespace>
<AssemblyName>DSMFramework</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.2.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\libs\0Harmony.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\libs\Assembly-CSharp.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\libs\Assembly-CSharp-firstpass.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\libs\UnityEngine.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\libs\UnityEngine.UI.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityModManager, Version=0.23.5.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\libs\UnityModManager.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Loader.cs" />
<Compile Include="Modding\Commands.cs" />
<Compile Include="Modding\ModUpgradeManager.cs" />
<Compile Include="Modding\ModGameEventManager.cs" />
<Compile Include="Modding\XmlHelper.cs" />
<Compile Include="Patches\DroneManager\RandomlyChooseUpgrades.cs" />
<Compile Include="Patches\DroneUpgradeFactory\CreateUpgradeInstance.cs" />
<Compile Include="Patches\DroneUpgradeFactory\Initialize.cs" />
<Compile Include="Patches\GameFileHelper\GetBaseGameFileLocation.cs" />
<Compile Include="Patches\GameplayManager\Start.cs" />
<Compile Include="Patches\ModificationsHelper\LoadModifications.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Info.json" />
</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">
<Copy SourceFiles="Info.json" DestinationFolder="$(TargetDir)\packing" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(TargetDir)\DSMFramework.dll" DestinationFolder="$(TargetDir)\packing" SkipUnchangedFiles="true" />
<ZipDirectory SourceDirectory="$(TargetDir)\packing" DestinationFile="$(TargetDir)\DSMFramework.zip" Overwrite="true" />
</Target>




</Project>
7 changes: 7 additions & 0 deletions DSMFramework/Info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Id": "DSMFramework",
"DisplayName": "Duskers Simple Modding Framework",
"Author": "juanmuscaria",
"Version": "0.1",
"EntryMethod": "DSMFramework.Loader.Load"
}
79 changes: 79 additions & 0 deletions DSMFramework/Loader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using DSMFramework.Modding;
using HarmonyLib;
using UnityModManagerNet;

namespace DSMFramework
{
public static class Loader
{
public const string ModLoaderVersion = "0.1.*";
public const string UniqueModloaderIdent = "-Modded";


static void Load(UnityModManager.ModEntry modEntry)
{
//Load our patches
var harmony = new Harmony("com.juanmuscaria.DSMFramework");
harmony.PatchAll();


CommandManager.Manager.AddCommand(new DsmfCommand());
}

}

public class DsmfCommand : BaseCommand
{
public DsmfCommand() : base("dsmf", "dsmf <subcommand>")
{
}

public override bool Execute(ExecutedCommand command, bool partOfMultiCommand)
{
if (command.Arguments.Count == 0)
{
ConsoleWindow3.SendConsoleResponse($"Duskers Simple Modding Framework v{Loader.ModLoaderVersion} by juanmuscaria",
ConsoleMessageType.SpecialInfo);
ConsoleWindow3.SendConsoleResponse("Use dsmf mods to list all loaded mods",
ConsoleMessageType.SpecialInfo);
}
else
{
// if (command.Arguments[0].ToLower().Equals("mods"))
// {
// ConsoleWindow3.SendConsoleResponse($"Modloader v{Loader.MOD_LOADER_VERSION} by juanmuscaria",
// ConsoleMessageType.SpecialInfo);
// if (Loader.LoadedMods.Count > 0)
// {
// foreach (var mod in Loader.LoadedMods)
// {
// var info = ModInfo.OfMod(mod);
// ConsoleWindow3.SendConsoleResponse("--------------------", ConsoleMessageType.SpecialInfo);
// ConsoleWindow3.SendConsoleResponse($"Mod name: {info.name}",
// ConsoleMessageType.SpecialInfo);
// ConsoleWindow3.SendConsoleResponse($"Mod description: {info.description}",
// ConsoleMessageType.SpecialInfo);
// ConsoleWindow3.SendConsoleResponse($"Mod version: {info.version}",
// ConsoleMessageType.SpecialInfo);
// }
//
// ConsoleWindow3.SendConsoleResponse("--------------------", ConsoleMessageType.SpecialInfo);
// }
// else
// {
// ConsoleWindow3.SendConsoleResponse("You have no mod installed :(", ConsoleMessageType.Error);
// }
// }
// else
{
ConsoleWindow3.SendConsoleResponse($"Modloader v{Loader.ModLoaderVersion} by juanmuscaria",
ConsoleMessageType.SpecialInfo);
ConsoleWindow3.SendConsoleResponse("Unknown subcommand " + command.Arguments[0].ToLower(),
ConsoleMessageType.Error);
}
}

return true;
}
}
}
76 changes: 76 additions & 0 deletions DSMFramework/Modding/Commands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Collections.Generic;
using System.Linq;

namespace DSMFramework.Modding
{
public class CommandManager : ICommandable
{
/// <summary>
/// The global instance of CommandManager
/// </summary>
public static readonly CommandManager Manager = new CommandManager();

private readonly List<BaseCommand> _commands = new List<BaseCommand>();

private CommandManager()
{
}

public List<CommandDefinition> QueryAvailableCommands()
{
return _commands.Cast<CommandDefinition>().ToList();
}

public List<CommandDefinition> QueryContextCommands()
{
return new List<CommandDefinition>();
}

public void ExecuteCommand(ExecutedCommand command, bool partOfMultiCommand)
{
if (command.Command is BaseCommand)
{
var commandToRun = (BaseCommand) command.Command;
command.Handled = commandToRun.Execute(command, partOfMultiCommand);
}
}

public List<CommandDefinition> QueryDeveloperSpecialCaseCommands()
{
return new List<CommandDefinition>();
}

public string CommandHeader => "";
public bool IsPrimaryCommandContext { get; set; }

/// <summary>
/// Adds your custom command into the game.
/// </summary>
/// <param name="command">You command instance</param>
public void AddCommand(BaseCommand command)
{
_commands.Add(command);
}
}

/// <summary>
/// An base class that custom mod commands must extend.
/// </summary>
public abstract class BaseCommand : CommandDefinition
{
protected BaseCommand(string name, string usage) : base(name, usage)
{
}

/// <summary>
/// This method is executed when your command is called by the user
/// </summary>
/// <param name="command">The context of the current executed command</param>
/// <param name="partOfMultiCommand">true if the command is part of a multi command execution</param>
/// <returns>
/// true if the command was handled. returning false will continue the search for any other command matching the
/// same name
/// </returns>
public abstract bool Execute(ExecutedCommand command, bool partOfMultiCommand);
}
}
41 changes: 41 additions & 0 deletions DSMFramework/Modding/ModGameEventManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace DSMFramework.Modding
{
public class ModGameEventManager
{
/// <summary>
/// The global instance of ModGameEventManager
/// </summary>
public static readonly ModGameEventManager Manager = new ModGameEventManager();

private readonly List<Type> events = new List<Type>();

private ModGameEventManager()
{
}

/// <summary>
/// Registers your custom random event into the game!
/// </summary>
/// <param name="eventType">Your event class, it must extend BaseGameEvent and have a public empty constructor</param>
/// <exception cref="ArgumentException">If the class does not extend BaseGameEvent or no public constructor found</exception>
public void RegisterEvent(Type eventType)
{
if (!typeof(BaseGameEvent).IsAssignableFrom(eventType))
throw new ArgumentException("Event type does not extend BaseGameEvent");
if (eventType.GetConstructor(Type.EmptyTypes) == null)
throw new ArgumentException("No public empty constructor found!");
events.Add(eventType);
}

[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
internal void InjectEventsInto(GameEventManager manager)
{
foreach (var @event in events)
manager.AddEvent((BaseGameEvent) @event.GetConstructor(Type.EmptyTypes).Invoke(null));
}
}
}
Loading

0 comments on commit 8c4c92e

Please sign in to comment.