private void playBtn_Click(object sender, EventArgs e) { var title = titleList.SelectedItem as Title; if (title == null) { return; } new Thread(() => { Toolbelt.LaunchCemu(title.MetaLocation, null); }).Start(); }
private static void LaunchCemuButton() { new Thread(() => { if (SelectedItem == null) { Toolbelt.LaunchCemu(string.Empty, null); return; } SelectedItem.PlayTitle(); }).Start(); }
public GameObject npc; //for testing void Awake() { // Get gamemanager gameManager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>(); inventory = GetComponent <Inventory>(); skills = GetComponent <Skills>(); perkAttributes = GetComponent <PerkAttributes>(); toolbelt = GetComponent <Toolbelt>(); enemyAttributes = GetComponent <EnemyAttributes>(); thirst = 100; hunger = 100; }
public static GameObject CreateCubeRing(int n, float r) { var go = new GameObject(); var xf = go.GetTransform(); for (int i = 0; i < n; ++i) { var cube = Toolbelt.CreateCube(); cube.GetTransform().position = new Vector3(r, 0, 0); cube.GetTransform().parent = xf; xf.Rotate(0f, 360f / n, 0); } return(go); }
//------------------------------------------------------------------------------------------------------------ private void inputStatement(string[] tokens, int lineNumber, out int operationCode, out int operand) { if (!Toolbelt.IsValidVariable(tokens[2])) { throw new SystemException($"{tokens[2]} not valid for variable name following 'input' keyword -on code line {lineNumber}"); } char variable = Convert.ToChar(tokens[2]); var entry = _symbolTable.FindOrAdd((int)variable, TableEntry.VARIABLE); // Generate EPML instruction operationCode = (int)EPC.Code.READ; operand = entry.Location(); _compiledCode.Add(Word.Build(operationCode, operand), _workingLineNumber++); }
private void playBtn_Click(object sender, EventArgs e) { var title = titleList.SelectedItem as Title; if (title == null) { return; } if (!Toolbelt.LaunchCemu(title.MetaLocation, null)) { return; } TextLog.MesgLog.WriteLog($"Started playing {title.Name}"); }
public void PlayTitle() { if (MetaLocation.IsNullOrEmpty()) { return; } new Thread(() => { if (!Toolbelt.LaunchCemu(MetaLocation, SelectedGraphicPack)) { return; } TextLog.MesgLog.WriteLog($"Now Playing: {Name}"); }).Start(); }
//------------------------------------------------------------------------------------------------------------ private void putInSymbolTable(string[] tokens) { // place all variables and constants in the symbol table if missing for (int i = 2; i < tokens.Length; ++i) { var token = tokens[i]; if (Int32.TryParse(token, out int intToken)) { var tempEntry = _symbolTable.FindOrAddConst(intToken); _compiledCode.Add(tempEntry.Symbol(), tempEntry.Location()); } else if (Toolbelt.IsValidVariable(token)) { _symbolTable.FindOrAddVar(Convert.ToChar(token)); } } }
private void LaunchCemuButton() { if (SelectedItem == null) { return; } new Thread(() => { var pack = MainWindowViewModel.Instance.Config.SelectedItemGraphicPack; if (!Toolbelt.LaunchCemu(SelectedItem.MetaLocation, pack)) { return; } TextLog.MesgLog.WriteLog($"Now Playing: {SelectedItem.Name}"); }).Start(); }
public void ReceiveItem(Item item) { var itemStack = new ItemStack(item.Id); if (Toolbelt.HasCompatibleSlot(itemStack)) { Toolbelt.SetFirstCompatibleSlot(itemStack); } else if (Inventory.HasCompatibleSlot(itemStack)) { Inventory.SetFirstCompatibleSlot(itemStack); } else { throw new InvalidOperationException("The inventories are all full!"); } }
private async void titleIdTextBox_TextChanged(object sender, EventArgs e) { if (titleIdTextBox.Text.Length != 16) { return; } var title = await Database.FindTitleAsync(titleIdTextBox.Text); if (title == null) { return; } titleName.Text = Toolbelt.Ric(title.Name); SetCurrentImage(title); }
private void titleIdTextBox_TextChanged(object sender, EventArgs e) { if (titleIdTextBox.Text.Length != 16) { return; } var title = Database.SearchById(titleIdTextBox.Text); if (title == null) { return; } titleName.Text = Toolbelt.RIC(title.Name); SetCurrentImage(title); }
private void UpdateProgressBar(int percent, long _toReceive, long _received) { if (percent <= 0 || _toReceive <= 0 || _received <= 0) { return; } try { Invoke(new Action(() => progressBar.Value = percent)); var toReceive = Toolbelt.SizeSuffix(_toReceive); var received = Toolbelt.SizeSuffix(_received); progressOverlay.Invoke(new Action(() => { progressOverlay.Text = $@"{received} / {toReceive}"; })); } catch (Exception ex) { TextLog.MesgLog.WriteError($"{ex.Message}\n{ex.StackTrace}"); } }
//------------------------------------------------------------------------------------------------------------ private void printStatement(string[] tokens, int lineNumber, out int operationCode, out int operand) { if (tokens.Length == 2) { throw new SystemException($"Missing variable after 'print' keyword -on code line {lineNumber}"); } if (!Toolbelt.IsValidVariable(tokens[2])) { throw new SystemException($"Invalid token ({tokens[2]}) following 'print' statement. Single letter variable expected -on code line {lineNumber}"); } operationCode = (int)EPC.Code.WRITE; char printVar = Convert.ToChar(tokens[2]); var printEntry = _symbolTable.GetEntry((int)printVar); if (printEntry == null) { throw new SystemException($"Variable '{tokens[2]}' is missing from the Symbol Table"); } operand = printEntry.Location(); _compiledCode.Add(Word.Build(operationCode, operand), _workingLineNumber++); }
private static TMD DownloadTmd(string url, string saveTo) { var data = DownloadData(url); if (data.Length <= 0) { return(null); } var tmd = TMD.Load(data); if (tmd.TitleVersion > 999) { return(null); } Toolbelt.AppendLog(" - Parsing TMD..."); Toolbelt.AppendLog($" + Title Version: {tmd.TitleVersion}"); Toolbelt.AppendLog($" + {tmd.NumOfContents} Contents"); File.WriteAllBytes(saveTo, data); return(tmd); }
static void Chevrons() { var curve = Selection.activeGameObject.GetComponent(typeof(ParametricCurve)) as ParametricCurve; if (curve == null) { return; } int count = 100; var samples = new Vector3[count]; curve.SampleValues(samples, 0f, 1f); var root = new GameObject().GetTransform(); var head = Toolbelt.CreatePyramid(); head.GetTransform().Rotate(90f, 0f, 0f); var mesh = head.GetFilter().FreezeTransformation(); for (int i = 0; i < count; ++i) { var arrow = Toolbelt.CreatePrimitive("chevron"); arrow.GetFilter().sharedMesh = mesh; var xform = arrow.GetTransform(); xform.position = samples[i]; xform.localScale = new Vector3(0.5f, 0.5f, 0.5f); var u = i / (count - 1f); xform.rotation = Quaternion.LookRotation(curve.DerivAt(u).normalized); xform.parent = root; } GameObject.DestroyImmediate(head); }
//------------------------------------------------------------------------------------------------------------ private void forStatement(string[] tokens, int lineNumber) { // Place increment value into the symbol table _symbolTable.AddConst(FOR_LOOP_INCREMENT); if (findNext(out int intNextLineLocation)) // validate there is a 'next' statement { // validate that the 'for' statement following the correct syntax // [2] = variable, [3] = comparator, [4] = var/const, [5] = 'to', [6] = var/const string strLHS = tokens[2]; string strRHS = tokens[4]; string strCheck = tokens[6]; if (Toolbelt.IsValidVariable(strLHS) && tokens[3] == "=" && tokens[5] == "to") { putInSymbolTable(tokens); // Format the assignment string so it can be properly processed string assignment = $"00 let {strLHS} = {strRHS}"; letStatement(assignment.Split(' '), lineNumber); // after let statement is process, the next entry will be the start of the commands in the loop _forLoopEntries.Push(ForLoopEntry.Make( step: _workingLineNumber, lhs: _symbolTable.Find(strLHS).Location(), rhs: _symbolTable.Find(strCheck).Location(), increment: FOR_LOOP_INCREMENT )); } else { throw new SystemException($"Invalid 'for' statement -on code line {lineNumber}"); } } else { throw new SystemException($"'for' missing 'next' statment -on code line {lineNumber}"); } }
void Start() { if (GetComponent <Toolbelt>()) { toolbelt = GetComponent <Toolbelt>(); } if (GetComponent <Skills>()) { skills = GetComponent <Skills>(); } enemyCatalog = gameManager.getEnemyCatalog(); enemyName = enemyCatalog.getNameContains(transform.name); transform.name = enemyName; if (enemyCatalog.getEnemyByName(enemyName) != null) { description = enemyCatalog.getEnemyByName(enemyName).getDescription(); type = enemyCatalog.getEnemyByName(enemyName).getType(); level = enemyCatalog.getEnemyByName(enemyName).getLevel(); health = enemyCatalog.getEnemyByName(enemyName).getBaseHealth(); ranged = enemyCatalog.getEnemyByName(enemyName).getRanged(); magic = enemyCatalog.getEnemyByName(enemyName).getMagic(); melee = enemyCatalog.getEnemyByName(enemyName).getMelee(); armor = enemyCatalog.getEnemyByName(enemyName).getBaseArmor(); movementspeed = enemyCatalog.getEnemyByName(enemyName).getBaseMovementSpeed(); agent.speed = movementspeed; attackSpeed = enemyCatalog.getEnemyByName(enemyName).getAttackSpeed(); critChance = enemyCatalog.getEnemyByName(enemyName).getBaseCritChange(); attackRange = enemyCatalog.getEnemyByName(enemyName).getAttackRange(); frostResistance = enemyCatalog.getEnemyByName(enemyName).getFrostResistance(); fireRestistance = enemyCatalog.getEnemyByName(enemyName).getFireResistance(); aggressive = enemyCatalog.getEnemyByName(enemyName).getAggressive(); droptable = enemyCatalog.getEnemyByName(enemyName).getDroptable(); inventory = transform.GetComponent <Inventory>(); abilities = enemyCatalog.getEnemyByName(enemyName).getAbilities(); } }
//------------------------------------------------------------------------------------------------------------ private void compileAssignment(string[] tokens, int lineNumber, int storeLoc) { var token = tokens[4]; int loc = -1; if (Int32.TryParse(token, out int intValue)) // assigning a Constant { loc = _symbolTable.FindConstant(intValue).Location(); } else if (Toolbelt.IsValidVariable(token)) // assigning a variable value { if (Char.TryParse(token, out char chVar)) { loc = _symbolTable.FindVariable((int)chVar).Location(); } else { throw new SystemException($"Something bad happened -on code line {lineNumber}"); } } else { throw new SystemException($"Invalid character following '=' in 'let' statement -on code line {lineNumber}"); } if (loc >= 0) { // load constant or variable value from memory and store in assignment variable _compiledCode.Add(Word.Build((int)EPC.Code.LOAD, loc), _workingLineNumber++); if (_symbolTable.HasLocation(storeLoc) && _symbolTable.AtLocation(storeLoc).IsConst()) { throw new SystemException($"Cannot override constant value at memory[{storeLoc}] -on code line {lineNumber}"); } _compiledCode.Add(Word.Build((int)EPC.Code.STORE, storeLoc), _workingLineNumber++); } }
//------------------------------------------------------------------------------------------------------------ public TableEntry Find(string searchFor) { if (Int32.TryParse(searchFor, out int intConstant)) { // search string is a constant return(FindConstant(intConstant)); } else if (Toolbelt.IsValidVariable(searchFor)) { // search string is a variable if (Char.TryParse(searchFor, out char chVar)) { return(FindVariable((int)chVar)); } else { throw new SystemException($"SymbolTable Find({searchFor}) unexpected error. Something bad happened"); } } else { throw new SystemException($"SymbolTable Find({searchFor}) search string must be a variable or constant"); } }
private static async Task <int> DownloadContent(TMD tmd, string outputDir, string titleUrl) { var result = 0; for (var i = 0; i < tmd.NumOfContents; i++) { var i1 = i; result = await Task.Run(async() => { var numc = tmd.NumOfContents; var size = Toolbelt.SizeSuffix((long)tmd.Contents[i1].Size); Toolbelt.AppendLog($"Downloading Content #{i1 + 1} of {numc}... ({size})"); var contentPath = Path.Combine(outputDir, tmd.Contents[i1].ContentID.ToString("x8")); if (!Toolbelt.IsValid(tmd.Contents[i1], contentPath)) { try { var downloadUrl = $"{titleUrl}/{tmd.Contents[i1].ContentID:x8}"; await Web.DownloadFileAsync(downloadUrl, contentPath); } catch (Exception ex) { Toolbelt.AppendLog($"Downloading Content #{i1 + 1} of {numc} failed...\n{ex.Message}"); return(0); } } ReportProgress(0, tmd.NumOfContents - 1, i1); return(1); }); if (result == 0) { break; } } ReportProgress(0, 100, 0); return(result); }
//------------------------------------------------------------------------------------------------------------ private void ifStatement(string[] tokens, int lineNumber) { // Assume only one token to the left of the comparator eg. 20 if x == y goto 50 // [2] = Left, [3] = Comparator, [4] = Right, [5] = 'goto', [6] = LineNumber if (!tokens.Contains("goto")) { throw new SystemException($"'if' statement missing corresponding 'goto' -on code line {lineNumber}"); } string left = tokens[2]; string comparator = tokens[3]; string right = tokens[4]; string goTo = tokens[5]; string gotoLine = tokens[6]; TableEntry leftEntry, rightEntry; //------------------Begin Validations--------Symbol table update------------ // Validate left of comparator if (Int32.TryParse(left, out int intLeft)) // Third token is a number (constant) { leftEntry = _symbolTable.FindOrAddConst(intLeft); _compiledCode.Add(leftEntry.Symbol(), leftEntry.Location()); } else if (Toolbelt.IsValidVariable(left)) // Third token is a valid variable { char leftVar = Convert.ToChar(left); leftEntry = _symbolTable.FindOrAddVar((int)leftVar); } else { throw new SystemException($"{left} not valid following 'if' keyword -on code line {lineNumber}"); } // Validate comparator if (!Toolbelt.IsComparator(comparator)) // Fourth token is a valid comparator { throw new SystemException($"{comparator} is is not a valid comparator in 'if' statement -on code line {lineNumber}"); } // Validate left of comparator if (Int32.TryParse(right, out int intRight)) // Third token is a number (constant) { rightEntry = _symbolTable.FindOrAddConst(intRight); _compiledCode.Add(rightEntry.Symbol(), rightEntry.Location()); } else if (Toolbelt.IsValidVariable(right)) // Third token is a valid variable { char rightVar = Convert.ToChar(right); rightEntry = _symbolTable.FindOrAddVar((int)rightVar); } else { throw new SystemException($"{right} not valid following comparator in 'if' statement -on code line {lineNumber}"); } // validate that 'goto' is in position 5 if (goTo != "goto") { throw new SystemException($"Expected 'goto' after comparison in 'if' statement. ({goTo}) -on code line {lineNumber}"); } // validate that following the 'goto' is a numeric value if (!Int32.TryParse(gotoLine, out int intGotoLine)) { throw new SystemException($"'{gotoLine}' invalid token following 'goto' in 'if' statement. Integer value expected. -on code line {lineNumber}"); } //-------------End Validations-------------------- if (leftEntry == null || rightEntry == null) { throw new SystemException($"Unknown error occurred in 'if/goto' statement -on code line {lineNumber}"); } // lookup goto line number in symbol table var gotoLineEntry = _symbolTable.FindLineNumber(intGotoLine); var gotoLineNumber = 00; bool needsFlag = false; if (gotoLineEntry != null) { gotoLineNumber = gotoLineEntry.Location(); } else { needsFlag = true; } // perform calculations with right operand // add appropriate branch command switch (comparator) { case "==": _compiledCode.Add(Word.Build((int)EPC.Code.LOAD, leftEntry.Location()), _workingLineNumber++); _compiledCode.Add(Word.Build((int)EPC.Code.SUBTRACT, rightEntry.Location()), _workingLineNumber++); if (needsFlag) { _flags.Add(_workingLineNumber, intGotoLine); } _compiledCode.Add(Word.Build((int)EPC.Code.BRANCHZERO, gotoLineNumber), _workingLineNumber++); break; case "!=": // check if greater than _compiledCode.Add(Word.Build((int)EPC.Code.LOAD, rightEntry.Location()), _workingLineNumber++); _compiledCode.Add(Word.Build((int)EPC.Code.SUBTRACT, leftEntry.Location()), _workingLineNumber++); if (needsFlag) { _flags.Add(_workingLineNumber, intGotoLine); } _compiledCode.Add(Word.Build((int)EPC.Code.BRANCHNEG, gotoLineNumber), _workingLineNumber++); // check if less than _compiledCode.Add(Word.Build((int)EPC.Code.LOAD, leftEntry.Location()), _workingLineNumber++); _compiledCode.Add(Word.Build((int)EPC.Code.SUBTRACT, rightEntry.Location()), _workingLineNumber++); if (needsFlag) { _flags.Add(_workingLineNumber, intGotoLine); } _compiledCode.Add(Word.Build((int)EPC.Code.BRANCHNEG, gotoLineNumber), _workingLineNumber++); break; case "<": _compiledCode.Add(Word.Build((int)EPC.Code.LOAD, leftEntry.Location()), _workingLineNumber++); _compiledCode.Add(Word.Build((int)EPC.Code.SUBTRACT, rightEntry.Location()), _workingLineNumber++); if (needsFlag) { _flags.Add(_workingLineNumber, intGotoLine); } _compiledCode.Add(Word.Build((int)EPC.Code.BRANCHNEG, gotoLineNumber), _workingLineNumber++); break; case ">": _compiledCode.Add(Word.Build((int)EPC.Code.LOAD, rightEntry.Location()), _workingLineNumber++); _compiledCode.Add(Word.Build((int)EPC.Code.SUBTRACT, leftEntry.Location()), _workingLineNumber++); if (needsFlag) { _flags.Add(_workingLineNumber, intGotoLine); } _compiledCode.Add(Word.Build((int)EPC.Code.BRANCHNEG, gotoLineNumber), _workingLineNumber++); break; case "<=": _compiledCode.Add(Word.Build((int)EPC.Code.LOAD, leftEntry.Location()), _workingLineNumber++); _compiledCode.Add(Word.Build((int)EPC.Code.SUBTRACT, rightEntry.Location()), _workingLineNumber++); if (needsFlag) { _flags.Add(_workingLineNumber, intGotoLine); } _compiledCode.Add(Word.Build((int)EPC.Code.BRANCHNEG, gotoLineNumber), _workingLineNumber++); if (needsFlag) { _flags.Add(_workingLineNumber, intGotoLine); } _compiledCode.Add(Word.Build((int)EPC.Code.BRANCHZERO, gotoLineNumber), _workingLineNumber++); break; case ">=": _compiledCode.Add(Word.Build((int)EPC.Code.LOAD, rightEntry.Location()), _workingLineNumber++); _compiledCode.Add(Word.Build((int)EPC.Code.SUBTRACT, leftEntry.Location()), _workingLineNumber++); if (needsFlag) { _flags.Add(_workingLineNumber, intGotoLine); } _compiledCode.Add(Word.Build((int)EPC.Code.BRANCHNEG, gotoLineNumber), _workingLineNumber++); if (needsFlag) { _flags.Add(_workingLineNumber, intGotoLine); } _compiledCode.Add(Word.Build((int)EPC.Code.BRANCHZERO, gotoLineNumber), _workingLineNumber++); break; } }
public override string ToString() { var cType = ContentType.Contains("App") ? "" : $"[{ContentType}]"; return(Toolbelt.RIC($"{cType}[{Region}] {Name}")); }
private static void DownloadTitle(string id, string outputDir, string contentType, string version) { #region Setup var workingId = id.ToUpper(); //download dlc if applicable if (contentType == "DLC") { workingId = $"0005000C{workingId.Substring(8).ToUpper()}"; } //download patch if applicable if (contentType == "Patch") { workingId = $"0005000E{workingId.Substring(8).ToUpper()}"; } var title = Database.FindTitleKey(workingId); if (title.titleKey.Length != 32) { throw new Exception("Could not locate the title key"); } var key = title.titleKey; var name = title.name; if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(name)) { return; } var result = MessageBoxResult.Cancel; var str = $"Download {contentType} content to the following location?\n\"{outputDir}\""; Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { result = MessageBox.Show(Application.Current.MainWindow, str, name, MessageBoxButton.YesNo); })); if (result != MessageBoxResult.Yes) { return; } if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } Toolbelt.AppendLog($"Output Directory '{outputDir}'"); #endregion #region TMD Toolbelt.AppendLog(" - Loading TMD..."); TMD tmd = null; var nusUrls = new List <string> { "http://ccs.cdn.wup.shop.nintendo.net/ccs/download/", "http://nus.cdn.shop.wii.com/ccs/download/", "http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/" }; foreach (var nusUrl in nusUrls) { var titleUrl = $"{nusUrl}{workingId}/"; tmd = LoadTmd(workingId, key, outputDir, titleUrl, version); if (tmd != null) { break; } } if (tmd == null) { TextLog.MesgLog.WriteError("Could not locate TMD. Is this content request valid?"); return; } #endregion #region Ticket Toolbelt.AppendLog("Generating Ticket..."); var tikData = MapleTicket.Create(Database.FindTitleKey(workingId)); if (tikData == null) { throw new Exception("Invalid ticket data. Verify Title ID."); } var ticket = Ticket.Load(tikData); ticket.Save(Path.Combine(outputDir, "cetk")); #endregion #region Content Toolbelt.AppendLog($"[+] [{contentType}] {name} v{tmd.TitleVersion}"); Toolbelt.SetStatus($"Output Directory: {outputDir}"); foreach (var nusUrl in nusUrls) { var url = nusUrl + workingId; if (DownloadContent(tmd, outputDir, url) != 1) { continue; } Toolbelt.AppendLog(string.Empty); Toolbelt.AppendLog(" - Decrypting Content"); Toolbelt.AppendLog(" + This may take a minute. Please wait..."); Toolbelt.SetStatus("Decrypting Content. This may take a minute. Please wait...", Color.OrangeRed); if (Toolbelt.CDecrypt(outputDir) != 0) { CleanUp(outputDir, tmd); Toolbelt.AppendLog($"Error while decrypting {name}"); return; } CleanUp(outputDir, tmd); break; } #endregion Web.ResetDownloadProgressChanged(); Toolbelt.AppendLog($"[+] [{contentType}] {name} v{tmd.TitleVersion} Finished."); Toolbelt.SetStatus($"[+] [{contentType}] {name} v{tmd.TitleVersion} Finished."); }
/// <summary> /// Grabs a title from NUS, you can define several store types. /// Leave the title version empty for the latest. /// </summary> /// <param name="titleId"></param> /// <param name="titleVersion"></param> /// <param name="outputDir"></param> /// <param name="storeTypes"></param> public void DownloadTitle(string titleId, string titleVersion, string outputDir, StoreType[] storeTypes) { FireDebug("Downloading Title {0} v{1}...", titleId, (string.IsNullOrEmpty(titleVersion)) ? "[Latest]" : titleVersion); if (storeTypes.Length < 1) { FireDebug(" No store types were defined..."); throw new Exception("You must at least define one store type!"); } var titleInfo = Database.GetTitle(titleId); string titleUrl = $"{nusUrl}{titleId}/"; string titleUrl2 = $"{nusUrl2}{titleId}/"; bool storeEncrypted = false; bool storeDecrypted = false; FireProgress(0); foreach (StoreType st in storeTypes) { switch (st) { case StoreType.DecryptedContent: FireDebug(" [=] Storing Decrypted Content..."); storeDecrypted = true; break; case StoreType.EncryptedContent: FireDebug(" [=] Storing Encrypted Content..."); storeEncrypted = true; break; case StoreType.All: FireDebug(" [=] Storing Decrypted Content..."); FireDebug(" [=] Storing Encrypted Content..."); FireDebug(" [=] Storing WAD..."); storeDecrypted = true; storeEncrypted = true; break; case StoreType.Empty: break; } } FireDebug(" - Checking for Internet connection..."); if (!CheckInet()) { FireDebug(" + Connection not found..."); throw new Exception("You're not connected to the internet!"); } if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } if (!Directory.Exists(Path.Combine(outputDir, titleInfo.Name))) { Directory.CreateDirectory(Path.Combine(outputDir, titleInfo.Name)); } outputDir = Path.Combine(outputDir, titleInfo.Name); string tmdFile = "tmd" + (string.IsNullOrEmpty(titleVersion) ? string.Empty : string.Format(".{0}", titleVersion)); //Download TMD FireDebug(" - Downloading TMD..."); TMD tmd; byte[] tmdFileWithCerts; try { tmdFileWithCerts = wcNus.DownloadData(titleUrl + tmdFile); tmd = TMD.Load(tmdFileWithCerts); } catch (Exception ex) { FireDebug(" + Downloading TMD Failed..."); throw new Exception("Downloading TMD Failed:\n" + ex.Message); } //Parse TMD FireDebug(" - Parsing TMD..."); if (string.IsNullOrEmpty(titleVersion)) { FireDebug(" + Title Version: {0}", tmd.TitleVersion); } FireDebug(" + {0} Contents", tmd.NumOfContents); if (!Directory.Exists(Path.Combine(outputDir, tmd.TitleVersion.ToString()))) { Directory.CreateDirectory(Path.Combine(outputDir, tmd.TitleVersion.ToString())); } outputDir = Path.Combine(outputDir, tmd.TitleVersion.ToString()); titleversion = tmd.TitleVersion; File.WriteAllBytes(Path.Combine(outputDir, tmdFile), tmdFileWithCerts); FireProgress(5); //Download cetk FireDebug(" - Downloading Ticket..."); try { wcNus.DownloadFile(Path.Combine(titleUrl, "cetk"), Path.Combine(outputDir, "cetk")); } catch (Exception ex) { try { if (titleInfo.Ticket == "1") { var cetkUrl = $"{WII_TIK_URL}{titleId.ToLower()}.tik"; wcNus.DownloadFile(cetkUrl, Path.Combine(outputDir, "cetk")); } } catch { continueWithoutTicket = false; if (!continueWithoutTicket || !storeEncrypted) { FireDebug(" + Downloading Ticket Failed..."); throw new Exception("Downloading Ticket Failed:\n" + ex.Message); } if (!(File.Exists(Path.Combine(outputDir, "cetk")))) { storeDecrypted = false; } } } FireProgress(10); // Parse Ticket Ticket tik = new Ticket(); if (File.Exists(Path.Combine(outputDir, "cetk"))) { FireDebug(" + Parsing Ticket..."); tik = Ticket.Load(Path.Combine(outputDir, "cetk")); // DSi ticket? Must make sure to use DSi Key :D if (nusUrl == DSI_NUS_URL) { tik.DSiTicket = true; } } else { FireDebug(" + Ticket Unavailable..."); } string[] encryptedContents = new string[tmd.NumOfContents]; //Download Content for (int i = 0; i < tmd.NumOfContents; i++) { Form1.token.ThrowIfCancellationRequested(); var size = Toolbelt.SizeSuffix(tmd.Contents[i].Size); FireDebug(" - Downloading Content #{0} of {1}... ({2} bytes)", i + 1, tmd.NumOfContents, size); FireProgress(((i + 1) * 60 / tmd.NumOfContents) + 10); var contentPath = Path.Combine(outputDir, tmd.Contents[i].ContentID.ToString("x8")); if (useLocalFiles && Toolbelt.IsValid(tmd.Contents[i], contentPath)) { FireDebug(" + Using Local File, Skipping..."); continue; } try { var downloadUrl = titleUrl + tmd.Contents[i].ContentID.ToString("x8"); var outputdir = Path.Combine(outputDir, tmd.Contents[i].ContentID.ToString("x8")); wcNus.DownloadFile(downloadUrl, outputdir); encryptedContents[i] = tmd.Contents[i].ContentID.ToString("x8"); } catch (Exception ex) { FireDebug(" - Downloading Content #{0} of {1} failed...", i + 1, tmd.NumOfContents); throw new Exception("Downloading Content Failed:\n" + ex.Message); } } //Decrypt Content if (storeDecrypted) { FireDebug(" - Decrypting Content..."); Toolbelt.CDecrypt(this, outputDir); } //Delete not wanted files if (!storeEncrypted) { FireDebug(" - Deleting Encrypted Contents..."); for (int i = 0; i < tmd.Contents.Length; i++) { if (File.Exists(Path.Combine(outputDir, tmd.Contents[i].ContentID.ToString("x8")))) { File.Delete(Path.Combine(outputDir, tmd.Contents[i].ContentID.ToString("x8"))); } } } if (!storeDecrypted && !storeEncrypted) { FireDebug(" - Deleting TMD and Ticket..."); File.Delete(Path.Combine(outputDir, tmdFile)); File.Delete(Path.Combine(outputDir, "cetk")); } FireDebug("Downloading Title {0} v{1} Finished...", titleId, tmd.TitleVersion /*(string.IsNullOrEmpty(titleVersion)) ? "[Latest]" : titleVersion*/); FireProgress(100); }
public static async Task DownloadTitle(string id, string outputDir, string contentType, string version) { #region Setup var workingId = id.ToUpper(); if (contentType == "Patch") { workingId = $"0005000E{workingId.Substring(8)}"; if (Settings.Cemu173Patch) { outputDir = Path.Combine(Settings.BasePatchDir, workingId.Substring(8)); } } if (contentType == "DLC") { workingId = $"0005000C{workingId.Substring(8)}"; if (Settings.Cemu173Patch) { outputDir = Path.Combine(Settings.BasePatchDir, workingId.Substring(8), "aoc"); } } Title title; if ((title = SearchById(workingId)) == null) { throw new Exception("Could not locate the title key"); } var key = title.Key; var name = title.Name; if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(name)) { return; } if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } var str = $"Download {contentType} content to the following location?\n\"{outputDir}\""; var result = MessageBox.Show(str, name, MessageBoxButtons.YesNo); if (result != DialogResult.Yes) { return; } Toolbelt.AppendLog($"Output Directory '{outputDir}'"); #endregion #region TMD Toolbelt.AppendLog(" - Loading TMD..."); TMD tmd = null; var nusUrls = new List <string> { "http://ccs.cdn.wup.shop.nintendo.net/ccs/download/", "http://nus.cdn.shop.wii.com/ccs/download/", "http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/" }; foreach (var nusUrl in nusUrls) { string titleUrl = $"{nusUrl}{workingId}/"; tmd = await LoadTmd(id, key, outputDir, titleUrl, version); if (tmd != null) { break; } } if (tmd == null) { TextLog.MesgLog.WriteError("Could not locate TMD. Is this content request valid?"); return; } #endregion #region Ticket Toolbelt.AppendLog("Generating Ticket..."); var tikData = MapleTicket.Create(SearchById(id)); if (tikData == null) { throw new Exception("Invalid ticket data. Verify Title ID."); } var ticket = Ticket.Load(tikData); ticket.Save(Path.Combine(outputDir, "cetk")); #endregion #region Content Toolbelt.AppendLog($"[+] [{contentType}] {name} v{tmd.TitleVersion}"); Toolbelt.SetStatus($"Output Directory: {outputDir}"); foreach (var nusUrl in nusUrls) { var url = nusUrl + workingId; if (await DownloadContent(tmd, outputDir, url) != 1) { continue; } Toolbelt.AppendLog(string.Empty); Toolbelt.AppendLog(" - Decrypting Content"); Toolbelt.AppendLog(" + This may take a minute. Please wait..."); Toolbelt.SetStatus("Decrypting Content. This may take a minute. Please wait...", Color.OrangeRed); if (await Toolbelt.CDecrypt(outputDir) != 0) { CleanUp(outputDir, tmd); Toolbelt.AppendLog($"Error while decrypting {name}"); return; } CleanUp(outputDir, tmd); break; } #endregion Web.ResetDownloadProgressChanged(); Toolbelt.AppendLog($"[+] [{contentType}] {name} v{tmd.TitleVersion} Finished."); Toolbelt.SetStatus($"[+] [{contentType}] {name} v{tmd.TitleVersion} Finished."); }
private void Start() { world = World.Instance; crackedMesh = crackedBlock.GetComponent <MeshRenderer>(); toolbelt = GetComponent <Toolbelt>(); }
/// <inheritdoc /> public override string ToString() { return(Toolbelt.RIC(Name)); }
//------------------------------------------------------------------------------------------------------------ private int evaluatePostfix(string postfix, int lineNumber) { Stack <string> expression = new Stack <string>(postfix.Split(' ').Reverse()); Stack <int> operands = new Stack <int>(); Stack <int> temps = new Stack <int>(); int firstTemp = _symbolTable.TempLocation; while (expression.Count > 0) { string working = expression.Pop(); if (Int32.TryParse(working, out int intWorking)) { // working string is an integer value operands.Push(_symbolTable.FindConstant(intWorking).Location()); } else if (Toolbelt.IsValidVariable(working)) { char workingChar = Convert.ToChar(working); operands.Push(_symbolTable.FindVariable(Convert.ToInt32(workingChar)).Location()); } else if (Toolbelt.IsOperator(working)) { int left, right; char op = Convert.ToChar(working); if (operands.Count() >= 2) { right = operands.Pop(); left = operands.Pop(); } else if (operands.Count() == 1 && temps.Count >= 1) { right = temps.Pop(); left = operands.Pop(); } else if (temps.Count >= 2) { right = temps.Pop(); left = temps.Pop(); } else { return(-1); } // load 'left' from memory _compiledCode.Add(Word.Build((int)EPC.Code.LOAD, left), _workingLineNumber++); // perform calculation on 'left' switch (op) { case '+': _compiledCode.Add(Word.Build((int)EPC.Code.ADD, right), _workingLineNumber++); break; case '-': _compiledCode.Add(Word.Build((int)EPC.Code.SUBTRACT, right), _workingLineNumber++); break; case '*': _compiledCode.Add(Word.Build((int)EPC.Code.MULTIPLY, right), _workingLineNumber++); break; case '/': _compiledCode.Add(Word.Build((int)EPC.Code.DIVIDE, right), _workingLineNumber++); break; } // store result in 'temp' temps.Push(firstTemp - temps.Count()); if (_symbolTable.HasLocation(temps.Peek()) && _symbolTable.AtLocation(temps.Peek()).IsConst()) { throw new SystemException($"Cannot override constant value at memory[{temps.Peek()}] -on code line {lineNumber}"); } _compiledCode.Add(Word.Build((int)EPC.Code.STORE, temps.Peek()), _workingLineNumber++); } else { return(-1); } } return(temps.Pop()); }