Skip to content

Commit

Permalink
Proc Type API (#513)
Browse files Browse the repository at this point in the history
* ive got a bad feeling about this

* worst mistakes

* network settings and IL fix

* hashing and clean up

* memorize tests and optimization

* basic documentation and get modded mask overload

* add stripped patch

* update hash function

* basic readme

* doktor, turn off my memory inhibitors

switch underlying data from bool[] to byte[], add GetRaw versions of public mask access

* some internal documentation

* documentation and ts updates

* fix patcher encapsulation

* Improvements to ProcTypeAPI

---------

Co-authored-by: KingEnderBrine <kingenderbrin@gmail.com>
  • Loading branch information
Priscillalala and KingEnderBrine authored Nov 8, 2024
1 parent 4133383 commit c5f864e
Show file tree
Hide file tree
Showing 14 changed files with 704 additions and 0 deletions.
13 changes: 13 additions & 0 deletions R2API.ProcType.Interop/ProcTypeInterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using RoR2;
using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo("R2API.ProcType")]

namespace R2API;

internal static class ProcTypeInterop
{
public static byte[] GetModdedMask(ProcChainMask procChainMask) => procChainMask.r2api_moddedMask;

public static void SetModdedMask(ref ProcChainMask procChainMask, byte[] value) => procChainMask.r2api_moddedMask = value;
}
13 changes: 13 additions & 0 deletions R2API.ProcType.Interop/R2API.ProcType.Interop.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>annotations</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);NU5104</NoWarn>
<RootNamespace>R2API</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\RoR2.Patched\RoR2.Patched.csproj" Private="false" PrivateAssets="all"/>
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions R2API.ProcType.Patcher/ProcTypePatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using BepInEx;
using BepInEx.Logging;
using Mono.Cecil;
using System.Collections.Generic;

namespace R2API;

internal static class ProcTypePatcher
{
public static IEnumerable<string> TargetDLLs
{
get
{
yield return "RoR2.dll";
}
}

public static void Patch(AssemblyDefinition assembly)
{
TypeDefinition procChainMask = assembly.MainModule.GetType("RoR2", "ProcChainMask");
procChainMask?.Fields.Add(new FieldDefinition("r2api_moddedMask", FieldAttributes.Public, assembly.MainModule.ImportReference(typeof(byte[]))));
}
}
14 changes: 14 additions & 0 deletions R2API.ProcType.Patcher/R2API.ProcType.Patcher.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>annotations</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);NU5104</NoWarn>
<RootNamespace>R2API</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Core" Version="5.4.19" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions R2API.ProcType/ModdedProcType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using RoR2;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

namespace R2API;

/// <summary>
/// A modded equivalent of <see cref="ProcType"/> for use with <see cref="ProcTypeAPI"/>.
/// </summary>
public enum ModdedProcType : int
{
/// <summary>
/// Represents an invalid value of <see cref="ModdedProcType"/>.
/// </summary>
/// <remarks>All negative values of <see cref="ModdedProcType"/> are considered invalid.</remarks>
Invalid = -1
}
Loading

0 comments on commit c5f864e

Please sign in to comment.