Skip to content

Commit

Permalink
Add option for CS1-3 to force XInput for controllers (see #95).
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralCurtiss committed Jul 10, 2022
1 parent 0745cef commit 49795c2
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 31 deletions.
8 changes: 7 additions & 1 deletion SenLib/Sen1/FileFixes/ed8_exe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ed8_exe : FileMod {
bool DisablePauseOnFocusLoss;
bool FixArtsSupport;
bool Force0Kerning;
bool ForceXInput;

public ed8_exe(
bool jp,
Expand All @@ -31,7 +32,8 @@ public ed8_exe(
bool showMouseCursor,
bool disablePauseOnFocusLoss,
bool fixArtsSupport,
bool force0Kerning
bool force0Kerning,
bool forceXInput
) {
IsJp = jp;
RemoveTurboSkip = removeTurboSkip;
Expand All @@ -44,6 +46,7 @@ bool force0Kerning
DisablePauseOnFocusLoss = disablePauseOnFocusLoss;
FixArtsSupport = fixArtsSupport;
Force0Kerning = force0Kerning;
ForceXInput = forceXInput;
}

public string GetDescription() {
Expand Down Expand Up @@ -100,6 +103,9 @@ public IEnumerable<FileModResult> TryApply(FileStorage storage) {
if (!IsJp && Force0Kerning) {
Sen1ExecutablePatches.PatchForce0Kerning(ms, PatchInfo);
}
if (ForceXInput) {
Sen1ExecutablePatches.PatchForceXInput(ms, PatchInfo);
}

if (IsJp) {
// this inits the struct responsible for telling which button to use for the textbox text advance prompts
Expand Down
10 changes: 10 additions & 0 deletions SenLib/Sen1/Sen1ExecutablePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public static void PatchForce0Kerning(Stream binary, Sen1ExecutablePatchState pa
binary.WriteUInt8(0x90); // nop
}

public static void PatchForceXInput(Stream binary, Sen1ExecutablePatchState patchInfo) {
binary.Position = (long)patchInfo.Mapper.MapRamToRom(patchInfo.IsJp ? 0x939766 : 0x93b036);
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
}

public static void PatchThorMasterQuartzString(Stream binary, Sen1ExecutablePatchState patchInfo) {
binary.Position = patchInfo.RomAddressThorMasterQuartzTextureIdTypo;
long p = binary.Position;
Expand Down
6 changes: 4 additions & 2 deletions SenLib/Sen1/Sen1Mods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static List<FileMod> GetExecutableMods(
bool showMouseCursor = false,
bool disablePauseOnFocusLoss = false,
bool fixArtsSupport = false,
bool force0Kerning = false
bool force0Kerning = false,
bool forceXInput = false
) {
var f = new List<FileMod>();
for (int i = 0; i < 2; ++i) {
Expand All @@ -32,7 +33,8 @@ public static List<FileMod> GetExecutableMods(
showMouseCursor: showMouseCursor,
disablePauseOnFocusLoss: disablePauseOnFocusLoss,
fixArtsSupport: fixArtsSupport,
force0Kerning: force0Kerning
force0Kerning: force0Kerning,
forceXInput: forceXInput
));
}
return f;
Expand Down
8 changes: 7 additions & 1 deletion SenLib/Sen2/FileFixes/ed8_2_exe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ed8_2_exe : FileMod {
bool FixArtsSupport;
bool Force0Kerning;
bool FixBattleScopeCrash;
bool ForceXInput;

public ed8_2_exe(
Sen2Version version,
Expand All @@ -33,7 +34,8 @@ public ed8_2_exe(
bool fixControllerMapping,
bool fixArtsSupport,
bool force0Kerning,
bool fixBattleScopeCrash
bool fixBattleScopeCrash,
bool forceXInput
) {
Version = version;
IsJp = jp;
Expand All @@ -49,6 +51,7 @@ bool fixBattleScopeCrash
FixArtsSupport = fixArtsSupport;
Force0Kerning = force0Kerning;
FixBattleScopeCrash = fixBattleScopeCrash;
ForceXInput = forceXInput;
}

public string GetDescription() {
Expand Down Expand Up @@ -128,6 +131,9 @@ public IEnumerable<FileModResult> TryApply(FileStorage storage) {
if (FixBattleScopeCrash) {
Sen2ExecutablePatches.PatchAddNullCheckBattleScopeCrashMaybe(ms, state);
}
if (ForceXInput) {
Sen2ExecutablePatches.PatchForceXInput(ms, state);
}

// call CreateMutex without names so multiple instances of CS2 don't block eachother
ms.Position = state.Mapper.MapRamToRom(IsJp ? 0x71d484 : 0x71e4e4);
Expand Down
10 changes: 10 additions & 0 deletions SenLib/Sen2/Sen2ExecutablePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,15 @@ public static void PatchForce0Kerning(Stream binary, Sen2ExecutablePatchState pa
binary.WriteUInt16(0x31c0, EndianUtils.Endianness.BigEndian); // xor eax, eax
binary.WriteUInt8(0x90); // nop
}

public static void PatchForceXInput(Stream binary, Sen2ExecutablePatchState patchInfo) {
binary.Position = (long)patchInfo.Mapper.MapRamToRom(patchInfo.IsJp ? 0x7f9fe1 : 0x7fb0a1);
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
}
}
}
6 changes: 4 additions & 2 deletions SenLib/Sen2/Sen2Mods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static List<FileMod> GetExecutableMods(
bool fixControllerMapping = false,
bool fixArtsSupport = false,
bool force0Kerning = false,
bool fixBattleScopeCrash = false
bool fixBattleScopeCrash = false,
bool forceXInput = false
) {
var f = new List<FileMod>();
for (int i = 0; i < 2; ++i) {
Expand All @@ -42,7 +43,8 @@ public static List<FileMod> GetExecutableMods(
fixControllerMapping: fixControllerMapping,
fixArtsSupport: fixArtsSupport,
force0Kerning: force0Kerning,
fixBattleScopeCrash: fixBattleScopeCrash
fixBattleScopeCrash: fixBattleScopeCrash,
forceXInput: forceXInput
));
}
return f;
Expand Down
8 changes: 7 additions & 1 deletion SenLib/Sen3/FileFixes/ed8_3_exe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ed8_3_exe : FileMod {
bool ShowMouseCursor;
bool DisablePauseOnFocusLoss;
bool FixControllerMapping;
bool ForceXInput;

public ed8_3_exe(
bool jp,
Expand All @@ -21,7 +22,8 @@ public ed8_3_exe(
bool disableMouseCapture,
bool showMouseCursor,
bool disablePauseOnFocusLoss,
bool fixControllerMapping
bool fixControllerMapping,
bool forceXInput
) {
IsJp = jp;
FixInGameButtonMappingValidity = fixInGameButtonMappingValidity;
Expand All @@ -31,6 +33,7 @@ bool fixControllerMapping
ShowMouseCursor = showMouseCursor;
DisablePauseOnFocusLoss = disablePauseOnFocusLoss;
FixControllerMapping = fixControllerMapping;
ForceXInput = forceXInput;
}

public string GetDescription() {
Expand Down Expand Up @@ -70,6 +73,9 @@ public IEnumerable<FileModResult> TryApply(FileStorage storage) {
if (DisablePauseOnFocusLoss) {
Sen3ExecutablePatches.PatchDisablePauseOnFocusLoss(ms, PatchInfo);
}
if (ForceXInput) {
Sen3ExecutablePatches.PatchForceXInput(ms, PatchInfo);
}

// add indicator to the title screen that we're running a modified executable
{
Expand Down
10 changes: 10 additions & 0 deletions SenLib/Sen3/Sen3ExecutablePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,15 @@ public static void SwapBrokenMasterQuartzValuesForDisplay(Stream bin, Sen3Execut
codespace.TakeToAddress(state.Mapper.MapRomToRam(bin.Position), "Master Quartz description: Swap params on sentinel flag");
}
}

public static void PatchForceXInput(Stream binary, Sen3ExecutablePatchState patchInfo) {
binary.Position = (long)patchInfo.Mapper.MapRamToRom(patchInfo.IsJp ? 0x1406ada75 : 0x1406b9ed5);
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
binary.WriteUInt8(0x90); // nop
}
}
}
6 changes: 4 additions & 2 deletions SenLib/Sen3/Sen3Mods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static List<FileMod> GetExecutableMods(
bool disableMouseCapture = false,
bool showMouseCursor = false,
bool disablePauseOnFocusLoss = false,
bool fixControllerMapping = false
bool fixControllerMapping = false,
bool forceXInput = false
) {
var f = new List<FileMod>();
for (int i = 0; i < 2; ++i) {
Expand All @@ -26,7 +27,8 @@ public static List<FileMod> GetExecutableMods(
disableMouseCapture: disableMouseCapture,
showMouseCursor: showMouseCursor,
disablePauseOnFocusLoss: disablePauseOnFocusLoss,
fixControllerMapping: fixControllerMapping
fixControllerMapping: fixControllerMapping,
forceXInput: forceXInput
));
}
return f;
Expand Down
36 changes: 25 additions & 11 deletions SenPatcherGui/Sen1Form.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion SenPatcherGui/Sen1Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private void buttonPatch_Click(object sender, EventArgs e) {
bool disablePauseOnFocusLoss = checkBoxDisablePauseOnFocusLoss.Checked;
bool fixArtsSupport = checkBoxArtsSupport.Checked;
bool force0Kerning = checkBoxForce0Kerning.Checked;
bool forceXInput = checkBoxForceXInput.Checked;

var mods = new List<FileMod>();
mods.AddRange(Sen1Mods.GetExecutableMods(
Expand All @@ -74,7 +75,8 @@ private void buttonPatch_Click(object sender, EventArgs e) {
showMouseCursor: showMouseCursor,
disablePauseOnFocusLoss: disablePauseOnFocusLoss,
fixArtsSupport: fixArtsSupport,
force0Kerning: force0Kerning
force0Kerning: force0Kerning,
forceXInput: forceXInput
));
if (patchAssets) {
mods.AddRange(Sen1Mods.GetAssetMods());
Expand Down
Loading

0 comments on commit 49795c2

Please sign in to comment.