From da1a5d93fb213d2923e2e3d031361f00031284ec Mon Sep 17 00:00:00 2001
From: Wojciech Zylinski <w.zylinski@boskee.co.uk>
Date: Tue, 18 Aug 2020 01:29:39 +0100
Subject: [PATCH 1/3] Fixed Access Violation on Windows 10 (x64)

hFile should be defined as intptr_t to resolve 0xC0000005: Access Violation in ntdll.dll, as per https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/findnext-functions?redirectedfrom=MSDN&view=vs-2019
---
 src/stratagus/iolib.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/stratagus/iolib.cpp b/src/stratagus/iolib.cpp
index 39f74f67a..7e21b8f99 100644
--- a/src/stratagus/iolib.cpp
+++ b/src/stratagus/iolib.cpp
@@ -715,8 +715,8 @@ int ReadDataDirectory(const char *dirname, std::vector<FileList> &fl)
 #else
 	strcat_s(buffer, sizeof(buffer), "*.*");
 	struct _finddata_t fileinfo;
-	long hFile = _findfirst(buffer, &fileinfo);
-	if (hFile != -1L) {
+	intptr_t hFile = _findfirst(buffer, &fileinfo);
+	if (hFile != -1) {
 		do {
 			filename = fileinfo.name;
 #endif

From 4ef8e5388845dc62a1964c32cd202ed3b30d170c Mon Sep 17 00:00:00 2001
From: Tim Felgentreff <timfelgentreff@gmail.com>
Date: Sun, 20 Sep 2020 15:14:39 +0200
Subject: [PATCH 2/3] commit vscode settings

---
 .gitignore                   |  7 ++++++-
 .vscode/extensions.json      |  0
 .vscode/launch.json          | 28 ++++++++++++++++++++++++++++
 .vscode/scripts/download.ps1 |  4 ++++
 .vscode/settings.json        | 16 ++++++++++++++++
 .vscode/tasks.json           | 16 ++++++++++++++++
 6 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 .vscode/extensions.json
 create mode 100644 .vscode/launch.json
 create mode 100644 .vscode/scripts/download.ps1
 create mode 100644 .vscode/settings.json
 create mode 100644 .vscode/tasks.json

diff --git a/.gitignore b/.gitignore
index 2cd9fadcb..e6d9f7f11 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,11 @@ obj-*
 ./tolua.cpp
 ./tolua.cpp.rule
 build
-.vscode
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+!.vscode/scripts
 .clangd
 compile_commands.json
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 000000000..e69de29bb
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 000000000..0e1fe0144
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,28 @@
+{
+    "configurations": [
+        {
+            "name": "Stratagus",
+            "type": "cppvsdbg",
+            "request": "launch",
+            "program": "${workspaceFolder}/build/Debug/stratagus.exe",
+            "args": ["-d", "${env:APPDATA}/Stratagus/data.${input:game}"],
+            "stopAtEntry": false,
+            "cwd": "${workspaceFolder}/../${input:game}",
+            "environment": [{"name": "PATH", "value": "${workspaceFolder}\\..\\dependencies\\bin;${env:PATH}"}],
+            "externalConsole": true
+        }
+    ],
+    "inputs": [
+        {
+          "type": "pickString",
+          "id": "game",
+          "description": "Which game to launch?",
+          "options": [
+            "wargus",
+            "war1gus",
+            "stargus",
+          ],
+          "default": "wargus"
+        },
+    ]
+}
diff --git a/.vscode/scripts/download.ps1 b/.vscode/scripts/download.ps1
new file mode 100644
index 000000000..20137e8ad
--- /dev/null
+++ b/.vscode/scripts/download.ps1
@@ -0,0 +1,4 @@
+curl https://github.com/Wargus/win32-stratagus-dependencies/releases/download/master-builds/dependencies.zip -OutFile "$args[0]/../dependencies.zip"
+Expand-Archive "$args[0]/../dependencies.zip"
+move "$args[0]/../dependencies/dependencies/"* "$args[0]/../dependencies/"
+curl https://github.com/Wargus/stratagus/releases/download/2015-30-11/ffmpeg.exe -OutFile "$args[0]/../dependencies/bin/ffmpeg.exe"
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 000000000..268ae4ab9
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,16 @@
+{
+    "cmake.configureEnvironment": {
+        "CMAKE_PREFIX_PATH": "${workspaceFolder}\\..\\dependencies",
+    },
+    "cmake.configureArgs": [
+        "-DENABLE_STDIO_REDIRECT=ON",
+        //"-G", "Visual Studio 16 2019",
+        //"-T", "v141_xp",
+        //"-A", "win32",
+    ],
+    "cmake.generator":  "Visual Studio 16 2019",
+    "cmake.toolset": "v141_xp",
+    "cmake.platform": "win32",
+    "cmake.copyCompileCommands": "${workspaceFolder}",
+    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
+}
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 000000000..ffab72cb9
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,16 @@
+{
+    "version": "2.0.0",
+    "tasks": [
+        {
+            "label": "Download games and dependencies",
+            "type": "shell",
+            "command": "PowerShell.exe -ExecutionPolicy Bypass -File ${workspaceFolder}/.vscode/scripts/download.ps1 '${workspaceFolder}'",
+            "problemMatcher": [],
+            "group": "build",
+            "presentation": {
+                "reveal": "always",
+                "panel": "new"
+            }
+        }
+    ]
+}

From 72f8ea9e7d34ac6ae3cb1f1619b90c678a846be0 Mon Sep 17 00:00:00 2001
From: Tim Felgentreff <timfelgentreff@gmail.com>
Date: Mon, 21 Sep 2020 09:28:52 +0200
Subject: [PATCH 3/3] improve task for auto-download of related projects and
 dependencies

---
 .vscode/scripts/download.ps1 | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/.vscode/scripts/download.ps1 b/.vscode/scripts/download.ps1
index 20137e8ad..03e29de4e 100644
--- a/.vscode/scripts/download.ps1
+++ b/.vscode/scripts/download.ps1
@@ -1,4 +1,16 @@
-curl https://github.com/Wargus/win32-stratagus-dependencies/releases/download/master-builds/dependencies.zip -OutFile "$args[0]/../dependencies.zip"
-Expand-Archive "$args[0]/../dependencies.zip"
-move "$args[0]/../dependencies/dependencies/"* "$args[0]/../dependencies/"
-curl https://github.com/Wargus/stratagus/releases/download/2015-30-11/ffmpeg.exe -OutFile "$args[0]/../dependencies/bin/ffmpeg.exe"
+if (-not (Test-Path "$args[0]/../dependencies")) {
+    if (-not (Test-Path "$args[0]/../dependencies.zip")) {
+        Invoke-WebRequest https://github.com/Wargus/win32-stratagus-dependencies/releases/download/master-builds/dependencies.zip -OutFile "$args[0]/../dependencies.zip"
+    }
+    Expand-Archive "$args[0]/../dependencies.zip"
+    Move-Item "$args[0]/../dependencies/dependencies/"* "$args[0]/../dependencies/"
+}
+if (-not (Test-Path "$args[0]/../dependencies/bin/ffmpeg.exe")) {
+    Invoke-WebRequest https://github.com/Wargus/stratagus/releases/download/2015-30-11/ffmpeg.exe -OutFile "$args[0]/../dependencies/bin/ffmpeg.exe"
+}
+if (-not (Test-Path "$args[0]/../wargus")) {
+    git clone https://github.com/Wargus/wargus "$args[0]/../wargus"
+}
+if (-not (Test-Path "$args[0]/../war1gus")) {
+    git clone https://github.com/Wargus/wargus "$args[0]/../war1gus"
+}