Пример #1
0
            public void LoadGameLayout(string path, SupportedGame game)
            {
                // Load XContainer
                if (!File.Exists(path))
                {
                    return;
                }

                XDocument layoutDocument = XDocument.Load(path);

                // Make sure there is a root <layouts> tag
                XContainer layoutContainer = layoutDocument.Element("layouts");

                if (layoutContainer == null)
                {
                    throw new ArgumentException("Invalid layout document");
                }

                // Layout tags have the format:
                // <layout for="(layout's purpose)">(structure fields)</layout>
                foreach (XElement layout in layoutContainer.Elements("layout"))
                {
                    XAttribute forAttrib = layout.Attribute("for");
                    if (forAttrib == null)
                    {
                        throw new ArgumentException("Layout tags must have a \"for\" attribute");
                    }
                    game.AddLayout(forAttrib.Value, XMLLayoutLoader.LoadLayout(layout));
                }
            }
Пример #2
0
        private int WorkerTestDetermineTurnResultGame(SupportedGame selectedGame, string player1Move, string player2Move)
        {
            var game = Game.CreateGame(selectedGame, 1);

            int Player1Move = game.SupportedMoves.IndexOf(player1Move);
            int Player2Move = game.SupportedMoves.IndexOf(player2Move);

            return(game.DetermineTurnResult(Player1Move, Player2Move));
        }
Пример #3
0
 private void OnFocus()
 {
     projectPath       = EditorPrefs.GetString("TRMB.ProjectPath");
     gamePath          = EditorPrefs.GetString("TRMB.GamePath");
     exportFolderName  = EditorPrefs.HasKey("TRMB.ExportFolderName") ? EditorPrefs.GetString("TRMB.ExportFolderName") : "MyMod";
     exportTo          = (ExportTo)EditorPrefs.GetInt("TRMB.ExportTo");
     toDefault         = EditorPrefs.GetBool("TRMB.ToDefault");
     runGameAfterBuild = EditorPrefs.GetBool("TRMB.RunGameAfterBuild");
     cleanDestination  = EditorPrefs.GetBool("TRMB.CleanDestination");
     runGameArguments  = EditorPrefs.GetString("TRMB.RunGameArguments");
     gameName          = (SupportedGame)EditorPrefs.GetInt("TRMB.GameName");
     action            = (Action)EditorPrefs.GetInt("TRMB.Action");
 }
Пример #4
0
        public static IGame CreateGame(SupportedGame selectedGame, int numberOfTurns)
        {
            switch (selectedGame)
            {
            case SupportedGame.Null:
                throw new ArgumentNullException();

            case SupportedGame.RockPaperScissors:
                return(new RockPaperScissorsGame(numberOfTurns));

            case SupportedGame.RockPaperScissorsLizardSpock:
                return(new RockPaperScissorsLizardSpockGame(numberOfTurns));

            default:
                throw new ArgumentException();
            }
        }
Пример #5
0
        private int WorkerTestPlayGame(SupportedGame selectedGame, int numberOfTurns, string[] player1Strategy, string[] player2Strategy)
        {
            var game           = Game.CreateGame(selectedGame, numberOfTurns);
            var supportedMoves = game.SupportedMoves;

            string consoleInputString = "";

            for (int turn = 0; turn < numberOfTurns; turn++)
            {
                consoleInputString = consoleInputString + supportedMoves.IndexOf(player1Strategy[turn]) + "\n" + supportedMoves.IndexOf(player2Strategy[turn]) + "\n";
            }
            var consoleInput = new StringReader(consoleInputString);

            Console.SetIn(consoleInput);

            IPlayer player1 = Player.CreatePlayer(SupportedPlayer.HumanPlayer, "TestPlayer1");
            IPlayer player2 = Player.CreatePlayer(SupportedPlayer.HumanPlayer, "TestPlayer2");

            return(game.Play(player1, player2));
        }
Пример #6
0
        private IGame WorkerTestGameFactory(SupportedGame selectedGameType)
        {
            var NumberOfTurns = 3;

            return(Game.CreateGame(selectedGameType, NumberOfTurns));
        }
Пример #7
0
            public void LoadGames()
            {
                string applicationFormatsPath = VariousFunctions.GetApplicationLocation() + "Formats\\";

                // Load XContainer
                if (!File.Exists(applicationFormatsPath + "SupportedGames.xml"))
                {
                    return;
                }
                XDocument  gameInfo       = XDocument.Load(applicationFormatsPath + "SupportedGames.xml");
                XContainer supportedGames = gameInfo.Element("games");

                // Find the first game
                IList <XElement> games = supportedGames.Elements("game").ToList();

                if (games == null)
                {
                    return;
                }

                // Loop though games, getting their info
                foreach (XElement game in games)
                {
                    XAttribute nameAttrib             = game.Attribute("name");
                    XAttribute safeNameAttrib         = game.Attribute("safeName");
                    XAttribute diffucultyShieldAttrib = game.Attribute("diffucultyShield");
                    XAttribute titleIDAttrib          = game.Attribute("titleID");
                    XAttribute subPackageNameAttrib   = game.Attribute("subPackageName");
                    XAttribute hasGameStateAttrib     = game.Attribute("hasGameState");
                    XAttribute stfsStartsWithAttrib   = game.Attribute("stfsStartsWith");
                    XAttribute securityTypeAttrib     = game.Attribute("securityType");
                    XAttribute securitySaltAttrib     = game.Attribute("securitySalt");
                    XAttribute filenameAttrib         = game.Attribute("filename");

                    // Check compulsary fields
                    if (nameAttrib != null && safeNameAttrib != null &&
                        diffucultyShieldAttrib != null && titleIDAttrib != null &&
                        subPackageNameAttrib != null && hasGameStateAttrib != null &&
                        stfsStartsWithAttrib != null && securityTypeAttrib != null &&
                        filenameAttrib != null)
                    {
                        SupportedGame supportedGame = new SupportedGame();
                        supportedGame.Name           = nameAttrib.Value;
                        supportedGame.SafeName       = safeNameAttrib.Value;
                        supportedGame.TitleID        = long.Parse(titleIDAttrib.Value.Replace("0x", ""), System.Globalization.NumberStyles.HexNumber);
                        supportedGame.SubPackageName = subPackageNameAttrib.Value;
                        supportedGame.HasGamestate   = Convert.ToBoolean(hasGameStateAttrib.Value);
                        supportedGame.STFSStartsWith = stfsStartsWithAttrib.Value;
                        supportedGame.SecurityType   = securityTypeAttrib.Value.ToLower() == "SHA1" ?
                                                       SecurityType.SHA1 : SecurityType.CRC32;
                        if (securitySaltAttrib != null)
                        {
                            supportedGame.SecuritySalt = VariousFunctions.StringToByteArray(securitySaltAttrib.Value.Replace("0x", "").Replace(" ", "").Replace(",", ""));
                        }
                        supportedGame.FileName = filenameAttrib.Value;
                        LoadGameLayout(applicationFormatsPath + supportedGame.FileName, supportedGame);

                        _games.Add(supportedGame);
                    }
                }
            }
Пример #8
0
        /// <summary>
        /// Create and encode login POST data
        /// </summary>
        private static string ConstructPostData(string email, string password, SupportedGame game)
        {
            // TODO: Combine params maybe?!
            string postData = null;
            Dictionary<string, string> postParams;

            if (game == SupportedGame.Battlefield3)
            {
                postParams = new Dictionary<string, string>
                    {
                        {"redirect", "|bf3|"},
                        {"email", email},
                        {"password", password},
                        {"remember", "0"},
                        {"submit", "Sign in"}
                    };
            }
            else
            {
                postParams = new Dictionary<string, string>
                    {
                        {"redirect", "|bf4|"},
                        {"email", email},
                        {"password", password},
                        {"remember", "0"},
                        {"submit", "Log in"}
                    };
            }
            foreach (var param in postParams)
            {
                if (postData != null)
                    postData += "&";
                postData += HttpUtility.UrlEncode(param.Key) + "=" + HttpUtility.UrlEncode(param.Value);
            }

            return postData;
        }
Пример #9
0
        private async void LogIn(SupportedGame game)
        {
            UserInterfaceEnabled = false;
            StatusInformation = Common.StatusInformationVerifyingCredential;
            SaveCredentials();

            Uri requestUri = game == SupportedGame.Battlefield3 ? ViewModelLocator.Bf3LogInUri : ViewModelLocator.Bf4LogInUri;
            Uri responseUri = game == SupportedGame.Battlefield3 ? ViewModelLocator.Bf3LogInResponseUri : ViewModelLocator.Bf4LogInResponseUri;

            var request = WebRequest.Create(requestUri) as HttpWebRequest;
            if (request == null)
                throw new ArgumentNullException();

            request.Credentials = new NetworkCredential(Email, Password);
            request.Method = Common.HttpPostMethod;
            request.Accept = Common.HttpAccept;
            request.UserAgent = Common.HttpUserAgent;
            request.ContentType = Common.HttpContentType;
            request.CookieContainer = ViewModelLocator.CookieJar;

            _timedOut = false;
            var dispatchTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(Common.TimeOutInSeconds) };
            dispatchTimer.Tick += TimerTicked;
            dispatchTimer.Start();

            var streamTask = request.GetRequestStreamAsync();

            var requestStream = await streamTask.ConfigureAwait(false);
            using (var writer = new StreamWriter(requestStream))
            {
                await writer.WriteAsync(ConstructPostData(Email, Password, Game)).ConfigureAwait(false);
                writer.Close();
            }

            if (_timedOut)
            {
                ResetControls();
                DispatcherHelper.CheckBeginInvokeOnUI(() => LogInFailedReason = Common.LogInFailedReasonTimedOut);
                return;
            }

            // Got response
            var responseTask = request.GetResponseAsync();
            try
            {
                var response = await responseTask.ConfigureAwait(false);
                if (response.ResponseUri.Equals(responseUri))
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                        {
                            ViewModelLocator.Soldier.Game = game;
                            ViewModelLocator.Soldier.UpdateData(false);
                        });
                }
                else
                {
                    ResetControls();
                    DispatcherHelper.CheckBeginInvokeOnUI(() => LogInFailedReason = Common.LogInFailedReasonInvalidCredentials);
                }
            }
            catch (WebException we)
            {
                ResetControls();
                DispatcherHelper.CheckBeginInvokeOnUI(() => LogInFailedReason = we.Message);
            }
        }
 public UserIdAndPlatformResolver(SupportedGame game)
 {
     _game = game;
 }
Пример #11
0
        static void Build(Action behaviour)
        {
            // Check error
            if (exportTo == ExportTo.Project && !Directory.Exists(Path.Combine(projectPath, "Assets/StreamingAssets")))
            {
                Debug.LogError("Cannot deploy to project dir as the folder doesn't seem to be an Unity project");
                return;
            }
            if (exportTo == ExportTo.Game)
            {
                bool gameSupported = false;
                foreach (string supportedGame in Enum.GetNames(typeof(SupportedGame)))
                {
                    if (File.Exists(Path.Combine(gamePath, supportedGame + ".exe")))
                    {
                        gameSupported = true;
                        gameName      = (SupportedGame)Enum.Parse(typeof(SupportedGame), supportedGame);
                    }
                }
                if (!gameSupported)
                {
                    Debug.LogError("Target game not supported!");
                    return;
                }
            }
#if PrivateSDK
            if (exportTo == ExportTo.Android)
            {
                string adbPath = Path.Combine(EditorPrefs.GetString("AndroidSdkRoot"), "platform-tools", "adb.exe");
                if (!EditorPrefs.HasKey("AndroidSdkRoot") || !File.Exists(adbPath))
                {
                    Debug.LogError("Android SDK is not installed!");
                    Debug.LogError("Path not found " + adbPath);
                    return;
                }
            }
#endif
            // Configure stereo rendering
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
            {
                PlayerSettings.stereoRenderingPath = StereoRenderingPath.SinglePass;
            }
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows || EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64)
            {
                PlayerSettings.stereoRenderingPath = StereoRenderingPath.Instancing;
            }

            // Configure addressable groups
            if (AddressableAssetSettingsDefaultObject.Settings != null)
            {
                foreach (AddressableAssetGroup group in AddressableAssetSettingsDefaultObject.Settings.groups)
                {
                    BundledAssetGroupSchema bundledAssetGroupSchema = group.GetSchema <BundledAssetGroupSchema>();
                    if (bundledAssetGroupSchema != null)
                    {
                        if (group.Default)
                        {
                            bundledAssetGroupSchema.BuildPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, "LocalBuildPath");
                            bundledAssetGroupSchema.LoadPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, "LocalLoadPath");
                        }
                        bundledAssetGroupSchema.BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash;
                        bundledAssetGroupSchema.BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash;
                        AddressableAssetSettingsDefaultObject.Settings.profileSettings.SetValue(group.Settings.activeProfileId, "LocalBuildPath", "[ThunderRoad.ModBuilder.buildPath]");
                        AddressableAssetSettingsDefaultObject.Settings.profileSettings.SetValue(group.Settings.activeProfileId, "LocalLoadPath", (toDefault ? "{ThunderRoad.FileManager.aaDefaultPath}/" : "{ThunderRoad.FileManager.aaModPath}/") + exportFolderName);
                        // Set builtin shader to export folder name to avoid duplicates
                        AddressableAssetSettingsDefaultObject.Settings.ShaderBundleNaming       = UnityEditor.AddressableAssets.Build.ShaderBundleNaming.Custom;
                        AddressableAssetSettingsDefaultObject.Settings.ShaderBundleCustomNaming = exportFolderName;
                        AddressableAssetSettingsDefaultObject.Settings.BuildRemoteCatalog       = true;

                        /* TODO: OBB support (zip file uncompressed and adb push to obb folder)
                         *  AddressableAssetSettingsDefaultObject.Settings.profileSettings.SetValue(group.Settings.activeProfileId, "LocalLoadPath", "{ThunderRoad.FileManager.obbPath}/" + exportFolderName + "{ThunderRoad.FileManager.obbPathEnd}");
                         */
                    }
                }
            }
            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();

            // Build
            if (behaviour == Action.BuildAndExport || behaviour == Action.BuildOnly)
            {
                Debug.Log("Build path is: " + buildPath);
                if (OnBuildEvent != null)
                {
                    OnBuildEvent.Invoke(EventTime.OnStart);
                }

                // Clean build path
                if (Directory.Exists(buildPath))
                {
                    foreach (string filePath in Directory.GetFiles(buildPath, "*.*", SearchOption.AllDirectories))
                    {
                        File.Delete(filePath);
                    }
                }

                BuildCache.PurgeCache(true);
                AddressableAssetSettings.CleanPlayerContent();
                AddressableAssetSettings.CleanPlayerContent(AddressableAssetSettingsDefaultObject.Settings.ActivePlayerDataBuilder);
                AddressableAssetSettings.BuildPlayerContent();
                Debug.Log("Build done");

                if (OnBuildEvent != null)
                {
                    OnBuildEvent.Invoke(EventTime.OnEnd);
                }
            }

            // Export
            if (behaviour == Action.BuildAndExport || behaviour == Action.ExportOnly)
            {
                if (exportTo == ExportTo.Game || exportTo == ExportTo.Project)
                {
                    // Get paths
                    string buildFullPath          = Path.Combine(Directory.GetCurrentDirectory(), buildPath);
                    string catalogFullPath        = Path.Combine(Directory.GetCurrentDirectory(), catalogPath);
                    string destinationAssetsPath  = "";
                    string destinationCatalogPath = "";
                    if (exportTo == ExportTo.Project)
                    {
                        destinationAssetsPath  = Path.Combine(projectPath, buildPath);
                        destinationCatalogPath = Path.Combine(projectPath, catalogPath);
                    }
                    else if (exportTo == ExportTo.Game)
                    {
                        if (toDefault)
                        {
                            destinationAssetsPath = destinationCatalogPath = Path.Combine(gamePath, gameName + "_Data/StreamingAssets/Default", exportFolderName);
                        }
                        else
                        {
                            destinationAssetsPath = destinationCatalogPath = Path.Combine(gamePath, gameName + "_Data/StreamingAssets/Mods", exportFolderName);
                        }
                    }

                    // Create folders if needed
                    if (!File.Exists(destinationAssetsPath))
                    {
                        Directory.CreateDirectory(destinationAssetsPath);
                    }
                    if (!File.Exists(destinationCatalogPath))
                    {
                        Directory.CreateDirectory(destinationCatalogPath);
                    }

                    // Clean destination path
                    if (cleanDestination)
                    {
                        foreach (string filePath in Directory.GetFiles(destinationAssetsPath, "*.*", SearchOption.AllDirectories))
                        {
                            File.Delete(filePath);
                        }
                        if (exportTo == ExportTo.Game)
                        {
                            foreach (string filePath in Directory.GetFiles(destinationCatalogPath, "*.*", SearchOption.AllDirectories))
                            {
                                File.Delete(filePath);
                            }
                        }
                    }
                    else
                    {
                        foreach (string filePath in Directory.GetFiles(destinationAssetsPath, "catalog_*.json", SearchOption.AllDirectories))
                        {
                            File.Delete(filePath);
                        }
                        foreach (string filePath in Directory.GetFiles(destinationAssetsPath, "catalog_*.hash", SearchOption.AllDirectories))
                        {
                            File.Delete(filePath);
                        }
                        if (exportTo == ExportTo.Game)
                        {
                            foreach (string filePath in Directory.GetFiles(destinationCatalogPath, "catalog_*.json", SearchOption.AllDirectories))
                            {
                                File.Delete(filePath);
                            }
                            foreach (string filePath in Directory.GetFiles(destinationCatalogPath, "catalog_*.hash", SearchOption.AllDirectories))
                            {
                                File.Delete(filePath);
                            }
                        }
                    }

                    // Copy addressable assets to destination path
                    CopyDirectory(buildFullPath, destinationAssetsPath);
                    Debug.Log("Copied addressable asset folder " + buildFullPath + " to " + destinationAssetsPath);

                    if (exportTo == ExportTo.Game)
                    {
                        // Copy json catalog to destination path
                        CopyDirectory(catalogFullPath, destinationCatalogPath);
                        Debug.Log("Copied catalog folder " + catalogFullPath + " to " + destinationCatalogPath);
                        // Copy plugin dll if any
                        string dllPath = Path.Combine("BuildStaging", "Plugins", exportFolderName) + "/bin/Release/netstandard2.0/" + exportFolderName + ".dll";
                        if (File.Exists(dllPath))
                        {
                            File.Copy(dllPath, destinationCatalogPath + "/" + exportFolderName + ".dll", true);
                            Debug.Log("Copied dll " + dllPath + " to " + destinationCatalogPath);
                        }
                    }
                }

                if ((exportTo == ExportTo.Game) && runGameAfterBuild)
                {
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo.FileName  = Path.Combine(gamePath, gameName + ".exe");
                    process.StartInfo.Arguments = runGameArguments;
                    process.Start();
                    Debug.Log("Start game: " + process.StartInfo.FileName + " " + process.StartInfo.Arguments);
                }
#if PrivateSDK
                if (exportTo == ExportTo.Android)
                {
                    string buildFullPath = Path.Combine(Directory.GetCurrentDirectory(), "BuildStaging", "AddressableAssets", "Android");
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo.FileName = GetAdbPath();
                    string destinationPath = "/sdcard/Android/data/com.Warpfrog." + gameName + "/files/mods/" + exportFolderName;
                    process.StartInfo.Arguments = "push " + buildFullPath + "/. " + destinationPath;
                    // for default: obb : /sdcard/Android/obb/" + PlayerSettings.applicationIdentifier + "/main.1.com.Warpfrog.BladeAndSorcery.obb");
                    process.Start();
                    process.WaitForExit();
                    Debug.Log(GetAdbPath() + " " + process.StartInfo.Arguments);

                    if (runGameAfterBuild)
                    {
                        process = new System.Diagnostics.Process();
                        process.StartInfo.FileName  = GetAdbPath();
                        process.StartInfo.Arguments = "shell am start -n " + PlayerSettings.applicationIdentifier + "/com.unity3d.player.UnityPlayerActivity";
                        process.Start();
                        Debug.Log("Start game: " + process.StartInfo.FileName + " " + process.StartInfo.Arguments);
                    }
                }
#endif
                Debug.Log("Export done");
            }
            // The end
            System.Media.SystemSounds.Asterisk.Play();
        }
Пример #12
0
        static void ExportToGUI()
        {
            GUILayout.BeginHorizontal();
            ExportTo newExportTo = (ExportTo)EditorGUILayout.EnumPopup("Export to", exportTo);

            if (newExportTo != exportTo)
            {
                EditorPrefs.SetInt("TRMB.ExportTo", (int)newExportTo);
                exportTo = newExportTo;
            }

            EditorGUI.BeginDisabledGroup((exportTo == ExportTo.Project) ? true : false);
            bool newRunGameAfterBuild = GUILayout.Toggle(runGameAfterBuild, "Run game after build", GUILayout.Width(150));

            if (newRunGameAfterBuild != runGameAfterBuild)
            {
                EditorPrefs.SetBool("TRMB.RunGameAfterBuild", newRunGameAfterBuild);
                runGameAfterBuild = newRunGameAfterBuild;
            }
            EditorGUI.EndDisabledGroup();

            bool newCleanDestination = GUILayout.Toggle(cleanDestination, "Clean destination", GUILayout.Width(150));

            if (newCleanDestination != cleanDestination)
            {
                EditorPrefs.SetBool("TRMB.CleanDestination", newCleanDestination);
                cleanDestination = newCleanDestination;
            }


            GUILayout.EndHorizontal();

            if (runGameAfterBuild && exportTo == ExportTo.Game)
            {
                GUILayout.Space(5);
                GUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("Arguments"), new GUIStyle("BoldLabel"), GUILayout.Width(150));
                string newRunGameArguments = GUILayout.TextField(runGameArguments, 25);
                if (newRunGameArguments != runGameArguments)
                {
                    EditorPrefs.SetString("TRMB.RunGameArguments", newRunGameArguments);
                    runGameArguments = newRunGameArguments;
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.Space(5);
#if PrivateSDK
            if (exportTo == ExportTo.Android)
            {
                GUILayout.Space(5);
                SupportedGame newGameName = (SupportedGame)EditorGUILayout.EnumPopup("Game name", gameName);
                if (newGameName != gameName)
                {
                    EditorPrefs.SetInt("TRMB.GameName", (int)newGameName);
                    gameName = newGameName;
                }
            }
#endif
            if (exportTo == ExportTo.Game)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("Game folder Directory"), new GUIStyle("BoldLabel"), GUILayout.Width(150));
                if (GUILayout.Button(gamePath, new GUIStyle("textField")))
                {
                    gamePath = EditorUtility.OpenFolderPanel("Select game folder", "", "");
                    EditorPrefs.SetString("TRMB.GamePath", gamePath);
                }
                GUILayout.EndHorizontal();
            }

            if (exportTo == ExportTo.Project)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("Project folder Directory"), new GUIStyle("BoldLabel"), GUILayout.Width(150));
                if (GUILayout.Button(projectPath, new GUIStyle("textField")))
                {
                    projectPath = EditorUtility.OpenFolderPanel("Select project folder", "", "");
                    EditorPrefs.SetString("TRMB.ProjectPath", projectPath);
                }
                GUILayout.EndHorizontal();
            }
        }