Skip to content

Commit

Permalink
UserScript is now deleted when backup is restored
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisenmonoxid committed Nov 26, 2024
1 parent f4a89fe commit b00d185
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
46 changes: 45 additions & 1 deletion Helpers/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using S6Patcher.Properties;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows.Forms;

Expand Down Expand Up @@ -125,8 +128,49 @@ public static bool CheckExecVersion(ref FileStream Reader, execID Identifier, In
return false;
}
}
public static List<string> GetUserScriptDirectories()
{
// <Documents>/Settlers/Script/UserScriptGlobal.lua && UserScriptLocal.lua are always loaded by the game when a map is started!
string DocumentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

List<string> Directories = new List<string>();
foreach (string Element in Directory.GetDirectories(DocumentPath))
{
if (Element.Contains("Aufstieg eines") || Element.Contains("Rise of an"))
{
Directories.Add(Path.Combine(DocumentPath, Element));
}
}

return Directories;
}
public static void RestoreUserScriptFiles()
{
string LocalScriptFile = "UserScriptLocal.lua";
List<string> Directories = GetUserScriptDirectories();

string ScriptPath = String.Empty;
foreach (string Element in Directories)
{
ScriptPath = Path.Combine(Element, "Script");
if (!Directory.Exists(ScriptPath))
{
continue;
}
try
{
File.Delete(Path.Combine(ScriptPath, LocalScriptFile));
}
catch (Exception) // Errors here do not matter
{
continue;
}
}
}
public static bool RestoreBackup(string filePath)
{
RestoreUserScriptFiles(); // Delete Userscript from Folders

string FileName = Path.GetFileNameWithoutExtension(filePath);
string DirectoryPath = Path.GetDirectoryName(filePath);
string FinalPath = Path.Combine(DirectoryPath, FileName + "_BACKUP.exe");
Expand Down
12 changes: 1 addition & 11 deletions Patcher/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,8 @@ public void SetLargeAddressAwareFlag(ref FileStream Stream)
}
public void SetLuaScriptBugFixes()
{
// <Documents>/Settlers/Script/UserScriptGlobal.lua && UserScriptLocal.lua are always loaded by the game when a map is started!
string LocalScriptFile = "UserScriptLocal.lua";
string DocumentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

List<string> Directories = new List<string>();
foreach (string Element in Directory.GetDirectories(DocumentPath))
{
if (Element.Contains("Aufstieg eines") || Element.Contains("Rise of an"))
{
Directories.Add(Path.Combine(DocumentPath, Element));
}
}
List<string> Directories = Helpers.GetUserScriptDirectories();

try
{
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

### Patch Original Game
- Für die Originalversion (OV) mit neuestem Patch 1.71.
- For the original game (OV) with newest Patch 1.71.
- For the original game (OV) with latest Patch 1.71.

German:
```
Expand All @@ -16,7 +16,7 @@ German:
- Kann das maximale Zoomlevel setzen.
- Kann das Large Address Aware Flag setzen, um mehr adressierbaren Speicher zu haben.
- Kann den Development-Mode ohne Registry-Key dauerhaft aktivieren.
- Kann den Meldungsstau - Bug im Spiel fixen (und andere Bugs im Lua-Script).
- Kann Script&Code-Bugs fixen (z.B. "Meldungsstau", "Entertainercrash").
-> Originalversionen von Steam müssen zuerst mit dem Tool "Steamless" entpackt werden!
```
English:
Expand All @@ -26,20 +26,20 @@ English:
- Can set the maximum zoom level in the game.
- Can activate the Development-Mode permanently without Registry-Key.
- Can set the Large Address Aware Flag for more usable memory.
- Can fix the "Meldungsstau" - Bug in the game (and other bugs in the Lua-Script).
- Can fix Bugs in Script&Code (e.g. "Meldungsstau", "Entertainercrash").
-> Original versions from Steam will need to be extracted with the tool "Steamless" first!
```
### Patch History Edition
- Für die History Edition von Ubisoft Connect und Steam.
- For the History Edition from Ubisoft Connect and Steam.
- Für alle History Editions.
- For all History Editions.

German:
```
- Kann den Development-Mode aktivieren (Notwendig für die Funktion des LuaDebuggers).
- Kann den Autosave deaktivieren oder einen benutzerdefinierten Intervall setzen.
- Kann das maximale Zoomlevel setzen.
- Kann das Large Address Aware Flag aktivieren, um mehr adressierbaren Speicher zu haben.
- Kann den Meldungsstau - Bug im Spiel fixen (und andere Bugs im Lua-Script).
- Kann Script&Code-Bugs fixen (z.B. "Meldungsstau", "Entertainercrash").
- Kann die Qualität von Bodentexturen auf einen benutzerdefinierten Wert setzen.
-> History Editions von Steam müssen zuerst mit dem Tool "Steamless" entpackt werden!
```
Expand All @@ -49,13 +49,13 @@ English:
- Can disable the autosave or set an custom timer interval.
- Can set the maximum zoom level in the game.
- Can set the Large Address Aware Flag for more usable memory.
- Can fix the "Meldungsstau" - Bug in the game (and other bugs in the Lua-Script).
- Can fix Bugs in Script&Code (e.g. "Meldungsstau", "Entertainercrash").
- Can enable highest quality ground textures or set a custom value.
-> History Editions from Steam will need to be extracted with the tool "Steamless" first!
```
### Patch Editor (OV and HE)
- Für alle Editoren, egal ob OV oder die beiden History Editions (Ubisoft Connect und Steam).
- For every Editor version, no matter if from the original game or from one of the History Editions.
- Für alle Editoren.
- For all Editors.

German:
```
Expand Down

0 comments on commit b00d185

Please sign in to comment.