Skip to content

Commit

Permalink
Fix bug with Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisenmonoxid committed Jan 22, 2025
1 parent 6241ca4 commit fba877f
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 240 deletions.
26 changes: 17 additions & 9 deletions Features/Modloader.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
# Modloader
The S6Patcher features a simple modloader, which makes it possible to load additional game files without having to overwrite/replace any existing files.
The files are placed in a special folder or packed into an archive file, which is then loaded by the game on startup.
The files are, depending on the game version, placed in a special folder or packed into an archive file, which is then loaded by the game on startup.

---

## Tech
### Original Release
When the `"Activate Modloader"` - option was checked when patching the game, it will try to load the file `"modloader\bba\mod.bba"` as first archive file on startup. If the file does not
When the `"Activate Modloader"` - option was checked when patching the game, it will try to load the file `"modloader\bba\mod.bba"` as its first archive file on startup. If the file does not
exist, the game will display an error message and abort the boot process.

### History Edition
Here, the process is a bit different: Since the game does not use archive files, it will add the folder path `"modloader\shr"` to its internal directory manager. The files in this
paths are loaded by the game first before loading anything else. If the path does not exist, the game will launch normally without notification.
path are loaded by the game first before loading anything else. If the path does not exist, the game will launch normally without notification.

---

## Creating a mod
Use the [bba6 - Tool](https://github.com/mcb5637/bba6tool) (written by yoq) to unpack your game files (.bba) and to create a `"mod.bba"` containing your modified game files and additional files. For the History Editions,
it is not necessary to use the bba6 - Tool, you can directly put any modified files in the folder mentioned above.
**Note:** The folder structure of the game has to be retained in the `mod.bba` / the `modloader/shr` folder.
When creating a mod for the OV, use the [bba6-Tool](https://github.com/mcb5637/bba6tool) (written by yoq) to unpack your game files (.bba) and to create a `"mod.bba"` containing your modified game files. For the History Editions,
it is not necessary to use the bba6-Tool, you can directly put any modified files in the folder mentioned above.
**Note:** The folder structure of the game has to be retained in the `mod.bba` file / the `modloader/shr` folder.

```
The full path in the Original Release should look something like this: <Program Files>\THE SETTLERS - Rise of an Empire\modloader\bba\mod.bba
In the History Edition, the path to the modified files looks like this: <Program Files>\Ubisoft\thesettlers6\modloader\shr\<Your modded files>
In the History Edition, the path to the modified files should look like this: <Program Files>\Ubisoft\thesettlers6\modloader\shr\<Your modded files>
```

---

## Small example mod (History Edition)
We want to change the default player color to yellow. So we locate the file that contains the player color mapping `<Settlers>\Data\base\shr\config\playercolor.xml`. We copy this file to to the modloader path
(the Patcher should have created the folders, if not, simply create them yourself). We have to rebuild the folder structure of the game in the `modloader\shr\` folder, so the game recognizes the modified file.
Expand All @@ -35,10 +41,12 @@ After that, we can open the .xml file in any editor and replace the second entry
</Color>
```
Save the file, start the game, and the changes should have been applied.
<img src="https://github.com/Eisenmonoxid/S6Patcher/blob/28b561a3ac6f39ad59e13dd84a3cb77610fad7fd/Features/Playercolor_Final.png" width="60%" height="60%" alt="Player_Color"/>
<img src="https://github.com/Eisenmonoxid/S6Patcher/blob/28b561a3ac6f39ad59e13dd84a3cb77610fad7fd/Features/Playercolor_Final.png" width="50%" height="50%" alt="Player_Color"/>

For the Original Release the process is basically the same, only difference is that the folders and the file must be packed into an .bba - archive with the bba6tool. The resulting .bba file must be named `mod.bba` and
For the Original Release, the process is basically the same, only difference is that the folders and the file must be packed into a .bba - archive with the bba6-Tool. The resulting .bba file must be named `mod.bba` and
must be located in the following path: `<Settlers>\modloader\bba\mod.bba`.

---

## Questions
**In case there are any questions: [Discord](https://discord.gg/7SGkQtAAET).**
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.9.0.0")]
[assembly: AssemblyFileVersion("2.9.0.0")]
[assembly: AssemblyVersion("2.9.0.1")]
[assembly: AssemblyFileVersion("2.9.0.1")]
9 changes: 0 additions & 9 deletions S6Patcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@
<Compile Include="Source\Forms\aboutBox.Designer.cs">
<DependentUpon>aboutBox.cs</DependentUpon>
</Compile>
<Compile Include="Source\Forms\modFrm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Source\Forms\modFrm.Designer.cs">
<DependentUpon>modFrm.cs</DependentUpon>
</Compile>
<Compile Include="Source\Helpers\IOFileHandler.cs" />
<Compile Include="Source\Helpers\Logger.cs" />
<Compile Include="Source\Helpers\Updater.cs" />
Expand Down Expand Up @@ -130,9 +124,6 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Source\Forms\modFrm.resx">
<DependentUpon>modFrm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Source\Resources\Scripts\UserScriptLocal.lua" />
<EmbeddedResource Include="Source\Resources\Scripts\EMXBinData.s6patcher" />
<EmbeddedResource Include="Source\Resources\Scripts\MainMenuUserScript.lua" />
Expand Down
1 change: 1 addition & 0 deletions Source/Forms/aboutBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private void lblFeatures_LinkClicked(object sender, LinkLabelLinkClickedEventArg
}
private void OpenLink(string Link, LinkLabel CurrentLabel)
{
Logger.Instance.Log("OpenLink(): " + Link);
var Info = new ProcessStartInfo(Link);
Process.Start(Info);
CurrentLabel.LinkVisited = true;
Expand Down
17 changes: 14 additions & 3 deletions Source/Forms/mainFrm.EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ private void mainFrm_FormClosing(object sender, FormClosingEventArgs e)
}
private void btnModFeatures_Click(object sender, EventArgs e)
{
modFrm Form = new modFrm();
Form.ShowDialog();
return; // Not implemented right now
}
private void cbModloader_CheckedChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -68,16 +67,20 @@ private void cbScriptBugFixes_CheckedChanged(object sender, EventArgs e)
}
private void btnPatch_Click(object sender, EventArgs e)
{
Logger.Instance.Log("btnPatch_Click(): Going to patch file ...");

SelectPatchFeatures();
string Name = GlobalStream.Name;
ResetForm();

Logger.Instance.Log("btnPatch_Click(): Finished patching file ...");

DialogResult Result;
Result = MessageBox.Show(Resources.FinishedSuccess, "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (Result == DialogResult.Yes)
{
Helpers.Helpers.CreateDesktopShortcut(Name);
}
}
}
private void mainFrm_HelpButtonClicked(object sender, System.ComponentModel.CancelEventArgs e)
{
Expand All @@ -87,18 +90,22 @@ private void mainFrm_HelpButtonClicked(object sender, System.ComponentModel.Canc
}
private void btnAbort_Click(object sender, EventArgs e)
{
Logger.Instance.Log("btnAbort_Click(): Exiting application ...");
CloseFileStream();
Environment.Exit(0);
}
private void btnBackup_Click(object sender, EventArgs e)
{
Logger.Instance.Log("btnBackup_Click(): Restoring backup ...");
bool Result = IOFileHandler.Instance.RestoreBackup(ref GlobalStream);
if (Result == false)
{
Logger.Instance.Log(Resources.ErrorBackupFail);
MessageBox.Show(Resources.ErrorBackupFail, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
Logger.Instance.Log(Resources.FinishedBackup);
MessageBox.Show(Resources.FinishedBackup, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

Expand All @@ -112,13 +119,15 @@ private void btnChooseFile_Click(object sender, EventArgs e)
{
if (IOFileHandler.Instance.CreateBackup(ofd.FileName) == false)
{
Logger.Instance.Log(Resources.ErrorBackup);
MessageBox.Show(Resources.ErrorBackup, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}

GlobalStream = IOFileHandler.Instance.OpenFileStream(ofd.FileName);
if (GlobalStream == null)
{
Logger.Instance.Log(Resources.ErrorWrongVersion);
MessageBox.Show(Resources.ErrorWrongVersion, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
Expand All @@ -127,6 +136,7 @@ private void btnChooseFile_Click(object sender, EventArgs e)
if (ValidExecutable == false)
{
CloseFileStream();
Logger.Instance.Log(Resources.ErrorWrongVersion);
MessageBox.Show(Resources.ErrorWrongVersion, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
Expand All @@ -137,6 +147,7 @@ private void btnChooseFile_Click(object sender, EventArgs e)
}
else
{
Logger.Instance.Log(Resources.ErrorNoFile);
MessageBox.Show(Resources.ErrorNoFile, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Expand Down
5 changes: 4 additions & 1 deletion Source/Forms/mainFrm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public mainFrm()
{
InitializeComponent();
this.Text = "S6Patcher - v" + Application.ProductVersion;
Logger.Instance.Log("Startup successful!");
Logger.Instance.Log("Startup successful! Text: " + this.Text);
}
private void SetControlValueFromStream(ref BinaryReader Reader, long Position, TextBox Control)
{
Expand Down Expand Up @@ -104,6 +104,7 @@ private List<string> GetPatchFeaturesByControls(List<GroupBox> Controls)

if (curControl.Checked)
{
Logger.Instance.Log("GetPatchFeaturesByControls(): Feature " + curControl.Text + " was checked!");
CheckedFeatures.Add(curControl.Text);
}
}
Expand Down Expand Up @@ -192,6 +193,8 @@ private void ResetForm()
btnBackup.Enabled = false;
btnModFeatures.Enabled = false;
txtExecutablePath.Text = String.Empty;

Logger.Instance.Log("ResetForm(): Form successfully reset!");
}
}
}
46 changes: 0 additions & 46 deletions Source/Forms/modFrm.Designer.cs

This file was deleted.

20 changes: 0 additions & 20 deletions Source/Forms/modFrm.cs

This file was deleted.

120 changes: 0 additions & 120 deletions Source/Forms/modFrm.resx

This file was deleted.

Loading

0 comments on commit fba877f

Please sign in to comment.