Skip to content

Commit 19de186

Browse files
committed
Merge branch 'upcoming' into upcoming-nuget-release
2 parents 5ac35bc + c4c1ee9 commit 19de186

9 files changed

Lines changed: 57 additions & 41 deletions

File tree

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"dotnet-ilverify": {
6-
"version": "5.0.0",
6+
"version": "9.0.0",
77
"commands": [
88
"ilverify"
99
]

OTAPI.Patcher/Common.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License
2323
using System.Linq;
2424
using System.Net.Http;
2525
using System.Reflection;
26+
using System.Threading.Tasks;
2627

2728
namespace OTAPI.Patcher;
2829

@@ -59,7 +60,7 @@ public static void Log(string message)
5960
return null;
6061
}
6162

62-
public static string DownloadZip(string url)
63+
public static async Task<string> DownloadZipAsync(string url)
6364
{
6465
Console.WriteLine($"Downloading {url}");
6566
var uri = new Uri(url);
@@ -71,7 +72,7 @@ public static string DownloadZip(string url)
7172
if (!File.Exists(savePath))
7273
{
7374
using var client = new HttpClient();
74-
var data = client.GetByteArrayAsync(url).Result;
75+
var data = await client.GetByteArrayAsync(url);
7576
File.WriteAllBytes(savePath, data);
7677
}
7778

OTAPI.Patcher/OTAPI.Patcher.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net9.0</TargetFramework>
6-
<Version>3.2.3</Version>
6+
<Version>3.2.4</Version>
77
<PreserveCompilationContext>true</PreserveCompilationContext>
88
<RuntimeIdentifiers>win;osx;linux;</RuntimeIdentifiers>
99
<Nullable>enable</Nullable>

OTAPI.Patcher/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ You should have received a copy of the GNU General Public License
1717
along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20+
using System.Threading.Tasks;
21+
2022
namespace OTAPI.Patcher;
2123

2224
[MonoMod.MonoModIgnore]
2325
static class Program
2426
{
25-
static void Main(string[] args)
27+
static async Task Main(string[] args)
2628
{
2729
var target = Targets.PatchTargets.DeterminePatchTarget();
28-
target.Patch();
30+
await target.PatchAsync();
2931
}
3032
}

OTAPI.Patcher/Targets/IPatchTarget.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
2525
using System.Collections.Generic;
2626
using System.IO;
2727
using System.Linq;
28+
using System.Threading.Tasks;
2829
using static ModFramework.ModContext;
2930

3031
namespace OTAPI.Patcher.Targets;
@@ -34,7 +35,7 @@ public interface IPatchTarget
3435
{
3536
string DisplayText { get; }
3637
string InstallDestination { get; }
37-
void Patch();
38+
Task PatchAsync();
3839
}
3940

4041
[MonoMod.MonoModIgnore]

OTAPI.Patcher/Targets/PCClientTarget.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Reflection;
1010
using System.Runtime.Loader;
11+
using System.Threading.Tasks;
1112
using static ModFramework.ModContext;
1213

1314
namespace OTAPI.Patcher.Targets;
@@ -158,7 +159,7 @@ void CopyRequiredLibs(ClientInstallPath<IInstallDiscoverer> discoverer)
158159
}
159160
}
160161

161-
public void Patch()
162+
public Task PatchAsync()
162163
{
163164
Console.WriteLine($"Open Terraria API v{Common.GetVersion()}");
164165

@@ -316,6 +317,7 @@ public void Patch()
316317
InstallModules();
317318

318319
SetStatus("Patching has completed.");
320+
return Task.CompletedTask;
319321
}
320322

321323
void CompileModules(string otapiexe)

OTAPI.Patcher/Targets/PCServerTarget.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Reflection;
1010
using System.Runtime.Loader;
11+
using System.Threading.Tasks;
1112
using static ModFramework.ModContext;
1213

1314
namespace OTAPI.Patcher.Targets;
@@ -38,10 +39,10 @@ public virtual string GetEmbeddedResourcesDirectory(string fileinput)
3839
return Path.Combine(ModContext.BaseDirectory, Path.GetDirectoryName(fileinput));
3940
}
4041

41-
public virtual string DownloadServer()
42+
public virtual async Task<string> DownloadServerAsync()
4243
{
4344
var zipUrl = this.GetZipUrl();
44-
var zipPath = Common.DownloadZip(zipUrl);
45+
var zipPath = await Common.DownloadZipAsync(zipUrl);
4546
var extracted = Common.ExtractZip(zipPath);
4647

4748
return FileResolver.DetermineInputAssembly(extracted);
@@ -77,7 +78,7 @@ public virtual void LoadModifications()
7778
ModContext.PluginLoader.AddFromFolder(Path.Combine(ModContext.BaseDirectory, "modifications"));
7879
}
7980

80-
public void Patch()
81+
public async Task PatchAsync()
8182
{
8283
Console.WriteLine($"Open Terraria API v{Common.GetVersion()}");
8384

@@ -86,7 +87,7 @@ public void Patch()
8687
{
8788
Common.AddMarkdownFormatter();
8889

89-
var vanillaDllPath = DownloadServer();
90+
var vanillaDllPath = await DownloadServerAsync();
9091
var vanillaName = Path.GetFileNameWithoutExtension(vanillaDllPath);
9192

9293
Console.WriteLine("[OTAPI] Extracting embedded binaries and packing into one binary...");
@@ -210,12 +211,15 @@ public void Patch()
210211
mm.Module.GetType("Terraria.NPC").CreateHooks(mm);
211212
mm.Module.GetType("Terraria.WorldGen").CreateHooks(mm);
212213
mm.Module.GetType("Terraria.Chat.ChatHelper").CreateHooks(mm);
214+
mm.Module.GetType("Terraria.GameContent.ItemDropRules.CommonCode").CreateHooks(mm);
213215
mm.Module.GetType("Terraria.IO.WorldFile").CreateHooks(mm);
214216
mm.Module.GetType("Terraria.Net.NetManager").CreateHooks(mm);
215217
mm.Module.GetType("Terraria.Projectile").CreateHooks(mm);
216218
mm.Module.GetType("Terraria.RemoteClient").CreateHooks(mm);
217219
mm.Module.GetType("Terraria.Liquid").CreateHooks(mm);
218220
mm.Module.GetType("Terraria.Program").CreateHooks(mm);
221+
mm.Module.GetType("Terraria.Wiring").CreateHooks(mm);
222+
mm.Module.GetType("Terraria.GameContent.PressurePlateHelper").CreateHooks(mm);
219223
Console.WriteLine("Done");
220224
}
221225
else if (modType == ModType.Write)

OTAPI.Scripts/Mods/HookNpcBossBag.Server.cs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2020 DeathCradle
2+
Copyright (C) 2020-2024 SignatureBeef & sors89
33
44
This file is part of Open Terraria API v3 (OTAPI)
55
@@ -26,46 +26,52 @@ You should have received a copy of the GNU General Public License
2626
using Mono.Cecil.Cil;
2727

2828
/// <summary>
29-
/// @doc Creates Hooks.NPC.BossBag. Allows plugins to cancel boss bag items.
29+
/// @doc Creates Hooks.NPC.BossBag. Allows plugins to customize boss loot as well as the distribution.
3030
/// </summary>
31-
[Modification(ModType.PreMerge, "Hooking npc boss bags")]
31+
[Modification(ModType.PreMerge, "Hooking NPC Boss Bag drops")]
3232
[MonoMod.MonoModIgnore]
3333
void HookNpcBossBag(ModFramework.ModFwModder modder)
3434
{
3535
// replace NewItem calls, and handle the -1 result to cancel the method from actioning.
36-
37-
var csr = modder.GetILCursor(() => (new Terraria.NPC()).DropItemInstanced(default, default, 0, 0, false));
38-
var callback = csr.Module.ImportReference(
36+
foreach (var csr in new[] {
37+
modder.GetILCursor(() => (new Terraria.NPC()).DropItemInstanced(default, default, 0, 0, false)),
38+
modder.GetILCursor(() => Terraria.GameContent.ItemDropRules.CommonCode.DropItemLocalPerClientAndSetNPCMoneyTo0(default, default, default, default))
39+
})
40+
{
41+
var callback = csr.Module.ImportReference(
3942
#if TerrariaServer_EntitySourcesActive || Terraria_EntitySourcesActive || tModLoader_EntitySourcesActive
40-
modder.GetMethodDefinition(() => OTAPI.Hooks.NPC.InvokeBossBag(null, 0, 0, 0, 0, 0, 0, false, 0, false, false, null))
43+
modder.GetMethodDefinition(() => OTAPI.Hooks.NPC.InvokeBossBag(null, 0, 0, 0, 0, 0, 0, false, 0, false, false, null))
4144
#else
42-
modder.GetMethodDefinition(() => OTAPI.Hooks.NPC.InvokeBossBag(0, 0, 0, 0, 0, 0, false, 0, false, false, null))
45+
modder.GetMethodDefinition(() => OTAPI.Hooks.NPC.InvokeBossBag(0, 0, 0, 0, 0, 0, false, 0, false, false, null))
4346
#endif
44-
);
47+
);
4548

46-
var instructions = csr.Body.Instructions.Where(x => x.OpCode == OpCodes.Call
47-
&& x.Operand is MethodReference mref && mref.Name == "NewItem"
48-
&& x.Next.OpCode == OpCodes.Stloc_0);
49+
var instructions = csr.Body.Instructions.Where(x => x.OpCode == OpCodes.Call
50+
&& x.Operand is MethodReference mref && mref.Name == "NewItem"
51+
&& x.Next.OpCode == OpCodes.Stloc_0);
4952

50-
if (instructions.Count() != 1) throw new NotSupportedException("Only one server NewItem call expected in DropBossBags.");
53+
if (instructions.Count() != 1) throw new NotSupportedException("Only one server NewItem call expected in DropBossBags.");
5154

52-
var ins = instructions.First();
55+
var ins = instructions.First();
5356

54-
ins.Operand = callback;
57+
ins.Operand = callback;
5558

56-
csr.Goto(ins);
57-
csr.EmitAll(
58-
new { OpCodes.Ldarg_0 }
59-
);
59+
csr.Goto(ins);
60+
csr.EmitAll(
61+
// reference to the npc works for both the instance, and the static method, only since the latter has the
62+
// variable first in the argument list.
63+
new { OpCodes.Ldarg_0 }
64+
);
6065

61-
csr.Goto(ins.Next.Next);
62-
csr.EmitAll(
63-
new { OpCodes.Ldloc_0 },
64-
new { OpCodes.Ldc_I4_M1 },
65-
new { OpCodes.Ceq },
66-
new { OpCodes.Brfalse_S, Operand = ins.Next.Next },
67-
new { OpCodes.Ret }
68-
);
66+
csr.Goto(ins.Next.Next);
67+
csr.EmitAll(
68+
new { OpCodes.Ldloc_0 },
69+
new { OpCodes.Ldc_I4_M1 },
70+
new { OpCodes.Ceq },
71+
new { OpCodes.Brfalse_S, Operand = ins.Next.Next },
72+
new { OpCodes.Ret }
73+
);
74+
}
6975
}
7076

7177
namespace OTAPI
@@ -142,4 +148,4 @@ Terraria.NPC npc
142148
}
143149
}
144150
}
145-
}
151+
}

examples/RuntimeExample.Client/RuntimeExample.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
</Reference>
2626
</ItemGroup>
2727
<ItemGroup>
28-
<PackageReference Include="ImGui.NET" Version="1.78.0" />
28+
<PackageReference Include="ImGui.NET" Version="1.91.0.1" />
2929
</ItemGroup>
3030
</Project>

0 commit comments

Comments
 (0)