private async void LoadItemsClick(object sender, RoutedEventArgs e) { ToggleControls("Load"); items.Clear(); try { // talk to wii u and get mem dump of data var result = await Task.Run(() => LoadItemData()); if (result) { GetNonItemData(); LoadTab(Weapons, 0); LoadTab(Bows, 1); LoadTab(Arrows, 2); LoadTab(Shields, 3); LoadTab(Armor, 4); LoadTab(Materials, 7); LoadTab(Food, 8); LoadTab(KeyItems, 9); Notification.Content = string.Format("Items found: {0}", itemTotal); ToggleControls("DataLoaded"); cbChanged.Clear(); tbChanged.Clear(); ddChanged.Clear(); Save.IsEnabled = HasChanged; DebugGrid.ItemsSource = items; DebugGrid.UpdateLayout(); Debug.UpdateLayout(); } } catch (Exception ex) { LogError(ex, "Load Items"); } }
private async void LoadClick(object sender, RoutedEventArgs e) { this.ToggleControls("Load"); this.items.Clear(); try { // talk to wii u and get mem dump of data var result = await Task.Run(() => this.LoadData()); if (result) { this.GetNonItemData(); this.LoadTab(this.Weapons, 0); this.LoadTab(this.Bows, 1); this.LoadTab(this.Arrows, 2); this.LoadTab(this.Shields, 3); this.LoadTab(this.Armor, 4); this.LoadTab(this.Materials, 7); this.LoadTab(this.Food, 8); this.LoadTab(this.KeyItems, 9); this.Notification.Content = string.Format("Items found: {0}", this.itemsFound); this.ToggleControls("DataLoaded"); this.cbChanged.Clear(); this.tbChanged.Clear(); this.ddChanged.Clear(); this.Save.IsEnabled = this.HasChanged; DebugGrid.ItemsSource = this.items; DebugGrid.UpdateLayout(); Debug.UpdateLayout(); } } catch (Exception ex) { this.LogError(ex, "Load Data"); } }
private bool SaveItemData(TabItem tab) { // Clear old errors ErrorLog.Document.Blocks.Clear(); if (!HasChanged) { // Nothing to update return(false); } #region SaveLoad try { // For these we amend the 0x3FCE7FF0 area which requires save/load if (Equals(tab, Weapons) || Equals(tab, Bows) || Equals(tab, Shields) || Equals(tab, Armor)) { var weaponList = items.Where(x => x.Page == 0).ToList(); var bowList = items.Where(x => x.Page == 1).ToList(); var arrowList = items.Where(x => x.Page == 2).ToList(); var shieldList = items.Where(x => x.Page == 3).ToList(); var armorList = items.Where(x => x.Page == 4 || x.Page == 5 || x.Page == 6).ToList(); var y = 0; if (Equals(tab, Weapons)) { foreach (var item in weaponList) { var foundTextBox = (TextBox)FindName("Value_" + item.ValueAddressHex); if (foundTextBox != null) { var offset = (uint)(SaveItemStart + (y * 0x8)); gecko.WriteUInt(offset, Convert.ToUInt32(foundTextBox.Text)); } y++; } } if (Equals(tab, Bows)) { // jump past weapons before we start y += weaponList.Count; foreach (var item in bowList) { var foundTextBox = (TextBox)FindName("Value_" + item.ValueAddressHex); if (foundTextBox != null) { var offset = (uint)(SaveItemStart + (y * 0x8)); gecko.WriteUInt(offset, Convert.ToUInt32(foundTextBox.Text)); } y++; } } if (Equals(tab, Shields)) { // jump past weapons/bows/arrows before we start y += weaponList.Count + bowList.Count + arrowList.Count; foreach (var item in shieldList) { var foundTextBox = (TextBox)FindName("Value_" + item.ValueAddressHex); if (foundTextBox != null) { var offset = (uint)(SaveItemStart + (y * 0x8)); gecko.WriteUInt(offset, Convert.ToUInt32(foundTextBox.Text)); } y++; } } if (Equals(tab, Armor)) { // jump past weapons/bows/arrows/shields before we start y += weaponList.Count + bowList.Count + arrowList.Count + shieldList.Count; foreach (var item in armorList) { var offset = (uint)(SaveItemStart + (y * 0x8)); var foundTextBox = (TextBox)FindName("Value_" + item.ValueAddressHex); if (foundTextBox != null) { gecko.WriteUInt(offset, Convert.ToUInt32(foundTextBox.Text)); } y++; } } } } catch (Exception ex) { LogError(ex, "Attempting to save data in 0x3FCE7FF0 region."); } #endregion #region Modified try { // Only update what has changed to avoid corruption. foreach (var tb in tbChanged) { if (string.IsNullOrEmpty(tb.Text)) { continue; } // These text boxes have been edited var type = tb.Name.Split('_')[0]; var tag = tb.Tag; if (type == "Id") { var newName = Encoding.Default.GetBytes(tb.Text); var address = uint.Parse(tag.ToString(), NumberStyles.HexNumber); var thisItem = items.Single(i => i.NameStart == address); // clear current name var zeros = new byte[36]; for (var i = 0; i < zeros.Length; i++) { zeros[i] = 0x0; } gecko.WriteBytes(address, zeros); uint x = 0x0; foreach (var b in newName) { gecko.WriteBytes(address + x, new[] { b }); x = x + 0x1; } thisItem.Id = tb.Text; // Name var foundTextBox = (TextBox)FindName("JsonName_" + tag); if (foundTextBox != null) { foundTextBox.Text = GetNameFromId(thisItem.Id, thisItem.PageName); } } if (type == "Value") { var address = uint.Parse(tag.ToString(), NumberStyles.HexNumber); int val; bool parsed = int.TryParse(tb.Text, out val); if (parsed) { gecko.WriteUInt(address, Convert.ToUInt32(val)); } } if (type == "Page") { var address = uint.Parse(tag.ToString(), NumberStyles.HexNumber); int val; bool parsed = int.TryParse(tb.Text, out val); if (parsed && val < 10 && val >= 0) { gecko.WriteUInt(address, Convert.ToUInt32(val)); } } if (type == "Mod") { var address = uint.Parse(tag.ToString(), NumberStyles.HexNumber); uint val; bool parsed = uint.TryParse(tb.Text, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out val); if (parsed) { gecko.WriteUInt(address, val); } } } } catch (Exception ex) { LogError(ex, "Attempting to update changed fields"); } #endregion #region Codes try { // For the 'Codes' tab we mimic JGecko and send cheats to codehandler if (Equals(tab, Codes)) { // Disable codehandler before we modify gecko.WriteUInt(CodeHandlerEnabled, 0x00000000); // clear current codes var array = new byte[4864]; Array.Clear(array, 0, array.Length); gecko.WriteBytes(CodeHandlerStart, array); var codelist = codes.CreateCodeList(); // Write our selected codes to mem stream var ms = new MemoryStream(); foreach (var code in codelist) { var b = BitConverter.GetBytes(code); ms.Write(b.Reverse().ToArray(), 0, 4); } var bytes = ms.ToArray(); gecko.WriteBytes(CodeHandlerStart, bytes); // Re-enable codehandler gecko.WriteUInt(CodeHandlerEnabled, 0x00000001); // Save controller choice if (Controller.SelectedValue.ToString() != Settings.Default.Controller) { Settings.Default.Controller = Controller.SelectedValue.ToString(); Settings.Default.Save(); } } DebugGrid.ItemsSource = items; DebugGrid.UpdateLayout(); Debug.UpdateLayout(); // clear changed after save tbChanged.Clear(); cbChanged.Clear(); ddChanged.Clear(); } catch (Exception ex) { LogError(ex); } #endregion return(true); }