Reattach resources

This commit is contained in:
Kurt
2024-06-02 18:50:22 -05:00
parent f324ea566d
commit 44df39709b
26 changed files with 175 additions and 133 deletions

11
Directory.Build.props Normal file
View File

@@ -0,0 +1,11 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<NeutralLanguage>en</NeutralLanguage>
<Product>pk3DS</Product>
<Company>Project Pokémon</Company>
<Authors>Kaphotics</Authors>
<Copyright>Kaphotics</Copyright>
<SourceRevisionId>$([System.DateTime]::UtcNow.ToString("yyMMddHHmmss"))</SourceRevisionId>
</PropertyGroup>
</Project>

View File

@@ -6,10 +6,11 @@
namespace pk3DS.Core.CTR;
internal static class ETC1
internal static partial class ETC1
{
[DllImport("ETC1Lib.dll", EntryPoint = "ConvertETC1", CallingConvention = CallingConvention.Cdecl)]
public static extern void ConvertETC1(IntPtr dataOut, ref uint dataOutSize, IntPtr dataIn, ushort width, ushort height, bool alpha);
[LibraryImport("ETC1Lib.dll", EntryPoint = "ConvertETC1")]
[UnmanagedCallConv(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])]
public static partial void ConvertETC1(IntPtr dataOut, ref uint dataOutSize, IntPtr dataIn, ushort width, ushort height, [MarshalAs(UnmanagedType.Bool)] bool alpha);
public static void CheckETC1Lib()
{

View File

@@ -73,7 +73,7 @@ public static int PackGARC(string folderPath, string garcPath, int version, int
#endregion
// Set Up the GARC template.
GARCFile garc = new GARCFile
var garc = new GARCFile
{
ContentPadToNearest = 4,
fato =
@@ -131,7 +131,7 @@ public static int PackGARC(string folderPath, string garcPath, int version, int
v = 1;
// Assemble Entry
FileInfo fi = new FileInfo(packOrder[i]);
var fi = new FileInfo(packOrder[i]);
int actualLength = (int)(fi.Length % 4 == 0 ? fi.Length : fi.Length + 4 - (fi.Length % 4));
garc.fatb.Entries[i].SubEntries[0].Start = od;
garc.fatb.Entries[i].SubEntries[0].End = actualLength + garc.fatb.Entries[i].SubEntries[0].Start;
@@ -167,7 +167,7 @@ public static int PackGARC(string folderPath, string garcPath, int version, int
v |= 1 << fileNumber;
// Assemble Entry
FileInfo fi = new FileInfo(s);
var fi = new FileInfo(s);
int actualLength = (int)(fi.Length % 4 == 0 ? fi.Length : fi.Length + 4 - (fi.Length % 4));
garc.fatb.Entries[i].SubEntries[fileNumber].Start = od;
garc.fatb.Entries[i].SubEntries[fileNumber].End = actualLength + garc.fatb.Entries[i].SubEntries[fileNumber].Start;
@@ -192,7 +192,7 @@ public static int PackGARC(string folderPath, string garcPath, int version, int
// Set up the Header Info
using var newGARC = new FileStream(garcPath, FileMode.Create);
using BinaryWriter gw = new BinaryWriter(newGARC);
using var gw = new BinaryWriter(newGARC);
#region Write GARC Headers
// Write GARC
@@ -327,7 +327,7 @@ public static int GarcUnpack(string garcPath, string outPath, bool skipDecompres
FileCountDetermined?.Invoke(null, new FileCountDeterminedEventArgs { Total = fileCount });
using BinaryReader br = new BinaryReader(File.OpenRead(garcPath));
using var br = new BinaryReader(File.OpenRead(garcPath));
// Create Extraction folder if it does not exist.
if (!Directory.Exists(outPath))
Directory.CreateDirectory(outPath);
@@ -365,7 +365,7 @@ public static int GarcUnpack(string garcPath, string outPath, bool skipDecompres
// Write File
string fileOut = Path.Combine(parentFolder, (Entry.IsFolder ? i.ToString("00") : fileName) + "." + ext);
using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut)))
using (var bw = new BinaryWriter(File.OpenWrite(fileOut)))
{
// Write out the data for the file
br.BaseStream.Position = SubEntry.Start + garc.DataOffset;
@@ -412,8 +412,8 @@ private static GARCFile UnpackGARC(byte[] data)
private static GARCFile UnpackGARC(Stream stream)
{
using BinaryReader br = new BinaryReader(stream);
GARCFile garc = new GARCFile
using var br = new BinaryReader(stream);
var garc = new GARCFile
{
Magic = br.ReadChars(4),
HeaderSize = br.ReadUInt32(),
@@ -494,7 +494,7 @@ public static MemGARC PackGARC(byte[][] data, int version, int contentpadnearest
if (contentpadnearest < 0)
contentpadnearest = 4;
// Set Up the GARC template.
GARCFile garc = new GARCFile
var garc = new GARCFile
{
ContentPadToNearest = (uint)contentpadnearest,
fato =
@@ -544,7 +544,7 @@ public static MemGARC PackGARC(byte[][] data, int version, int contentpadnearest
// Set up the Header Info
string tempFile = Path.GetTempFileName();
using (var newGARC = new FileStream(tempFile, FileMode.Create))
using (BinaryWriter gw = new BinaryWriter(newGARC))
using (var gw = new BinaryWriter(newGARC))
{
#region Write GARC Headers
@@ -746,7 +746,7 @@ public GARCEntry(byte[] data)
try
{
using (MemoryStream newMS = new MemoryStream())
using (var newMS = new MemoryStream())
{
LZSS.Decompress(new MemoryStream(data), data.Length, newMS);
Data = newMS.ToArray();
@@ -764,7 +764,7 @@ public byte[] Save()
byte[] data;
try
{
using MemoryStream newMS = new MemoryStream();
using var newMS = new MemoryStream();
LZSS.Compress(new MemoryStream(Data), Data.Length, newMS, original: true);
data = newMS.ToArray();
}

View File

@@ -25,15 +25,15 @@ public BCLIM(string path)
private void ReadBCLIM(Stream ms)
{
PixelData = new byte[ms.Length - FLIMHeader.SIZE];
ms.Read(PixelData, 0, PixelData.Length);
_ = ms.Read(PixelData, 0, PixelData.Length);
var footer = new byte[FLIMHeader.SIZE];
ms.Read(footer, 0, footer.Length);
_ = ms.Read(footer, 0, footer.Length);
Footer = footer.ToStructure<CLIMHeader>();
}
public override uint[] GetPixels()
{
if (Format == (XLIMEncoding)7 && BitConverter.ToUInt16(PixelData, 0) == 2) // Gen6 Palette
if (Format == XLIMEncoding.RGB5A1 && BitConverter.ToUInt16(PixelData, 0) == 2) // Gen6 Palette
return GetPixelsViaPalette();
return base.GetPixels();
}
@@ -72,8 +72,8 @@ private uint[] GetPixelsViaPalette()
// todo: move System.Drawing utilization out, make encoding generic for bflim
public static byte[] IMGToBCLIM(Image img, char fc)
{
Bitmap mBitmap = new Bitmap(img);
MemoryStream ms = new MemoryStream();
var mBitmap = new Bitmap(img);
var ms = new MemoryStream();
int bclimformat = 7; // Init to default (for X)
if (fc == 'X')
@@ -96,7 +96,7 @@ public static byte[] IMGToBCLIM(Image img, char fc)
long datalength = ms.Length;
// Write the CLIM + imag data.
using (BinaryWriter bw = new BinaryWriter(ms))
using (var bw = new BinaryWriter(ms))
{
bw.Write((uint)0x4D494C43); // CLIM
bw.Write((ushort)0xFEFF); // BOM
@@ -156,8 +156,8 @@ public static Image MakeBMP(string path, bool autosave = false, bool crop = true
// BCLIM Data Writing
public static int Write16BitColorPalette(Bitmap img, MemoryStream ms)
{
using Stream pixelcolors = new MemoryStream();
using BinaryWriter bz = new BinaryWriter(pixelcolors);
using var pixelcolors = new MemoryStream();
using var bz = new BinaryWriter(pixelcolors);
// Set up our basis.
bool under16colors = false;
int colors = GetColorCount(img);
@@ -284,8 +284,8 @@ public static byte[] GetPixelData(Bitmap img, int format, bool rectangle = true)
}
}
using MemoryStream mz = new MemoryStream();
using BinaryWriter bz = new BinaryWriter(mz);
using var mz = new MemoryStream();
using var bz = new BinaryWriter(mz);
int p = XLIMUtil.GreatestCommonMultiple(w, 8) / 8;
if (p == 0) p = 1;
for (uint i = 0; i < w * h; i++)

View File

@@ -48,10 +48,10 @@ public static void PackMini(string path, string ident, string fileName, string o
int dataOffset = 4 + 4 + (count * 4);
// Start the data filling.
using (MemoryStream dataout = new MemoryStream())
using (MemoryStream offsetMap = new MemoryStream())
using (BinaryWriter bd = new BinaryWriter(dataout))
using (BinaryWriter bo = new BinaryWriter(offsetMap))
using (var dataout = new MemoryStream())
using (var offsetMap = new MemoryStream())
using (var bd = new BinaryWriter(dataout))
using (var bo = new BinaryWriter(offsetMap))
{
// For each file...
for (int i = 0; i < count; i++)
@@ -96,10 +96,10 @@ public static byte[] PackMini(byte[][] fileData, string ident)
int dataOffset = 4 + 4 + (count * 4);
// Start the data filling.
using MemoryStream dataout = new MemoryStream();
using MemoryStream offsetMap = new MemoryStream();
using BinaryWriter bd = new BinaryWriter(dataout);
using BinaryWriter bo = new BinaryWriter(offsetMap);
using var dataout = new MemoryStream();
using var offsetMap = new MemoryStream();
using var bd = new BinaryWriter(dataout);
using var bo = new BinaryWriter(offsetMap);
// For each file...
for (int i = 0; i < count; i++)
{
@@ -148,7 +148,7 @@ public static void UnpackMini(string path, string ident, string outFolder = null
using (var s = new MemoryStream(File.ReadAllBytes(path)))
using (var br = new BinaryReader(s))
{
string fx = new string(br.ReadChars(2));
var fx = new string(br.ReadChars(2));
if (fx != ident) return;
@@ -164,7 +164,7 @@ public static void UnpackMini(string path, string ident, string outFolder = null
for (int i = 0; i < count; i++)
{
br.BaseStream.Seek(offsets[i], SeekOrigin.Begin);
using MemoryStream dataout = new MemoryStream();
using var dataout = new MemoryStream();
byte[] data = [];
s.CopyTo(dataout, (int)offsets[i]);
int len = (int)offsets[i + 1] - (int)offsets[i];
@@ -217,7 +217,7 @@ public static string GetIsMini(string path)
var fi = new FileInfo(path);
try
{
string fx = new string(new[] { (char)data[0], (char)data[1] });
string fx = new(new[] { (char)data[0], (char)data[1] });
ushort count = BitConverter.ToUInt16(data, 2);
uint[] offsets = new uint[count + 1];

View File

@@ -241,7 +241,7 @@ private GARC.LazyGARC GetlzGARC(string file)
public TextVariableCode GetVariableCode(string name) { return Variables?.FirstOrDefault(v => v.Name == name); }
public TextVariableCode GetVariableName(int value) { return Variables?.FirstOrDefault(v => v.Code == value); }
private TextReference GetGameText(TextName name) { return GameText?.FirstOrDefault(f => f.Name == name); }
private TextReference GetGameText(TextName name) { return GameText.FirstOrDefault(f => f.Name == name); }
public TextData GetTextData(TextName file) => new(GetText(file));
public string[] GetText(TextName file)

View File

@@ -19,7 +19,7 @@ namespace pk3DS.Core.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Resources {
@@ -160,16 +160,6 @@ public class Resources {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] XY {
get {
object obj = ResourceManager.GetObject("XY", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
@@ -189,5 +179,15 @@ public class Resources {
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] XY {
get {
object obj = ResourceManager.GetObject("XY", resourceCulture);
return ((byte[])(obj));
}
}
}
}

View File

@@ -142,7 +142,7 @@ public byte[][] LineData
public string[] Lines
{
get => LineData.Select(z => GetLineString(Config, z)).ToArray();
get => Array.ConvertAll(LineData, z => GetLineString(Config, z));
set => LineData = ConvertLinesToData(value);
}
@@ -186,8 +186,8 @@ private byte[] GetLineData(GameConfig config, string line)
if (line == null)
return new byte[2];
MemoryStream ms = new MemoryStream();
using BinaryWriter bw = new BinaryWriter(ms);
var ms = new MemoryStream();
using var bw = new BinaryWriter(ms);
int i = 0;
while (i < line.Length)
{
@@ -200,7 +200,7 @@ private byte[] GetLineData(GameConfig config, string line)
case '[':
{
// grab the string
int bracket = line.IndexOf("]", i, StringComparison.Ordinal);
int bracket = line.IndexOf(']', i);
if (bracket < 0)
throw new ArgumentException("Variable text is not capped properly: " + line);
string varText = line[i..bracket];
@@ -255,20 +255,17 @@ private ushort TryUnmapChar(ushort val)
private string GetLineString(GameConfig config, byte[] data)
{
if (data == null)
return null;
var s = new StringBuilder();
int i = 0;
while (i < data.Length)
{
ushort val = BitConverter.ToUInt16(data, i);
if (val == KEY_TERMINATOR) break;
if (val == KEY_TERMINATOR)
break;
i += 2;
switch (val)
{
case KEY_TERMINATOR: return s.ToString();
case KEY_VARIABLE: s.Append(GetVariableString(config, data, ref i)); break;
case '\n': s.Append(@"\n"); break;
case '\\': s.Append(@"\\"); break;
@@ -318,7 +315,7 @@ private static string GetVariableString(GameConfig config, byte[] data, ref int
return s.ToString();
}
private static IEnumerable<ushort> GetEscapeValues(char esc)
private static List<ushort> GetEscapeValues(char esc)
{
var vals = new List<ushort>();
switch (esc)
@@ -332,7 +329,7 @@ private static IEnumerable<ushort> GetEscapeValues(char esc)
}
}
private IEnumerable<ushort> GetVariableValues(GameConfig config, string variable)
private static List<ushort> GetVariableValues(GameConfig config, string variable)
{
string[] split = variable.Split(' ');
if (split.Length < 2)
@@ -359,7 +356,7 @@ private IEnumerable<ushort> GetVariableValues(GameConfig config, string variable
return vals;
}
private IEnumerable<ushort> GetVariableParameters(GameConfig config, string text)
private static List<ushort> GetVariableParameters(GameConfig config, string text)
{
var vals = new List<ushort>();
int bracket = text.IndexOf('(');
@@ -405,7 +402,7 @@ private static string GetVariableString(GameConfig config, ushort variable)
public static string[] GetStrings(GameConfig config, byte[] data, bool remapChars = false)
{
TextFile t;
try { t = new TextFile(config, data, remapChars); } catch { return null; }
try { t = new TextFile(config, data, remapChars); } catch { return []; }
return t.Lines;
}

View File

@@ -10,9 +10,7 @@ public static class Util
public static FileInfo GetNewestFile(DirectoryInfo directory)
{
return directory.GetFiles()
.Union(directory.GetDirectories().Select(GetNewestFile))
.OrderByDescending(f => f?.LastWriteTime ?? DateTime.MinValue)
.FirstOrDefault();
.Union(directory.GetDirectories().Select(GetNewestFile)).MaxBy(f => f?.LastWriteTime ?? DateTime.MinValue);
}
public static string NormalizePath(string path)
@@ -60,9 +58,7 @@ public static void Shuffle<T>(T[] array)
for (int i = 0; i < n; i++)
{
int r = i + (int)(Rand.NextDouble() * (n - i));
T t = array[r];
array[r] = array[i];
array[i] = t;
(array[r], array[i]) = (array[i], array[r]);
}
}
@@ -149,7 +145,7 @@ public static string GuessExtension(BinaryReader br, string defaultExt, bool byp
public static string GuessExtension(string path, bool bypass)
{
using BinaryReader br = new BinaryReader(File.OpenRead(path));
using var br = new BinaryReader(File.OpenRead(path));
return GuessExtension(br, "bin", bypass);
}

View File

@@ -2,7 +2,19 @@
<PropertyGroup>
<UseWindowsForms>true</UseWindowsForms>
<TargetFrameworks>net8.0-windows</TargetFrameworks>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@@ -216,6 +216,9 @@ private void OpenExeFSCombined(string path, FileInfo fi)
{
if (fi.Length % 0x200 != 0)
return;
var dir = Path.GetDirectoryName(path);
if (dir is null)
return;
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Detected ExeFS.bin.", "Unpack?");
if (prompt != DialogResult.Yes)
@@ -224,7 +227,7 @@ private void OpenExeFSCombined(string path, FileInfo fi)
new Thread(() =>
{
Interlocked.Increment(ref threads);
ExeFS.UnpackExeFS(path, Path.GetDirectoryName(path));
ExeFS.UnpackExeFS(path, dir);
Interlocked.Decrement(ref threads);
WinFormsUtil.Alert("Unpacked!");
}).Start();
@@ -317,8 +320,12 @@ private void OpenDirectory(string path)
UpdateStatus("Data found! Loading persistent data for subforms...", false);
try
{
Config.Initialize(RomFSPath, ExeFSPath, Language);
Config.BackupFiles();
if (Config is not null)
{
if (ExeFSPath is not null)
Config.Initialize(RomFSPath, ExeFSPath, Language);
Config.BackupFiles();
}
}
catch (Exception ex)
{
@@ -493,7 +500,11 @@ private static GameConfig CheckGameType(string[] files)
{
if (files.Length > 1000)
return null;
string[] fileArr = Directory.GetFiles(Path.Combine(Directory.GetParent(files[0]).FullName, "a"), "*", SearchOption.AllDirectories);
var parent = Directory.GetParent(files[0]);
if (parent is null)
return null;
string[] fileArr = Directory.GetFiles(Path.Combine(parent.FullName, "a"), "*", SearchOption.AllDirectories);
int fileCount = fileArr.Count(file => Path.GetFileName(file).Length == 1);
return new GameConfig(fileCount);
}
@@ -588,12 +599,14 @@ private bool ThreadActive()
private void TabMain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
if (e.Data?.GetDataPresent(DataFormats.FileDrop) is true)
e.Effect = DragDropEffects.Copy;
}
private void TabMain_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (e.Data?.GetData(DataFormats.FileDrop) is not string[] { Length: not 0 } files)
return;
string path = files[0]; // open first D&D
OpenQuick(path);
}

View File

@@ -116,7 +116,7 @@ private void B_PatchCIA_Click(object sender, EventArgs e)
private string[] GetGARCs()
{
StringCollection sc = new StringCollection();
var sc = new StringCollection();
foreach (int indexChecked in CHKLB_GARCs.CheckedIndices)
sc.Add(CHKLB_GARCs.Items[indexChecked].ToString());

View File

@@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace pk3DS.Properties {
namespace pk3DS.WinForms.Properties {
using System;
@@ -19,7 +19,7 @@ namespace pk3DS.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
@@ -39,7 +39,7 @@ internal class Resources {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("pk3DS.Properties.Resources", typeof(Resources).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("pk3DS.WinForms.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;

View File

@@ -8,11 +8,11 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace pk3DS.Properties {
namespace pk3DS.WinForms.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View File

@@ -6,10 +6,10 @@
using System.Media;
using System.Text;
using System.Windows.Forms;
using pk3DS.Properties;
using pk3DS.Core.Structures;
using pk3DS.Core;
using pk3DS.Core.Randomizers;
using pk3DS.WinForms.Properties;
namespace pk3DS.WinForms;
@@ -176,7 +176,7 @@ public void CalcStats()
byte[] movedata = files[i];
if (movedata.Length <= 2) continue;
int movecount = BitConverter.ToUInt16(movedata, 0);
if (movecount == 65535 || movecount < 0)
if (movecount == 65535)
continue;
species++;
movectr += movecount; // Average Moves

View File

@@ -5,10 +5,10 @@
using System.Media;
using System.Text;
using System.Windows.Forms;
using pk3DS.Properties;
using pk3DS.Core;
using pk3DS.Core.Randomizers;
using pk3DS.Core.Structures;
using pk3DS.WinForms.Properties;
namespace pk3DS.WinForms;

View File

@@ -6,10 +6,10 @@
using System.Media;
using System.Text;
using System.Windows.Forms;
using pk3DS.Properties;
using pk3DS.Core.Structures;
using pk3DS.Core;
using pk3DS.Core.Randomizers;
using pk3DS.WinForms.Properties;
namespace pk3DS.WinForms;

View File

@@ -183,7 +183,7 @@ private void ByteLimiter(object sender, EventArgs e)
{
if (sender is not MaskedTextBox mtb)
return;
int.TryParse(mtb.Text, out int val);
_ = int.TryParse(mtb.Text, out int val);
if (Array.IndexOf(byte_boxes, mtb) > -1 && val > 255)
mtb.Text = "255";
else if (Array.IndexOf(ev_boxes, mtb) > -1 && val > 3)
@@ -271,8 +271,8 @@ private void ReadEntry()
int f = formVal[entry];
if (entry <= Main.Config.MaxSpeciesID)
s = entry;
Bitmap rawImg = WinFormsUtil.GetSprite(s, f, 0, 0, Main.Config);
Bitmap bigImg = new Bitmap(rawImg.Width * 2, rawImg.Height * 2);
var rawImg = WinFormsUtil.GetSprite(s, f, 0, 0, Main.Config);
var bigImg = new Bitmap(rawImg.Width * 2, rawImg.Height * 2);
for (int x = 0; x < rawImg.Width; x++)
{
for (int y = 0; y < rawImg.Height; y++)
@@ -321,8 +321,8 @@ private void SavePersonal()
pkm.Color = (byte)(Convert.ToByte(CB_Color.SelectedIndex) | (Convert.ToByte(TB_RawColor.Text) & 0xF0));
pkm.BaseEXP = Convert.ToUInt16(TB_BaseExp.Text);
decimal.TryParse(TB_Height.Text, out var h);
decimal.TryParse(TB_Weight.Text, out var w);
_ = decimal.TryParse(TB_Height.Text, out var h);
_ = decimal.TryParse(TB_Weight.Text, out var w);
pkm.Height = (int)(h * 100);
pkm.Weight = (int)(w * 10);
@@ -447,7 +447,7 @@ private void B_Dump_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Dump all Personal Entries to Text File?"))
return;
SaveFileDialog sfd = new SaveFileDialog { FileName = "Personal Entries.txt", Filter = "Text File|*.txt" };
var sfd = new SaveFileDialog { FileName = "Personal Entries.txt", Filter = "Text File|*.txt" };
SystemSounds.Asterisk.Play();
if (sfd.ShowDialog() != DialogResult.OK)
return;

View File

@@ -217,7 +217,7 @@ private void B_Dump_Click(object sender, EventArgs e)
string tdata = GetTRSummary();
toret += tdata;
}
SaveFileDialog sfd = new SaveFileDialog { FileName = "Battles.txt", Filter = "Text File|*.txt" };
var sfd = new SaveFileDialog { FileName = "Battles.txt", Filter = "Text File|*.txt" };
SystemSounds.Asterisk.Play();
if (sfd.ShowDialog() == DialogResult.OK)
@@ -465,7 +465,7 @@ private void Setup()
public static int[] rFinalEvo;
private string[] rImportant;
private readonly List<string> Tags = [];
private readonly Dictionary<string, int> TagTypes = new();
private readonly Dictionary<string, int> TagTypes = [];
public static int[] sL; // Random Species List
public static decimal rGiftPercent, rLevelMultiplier, rMinPKM, rMaxPKM, rForceFullyEvolvedLevel, rForceHighPowerLevel;
@@ -514,7 +514,7 @@ private void Randomize()
GymE4Types.AddRange(Enumerable.Range(0, types.Length).ToArray());
}
foreach (int t1 in rEnsureMEvo.Where(t1 => rTags[t1].Length != 0 && !TagTypes.Keys.Contains(rTags[t1])))
foreach (int t1 in rEnsureMEvo.Where(t1 => rTags[t1].Length != 0 && !TagTypes.ContainsKey(rTags[t1])))
{
int t;
if (rTags[t1].Contains("GYM") || rTags[t1].Contains("ELITE") || rTags[t1].Contains("CHAMPION"))
@@ -531,7 +531,7 @@ private void Randomize()
}
foreach (string t1 in Tags)
{
if (!TagTypes.Keys.Contains(t1) && t1.Length != 0)
if (!TagTypes.ContainsKey(t1) && t1.Length != 0)
{
int t;
if (t1.Contains("GYM") || t1.Contains("ELITE") || t1.Contains("CHAMPION"))

View File

@@ -6,10 +6,10 @@
using System.Media;
using System.Text;
using System.Windows.Forms;
using pk3DS.Properties;
using pk3DS.Core.Structures;
using pk3DS.Core;
using pk3DS.Core.Randomizers;
using pk3DS.WinForms.Properties;
namespace pk3DS.WinForms;

View File

@@ -6,12 +6,10 @@
using System.Media;
using System.Text;
using System.Windows.Forms;
using pk3DS.Properties;
using pk3DS.Core.Structures;
using pk3DS.Core;
using pk3DS.Core.Randomizers;
using pk3DS.WinForms.Properties;
namespace pk3DS.WinForms;
@@ -162,7 +160,8 @@ private void B_RandAll_Click(object sender, EventArgs e)
private void B_Metronome_Click(object sender, EventArgs e)
{
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Play using Metronome Mode?", "This will modify learnsets to only have Metronome.") != DialogResult.Yes) return;
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Play using Metronome Mode?", "This will modify learnsets to only have Metronome.") != DialogResult.Yes)
return;
// clear all data, then only assign Metronome at Lv1
for (int i = 0; i < CB_Species.Items.Count; i++)

View File

@@ -28,10 +28,12 @@ public TextEditor(string[][] infiles, string mode)
// IO
private void B_Export_Click(object sender, EventArgs e)
{
if (files.Length == 0) return;
SaveFileDialog Dump = new SaveFileDialog { Filter = "Text File|*.txt" };
DialogResult sdr = Dump.ShowDialog();
if (sdr != DialogResult.OK) return;
if (files.Length == 0)
return;
var Dump = new SaveFileDialog { Filter = "Text File|*.txt" };
var 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;
ExportTextFile(path, newline, files);
@@ -39,13 +41,16 @@ private void B_Export_Click(object sender, EventArgs e)
private void B_Import_Click(object sender, EventArgs e)
{
if (files.Length == 0) return;
OpenFileDialog Dump = new OpenFileDialog { Filter = "Text File|*.txt" };
DialogResult odr = Dump.ShowDialog();
if (odr != DialogResult.OK) return;
if (files.Length == 0)
return;
var Dump = new OpenFileDialog { Filter = "Text File|*.txt" };
var odr = Dump.ShowDialog();
if (odr != DialogResult.OK)
return;
string path = Dump.FileName;
if (!ImportTextFile(path)) return;
if (!ImportTextFile(path))
return;
// Reload the form with the new data.
ChangeEntry(null, null);
@@ -174,7 +179,7 @@ private void SetStringsDataGridView(string[] textArray)
};
dgvLine.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
DataGridViewTextBoxColumn dgvText = new DataGridViewTextBoxColumn
var dgvText = new DataGridViewTextBoxColumn
{
HeaderText = "Text",
DisplayIndex = 1,

View File

@@ -106,8 +106,8 @@ internal static uint[] QuickDecompress(byte[] data, int count)
// Compression
internal static byte[] CompressScript(byte[] data)
{
if (data == null || data.Length % 4 != 0) // Bad Input
return null;
if (data.Length % 4 != 0) // Bad Input
throw new ArgumentException(nameof(data));
using var mn = new MemoryStream();
using var bw = new BinaryWriter(mn);
int pos = 0;
@@ -622,7 +622,7 @@ internal static string[] ParseScript(uint[] cmd, int sanity = -1)
}
if (sanity >= 0 && sanity != sanityMode)
throw new ArgumentException();
throw new ArgumentException(null, nameof(sanity));
return [.. parse];
}

View File

@@ -7,7 +7,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using pk3DS.Properties;
using pk3DS.WinForms.Properties;
namespace pk3DS.WinForms;

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="pk3DS.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>
<pk3DS.Properties.Settings>
<setting name="Language" serializeAs="String">
<value>2</value>
</setting>
<setting name="GamePath" serializeAs="String">
<value/>
</setting>
</pk3DS.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/></startup></configuration>

View File

@@ -4,7 +4,6 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
@@ -15,4 +14,31 @@
<Content Include="Resources\*" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>