Skip to content

Commit

Permalink
Wayland Resolution Service (#112)
Browse files Browse the repository at this point in the history
* Add resolution service for wayland users. Wayland users no longer need x11 to run the patcher.
  • Loading branch information
FaithBeam authored Nov 10, 2024
1 parent 4b3d6df commit 7107f48
Show file tree
Hide file tree
Showing 80 changed files with 691 additions and 463 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: .NET

env:
PACK_ID: Sims1WidescreenPatcher
PACK_VER: 3.10.0
PACK_VER: 3.11.0

on:
push:
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ This program patches **The Sims 1** to a custom resolution.

* NoCD/Cracked Sims Executable
* This exe cannot be previously patched to a custom resolution. For example, if you downloaded a crack that was patched to 1080p, this program will not work.

### Linux Requirements

* X11
* You don't need to run X11, but you do need it installed

### OS Version Compatability

Expand Down
3 changes: 1 addition & 2 deletions Sims1WidescreenPatcher.Core/Enums/DDrawCompatEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
public enum DDrawCompatEnums
{
BorderlessFullscreen,
ExclusiveFullscreen
ExclusiveFullscreen,
}

5 changes: 2 additions & 3 deletions Sims1WidescreenPatcher.Core/Events/NewProgressEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ public class NewProgressEventArgs
public string Status { get; }
public string Status2 { get; }

public NewProgressEventArgs(double progress) : this(progress, string.Empty, string.Empty)
{
}
public NewProgressEventArgs(double progress)
: this(progress, string.Empty, string.Empty) { }

public NewProgressEventArgs(double progress, string status, string status2)
{
Expand Down
5 changes: 1 addition & 4 deletions Sims1WidescreenPatcher.Core/Events/NewUninstallEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
namespace Sims1WidescreenPatcher.Core.Events;

public class NewUninstallEventArgs : EventArgs
{

}
public class NewUninstallEventArgs : EventArgs { }
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Sims1WidescreenPatcher.Core.Factories;

public class CheckboxViewModelFactory: UserControlViewModelCreator
public class CheckboxViewModelFactory : UserControlViewModelCreator
{
public override IReactiveObject Create(string label)
{
Expand All @@ -14,4 +14,4 @@ public IReactiveObject Create(string label, string tooltip)
{
return new CheckboxViewModel(label, tooltip);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ namespace Sims1WidescreenPatcher.Core.Factories;
public interface IUserControlViewModelCreator
{
IReactiveObject Create(string arg0);
}
}
5 changes: 1 addition & 4 deletions Sims1WidescreenPatcher.Core/Factories/ImageJobFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
namespace Sims1WidescreenPatcher.Core.Factories;

public class ImageJobFactory
{

}
public class ImageJobFactory { }
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ namespace Sims1WidescreenPatcher.Core.Factories;
public abstract class UserControlViewModelCreator : IUserControlViewModelCreator
{
public abstract IReactiveObject Create(string arg0);
}
}
2 changes: 1 addition & 1 deletion Sims1WidescreenPatcher.Core/Models/AppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ public Resolution? Resolution
get => _resolution;
set => this.RaiseAndSetIfChanged(ref _resolution, value);
}
}
}
11 changes: 7 additions & 4 deletions Sims1WidescreenPatcher.Core/Models/AspectRatio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ public virtual bool Equals(AspectRatio? other) =>

public int CompareTo(AspectRatio? other)
{
if (ReferenceEquals(this, other)) return 0;
if (other is null) return 1;
if (ReferenceEquals(this, other))
return 0;
if (other is null)
return 1;
var numeratorComparison = Numerator.CompareTo(other.Numerator);
if (numeratorComparison != 0) return numeratorComparison;
if (numeratorComparison != 0)
return numeratorComparison;
return Denominator.CompareTo(other.Denominator);
}

Expand All @@ -39,4 +42,4 @@ public void Deconstruct(out int Width, out int Height)
Width = this.Width;
Height = this.Height;
}
}
}
5 changes: 3 additions & 2 deletions Sims1WidescreenPatcher.Core/Models/BaseImageProcessingJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public virtual void Run()
BaseImageName = Path.GetFileName(Output);
}
var destDir = Path.GetDirectoryName(Output);
if (destDir == null || Directory.Exists(destDir)) return;
if (destDir == null || Directory.Exists(destDir))
return;
Directory.CreateDirectory(destDir);
if (ImageBytes is null || string.IsNullOrWhiteSpace(Output))
{
Expand All @@ -36,4 +37,4 @@ protected static void SetCommonBmpSettings(MagickImage bmp)
bmp.ColorType = ColorType.Palette;
bmp.Alpha(AlphaOption.Off);
}
}
}
20 changes: 13 additions & 7 deletions Sims1WidescreenPatcher.Core/Models/CheckboxSelectionSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ public CheckboxSelectionSnapshot(params bool[] vms)

public bool Equals(CheckboxSelectionSnapshot? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
if (_vms.Length != other._vms.Length) return false;
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;
if (_vms.Length != other._vms.Length)
return false;

for (int i = 0; i < _vms.Length; i++)
{
Expand All @@ -28,14 +31,17 @@ public bool Equals(CheckboxSelectionSnapshot? other)

public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != this.GetType())
return false;
return Equals((CheckboxSelectionSnapshot)obj);
}

public override int GetHashCode()
{
return _vms.GetHashCode();
}
}
}
4 changes: 2 additions & 2 deletions Sims1WidescreenPatcher.Core/Models/CompositeImageJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public override void Run()
{
throw new Exception("Color is null");
}

using var image = new MagickImage(ImageBytes!);
using var background = new MagickImage(new MagickColor(Color), (uint)Width, (uint)Height);
background.Composite(image, Gravity.Center);
SetCommonBmpSettings(background);
background.Write(Output!);
}
}
}
2 changes: 1 addition & 1 deletion Sims1WidescreenPatcher.Core/Models/IAppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public interface IAppState
Resolution? Resolution { get; set; }
string SimsBackupPath { get; }
bool SimsBackupExists { get; }
}
}
18 changes: 12 additions & 6 deletions Sims1WidescreenPatcher.Core/Models/Resolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ public Resolution(int Width, int Height)

public override string ToString() => $"{Width}x{Height} ({AspectRatio})";

public virtual bool Equals(Resolution? other) => other is not null && Width == other.Width &&
Height == other.Height && AspectRatio.Equals(other.AspectRatio);
public virtual bool Equals(Resolution? other) =>
other is not null
&& Width == other.Width
&& Height == other.Height
&& AspectRatio.Equals(other.AspectRatio);

public override int GetHashCode() => HashCode.Combine(AspectRatio, Width, Height);

public int CompareTo(Resolution? other)
{
if (ReferenceEquals(this, other)) return 0;
if (other is null) return 1;
if (ReferenceEquals(this, other))
return 0;
if (other is null)
return 1;
var widthComparison = Width.CompareTo(other.Width);
if (widthComparison != 0) return widthComparison;
if (widthComparison != 0)
return widthComparison;
return Height.CompareTo(other.Height);
}

Expand All @@ -35,4 +41,4 @@ public void Deconstruct(out int Width, out int Height)
Width = this.Width;
Height = this.Height;
}
}
}
11 changes: 8 additions & 3 deletions Sims1WidescreenPatcher.Core/Models/ScalePanelBackJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ public class ScalePanelBackJob : BaseImageProcessingJob
public override void Run()
{
base.Run();

using var image = new MagickImage(ImageBytes!);
var left = image.Clone(0, 0, 286, 100);
var middle = image.Clone((int)left.Width, 0, 500, 100);
var right = image.Clone((int)left.Width + (int)middle.Width, 0, 18, 100);
middle.Resize(new MagickGeometry((uint)Width - left.Width - right.Width, (uint)Height) { IgnoreAspectRatio = true });
middle.Resize(
new MagickGeometry((uint)Width - left.Width - right.Width, (uint)Height)
{
IgnoreAspectRatio = true,
}
);
left.Page = new MagickGeometry("+0+0");
middle.Page = new MagickGeometry($"+{left.Width}+0");
right.Page = new MagickGeometry($"+{left.Width + middle.Width}+0");
Expand All @@ -24,4 +29,4 @@ public override void Run()
SetCommonBmpSettings((MagickImage)merged);
merged.Write(Output!);
}
}
}
4 changes: 2 additions & 2 deletions Sims1WidescreenPatcher.Core/Models/ScaleTallSubPanelJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class ScaleTallSubPanelJob : BaseImageProcessingJob
public override void Run()
{
base.Run();

using var image = new MagickImage(ImageBytes!, MagickFormat.Tga);
image.Resize(new MagickGeometry((uint)Width, (uint)Height) { IgnoreAspectRatio = true });
image.Depth = 32;
image.Settings.Compression = CompressionMethod.RLE;
image.Settings.Format = MagickFormat.Tga;
image.Write(Output!);
}
}
}
2 changes: 1 addition & 1 deletion Sims1WidescreenPatcher.Core/Models/YesNoDialogResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
public class YesNoDialogResponse
{
public bool Result { get; set; }
}
}
17 changes: 13 additions & 4 deletions Sims1WidescreenPatcher.Core/Services/CheatsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public bool CheatsEnabled()
{
return false;
}
var (found, _, _) = _patchFileService.FindPattern(_appState.SimsExePath, DisableCheatsPattern);
var (found, _, _) = _patchFileService.FindPattern(
_appState.SimsExePath,
DisableCheatsPattern
);
return found;
}

Expand All @@ -37,8 +40,14 @@ public bool CanEnableCheats()
{
return false;
}
var (disablePatternFound, _, _) = _patchFileService.FindPattern(_appState.SimsExePath, DisableCheatsPattern);
var (enablePatternFound, _, _) = _patchFileService.FindPattern(_appState.SimsExePath,EnableCheatsPattern);
var (disablePatternFound, _, _) = _patchFileService.FindPattern(
_appState.SimsExePath,
DisableCheatsPattern
);
var (enablePatternFound, _, _) = _patchFileService.FindPattern(
_appState.SimsExePath,
EnableCheatsPattern
);
return disablePatternFound || enablePatternFound;
}

Expand Down Expand Up @@ -69,4 +78,4 @@ private void EditSimsExe(string pattern, Tuple<byte, byte> replacementBytes)

_patchFileService.WriteChanges(_appState.SimsExePath, bytes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public static string DDrawCompatSettingsExist(string pathToSimsExe)
var ddrawSettingsPath = Path.Combine(dir, "DDrawCompat.ini");
return File.Exists(ddrawSettingsPath) ? ddrawSettingsPath : string.Empty;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ namespace Sims1WidescreenPatcher.Core.Services;

public static class DDrawCompatSettingsService
{
public static async Task CreateDDrawCompatSettingsFile(string pathToSimsExe, params DDrawCompatEnums[] settings)
public static async Task CreateDDrawCompatSettingsFile(
string pathToSimsExe,
params DDrawCompatEnums[] settings
)
{
var dir = Path.GetDirectoryName(pathToSimsExe);
if (string.IsNullOrWhiteSpace(dir))
Expand All @@ -27,7 +30,7 @@ public static async Task CreateDDrawCompatSettingsFile(string pathToSimsExe, par
break;
}
}
await sw.WriteLineAsync("CPUAffinity=all"); // the default was changed to 1 in 0.4.0 which was a culprit for the major issues, crashes, and lag
await sw.WriteLineAsync("CPUAffinity=all"); // the default was changed to 1 in 0.4.0 which was a culprit for the major issues, crashes, and lag
await sw.WriteLineAsync("DisplayRefreshRate=desktop"); // removes erroneous lock to 60fps on higher-than-60hz displays when vsync is enabled
await sw.WriteLineAsync("AltTabFix=keepvidmem"); // fixes crashes/bugs when using Alt+Tab
}
Expand Down
Loading

0 comments on commit 7107f48

Please sign in to comment.