Skip to content

Commit

Permalink
Finish downgrading Reloaded.Memory to resolve issue with Reloaded.Asm…
Browse files Browse the repository at this point in the history
…Hooks not working with newest version
  • Loading branch information
jroweboy committed Oct 23, 2023
1 parent 354d859 commit c460568
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 51 deletions.
2 changes: 1 addition & 1 deletion MRDX.Game.HardMode/MRDX.Game.HardMode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Memory" Version="9.1.0" />
<PackageReference Include="Reloaded.Memory" Version="8.1.0" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.4.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.9.0" />
<PackageReference Include="Reloaded.Universal.Redirector.Interfaces" Version="1.1.0" />
Expand Down
11 changes: 4 additions & 7 deletions MRDX.Graphics.Widescreen/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ public Mod(ModContext context)
_owner = context.Owner;
_configuration = context.Configuration;
_modConfig = context.ModConfig;
Debugger.Launch();
_gameClient = _modLoader.GetController<IGameClient>();

_modLoader.GetController<IHooks>().TryGetTarget(out var hooks);
hooks!.AddHook<CreateOverlay>(CreateOverlayHook)
.ContinueWith(result => _createOverlayHook = result.Result?.Activate());
UpdateWindowBounds(_configuration.AspectRatio);
CalculateSkyboxCoords(_configuration.AspectRatio);
var _startupScanner = _modLoader.GetController<IStartupScanner>();
if (_startupScanner != null && _startupScanner.TryGetTarget(out var scanner)) InitSkyboxHooks(scanner);
var startupScanner = _modLoader.GetController<IStartupScanner>();
if (startupScanner != null && startupScanner.TryGetTarget(out var scanner)) InitSkyboxHooks(scanner);
else
_logger.WriteLine($"[{_modConfig.ModId}] Could not load startup scanner!");
}

#region For Exports, Serialization etc.
Expand Down Expand Up @@ -138,22 +139,18 @@ private nint CreateOverlayHook(nint self, OverlayDrawMode drawMode)
private void CalculateSkyboxCoords(Config.AspectRatioEnum ratio)
{
var newWidth = CalculateNewWidth(OriginalWidth, ratio);
_logger!.WriteLine($"[MRDX.Graphics.Widescreen] newwidth: {(uint)newWidth}");

_skyboxEndYPtr = Marshal.AllocHGlobal(2);
short newYVal = 0x78;
Marshal.WriteInt16(_skyboxEndYPtr, newYVal);
_logger!.WriteLine($"[MRDX.Graphics.Widescreen] newYVal: {(uint)newYVal}");

_skyboxStartXPtr = Marshal.AllocHGlobal(2);
var newXVal = (short)(newWidth / 2 * -1);
Marshal.WriteInt16(_skyboxStartXPtr, newXVal);
_logger!.WriteLine($"[MRDX.Graphics.Widescreen] newXVal: {(uint)newXVal}");

_skyboxEndXPtr = Marshal.AllocHGlobal(2);
var newXVal1 = (short)(newWidth / 2);
Marshal.WriteInt16(_skyboxEndXPtr, newXVal1);
_logger!.WriteLine($"[MRDX.Graphics.Widescreen] newXVal1: {(uint)newXVal1}");
}

private void InitSkyboxHooks(IStartupScanner scanner)
Expand Down
2 changes: 1 addition & 1 deletion MRDX.Qol.BattleTimer/MRDX.Qol.BattleTimer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Memory" Version="9.1.0" />
<PackageReference Include="Reloaded.Memory" Version="8.1.0" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.4.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.9.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MRDX.Qol.BattleTimer/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using MRDX.Qol.BattleTimer.Configuration;
using MRDX.Qol.BattleTimer.Template;
using Reloaded.Hooks.Definitions;
using Reloaded.Memory;
using Reloaded.Memory.Sources;
using Reloaded.Mod.Interfaces;
using IReloadedHooks = Reloaded.Hooks.ReloadedII.Interfaces.IReloadedHooks;

Expand Down
4 changes: 2 additions & 2 deletions MRDX.Qol.FastForward/MRDX.Qol.FastForward.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Assembler" Version="1.0.15" />
<PackageReference Include="Reloaded.Assembler" Version="1.0.14" />
<PackageReference Include="Reloaded.Hooks" Version="4.3.0" />
<PackageReference Include="Reloaded.Memory.Buffers" Version="3.0.6" />
<PackageReference Include="Reloaded.Memory.Buffers" Version="2.0.0" />
<PackageReference Include="Reloaded.Memory.SigScan.ReloadedII.Interfaces" Version="1.2.0" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.4.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.9.0" />
Expand Down
51 changes: 26 additions & 25 deletions MRDX.Qol.FastForward/Mod.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using MRDX.Base.Mod.Interfaces;
using System.Runtime.InteropServices;
using MRDX.Base.Mod.Interfaces;
using MRDX.Qol.FastForward.Template;
using Reloaded.Hooks;
using Reloaded.Hooks.Definitions;
using Reloaded.Hooks.Definitions.Enums;
using Reloaded.Memory.SigScan.ReloadedII.Interfaces;
using Reloaded.Mod.Interfaces;
using System.Runtime.InteropServices;

namespace MRDX.Qol.FastForward;

Expand Down Expand Up @@ -48,25 +48,13 @@ public class Mod : ModBase // <= Do not Remove.
/// </summary>
private Config _configuration;

private bool _wasPressed;

[DllImport("libcocos2d.dll",
EntryPoint = "?getInstance@Director@cocos2d@@SAPAV12@XZ",
ExactSpelling = true,
CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr GetDirectorInstance();

[DllImport("libcocos2d.dll",
EntryPoint = "?setAnimationInterval@Director@cocos2d@@QAEXM@Z",
ExactSpelling = true,
CallingConvention = CallingConvention.ThisCall)]
static extern IntPtr SetAnimationInterval(IntPtr director, float interval);
private nuint _fastForwardTickDelayAddr;

private IAsmHook _tickDelayHook;

private nuint _fastForwardTickDelayAddr;
private readonly nint _tickDelayPtr;

private nint _tickDelayPtr;
private bool _wasPressed;

public Mod(ModContext context)
{
Expand All @@ -85,15 +73,15 @@ public Mod(ModContext context)
_tickDelayPtr = Marshal.AllocHGlobal(4);
Marshal.WriteInt32(_tickDelayPtr, _configuration.TickDelay);

var _startupScanner = _modLoader.GetController<IStartupScanner>();
if (_startupScanner != null && _startupScanner.TryGetTarget(out var scanner))
{
var startupScanner = _modLoader.GetController<IStartupScanner>();
if (startupScanner != null && startupScanner.TryGetTarget(out var scanner))
scanner.AddMainModuleScan("BF 00 7D 00 00 BA 80 3E 00 00", result =>
{
_fastForwardTickDelayAddr = (nuint)(MRDX.Base.Mod.Base.ExeBaseAddress + result.Offset);
_fastForwardTickDelayAddr = (nuint)(Base.Mod.Base.ExeBaseAddress + result.Offset);
HookTickDelay();
});
}
else
_logger.WriteLine($"[{_modConfig.ModId}] Unable to load startup scanner!");
}

#region For Exports, Serialization etc.
Expand All @@ -106,6 +94,18 @@ public Mod()

#endregion

[DllImport("libcocos2d.dll",
EntryPoint = "?getInstance@Director@cocos2d@@SAPAV12@XZ",
ExactSpelling = true,
CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr GetDirectorInstance();

[DllImport("libcocos2d.dll",
EntryPoint = "?setAnimationInterval@Director@cocos2d@@QAEXM@Z",
ExactSpelling = true,
CallingConvention = CallingConvention.ThisCall)]
private static extern IntPtr SetAnimationInterval(IntPtr director, float interval);

private void HandleInputChanged(IInput input)
{
if (_gameClient == null || !_gameClient.TryGetTarget(out var game)) return;
Expand Down Expand Up @@ -136,11 +136,12 @@ private void HookTickDelay()
{
string[] modifyTickDelay =
{
$"use32",
$"mov edx, [{_tickDelayPtr}]",
"use32",
$"mov edx, [{_tickDelayPtr}]"
};

_tickDelayHook = new AsmHook(modifyTickDelay, _fastForwardTickDelayAddr, AsmHookBehaviour.ExecuteAfter).Activate();
_tickDelayHook =
new AsmHook(modifyTickDelay, _fastForwardTickDelayAddr, AsmHookBehaviour.ExecuteAfter).Activate();
}

public override void ConfigurationUpdated(Config configuration)
Expand Down
1 change: 1 addition & 0 deletions MRDX.Qol.FastForward/ModConfig.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"IsUniversalMod": false,
"ModDependencies": [
"reloaded.sharedlib.hooks",
"Reloaded.Memory.SigScan.ReloadedII",
"MRDX.Base.Mod"
],
"OptionalDependencies": [],
Expand Down
2 changes: 1 addition & 1 deletion MRDX.Qol.SkipDrillAnim/MRDX.Qol.SkipDrillAnim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Memory" Version="9.1.0" />
<PackageReference Include="Reloaded.Memory" Version="8.1.0" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.4.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.9.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MRDX.Qol.SkipDrillAnim/Mod.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MRDX.Base.Mod.Interfaces;
using MRDX.Qol.SkipDrillAnim.Template;
using Reloaded.Hooks.Definitions;
using Reloaded.Memory;
using Reloaded.Memory.Sources;
using Reloaded.Mod.Interfaces;

namespace MRDX.Qol.SkipDrillAnim;
Expand Down
2 changes: 1 addition & 1 deletion MRDX.Ui.RawTechValues/MRDX.Ui.RawTechValues.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Memory" Version="9.1.0" />
<PackageReference Include="Reloaded.Memory" Version="8.1.0" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.4.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.9.0" />
<PackageReference Include="Reloaded.Universal.Redirector.Interfaces" Version="1.1.0" />
Expand Down
2 changes: 1 addition & 1 deletion MRDX.Ui.RawTechValues/Mod.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MRDX.Base.Mod.Interfaces;
using MRDX.Ui.RawTechValues.Template;
using Reloaded.Hooks.Definitions;
using Reloaded.Memory;
using Reloaded.Memory.Sources;
using Reloaded.Mod.Interfaces;
using IReloadedHooks = Reloaded.Hooks.ReloadedII.Interfaces.IReloadedHooks;

Expand Down
20 changes: 10 additions & 10 deletions PublishAll.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ Split-Path $MyInvocation.MyCommand.Path | Push-Location

# Name of interface mod, version
# These are kinda hard coded into the publish script for now.
$BaseModInterfaceVersion = "1.1.0"
$BaseModInterfaceVersion = "1.1.1"
$InterfaceVersions = @{
BaseExtractDataBinInterface = "1.1.1";
BaseModInterfaces = $BaseModInterfaceVersion
}

$AllProjects = @(
# Name of mod, version
@("MRDX.Audio.VolumeConfig", "1.1.4", $false),
@("MRDX.Base.ExtractDataBin", "1.1.1", $false),
@("MRDX.Audio.VolumeConfig", "1.1.5", $false),
@("MRDX.Base.ExtractDataBin", "1.1.2", $false),
@("MRDX.Base.Mod", $BaseModInterfaceVersion, $false),
@("MRDX.Game.HardMode", "2.1.0", $false),
@("MRDX.Game.HardMode", "2.1.1", $false),
# Not ready for release yet, so leave it commented out for now
# @("MRDX.Game.MonsterEditor", "1.0.0", $false),
@("MRDX.Graphics.Widescreen", "1.2.1", $false),
@("MRDX.Qol.BattleTimer", "1.0.1", $false),
@("MRDX.Qol.FastForward", "1.3.3", $false),
@("MRDX.Qol.SkipDrillAnim", "1.2.5", $false),
@("MRDX.Qol.TurboInput", "1.0.3", $false),
@("MRDX.Ui.RawTechValues", "1.0.6", $false)
@("MRDX.Graphics.Widescreen", "1.2.2", $false),
@("MRDX.Qol.BattleTimer", "1.0.2", $false),
@("MRDX.Qol.FastForward", "1.3.4", $false),
@("MRDX.Qol.SkipDrillAnim", "1.2.6", $false),
@("MRDX.Qol.TurboInput", "1.0.4", $false),
@("MRDX.Ui.RawTechValues", "1.0.7", $false)
)

Write-Output "Starting Publish All"
Expand Down

0 comments on commit c460568

Please sign in to comment.