Skip to content

Commit

Permalink
Merge pull request #1646 from NPBruce/dev/2.6
Browse files Browse the repository at this point in the history
Rolling Dev/2.6 into master
  • Loading branch information
Quantumrunner authored Nov 22, 2023
2 parents b949d54 + 2f37f93 commit 43c55f5
Show file tree
Hide file tree
Showing 182 changed files with 19,985 additions and 2,490 deletions.
20 changes: 16 additions & 4 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ echo --- ERROR --- UNITY_EDITOR_HOME path not set : please set unity editor
exit /B
)

rem find visual studio installation path so we can find the msbuild executable. e.g. in C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\
rem this way we can find whatever year/version of vs is installed.
FOR /D %%B in ("%ProgramFiles%\Microsoft Visual Studio\*") do (SET "VSPATH=%%B")

echo using visual studio path: %VSPATH%

rem you can get NSIS from https://nsis.sourceforge.io/Main_Page
SET PATH=%PATH%;%JDK_HOME%\bin;%UNITY_EDITOR_HOME%;%ProgramFiles%\7-Zip;%WinDir%/Microsoft.NET/Framework/v4.0.30319;%ProgramFiles(x86)%\NSIS;%~dp0libraries\SetVersion\bin\Release;%ANDROID_BUILD_TOOLS%
@echo on
SET PATH=%PATH%;%JDK_HOME%\bin;%UNITY_EDITOR_HOME%;%ProgramFiles%\7-Zip;%VSPATH%\Community\MSBuild\Current\Bin\;%ProgramFiles(x86)%\NSIS;%~dp0libraries\SetVersion\bin\Release;%ANDROID_BUILD_TOOLS%;%localappdata%\NuGet;%ProgramFiles%\Git\bin

rem cleanup
rmdir /s /q build\android
Expand Down Expand Up @@ -70,9 +75,16 @@ mkdir build\macos
mkdir build\macos\Valkyrie.app
mkdir build\linux

rem download the latest version of Android Storage Access Framework library.
POWERSHELL -Command "Invoke-WebRequest -Uri https://github.com/seinsinnes/FSAF/releases/latest/download/fsaf-release.aar -OutFile .\unity\Assets\Plugins\Android\fsaf-release.aar"

rem Because reasons
set Target=

rem install any external packages required by the libraries
winget install -q Microsoft.NuGet -l "%localappdata%\NuGet" --accept-source-agreements --accept-package-agreements
nuget restore libraries/libraries.sln

rem Build libraries
msbuild libraries/libraries.sln /nologo /p:Configuration="Release" /p:NoWarn=0108

Expand All @@ -81,7 +93,7 @@ SetVersion %~dp0

rem build unity
Unity -batchmode -quit -projectPath "%~dp0unity" -buildWindowsPlayer ..\build\win\valkyrie.exe
rem copy %LOCALAPPDATA%\Unity\Editor\Editor.log %LOCALAPPDATA%\Unity\Editor\Editor_valkyrie-windows.log
rem copy %LOCALAPPDATA%\Unity\Editor\Editor.log ..\build\Editor_valkyrie-windows.log

Unity -batchmode -quit -projectPath "%~dp0unity" -buildTarget OSXUniversal -buildOSXUniversalPlayer ..\build\macos\Valkyrie.app
rem copy %LOCALAPPDATA%\Unity\Editor\Editor.log %LOCALAPPDATA%\Unity\Editor\Editor_valkyrie-macos.log
Expand All @@ -90,7 +102,7 @@ Unity -batchmode -quit -projectPath "%~dp0unity" -buildLinuxUniversalPlayer ..\b
rem copy %LOCALAPPDATA%\Unity\Editor\Editor.log %LOCALAPPDATA%\Unity\Editor\Editor_valkyrie-linux.log

Unity -batchmode -quit -projectPath "%~dp0unity" -executeMethod PerformBuild.CommandLineBuildAndroid +buildlocation "%~dp0build\android\Valkyrie-android.apk"
rem copy %LOCALAPPDATA%\Unity\Editor\Editor.log %LOCALAPPDATA%\Unity\Editor\Editor_valkyrie-android.log
rem copy %LOCALAPPDATA%\Unity\Editor\Editor.log Editor_valkyrie-android.log

rem delete the META-INF from the apk
7z -tzip d "%~dp0build\android\Valkyrie-android.apk" META-INF
Expand Down
90 changes: 73 additions & 17 deletions libraries/FFGAppImport/AssetImport/AppFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ abstract public class AppFinder
public abstract string Executable();
public abstract string RequiredFFGVersion();
public abstract string ObbPath();
public abstract string DataPath();
public abstract string AuxDataPath();
public string location = "";
public string obbRoot = "";
public string obbVersion = "";
public string exeLocation;
public string apkPath;
public abstract int ObfuscateKey();

public Platform platform;
Expand Down Expand Up @@ -140,32 +143,57 @@ internal void DeleteObb()
if (platform != Platform.Android) return;
if (!Directory.Exists(obbRoot)) return;
Directory.Delete(obbRoot, true);
}

public void ExtractObb()
}

public void ExtractApk()
{
if (platform != Platform.Android) return;

ValkyrieDebug.Log("Extracting the file " + apkPath + " to " + obbRoot);
DeleteObb();
Directory.CreateDirectory(obbRoot);
using (var zip = ZipFile.Read(apkPath))
{
zip.ExtractAll(obbRoot);
}

}

public bool ExtractObb()
{
if (platform != Platform.Android) return true;
//string obbFile = "C:/Users/Bruce/Desktop/Mansions of Madness_v1.3.5_apkpure.com/Android/obb/com.fantasyflightgames.mom/main.598.com.fantasyflightgames.mom.obb";
//string obbFile = "C:/Users/Bruce/Desktop/Road to Legend_v1.3.1_apkpure.com/Android/obb/com.fantasyflightgames.rtl/main.319.com.fantasyflightgames.rtl.obb";
string obbPath = ObbPath();
if (obbPath == "") return false;
ValkyrieDebug.Log("Extracting the file " + obbPath + " to " + obbRoot);
DeleteObb();
Directory.CreateDirectory(obbRoot);
using (var zip = ZipFile.Read(obbPath))
try
{
zip.ExtractAll(obbRoot);
}
Directory.CreateDirectory(obbRoot);
using (var zip = ZipFile.Read(obbPath))
{
zip.ExtractAll(obbRoot);
}

ConvertObbStreamingAssets();
ConvertObbAssets();
ConvertObbStreamingAssets();
ConvertObbAssets();
return true;
}
catch (System.Exception e)
{
ValkyrieDebug.Log(e.ToString());
return false;
}
}

internal string ExtractObbVersion()
{
if (platform != Platform.Android) return "";

if (!string.IsNullOrEmpty(obbVersion)) return obbVersion; // lookup version only once
string obbPath = ObbPath();
if (obbPath == "") return "";
ValkyrieDebug.Log("Extracting the version from " + obbPath + ".");
using (var zip = ZipFile.Read(obbPath))
{
Expand Down Expand Up @@ -287,18 +315,46 @@ private void ConvertObbStreamingAssets()
Directory.Move(dirAssetBundles, dirAssetBundlesWin);
}

protected string GetObbPath(string prefix, string suffix)
public string GetDataPath(string packageName)
{

return Android.GetStorage() + "/Android/data/" + packageName;
}

public string GetAuxDataPath(string packageName)
{

return Android.GetStorage() + "/Valkyrie/" + packageName;
}

protected string GetObbPath(string prefix, string suffix, string altprefix = null)
{
if (prefix == null) throw new ArgumentNullException("prefix");
if (suffix == null) throw new ArgumentNullException("suffix");
if (suffix == null) throw new ArgumentNullException("suffix");
try
{
string location = Path.Combine(Android.GetStorage(), prefix);

string location = Path.Combine(Android.GetStorage(), prefix);
if (!Directory.Exists(location))
{
return "";
if (!Directory.Exists(location))
{
return "";
}
var file = Directory.GetFiles(location).ToList().Find(x => x.EndsWith(suffix));
return file ?? "";
}
catch (Exception ex)
{
ValkyrieDebug.Log("GetObbPath caused " + ex.GetType().Name + ": " + ex.Message + " " + ex.StackTrace);
if(altprefix == null)
{
return "";
}
else
{
return GetObbPath(altprefix, suffix);
}
}
var file = Directory.GetFiles(location).ToList().Find(x => x.EndsWith(suffix));
return file ?? "";

}
}
}
55 changes: 55 additions & 0 deletions libraries/FFGAppImport/AssetImport/AssetStudio/7zip/Common/CRC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Common/CRC.cs

namespace SevenZip
{
public class CRC
{
public static readonly uint[] Table;

static CRC()
{
Table = new uint[256];
const uint kPoly = 0xEDB88320;
for (uint i = 0; i < 256; i++)
{
uint r = i;
for (int j = 0; j < 8; j++)
if ((r & 1) != 0)
r = (r >> 1) ^ kPoly;
else
r >>= 1;
Table[i] = r;
}
}

uint _value = 0xFFFFFFFF;

public void Init() { _value = 0xFFFFFFFF; }

public void UpdateByte(byte b)
{
_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);
}

public void Update(byte[] data, uint offset, uint size)
{
for (uint i = 0; i < size; i++)
_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);
}

public uint GetDigest() { return _value ^ 0xFFFFFFFF; }

static uint CalculateDigest(byte[] data, uint offset, uint size)
{
CRC crc = new CRC();
// crc.Init();
crc.Update(data, offset, size);
return crc.GetDigest();
}

static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)
{
return (CalculateDigest(data, offset, size) == digest);
}
}
}
Loading

0 comments on commit 43c55f5

Please sign in to comment.