Skip to content

Commit

Permalink
Merge branch 'upcoming' into upcoming-nuget-release
Browse files Browse the repository at this point in the history
  • Loading branch information
SignatureBeef committed Jan 2, 2025
2 parents 0ad323d + 08e3d30 commit 26803ce
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 18 deletions.
6 changes: 3 additions & 3 deletions OTAPI.Client.Launcher/OTAPI.Client.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ImGui.NET" Version="1.91.0.1" GeneratePathProperty="true" />
<PackageReference Include="ModFramework.Modules.ClearScript" Version="1.1.11" GeneratePathProperty="true" />
<PackageReference Include="ModFramework.Modules.CSharp" Version="1.1.11" GeneratePathProperty="true" />
<PackageReference Include="ModFramework.Modules.Lua" Version="1.1.11" GeneratePathProperty="true" />
<PackageReference Include="ModFramework.Modules.ClearScript" Version="1.1.12" GeneratePathProperty="true" />
<PackageReference Include="ModFramework.Modules.CSharp" Version="1.1.12" GeneratePathProperty="true" />
<PackageReference Include="ModFramework.Modules.Lua" Version="1.1.12" GeneratePathProperty="true" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
<PackageReference Include="MonoMod.RuntimeDetour.HookGen" Version="22.7.31.1" />
Expand Down
8 changes: 4 additions & 4 deletions OTAPI.Patcher/OTAPI.Patcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<Version>3.2.0</Version>
<Version>3.2.1</Version>
<PreserveCompilationContext>true</PreserveCompilationContext>
<RuntimeIdentifiers>win;osx;linux;</RuntimeIdentifiers>
<Nullable>enable</Nullable>
<PackageReleaseNotes>Terraria 1.4.4.9 on .NET9</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ModFramework.Modules.ClearScript" Version="1.1.11" />
<PackageReference Include="ModFramework.Modules.CSharp" Version="1.1.11" />
<PackageReference Include="ModFramework.Modules.Lua" Version="1.1.11" />
<PackageReference Include="ModFramework.Modules.ClearScript" Version="1.1.12" />
<PackageReference Include="ModFramework.Modules.CSharp" Version="1.1.12" />
<PackageReference Include="ModFramework.Modules.Lua" Version="1.1.12" />
<PackageReference Include="Steamworks.NET" Version="2024.8.0" />
<PackageReference Include="MonoMod.RuntimeDetour.HookGen" Version="22.7.31.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
71 changes: 71 additions & 0 deletions OTAPI.Scripts/Mods/HookAchievementInitializer.Both.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright (C) 2024 SignatureBeef
This file is part of Open Terraria API v3 (OTAPI)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma warning disable CS8321 // Local function is declared but never used

using System;
using ModFramework;
using MonoMod;
using Mono.Cecil;
using Mono.Cecil.Cil;

/// <summary>
/// @doc Intercepts the Terraria.Initializers.AchievementInitializer.Load method to allow consumers to control if achievements are loaded.
/// </summary>
[Modification(ModType.PreMerge, "Hooking achievement load")]
[MonoMod.MonoModIgnore]
void HookAchievementInitializer(MonoModder modder)
{
var loadMethod = modder.GetILCursor(() => Terraria.Initializers.AchievementInitializer.Load());

loadMethod.GotoNext(ins => ins.OpCode == OpCodes.Ldsfld && ins.Operand is FieldReference fr && fr.Name == "netMode");
if(loadMethod.Index != 0) throw new Exception("Failed to find the netMode field reference in the AchievementInitializer.Load method.");

// 1. remove the field ref and its comparison value
// 2. replace the bne.un.s with a brtrue.s
// 3. add a call to the event handler, which returns true when the load should continue.
loadMethod.RemoveRange(2);
loadMethod.Next.OpCode = OpCodes.Brtrue_S;
loadMethod.EmitDelegate(OTAPI.Hooks.Initializers.InvokeAchievementInitializerLoad);
}

namespace OTAPI
{
public static partial class Hooks
{
public static partial class Initializers
{
public class AchievementInitializerLoadEventArgs : EventArgs
{
public bool ShouldLoad { get; set; }
}
public static event EventHandler<AchievementInitializerLoadEventArgs>? AchievementInitializerLoad;

public static bool InvokeAchievementInitializerLoad()
{
AchievementInitializerLoadEventArgs args = new()
{
// replicate what the vanilla code does
ShouldLoad = Terraria.Main.netMode != 2
};
AchievementInitializerLoad?.Invoke(null, args);
return args.ShouldLoad;
}
}
}
}
2 changes: 1 addition & 1 deletion OTAPI.Scripts/OTAPI.Scripts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ItemGroup>
<ProjectReference Include="..\FNA\FNA.Core.csproj" />
<PackageReference Include="Steamworks.NET" Version="2024.8.0" />
<PackageReference Include="ModFramework" Version="1.1.11" />
<PackageReference Include="ModFramework" Version="1.1.12" />
<PackageReference Include="MonoMod" Version="22.7.31.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions OTAPI.Scripts/Patches/OTAPI.Both.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ static string GetVersion(Assembly assembly)
/// </summary>
public static readonly string Version = GetVersion();

/// <summary>
/// Returns the current version string of OTAPI with a short hash name
/// </summary>
public static readonly string VersionShort = Version[..(Version.IndexOf('+')+1 + 7/* commit hash */)];

/// <summary>
/// The file name(no ext.) of the file that was patched.
/// e.g. tModLoaderServer
Expand Down Expand Up @@ -112,6 +117,11 @@ public static partial class ModFramework
/// Returns the current version string of ModFramework
/// </summary>
public static readonly string Version = GetVersion(typeof(global::ModFramework.ModFwModder).Assembly);

/// <summary>
/// Returns the current version string of ModFramework with a short hash name
/// </summary>
public static readonly string VersionShort = Version[..(Version.IndexOf('+')+1 + 7/* commit hash */)];
}
}
}
22 changes: 18 additions & 4 deletions OTAPI.Scripts/Patches/Terraria.Program.Both.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,19 @@ public static void LaunchOTAPI()
{
Configure();

Console.WriteLine($"[OTAPI] Starting up ({CSV(OTAPI.Common.Target, OTAPI.Common.Version, OTAPI.Common.GitHubCommit, $"ModFw:{OTAPI.Common.ModFramework.Version}")}).");
Console.WriteLine($"[OTAPI] Starting up ({CSV(
OTAPI.Common.Target.Replace("OTAPI", "").Trim(),
OTAPI.Common.VersionShort,
$"ModFw:{OTAPI.Common.ModFramework.VersionShort}"
)}).");

// set Assembly type to Terraria/OTAPI for runtime plugins to resolve easier when they dont have a direct ref
ModContext.Parameters.Add(Assembly.GetExecutingAssembly());

// load modfw plugins
const String modificationsPath = "modifications"; // dont use current directory, this then should work for packaged consumers
if (Directory.Exists(modificationsPath)) {
ModContext.PluginLoader.AddFromFolder(modificationsPath, searchOption: SearchOption.AllDirectories/*load sub folders, e.g. OTAPI.Mods*/);
if (Directory.Exists(modificationsPath)) {
ModContext.PluginLoader.AddFromFolder(modificationsPath, searchOption: SearchOption.AllDirectories/*load sub folders, e.g. OTAPI.Mods*/);
}
ModContext.Apply(ModType.Runtime);

Expand Down Expand Up @@ -141,7 +145,7 @@ public static void LaunchGame_(bool isServer)
orig_LaunchGame_(isServer);
ShutdownOTAPI();
}
#else // server + client
#else // server + client
#if Terraria_1442_OrAbove || TerrariaServer_1442_OrAbove
public static extern void orig_RunGame();
public static void RunGame()
Expand Down Expand Up @@ -181,6 +185,11 @@ public static partial class Common
/// </summary>
public static readonly string Version;

/// <summary>
/// Returns the current version string of OTAPI with a short hash name
/// </summary>
public static readonly string VersionShort;

/// <summary>
/// The short git hash of the commit used to produce this assembly.
/// </summary>
Expand All @@ -193,6 +202,11 @@ public static partial class ModFramework
/// Returns the current version string of ModFramework
/// </summary>
public static readonly string Version;

/// <summary>
/// Returns the current version string of ModFramework with a short hash name
/// </summary>
public static readonly string VersionShort;
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
}
Expand Down
8 changes: 4 additions & 4 deletions OTAPI.Server.Launcher/OTAPI.Server.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ModFramework" Version="1.1.11">
<PackageReference Include="ModFramework" Version="1.1.12">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</PackageReference>
<PackageReference Include="ModFramework.Modules.ClearScript" Version="1.1.11" />
<PackageReference Include="ModFramework.Modules.CSharp" Version="1.1.11" />
<PackageReference Include="ModFramework.Modules.Lua" Version="1.1.11" />
<PackageReference Include="ModFramework.Modules.ClearScript" Version="1.1.12" />
<PackageReference Include="ModFramework.Modules.CSharp" Version="1.1.12" />
<PackageReference Include="ModFramework.Modules.Lua" Version="1.1.12" />
<PackageReference Include="Steamworks.NET" Version="2024.8.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.0" />
Expand Down
14 changes: 14 additions & 0 deletions OTAPI.Server.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ static void Program_LaunchGame(object sender, HookEvents.Terraria.Program.Launch
SavePath.SetValue(null, Terraria.Program.LaunchParameters.ContainsKey("-savedirectory") ? Terraria.Program.LaunchParameters["-savedirectory"] : Platform.Get<IPathService>().GetStoragePath("Terraria"));
}

HookEvents.Terraria.Main.Initialize += (s, args) =>
{
args.ContinueExecution = false;
args.OriginalMethod();

Terraria.Main.instance._achievements = new Terraria.Achievements.AchievementManager();
Hooks.Initializers.AchievementInitializerLoad += (_, e) =>
{
e.ShouldLoad = true;
};
Terraria.Initializers.AchievementInitializer.Load();
};

// Steamworks.NET is not supported on ARM64, and will cause a crash
// TODO: create a shim generator in modfw to dynamically remove this for servers while keeping API compatibility
// Terraria.Main.SkipAssemblyLoad = true;
Expand Down Expand Up @@ -167,6 +180,7 @@ static void Program_OnLaunched(object sender, EventArgs e)
//Console.WriteLine($"RemoteClient.Reset: HOOK ID#{rc.Id} IsActive:{rc.IsActive},PT:{rc.PendingTermination}");
orig(rc);
};

}

static void Main_ctor(On.Terraria.Main.orig_ctor orig, Terraria.Main self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ModFramework" Version="1.1.11" />
<PackageReference Include="ModFramework" Version="1.1.12" />
</ItemGroup>
<ItemGroup>
<Reference Include="OTAPI.Runtime">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ModFramework" Version="1.1.11" />
<PackageReference Include="ModFramework" Version="1.1.12" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down

0 comments on commit 26803ce

Please sign in to comment.