Skip to content

Commit

Permalink
Improved patcher, fixed crash when starting AA
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrdacor committed May 10, 2023
1 parent 3801f4c commit 4d20db6
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Ambermoon.Core/GameVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class GameVersion
public bool ExternalData;
public Func<IGameData> DataProvider;

internal const string RemakeReleaseDate = "09-05-2023";
internal const string RemakeReleaseDate = "10-05-2023";
}

public static class GameLanguageExtensions
Expand Down
4 changes: 2 additions & 2 deletions Ambermoon.Core/Render/TextureAtlasManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void AddFont(IFontProvider fontProvider)
}

public void AddAll(IGameData gameData, IGraphicProvider graphicProvider, IFontProvider fontProvider,
Dictionary<uint, Graphic> introTextGlyphs, Dictionary<uint, Graphic> introGraphics)
Dictionary<uint, Graphic> introTextGlyphs, Dictionary<uint, Graphic> introGraphics, Features features)
{
if (gameData == null)
throw new ArgumentNullException(nameof(gameData));
Expand Down Expand Up @@ -221,7 +221,7 @@ public void AddAll(IGameData gameData, IGraphicProvider graphicProvider, IFontPr
// On world maps the travel graphics are used.
// Only 4 sprites are used (one for each direction).
var travelGraphics = graphicProvider.GetGraphics(GraphicType.TravelGfx);
int count = gameData.Advanced ? 12 : 11;
int count = features.HasFlag(Features.WaspTransport) ? 12 : 11;

if (travelGraphics.Count != count * 4)
throw new AmbermoonException(ExceptionScope.Data, "Wrong number of travel graphics.");
Expand Down
8 changes: 4 additions & 4 deletions Ambermoon.Core/UI/VersionSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ void AddBorder(PopupFrame frame, int column, int row)
string text = BuildVersionEntryText(gameVersion);
var versionArea = new Rect(versionListArea.X, versionListArea.Y + index * 10, versionListArea.Width, 10);
var markerArea = versionArea.CreateModified(0, 0, 0, -1);
var highlight = versionHighlights[index] = FillArea(markerArea, Color.White, 3);
var highlight = versionHighlights[index] = FillArea(markerArea, Color.White, 6);
highlight.Visible = false;
versionTexts[index] = AddText(new Position(versionArea.X + 1, versionArea.Y + 2), text, TextColor.White, true, 7);
versionTextHighlightShadows[index] = AddText(new Position(versionArea.X + 2, versionArea.Y + 3), text, TextColor.LightGray, false, 5);
versionTexts[index] = AddText(new Position(versionArea.X + 1, versionArea.Y + 2), text, TextColor.White, true, 14);
versionTextHighlightShadows[index] = AddText(new Position(versionArea.X + 2, versionArea.Y + 3), text, TextColor.LightGray, false, 10);
versionTextHighlightShadows[index].Visible = false;
if (SelectedVersion == index)
selectedVersionMarker = FillArea(markerArea, Color.Green, 1);
selectedVersionMarker = FillArea(markerArea, Color.Green, 2);
versionAreas.Add(versionArea);

mergedGameVersions.Add(new List<GameVersion>() { gameVersion });
Expand Down
5 changes: 3 additions & 2 deletions Ambermoon.Data.Common/Enumerations/Features.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum Features : ushort
AdjustedSPAndSLP = 0x10,
AdjustedEPFactors = 0x20,
SageScrollIdentification = 0x40,
AdvancedSpells = 0x80,
AmbermoonAdvanced = Elements | AdjustedSpellDamage | SpellDamageBonus | ReducedFoodWeight | AdjustedSPAndSLP | AdjustedEPFactors | SageScrollIdentification | AdvancedSpells
AdvancedSpells = 0x80, // TODO: Add later to AmbermoonAdvanced
WaspTransport = 0x100, // TODO: Add later to AmbermoonAdvanced
AmbermoonAdvanced = Elements | AdjustedSpellDamage | SpellDamageBonus | ReducedFoodWeight | AdjustedSPAndSLP | AdjustedEPFactors | SageScrollIdentification
}
}
2 changes: 1 addition & 1 deletion Ambermoon.net/Ambermoon.net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Ambermoon</RootNamespace>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
<Version>1.8.5</Version>
<Version>1.8.6</Version>
<Copyright>Copyright (C) 2020-2023 by Robert Schneckenhaus</Copyright>
<Company>Robert Schneckenhaus</Company>
<Authors>Robert Schneckenhaus</Authors>
Expand Down
15 changes: 9 additions & 6 deletions Ambermoon.net/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ void StartGame(IGameData gameData, string savePath, GameLanguage gameLanguage, F
{
var textureAtlasManager = TextureAtlasManager.Instance;
textureAtlasManager.AddAll(gameData, graphicProvider, fontProvider, introFont.GlyphGraphics,
introData.Graphics.ToDictionary(g => (uint)g.Key, g => g.Value));
introData.Graphics.ToDictionary(g => (uint)g.Key, g => g.Value), features);
logoPyrdacor?.Initialize(textureAtlasManager);
AdvancedLogo.Initialize(textureAtlasManager);
return textureAtlasManager;
Expand Down Expand Up @@ -1381,17 +1381,20 @@ void CheckPatches()
{
configuration.PatcherTimeout ??= 1250;
int timeout = configuration.PatcherTimeout.Value;
patcher.CheckPatches(afterCloseAction =>
patcher.CheckPatches(ok =>
{
if (afterCloseAction?.Invoke() == true)
if (ok)
window.Close();
}, () =>
else
NotPatched();
}, NotPatched, ref timeout);
configuration.PatcherTimeout = timeout;
void NotPatched()
{
patcher?.CleanUp(true);
patcher = null;
logoPyrdacor?.PlayMusic();
}, ref timeout);
configuration.PatcherTimeout = timeout;
}
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion Ambermoon.net/Mac/Ambermoon.net.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleName</key>
<string>Ambermoon.net</string>
<key>CFBundleVersion</key>
<string>1.8.5</string>
<string>1.8.6</string>
<key>CFBundleIconFile</key>
<string>Ambermoon.icns</string>
<key>CFBundleIdentifier</key>
Expand Down
43 changes: 32 additions & 11 deletions Ambermoon.net/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ void AddBorder(UIGraphic frame, int column, int row)
"Ambermoon {0} wird heruntergeladen ...",
"{0} von {1}",
"Fertig",
"Download abbrechen"
"Download abbrechen",
"Fehler beim Patchen. Bitte lade dir die neuste Version manuell herunter."
}
},
{ GameLanguage.English, new string[]
Expand All @@ -167,7 +168,8 @@ void AddBorder(UIGraphic frame, int column, int row)
"Downloading Ambermoon {0} ...",
"{0} of {1}",
"Done",
"Cancel download"
"Cancel download",
"Failed to apply patch. Please download the most recent version manually."
}
},
{ GameLanguage.French, new string[]
Expand All @@ -181,7 +183,8 @@ void AddBorder(UIGraphic frame, int column, int row)
"Télécharger Ambermoon {0} ...",
"{0} de {1}",
"Terminé",
"Annuler"
"Annuler",
"Échec de l'application du correctif. Veuillez télécharger manuellement la version la plus récente."
}
}
};
Expand All @@ -197,7 +200,8 @@ enum TextId
Downloading,
Progress,
Done,
AbortButton
AbortButton,
FailedToPatch
}

string GetText(TextId index)
Expand Down Expand Up @@ -250,7 +254,7 @@ UI.Button AddButton(ButtonType buttonType, int x, int y, Action buttonAction, by
}
}

public void CheckPatches(Action<Func<bool>> closeAppAction, Action noPatchAction, ref int timeout)
public void CheckPatches(Action<bool> closeAppAction, Action noPatchAction, ref int timeout)
{
string version;
using var httpClient = new HttpClient();
Expand Down Expand Up @@ -449,7 +453,7 @@ void SafeDisposeClient()

clickHandler = () =>
{
closeAppAction(() => WriteAndRunInstaller(tempPath));
WriteAndRunInstaller(tempPath, closeAppAction);
};
}
else if (!finished)
Expand Down Expand Up @@ -667,8 +671,10 @@ public void OnMouseDown(Position position, MouseButtons buttons)
{
if (clickHandler != null)
{
var oldHandler = clickHandler;
clickHandler();
clickHandler = null;
if (clickHandler == oldHandler)
clickHandler = null;
return;
}

Expand Down Expand Up @@ -778,18 +784,33 @@ static bool TestWritePermission()

}

bool WriteAndRunInstaller(string downloadPath)
void WriteAndRunInstaller(string downloadPath, Action<bool> resultHandler)
{
try
{
var installDirectory = Configuration.ExecutableDirectoryPath;
Process.Start(patcherPath, $"\"{downloadPath}\" \"{installDirectory}\"");
return true;
ExecuteAsAdmin(patcherPath, $"\"{downloadPath}\" \"{installDirectory}\"");
resultHandler?.Invoke(true);
}
catch
{
Console.WriteLine("Unable to write or start the patcher script. Please update the game manually.");
return false;
CleanUpTextsAndButtons(true);
AddText(GetText(TextId.FailedToPatch),
new Rect(clientArea.X + 4, clientArea.Y + 18, clientArea.Width - 8, 42), Data.Enumerations.Color.LightRed, TextAlign.Left, 50, true);
AddText(GetText(TextId.ContinueWithClick), new Rect(clientArea.X, clientArea.Y + 64, clientArea.Width, 7),
Data.Enumerations.Color.White, TextAlign.Center, 50, true);
clickHandler = () => resultHandler?.Invoke(false);
}

static void ExecuteAsAdmin(string fileName, string args)
{
var proc = new Process();
proc.StartInfo.FileName = fileName;
proc.StartInfo.Arguments = args;
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.Verb = "runas";
proc.Start();
}
}
}
Expand Down
Binary file modified Ambermoon.net/versions.dat
Binary file not shown.
3 changes: 2 additions & 1 deletion AmbermoonPatcher/AmbermoonPatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishTrimmed>true</PublishTrimmed>
<Version>1.8.5</Version>
<Version>1.8.6</Version>
<Configurations>Debug;Release;DebugES;ReleaseES</Configurations>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions AmbermoonPatcher/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
</assembly>
2 changes: 1 addition & 1 deletion Package/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


------------------------------------------------------------------
| Ambermoon rewrite by Pyrdacor - Version 1.8.5 - May 2023 |
| Ambermoon rewrite by Pyrdacor - Version 1.8.6 - May 2023 |
------------------------------------------------------------------


Expand Down
4 changes: 3 additions & 1 deletion build-arm64.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mkdir publish-arm64
copy versions.dat publish-arm64
cp ./Ambermoon.net/versions.dat publish-arm64
cp ./Ambermoon.net/diffs.dat publish-arm64
dotnet publish -c Debug ./Ambermoon.ConcatFiles/Ambermoon.ConcatFiles.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r linux-arm64 --nologo --self-contained -o ./publish-arm64
dotnet publish -c Debug ./Ambermoon.net/Ambermoon.net.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r linux-arm64 --nologo --self-contained -o ./publish-arm64
dotnet publish -c Debug ./AmbermoonPatcher/AmbermoonPatcher.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r linux-arm64 --nologo --self-contained -o ./publish-arm64
cd publish-arm64
./Ambermoon.ConcatFiles versions versions.dat patcher AmbermoonPatcher Ambermoon.net
rm ./versions.dat
rm ./diffs.dat
rm ./Ambermoon.ConcatFiles
4 changes: 3 additions & 1 deletion build-linux.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mkdir publish-linux
copy versions.dat publish-linux
cp ./Ambermoon.net/versions.dat publish-linux
cp ./Ambermoon.net/diffs.dat publish-linux
dotnet publish -c Debug ./Ambermoon.ConcatFiles/Ambermoon.ConcatFiles.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r linux-x64 --nologo --self-contained -o ./publish-linux
dotnet publish -c Debug ./Ambermoon.net/Ambermoon.net.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r linux-x64 --nologo --self-contained -o ./publish-linux
dotnet publish -c Debug ./AmbermoonPatcher/AmbermoonPatcher.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r linux-x64 --nologo --self-contained -o ./publish-linux
cd publish-v
Ambermoon.ConcatFiles versions versions.dat patcher AmbermoonPatcher Ambermoon.net
rm ./versions.dat
rm ./diffs.dat
rm ./Ambermoon.ConcatFiles
4 changes: 2 additions & 2 deletions build-win64.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mkdir publish-win64
copy versions.dat publish-win64
copy diffs.dat publish-win64
copy Ambermoon.net\versions.dat publish-win64\versions.dat
copy Ambermoon.net\diffs.dat publish-win64\diffs.dat
dotnet publish -c Debug ./Ambermoon.ConcatFiles/Ambermoon.ConcatFiles.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r win-x64 --nologo --self-contained -o ./publish-win64
dotnet publish -c Debug ./Ambermoon.net/Ambermoon.net.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r win-x64 --nologo --self-contained -o ./publish-win64
dotnet publish -c Debug ./AmbermoonPatcher/AmbermoonPatcher.csproj -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -r win-x64 --nologo --self-contained -o ./publish-win64
Expand Down
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog


## 1.8.0 - Eighth patch (July 2022 - March 2023)
## 1.8.0 - Eighth patch (July 2022 - May 2023)

- Version [1.8.6](https://github.com/Pyrdacor/Ambermoon.net/releases/tag/v1.8.6): Advanced start crash fix for 1.8.5
- Version [1.8.5](https://github.com/Pyrdacor/Ambermoon.net/releases/tag/v1.8.5): Added game data version 1.18, fixed dmg/def calculation
- Version [1.8.4](https://github.com/Pyrdacor/Ambermoon.net/releases/tag/v1.8.4): Important savegame bugfix, input crash fix
- Version [1.8.3](https://github.com/Pyrdacor/Ambermoon.net/releases/tag/v1.8.3): Bugfixes
- Version [1.8.2](https://github.com/Pyrdacor/Ambermoon.net/releases/tag/v1.8.2): Added fantasy intro, french version and language selection
Expand Down

0 comments on commit 4d20db6

Please sign in to comment.