-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMod.cs
More file actions
93 lines (78 loc) · 3.04 KB
/
Copy pathMod.cs
File metadata and controls
93 lines (78 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Reloaded.Mod.Interfaces;
using p5rpc.FixShadowSettings.Template;
using Reloaded.Memory.Sigscan;
using System.Diagnostics;
using Reloaded.Memory.Sources;
namespace p5rpc.FixShadowSettings;
/// <summary>
/// Your mod logic goes here.
/// </summary>
public class Mod : ModBase // <= Do not Remove.
{
/// <summary>
/// Provides access to the mod loader API.
/// </summary>
private readonly IModLoader _modLoader;
/// <summary>
/// Provides access to the Reloaded logger.
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Entry point into the mod, instance that created this class.
/// </summary>
private readonly IMod _owner;
public Mod(ModContext context)
{
_modLoader = context.ModLoader;
_logger = context.Logger;
_owner = context.Owner;
// For more information about this template, please see
// https://reloaded-project.github.io/Reloaded-II/ModTemplate/
// If you want to implement e.g. unload support in your mod,
// and some other neat features, override the methods in ModBase.
var mainModule = Process.GetCurrentProcess().MainModule;
if( mainModule == null)
{
throw new Exception("[FixShadowSetting]Main Module is Null!");
}
var baseAddress = mainModule.BaseAddress;
var exeSize = mainModule.ModuleMemorySize;
unsafe
{
using var scanner = new Scanner((byte*)baseAddress, exeSize);
// Pattern for Steam 1.04
var result = scanner.FindPattern("89 05 ?? ?? ?? ?? 80 BB ?? ?? ?? ?? 00 74 05 83 C9 20");
if (!result.Found)
{
_logger.WriteLine("[FixShadowSetting]Pattern not found for 1.04");
// Pattern for Steam 1.03B
result = scanner.FindPattern("89 05 ?? ?? ?? ?? 41 80 BA ?? ?? ?? ?? 00");
if (!result.Found)
{
throw new Exception("[FixShadowSetting]Pattern not found");
}
}
_logger.WriteLine($"[FixShadowSetting] instruction offset {result.Offset:X}");
// Nop the instruction that sets the medium shadow quality on every load screen...
var ínstructionAddress = baseAddress + result.Offset;
var instructionSize = 6;
NopInstruction(ínstructionAddress, instructionSize);
_logger.WriteLine($"[FixShadowSetting] Init ok");
}
}
private void NopInstruction(nint ínstructionAddress, int instructionSize)
{
byte nopOpcodeX64 = 0x90;
for (var i = 0; i < instructionSize; i++)
{
Memory.Instance.SafeWrite(ínstructionAddress + i, nopOpcodeX64);
}
}
#region Standard Overrides
#endregion
#region For Exports, Serialization etc.
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public Mod() { }
#pragma warning restore CS8618
#endregion
}