Skip to content

Commit

Permalink
- Added FAQ / README screen.
Browse files Browse the repository at this point in the history
- Added in-game compare screens.
- Corrected typos.
- Copyright note updates for 2016.
  • Loading branch information
FireEmerald committed Jan 10, 2016
1 parent 6454bb6 commit fa692be
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 50 deletions.
37 changes: 28 additions & 9 deletions GameResolution.vb
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
Public Class GameResolution
'* Copyright (C) 2015-2016 FireEmerald <https://github.com/FireEmerald>
'*
'* Project: Settlers4-Widescreen-Tool
'*
'* Requires: .NET Framework 3.5 or higher.
'*
'* 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 2 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/>.

Public Class GameResolution
Public Enum AVAILABLE_RESOLUTIONS
RES_UNKOWN = -1
RES_UNKNOWN = -1
RES_DEFAULT = 0
RES_1024_600 = 1
RES_1280_720 = 2
Expand All @@ -13,16 +32,16 @@
End Enum

Private _GameResolution As AVAILABLE_RESOLUTIONS
Private _Width, _Height, _Dll_SHA1Hash, _UnkownInfo As String
Private _Width, _Height, _Dll_SHA1Hash, _UnknownInfo As String
Private _CheckBoxIndex As Integer
Private _Dll As Byte()

Sub New(GameResolution As AVAILABLE_RESOLUTIONS, Optional UnkownInfo As String = "")
Sub New(GameResolution As AVAILABLE_RESOLUTIONS, Optional UnknownInfo As String = "")
_GameResolution = GameResolution
_UnkownInfo = UnkownInfo
_UnknownInfo = UnknownInfo

Select Case GameResolution
Case AVAILABLE_RESOLUTIONS.RES_UNKOWN
Case AVAILABLE_RESOLUTIONS.RES_UNKNOWN
_Width = ""
_Height = ""
_Dll_SHA1Hash = ""
Expand Down Expand Up @@ -83,7 +102,7 @@
_CheckBoxIndex = 8
_Dll = My.Resources.GfxEngine_1920x1200
Case Else
Throw New Exception("GameResolution not handeled.")
Throw New Exception("GameResolution not handled.")
End Select
End Sub

Expand All @@ -107,9 +126,9 @@
Return _Dll_SHA1Hash
End Get
End Property
Public ReadOnly Property UnkownInfo As String
Public ReadOnly Property UnknownInfo As String
Get
Return _UnkownInfo
Return _UnknownInfo
End Get
End Property
Public ReadOnly Property CheckBoxIndex As Integer
Expand Down
25 changes: 13 additions & 12 deletions MainWindow.Designer.vb

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

84 changes: 62 additions & 22 deletions MainWindow.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
Imports System.IO
'* Copyright (C) 2015-2016 FireEmerald <https://github.com/FireEmerald>
'*
'* Project: Settlers4-Widescreen-Tool
'*
'* Requires: .NET Framework 3.5 or higher.
'*
'* 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 2 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/>.

Imports System.IO
Imports System.Security.Cryptography

Public Class fmMainWindow
Expand All @@ -25,6 +44,8 @@ Public Class fmMainWindow
Private Const INI_KEY_SCREENMODE As String = "Screenmode"
Private Const INI_DEFAULT_VALUE As String = ""

Private _ReadMeWindow As fmReadMeWindow

#Region "GameSettings Handling"
''' <summary>
''' Retrieves a string from the specified section in an initialization file.
Expand Down Expand Up @@ -57,15 +78,16 @@ Public Class fmMainWindow
Private Sub Button_Handler(sender As Object, e As EventArgs) Handles btnApply.Click, _
btnExit.Click, _
btnOpenFileDialog_S4_exe.Click, _
btnPlay.Click
btnPlay.Click, _
lblVersion.Click
Select Case True
Case sender Is btnApply
If cbResolutions.SelectedIndex >= 0 And tbS4_exe_Filepath.Text.Length > 0 Then
tbMessages.Clear()

Dim _NewResolution As GameResolution = ApplyNewResolution()
If _NewResolution.GameResolution = GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKOWN Then
Message(_NewResolution.UnkownInfo)
If _NewResolution.GameResolution = GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKNOWN Then
Message(_NewResolution.UnknownInfo)
Else
Message(String.Format("\nChanges applied successfully. Resolution set to {0} x {1} Pixel.", _
_NewResolution.Width, _NewResolution.Height))
Expand Down Expand Up @@ -95,26 +117,34 @@ Public Class fmMainWindow
Else
Message("The Settlers 4 is already running.")
End If
Case sender Is lblVersion
ShowReadMeWindow()
Case Else
Throw New Exception("Button not handeled.")
Throw New Exception("Button not handled.")
End Select
End Sub

Private Sub fmMainWindow_Shown(sender As Object, e As EventArgs) Handles Me.Shown
lblVersion.Text = "Version: " & Application.ProductVersion
lblVersion.Text = "Version: " & Application.ProductVersion & " (README)"

Dim _DetectedResolution As GameResolution = GetCurrentResolution()
If _DetectedResolution.GameResolution = GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKOWN Then
Message(_DetectedResolution.UnkownInfo)
If _DetectedResolution.GameResolution = GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKNOWN Then
Message(_DetectedResolution.UnknownInfo)
Else
Message("Existing settings successfully read.")
End If
SetCheckBoxResolution(_DetectedResolution)

'// Show README if the tool was started the first time.
If My.Settings.SkipReadMe = False Then
My.Settings.SkipReadMe = True
ShowReadMeWindow()
End If
End Sub

Private Sub SetCheckBoxResolution(Resolution As GameResolution)
Select Case Resolution.GameResolution
Case GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKOWN, _
Case GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKNOWN, _
GameResolution.AVAILABLE_RESOLUTIONS.RES_DEFAULT, _
GameResolution.AVAILABLE_RESOLUTIONS.RES_1024_600, _
GameResolution.AVAILABLE_RESOLUTIONS.RES_1280_720, _
Expand All @@ -134,21 +164,21 @@ Public Class fmMainWindow
Dim _fiS4_exe As FileInfo = Nothing, _fiGameSettings As FileInfo = Nothing, _fiGfxEngine As FileInfo = Nothing

'// Perform the initial checks and get the FileInfos. If we get a empty string, all is OK.
Dim _UnkownInfo As String = PerformInitialChecks(_fiS4_exe, _fiGameSettings, _fiGfxEngine)
If Not String.Equals(_UnkownInfo, String.Empty) Then
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKOWN, _UnkownInfo)
Dim _UnknownInfo As String = PerformInitialChecks(_fiS4_exe, _fiGameSettings, _fiGfxEngine)
If Not String.Equals(_UnknownInfo, String.Empty) Then
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKNOWN, _UnknownInfo)
End If

Dim _BackupFiles As Boolean = (cbBackup.CheckState = CheckState.Checked)

'// Validate the Hash of the existing DLL against the known Hashes.
Dim _GfxEngine_SHA1Hash As String = SHA1_CalculateHash(_fiGfxEngine)
If IsNothing(_AvailableResolutions.FirstOrDefault(Function(r) String.Equals(r.Dll_SHA1Hash, _GfxEngine_SHA1Hash))) Then
If MessageBox.Show("Your GfxEngine.dll is invalid. The patch could break your game!" & Environment.NewLine & "Would you like to continue anyway?" & Environment.NewLine & Environment.NewLine & "(A Backup (*.bak) will be created)", "Unkown Version of GfxEngine.dll", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
If MessageBox.Show("Your GfxEngine.dll is invalid. The patch could break your game!" & Environment.NewLine & "Would you like to continue anyway?" & Environment.NewLine & Environment.NewLine & "(A Backup (*.bak) will be created)", "Unknown Version of GfxEngine.dll", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
cbBackup.CheckState = CheckState.Checked
_BackupFiles = True
Else
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKOWN, "GfxEngine.dll - INVALID HASH\nPatching aborted, due to invalid GfxEngine.dll. Make sure you installed:\nThe Settlers IV: Gold Edition")
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKNOWN, "GfxEngine.dll - INVALID HASH\nPatching aborted, due to invalid GfxEngine.dll. Make sure you installed:\nThe Settlers IV: Gold Edition")
End If
End If

Expand All @@ -159,7 +189,7 @@ Public Class fmMainWindow
_fiGfxEngine.CopyTo(_fiGfxEngine.FullName & ".bak", False)
Message("GameSettings.cfg and GfxEngine.dll backed up as *.bak files.\n")
Else
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKOWN, "Patching aborted, due to already existing backup(s). Make sure theres no:\nGfxEngine.dll.bak or GameSettings.cfg.bak")
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKNOWN, "Patching aborted, due to already existing backup(s). Make sure theres no:\nGfxEngine.dll.bak or GameSettings.cfg.bak")
End If
End If

Expand All @@ -169,7 +199,7 @@ Public Class fmMainWindow
Not INI_WriteValueToFile(INI_SECTION, INI_KEY_WIDTH, _Resolution.Width, _fiGameSettings.FullName) Or _
Not INI_WriteValueToFile(INI_SECTION, INI_KEY_FULLSCREEN, "1", _fiGameSettings.FullName) Or _
Not INI_WriteValueToFile(INI_SECTION, INI_KEY_SCREENMODE, "2", _fiGameSettings.FullName) Then
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKOWN, "A unkown error occured, while writing your GameSettings.cfg!\nPlease open the file with Notepad and check the content. It should look like:\n[GAMESETTINGS]\n{\n AILevel = 0\nand so on...\nYou could also try to delete the file, it will be created new.")
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKNOWN, "A unknown error occurred, while writing your GameSettings.cfg!\nPlease open the file with Notepad and check the content. It should look like:\n[GAMESETTINGS]\n{\n AILevel = 0\nand so on...\nYou could also try to delete the file, it will be created new.")
Else
Message("GameSettings.cfg - PATCHED OK !")
'Message(String.Format("GameSettings.cfg:\n{0} set to {1}.\n{2} set to {3}\n{4} set to {5}\n{6} set to {7}", _
Expand Down Expand Up @@ -212,9 +242,9 @@ Public Class fmMainWindow
Dim _fiS4_exe As FileInfo = Nothing, _fiGameSettings As FileInfo = Nothing, _fiGfxEngine As FileInfo = Nothing

'// Perform the initial checks and get the FileInfos. If we get a empty string, all is OK.
Dim _UnkownInfo As String = PerformInitialChecks(_fiS4_exe, _fiGameSettings, _fiGfxEngine)
If Not String.Equals(_UnkownInfo, String.Empty) Then
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKOWN, _UnkownInfo)
Dim _UnknownInfo As String = PerformInitialChecks(_fiS4_exe, _fiGameSettings, _fiGfxEngine)
If Not String.Equals(_UnknownInfo, String.Empty) Then
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKNOWN, _UnknownInfo)
End If

'// Read the height and width from the INI file.
Expand All @@ -230,23 +260,23 @@ Public Class fmMainWindow
If Not IsNothing(_CurrentResolution_fromGameSettings) AndAlso Not IsNothing(_CurrentResolution_fromGfxEngine) AndAlso _CurrentResolution_fromGameSettings.GameResolution = _CurrentResolution_fromGfxEngine.GameResolution Then
Return _CurrentResolution_fromGfxEngine
Else
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKOWN, "Your GameSettings.cfg and GfxEngine.dll doesn't fit together.\nSelect any Resolution and click Apply to correct this.")
Return New GameResolution(GameResolution.AVAILABLE_RESOLUTIONS.RES_UNKNOWN, "Your GameSettings.cfg and GfxEngine.dll doesn't fit together.\nSelect any Resolution and click Apply to correct this.")
End If
End Function

Private Function SHA1_CalculateHash(FileToHash As FileInfo) As String
Const BLOCKSIZE As Integer = 256 * 256

Using _SHA1 As New SHA1CryptoServiceProvider, _fs As New FileStream(FileToHash.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)
'// Get filesize
'// Get file size
Dim _fileSize As Long = _fs.Length

'// Declare buffer + other vars
Dim _readBuffer(BLOCKSIZE - 1) As Byte, _readBytes As Integer
Dim _transformBuffer As Byte(), transformBytes As Integer, _transformBytesTotal As Long = 0
'// Read first block
_readBytes = _fs.Read(_readBuffer, 0, BLOCKSIZE)
'// Read + transform blockwise
'// Read + transform block wise
While _readBytes > 0
'// Save last read
_transformBuffer = _readBuffer
Expand Down Expand Up @@ -280,6 +310,16 @@ Public Class fmMainWindow
Return _sb.ToString.ToUpper
End Function

Private Sub ShowReadMeWindow()
If IsNothing(_ReadMeWindow) OrElse _ReadMeWindow.IsDisposed Then
_ReadMeWindow = New fmReadMeWindow
_ReadMeWindow.Show()
Else
_ReadMeWindow.Show()
_ReadMeWindow.Focus()
End If
End Sub

Private Sub Message(FormattedMessage As String)
'// \n is interpreted as a new line.
tbMessages.AppendText(FormattedMessage.Replace("\n", Environment.NewLine) & Environment.NewLine)
Expand Down
6 changes: 3 additions & 3 deletions My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyDescription("Play the Settlers 4 in a Resolution, up to FullHD.")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("The Settlers 4: Gold Edition Widescreen Tool")>
<Assembly: AssemblyCopyright("Copyright © FireEmerald 2015")>
<Assembly: AssemblyCopyright("Copyright © FireEmerald 2016")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(False)>
Expand All @@ -33,7 +33,7 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("1.0.1.0")>
<Assembly: AssemblyFileVersion("1.0.1.0")>
<Assembly: AssemblyVersion("1.0.2.0")>
<Assembly: AssemblyFileVersion("1.0.2.0")>

<Assembly: NeutralResourcesLanguageAttribute("en")>
12 changes: 12 additions & 0 deletions My Project/Settings.Designer.vb

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

3 changes: 3 additions & 0 deletions My Project/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<Setting Name="S4_exe_Filepath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SkipReadMe" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit fa692be

Please sign in to comment.