Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Merge branch 'gurrenm3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrenm3 authored and Gurrenm3 committed Feb 17, 2020
2 parents 6e93bc1 + 302a37d commit a944a97
Show file tree
Hide file tree
Showing 36 changed files with 6,337 additions and 212 deletions.
42 changes: 42 additions & 0 deletions BTDToolbox/BTDToolbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,34 @@
<ItemGroup>
<Compile Include="Classes\Announcements.cs" />
<Compile Include="Classes\CrackBTDB_Pass.cs" />
<Compile Include="Classes\ImageProcessing.cs" />
<Compile Include="Classes\ModLoader_Handling.cs" />
<Compile Include="Classes\NKHook_Handling.cs" />
<Compile Include="Classes\QuickType.cs" />
<Compile Include="Classes\Sprite_Class.cs" />
<Compile Include="Classes\Tower_Class.cs" />
<Compile Include="Classes\UpdateHandler.cs" />
<Compile Include="Classes\ConsoleHandler.cs" />
<Compile Include="Classes\JSON_Reader.cs" />
<Compile Include="Classes\WebHandler.cs" />
<Compile Include="Extra Forms\BGForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Extra Forms\BGForm.Designer.cs">
<DependentUpon>BGForm.cs</DependentUpon>
</Compile>
<Compile Include="Extra Forms\CreditViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Extra Forms\CreditViewer.Designer.cs">
<DependentUpon>CreditViewer.cs</DependentUpon>
</Compile>
<Compile Include="Extra Forms\EasyTowerEditor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Extra Forms\EasyTowerEditor.Designer.cs">
<DependentUpon>EasyTowerEditor.cs</DependentUpon>
</Compile>
<Compile Include="Extra Forms\First_Time_Use.cs">
<SubType>Form</SubType>
</Compile>
Expand All @@ -90,6 +106,12 @@
<Compile Include="Extra Forms\FlashReader.Designer.cs">
<DependentUpon>FlashReader.cs</DependentUpon>
</Compile>
<Compile Include="Extra Forms\SpriteVisualizer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Extra Forms\SpriteVisualizer.Designer.cs">
<DependentUpon>SpriteVisualizer.cs</DependentUpon>
</Compile>
<Compile Include="Extra Forms\UpdateChangelog.cs">
<SubType>Form</SubType>
</Compile>
Expand All @@ -102,6 +124,12 @@
<Compile Include="ZipForm.Designer.cs">
<DependentUpon>ZipForm.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Extra Forms\BGForm.resx">
<DependentUpon>BGForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Extra Forms\EasyTowerEditor.resx">
<DependentUpon>EasyTowerEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Extra Forms\First_Time_Use.resx">
<DependentUpon>First_Time_Use.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -111,6 +139,9 @@
<EmbeddedResource Include="Extra Forms\SettingsWindow.resx">
<DependentUpon>SettingsWindow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Extra Forms\SpriteVisualizer.resx">
<DependentUpon>SpriteVisualizer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Extra Forms\UpdateChangelog.resx">
<DependentUpon>UpdateChangelog.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -263,5 +294,16 @@
<None Include="Resources\PossibleBTD5MODIcon.png" />
<None Include="Resources\PossibleBTD5MODIcon.ico" />
</ItemGroup>
<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
10 changes: 10 additions & 0 deletions BTDToolbox/Classes/ConsoleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public static void announcement()
if (validateConsole())
console.GetAnnouncement();
}
public static void ClearConsole()
{
if (validateConsole())
console.Close();

console = new Console();
console.MdiParent = Main.getInstance();
console.Show();
console.BringToFront();
}

public static bool validateConsole()
{
Expand Down
63 changes: 61 additions & 2 deletions BTDToolbox/Classes/GeneralMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,28 @@ public static bool Validate_Backup(string gameName)
{
string backupName = gameName + "_Original.jet";
string backupDir = Environment.CurrentDirectory + "\\Backups";
string backupLocName = gameName + "_Original_LOC.xml";

ConsoleHandler.appendLog("Attempting to validate backup...");
if (Directory.Exists(backupDir))
{
if (File.Exists(backupDir + "\\" + backupName))
{
return true;

}
else
{
return false;
}
if (File.Exists(backupDir + "\\" + backupLocName))
{

}
else
{
return false;
}
return true;
}
else
{
Expand Down Expand Up @@ -274,6 +284,7 @@ public static void CreateBackup(string game)
{
string backupDir = Environment.CurrentDirectory + "\\Backups";
string backupName = game + "_Original.jet";
string backupLocName = game + "_Original_LOC.xml";
string fullBackupPath = backupDir + "\\" + backupName;

if (!Directory.Exists(backupDir))
Expand All @@ -282,10 +293,21 @@ public static void CreateBackup(string game)
Directory.CreateDirectory(backupDir);
}

string gameDir = "";
if(game == "BTD5")
{
gameDir = DeserializeConfig().BTD5_Directory;
}
else
{
gameDir = DeserializeConfig().BTDB_Directory;
}

string steamJetPath = GetJetPath(game);
if (steamJetPath != null)
{
CopyFile(steamJetPath, fullBackupPath);
CopyFile(gameDir + "\\Assets\\Loc\\English.xml", backupDir + "\\" + backupLocName);
CopyFile(steamJetPath, fullBackupPath);
if (File.Exists(fullBackupPath))
ConsoleHandler.appendLog("Backup created!");
else
Expand Down Expand Up @@ -335,6 +357,43 @@ public static void RestoreGame_ToBackup(string game)
ConsoleHandler.appendLog("Unable to restore " + jetName + ". Game directory not detected..");
}
}
public static void RestoreGame_ToBackup_LOC(string game)
{
string gameDir = "";
string backupJetLoc = Environment.CurrentDirectory + "\\Backups\\" + game + "_Original_LOC.xml";
string locName = "English.xml";

if (isGamePathValid(game) == true)
{
if (game == "BTD5")
{
gameDir = DeserializeConfig().BTD5_Directory;
}
else if (game == "BTDB")
{
gameDir = DeserializeConfig().BTDB_Directory;
}
string locPath = gameDir + "\\Assets\\Loc\\" + locName;

if (!File.Exists(backupJetLoc))
{
ConsoleHandler.appendLog("Unable to restore " + locName + ". Backup file doesn't exist..");
}
else
{
ConsoleHandler.appendLog("Replacing " + locName + " with the backup " + locName);
if (File.Exists(locPath))
File.Delete(locPath);

File.Copy(backupJetLoc, locPath);
ConsoleHandler.appendLog(locName + " successfully restored!");
}
}
else
{
ConsoleHandler.appendLog("Unable to restore " + locName + ". Game directory not detected..");
}
}
public static bool IsJSON_Valid(string text)
{
try
Expand Down
140 changes: 140 additions & 0 deletions BTDToolbox/Classes/ImageProcessing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BTDToolbox.Classes
{
class ImageProcessing
{
public string dir = Environment.CurrentDirectory + "\\";
string[] files = new string[4] { Environment.CurrentDirectory + "\\" + "248.png", Environment.CurrentDirectory + "\\" + "249.png", Environment.CurrentDirectory + "\\" + "250.png", Environment.CurrentDirectory + "\\" + "878.png" };

public static System.Drawing.Bitmap CombineBitmap(Bitmap[] files)
{
//read all images into memory
List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
System.Drawing.Bitmap finalImage = null;

try
{
int width = 0;
int height = 0;

foreach (Bitmap image in files)
{
//create a Bitmap from the file and add it to the list
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);

//update the size of the final bitmap
width += bitmap.Width;
height = bitmap.Height > height ? bitmap.Height : height;
image.MakeTransparent();
images.Add(image);
}

//create a bitmap to hold the combined image
finalImage = new System.Drawing.Bitmap(width, height);
finalImage.MakeTransparent();
//get a graphics object from the image so we can draw on it
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
{
//set background color
//g.Clear(System.Drawing.Color.Black);
g.Clear(System.Drawing.Color.Transparent);

//go through each image and draw it on the final image
int offset = 0;
foreach (System.Drawing.Bitmap image in images)
{
g.DrawImage(image,
new System.Drawing.Rectangle(offset, 0, image.Width, image.Height));
//offset += image.Width;
}
}

return finalImage;
}
catch (Exception ex)
{
if (finalImage != null)
finalImage.Dispose();

//return finalImage;
throw ex;
}
finally
{
//clean up memory
foreach (System.Drawing.Bitmap image in images)
{
image.Dispose();
}
}
}


public static System.Drawing.Bitmap CombineBitmap2(string[] files)
{
//read all images into memory
List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
System.Drawing.Bitmap finalImage = null;

try
{
int width = 0;
int height = 0;

foreach (string image in files)
{
//create a Bitmap from the file and add it to the list
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);

//update the size of the final bitmap
width += bitmap.Width;
height = bitmap.Height > height ? bitmap.Height : height;

images.Add(bitmap);
}

//create a bitmap to hold the combined image
finalImage = new System.Drawing.Bitmap(width, height);

//get a graphics object from the image so we can draw on it
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
{
//set background color
g.Clear(System.Drawing.Color.Black);

//go through each image and draw it on the final image
int offset = 0;
foreach (System.Drawing.Bitmap image in images)
{
g.DrawImage(image,
new System.Drawing.Rectangle(offset, 0, image.Width, image.Height));
//offset += image.Width;
}
}

return finalImage;
}
catch (Exception ex)
{
if (finalImage != null)
finalImage.Dispose();

throw ex;
}
finally
{
//clean up memory
foreach (System.Drawing.Bitmap image in images)
{
image.Dispose();
}
}
}
}
}
Loading

0 comments on commit a944a97

Please sign in to comment.