mirror of
https://github.com/kwsch/pkNX.git
synced 2026-04-24 23:06:56 -05:00
Misc clean
no functional change
This commit is contained in:
parent
b3babeeb63
commit
b611df6823
|
|
@ -48,7 +48,7 @@ public static IFileContainer GetContainer(string path)
|
|||
/// <param name="stream">Stream for the binary data</param>
|
||||
public static IFileContainer GetContainer(Stream stream)
|
||||
{
|
||||
BinaryReader br = new BinaryReader(stream);
|
||||
var br = new BinaryReader(stream);
|
||||
var container = GetContainer(br);
|
||||
if (!(container is LargeContainer)) // not kept
|
||||
br.Dispose();
|
||||
|
|
|
|||
|
|
@ -2,8 +2,19 @@
|
|||
|
||||
namespace pkNX.Containers
|
||||
{
|
||||
/// <summary>
|
||||
/// Man in the middle redirection of file r/w requests
|
||||
/// </summary>
|
||||
public static class FileMitm
|
||||
{
|
||||
public static bool Enabled { get; private set; }
|
||||
|
||||
public static void EnableIfSetup() => Enabled = PathOriginal != null;
|
||||
public static void Disable() => Enabled = false;
|
||||
|
||||
private static string PathOriginal;
|
||||
private static string PathRedirect;
|
||||
|
||||
public static byte[] ReadAllBytes(string path)
|
||||
{
|
||||
path = GetRedirectedReadPath(path);
|
||||
|
|
@ -42,13 +53,5 @@ public static void SetRedirect(string original, string dest)
|
|||
PathRedirect = dest;
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
public static bool Enabled { get; private set; }
|
||||
|
||||
public static void EnableIfSetup() => Enabled = PathOriginal != null;
|
||||
public static void Disable() => Enabled = false;
|
||||
|
||||
private static string PathOriginal;
|
||||
private static string PathRedirect;
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ public interface IFileContainer
|
|||
void CancelEdits();
|
||||
}
|
||||
|
||||
public static partial class Extensions
|
||||
public static class FileContainerExtensions
|
||||
{
|
||||
public static string GetFileFormatString(this IFileContainer c) => "D" + Math.Ceiling(Math.Log10(c.Count));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ private void ReadHeader(BinaryReader br)
|
|||
Decompress();
|
||||
}
|
||||
|
||||
public byte[] GetCompressedSegment(BinaryReader br, SegmentHeader h, int sizeCompressed)
|
||||
public static byte[] GetCompressedSegment(BinaryReader br, SegmentHeader h, int sizeCompressed)
|
||||
{
|
||||
br.BaseStream.Position = h.FileOffset;
|
||||
return br.ReadBytes(sizeCompressed);
|
||||
|
|
@ -59,7 +59,7 @@ public byte[] GetDecompressedSegment(BinaryReader br, SegmentHeader h, int sizeC
|
|||
return LZ4.Decode(data, h.DecompressedSize);
|
||||
}
|
||||
|
||||
public byte[] Hash(byte[] data)
|
||||
public static byte[] Hash(byte[] data)
|
||||
{
|
||||
using (var method = SHA256.Create())
|
||||
return method.ComputeHash(data);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ private static byte GetEffectiveness(int rv)
|
|||
0xFF008000
|
||||
};
|
||||
|
||||
public byte[] GetTypeChartImageData(int itemsize, int itemsPerRow, byte[] vals, out int width, out int height)
|
||||
public static byte[] GetTypeChartImageData(int itemsize, int itemsPerRow, byte[] vals, out int width, out int height)
|
||||
{
|
||||
width = itemsize * itemsPerRow;
|
||||
height = itemsize * vals.Length / itemsPerRow;
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ public override void Execute()
|
|||
|
||||
public static void MaximizeAIFlags(VsTrainer tr)
|
||||
{
|
||||
tr.Self.AI |= (int) (TrainerAI.Basic | TrainerAI.Strong | TrainerAI.Expert | TrainerAI.PokeChange);
|
||||
const TrainerAI max = (TrainerAI.Basic | TrainerAI.Strong | TrainerAI.Expert | TrainerAI.PokeChange);
|
||||
tr.Self.AI |= (int)max;
|
||||
}
|
||||
|
||||
private void SetupTeamCount(VsTrainer tr)
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ public override bool CanMegaEvolve
|
|||
public override int Move3 { get => BitConverter.ToUInt16(Data, 0x24); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x24); }
|
||||
public override int Move4 { get => BitConverter.ToUInt16(Data, 0x26); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x26); }
|
||||
|
||||
|
||||
public override ushort[] GetStats(PersonalInfo p)
|
||||
{
|
||||
return CalculateStatsBeluga(p);
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public void SaveEvolution()
|
|||
private static readonly string[] Stats = Enumerable.Range(0, 255 + 1).Select(z => z.ToString()).ToArray();
|
||||
private static readonly string[] None = { "" };
|
||||
|
||||
private string[] GetArgs(EvolutionTypeArgumentType type)
|
||||
private static string[] GetArgs(EvolutionTypeArgumentType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ private void ClickView(object sender, EventArgs e)
|
|||
if (pk.Species != 0)
|
||||
{
|
||||
try { PopulateFields(pk); }
|
||||
catch { }
|
||||
catch (Exception ex) { Console.WriteLine(ex.Message); }
|
||||
// Visual to display what slot is currently loaded.
|
||||
GetSlotColor(slot, Sprites.Properties.Resources.slotView);
|
||||
}
|
||||
|
|
@ -592,7 +592,6 @@ private void B_MaxAI_Click(object sender, EventArgs e)
|
|||
|
||||
public static class FormUtil
|
||||
{
|
||||
// Utility (Shared)
|
||||
internal static void SetForms(int species, ComboBox cb, string[][] AltForms)
|
||||
{
|
||||
cb.Items.Clear();
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public TMList(ushort[] moves, int[] allowed, string[] movenames)
|
|||
private void SetupDGV(string[] list)
|
||||
{
|
||||
dgvTM.Columns.Clear();
|
||||
DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn();
|
||||
var dgvIndex = new DataGridViewTextBoxColumn();
|
||||
{
|
||||
dgvIndex.HeaderText = "Index";
|
||||
dgvIndex.DisplayIndex = 0;
|
||||
|
|
@ -37,7 +37,7 @@ private void SetupDGV(string[] list)
|
|||
dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||||
dgvIndex.SortMode = DataGridViewColumnSortMode.NotSortable;
|
||||
}
|
||||
DataGridViewComboBoxColumn dgvMove = new DataGridViewComboBoxColumn();
|
||||
var dgvMove = new DataGridViewComboBoxColumn();
|
||||
{
|
||||
dgvMove.HeaderText = "Move";
|
||||
dgvMove.DisplayIndex = 1;
|
||||
|
|
|
|||
|
|
@ -36,23 +36,28 @@ public TextEditor(TextContainer c, TextEditorMode mode)
|
|||
private void B_Export_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (TextData.Length <= 0) return;
|
||||
SaveFileDialog Dump = new SaveFileDialog {Filter = "Text File|*.txt"};
|
||||
DialogResult sdr = Dump.ShowDialog();
|
||||
if (sdr != DialogResult.OK) return;
|
||||
bool newline = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Remove newline formatting codes? (\\n,\\r,\\c)", "Removing newline formatting will make it more readable but will prevent any importing of that dump.") == DialogResult.Yes;
|
||||
string path = Dump.FileName;
|
||||
var dump = new SaveFileDialog {Filter = "Text File|*.txt"};
|
||||
if (dump.ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
|
||||
var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNo,
|
||||
"Remove newline formatting codes? (\\n,\\r,\\c)",
|
||||
"Removing newline formatting will make it more readable but will prevent any importing of that dump.");
|
||||
bool newline = result == DialogResult.Yes;
|
||||
string path = dump.FileName;
|
||||
ExportTextFile(path, newline, TextData);
|
||||
}
|
||||
|
||||
private void B_Import_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (TextData.Length <= 0) return;
|
||||
OpenFileDialog Dump = new OpenFileDialog { Filter = "Text File|*.txt" };
|
||||
DialogResult odr = Dump.ShowDialog();
|
||||
if (odr != DialogResult.OK) return;
|
||||
string path = Dump.FileName;
|
||||
var dump = new OpenFileDialog { Filter = "Text File|*.txt" };
|
||||
if (dump.ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
|
||||
if (!ImportTextFiles(path)) return;
|
||||
string path = dump.FileName;
|
||||
if (!ImportTextFiles(path))
|
||||
return;
|
||||
|
||||
// Reload the form with the new data.
|
||||
ChangeEntry(null, null);
|
||||
|
|
@ -124,10 +129,8 @@ private bool ImportTextFiles(string fileName)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// pray that the filename index lines up
|
||||
}
|
||||
// else pray that the filename index lines up
|
||||
|
||||
i += 2; // Skip over the other header line
|
||||
List<string> Lines = new List<string>();
|
||||
while (i < fileText.Length && fileText[i] != "~~~~~~~~~~~~~~~")
|
||||
|
|
@ -147,7 +150,7 @@ private bool ImportTextFiles(string fileName)
|
|||
$"Received: {ctr}, Expected: {TextData.Length}"); return false; }
|
||||
if (!newlineFormatting)
|
||||
{
|
||||
WinFormsUtil.Error("The input Text Files do not have the ingame newline formatting codes (\\n,\\r,\\c).",
|
||||
WinFormsUtil.Error("The input Text Files do not have the in-game newline formatting codes (\\n,\\r,\\c).",
|
||||
"When exporting text, do not remove newline formatting."); return false; }
|
||||
|
||||
// All Text Lines received. Store all back.
|
||||
|
|
@ -279,7 +282,7 @@ private void B_Randomize_Click(object sender, EventArgs e)
|
|||
|
||||
// get if the user wants to randomize current text file or all files
|
||||
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel,
|
||||
$"Yes: Randomize ALL{Environment.NewLine}No: Randomize current textfile{Environment.NewLine}Cancel: Abort");
|
||||
$"Yes: Randomize ALL{Environment.NewLine}No: Randomize current Text File{Environment.NewLine}Cancel: Abort");
|
||||
|
||||
if (dr == DialogResult.Cancel)
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ private void B_RTM_Click(object sender, EventArgs e)
|
|||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
||||
private void LoadChart() => PB_Chart.Image = GetGrid(TypeWidth, TypeCount, Chart);
|
||||
private void LoadChart() => PB_Chart.Image = GetGrid(Chart, TypeWidth, TypeCount);
|
||||
|
||||
// gui logic below
|
||||
|
||||
|
|
@ -110,14 +110,18 @@ public static byte ToggleEffectiveness(byte currentValue, bool increase)
|
|||
return vals[newIndex];
|
||||
}
|
||||
|
||||
public Bitmap GetGrid(int itemsize, int itemsPerRow, byte[] vals)
|
||||
public static Bitmap GetGrid(byte[] vals, int itemsize, int itemsPerRow)
|
||||
{
|
||||
// set up image
|
||||
byte[] bmpData = Editor.GetTypeChartImageData(itemsize, itemsPerRow, vals, out int width, out int height);
|
||||
var bmpData = TypeChartEditor.GetTypeChartImageData(itemsize, itemsPerRow, vals, out int width, out int height);
|
||||
return CreateImage(width, height, bmpData);
|
||||
}
|
||||
|
||||
private static Bitmap CreateImage(int width, int height, byte[] bmpData)
|
||||
{
|
||||
// assemble image
|
||||
Bitmap b = new Bitmap(width, height, PixelFormat.Format32bppArgb);
|
||||
BitmapData bData = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
var b = new Bitmap(width, height, PixelFormat.Format32bppArgb);
|
||||
var bData = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
System.Runtime.InteropServices.Marshal.Copy(bmpData, 0, bData.Scan0, bmpData.Length);
|
||||
b.UnlockBits(bData);
|
||||
return b;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public static class WinFormsUtil
|
|||
/// <returns>The <see cref="DialogResult"/> associated with the dialog.</returns>
|
||||
internal static DialogResult Error(params string[] lines)
|
||||
{
|
||||
System.Media.SystemSounds.Exclamation.Play();
|
||||
System.Media.SystemSounds.Hand.Play();
|
||||
string msg = string.Join(Environment.NewLine + Environment.NewLine, lines);
|
||||
return MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user