Skip to content

Commit

Permalink
Merge pull request #9 from All-Of-Us-Mods/dev
Browse files Browse the repository at this point in the history
0.1.3 Changes
  • Loading branch information
ang-xd authored Aug 29, 2024
2 parents bdce8fa + ab5f997 commit 56c2d9c
Show file tree
Hide file tree
Showing 30 changed files with 920 additions and 216 deletions.
31 changes: 28 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
name: CI

on: workflow_dispatch
on: ["workflow_dispatch", "push", "pull_request"]

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true

- uses: actions/cache@v3
with:
path: |
~/.nuget/packages
~/.cache/bepinex
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.x
dotnet-version: 8.0.x

- name: Run the Cake script
uses: cake-build/cake-action@v2
Expand All @@ -24,3 +33,19 @@ jobs:
with:
name: MiraAPI.dll
path: MiraAPI/bin/Release/net6.0/MiraAPI.dll

- uses: actions/upload-artifact@v3
with:
name: AllOfUs.MiraAPI.nupkg
path: MiraAPI/bin/Release/AllOfUs.MiraAPI.*.nupkg

- uses: softprops/action-gh-release@v1
if: github.ref_type == 'tag'
with:
draft: true
files: MiraAPI/bin/Release/net6.0/MiraAPI.dll

- name: Push NuGet package
if: github.repository == 'All-Of-Us-Mods/MiraAPI' && github.ref == 'refs/heads/master' && github.ref_type == 'tag'
run: |
dotnet nuget push {MiraAPI/bin/Release/AllOfUs.MiraAPI.*.nupkg} --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
obj/
bin/

*.user
*.user
*.lock.json
14 changes: 14 additions & 0 deletions AmongUs.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<ItemGroup>
<PackageReference Include="Reactor" Version="2.3.1" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.697" Private="false" ExcludeAssets="runtime;native" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.8.13" PrivateAssets="all" />

<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.0.1" PrivateAssets="all" ExcludeAssets="runtime" />
</ItemGroup>

<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUs)/BepInEx/plugins/" UseSymboliclinksIfPossible="true" />
</Target>
</Project>
40 changes: 40 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<DebugType>embedded</DebugType>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>

<VersionPrefix>0.1.3</VersionPrefix>
<VersionSuffix>dev</VersionSuffix>

<Authors>All Of Us, XtraCube, Angxl</Authors>
<Company>All Of Us</Company>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/All-Of-Us-Mods/MiraAPI</RepositoryUrl>
<PackageLicenseExpression>LGPL-2.1-or-later</PackageLicenseExpression>

<!-- SourceLink -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
</PropertyGroup>

<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>recommended</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="all" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)\stylecop.json" Link="stylecop.json" Visible="false" />
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)\stylecop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion MiraAPI.Example/Buttons/Freezer/FreezeButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FreezeButton : CustomActionButton<PlayerControl>

protected override void OnClick()
{
Target.AddModifier<FreezeModifier>();
Target?.RpcAddModifier<FreezeModifier>();
}

public override PlayerControl GetTarget()
Expand Down
2 changes: 1 addition & 1 deletion MiraAPI.Example/Buttons/MeetingButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override void OnClick()

if (UsesLeft == 0 && PlayerControl.LocalPlayer.HasModifier<CaptainModifier>())
{
PlayerControl.LocalPlayer.RemoveModifier<CaptainModifier>();
PlayerControl.LocalPlayer.RpcRemoveModifier<CaptainModifier>();
}
}
}
2 changes: 1 addition & 1 deletion MiraAPI.Example/Buttons/Teleporter/TeleportButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TeleportButton : CustomActionButton

public override int MaxUses => 0;

public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
public override LoadableAsset<Sprite> Sprite => ExampleAssets.TeleportButton;
public static bool IsZoom { get; private set; }

public override bool Enabled(RoleBehaviour role)
Expand Down
3 changes: 3 additions & 0 deletions MiraAPI.Example/ExampleAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ namespace MiraAPI.Example;
public static class ExampleAssets
{
public static LoadableResourceAsset ExampleButton { get; } = new("MiraAPI.Example.Resources.ExampleButton.png");

// Credit to EpicHorrors for the teleport button asset.
public static LoadableResourceAsset TeleportButton { get; } = new("MiraAPI.Example.Resources.TeleportButton.png");
public static LoadableResourceAsset Banner { get; } = new("MiraAPI.Example.Resources.FortniteBanner.jpeg");
}
25 changes: 4 additions & 21 deletions MiraAPI.Example/MiraAPI.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<DebugType>embedded</DebugType>

<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>dev</VersionSuffix>
<Version>1.0.0</Version>
<Description>Example mod for Mira API</Description>
<Authors>Angxl, XtraCube</Authors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Reactor" Version="2.3.1" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.697" Private="false" ExcludeAssets="runtime;native" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.8.13" PrivateAssets="all" />

<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.1.0-rc.1" PrivateAssets="all" ExcludeAssets="runtime">
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MiraAPI\MiraAPI.csproj" />
Expand All @@ -28,9 +12,8 @@
<ItemGroup>
<EmbeddedResource Include="Resources\ExampleButton.png" />
<EmbeddedResource Include="Resources\FortniteBanner.jpeg" />
<EmbeddedResource Include="Resources\TeleportButton.png" />
</ItemGroup>

<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUs)/BepInEx/plugins/" UseSymboliclinksIfPossible="true" />
</Target>
<Import Project="..\AmongUs.props" />
</Project>
12 changes: 6 additions & 6 deletions MiraAPI.Example/Options/ExampleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class ExampleOptions : AbstractOptionGroup
[ModdedStringOption("String Opt", ["Hello", "Hey", "Bye"])]
public int StringOpt { get; set; } = 2;

[ModdedEnumOption("Enum Opt", typeof(TestEnum))]
public TestEnum EnumOpt { get; set; } = TestEnum.Mira;
[ModdedEnumOption("Best API", typeof(BestApiEnum), ["Mira API", "Mitochondria", "Reactor"])]
public BestApiEnum EnumOpt { get; set; } = BestApiEnum.MiraAPI;
}

public enum TestEnum
public enum BestApiEnum
{
Welcome,
To,
Mira
MiraAPI,
Mitochondria,
Reactor
}
Binary file added MiraAPI.Example/Resources/TeleportButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion MiraAPI.Example/Roles/FreezerRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public class FreezerRole : ImpostorRole, ICustomRole
public Color RoleColor => Palette.Blue;
public ModdedRoleTeams Team => ModdedRoleTeams.Impostor;
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;

public int MaxPlayers => 2;
}
4 changes: 2 additions & 2 deletions MiraAPI/GameOptions/Attributes/ModdedEnumOptionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace MiraAPI.GameOptions.Attributes;

public class ModdedEnumOptionAttribute(string title, Type enumType, Type roleType = null)
public class ModdedEnumOptionAttribute(string title, Type enumType, string[] values = null, Type roleType = null)

Check warning on line 7 in MiraAPI/GameOptions/Attributes/ModdedEnumOptionAttribute.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 7 in MiraAPI/GameOptions/Attributes/ModdedEnumOptionAttribute.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 7 in MiraAPI/GameOptions/Attributes/ModdedEnumOptionAttribute.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 7 in MiraAPI/GameOptions/Attributes/ModdedEnumOptionAttribute.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
: ModdedOptionAttribute(title, roleType)
{
internal override IModdedOption CreateOption(object value, PropertyInfo property)
{
var opt = new ModdedEnumOption(Title, (int)value, enumType, RoleType);
var opt = new ModdedEnumOption(Title, (int)value, enumType, values, RoleType);
return opt;
}

Expand Down
16 changes: 15 additions & 1 deletion MiraAPI/GameOptions/ModdedOptionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ internal static void SyncAllOptions(int targetId=-1)

internal static void HandleSyncOptions(NetData[] data)
{
// necessary to disable then re-enable this setting
// we dont know how other plugins handle their configs
// this way, all the options are saved at once, instead of one by one
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins.Values)
{
plugin.PluginConfig.SaveOnConfigSet = false;
}

foreach (var netData in data)
{
if (!ModdedOptions.TryGetValue(netData.Id, out var option))
Expand All @@ -129,7 +137,13 @@ internal static void HandleSyncOptions(NetData[] data)

option.HandleNetData(netData.Data);
}


foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins.Values)
{
plugin.PluginConfig.Save();
plugin.PluginConfig.SaveOnConfigSet = true;
}

if (LobbyInfoPane.Instance)
{
LobbyInfoPane.Instance.RefreshPane();
Expand Down
17 changes: 10 additions & 7 deletions MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Reactor.Localization.Utilities;
using MiraAPI.Networking;
using Reactor.Localization.Utilities;
using System;
using System.Linq;
using MiraAPI.Networking;
using UnityEngine;
using Object = UnityEngine.Object;

Expand All @@ -11,15 +11,18 @@ public class ModdedEnumOption : ModdedOption<int>
{
public string[] Values { get; }

public ModdedEnumOption(string title, int defaultValue, Type enumType, Type roleType=null) : base(title, defaultValue, roleType)
public ModdedEnumOption(string title, int defaultValue, Type enumType, string[] values = null, Type roleType = null) : base(title, defaultValue, roleType)
{
Values = Enum.GetNames(enumType);
Values = values is null ? Enum.GetNames(enumType) : values;
Data = ScriptableObject.CreateInstance<StringGameSetting>();
var data = (StringGameSetting)Data;

data.Title = StringName;
data.Type = global::OptionTypes.String;
data.Values = Values.Select(CustomStringName.CreateAndRegister).ToArray();
data.Values = values is null ?
Enum.GetNames(enumType).Select(CustomStringName.CreateAndRegister).ToArray()
: values.Select(CustomStringName.CreateAndRegister).ToArray();

data.Index = Value;
}

Expand All @@ -29,7 +32,7 @@ public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOptio

stringOption.SetUpFromData(Data, 20);
stringOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;

// SetUpFromData method doesnt work correctly so we must set the values manually
stringOption.Title = StringName;
stringOption.Values = ((StringGameSetting)Data).Values;
Expand Down
10 changes: 5 additions & 5 deletions MiraAPI/GameOptions/OptionTypes/ModdedOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public void SetValue(T newValue)

if (AmongUsClient.Instance.AmHost)
{
if (ParentMod?.GetConfigFile().TryGetEntry<T>(ConfigDefinition, out var entry) == true)
{
entry.Value = Value;
}

Rpc<SyncOptionsRpc>.Instance.Send(PlayerControl.LocalPlayer, [GetNetData()], true);
}

if (ParentMod?.GetConfigFile().TryGetEntry<T>(ConfigDefinition, out var entry) == true)
{
entry.Value = Value;
}

OnValueChanged(newValue);
}

Expand Down
Loading

0 comments on commit 56c2d9c

Please sign in to comment.