public void RemoveFromTargetList(GameTarget target) { if (TargetList.Contains(target)) { TargetList.Remove(target); } }
internal static bool CheckIfBinkw32ASIIsInstalled(GameTarget target) { if (target == null) { return(false); } string binkPath = null; string expectedHash = null; if (target.Game == Mod.MEGame.ME1) { binkPath = Path.Combine(target.TargetPath, "Binaries", "binkw32.dll"); expectedHash = ME1ASILoaderHash; } else if (target.Game == Mod.MEGame.ME2) { binkPath = Path.Combine(target.TargetPath, "Binaries", "binkw32.dll"); expectedHash = ME2ASILoaderHash; } else if (target.Game == Mod.MEGame.ME3) { binkPath = Path.Combine(target.TargetPath, "Binaries", "win32", "binkw32.dll"); expectedHash = ME3ASILoaderHash; } if (File.Exists(binkPath)) { return(CalculateMD5(binkPath) == expectedHash); } return(false); }
private void LoadME2Keys(GameTarget target) { if (target.Game != Mod.MEGame.ME2) { throw new Exception(@"Cannot load ME2 keys from target that is not ME2"); } var me2c = ME2Coalesced.OpenFromTarget(target); var bioinput = me2c.Inis.FirstOrDefault(x => Path.GetFileName(x.Key).Equals(@"BioInput.ini", StringComparison.InvariantCultureIgnoreCase)); var engineConsole = bioinput.Value.Sections.FirstOrDefault(x => x.Header == @"Engine.Console"); if (engineConsole != null) { var consoleKey = engineConsole.Entries.FirstOrDefault(x => x.Key == @"ConsoleKey"); if (consoleKey == null) { ME2FullConsoleKeyText = M3L.GetString(M3L.string_fullConsoleNotBoundToAKey); } else { ME2FullConsoleKeyText = M3L.GetString(M3L.string_interp_fullConsoleBoundToX, consoleKey.Value); } var typeKey = engineConsole.Entries.FirstOrDefault(x => x.Key == @"TypeKey"); if (typeKey == null) { ME2MiniConsoleKeyText = M3L.GetString(M3L.string_miniConsoleNotBoundToAKey); } else { ME2MiniConsoleKeyText = M3L.GetString(M3L.string_interp_miniConsoleBoundToX, typeKey.Value); } } }
internal static bool IsOfficialDLCInstalled(ModJob.JobHeader header, GameTarget gameTarget) { if (header == ModJob.JobHeader.BALANCE_CHANGES) { return(true); //Don't check balance changes } if (header == ModJob.JobHeader.ME2_RCWMOD) { return(true); //Don't check } if (header == ModJob.JobHeader.ME1_CONFIG) { return(true); //Don't check } if (header == ModJob.JobHeader.BASEGAME) { return(true); //Don't check basegame } if (header == ModJob.JobHeader.CUSTOMDLC) { return(true); //Don't check custom dlc } if (header == ModJob.JobHeader.LOCALIZATION) { return(true); //Don't check localization } if (header == ModJob.JobHeader.TESTPATCH) { return(File.Exists(ME3Directory.GetTestPatchPath(gameTarget))); } else { return(MEDirectories.GetInstalledDLC(gameTarget).Contains(ModJob.GetHeadersToDLCNamesMap(gameTarget.Game)[header])); } }
private void OnSelectedBatchQueueChanged() { GameTarget currentTarget = SelectedGameTarget; SelectedGameTarget = null; InstallationTargetsForGroup.ClearEx(); if (SelectedBatchQueue != null) { InstallationTargetsForGroup.AddRange(mainwindow.InstallationTargets.Where(x => x.Game == SelectedBatchQueue.Game)); if (InstallationTargetsForGroup.Contains(currentTarget)) { SelectedGameTarget = currentTarget; } else { SelectedGameTarget = InstallationTargetsForGroup.FirstOrDefault(); } if (SelectedBatchQueue.ModsToInstall.Any()) { SelectedModInGroup = SelectedBatchQueue.ModsToInstall.First(); } if (SelectedBatchQueue.Game == MEGame.ME1) { SelectedBatchQueue.InstallCompressed = false; } } TriggerPropertyChangedFor(nameof(CanCompressPackages)); }
internal static bool UninstallBinkBypass(GameTarget target) { if (target == null) { return(false); } var binkPath = GetBinkw32File(target); if (target.Game == Mod.MEGame.ME1) { var obinkPath = Path.Combine(target.TargetPath, "Binaries", "binkw23.dll"); File.Delete(obinkPath); Utilities.ExtractInternalFile("MassEffectModManagerCore.modmanager.binkw32.me1.binkw23.dll", binkPath, true); } else if (target.Game == Mod.MEGame.ME2) { var obinkPath = Path.Combine(target.TargetPath, "Binaries", "binkw23.dll"); File.Delete(obinkPath); Utilities.ExtractInternalFile("MassEffectModManagerCore.modmanager.binkw32.me2.binkw23.dll", binkPath, true); } else if (target.Game == Mod.MEGame.ME3) { var obinkPath = Path.Combine(target.TargetPath, "Binaries", "win32", "binkw23.dll"); File.Delete(obinkPath); Utilities.ExtractInternalFile("MassEffectModManagerCore.modmanager.binkw32.me3.binkw23.dll", binkPath, true); } return(true); }
public BackupCreator(List <GameTarget> targetsList, GameTarget selectedTarget, Window window) { DataContext = this; this.targetsList = targetsList; LoadCommands(); InitializeComponent(); }
public bool Validate(string dlcName, GameTarget target, CaseInsensitiveDictionary <string> loadedFiles) { foreach (var outfit in Outfits) { // Check packages if (!loadedFiles.ContainsKey($@"{outfit.HenchPackage}.pcc")) { Log.Error($@"SquadmateMergeInfo failed validation: {outfit.HenchPackage}.pcc not found in game"); return(false); } if (Game.IsGame3()) { if (!loadedFiles.ContainsKey($@"{outfit.HenchPackage}_Explore.pcc")) { Log.Error($@"SquadmateMergeInfo failed validation: {outfit.HenchPackage}_Explore.pcc not found in game"); return(false); } } if (!loadedFiles.ContainsKey($@"SFXHenchImages_{dlcName}.pcc")) { Log.Error($@"SquadmateMergeInfo failed validation: SFXHenchImages_{dlcName}.pcc not found in game"); return(false); } } return(true); }
/// <summary> /// Patches the ME1 PhysxLoader to always use local. This will make it so ME1 will run regardless if it can access the registry or not with the enableLocalPhysXCore key. /// </summary> /// <param name="me1Target"></param> /// <returns></returns> public static bool PatchPhysXLoaderME1(GameTarget me1Target) { Log.Information(@"Patching PhysXLoader.dll to force loading local PhysXCore"); var loaderPath = Path.Combine(me1Target.TargetPath, @"Binaries", @"PhysXLoader.dll"); if (File.Exists(loaderPath) && new FileInfo(loaderPath).Length == 68688) //Make sure it's same size so it's not like some other build { using var pls = File.Open(loaderPath, FileMode.Open, FileAccess.ReadWrite); pls.Seek(0x1688, SeekOrigin.Begin); var jzByte1 = pls.ReadByte(); var jzByte2 = pls.ReadByte(); Log.Information($@"Byte 1 @ 0x1688: 0x{jzByte1:X2}"); Log.Information($@"Byte 2 @ 0x1689: 0x{jzByte2:X2}"); if (jzByte1 == 0x75 && jzByte2 == 0x19) { // It's a jz instruction. Change to nop Log.Information(@"This file is has the original PhysXLoader.dll jump instruction for allowing system PhysX. Patching out to force local PhysX codepath"); pls.Seek(-2, SeekOrigin.Current); pls.WriteByte(0x90); //nop pls.WriteByte(0x90); //nop Log.Information(@"PhysXLoader.dll has been patched"); } else if (jzByte1 == 0x90 && jzByte2 == 0x90) { Log.Information(@"This file appears to have already been patched to force local use of PhysX. Not patching file."); } else { Log.Warning(@"Bytes are not expected values. We will not patch this file."); return(false); } } return(true); }
internal static List <GameTarget> GetCachedTargets(Mod.MEGame game) { var cacheFile = GetCachedTargetsFile(game); if (File.Exists(cacheFile)) { List <GameTarget> targets = new List <GameTarget>(); foreach (var file in File.ReadAllLines(cacheFile)) { //Validate game directory GameTarget target = new GameTarget(game, file, false); var failureReason = target.ValidateTarget(); if (failureReason == null) { targets.Add(target); } else { Log.Error("Cached target for " + target.Game.ToString() + " is invalid: " + failureReason); } } return(targets); } else { return(new List <GameTarget>()); } }
private void SetME3KeyWithThread(GameTarget target, string consoleKeyStr = null, string typeKeyStr = null) { OperationInProgress = true; ME3FullConsoleKeyText = M3L.GetString(M3L.string_updatingKeybindsPleaseWait); ME3MiniConsoleKeyText = ""; NamedBackgroundWorker nbw = new NamedBackgroundWorker(@"ME3-ConsoleKeySetterThread"); nbw.DoWork += (a, b) => { SetME3ConsoleKeybinds(SelectedME3Target, consoleKeyStr, typeKeyStr); LoadME3Keys(SelectedME3Target); Analytics.TrackEvent(@"Set ME3 Console Keys", new Dictionary <string, string>() { { @"Full Console Key", consoleKeyStr }, { @"Mini Console Key", typeKeyStr } }); }; nbw.RunWorkerCompleted += (a, b) => { if (b.Error != null) { Log.Error($@"Exception occurred in {nbw.Name} thread: {b.Error.Message}"); } OperationInProgress = false; CommandManager.InvalidateRequerySuggested(); }; nbw.RunWorkerAsync(); }
private static void handleM3Passthrough() { if (PassthroughME1Path != null) { handlePassthrough(MEGame.ME1, PassthroughME1Path); } if (PassthroughME2Path != null) { handlePassthrough(MEGame.ME2, PassthroughME2Path); } if (PassthroughME3Path != null) { handlePassthrough(MEGame.ME3, PassthroughME3Path); } PassthroughME1Path = PassthroughME2Path = PassthroughME3Path = null; void handlePassthrough(MEGame game, string path) { if (path != null && Directory.Exists(path)) { GameTarget gt = new GameTarget(game, path, true, false); var passThroughValidationResult = gt.ValidateTarget(false); if (passThroughValidationResult != null) { MERLog.Error($@"{game} path passthrough failed game target validation: {passThroughValidationResult}"); } else { MERLog.Information($@"Valid passthrough for game {game}. Assigning path."); Locations.SetTarget(gt, false); } } } }
public byte[] GetImageBytesForMip(Texture2DMipInfo info, GameTarget target, bool useLowerMipsIfTFCMissing, List <string> additionalTFCs = null) { byte[] imageBytes = null; try { imageBytes = GetTextureData(info, target, additionalTFCs: additionalTFCs); } catch (FileNotFoundException e) { if (useLowerMipsIfTFCMissing) { Debug.WriteLine("External cache not found. Defaulting to internal mips."); //External archive not found - using built in mips (will be hideous, but better than nothing) info = Mips.FirstOrDefault(x => x.storageType == StorageTypes.pccUnc); if (info != null) { imageBytes = GetTextureData(info, target); } } else { throw e; //rethrow } } if (imageBytes == null) { throw new Exception("Could not fetch texture data for texture " + info?.Export.ObjectName); } return(imageBytes); }
/// <summary> /// Gets a Dictionary of all loaded files in the given target. Key is the filename, value is file path /// </summary> /// <param name="target">Game target</param> /// <returns>Mapping of files</returns> public static Dictionary <string, string> GetFilesLoadedInGame(GameTarget target, bool includeTFC = false, bool includeBasegame = true) { Mod.MEGame game = target.Game; //make dictionary from basegame files var loadedFiles = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase); var directories = GetEnabledDLC(target).OrderBy(dir => GetMountPriority(dir, target.Game)); if (includeBasegame) { directories.Prepend(MEDirectories.BioGamePath(target)); } foreach (string directory in directories) { foreach (string filePath in GetCookedFiles(target.Game, directory, includeTFC)) { string fileName = Path.GetFileName(filePath); if (fileName != null) { loadedFiles[fileName] = filePath; } } } return(loadedFiles); }
public void ValidateTargetsME3() { GlobalTest.Init(); var root = GlobalTest.GetTestGameFoldersDirectory(Mod.MEGame.ME3); Console.WriteLine("TargetTesting: Game directories folder for ME3: " + root); var normal = Path.Combine(root, "normal"); //correct game GameTarget gt = new GameTarget(Mod.MEGame.ME3, normal, false); var failureReason = gt.ValidateTarget(); Assert.IsNull(failureReason, "GameTarget for ME3 Normal should not have returned a failure string when validating against the correct game. Failure reason returned: " + failureReason); Assert.IsTrue(gt.IsValid, "GameTarget for ME3 Normal should have been marked as valid when validating against the correct game, but it wasn't"); //wrong game gt = new GameTarget(Mod.MEGame.ME1, normal, false); failureReason = gt.ValidateTarget(); Assert.IsNotNull(failureReason, "GameTarget for ME3 Normal should have returned a failure string when validating against the wrong game (ME1), but none was returned"); Assert.IsFalse(gt.IsValid, "GameTarget for ME3 Normal should have been marked as invalid when validating against the wrong game (ME1), but wasn't"); gt = new GameTarget(Mod.MEGame.ME2, normal, false); failureReason = gt.ValidateTarget(); Assert.IsNotNull(failureReason, "GameTarget for ME3 Normal should have returned a failure string when validating against the wrong game (ME2), but none was returned"); Assert.IsFalse(gt.IsValid, "GameTarget for ME3 Normal should have been marked as invalid when validating against the wrong game (ME2), but wasn't"); }
public static void GenerateMergeDLC(GameTarget target, Guid guid) { // Generate M3 DLC Folder // Does not work for LE1/ME1! var sko = new StarterKitGeneratorWindow.StarterKitOptions() { ModGame = target.Game, GenerateModdesc = false, OutputFolderOverride = M3Directories.GetDLCPath(target), ModDescription = null, ModInternalName = @"ME3Tweaks Mod Manager Merge DLC", ModInternalTLKID = 1928304430, ModMountFlag = target.Game.IsGame3() ? new MountFlag(EME3MountFileFlag.LoadsInSingleplayer) : new MountFlag(0, true), ModDeveloper = @"ME3Tweaks Mod Manager", ModMountPriority = 1900000000, ModDLCFolderNameSuffix = MERGE_DLC_FOLDERNAME.Substring(@"DLC_MOD_".Length) }; StarterKitGeneratorWindow.CreateStarterKitMod(sko, null); MetaCMM mcmm = new MetaCMM() { ModName = @"ME3Tweaks Mod Manager Auto-Generated Merge DLC", Version = @"1.0" }; mcmm.WriteMetaCMM(Path.Combine(M3Directories.GetDLCPath(target), MERGE_DLC_FOLDERNAME, @"_metacmm.txt")); }
/// <summary> /// Gets a list of superceding package files from the DLC of the game. Only files in DLC mods are returned /// </summary> /// <param name="target">Target to get supercedances for</param> /// <returns>Dictionary mapping filename to list of DLCs that contain that file, in order of highest priority to lowest</returns> public static Dictionary <string, List <string> > GetFileSupercedances(GameTarget target) { //make dictionary from basegame files var fileListMapping = new CaseInsensitiveDictionary <List <string> >(); var directories = MELoadedFiles.GetEnabledDLC(target).OrderBy(dir => MELoadedFiles.GetMountPriority(dir, target.Game)); foreach (string directory in directories) { var dlc = Path.GetFileName(directory); if (MEDirectories.OfficialDLC(target.Game).Contains(dlc)) { continue; //skip } foreach (string filePath in MELoadedFiles.GetCookedFiles(target.Game, directory, false)) { string fileName = Path.GetFileName(filePath); if (fileName != null && fileName.RepresentsPackageFilePath()) { if (fileListMapping.TryGetValue(fileName, out var supercedingList)) { supercedingList.Insert(0, dlc); } else { fileListMapping[fileName] = new List <string>(new[] { dlc }); } } } } return(fileListMapping); }
public BasegameCloudDBFile(string file, GameTarget gameTarget, Mod modBeingInstalled) { this.file = file.Substring(gameTarget.TargetPath.Length + 1); this.hash = Utilities.CalculateMD5(file); this.game = gameTarget.Game.ToString().Substring(2); this.source = modBeingInstalled.ModName + @" " + modBeingInstalled.ModVersionString; }
private void LoadME2FilesList() { var me2files = new List <BackupFile>(); var bup = Utilities.GetGameBackupPath(Mod.MEGame.ME2); if (bup != null) { var target = new GameTarget(Mod.MEGame.ME2, bup, false); var cookedPath = MEDirectories.CookedPath(target); foreach (var f in Extensions.GetFiles(cookedPath, @"\.pcc|\.tfc|\.afc|\.bin|\.tlk", SearchOption.AllDirectories)) { me2files.Add(new BackupFile(@"BASEGAME", Path.GetFileName(f))); } var dlcDir = MEDirectories.DLCPath(target); var officialDLC = VanillaDatabaseService.GetInstalledOfficialDLC(target); foreach (var v in officialDLC) { var cookedDLCPath = Path.Combine(dlcDir, v, @"CookedPC"); if (Directory.Exists(cookedDLCPath)) { foreach (var f in Directory.EnumerateFiles(cookedDLCPath, @"*.pcc", SearchOption.TopDirectoryOnly)) { me2files.Add(new BackupFile(v, Path.GetFileName(f))); } } } } Application.Current.Dispatcher.Invoke(delegate { ME2Files.ReplaceAll(me2files); }); Debug.WriteLine(@"Num ME2 files: " + ME2Files.Count); }
/// <summary> /// Validates this mod can install against a game target with respect to the list of RequiredDLC. /// </summary> /// <param name="gameTarget">Target to validate against</param> /// <returns>List of missing DLC modules, or an empty list if none</returns> internal bool ValidateSingleOptionalRequiredDLCInstalled(GameTarget gameTarget) { if (gameTarget.Game != Game) { throw new Exception(@"Cannot validate a mod against a gametarget that is not for its game"); } if (Enumerable.Any <string>(OptionalSingleRequiredDLC)) { var requiredAnyDLC = Enumerable.Select <string, string>(OptionalSingleRequiredDLC, x => { if (Enum.TryParse(x, out ModJob.JobHeader parsedHeader) && ModJob.GetHeadersToDLCNamesMap(Game) .TryGetValue(parsedHeader, out var dlcname)) { return(dlcname); } return(x); }); var installedDLC = M3Directories.GetInstalledDLC(gameTarget); return(installedDLC.FirstOrDefault(x => requiredAnyDLC.Contains(x)) != null); } return(true); }
public static string GetExecutableDirectory(GameTarget target) { if (target.Game == MEGame.LELauncher) { return(target.TargetPath); // LELauncher } return(MEDirectories.GetExecutableFolderPath(target.Game, target.TargetPath)); }
public RestorePanel(List <GameTarget> targetsList, GameTarget selectedTarget) { this.targetsList = targetsList; LoadCommands(); InitializeComponent(); //InstallationTargets_ComboBox.SelectedItem = selectedTarget; }
public static string GetTestPatchSFARPath(GameTarget target) { if (target.Game != MEGame.ME3) { throw new Exception(@"Cannot fetch TestPatch SFAR for games that are not ME3"); } return(ME3Directory.GetTestPatchSFARPath(target.TargetPath)); }
public override void Destroy() { base.Destroy(); GameTarget.Dispose(); UiTarget?.Dispose(); Batcher2D.Dispose(); }
public BasegameCloudDBFile(string fullfilepath, int size, GameTarget gameTarget, Mod modBeingInstalled, string md5 = null) { this.file = fullfilepath.Substring(gameTarget.TargetPath.Length + 1); this.hash = md5 ?? Utilities.CalculateMD5(fullfilepath); this.game = gameTarget.Game.ToGameNum().ToString(); this.size = size; this.source = modBeingInstalled.ModName + @" " + modBeingInstalled.ModVersionString; }
public InstallationInformation(List <GameTarget> targetsList, GameTarget selectedTarget) { DataContext = this; InstallationTargets.AddRange(targetsList); LoadCommands(); InitializeComponent(); SelectedTarget = selectedTarget; }
/// <summary> /// Gets the path to the testpatch DLC file for the specified game target /// </summary> /// <param name="target">target to resolve path for</param> /// <returns>Null if gametarget game is not ME3. Path where SFAR should be if ME3.</returns> public static string GetTestPatchPath(GameTarget target) { if (target.Game != Mod.MEGame.ME3) { return(null); } return(Path.Combine(target.TargetPath, @"BIOGame\Patches\PCConsole\Patch_001.sfar")); }
public BackupCreator(List <GameTarget> targetsList, GameTarget selectedTarget, Window window) { DataContext = this; this.targetsList = targetsList; LoadCommands(); InitializeComponent(); //InstallationTargets_ComboBox.SelectedItem = selectedTarget; }
public static void RemoveMergeDLC(GameTarget target) { var mergePath = Path.Combine(M3Directories.GetDLCPath(target), MERGE_DLC_FOLDERNAME); if (Directory.Exists(mergePath)) { Utilities.DeleteFilesAndFoldersRecursively(mergePath); } }
public InstallationInformation(List <GameTarget> targetsList, GameTarget selectedTarget) { MemoryAnalyzer.AddTrackedMemoryItem(@"Installation Information Panel", new WeakReference(this)); DataContext = this; InstallationTargets.AddRange(targetsList); LoadCommands(); InitializeComponent(); SelectedTarget = selectedTarget; }
public void LoadStageData(int levelNum) { _config = new ConfigOperator("Level" + levelNum); _config.Read(); int targetInt = 0; _config.GetValue<int>("Target", out targetInt); Target = (GameTarget)targetInt; _config.GetValue<int>("StepLimit", out StepLimit); _config.GetValue<int>("TimeLimit", out TimeLimit); _config.GetValue<int>("ColorCount", out ColorCount); _config.GetValue<int>("Nut1Count", out Nut1Count); _config.GetValue<int>("Nut2Count", out Nut2Count); _config.GetValue<int>("NutInitCount", out NutInitCount); _config.GetValue<int>("NutMaxCount", out NutMaxCount); _config.GetValue<int>("NutStep", out NutStep); _config.GetValue<int>("PlusInitCount", out PlusInitCount); _config.GetValue<int>("PlusMaxCount", out PlusMaxCount); _config.GetValue<int>("PlusStartTime", out PlusStartTime); _config.GetValue<int>("PlusStep", out PlusStep); _config.GetValue<int>("Seed", out Seed); if (ColorCount == 0) { ColorCount = 7; } string temp; _config.GetValue<string>("StarScore", out temp); string [] scoreTokens = temp.Split(','); for (int i = 0; i < 3; ++i) { StarScore[i] = (int)System.Convert.ChangeType(scoreTokens[i], typeof(int)); } //GridData _config.GetValue<string>("GridDataArray", out temp); string[] gridDataTokens = temp.Split(','); for (int i = 0; i < GameLogic.BlockCountX; ++i ) { for (int j = 0; j < GameLogic.BlockCountY; ++j ) { int number = (int)System.Convert.ChangeType(gridDataTokens[j * GameLogic.BlockCountX + i], typeof(int)); GridData[i, j] = number; } } PortalToMap.Clear(); PortalFromMap.Clear(); //Portals _config.GetValue<string>("PortalArray", out temp); if (temp != null) { string[] portalDataTokens = temp.Split(','); for (int i = 0; i < portalDataTokens.Length - 4; i += 5) { Portal portal = new Portal(); portal.from = new Position((int)System.Convert.ChangeType(portalDataTokens[i], typeof(int)), (int)System.Convert.ChangeType(portalDataTokens[i + 1], typeof(int))); portal.to = new Position((int)System.Convert.ChangeType(portalDataTokens[i + 2], typeof(int)), (int)System.Convert.ChangeType(portalDataTokens[i + 3], typeof(int))); portal.flag = (int)System.Convert.ChangeType(portalDataTokens[i + 4], typeof(int)); PortalToMap.Add(portal.to.ToInt(), portal); PortalFromMap.Add(portal.from.ToInt(), portal); } } Debug.Log("Level " + levelNum + " Loaded"); }
public void CopyStageData(StageData data) //这样Copy后,原数据不能销毁或修改,因为有部分内容直接引用了原数据的 { Target = data.Target; StepLimit = data.StepLimit; TimeLimit = data.TimeLimit; ColorCount = data.ColorCount; Nut1Count = data.Nut1Count; Nut2Count = data.Nut2Count; NutInitCount = data.NutInitCount; NutMaxCount = data.NutMaxCount; NutMinCount = data.NutMinCount; NutStep = data.NutStep; PlusInitCount = data.PlusInitCount; PlusMaxCount = data.PlusMaxCount; PlusStartTime = data.PlusStartTime; PlusStepMin = data.PlusStepMin; PlusStepMax = data.PlusStepMax; Seed = data.Seed; for (int i = 0; i < 3; ++i) { StarScore[i] = data.StarScore[i]; CollectCount[i] = data.CollectCount[i]; CollectColors[i] = data.CollectColors[i]; CollectSpecial[i] = data.CollectSpecial[i]; } for (int i = 0; i < GameLogic.BlockCountX; ++i) { for (int j = 0; j < GameLogic.BlockCountY; ++j) { GridData[i, j] = data.GridData[i, j]; } } ChocolateCount = data.ChocolateCount; StoneCount = data.StoneCount; //这几个是只读的,就直接用源数据的就行了 PortalToMap = data.PortalToMap; PortalFromMap = data.PortalFromMap; SpecialBlock = data.SpecialBlock; FTUEMap = data.FTUEMap; }
public void LoadStageData(int levelNum) { _config = new ConfigOperator("Level" + levelNum); _config.Read(); int targetInt = 0; _config.GetIntValue("Target", out targetInt); Target = (GameTarget)targetInt; _config.GetIntValue("StepLimit", out StepLimit); _config.GetIntValue("TimeLimit", out TimeLimit); _config.GetIntValue("ColorCount", out ColorCount); _config.GetIntValue("Nut1Count", out Nut1Count); _config.GetIntValue("Nut2Count", out Nut2Count); _config.GetIntValue("NutInitCount", out NutInitCount); _config.GetIntValue("NutMaxCount", out NutMaxCount); _config.GetIntValue("NutMinCount", out NutMinCount); _config.GetIntValue("NutStep", out NutStep); _config.GetIntValue("PlusInitCount", out PlusInitCount); _config.GetIntValue("PlusMaxCount", out PlusMaxCount); _config.GetIntValue("PlusStartTime", out PlusStartTime); if (!_config.GetIntValue("PlusStepMin", out PlusStepMin)) { PlusStepMin = 5; } if (!_config.GetIntValue("PlusStepMax", out PlusStepMax)) { PlusStepMax = 10; } _config.GetIntValue("Seed", out Seed); if (ColorCount == 0) { ColorCount = 7; } string temp; _config.GetStringValue("StarScore", out temp); string [] scoreTokens = temp.Split(','); for (int i = 0; i < 3; ++i) { StarScore[i] = (int)System.Convert.ChangeType(scoreTokens[i], typeof(int)); } if (_config.GetStringValue("CollectCount", out temp)) { string[] collectCountTokens = temp.Split(','); for (int i = 0; i < 3; ++i) { CollectCount[i] = System.Convert.ToInt32(collectCountTokens[i]); } } if (_config.GetStringValue("CollectColors", out temp)) { string[] collectColorTokens = temp.Split(','); for (int i = 0; i < 3; ++i) { CollectColors[i] = (TBlockColor)System.Convert.ToInt32(collectColorTokens[i]); } } if (_config.GetStringValue("CollectSpecial", out temp)) { string[] collectSpecialTokens = temp.Split(','); for (int i = 0; i < 3; ++i) { CollectSpecial[i] = (TSpecialBlock)System.Convert.ToInt32(collectSpecialTokens[i]); } } //GridData _config.GetStringValue("GridDataArray", out temp); string[] gridDataTokens = temp.Split(','); for (int i = 0; i < GameLogic.BlockCountX; ++i ) { for (int j = 0; j < GameLogic.BlockCountY; ++j ) { int number = (int)System.Convert.ChangeType(gridDataTokens[j * GameLogic.BlockCountX + i], typeof(int)); if ((number & (int)GridFlag.Chocolate) > 0) { ++ChocolateCount; } if ((number & (int)GridFlag.Stone) > 0) { ++StoneCount; } if ((number & (int)GridFlag.Iron) > 0) { ++StoneCount; } GridData[i, j] = number; } } PortalToMap.Clear(); PortalFromMap.Clear(); //Portals _config.GetStringValue("PortalArray", out temp); if (temp != null) { string[] portalDataTokens = temp.Split(','); for (int i = 0; i < portalDataTokens.Length - 4; i += 5) { Portal portal = new Portal(); portal.from = new Position((int)System.Convert.ChangeType(portalDataTokens[i], typeof(int)), (int)System.Convert.ChangeType(portalDataTokens[i + 1], typeof(int))); portal.to = new Position((int)System.Convert.ChangeType(portalDataTokens[i + 2], typeof(int)), (int)System.Convert.ChangeType(portalDataTokens[i + 3], typeof(int))); portal.flag = (int)System.Convert.ChangeType(portalDataTokens[i + 4], typeof(int)); PortalToMap.Add(portal.to.ToInt(), portal); PortalFromMap.Add(portal.from.ToInt(), portal); } } SpecialBlock.Clear(); //清理已有内容 //Portals _config.GetStringValue("SpecialArray", out temp); if (temp != null) { string[] specialDataTokens = temp.Split(','); for (int i = 0; i < specialDataTokens.Length - 2; i += 3) { Position pos = new Position((int)System.Convert.ChangeType(specialDataTokens[i], typeof(int)), (int)System.Convert.ChangeType(specialDataTokens[i + 1], typeof(int))); int special = (int)System.Convert.ChangeType(specialDataTokens[i + 2], typeof(int)); SpecialBlock.Add(pos.ToInt(), special); } } Debug.Log("Level " + levelNum + " Loaded"); FTUEMap.Clear(); string ftue = ResourceManager.Singleton.LoadTextFile("FTUE" + levelNum); if (ftue != string.Empty) { List<FTUEData> curFTUEGroup = new List<FTUEData>(); int step = -1; StringReader sr = new StringReader(ftue); string line = sr.ReadLine(); while (line != null) { if (line.Contains("//")) { line = sr.ReadLine(); continue; } if (string.IsNullOrEmpty(line)) { line = sr.ReadLine(); continue; } string[] values = line.Split(new string[] { "\t", " " }, System.StringSplitOptions.RemoveEmptyEntries); if (values.Length > 0) { int num = System.Convert.ToInt32(values[0]); if (step == -1) { step = num; FTUEMap.Add(step, curFTUEGroup); //添加一个组 } else if(num != step) { curFTUEGroup = new List<FTUEData>(); step = num; FTUEMap.Add(step, curFTUEGroup); //添加一个组 } FTUEData data = new FTUEData(); data.highLightPosList = new List<Position>(); data.headImage = values[1]; data.dialog = values[2]; string[] posArray; if (values[3] != "None") { posArray = values[3].Split(','); data.from.x = System.Convert.ToInt32(posArray[0]); data.from.y = System.Convert.ToInt32(posArray[1]); } else { data.from.MakeItUnAvailable(); } if (values[4] != "None") { posArray = values[4].Split(','); data.to.x = System.Convert.ToInt32(posArray[0]); data.to.y = System.Convert.ToInt32(posArray[1]); } else { data.to.MakeItUnAvailable(); } if (values[5] != "None") { posArray = values[5].Split(','); for (int i = 0; i < posArray.Length / 2; ++i) { int x = System.Convert.ToInt32(posArray[i * 2]); int y = System.Convert.ToInt32(posArray[i * 2 + 1]); data.highLightPosList.Add(new Position(x, y)); } } if (values.Length > 6) { data.pic = values[6]; } else { data.pic = "None"; } if (values.Length > 7) { if (System.Convert.ToInt32(values[7]) == 1) { data.bHighLightBackground = true; data.bHighLightBlock = false; } else if (System.Convert.ToInt32(values[7]) == 2) { data.bHighLightBackground = true; data.bHighLightBlock = true; } else if (System.Convert.ToInt32(values[7]) == 0) { data.bHighLightBackground = false; data.bHighLightBlock = true; } } else { data.bHighLightBackground = false; data.bHighLightBlock = true; } if (values.Length > 8) { posArray = values[8].Split(','); data.dialogPos = System.Convert.ToInt32(posArray[0]); data.picturePos = System.Convert.ToInt32(posArray[1]); } curFTUEGroup.Add(data); //添加对话数据 } line = sr.ReadLine(); } sr.Close(); } }