Skip to content

Commit 669b194

Browse files
committed
Adapt to new MonkeyLoader updates
1 parent 34dd37f commit 669b194

6 files changed

Lines changed: 181 additions & 55 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,56 @@
11
name: CI
22

3-
on: [push]
3+
# Trigger the action on push to master
4+
on:
5+
push:
6+
branches:
7+
- master
48

5-
env:
6-
ResonitePath: "${{ github.workspace }}/Resonite"
9+
# Sets permissions of the GITHUB_TOKEN to allow reading packages and writing to GH pages
10+
permissions:
11+
actions: read
12+
pages: write
13+
id-token: write
14+
packages: read
15+
16+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
17+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
18+
concurrency:
19+
group: "ci"
20+
cancel-in-progress: false
721

822
jobs:
9-
ci:
23+
publish-docs:
24+
environment:
25+
name: github-pages
26+
url: ${{ steps.deployment.outputs.page_url }}
1027
runs-on: ubuntu-latest
11-
1228
steps:
13-
- uses: actions/checkout@v4
14-
- name: Get Resonite Infos
15-
run: |
16-
{
17-
echo "APP_INFO<<EOFEOF"
18-
curl https://api.steamcmd.net/v1/info/2519830
19-
echo ""
20-
echo "EOFEOF"
21-
} >> "$GITHUB_ENV"
22-
- name: Get Resonite from Cache
23-
id: cache-resonite
24-
uses: actions/cache@v3
25-
with:
26-
path: "${{ env.ResonitePath }}"
27-
key: "${{ fromJson( env.APP_INFO ).data['2519830'].depots.branches.public.buildid }}"
28-
- name: Download Steam
29-
if: steps.cache-resonite.outputs.cache-hit != 'true'
30-
uses: CyberAndrii/setup-steamcmd@b786e0da44db3d817e66fa3910a9560cb28c9323
31-
- name: Download Resonite
32-
if: steps.cache-resonite.outputs.cache-hit != 'true'
33-
run: |
34-
steamcmd '+@sSteamCmdForcePlatformType windows' '+force_install_dir "${{ env.ResonitePath }}"' '+login "${{ secrets.STEAM_USER }}" "${{ secrets.STEAM_TOKEN }}"' '+app_license_request 2519830' '+app_update 2519830 validate' '+quit'
35-
#The following line makes the cache much much smaller:
36-
rm -r '${{ env.ResonitePath }}/RuntimeData/PreCache'
37-
- name: Setup dotnet
38-
uses: actions/setup-dotnet@v3
39-
with:
40-
dotnet-version: '6.x'
41-
- uses: actions/cache@v3
42-
with:
43-
path: ~/.nuget/packages
44-
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
45-
restore-keys: |
46-
${{ runner.os }}-nuget
47-
- name: Install dependencies
48-
run: dotnet restore
49-
- name: Build
50-
run: dotnet build
51-
- name: Test
52-
run: dotnet test
29+
# Setup environment
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
- name: Dotnet Setup
33+
uses: actions/setup-dotnet@v3
34+
with:
35+
dotnet-version: 8.x
36+
source-url: https://nuget.pkg.github.com/MonkeyModdingTroop/index.json
37+
env:
38+
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
40+
# Cache NuGet packages
41+
- uses: actions/cache@v3
42+
with:
43+
path: ~/.nuget/packages
44+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
45+
restore-keys: |
46+
${{ runner.os }}-nuget
47+
48+
# Build and test projects
49+
- name: Install dependencies
50+
run: dotnet restore
51+
52+
- name: Build
53+
run: dotnet build
54+
55+
- name: Test
56+
run: dotnet test

FlexibleContactsSort/ExtraContactColoring.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ namespace FlexibleContactsSort
1616
[HarmonyPatch(typeof(LegacyUIStyle), nameof(LegacyUIStyle.GetStatusColor))]
1717
internal sealed class ExtraContactColoring : ResoniteMonkey<ExtraContactColoring>
1818
{
19+
public override bool CanBeDisabled => true;
1920
public override string Name { get; } = "ExtraContactColoring";
2021

2122
protected override IEnumerable<IFeaturePatch> GetFeaturePatches() => Enumerable.Empty<IFeaturePatch>();
2223

2324
private static void Postfix(Contact contact, ContactData status, bool text, ref colorX __result)
2425
{
25-
if (contact.ContactStatus == ContactStatus.Accepted && !contact.IsAccepted)
26+
if (Enabled && contact.ContactStatus == ContactStatus.Accepted && !contact.IsAccepted)
2627
__result = text ? RadiantUI_Constants.Hero.YELLOW : RadiantUI_Constants.MidLight.YELLOW;
2728
}
2829
}

FlexibleContactsSort/FlexibleContactSorting.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ internal sealed class FlexibleContactSorting : ConfiguredResoniteMonkey<Flexible
2020

2121
private static readonly ConditionalWeakTable<ContactItem, ReadMessageTracker> _contactReadMessageTrackers = new();
2222

23+
public override bool CanBeDisabled => true;
24+
2325
internal static int Compare((ContactData?, bool) contactSortInfo1, (ContactData?, bool) contactSortInfo2)
2426
{
2527
var contact1 = contactSortInfo1.Item1?.Contact;
@@ -139,9 +141,15 @@ private static void OnCommonUpdatePostfix(ContactsDialog __instance, bool __stat
139141
[HarmonyPatch(nameof(ContactsDialog.OnCommonUpdate))]
140142
private static void OnCommonUpdatePrefix(ContactsDialog __instance, out bool __state)
141143
{
144+
if (!Enabled)
145+
{
146+
__state = false;
147+
return;
148+
}
149+
142150
// steal the sortList bool's value, and force it to false from Resonite's perspective
143151
__state = __instance.sortList;
144-
__instance.sortList = false;
152+
__instance.sortList &= !Enabled;
145153
}
146154

147155
[HarmonyPostfix]

FlexibleContactsSort/FlexibleContactsSort.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageId>FlexibleContactSorting</PackageId>
1212
<Title>Flexible Contact Sorting</Title>
1313
<Authors>Banane9</Authors>
14-
<Version>0.3.0-beta</Version>
14+
<Version>0.4.0-beta</Version>
1515
<Description>This MonkeyLoader mod for Resonite allows sorting contacts flexibly and to your liking, including pinning your favorites to the top.</Description>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>
1717
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
@@ -42,14 +42,14 @@
4242
</ItemGroup>
4343

4444
<ItemGroup>
45-
<PackageReference Include="MonkeyLoader" Version="0.11.0-beta" />
46-
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" Version="0.10.1-beta" />
45+
<PackageReference Include="MonkeyLoader" Version="0.15.0-beta" />
46+
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" Version="0.13.0-beta" />
4747
<PackageReference Include="PolySharp" Version="1.14.1">
4848
<PrivateAssets>all</PrivateAssets>
4949
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5050
</PackageReference>
5151
<PackageReference Include="Resonite.Elements.Core" Version="1.0.2" />
52-
<PackageReference Include="Resonite.FrooxEngine" Version="2024.3.3.1178" />
52+
<PackageReference Include="Resonite.FrooxEngine" Version="2024.4.17.1407" />
5353
<PackageReference Include="Resonite.SkyFrost.Base" Version="1.0.2" />
5454
<PackageReference Include="System.Text.Json" Version="8.0.2">
5555
<PrivateAssets>all</PrivateAssets>

FlexibleContactsSort/LagFreeContactsLoading.cs

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Elements.Core;
1+
using Elements.Assets;
22
using FrooxEngine;
33
using HarmonyLib;
44
using MonkeyLoader.Patching;
@@ -20,6 +20,7 @@ internal sealed class LagFreeContactsLoading : ResoniteMonkey<LagFreeContactsLoa
2020
{
2121
private const int ContactsPerUpdate = 8;
2222

23+
public override bool CanBeDisabled => true;
2324
internal static bool AllowSorting { get; private set; } = true;
2425

2526
protected override IEnumerable<IFeaturePatch> GetFeaturePatches() => Enumerable.Empty<IFeaturePatch>();
@@ -43,22 +44,39 @@ private static void AddContactItems(ContactsDialog contactsDialog)
4344
var segments = contactsSortInfo.Length / ContactsPerUpdate;
4445
for (var segment = 0; segment < segments; ++segment)
4546
{
46-
for (var i = 0; i <= ContactsPerUpdate; ++i)
47-
contactsDialog.UpdateContactItem(contactsSortInfo[ContactsPerUpdate * segment + i].contactData);
47+
for (var i = 0; i < ContactsPerUpdate; ++i)
48+
contactsDialog.UpdateContactItem(contactsSortInfo[(ContactsPerUpdate * segment) + i].contactData);
4849

4950
await default(NextUpdate);
5051
}
5152

5253
for (var i = segments * ContactsPerUpdate; i < contactsSortInfo.Length; ++i)
5354
contactsDialog.UpdateContactItem(contactsSortInfo[i].contactData);
5455

56+
await default(NextUpdate);
57+
5558
AllowSorting = true;
5659
});
5760

61+
private static void AddSearchResult(ContactsDialog contactsDialog, SkyFrost.Base.User user)
62+
{
63+
if (contactsDialog._contactItems.ContainsKey(user.Id)
64+
|| contactsDialog._searchResultItems.Any(item => item.Contact.ContactUserId == user.Id)
65+
|| user.Id == contactsDialog.Cloud.CurrentUserID)
66+
return;
67+
68+
var contactItem = contactsDialog.AddContactItem();
69+
contactItem.Update(user);
70+
contactsDialog._searchResultItems.Add(contactItem);
71+
}
72+
5873
[HarmonyTranspiler]
59-
[HarmonyPatch("OnAttach")]
74+
[HarmonyPatch(nameof(ContactsDialog.OnAttach))]
6075
private static IEnumerable<CodeInstruction> OnAttachTranspiler(IEnumerable<CodeInstruction> instructionsEnumerable)
6176
{
77+
if (!Enabled)
78+
return instructionsEnumerable;
79+
6280
var foreachContactDataMethod = AccessTools.Method(typeof(ContactManager), nameof(ContactManager.ForeachContactData));
6381
var addContactItemsMethod = AccessTools.Method(typeof(LagFreeContactsLoading), nameof(AddContactItems));
6482

@@ -71,5 +89,95 @@ private static IEnumerable<CodeInstruction> OnAttachTranspiler(IEnumerable<CodeI
7189

7290
return instructions;
7391
}
92+
93+
private static bool RemoveItem(ContactItem contact, string? searchTerm, bool clear)
94+
{
95+
if (clear || !(contact.Username.StartsWith(searchTerm)
96+
|| contact.AlternateNames.Any(name => name.StartsWith(searchTerm, StringComparison.InvariantCulture))))
97+
{
98+
contact.Slot.Destroy();
99+
return true;
100+
}
101+
102+
return false;
103+
}
104+
105+
[HarmonyPrefix]
106+
[HarmonyPatch(nameof(ContactsDialog.SearchTextChanged))]
107+
private static bool SearchTextChangedPrefix(ContactsDialog __instance, TextEditor editor)
108+
{
109+
if (!Enabled)
110+
return true;
111+
112+
__instance.StartTask(async () =>
113+
{
114+
var searchTerm = editor.TargetString?.Trim().ToLower();
115+
var clear = string.IsNullOrWhiteSpace(searchTerm);
116+
117+
var segments = __instance._searchResultItems.Count / ContactsPerUpdate;
118+
119+
for (var i = __instance._searchResultItems.Count - 1; i >= segments * ContactsPerUpdate; --i)
120+
{
121+
if (RemoveItem(__instance._searchResultItems[i], searchTerm, clear))
122+
__instance._searchResultItems.RemoveAt(i);
123+
}
124+
125+
for (var segment = segments - 1; segment >= 0; --segment)
126+
{
127+
await default(NextUpdate);
128+
129+
for (var i = ContactsPerUpdate - 1; i >= 0; --i)
130+
{
131+
var x = (ContactsPerUpdate * segment) + i;
132+
133+
if (RemoveItem(__instance._searchResultItems[x], searchTerm, clear))
134+
__instance._searchResultItems.RemoveAt(x);
135+
}
136+
}
137+
138+
await default(NextUpdate);
139+
140+
foreach (var contactItem in __instance._contactItems)
141+
{
142+
contactItem.Value.Slot.ActiveSelf = clear
143+
|| contactItem.Value.Username.StartsWith(searchTerm, StringComparison.InvariantCultureIgnoreCase)
144+
|| contactItem.Value.AlternateNames.Any(name => name.StartsWith(searchTerm, StringComparison.InvariantCulture));
145+
}
146+
});
147+
148+
__instance.globalSearchTimer = 0.5;
149+
150+
return false;
151+
}
152+
153+
[HarmonyPrefix]
154+
[HarmonyPatch(nameof(ContactsDialog.SetSearchResults))]
155+
private static bool SetSearchResultsPrefix(ContactsDialog __instance, List<SkyFrost.Base.User> users)
156+
{
157+
if (!Enabled)
158+
return true;
159+
160+
__instance.StartTask(async () =>
161+
{
162+
var segments = users.Count / ContactsPerUpdate;
163+
164+
for (var segment = 0; segment < segments; ++segment)
165+
{
166+
for (var i = 0; i < ContactsPerUpdate; ++i)
167+
AddSearchResult(__instance, users[(ContactsPerUpdate * segment) + i]);
168+
169+
await default(NextUpdate);
170+
}
171+
172+
for (var i = segments * ContactsPerUpdate; i < users.Count; ++i)
173+
AddSearchResult(__instance, users[i]);
174+
175+
await default(NextUpdate);
176+
177+
__instance.sortList = true;
178+
});
179+
180+
return false;
181+
}
74182
}
75183
}

FlexibleContactsSort/SessionUserCapacity.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ namespace FlexibleContactsSort
1616
[HarmonyPatch(typeof(SessionItem), nameof(SessionItem.Update))]
1717
internal sealed class SessionUserCapacity : ConfiguredResoniteMonkey<SessionUserCapacity, SessionCapacityConfig>
1818
{
19+
public override bool CanBeDisabled => true;
20+
1921
protected override IEnumerable<IFeaturePatch> GetFeaturePatches() => Enumerable.Empty<IFeaturePatch>();
2022

2123
private static void Postfix(SessionItem __instance, SessionInfo session)
2224
{
25+
if (!Enabled)
26+
return;
27+
2328
var format = "{0} ({1})";
2429

2530
if (ConfigSection.ShowUserCapacityInSessionList)

0 commit comments

Comments
 (0)