about summary refs log tree commit diff
path: root/pkgs/games/gog/war-for-the-overworld.nix
blob: 754310ff34c7d216079a6c5f0797ce6e97ddaa5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{ buildUnity, fetchGog, mono, monogamePatcher }:

buildUnity {
  name = "war-for-the-overworld";
  fullName = "WFTOGame";
  saveDir = "Subterranean Games/War For The Overworld";
  version = "2.0.4";

  src = fetchGog {
    productId = 1964276929;
    sha256 = "0p54dhd2j7zvc78444jnjmkjv7kf6sskbphxkj5vlxmfcrmbd2xq";
  };

  nativeBuildInputs = [ mono monogamePatcher ];

  # The game tries to write stuff to its dataPath and it's even more
  # complicated than for most other games that try to write stuff into their
  # dataPath because the paths overlap with the assets.
  #
  # I've reported this upstream at:
  #
  # https://brightrockgames.userecho.com/communities/1/topics/4720-xdg
  #
  # So let's patch a few stuff so that at least starting the game and
  # loading/saving games will work.
  buildPhase = ''
    cat > nix-support.cs <<EOF
    using UnityEngine;
    using System.IO;

    public class NixSupport {
      public static string GetDataDir() {
        var path = Path.Combine(Application.persistentDataPath, "GameData");
        if (!Directory.Exists(path))
          Directory.CreateDirectory(path);
        return path;
      }

      public static string GetDataDir(string subpath) {
        var path = Path.Combine(NixSupport.GetDataDir(), subpath);
        if (!Directory.Exists(path))
          Directory.CreateDirectory(path);
        return path;
      }

      public static string GetFullPathMkParent(string path) {
        var fullpath = Path.GetFullPath(path);
        var dirname = Path.GetDirectoryName(fullpath);
        if (!Directory.Exists(dirname))
          Directory.CreateDirectory(dirname);
        return fullpath;
      }
    }
    EOF

    mcs nix-support.cs -target:library -r:WFTOGame_Data/Managed/UnityEngine \
      -out:WFTOGame_Data/Managed/NixSupport.dll

    monogame-patcher replace-call \
      -i WFTOGame_Data/Managed/Assembly-CSharp.dll \
      'System.String UnityEngine.Application::get_dataPath()' \
      'System.String UnityEngine.Application::get_persistentDataPath()' \
      IniParser SaveMeta::UpdateMetaDataAndMinimap SaveMeta::GetMinimapPath \
      SaveMeta::GetMinimapPath SaveMeta::GetMinimapAbsolutePath

    monogame-patcher replace-call \
      -i WFTOGame_Data/Managed/Assembly-CSharp.dll \
      -a WFTOGame_Data/Managed/NixSupport.dll \
      'System.String GameDataFolder::Get(System.String)' \
      'System.String NixSupport::GetDataDir(System.String)' \
      Serializer::MapSave DRMFree::FullPath DRMFree::OnEnable \
      SaveStatAchievementLAN::FullPath SaveStatAchievementLAN::GetFolders

    monogame-patcher replace-call \
      -i WFTOGame_Data/Managed/Assembly-CSharp.dll \
      -a WFTOGame_Data/Managed/NixSupport.dll \
      'System.String System.IO.Path::GetFullPath(System.String)' \
      'System.String NixSupport::GetFullPathMkParent(System.String)' \
      SaveMeta::GetMinimapAbsolutePath

    monogame-patcher fix-filestreams \
      -i WFTOGame_Data/Managed/Assembly-CSharp-firstpass.dll \
      UnityGTResourceHandler
  '';
}