2020-03-13 22:35:20 +00:00
using GameBaseClassLibrary ;
using System ;
2020-03-01 15:07:22 +00:00
using System.Collections.Generic ;
2020-03-13 22:35:20 +00:00
using System.Configuration ;
using System.IO ;
2020-04-06 19:30:31 +00:00
using System.IO.Compression ;
2020-03-01 15:07:22 +00:00
using System.Linq ;
2020-04-03 23:20:15 +00:00
using System.Net ;
2020-04-06 19:30:31 +00:00
using System.Runtime.Serialization ;
using System.Runtime.Serialization.Formatters.Binary ;
2020-03-01 15:07:22 +00:00
using System.Text ;
using System.Threading.Tasks ;
2020-04-06 19:30:31 +00:00
using System.Windows.Controls ;
2020-04-02 19:45:24 +00:00
using System.Windows.Forms ;
2020-03-13 22:35:20 +00:00
using UWUVCI_AIO_WPF.Classes ;
using UWUVCI_AIO_WPF.Properties ;
2020-04-04 22:16:55 +00:00
using UWUVCI_AIO_WPF.UI ;
2020-04-06 17:50:12 +00:00
using UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Bases ;
2020-04-06 19:30:31 +00:00
using UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Configurations ;
2020-03-13 22:35:20 +00:00
using UWUVCI_AIO_WPF.UI.Windows ;
2020-04-07 21:21:38 +00:00
using AutoUpdaterDotNET ;
2020-04-17 16:02:45 +00:00
using System.Threading ;
2020-04-18 03:31:36 +00:00
using System.Windows.Threading ;
using System.Diagnostics ;
2020-04-20 09:31:26 +00:00
using Microsoft.WindowsAPICodePack.Dialogs ;
2020-04-21 19:52:52 +00:00
using System.Text.RegularExpressions ;
2020-04-25 06:40:38 +00:00
using MaterialDesignThemes.Wpf ;
2020-04-30 15:01:41 +00:00
using NAudio.Wave ;
using System.Timers ;
using NAudio.Utils ;
2020-06-05 11:02:11 +00:00
using System.Runtime.InteropServices.WindowsRuntime ;
2020-06-13 07:27:42 +00:00
using System.Security.Cryptography ;
2020-06-15 18:54:37 +00:00
using System.Drawing ;
2020-03-01 15:07:22 +00:00
namespace UWUVCI_AIO_WPF
{
2020-04-17 01:28:14 +00:00
public class MainViewModel : BaseModel
2020-03-01 15:07:22 +00:00
{
2020-06-24 15:54:51 +00:00
public bool saveworkaround = false ;
2020-06-22 20:19:39 +00:00
private bool Injected2 = false ;
public bool injected2
{
2022-07-14 18:17:37 +00:00
get { return Injected2 ; }
2020-06-22 20:19:39 +00:00
set
2022-07-14 18:17:37 +00:00
{
2020-06-22 20:19:39 +00:00
Injected2 = value ;
OnPropertyChanged ( ) ;
}
2022-07-14 18:17:37 +00:00
2020-06-22 20:19:39 +00:00
}
2020-05-22 09:36:31 +00:00
public string prodcode = "" ;
2020-03-01 15:07:22 +00:00
//public GameConfig GameConfiguration { get; set; }
2020-03-01 16:15:54 +00:00
private GameConfig gameConfiguration = new GameConfig ( ) ;
2020-03-01 15:07:22 +00:00
2020-04-28 23:40:54 +00:00
public bool addi = false ;
2020-03-01 15:07:22 +00:00
public GameConfig GameConfiguration
{
get { return gameConfiguration ; }
set
{
gameConfiguration = value ;
OnPropertyChanged ( ) ;
}
}
2020-03-01 16:15:54 +00:00
private string romPath ;
2020-06-13 19:52:39 +00:00
public bool regionfrii = false ;
public bool regionfriius = false ;
public bool regionfriijp = false ;
2020-03-01 16:15:54 +00:00
public string RomPath
{
get { return romPath ; }
2022-07-14 18:17:37 +00:00
set
{
romPath = value ;
2020-03-01 16:15:54 +00:00
OnPropertyChanged ( ) ;
}
}
2020-03-01 15:07:22 +00:00
2020-05-30 22:35:01 +00:00
public bool jppatch = false ;
2020-06-11 08:12:03 +00:00
public bool pixelperfect = false ;
2020-03-13 22:35:20 +00:00
private GameBases gbTemp ;
public GameBases GbTemp
{
get { return gbTemp ; }
set { gbTemp = value ; }
}
2020-04-02 23:45:12 +00:00
private string selectedBaseAsString ;
public string SelectedBaseAsString
{
get { return selectedBaseAsString ; }
set { selectedBaseAsString = value ; }
}
2020-03-13 22:35:20 +00:00
private List < string > lGameBasesString = new List < string > ( ) ;
public List < string > LGameBasesString
{
get { return lGameBasesString ; }
set
{
lGameBasesString = value ;
OnPropertyChanged ( ) ;
}
}
private bool pathsSet { get ; set ; } = false ;
2020-03-01 15:52:59 +00:00
public bool PathsSet
{
get { return pathsSet ; }
set
{
pathsSet = value ;
OnPropertyChanged ( ) ;
}
}
2020-03-01 15:07:22 +00:00
2020-04-02 19:45:24 +00:00
private string baseStore ;
public string BaseStore
{
get { return baseStore ; }
2022-07-14 18:17:37 +00:00
set
{
baseStore = value ;
2020-04-02 19:45:24 +00:00
OnPropertyChanged ( ) ;
}
}
private string injectStore ;
public string InjectStore
{
get { return injectStore ; }
2022-07-14 18:17:37 +00:00
set
{
injectStore = value ;
2020-04-02 19:45:24 +00:00
OnPropertyChanged ( ) ;
}
}
2020-04-04 22:16:55 +00:00
private bool injected = false ;
public bool Injected
{
get { return injected ; }
2022-07-14 18:17:37 +00:00
set
{
injected = value ;
2020-04-04 22:16:55 +00:00
OnPropertyChanged ( ) ;
}
}
2020-04-06 19:30:31 +00:00
private Page thing ;
public Page Thing
{
get { return thing ; }
set { thing = value ; }
}
2020-04-02 23:45:12 +00:00
public int OldIndex { get ; set ; }
2020-04-02 19:45:24 +00:00
2020-04-04 00:41:56 +00:00
public bool RomSet { get ; set ; }
2020-04-02 19:45:24 +00:00
2020-03-13 22:35:20 +00:00
private List < GameBases > lBases = new List < GameBases > ( ) ;
public List < GameBases > LBases
{
get { return lBases ; }
2022-07-14 18:17:37 +00:00
set
{
lBases = value ;
2020-03-13 22:35:20 +00:00
OnPropertyChanged ( ) ;
}
}
2020-04-16 18:52:26 +00:00
private int progress = 0 ;
public int Progress
{
2022-07-14 18:17:37 +00:00
get { return progress ; }
set
{
progress = value ;
2020-04-16 18:52:26 +00:00
OnPropertyChanged ( ) ;
}
}
2020-04-28 23:40:54 +00:00
public BaseContainerFrame bcf = null ;
2020-03-13 22:35:20 +00:00
#region TKLIST
private List < GameBases > lNDS = new List < GameBases > ( ) ;
public List < GameBases > LNDS
{
get { return lNDS ; }
set { lNDS = value ; OnPropertyChanged ( ) ; }
}
private List < GameBases > lN64 = new List < GameBases > ( ) ;
public List < GameBases > LN64
{
get { return lN64 ; }
set { lN64 = value ; OnPropertyChanged ( ) ; }
}
private List < GameBases > lNES = new List < GameBases > ( ) ;
2020-04-06 19:30:31 +00:00
2020-03-13 22:35:20 +00:00
public List < GameBases > LNES
{
get { return lNES ; }
set { lNES = value ; OnPropertyChanged ( ) ; }
}
private List < GameBases > lGBA = new List < GameBases > ( ) ;
public List < GameBases > LGBA
{
get { return lGBA ; }
set { lGBA = value ; OnPropertyChanged ( ) ; }
}
private List < GameBases > lSNES = new List < GameBases > ( ) ;
2020-04-02 23:45:12 +00:00
2020-03-13 22:35:20 +00:00
public List < GameBases > LSNES
{
get { return lSNES ; }
set { lSNES = value ; OnPropertyChanged ( ) ; }
}
2020-04-06 13:50:54 +00:00
private List < GameBases > lTG16 = new List < GameBases > ( ) ;
2020-05-22 09:36:31 +00:00
public string ReadCkeyFromOtp ( )
2022-07-14 18:17:37 +00:00
{
string ret = "" ;
2020-05-22 09:36:31 +00:00
using ( var dialog = new System . Windows . Forms . OpenFileDialog ( ) )
{
dialog . Filter = "OTP.bin | otp.bin" ;
DialogResult res = dialog . ShowDialog ( ) ;
if ( res = = DialogResult . OK )
{
var filepath = dialog . FileName ;
using ( var fs = new FileStream ( filepath ,
FileMode . Open ,
FileAccess . Read ) )
{
byte [ ] test = new byte [ 16 ] ;
fs . Seek ( 0xE0 , SeekOrigin . Begin ) ;
2020-04-06 13:50:54 +00:00
2020-05-22 09:36:31 +00:00
fs . Read ( test , 0 , 16 ) ;
fs . Close ( ) ;
2022-07-14 18:17:37 +00:00
foreach ( var b in test )
2020-05-22 09:36:31 +00:00
{
ret + = string . Format ( "{0:X2}" , b ) ;
}
}
}
}
2022-07-14 18:17:37 +00:00
return ret ;
}
2020-04-06 13:50:54 +00:00
public List < GameBases > LTG16
{
get { return lTG16 ; }
set { lTG16 = value ; OnPropertyChanged ( ) ; }
}
2020-04-07 01:09:05 +00:00
private List < GameBases > lMSX = new List < GameBases > ( ) ;
public List < GameBases > LMSX
{
get { return lMSX ; }
set { lMSX = value ; OnPropertyChanged ( ) ; }
}
2020-06-01 23:36:49 +00:00
public void RemoveCreatedIMG ( )
{
if ( Directory . Exists ( @"bin\createdIMG" ) )
{
Directory . Delete ( @"bin\createdIMG" , true ) ;
}
}
2020-04-16 04:41:25 +00:00
private List < GameBases > lWii = new List < GameBases > ( ) ;
2020-04-07 01:09:05 +00:00
2020-05-06 21:53:52 +00:00
public void IsIsoNkit ( )
{
using ( var fs = new FileStream ( RomPath ,
FileMode . Open ,
2020-07-14 19:03:30 +00:00
FileAccess . Read ) )
2020-05-06 21:53:52 +00:00
{
byte [ ] procode = new byte [ 4 ] ;
fs . Seek ( 0x200 , SeekOrigin . Begin ) ;
fs . Read ( procode , 0 , 4 ) ;
var s = ByteArrayToString ( procode ) ;
2022-07-14 18:17:37 +00:00
2020-05-06 21:53:52 +00:00
fs . Close ( ) ;
if ( s . ToLower ( ) . Contains ( "nkit" ) )
{
NKITFLAG = true ;
2022-07-14 18:17:37 +00:00
2020-05-06 21:53:52 +00:00
}
else
{
NKITFLAG = false ;
}
}
}
2020-06-01 23:36:49 +00:00
public bool CheckTime ( DateTime creationTime )
{
DateTime curr = DateTime . Now ;
2022-07-14 18:17:37 +00:00
if ( creationTime . Hour = = curr . Hour | | creationTime . Hour = = curr . Hour - 1 )
2020-06-01 23:36:49 +00:00
{
2022-07-14 18:17:37 +00:00
if ( creationTime . Minute = = curr . Minute | | creationTime . Minute = = curr . Minute - 2 )
2020-06-01 23:36:49 +00:00
{
return true ;
}
else
{
return false ;
}
}
else
{
return false ;
}
}
2020-04-16 04:41:25 +00:00
public List < GameBases > LWII
{
get { return lWii ; }
set { lWii = value ; OnPropertyChanged ( ) ; }
}
2020-04-07 01:09:05 +00:00
2020-03-31 23:48:50 +00:00
private List < GameBases > ltemp = new List < GameBases > ( ) ;
public List < GameBases > Ltemp
{
get { return ltemp ; }
set { ltemp = value ; OnPropertyChanged ( ) ; }
}
2020-03-13 22:35:20 +00:00
#endregion
2020-04-02 23:45:12 +00:00
public bool BaseDownloaded { get ; set ; } = false ;
private bool canInject = false ;
public bool CanInject
{
get { return canInject ; }
2022-07-14 18:17:37 +00:00
set
{
canInject = value ;
2020-04-02 23:45:12 +00:00
OnPropertyChanged ( ) ;
}
}
2020-04-06 19:30:31 +00:00
private string cBasePath ;
public string CBasePath
{
get { return cBasePath ; }
2022-07-14 18:17:37 +00:00
set
{
cBasePath = value ;
2020-04-06 19:30:31 +00:00
OnPropertyChanged ( ) ;
}
}
2020-04-16 04:41:25 +00:00
public int Index = - 1 ;
public bool LR = false ;
public bool GC = false ;
2020-04-16 18:52:26 +00:00
public bool debug = false ;
public string doing = "" ;
2020-04-17 01:28:14 +00:00
public bool Patch = false ;
public bool toPal = false ;
2020-04-16 18:52:26 +00:00
private string Msg ;
2022-07-14 18:17:37 +00:00
2020-04-19 17:36:03 +00:00
private string Gc2rom = "" ;
public string gc2rom
{
get { return Gc2rom ; }
2022-07-14 18:17:37 +00:00
set
{
Gc2rom = value ;
2020-04-19 17:36:03 +00:00
OnPropertyChanged ( ) ;
}
}
2020-05-24 20:59:09 +00:00
public string foldername = "" ;
2020-04-16 18:52:26 +00:00
public string msg
{
get { return Msg ; }
2022-07-14 18:17:37 +00:00
set
{
Msg = value ;
2020-04-16 18:52:26 +00:00
OnPropertyChanged ( ) ;
}
}
2020-04-25 06:40:38 +00:00
private string bootsound ;
public string BootSound
{
get { return bootsound ; }
2022-07-14 18:17:37 +00:00
set
{
bootsound = value ;
2020-04-25 06:40:38 +00:00
OnPropertyChanged ( ) ;
}
}
2020-04-16 18:52:26 +00:00
2020-04-21 02:05:19 +00:00
public System . Windows . Controls . ListViewItem curr = null ;
2020-04-16 18:52:26 +00:00
2020-04-19 17:36:03 +00:00
private bool ckeys ;
public bool Ckeys
{
get { return ckeys ; }
2022-07-14 18:17:37 +00:00
set
{
ckeys = value ;
2020-04-19 17:36:03 +00:00
OnPropertyChanged ( ) ;
}
}
2020-04-06 19:30:31 +00:00
2022-07-02 07:13:33 +00:00
public bool NKITFLAG { get ; set ; } = false ;
2020-05-06 21:53:52 +00:00
2020-04-08 02:25:08 +00:00
public MainWindow mw ;
2020-04-06 17:50:12 +00:00
private CustomBaseFrame cb = null ;
2020-04-18 03:31:36 +00:00
DispatcherTimer timer = new DispatcherTimer ( ) ;
2020-04-21 02:05:19 +00:00
public bool PokePatch = false ;
2022-07-14 15:25:28 +00:00
public void Update ( bool button )
2020-04-07 21:21:38 +00:00
{
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnection ( ) )
2020-04-07 21:21:38 +00:00
{
2020-04-19 17:36:03 +00:00
System . Reflection . Assembly assembly = System . Reflection . Assembly . GetExecutingAssembly ( ) ;
FileVersionInfo fvi = FileVersionInfo . GetVersionInfo ( assembly . Location ) ;
string version = fvi . FileVersion ;
AutoUpdater . Start ( "https://raw.githubusercontent.com/Hotbrawl20/testing/master/update.xml" ) ;
if ( Properties . Settings . Default . UpgradeRequired )
2020-04-18 03:31:36 +00:00
{
2020-04-19 17:36:03 +00:00
Properties . Settings . Default . Upgrade ( ) ;
Properties . Settings . Default . UpgradeRequired = false ;
Properties . Settings . Default . Save ( ) ;
2020-04-18 03:31:36 +00:00
}
2022-07-14 15:25:28 +00:00
if ( button & & Convert . ToInt32 ( version . Split ( '.' ) [ 3 ] ) > = GetNewVersion ( ) )
2020-04-19 17:36:03 +00:00
{
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "No Updates available" , " You are currently using the newest version of UWUVCI AIO " ) ;
2020-04-19 17:36:03 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-18 03:31:36 +00:00
2020-04-19 17:36:03 +00:00
}
2022-07-14 18:17:37 +00:00
else if ( button )
{
var client = new Octokit . GitHubClient ( new Octokit . ProductHeaderValue ( "UWUVCI-AIO-WPF" ) ) ;
var releases = Task . Run ( ( ) = > client . Repository . Release . GetAll ( "stuff-by-3-random-dudes" , "UWUVCI-AIO-WPF" ) ) . GetAwaiter ( ) . GetResult ( ) ;
int comparison ;
try
{
var latestString = Regex . Replace ( releases [ 0 ] . TagName , "[^0-9.]" , "" ) ;
var latestLength = latestString . Split ( '.' ) . Length ;
var localLength = version . Split ( '.' ) . Length ;
for ( var i = 0 ; i < localLength - latestLength ; i + + )
latestString + = ".0" ;
var latestVersion = new Version ( latestString ) ;
var localVersion = new Version ( version ) ;
comparison = localVersion . CompareTo ( latestVersion ) ;
}
catch
{
//Someone messed up versioning, so eff it just don't even bother then
return ;
}
if ( comparison > 0 )
{
using ( var webClient = new WebClient ( ) )
{
webClient . Headers . Add ( HttpRequestHeader . UserAgent , "MyUserAgent" ) ;
webClient . DownloadFile ( releases [ 0 ] . ZipballUrl , "UWUVCI_INSTALLER.exe" ) ;
}
var cm = new Custom_Message ( "Update Available!" , "Latest version is currently being downloaded!\nPlease look for the file \"UWUVCI_INSTALLER.exe\" in\n" + Directory . GetCurrentDirectory ( ) ) ;
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
}
2022-09-29 03:55:05 +00:00
else
{
var cm = new Custom_Message ( "No Update Available" , "This is currently the latest version." ) ;
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
}
2022-07-14 18:17:37 +00:00
}
2020-04-18 03:31:36 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-18 03:31:36 +00:00
}
2022-07-14 15:25:28 +00:00
private int GetNewVersion ( )
2020-04-18 03:31:36 +00:00
{
try
{
WebRequest request ;
//get download link from uwuvciapi
2022-07-14 18:17:37 +00:00
request = WebRequest . Create ( "https://uwuvciapi.azurewebsites.net/GetVersionNum" ) ;
2020-04-18 03:31:36 +00:00
2022-07-14 15:25:28 +00:00
var response = request . GetResponse ( ) ;
2020-04-18 03:31:36 +00:00
using ( Stream dataStream = response . GetResponseStream ( ) )
{
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader ( dataStream ) ;
// Read the content.
string responseFromServer = reader . ReadToEnd ( ) ;
// Display the content.
return Convert . ToInt32 ( responseFromServer ) ;
}
}
catch ( Exception )
{
return 100000 ;
}
2020-04-07 21:21:38 +00:00
}
2020-04-18 03:31:36 +00:00
2020-04-25 06:40:38 +00:00
public bool ConfirmRiffWave ( string path )
{
using ( var reader = new BinaryReader ( File . OpenRead ( path ) ) )
{
reader . BaseStream . Position = 0x00 ;
long WAVHeader1 = reader . ReadInt32 ( ) ;
reader . BaseStream . Position = 0x08 ;
long WAVHeader2 = reader . ReadInt32 ( ) ;
if ( WAVHeader1 = = 1179011410 & WAVHeader2 = = 1163280727 )
{
return true ;
}
else
{
return false ;
}
}
}
2020-04-18 03:31:36 +00:00
public void OpenDialog ( string title , string msg )
2020-03-01 15:07:22 +00:00
{
2020-04-18 03:31:36 +00:00
Custom_Message cm = new Custom_Message ( title , msg ) ;
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-17 16:02:45 +00:00
}
2022-07-14 18:17:37 +00:00
public MainViewModel ( )
{
2020-12-13 21:19:21 +00:00
if ( ! Environment . Is64BitOperatingSystem )
{
List < string > Tools = ToolCheck . ToolNames . ToList ( ) ;
Tools . Remove ( "CNUSPACKER.exe" ) ;
Tools . Add ( "NUSPacker.jar" ) ;
ToolCheck . ToolNames = Tools . ToArray ( ) ;
}
2022-07-14 18:17:37 +00:00
2020-12-13 21:19:21 +00:00
2020-04-17 01:28:14 +00:00
//if (Directory.Exists(@"Tools")) Directory.Delete(@"Tools", true);
2022-07-14 15:25:28 +00:00
if ( Directory . Exists ( @"bases" ) ) Directory . Delete ( @"bases" , true ) ;
if ( Directory . Exists ( @"temp" ) ) Directory . Delete ( @"temp" , true ) ;
2020-04-17 01:28:14 +00:00
if ( Directory . Exists ( @"keys" ) )
{
2022-07-14 18:17:37 +00:00
if ( Directory . Exists ( @"bin\keys" ) ) Directory . Delete ( @"bin\keys" , true ) ;
2020-04-17 01:28:14 +00:00
Injection . DirectoryCopy ( "keys" , "bin/keys" , true ) ;
Directory . Delete ( "keys" , true ) ;
}
2022-07-14 15:25:28 +00:00
if ( ! Directory . Exists ( "InjectedGames" ) ) Directory . CreateDirectory ( "InjectedGames" ) ;
if ( ! Directory . Exists ( "SourceFiles" ) ) Directory . CreateDirectory ( "SourceFiles" ) ;
if ( ! Directory . Exists ( "bin\\BaseGames" ) ) Directory . CreateDirectory ( "bin\\BaseGames" ) ;
2022-07-14 18:17:37 +00:00
if ( Properties . Settings . Default . OutPath = = "" | | Properties . Settings . Default . OutPath = = null )
2022-07-14 15:25:28 +00:00
{
2020-04-17 01:28:14 +00:00
Settings . Default . OutPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "InjectedGames" ) ;
2022-07-14 15:25:28 +00:00
}
2022-07-14 18:17:37 +00:00
if ( Settings . Default . BasePath = = "" | | Properties . Settings . Default . BasePath = = null )
2022-07-14 15:25:28 +00:00
{
2020-04-17 01:28:14 +00:00
Settings . Default . BasePath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "BaseGames" ) ;
2022-07-14 15:25:28 +00:00
}
2020-04-17 01:28:14 +00:00
Settings . Default . Save ( ) ;
ArePathsSet ( ) ;
2022-07-14 15:25:28 +00:00
Update ( false ) ;
2020-04-07 21:21:38 +00:00
2022-07-14 15:25:28 +00:00
toolCheck ( ) ;
2022-07-03 07:58:03 +00:00
BaseCheck ( ) ;
2020-04-06 19:30:31 +00:00
2020-03-01 15:07:22 +00:00
GameConfiguration = new GameConfig ( ) ;
2020-04-06 19:30:31 +00:00
if ( ! ValidatePathsStillExist ( ) & & Settings . Default . SetBaseOnce & & Settings . Default . SetOutOnce )
2020-04-02 19:45:24 +00:00
{
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Issue" , " One of your added Paths seems to not exist anymore. \n The Tool is now using it's default Paths \n Please check the paths in the Path menu! " ) ;
2020-05-06 21:53:52 +00:00
try
{
cm . Owner = mw ;
2022-07-14 18:17:37 +00:00
}
catch ( Exception )
2020-05-06 21:53:52 +00:00
{
}
cm . ShowDialog ( ) ;
2020-04-02 19:45:24 +00:00
}
UpdatePathSet ( ) ;
2020-04-03 23:20:15 +00:00
2020-03-13 22:35:20 +00:00
GetAllBases ( ) ;
2020-04-03 23:20:15 +00:00
}
2020-04-08 02:25:08 +00:00
public string turbocd ( )
{
2022-07-14 18:17:37 +00:00
2020-04-08 02:25:08 +00:00
string ret = string . Empty ;
2020-08-26 03:02:21 +00:00
Custom_Message cm = new Custom_Message ( "Information" , " Please put a TurboGrafX CD ROM into a folder and select said folder. \n\n The Folder should at least contain: \n EXACTLY ONE *.hcd file \n One or more *.ogg files \n One or More *.bin files \n\n Not doing so will result in a faulty Inject. You have been warned! " ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-17 16:02:45 +00:00
2020-04-20 09:31:26 +00:00
using ( var dialog = new CommonOpenFileDialog ( ) )
2020-04-08 02:25:08 +00:00
{
2020-04-20 09:31:26 +00:00
dialog . IsFolderPicker = true ;
2022-07-14 18:17:37 +00:00
CommonFileDialogResult result = dialog . ShowDialog ( ) ;
2020-04-20 09:31:26 +00:00
if ( result = = CommonFileDialogResult . Ok )
2020-04-08 02:25:08 +00:00
{
try
{
2020-04-20 09:31:26 +00:00
if ( DirectoryIsEmpty ( dialog . FileName ) )
2020-04-08 02:25:08 +00:00
{
2020-06-13 18:34:54 +00:00
cm = new Custom_Message ( "Issue" , " The folder is Empty. Please choose another folder " ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-08 02:25:08 +00:00
}
else
{
2020-04-20 09:31:26 +00:00
if ( Directory . GetDirectories ( dialog . FileName ) . Length > 0 )
2020-04-08 02:25:08 +00:00
{
2020-06-13 18:34:54 +00:00
cm = new Custom_Message ( "Issue" , " This folder mustn't contain any subfolders. " ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-17 16:02:45 +00:00
2020-04-08 02:25:08 +00:00
}
else
{
//WUP
2020-04-20 09:31:26 +00:00
if ( Directory . GetFiles ( dialog . FileName , "*.hcd" ) . Length = = 1 & & Directory . GetFiles ( dialog . FileName , "*.ogg" ) . Length > 0 & & Directory . GetFiles ( dialog . FileName , "*.bin" ) . Length > 0 )
2020-04-08 02:25:08 +00:00
{
2020-04-20 09:31:26 +00:00
ret = dialog . FileName ;
2020-04-08 02:25:08 +00:00
}
else
{
2020-06-13 18:34:54 +00:00
cm = new Custom_Message ( "Issue" , " This Folder does not contain needed minimum of Files " ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-08 02:25:08 +00:00
}
}
}
}
catch ( Exception )
{
}
}
}
return ret ;
}
2020-04-21 02:05:19 +00:00
public GameConfig saveconf = null ;
2020-04-06 17:50:12 +00:00
public void resetCBASE ( )
{
2020-04-06 19:30:31 +00:00
if ( cb ! = null ) cb . Reset ( ) ;
2020-04-06 17:50:12 +00:00
}
public void removeCBASE ( )
{
cb = null ;
}
2020-04-06 19:30:31 +00:00
public void setThing ( Page T )
{
Thing = T ;
}
2020-04-06 17:50:12 +00:00
public void SetCBASE ( CustomBaseFrame cbs )
{
cb = cbs ;
}
2020-04-04 22:16:55 +00:00
public void setMW ( MainWindow mwi )
{
mw = mwi ;
}
2020-06-14 22:35:45 +00:00
public bool cd = false ;
2020-04-06 19:30:31 +00:00
public void ExportFile ( )
{
2020-04-21 02:05:19 +00:00
string drcp = null ;
string tvcp = null ;
string iccp = null ;
string lgcp = null ;
string incp = null ;
2022-07-14 18:17:37 +00:00
if ( GameConfiguration . TGADrc . ImgPath ! = null | | GameConfiguration . TGADrc . ImgPath = = "" ) drcp = String . Copy ( GameConfiguration . TGADrc . ImgPath ) ;
2020-04-21 02:05:19 +00:00
if ( GameConfiguration . TGATv . ImgPath ! = null | | GameConfiguration . TGATv . ImgPath = = "" ) tvcp = String . Copy ( GameConfiguration . TGATv . ImgPath ) ;
if ( GameConfiguration . TGAIco . ImgPath ! = null | | GameConfiguration . TGAIco . ImgPath = = "" ) iccp = String . Copy ( GameConfiguration . TGAIco . ImgPath ) ;
if ( GameConfiguration . TGALog . ImgPath ! = null | | GameConfiguration . TGALog . ImgPath = = "" ) lgcp = String . Copy ( GameConfiguration . TGALog . ImgPath ) ;
2020-06-14 22:35:45 +00:00
GameConfiguration . pixelperfect = pixelperfect ;
GameConfiguration . lr = LR ;
GameConfiguration . pokepatch = PokePatch ;
GameConfiguration . tgcd = cd ;
GameConfiguration . donttrim = donttrim ;
2020-06-15 18:54:37 +00:00
GameConfiguration . motepass = passtrough ;
GameConfiguration . jppatch = jppatch ;
GameConfiguration . vm = Patch ;
GameConfiguration . vmtopal = toPal ;
GameConfiguration . rf = regionfrii ;
GameConfiguration . rfjp = regionfriijp ;
GameConfiguration . rfus = regionfriius ;
2022-07-14 18:17:37 +00:00
if ( Index ! = - 1 )
2020-06-14 22:35:45 +00:00
{
GameConfiguration . disgamepad = false ;
}
else
{
GameConfiguration . disgamepad = true ;
}
GameConfiguration . fourbythree = cd ;
2020-04-21 02:05:19 +00:00
if ( GameConfiguration . N64Stuff . INIPath ! = null | | GameConfiguration . N64Stuff . INIPath = = "" ) incp = String . Copy ( GameConfiguration . N64Stuff . INIPath ) ;
2020-06-14 22:35:45 +00:00
ReadBootSoundIntoConfig ( ) ;
2020-04-06 19:30:31 +00:00
ReadImagesIntoConfig ( ) ;
if ( GameConfiguration . Console = = GameConsoles . N64 )
{
ReadIniIntoConfig ( ) ;
}
2020-04-20 09:31:26 +00:00
GameConfig backup = GameConfiguration ;
if ( test = = GameConsoles . GCN ) backup . Console = GameConsoles . GCN ;
2022-07-14 18:17:37 +00:00
if ( GameConfiguration . TGADrc . ImgBin ! = null & & GameConfiguration . TGADrc . ImgBin . Length > 0 ) backup . TGADrc . ImgPath = "Added via Config" ;
2020-04-20 09:31:26 +00:00
if ( GameConfiguration . TGATv . ImgBin ! = null & & GameConfiguration . TGATv . ImgBin . Length > 0 ) backup . TGATv . ImgPath = "Added via Config" ;
if ( GameConfiguration . TGALog . ImgBin ! = null & & GameConfiguration . TGALog . ImgBin . Length > 0 ) backup . TGALog . ImgPath = "Added via Config" ;
if ( GameConfiguration . TGAIco . ImgBin ! = null & & GameConfiguration . TGAIco . ImgBin . Length > 0 ) backup . TGAIco . ImgPath = "Added via Config" ;
if ( GameConfiguration . N64Stuff . INIBin ! = null & & GameConfiguration . N64Stuff . INIBin . Length > 0 ) backup . N64Stuff . INIPath = "Added via Config" ;
if ( GameConfiguration . GameName = = "" | | GameConfiguration . GameName = = null ) backup . GameName = "NoName" ;
2020-05-15 21:20:24 +00:00
GameConfiguration . Index = Index ;
2020-04-06 19:30:31 +00:00
CheckAndFixConfigFolder ( ) ;
2021-04-15 23:07:12 +00:00
var sanitizedGameName = backup . GameName ;
Array . ForEach ( Path . GetInvalidFileNameChars ( ) ,
c = > sanitizedGameName = sanitizedGameName . Replace ( c . ToString ( ) , string . Empty ) ) ;
string outputPath = $@"configs\[{backup.Console}]{sanitizedGameName}.uwuvci" ;
2020-04-20 09:31:26 +00:00
int i = 1 ;
while ( File . Exists ( outputPath ) )
2020-04-09 18:40:48 +00:00
{
2021-04-15 23:07:12 +00:00
outputPath = $@"configs\[{backup.Console}]{sanitizedGameName}_{i}.uwuvci" ;
2020-04-09 18:40:48 +00:00
i + + ;
}
2021-04-15 23:07:12 +00:00
2020-04-09 18:40:48 +00:00
Stream createConfigStream = new FileStream ( outputPath , FileMode . Create , FileAccess . Write ) ;
2020-04-06 19:30:31 +00:00
GZipStream compressedStream = new GZipStream ( createConfigStream , CompressionMode . Compress ) ;
IFormatter formatter = new BinaryFormatter ( ) ;
2020-04-20 09:31:26 +00:00
formatter . Serialize ( compressedStream , backup ) ;
2020-04-06 19:30:31 +00:00
compressedStream . Close ( ) ;
createConfigStream . Close ( ) ;
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Export success" , " The Config was successfully exported.\n Click the Open Folder Button to open the Location where the Config is stored. " , Path . Combine ( Directory . GetCurrentDirectory ( ) , outputPath ) ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-06-14 22:35:45 +00:00
2020-04-21 02:05:19 +00:00
GameConfiguration . TGADrc . ImgPath = drcp ;
GameConfiguration . TGATv . ImgPath = tvcp ;
GameConfiguration . TGAIco . ImgPath = iccp ;
GameConfiguration . TGALog . ImgPath = lgcp ;
GameConfiguration . TGADrc . ImgBin = null ;
GameConfiguration . TGATv . ImgBin = null ;
GameConfiguration . TGAIco . ImgBin = null ;
GameConfiguration . TGALog . ImgBin = null ;
if ( incp ! = null )
{
GameConfiguration . N64Stuff . INIBin = null ;
GameConfiguration . N64Stuff . INIPath = incp ;
}
/ * if ( GameConfiguration . Console = = GameConsoles . N64 )
2020-04-20 09:31:26 +00:00
{
( thing as N64Config ) . reset ( ) ;
}
else if ( gameConfiguration . Console = = GameConsoles . TG16 )
{
( thing as TurboGrafX ) . reset ( ) ;
}
else if ( gameConfiguration . Console = = GameConsoles . WII & & test ! = GameConsoles . GCN )
{
( thing as WiiConfig ) . reset ( ) ;
}
else if ( test = = GameConsoles . GCN )
{
( thing as GCConfig ) . reset ( ) ;
}
else
{
try
{
( thing as OtherConfigs ) . reset ( ) ;
}
catch ( Exception e )
{
( thing as GCConfig ) . reset ( ) ;
}
2020-04-21 02:05:19 +00:00
} * /
2020-04-18 03:31:36 +00:00
}
2020-04-06 19:30:31 +00:00
public void ImportConfig ( string configPath )
{
FileInfo fn = new FileInfo ( configPath ) ;
2020-06-14 22:35:45 +00:00
if ( Directory . Exists ( @"bin\cfgBoot" ) )
{
Directory . Delete ( @"bin\cfgBoot" , true ) ;
}
2020-04-06 19:30:31 +00:00
if ( fn . Extension . Contains ( "uwuvci" ) )
{
FileStream inputConfigStream = new FileStream ( configPath , FileMode . Open , FileAccess . Read ) ;
GZipStream decompressedConfigStream = new GZipStream ( inputConfigStream , CompressionMode . Decompress ) ;
IFormatter formatter = new BinaryFormatter ( ) ;
GameConfiguration = ( GameConfig ) formatter . Deserialize ( decompressedConfigStream ) ;
2020-06-14 22:35:45 +00:00
pixelperfect = GameConfiguration . pixelperfect ;
LR = GameConfiguration . lr ;
cd = GameConfiguration . tgcd ;
PokePatch = GameConfiguration . pokepatch ;
2020-06-15 18:54:37 +00:00
passtrough = GameConfiguration . motepass ;
jppatch = GameConfiguration . jppatch ;
2022-07-14 18:17:37 +00:00
Patch = GameConfiguration . vm ;
2020-06-15 18:54:37 +00:00
toPal = GameConfiguration . vmtopal ;
regionfrii = GameConfiguration . rf ;
regionfriijp = GameConfiguration . rfjp ;
regionfriius = GameConfiguration . rfus ;
2020-04-06 19:30:31 +00:00
}
2022-07-14 18:17:37 +00:00
if ( GameConfiguration . Console = = GameConsoles . N64 )
2020-04-06 19:30:31 +00:00
{
( thing as N64Config ) . getInfoFromConfig ( ) ;
}
2022-07-14 18:17:37 +00:00
else if ( gameConfiguration . Console = = GameConsoles . TG16 )
2020-04-20 00:35:31 +00:00
{
( thing as TurboGrafX ) . getInfoFromConfig ( ) ;
2022-07-14 18:17:37 +00:00
}
else if ( gameConfiguration . Console = = GameConsoles . WII & & test ! = GameConsoles . GCN )
2020-04-20 00:35:31 +00:00
{
( thing as WiiConfig ) . getInfoFromConfig ( ) ;
2022-07-14 18:17:37 +00:00
}
else if ( test = = GameConsoles . GCN )
2020-04-20 00:35:31 +00:00
{
( thing as GCConfig ) . getInfoFromConfig ( ) ;
2022-07-14 18:17:37 +00:00
}
else if ( gameConfiguration . Console = = GameConsoles . GBA )
2020-04-21 02:05:19 +00:00
{
( thing as GBA ) . getInfoFromConfig ( ) ;
2020-04-20 00:35:31 +00:00
}
2020-04-06 19:30:31 +00:00
else
{
2020-04-20 00:35:31 +00:00
try
{
( thing as OtherConfigs ) . getInfoFromConfig ( ) ;
}
2022-07-14 18:17:37 +00:00
catch ( Exception )
2020-04-20 00:35:31 +00:00
{
( thing as GCConfig ) . getInfoFromConfig ( ) ;
}
2020-04-06 19:30:31 +00:00
}
}
2020-06-14 22:35:45 +00:00
public void ReadBootSoundIntoConfig ( )
{
ReadFileAsBin ( GameConfiguration , bootsound , 6 ) ;
}
2022-07-14 18:17:37 +00:00
2020-04-06 19:30:31 +00:00
public void ReadImagesIntoConfig ( )
{
ReadFileAsBin ( GameConfiguration , GameConfiguration . TGAIco . ImgPath , 1 ) ;
ReadFileAsBin ( GameConfiguration , GameConfiguration . TGADrc . ImgPath , 2 ) ;
ReadFileAsBin ( GameConfiguration , GameConfiguration . TGATv . ImgPath , 3 ) ;
ReadFileAsBin ( GameConfiguration , GameConfiguration . TGALog . ImgPath , 4 ) ;
}
public void ReadIniIntoConfig ( )
{
ReadFileAsBin ( GameConfiguration , GameConfiguration . N64Stuff . INIPath , 5 ) ;
}
2022-07-14 18:17:37 +00:00
2020-04-06 19:30:31 +00:00
private void ReadFileAsBin ( GameConfig file , string FilePath , int scase )
{
2022-07-14 18:17:37 +00:00
if ( FilePath ! = null )
2020-04-06 19:30:31 +00:00
{
try
{
var filedata = new FileStream ( FilePath , FileMode . Open ) ;
var len = ( int ) filedata . Length ;
switch ( scase )
{
case 1 :
file . TGAIco . ImgBin = new byte [ len ] ;
filedata . Read ( file . TGAIco . ImgBin , 0 , len ) ;
break ;
case 2 :
file . TGADrc . ImgBin = new byte [ len ] ;
filedata . Read ( file . TGADrc . ImgBin , 0 , len ) ;
break ;
case 3 :
file . TGATv . ImgBin = new byte [ len ] ;
filedata . Read ( file . TGATv . ImgBin , 0 , len ) ;
break ;
case 4 :
file . TGALog . ImgBin = new byte [ len ] ;
filedata . Read ( file . TGALog . ImgBin , 0 , len ) ;
break ;
case 5 :
file . N64Stuff . INIBin = new byte [ len ] ;
filedata . Read ( file . N64Stuff . INIBin , 0 , len ) ;
break ;
2020-06-14 22:35:45 +00:00
case 6 :
2022-07-14 18:17:37 +00:00
2020-06-14 22:35:45 +00:00
file . bootsound = new byte [ len ] ;
filedata . Read ( file . bootsound , 0 , len ) ;
file . extension = new FileInfo ( FilePath ) . Extension . Replace ( "." , "" ) ;
break ;
2020-04-06 19:30:31 +00:00
}
filedata . Close ( ) ;
}
catch ( Exception )
{
switch ( scase )
{
case 1 :
file . TGAIco . ImgBin = null ;
break ;
case 2 :
file . TGADrc . ImgBin = null ;
break ;
case 3 :
file . TGATv . ImgBin = null ;
break ;
case 4 :
file . TGALog . ImgBin = null ;
break ;
case 5 :
file . N64Stuff . INIBin = null ;
break ;
}
}
}
2022-07-14 18:17:37 +00:00
2020-04-06 19:30:31 +00:00
}
2020-05-04 16:20:21 +00:00
public bool donttrim = false ;
2020-04-06 19:30:31 +00:00
private static void CheckAndFixConfigFolder ( )
{
if ( ! Directory . Exists ( @"configs" ) )
{
Directory . CreateDirectory ( @"configs" ) ;
}
}
2020-04-04 22:16:55 +00:00
public void Pack ( bool loadiine )
{
2020-04-19 17:36:03 +00:00
ValidatePathsStillExist ( ) ;
2020-04-04 22:16:55 +00:00
if ( loadiine )
{
Injection . Loadiine ( GameConfiguration . GameName ) ;
2020-04-17 01:28:14 +00:00
//
2020-04-04 22:16:55 +00:00
}
else
{
2022-07-14 18:17:37 +00:00
if ( gameConfiguration . GameName ! = null )
2020-04-28 23:40:54 +00:00
{
Regex reg = new Regex ( "[^a-zA-Z0-9 é -]" ) ;
2020-06-23 17:13:45 +00:00
gameConfiguration . GameName = gameConfiguration . GameName . Replace ( "|" , " " ) ;
2020-04-28 23:40:54 +00:00
gameConfiguration . GameName = reg . Replace ( gameConfiguration . GameName , "" ) ;
}
2022-07-14 18:17:37 +00:00
2020-04-16 18:52:26 +00:00
Task . Run ( ( ) = > { Injection . Packing ( GameConfiguration . GameName , this ) ; } ) ;
2020-04-17 17:15:27 +00:00
DownloadWait dw = new DownloadWait ( "Packing Inject - Please Wait" , "" , this ) ;
try
{
2020-04-30 15:01:41 +00:00
dw . changeOwner ( mw ) ;
2020-04-17 17:15:27 +00:00
}
catch ( Exception ) { }
dw . ShowDialog ( ) ;
2022-07-14 18:17:37 +00:00
2020-04-16 18:52:26 +00:00
Progress = 0 ;
2020-04-17 01:28:14 +00:00
string extra = "" ;
2020-06-13 20:16:15 +00:00
string names = "Copy to SD" ;
2020-06-13 19:52:39 +00:00
if ( GameConfiguration . Console = = GameConsoles . WII ) extra = "\n Some games cannot reboot into the WiiU Menu. Shut down via the GamePad. \n If Stuck in a BlackScreen, you need to unplug your WiiU." ;
2020-06-13 18:34:54 +00:00
if ( GameConfiguration . Console = = GameConsoles . WII & & romPath . ToLower ( ) . Contains ( ".wad" ) ) extra + = "\n Make sure that the chosen WAD is installed in your vWii!" ;
2020-06-13 20:16:15 +00:00
if ( GC )
{
extra = "\n Make sure to have Nintendon't + config on your SD.\n You can add them by pressing the \"SD Setup\" button or using the \"Start Nintendont Config Tool\" button under Settings. " ;
names = "SD Setup" ;
}
2020-04-19 17:36:03 +00:00
gc2rom = "" ;
2020-06-13 20:16:15 +00:00
2022-07-14 18:17:37 +00:00
Custom_Message cm = new Custom_Message ( "Injection Complete" , $" You need CFW (example: haxchi or mocha) to run and install this inject! \n It's recommended to install onto USB to avoid brick risks.{extra}\n To Open the Location of the Inject press Open Folder.\n If you want the inject to be put on your SD now, press {names}. " , Settings . Default . OutPath ) ; try
2020-04-18 03:31:36 +00:00
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-04 22:16:55 +00:00
}
LGameBasesString . Clear ( ) ;
CanInject = false ;
RomSet = false ;
RomPath = null ;
Injected = false ;
2020-04-06 17:50:12 +00:00
GameConfiguration . CBasePath = null ;
2020-04-16 04:41:25 +00:00
GC = false ;
2020-04-25 06:40:38 +00:00
bootsound = "" ;
2020-05-06 21:53:52 +00:00
NKITFLAG = false ;
2020-05-07 07:49:36 +00:00
CBasePath = null ;
2020-05-22 09:36:31 +00:00
prodcode = "" ;
2020-06-09 09:43:17 +00:00
ClearImage ( ) ;
2020-05-24 20:59:09 +00:00
foldername = "" ;
2020-06-11 08:12:03 +00:00
mw . ListView_Click ( mw . listCONS , null ) ;
2020-04-04 22:16:55 +00:00
}
2020-04-18 03:31:36 +00:00
2020-06-09 09:43:17 +00:00
private void ClearImage ( )
{
switch ( GameConfiguration . Console )
{
case GameConsoles . NDS :
( thing as OtherConfigs ) . icoIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . tvIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . drcIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . logIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . Injection . IsEnabled = false ;
2022-07-14 18:17:37 +00:00
2020-06-09 09:43:17 +00:00
break ;
case GameConsoles . GBA :
( thing as GBA ) . icoIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as GBA ) . tvIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as GBA ) . drcIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as GBA ) . logIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as GBA ) . Injection . IsEnabled = false ;
break ;
case GameConsoles . N64 :
( thing as N64Config ) . icoIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as N64Config ) . tvIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as N64Config ) . drcIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as N64Config ) . logIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as N64Config ) . Injection . IsEnabled = false ;
break ;
case GameConsoles . NES :
( thing as OtherConfigs ) . icoIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . tvIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . drcIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . logIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . Injection . IsEnabled = false ;
break ;
case GameConsoles . SNES :
( thing as OtherConfigs ) . icoIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . tvIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . drcIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . logIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . Injection . IsEnabled = false ;
break ;
case GameConsoles . TG16 :
( thing as TurboGrafX ) . icoIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as TurboGrafX ) . tvIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as TurboGrafX ) . drcIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as TurboGrafX ) . logIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as TurboGrafX ) . Injection . IsEnabled = false ;
break ;
case GameConsoles . MSX :
( thing as OtherConfigs ) . icoIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . tvIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . drcIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . logIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as OtherConfigs ) . Injection . IsEnabled = false ;
break ;
case GameConsoles . WII :
2022-07-14 18:17:37 +00:00
if ( test = = GameConsoles . GCN )
2020-06-09 09:43:17 +00:00
{
( thing as GCConfig ) . icoIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as GCConfig ) . tvIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as GCConfig ) . drcIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as GCConfig ) . logIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as GCConfig ) . Injection . IsEnabled = false ;
}
else
{
( thing as WiiConfig ) . icoIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as WiiConfig ) . tvIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as WiiConfig ) . drcIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as WiiConfig ) . logIMG . Visibility = System . Windows . Visibility . Hidden ;
( thing as WiiConfig ) . Injection . IsEnabled = false ;
}
break ;
}
}
2020-04-18 03:31:36 +00:00
DownloadWait Injectwait ;
2020-04-17 16:02:45 +00:00
public void runInjectThread ( bool force )
2020-04-04 22:16:55 +00:00
{
2022-07-14 18:17:37 +00:00
2020-04-18 03:31:36 +00:00
timer . Interval = TimeSpan . FromSeconds ( 1 ) ;
timer . Tick + = timer_Tick2 ;
timer . Start ( ) ;
2020-04-17 16:02:45 +00:00
var thread = new Thread ( ( ) = >
2020-04-16 18:52:26 +00:00
{
2022-07-14 18:17:37 +00:00
Injectwait = new DownloadWait ( "Injecting Game - Please Wait" , "" , this ) ;
2020-04-18 03:31:36 +00:00
try
{
2020-04-30 15:01:41 +00:00
Injectwait . changeOwner ( mw ) ;
2020-04-18 03:31:36 +00:00
}
catch ( Exception ) { }
Injectwait . Topmost = true ;
Injectwait . ShowDialog ( ) ;
2020-04-16 18:52:26 +00:00
} ) ;
2020-04-17 16:02:45 +00:00
thread . SetApartmentState ( ApartmentState . STA ) ;
thread . Start ( ) ;
2022-07-14 18:17:37 +00:00
2020-04-18 03:31:36 +00:00
2020-04-17 16:02:45 +00:00
}
2020-06-27 17:15:57 +00:00
public bool failed = false ;
2020-04-18 03:31:36 +00:00
2020-04-17 16:02:45 +00:00
public void Inject ( bool force )
{
2020-04-19 17:36:03 +00:00
ValidatePathsStillExist ( ) ;
2020-04-18 03:31:36 +00:00
/ * var task = new Task ( ( ) = > runInjectThread ( true ) ) ;
task . Start ( ) ; * /
Task . Run ( ( ) = >
2020-04-17 17:15:27 +00:00
{
2020-06-22 20:19:39 +00:00
if ( Injection . Inject ( GameConfiguration , RomPath , this , force ) )
{
Injected = true ;
injected2 = true ;
2022-07-14 18:17:37 +00:00
if ( GameConfiguration . Console = = GameConsoles . WII | | GameConfiguration . Console = = GameConsoles . GCN )
2020-06-22 20:19:39 +00:00
{
injected2 = false ;
}
2022-07-14 18:17:37 +00:00
2020-06-22 20:19:39 +00:00
}
else { Injected = false ; injected2 = false ; }
2020-04-18 03:31:36 +00:00
} ) ;
2020-04-19 17:36:03 +00:00
DownloadWait dw = new DownloadWait ( "Injecting Game - Please Wait" , "" , this ) ;
try
{
2020-04-30 15:01:41 +00:00
dw . changeOwner ( mw ) ;
}
2022-07-14 18:17:37 +00:00
catch ( Exception ) { }
2020-04-19 17:36:03 +00:00
dw . ShowDialog ( ) ;
2020-04-18 03:31:36 +00:00
Progress = 0 ;
2020-04-17 01:28:14 +00:00
if ( Injected )
{
2020-06-13 19:52:39 +00:00
Custom_Message cm = new Custom_Message ( "Finished Injection Part" , " Injection Finished, please choose how you want to export the Inject next. " ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-17 01:28:14 +00:00
}
2020-06-27 17:15:57 +00:00
else
{
if ( failed )
{
MessageBox . Show ( "In here" ) ;
mw . allowBypass ( ) ;
if ( debug )
{
mw . setDebug ( true ) ;
}
Inject ( force ) ;
}
}
2022-07-14 18:17:37 +00:00
2020-04-04 22:16:55 +00:00
}
2022-07-03 07:58:03 +00:00
private void BaseCheck ( )
2020-04-03 23:20:15 +00:00
{
2020-04-17 01:28:14 +00:00
if ( Directory . Exists ( @"bin\bases" ) )
2020-04-03 23:20:15 +00:00
{
var test = GetMissingVCBs ( ) ;
2020-04-17 01:28:14 +00:00
if ( test . Count > 0 )
2020-04-03 23:20:15 +00:00
{
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnection ( ) )
2020-04-19 17:36:03 +00:00
{
Progress = 0 ;
2022-07-03 04:06:25 +00:00
Task . Run ( ( ) = >
2020-04-19 17:36:03 +00:00
{
double stuff = 100 / test . Count ;
foreach ( string s in test )
{
2022-07-14 15:25:28 +00:00
DownloadBase ( s , this ) ;
2020-04-19 17:36:03 +00:00
Progress + = Convert . ToInt32 ( stuff ) ;
}
2022-07-13 02:50:41 +00:00
Progress = 100 ;
2020-04-19 17:36:03 +00:00
} ) ;
DownloadWait dw = new DownloadWait ( "Downloading needed Data - Please Wait" , "" , this ) ;
try
{
2020-04-30 15:01:41 +00:00
dw . changeOwner ( mw ) ;
2020-04-19 17:36:03 +00:00
}
catch ( Exception ) { }
dw . ShowDialog ( ) ;
2022-07-03 07:58:03 +00:00
BaseCheck ( ) ;
2020-04-19 17:36:03 +00:00
}
else
{
2020-06-13 18:34:54 +00:00
Custom_Message dw = new Custom_Message ( "No Internet connection" , " You have files missing, which need to be downloaded but you dont have an Internet Connection. \n The Program will now terminate " ) ;
2020-04-19 17:36:03 +00:00
try
{
dw . Owner = mw ;
}
catch ( Exception ) { }
dw . ShowDialog ( ) ;
Environment . Exit ( 1 ) ;
}
}
}
else
{
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnection ( ) )
2020-04-19 17:36:03 +00:00
{
Directory . CreateDirectory ( @"bin\bases" ) ;
var test = GetMissingVCBs ( ) ;
2020-04-17 01:28:14 +00:00
Progress = 0 ;
2022-07-03 04:06:25 +00:00
Task . Run ( ( ) = >
2020-04-03 23:20:15 +00:00
{
2020-04-17 01:28:14 +00:00
double stuff = 100 / test . Count ;
foreach ( string s in test )
2020-04-03 23:20:15 +00:00
{
2022-07-14 15:25:28 +00:00
DownloadBase ( s , this ) ;
2020-04-17 01:28:14 +00:00
Progress + = Convert . ToInt32 ( stuff ) ;
2020-04-03 23:20:15 +00:00
}
2022-07-13 02:50:41 +00:00
Progress = 100 ;
2020-04-17 01:28:14 +00:00
} ) ;
2020-04-17 17:15:27 +00:00
DownloadWait dw = new DownloadWait ( "Downloading needed Data - Please Wait" , "" , this ) ;
try
{
2020-04-30 15:01:41 +00:00
dw . changeOwner ( mw ) ;
2020-04-17 17:15:27 +00:00
}
catch ( Exception ) { }
dw . ShowDialog ( ) ;
2020-04-19 17:36:03 +00:00
Progress = 0 ;
2022-07-03 07:58:03 +00:00
BaseCheck ( ) ;
2020-04-03 23:20:15 +00:00
}
2020-04-19 17:36:03 +00:00
else
{
2020-06-13 18:34:54 +00:00
Custom_Message dw = new Custom_Message ( "No Internet connection" , " You have files missing, which need to be downloaded but you dont have an Internet Connection. \n The Program will now terminate " ) ;
2020-04-19 17:36:03 +00:00
try
{
dw . Owner = mw ;
}
catch ( Exception ) { }
dw . ShowDialog ( ) ;
Environment . Exit ( 1 ) ;
}
2022-07-14 18:17:37 +00:00
2020-04-19 17:36:03 +00:00
2020-04-03 23:20:15 +00:00
}
2020-04-17 01:28:14 +00:00
2020-04-19 17:36:03 +00:00
}
2022-07-14 15:25:28 +00:00
public void UpdateTools ( )
2020-04-19 17:36:03 +00:00
{
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnection ( ) )
2020-04-19 17:36:03 +00:00
{
string [ ] bases = ToolCheck . ToolNames ;
2022-07-14 15:25:28 +00:00
Task . Run ( ( ) = >
2020-04-03 23:20:15 +00:00
{
2020-04-19 17:36:03 +00:00
Progress = 0 ;
double l = 100 / bases . Length ;
foreach ( string s in bases )
2020-04-03 23:20:15 +00:00
{
2020-04-19 17:36:03 +00:00
DeleteTool ( s ) ;
2022-07-14 15:25:28 +00:00
DownloadTool ( s , this ) ;
2020-04-19 17:36:03 +00:00
Progress + = Convert . ToInt32 ( l ) ;
2020-04-03 23:20:15 +00:00
}
2022-07-14 15:25:28 +00:00
Progress = 100 ;
2020-04-17 01:28:14 +00:00
} ) ;
2020-04-19 17:36:03 +00:00
DownloadWait dw = new DownloadWait ( "Updating Tools - Please Wait" , "" , this ) ;
2020-04-17 17:15:27 +00:00
try
{
2020-04-30 15:01:41 +00:00
dw . changeOwner ( mw ) ;
2020-04-17 17:15:27 +00:00
}
2020-04-19 17:36:03 +00:00
catch ( Exception )
{
2020-04-17 01:28:14 +00:00
2020-04-19 17:36:03 +00:00
}
dw . ShowDialog ( ) ;
2022-07-14 15:25:28 +00:00
toolCheck ( ) ;
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Finished Update" , " Finished Updating Tools! Restarting UWUVCI AIO " ) ;
2020-04-19 17:36:03 +00:00
try
2020-04-17 01:28:14 +00:00
{
2020-04-19 17:36:03 +00:00
cm . Owner = mw ;
2020-04-17 01:28:14 +00:00
}
2020-04-19 17:36:03 +00:00
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-06-09 09:43:17 +00:00
Process p = new Process ( ) ;
p . StartInfo . FileName = System . Windows . Application . ResourceAssembly . Location ;
if ( debug )
{
2020-06-24 15:54:51 +00:00
if ( saveworkaround )
{
p . StartInfo . Arguments = "--debug --skip --spacebypass" ;
}
else
{
p . StartInfo . Arguments = "--debug --skip" ;
}
2022-07-14 18:17:37 +00:00
2020-06-09 09:43:17 +00:00
}
else
{
2020-06-24 15:54:51 +00:00
if ( saveworkaround )
{
p . StartInfo . Arguments = "--skip --spacebypass" ;
}
else
{
p . StartInfo . Arguments = "--skip" ;
}
2020-06-09 09:43:17 +00:00
}
p . Start ( ) ;
2020-04-19 17:36:03 +00:00
Environment . Exit ( 0 ) ;
2020-04-18 03:31:36 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-07 21:21:38 +00:00
}
2020-04-17 16:02:45 +00:00
public void ResetTKQuest ( )
{
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Resetting TitleKeys" , " This Option will reset all entered TitleKeys meaning you will need to reenter them again! \n Do you still wish to continue?" ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
2020-04-19 22:53:34 +00:00
cm . ShowDialog ( ) ;
cm . Close ( ) ;
2020-04-17 16:02:45 +00:00
}
2020-04-08 22:22:42 +00:00
public void ResetTitleKeys ( )
{
2022-07-14 18:17:37 +00:00
File . Delete ( "bin/keys/gba.vck" ) ;
File . Delete ( "bin/keys/nds.vck" ) ;
File . Delete ( "bin/keys/nes.vck" ) ;
File . Delete ( "bin/keys/n64.vck" ) ;
File . Delete ( "bin/keys/msx.vck" ) ;
File . Delete ( "bin/keys/tg16.vck" ) ;
File . Delete ( "bin/keys/snes.vck" ) ;
File . Delete ( "bin/keys/wii.vck" ) ;
Custom_Message cm = new Custom_Message ( "Reset Successful" , " The TitleKeys are now reset. \n The Program will now restart." ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-19 22:53:34 +00:00
mw . Close ( ) ;
2020-06-09 09:43:17 +00:00
Process p = new Process ( ) ;
p . StartInfo . FileName = System . Windows . Application . ResourceAssembly . Location ;
if ( debug )
{
p . StartInfo . Arguments = "--debug --skip" ;
}
else
{
p . StartInfo . Arguments = "--skip" ;
}
p . Start ( ) ;
2020-04-19 22:53:34 +00:00
Environment . Exit ( 0 ) ;
2020-04-08 22:22:42 +00:00
}
2022-07-14 15:25:28 +00:00
public void UpdateBases ( )
2020-04-03 23:20:15 +00:00
{
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnection ( ) )
2020-04-17 17:15:27 +00:00
{
2020-04-19 17:36:03 +00:00
string [ ] bases = { "bases.vcbnds" , "bases.vcbn64" , "bases.vcbgba" , "bases.vcbsnes" , "bases.vcbnes" , "bases.vcbtg16" , "bases.vcbmsx" , "bases.vcbwii" } ;
2022-07-14 15:25:28 +00:00
Task . Run ( ( ) = > {
2020-04-19 17:36:03 +00:00
Progress = 0 ;
double l = 100 / bases . Length ;
foreach ( string s in bases )
{
DeleteBase ( s ) ;
2022-07-14 15:25:28 +00:00
DownloadBase ( s , this ) ;
2020-04-19 17:36:03 +00:00
GameConsoles g = new GameConsoles ( ) ;
if ( s . Contains ( "nds" ) ) g = GameConsoles . NDS ;
if ( s . Contains ( "nes" ) ) g = GameConsoles . NES ;
if ( s . Contains ( "snes" ) ) g = GameConsoles . SNES ;
if ( s . Contains ( "n64" ) ) g = GameConsoles . N64 ;
if ( s . Contains ( "gba" ) ) g = GameConsoles . GBA ;
if ( s . Contains ( "tg16" ) ) g = GameConsoles . TG16 ;
if ( s . Contains ( "msx" ) ) g = GameConsoles . MSX ;
if ( s . Contains ( "wii" ) ) g = GameConsoles . WII ;
UpdateKeyFile ( VCBTool . ReadBasesFromVCB ( $@"bin/bases/{s}" ) , g ) ;
Progress + = Convert . ToInt32 ( l ) ;
}
Progress = 100 ;
} ) ;
DownloadWait dw = new DownloadWait ( "Updating Base Files - Please Wait" , "" , this ) ;
try
{
2020-04-30 15:01:41 +00:00
dw . changeOwner ( mw ) ;
2020-04-19 17:36:03 +00:00
}
catch ( Exception )
{
2020-04-17 17:15:27 +00:00
2020-04-19 17:36:03 +00:00
}
dw . ShowDialog ( ) ;
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Finished Updating" , " Finished Updating Bases! Restarting UWUVCI AIO " ) ;
2020-04-19 17:36:03 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-06-09 09:43:17 +00:00
Process p = new Process ( ) ;
p . StartInfo . FileName = System . Windows . Application . ResourceAssembly . Location ;
if ( debug )
{
p . StartInfo . Arguments = "--debug --skip" ;
}
else
{
p . StartInfo . Arguments = "--skip" ;
}
p . Start ( ) ;
2020-04-19 17:36:03 +00:00
Environment . Exit ( 0 ) ;
2020-04-17 17:15:27 +00:00
}
2022-07-14 18:17:37 +00:00
2022-09-29 03:55:05 +00:00
}
public static int GetDeterministicHashCode ( string str )
{
unchecked
{
int hash1 = ( 5381 < < 16 ) + 5381 ;
int hash2 = hash1 ;
for ( int i = 0 ; i < str . Length ; i + = 2 )
{
hash1 = ( ( hash1 < < 5 ) + hash1 ) ^ str [ i ] ;
if ( i = = str . Length - 1 )
break ;
hash2 = ( ( hash2 < < 5 ) + hash2 ) ^ str [ i + 1 ] ;
}
return hash1 + ( hash2 * 1566083941 ) ;
}
2020-04-02 19:45:24 +00:00
}
2020-04-16 04:41:25 +00:00
public bool checkSysKey ( string key )
{
2022-10-02 01:14:19 +00:00
if ( key . GetHashCode ( ) = = - 589797700 )
2020-04-16 04:41:25 +00:00
{
Properties . Settings . Default . SysKey = key ;
Properties . Settings . Default . Save ( ) ;
return true ;
}
return false ;
}
public bool SysKey1set ( )
{
return checkSysKey1 ( Properties . Settings . Default . SysKey1 ) ;
}
public bool checkSysKey1 ( string key )
{
2022-10-02 01:14:19 +00:00
if ( key . GetHashCode ( ) = = - 1230232583 )
2020-04-16 04:41:25 +00:00
{
Properties . Settings . Default . SysKey1 = key ;
Properties . Settings . Default . Save ( ) ;
return true ;
}
return false ;
}
public bool SysKeyset ( )
{
return checkSysKey ( Properties . Settings . Default . SysKey ) ;
}
2020-04-06 19:30:31 +00:00
public bool GetConsoleOfConfig ( string configPath , GameConsoles console )
{
FileInfo fn = new FileInfo ( configPath ) ;
if ( fn . Extension . Contains ( "uwuvci" ) )
{
FileStream inputConfigStream = new FileStream ( configPath , FileMode . Open , FileAccess . Read ) ;
GZipStream decompressedConfigStream = new GZipStream ( inputConfigStream , CompressionMode . Decompress ) ;
IFormatter formatter = new BinaryFormatter ( ) ;
GameConfig check = ( GameConfig ) formatter . Deserialize ( decompressedConfigStream ) ;
if ( check . Console = = console ) return true ;
2022-07-14 18:17:37 +00:00
2020-04-06 19:30:31 +00:00
}
return false ;
}
2020-04-08 22:28:21 +00:00
public void selectConfig ( GameConsoles console )
2020-04-06 19:30:31 +00:00
{
string ret = string . Empty ;
using ( var dialog = new System . Windows . Forms . OpenFileDialog ( ) )
{
2020-04-30 15:01:41 +00:00
dialog . InitialDirectory = Path . Combine ( Directory . GetCurrentDirectory ( ) , "configs" ) ;
2020-04-06 19:30:31 +00:00
dialog . Filter = "UWUVCI Config (*.uwuvci) | *.uwuvci" ;
DialogResult res = dialog . ShowDialog ( ) ;
if ( res = = DialogResult . OK )
{
ret = dialog . FileName ;
2020-04-08 22:28:21 +00:00
if ( GetConsoleOfConfig ( ret , console ) )
{
ImportConfig ( ret ) ;
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Import Complete" , " Importing of Config completed. \n Please reselect a Base!" ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-08 22:28:21 +00:00
}
2020-04-10 17:04:35 +00:00
else
{
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Import Failed" , $" The config you are trying to import is not made for {console.ToString()} Injections. \n Please choose a config made for these kind of Injections or choose a different kind of Injection" ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-10 17:04:35 +00:00
}
2020-04-06 19:30:31 +00:00
}
}
2020-04-19 22:53:34 +00:00
}
2022-07-14 15:25:28 +00:00
private bool RemoteFileExists ( string url )
2020-04-19 22:53:34 +00:00
{
try
{
HttpWebRequest request = WebRequest . Create ( url ) as HttpWebRequest ;
request . Method = "HEAD" ;
2022-07-14 15:25:28 +00:00
HttpWebResponse response = request . GetResponse ( ) as HttpWebResponse ;
2020-04-19 22:53:34 +00:00
response . Close ( ) ;
return ( response . StatusCode = = HttpStatusCode . OK ) ;
}
catch
{
return false ;
}
2020-04-06 19:30:31 +00:00
}
2020-04-04 00:41:56 +00:00
public string GetFilePath ( bool ROM , bool INI )
{
2020-04-18 03:31:36 +00:00
Custom_Message cm ;
2020-04-04 00:41:56 +00:00
string ret = string . Empty ;
2020-04-25 06:40:38 +00:00
if ( ROM & & ! INI )
2020-04-08 02:25:08 +00:00
{
2020-04-19 19:15:00 +00:00
switch ( GameConfiguration . Console )
{
case GameConsoles . NDS :
2020-06-13 18:34:54 +00:00
cm = new Custom_Message ( "Information" , " You can only inject NDS ROMs that are not DSi Enhanced (example for not working: Pokémon Black & White) \n\n If attempting to inject a DSi Enhanced ROM, we will not give you any support with fixing said injection. " ) ;
2020-04-19 19:15:00 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
2020-05-07 07:49:36 +00:00
if ( ! Properties . Settings . Default . ndsw )
{
cm . ShowDialog ( ) ;
}
2022-07-14 18:17:37 +00:00
2020-04-18 03:31:36 +00:00
2020-04-19 19:15:00 +00:00
break ;
case GameConsoles . SNES :
2020-06-13 18:34:54 +00:00
cm = new Custom_Message ( "Information" , " You can only inject SNES ROMs that are not using any Co-Processors (example for not working: Star Fox) \n\n If attempting to inject a ROM in need of a Co-Processor, we will not give you any support with fixing said injection. " ) ;
2020-04-19 19:15:00 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
2020-05-07 07:49:36 +00:00
if ( ! Properties . Settings . Default . snesw )
{
cm . ShowDialog ( ) ;
}
2020-04-17 16:02:45 +00:00
2020-04-19 19:15:00 +00:00
break ;
}
2020-04-08 02:25:08 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-04 00:41:56 +00:00
using ( var dialog = new System . Windows . Forms . OpenFileDialog ( ) )
{
if ( ROM )
{
2020-04-25 06:40:38 +00:00
if ( INI )
2022-07-14 18:17:37 +00:00
{
2020-04-25 06:40:38 +00:00
dialog . Filter = "BootSound Files (*.mp3; *.wav; *.btsnd) | *.mp3;*.wav;*.btsnd" ;
}
else if ( GC )
2020-04-04 00:41:56 +00:00
{
2020-04-18 03:31:36 +00:00
dialog . Filter = "GCN ROM (*.iso; *.gcm) | *.iso; *.gcm" ;
}
else
{
switch ( GameConfiguration . Console )
{
case GameConsoles . NDS :
dialog . Filter = "Nintendo DS ROM (*.nds; *.srl) | *.nds;*.srl" ;
break ;
case GameConsoles . N64 :
dialog . Filter = "Nintendo 64 ROM (*.n64; *.v64; *.z64) | *.n64;*.v64;*.z64" ;
break ;
case GameConsoles . GBA :
dialog . Filter = "GameBoy Series ROM (*.gba;*.gbc;*.gb) | *.gba;*.gbc;*.gb" ;
break ;
case GameConsoles . NES :
dialog . Filter = "Nintendo Entertainment System ROM (*.nes) | *.nes" ;
break ;
case GameConsoles . SNES :
dialog . Filter = "Super Nintendo Entertainment System ROM (*.sfc; *.smc) | *.sfc;*.smc" ;
break ;
case GameConsoles . TG16 :
dialog . Filter = "TurboGrafX-16 ROM (*.pce) | *.pce" ;
break ;
case GameConsoles . MSX :
dialog . Filter = "MSX/MSX2 ROM (*.ROM) | *.ROM" ;
break ;
case GameConsoles . WII :
2022-07-14 18:17:37 +00:00
if ( test = = GameConsoles . GCN )
2020-04-18 03:31:36 +00:00
{
2020-06-26 21:23:10 +00:00
dialog . Filter = "GC ROM (*.iso; *.gcm; *.nkit.iso; *.nkit.gcz) | *.iso; *.gcm; *.nkit.iso; *.nkit.gcz" ;
2020-04-18 03:31:36 +00:00
}
else
{
2020-06-26 21:28:19 +00:00
dialog . Filter = "All Supported Types (*.*) | *.iso; *.wbfs; *.nkit.gcz; *.nkit.iso; *.dol; *.wad|Wii ROM (*.iso; *.wbfs; *.nkit.gcz; *.nkit.iso) | *.iso; *.wbfs; *.nkit.gcz; *.nkit.iso|Wii Homebrew (*.dol) | *.dol|Wii Channel (*.wad) | *.wad" ;
2020-06-26 21:23:10 +00:00
// dialog.Filter = "Wii ROM (*.iso; *.wbfs; *.nkit.gcz; *.nkit.iso) | *.iso; *.wbfs; *.nkit.gcz; *.nkit.iso|Wii Homebrew (*.dol) | *.dol|Wii Channel (*.wad) | *.wad";
2020-04-18 03:31:36 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-18 03:31:36 +00:00
break ;
case GameConsoles . GCN :
2020-05-07 20:00:24 +00:00
dialog . Filter = "GC ROM (*.iso; *.gcm; *.nkit.iso; *.nkit.gcz) | *.iso; *.gcm; *.nkit.iso; *.nkit.gcz" ;
2020-04-18 03:31:36 +00:00
break ;
}
2020-04-04 00:41:56 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-04 00:41:56 +00:00
}
2022-07-14 18:17:37 +00:00
else if ( ! INI )
2020-04-04 00:41:56 +00:00
{
2022-07-14 18:17:37 +00:00
2021-12-17 22:01:43 +00:00
dialog . Filter = "Images (*.png; *.jpg; *.bmp; *.tga; *jpeg) | *.png;*.jpg;*.bmp;*.tga;*jpeg" ;
2020-04-04 00:41:56 +00:00
}
2022-07-14 18:17:37 +00:00
else if ( INI )
2020-04-04 00:41:56 +00:00
{
dialog . Filter = "N64 VC Configuration (*.ini) | *.ini" ;
}
2020-04-18 03:31:36 +00:00
if ( Directory . Exists ( "SourceFiles" ) )
{
dialog . InitialDirectory = "SourceFiles" ;
}
2022-07-14 18:17:37 +00:00
2020-04-04 00:41:56 +00:00
DialogResult res = dialog . ShowDialog ( ) ;
2022-07-14 18:17:37 +00:00
if ( res = = DialogResult . OK )
2020-04-04 00:41:56 +00:00
{
2020-05-06 21:53:52 +00:00
if ( dialog . FileName . ToLower ( ) . Contains ( ".gcz" ) )
{
2020-06-13 18:34:54 +00:00
Custom_Message cm1 = new Custom_Message ( "Information" , " Using a GameCube GCZ Nkit for a Wii Inject or vice versa will break things. \n You will not be able to grab the BootImages or GameName using this type of ROM. " ) ;
2020-05-06 21:53:52 +00:00
try
{
cm1 . Owner = mw ;
2022-07-14 18:17:37 +00:00
}
catch ( Exception )
2020-05-06 21:53:52 +00:00
{
}
2020-05-07 07:49:36 +00:00
if ( ! Properties . Settings . Default . gczw )
{
cm1 . ShowDialog ( ) ;
}
2020-05-06 21:53:52 +00:00
}
2020-04-04 00:41:56 +00:00
ret = dialog . FileName ;
}
2020-05-06 21:53:52 +00:00
else
{
if ( dialog . Filter . Contains ( "BootImages" ) | | dialog . Filter . Contains ( "BootSound" ) )
{
ret = "" ;
}
}
2020-04-04 00:41:56 +00:00
}
return ret ;
}
2020-04-18 03:31:36 +00:00
public GameConsoles test ;
2020-04-03 23:20:15 +00:00
private static void CopyBase ( string console )
{
2020-04-17 01:28:14 +00:00
File . Copy ( console , $@"bin\bases\{console}" ) ;
2020-04-03 23:20:15 +00:00
File . Delete ( console ) ;
}
2020-04-07 21:21:38 +00:00
private static void DeleteTool ( string tool )
{
2020-04-17 01:28:14 +00:00
File . Delete ( $@"bin\Tools\{tool}" ) ;
2020-04-07 21:21:38 +00:00
}
2020-04-03 23:20:15 +00:00
private static void DeleteBase ( string console )
{
2020-04-17 01:28:14 +00:00
File . Delete ( $@"bin\bases\{console}" ) ;
2020-04-03 23:20:15 +00:00
}
public static List < string > GetMissingVCBs ( )
{
List < string > ret = new List < string > ( ) ;
2020-04-17 01:28:14 +00:00
string path = @"bin\bases\bases.vcb" ;
2020-04-03 23:20:15 +00:00
if ( ! File . Exists ( path + "nds" ) )
{
ret . Add ( path + "nds" ) ;
}
if ( ! File . Exists ( path + "nes" ) )
{
ret . Add ( path + "nes" ) ;
}
if ( ! File . Exists ( path + "n64" ) )
{
ret . Add ( path + "n64" ) ;
}
if ( ! File . Exists ( path + "snes" ) )
{
ret . Add ( path + "snes" ) ;
}
if ( ! File . Exists ( path + "gba" ) )
{
ret . Add ( path + "gba" ) ;
}
2020-04-06 13:50:54 +00:00
if ( ! File . Exists ( path + "tg16" ) )
{
ret . Add ( path + "tg16" ) ;
}
2020-04-07 01:09:05 +00:00
if ( ! File . Exists ( path + "msx" ) )
{
ret . Add ( path + "msx" ) ;
}
2020-04-16 04:41:25 +00:00
if ( ! File . Exists ( path + "wii" ) )
{
ret . Add ( path + "wii" ) ;
}
2020-04-03 23:20:15 +00:00
return ret ;
}
2022-07-14 15:25:28 +00:00
public static void DownloadBase ( string name , MainViewModel mvm )
2020-04-03 23:20:15 +00:00
{
2020-04-17 01:28:14 +00:00
string olddir = Directory . GetCurrentDirectory ( ) ;
2020-04-03 23:20:15 +00:00
try
{
2020-04-17 01:28:14 +00:00
string basePath = $@"bin\bases\" ;
Directory . SetCurrentDirectory ( basePath ) ;
2020-04-03 23:20:15 +00:00
using ( var client = new WebClient ( ) )
2022-07-14 15:25:28 +00:00
2020-04-03 23:20:15 +00:00
{
2020-04-17 01:28:14 +00:00
var fixname = name . Split ( '\\' ) ;
2022-07-14 18:17:37 +00:00
client . DownloadFile ( getDownloadLink ( name , false ) , fixname [ fixname . Length - 1 ] ) ;
2020-04-03 23:20:15 +00:00
}
2022-07-14 18:17:37 +00:00
}
catch ( Exception e )
2020-04-03 23:20:15 +00:00
{
Console . WriteLine ( e . Message ) ;
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Error 005: \"Unable to Download VCB Base\"" , " There was an Error downloading the VCB Base File. \n The Programm will now terminate." ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mvm . mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-03 23:20:15 +00:00
Environment . Exit ( 1 ) ;
}
2020-04-17 01:28:14 +00:00
Directory . SetCurrentDirectory ( olddir ) ;
2020-04-03 23:20:15 +00:00
}
2022-07-14 15:25:28 +00:00
public static void DownloadTool ( string name , MainViewModel mvm )
2020-04-03 23:20:15 +00:00
{
2020-04-17 01:28:14 +00:00
string olddir = Directory . GetCurrentDirectory ( ) ;
2020-04-03 23:20:15 +00:00
try
{
2022-07-14 18:17:37 +00:00
if ( Directory . GetCurrentDirectory ( ) . Contains ( "bin" ) & & Directory . GetCurrentDirectory ( ) . Contains ( "Tools" ) )
2020-06-05 11:02:11 +00:00
{
olddir = Directory . GetCurrentDirectory ( ) . Replace ( "bin\\Tools" , "" ) ;
}
else
{
string basePath = $@"bin\Tools\" ;
Directory . SetCurrentDirectory ( basePath ) ;
}
2020-08-10 13:11:56 +00:00
do
2020-04-06 23:33:46 +00:00
{
2020-08-10 13:11:56 +00:00
if ( File . Exists ( name ) )
{
File . Delete ( name ) ;
}
using ( var client = new WebClient ( ) )
{
2022-07-14 15:25:28 +00:00
client . DownloadFile ( getDownloadLink ( name , true ) , name ) ;
2020-08-10 13:11:56 +00:00
}
2022-07-14 15:25:28 +00:00
} while ( ! ToolCheck . IsToolRight ( name ) ) ;
2022-07-14 18:17:37 +00:00
2020-04-06 23:33:46 +00:00
}
catch ( Exception e )
{
Console . WriteLine ( e . Message ) ;
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Error 006: \"Unable to Download Tool\"" , " There was an Error downloading the Tool. \n The Programm will now terminate." ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mvm . mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-17 16:02:45 +00:00
2020-04-06 23:33:46 +00:00
Environment . Exit ( 1 ) ;
}
2020-04-17 01:28:14 +00:00
Directory . SetCurrentDirectory ( olddir ) ;
2020-04-06 23:33:46 +00:00
}
2022-07-14 15:25:28 +00:00
private static string getDownloadLink ( string toolname , bool tool )
2020-04-06 23:33:46 +00:00
{
try
{
2020-06-11 08:12:03 +00:00
bool ok = false ;
try
2020-04-06 23:33:46 +00:00
{
2020-06-11 08:12:03 +00:00
System . Net . WebClient client = new System . Net . WebClient ( ) ;
2022-07-14 15:25:28 +00:00
string result = client . DownloadString ( "https://uwuvciapi.azurewebsites.net/api/values" ) ;
2020-06-11 08:12:03 +00:00
ok = true ;
2020-04-06 23:33:46 +00:00
}
2022-10-01 21:40:01 +00:00
catch ( System . Net . WebException )
2020-04-06 23:33:46 +00:00
{
2022-07-14 18:17:37 +00:00
2020-06-11 08:12:03 +00:00
2020-04-06 23:33:46 +00:00
}
2020-06-11 08:12:03 +00:00
if ( ok )
2020-04-03 23:20:15 +00:00
{
2020-06-11 08:12:03 +00:00
WebRequest request ;
//get download link from uwuvciapi
if ( tool )
{
request = WebRequest . Create ( "https://uwuvciapi.azurewebsites.net/GetToolLink?tool=" + toolname ) ;
}
else
{
request = WebRequest . Create ( "https://uwuvciapi.azurewebsites.net/GetVcbLink?vcb=" + toolname ) ;
}
2022-07-14 15:25:28 +00:00
var response = request . GetResponse ( ) ;
2020-06-11 08:12:03 +00:00
using ( Stream dataStream = response . GetResponseStream ( ) )
{
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader ( dataStream ) ;
// Read the content.
string responseFromServer = reader . ReadToEnd ( ) ;
// Display the content.
2022-07-14 18:17:37 +00:00
if ( responseFromServer = = "" )
2020-06-11 08:12:03 +00:00
{
if ( tool )
{
return $"{ToolCheck.backupulr}{toolname}" ;
}
else
{
return $@"https://github.com/Hotbrawl20/UWUVCI-VCB/raw/master/" + toolname ;
}
}
return responseFromServer ;
}
}
else
{
if ( tool )
{
return $"{ToolCheck.backupulr}{toolname}" ;
}
else
{
2020-10-17 12:54:24 +00:00
return $@"https://github.com/Hotbrawl20/UWUVCI-VCB/raw/master/" + toolname . Replace ( "bin\\bases\\" , "" ) ;
2020-06-11 08:12:03 +00:00
}
2020-04-03 23:20:15 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-03 23:20:15 +00:00
}
catch ( Exception )
{
2020-06-05 11:02:11 +00:00
if ( tool )
{
return $"{ToolCheck.backupulr}{toolname}" ;
}
else
{
2022-07-14 18:17:37 +00:00
return $@"https://github.com/Hotbrawl20/UWUVCI-VCB/raw/master/" + toolname . Replace ( "bin\\bases\\" , "" ) ;
2020-06-05 11:02:11 +00:00
}
2020-06-11 08:12:03 +00:00
2020-04-03 23:20:15 +00:00
}
}
2022-07-03 07:13:08 +00:00
public void InjcttoolCheck ( )
2020-04-10 20:23:49 +00:00
{
if ( ToolCheck . DoesToolsFolderExist ( ) )
{
List < MissingTool > missingTools = new List < MissingTool > ( ) ;
missingTools = ToolCheck . CheckForMissingTools ( ) ;
if ( missingTools . Count > 0 )
{
2022-07-14 18:17:37 +00:00
foreach ( MissingTool m in missingTools )
{
DownloadTool ( m . Name , this ) ;
}
InjcttoolCheck ( ) ;
2020-04-10 20:23:49 +00:00
}
}
else
{
2020-04-17 01:28:14 +00:00
string path = $@"{Directory.GetCurrentDirectory()}bin\\Tools" ;
2022-07-14 18:17:37 +00:00
Directory . CreateDirectory ( $@"{Directory.GetCurrentDirectory()}bin\\Tools" ) ;
InjcttoolCheck ( ) ;
2020-04-10 20:23:49 +00:00
}
}
2022-07-02 07:13:33 +00:00
private void ThreadDownload ( List < MissingTool > missingTools )
2020-04-17 17:15:27 +00:00
{
2022-07-14 18:17:37 +00:00
2022-07-14 15:25:28 +00:00
var thread = new Thread ( ( ) = >
2020-04-17 17:15:27 +00:00
{
double l = 100 / missingTools . Count ;
2020-04-10 20:23:49 +00:00
2020-04-17 17:15:27 +00:00
foreach ( MissingTool m in missingTools )
{
2022-07-14 18:17:37 +00:00
if ( m . Name = = "blank.ini" )
2020-12-27 13:53:41 +00:00
{
2022-07-03 07:58:03 +00:00
StreamWriter sw = new StreamWriter ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "Tools" , "blank.ini" ) ) ;
sw . Close ( ) ;
2020-12-27 13:53:41 +00:00
}
else
{
2022-07-14 15:25:28 +00:00
DownloadTool ( m . Name , this ) ;
2020-12-27 13:53:41 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-17 17:15:27 +00:00
Progress + = Convert . ToInt32 ( l ) ;
}
Progress = 100 ;
2022-07-14 18:17:37 +00:00
2020-04-17 17:15:27 +00:00
} ) ;
2022-07-14 18:17:37 +00:00
thread . SetApartmentState ( ApartmentState . STA ) ;
2020-04-17 17:15:27 +00:00
thread . Start ( ) ;
2022-07-14 18:17:37 +00:00
2020-04-17 17:15:27 +00:00
}
2020-04-18 03:31:36 +00:00
private void timer_Tick2 ( object sender , EventArgs e )
{
2022-07-14 18:17:37 +00:00
2020-04-18 03:31:36 +00:00
if ( Progress = = 100 )
{
Injectwait . Close ( ) ;
2022-07-14 18:17:37 +00:00
2020-04-18 03:31:36 +00:00
timer . Stop ( ) ;
2022-07-14 18:17:37 +00:00
2020-04-18 03:31:36 +00:00
Progress = 0 ;
}
}
2022-07-14 15:25:28 +00:00
private void toolCheck ( )
2020-04-02 22:49:48 +00:00
{
2022-07-14 18:17:37 +00:00
if ( ToolCheck . DoesToolsFolderExist ( ) )
2020-04-02 22:49:48 +00:00
{
List < MissingTool > missingTools = new List < MissingTool > ( ) ;
missingTools = ToolCheck . CheckForMissingTools ( ) ;
2022-07-14 18:17:37 +00:00
if ( missingTools . Count > 0 )
2020-04-02 22:49:48 +00:00
{
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnection ( ) )
2020-04-19 17:36:03 +00:00
{
2022-07-14 15:25:28 +00:00
Task . Run ( ( ) = > ThreadDownload ( missingTools ) ) ;
2020-04-30 15:01:41 +00:00
DownloadWait dw = new DownloadWait ( "Downloading Tools - Please Wait" , "" , this ) ;
try
{
dw . changeOwner ( mw ) ;
}
catch ( Exception )
{
}
dw . ShowDialog ( ) ;
2020-04-19 17:36:03 +00:00
Thread . Sleep ( 200 ) ;
//Download Tools
Progress = 0 ;
2022-07-14 15:25:28 +00:00
toolCheck ( ) ;
2020-04-19 17:36:03 +00:00
}
else
{
2020-06-13 18:34:54 +00:00
Custom_Message dw = new Custom_Message ( "No Internet connection" , " You have files missing, which need to be downloaded but you dont have an Internet Connection. \n The Program will now terminate" ) ;
2020-04-19 17:36:03 +00:00
try
{
dw . Owner = mw ;
}
catch ( Exception ) { }
dw . ShowDialog ( ) ;
Environment . Exit ( 1 ) ;
}
2022-07-14 18:17:37 +00:00
2020-04-02 22:49:48 +00:00
}
}
else
{
2020-06-05 11:02:11 +00:00
if ( Directory . GetCurrentDirectory ( ) . Contains ( "bin/tools" ) )
{
}
else
{
2020-04-17 01:28:14 +00:00
Directory . CreateDirectory ( "bin/Tools" ) ;
2020-06-05 11:02:11 +00:00
}
2022-07-14 18:17:37 +00:00
2022-07-14 15:25:28 +00:00
toolCheck ( ) ;
2022-07-14 18:17:37 +00:00
2020-04-02 22:49:48 +00:00
}
}
2020-04-02 19:45:24 +00:00
public void UpdatePathSet ( )
{
2022-07-14 18:17:37 +00:00
2020-04-02 19:45:24 +00:00
PathsSet = Settings . Default . PathsSet ;
2020-08-11 19:35:17 +00:00
2022-07-14 18:17:37 +00:00
if ( BaseStore ! = Settings . Default . BasePath )
2020-04-02 19:45:24 +00:00
{
BaseStore = Settings . Default . BasePath ;
}
if ( InjectStore ! = Settings . Default . BasePath )
{
InjectStore = Settings . Default . OutPath ;
}
2020-03-01 15:52:59 +00:00
}
2020-04-02 19:45:24 +00:00
public bool ValidatePathsStillExist ( )
2020-03-01 15:52:59 +00:00
{
2020-04-02 19:45:24 +00:00
bool ret = false ;
bool basep = false ;
try
{
if ( Directory . Exists ( Settings . Default . BasePath ) )
{
basep = true ;
}
else
{
2022-07-14 18:17:37 +00:00
if ( ! Directory . Exists ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "BaseGames" ) ) ) Directory . CreateDirectory ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "BaseGames" ) ) ;
2020-04-19 17:36:03 +00:00
Settings . Default . BasePath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "BaseGames" ) ;
Settings . Default . PathsSet = true ;
2020-04-02 19:45:24 +00:00
Settings . Default . Save ( ) ;
}
if ( Directory . Exists ( Settings . Default . OutPath ) )
{
if ( basep )
{
ret = true ;
}
}
else
{
2020-04-19 17:36:03 +00:00
if ( ! Directory . Exists ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "InjectedGames" ) ) ) Directory . CreateDirectory ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "InjectedGames" ) ) ;
Settings . Default . OutPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "InjectedGames" ) ;
Settings . Default . PathsSet = true ;
2020-04-02 19:45:24 +00:00
Settings . Default . Save ( ) ;
}
}
catch ( Exception )
{
ret = false ;
}
return ret ;
2020-03-01 15:07:22 +00:00
}
2020-03-08 22:25:34 +00:00
2020-03-13 22:35:20 +00:00
public void GetBases ( GameConsoles Console )
{
List < GameBases > lTemp = new List < GameBases > ( ) ;
2020-04-17 01:28:14 +00:00
string vcbpath = $@"bin/bases/bases.vcb{Console.ToString().ToLower()}" ;
2020-03-13 22:35:20 +00:00
lTemp = VCBTool . ReadBasesFromVCB ( vcbpath ) ;
LBases . Clear ( ) ;
GameBases custom = new GameBases ( ) ;
custom . Name = "Custom" ;
custom . Region = Regions . EU ;
LBases . Add ( custom ) ;
2022-07-14 18:17:37 +00:00
foreach ( GameBases gb in lTemp )
2020-03-13 22:35:20 +00:00
{
LBases . Add ( gb ) ;
}
lGameBasesString . Clear ( ) ;
2022-07-14 18:17:37 +00:00
foreach ( GameBases gb in LBases )
2020-03-13 22:35:20 +00:00
{
2022-07-14 18:17:37 +00:00
if ( gb . Name = = "Custom" )
2020-06-28 18:58:09 +00:00
{
LGameBasesString . Add ( $"{gb.Name}" ) ;
}
else
{
LGameBasesString . Add ( $"{gb.Name} {gb.Region}" ) ;
}
2022-07-14 18:17:37 +00:00
2020-03-13 22:35:20 +00:00
}
}
2022-07-14 18:17:37 +00:00
2020-04-02 23:45:12 +00:00
public GameBases getBasefromName ( string Name )
{
string NameWORegion = Name . Remove ( Name . Length - 3 , 3 ) ;
string Region = Name . Remove ( 0 , Name . Length - 2 ) ;
2022-07-14 18:17:37 +00:00
foreach ( GameBases b in LNDS )
2020-04-02 23:45:12 +00:00
{
2022-07-14 18:17:37 +00:00
if ( b . Name = = NameWORegion & & b . Region . ToString ( ) = = Region )
2020-04-02 23:45:12 +00:00
{
return b ;
}
}
foreach ( GameBases b in LN64 )
{
if ( b . Name = = NameWORegion & & b . Region . ToString ( ) = = Region )
{
return b ;
}
}
foreach ( GameBases b in LNES )
{
if ( b . Name = = NameWORegion & & b . Region . ToString ( ) = = Region )
{
return b ;
}
}
foreach ( GameBases b in LSNES )
{
if ( b . Name = = NameWORegion & & b . Region . ToString ( ) = = Region )
{
return b ;
}
}
foreach ( GameBases b in LGBA )
{
if ( b . Name = = NameWORegion & & b . Region . ToString ( ) = = Region )
{
return b ;
}
}
2020-04-06 13:50:54 +00:00
foreach ( GameBases b in LTG16 )
{
if ( b . Name = = NameWORegion & & b . Region . ToString ( ) = = Region )
{
return b ;
}
}
2020-04-07 01:09:05 +00:00
foreach ( GameBases b in LMSX )
{
if ( b . Name = = NameWORegion & & b . Region . ToString ( ) = = Region )
{
return b ;
}
}
2020-04-16 04:41:25 +00:00
foreach ( GameBases b in LWII )
{
if ( b . Name = = NameWORegion & & b . Region . ToString ( ) = = Region )
{
return b ;
}
}
2020-04-02 23:45:12 +00:00
return null ;
}
2020-03-13 22:35:20 +00:00
private void GetAllBases ( )
{
LN64 . Clear ( ) ;
LNDS . Clear ( ) ;
LNES . Clear ( ) ;
LSNES . Clear ( ) ;
LGBA . Clear ( ) ;
2020-04-06 13:50:54 +00:00
LTG16 . Clear ( ) ;
2020-04-16 04:41:25 +00:00
LMSX . Clear ( ) ;
LWII . Clear ( ) ;
2020-04-17 01:28:14 +00:00
lNDS = VCBTool . ReadBasesFromVCB ( $@"bin/bases/bases.vcbnds" ) ;
lNES = VCBTool . ReadBasesFromVCB ( $@"bin/bases/bases.vcbnes" ) ;
lSNES = VCBTool . ReadBasesFromVCB ( $@"bin/bases/bases.vcbsnes" ) ;
lN64 = VCBTool . ReadBasesFromVCB ( $@"bin/bases/bases.vcbn64" ) ;
lGBA = VCBTool . ReadBasesFromVCB ( $@"bin/bases/bases.vcbgba" ) ;
lTG16 = VCBTool . ReadBasesFromVCB ( $@"bin/bases/bases.vcbtg16" ) ;
lMSX = VCBTool . ReadBasesFromVCB ( $@"bin/bases/bases.vcbmsx" ) ;
lWii = VCBTool . ReadBasesFromVCB ( $@"bin/bases/bases.vcbwii" ) ;
2020-03-13 22:35:20 +00:00
CreateSettingIfNotExist ( lNDS , GameConsoles . NDS ) ;
CreateSettingIfNotExist ( lNES , GameConsoles . NES ) ;
CreateSettingIfNotExist ( lSNES , GameConsoles . SNES ) ;
CreateSettingIfNotExist ( lGBA , GameConsoles . GBA ) ;
CreateSettingIfNotExist ( lN64 , GameConsoles . N64 ) ;
2020-04-06 13:50:54 +00:00
CreateSettingIfNotExist ( lTG16 , GameConsoles . TG16 ) ;
2020-04-07 01:09:05 +00:00
CreateSettingIfNotExist ( lMSX , GameConsoles . MSX ) ;
2020-04-16 04:41:25 +00:00
CreateSettingIfNotExist ( lWii , GameConsoles . WII ) ;
2020-03-13 22:35:20 +00:00
}
private void CreateSettingIfNotExist ( List < GameBases > l , GameConsoles console )
{
2020-04-17 01:28:14 +00:00
string file = $@"bin\keys\{console.ToString().ToLower()}.vck" ;
2020-03-13 22:35:20 +00:00
if ( ! File . Exists ( file ) )
{
List < TKeys > temp = new List < TKeys > ( ) ;
2022-07-14 18:17:37 +00:00
foreach ( GameBases gb in l )
2020-03-13 22:35:20 +00:00
{
TKeys tempkey = new TKeys ( ) ;
tempkey . Base = gb ;
temp . Add ( tempkey ) ;
}
KeyFile . ExportFile ( temp , console ) ;
}
2020-07-01 07:27:48 +00:00
else
{
FixupKeys ( l , console ) ;
}
2022-07-14 18:17:37 +00:00
2020-07-01 07:27:48 +00:00
}
2022-07-14 18:17:37 +00:00
private void FixupKeys ( List < GameBases > l , GameConsoles console )
2020-07-01 07:27:48 +00:00
{
string file = $@"bin\keys\{console.ToString().ToLower()}.vck" ;
2022-07-14 18:17:37 +00:00
var save = KeyFile . ReadBasesFromKeyFile ( file ) ;
2020-07-01 07:27:48 +00:00
List < TKeys > temp = new List < TKeys > ( ) ;
2022-07-14 18:17:37 +00:00
foreach ( TKeys a in save )
2020-07-01 07:27:48 +00:00
{
temp . Add ( a ) ;
}
foreach ( GameBases gb in l )
{
TKeys tempkey = new TKeys ( ) ;
bool check = false ;
2022-07-14 18:17:37 +00:00
foreach ( TKeys a in save )
2020-07-01 07:27:48 +00:00
{
2022-07-14 18:17:37 +00:00
if ( a . Base . Name = = gb . Name & & a . Base . Region = = gb . Region )
{
2020-07-01 07:27:48 +00:00
check = true ;
break ;
}
}
if ( ! check )
{
tempkey . Base = gb ;
temp . Add ( tempkey ) ;
}
2022-07-14 18:17:37 +00:00
2020-07-01 07:27:48 +00:00
}
File . Delete ( file ) ;
KeyFile . ExportFile ( temp , console ) ;
2020-03-13 22:35:20 +00:00
}
2020-04-06 23:33:46 +00:00
private void UpdateKeyFile ( List < GameBases > l , GameConsoles console )
{
2020-04-17 01:28:14 +00:00
string file = $@"bin\keys\{console.ToString().ToLower()}.vck" ;
2020-04-06 23:33:46 +00:00
if ( File . Exists ( file ) )
{
2020-04-17 01:28:14 +00:00
List < TKeys > keys = KeyFile . ReadBasesFromKeyFile ( $@"bin\keys\{console.ToString().ToLower()}.vck" ) ;
2022-07-14 18:17:37 +00:00
List < TKeys > newTK = new List < TKeys > ( ) ;
foreach ( GameBases gb in l )
2020-04-06 23:33:46 +00:00
{
bool inOld = false ;
2022-07-14 18:17:37 +00:00
foreach ( TKeys tk in keys )
2020-04-06 23:33:46 +00:00
{
2022-07-14 18:17:37 +00:00
if ( gb . Name = = tk . Base . Name & & gb . Region = = tk . Base . Region )
2020-04-06 23:33:46 +00:00
{
newTK . Add ( tk ) ;
inOld = true ;
}
if ( inOld ) break ;
}
if ( ! inOld )
{
TKeys tkn = new TKeys ( ) ;
tkn . Base = gb ;
tkn . Tkey = null ;
newTK . Add ( tkn ) ;
}
}
2020-04-17 01:28:14 +00:00
File . Delete ( $@"bin\keys\{console.ToString().ToLower()}.vck" ) ;
2020-04-06 23:33:46 +00:00
KeyFile . ExportFile ( newTK , console ) ;
}
}
2020-03-31 23:48:50 +00:00
public void getTempList ( GameConsoles console )
{
switch ( console )
{
case GameConsoles . NDS :
Ltemp = LNDS ;
break ;
case GameConsoles . N64 :
Ltemp = LN64 ;
break ;
case GameConsoles . GBA :
Ltemp = LGBA ;
break ;
case GameConsoles . NES :
Ltemp = LNES ;
break ;
case GameConsoles . SNES :
Ltemp = LSNES ;
break ;
2020-04-06 13:50:54 +00:00
case GameConsoles . TG16 :
Ltemp = LTG16 ;
break ;
2020-04-07 01:09:05 +00:00
case GameConsoles . MSX :
Ltemp = LMSX ;
break ;
2020-04-16 04:41:25 +00:00
case GameConsoles . WII :
Ltemp = LWII ;
break ;
2020-03-31 23:48:50 +00:00
}
}
2020-03-13 22:35:20 +00:00
2020-03-31 23:48:50 +00:00
public void EnterKey ( bool ck )
2020-03-13 22:35:20 +00:00
{
2020-03-31 23:48:50 +00:00
EnterKey ek = new EnterKey ( ck ) ;
2020-04-19 17:36:03 +00:00
try
{
ek . Owner = mw ;
2022-07-14 18:17:37 +00:00
}
catch ( Exception ) { }
2020-03-13 22:35:20 +00:00
ek . ShowDialog ( ) ;
}
2020-03-31 23:48:50 +00:00
public bool checkcKey ( string key )
{
2022-10-02 01:14:19 +00:00
if ( 1274359530 = = key . ToLower ( ) . GetHashCode ( ) )
2020-03-31 23:48:50 +00:00
{
2020-04-28 23:40:54 +00:00
Settings . Default . Ckey = key . ToLower ( ) ;
2020-04-19 17:36:03 +00:00
ckeys = true ;
2020-03-31 23:48:50 +00:00
Settings . Default . Save ( ) ;
2022-07-14 18:17:37 +00:00
2020-03-31 23:48:50 +00:00
return true ;
}
2020-04-19 17:36:03 +00:00
ckeys = false ;
2020-03-31 23:48:50 +00:00
return false ;
}
public bool isCkeySet ( )
{
2022-10-02 01:14:19 +00:00
if ( Settings . Default . Ckey . ToLower ( ) . GetHashCode ( ) = = 1274359530 )
2020-03-31 23:48:50 +00:00
{
2020-04-19 17:36:03 +00:00
ckeys = true ;
2020-03-31 23:48:50 +00:00
return true ;
}
else
{
2020-04-19 17:36:03 +00:00
ckeys = false ;
2020-03-31 23:48:50 +00:00
return false ;
}
}
2020-03-23 23:18:36 +00:00
public bool checkKey ( string key )
2020-03-13 22:35:20 +00:00
{
2022-10-02 01:14:19 +00:00
if ( GbTemp . KeyHash = = key . ToLower ( ) . GetHashCode ( ) )
2020-03-13 22:35:20 +00:00
{
2020-04-17 01:28:14 +00:00
UpdateKeyInFile ( key , $@"bin\keys\{GetConsoleOfBase(gbTemp).ToString().ToLower()}.vck" , GbTemp , GetConsoleOfBase ( gbTemp ) ) ;
2020-03-23 23:18:36 +00:00
return true ;
2020-03-13 22:35:20 +00:00
}
2020-03-23 23:18:36 +00:00
return false ;
2020-03-13 22:35:20 +00:00
}
public void UpdateKeyInFile ( string key , string file , GameBases Base , GameConsoles console )
{
if ( File . Exists ( file ) )
{
var temp = KeyFile . ReadBasesFromKeyFile ( file ) ;
2022-07-14 18:17:37 +00:00
foreach ( TKeys t in temp )
2020-03-13 22:35:20 +00:00
{
2022-07-14 18:17:37 +00:00
if ( t . Base . Name = = Base . Name & & t . Base . Region = = Base . Region )
2020-03-13 22:35:20 +00:00
{
t . Tkey = key ;
}
}
File . Delete ( file ) ;
KeyFile . ExportFile ( temp , console ) ;
}
}
2020-03-31 23:48:50 +00:00
public bool isKeySet ( GameBases bases )
{
2020-04-17 01:28:14 +00:00
var temp = KeyFile . ReadBasesFromKeyFile ( $@"bin\keys\{GetConsoleOfBase(bases).ToString().ToLower()}.vck" ) ;
2022-07-14 18:17:37 +00:00
foreach ( TKeys t in temp )
2020-03-31 23:48:50 +00:00
{
2022-07-14 18:17:37 +00:00
if ( t . Base . Name = = bases . Name & & t . Base . Region = = bases . Region )
2020-03-31 23:48:50 +00:00
{
2022-07-14 18:17:37 +00:00
if ( t . Tkey ! = null )
2020-03-31 23:48:50 +00:00
{
return true ;
}
}
}
return false ;
}
2020-04-06 15:51:15 +00:00
public void ImageWarning ( )
{
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Image Warning" , " Images need to either be in a Bit Depth of 32bit or 24bit. \n If using Tools like paint.net do not choose the Auto function." ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-06 15:51:15 +00:00
}
2020-04-17 16:02:45 +00:00
public bool choosefolder = false ;
2020-04-06 15:51:15 +00:00
public bool CBaseConvertInfo ( )
{
bool ret = false ;
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "NUS Custom Base" , " You seem to have added a NUS format Custom Base. \n Do you want it to be converted to be used with the Injector?" ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-17 16:02:45 +00:00
2020-04-18 03:31:36 +00:00
if ( choosefolder )
2020-04-06 15:51:15 +00:00
{
ret = true ;
2020-04-17 16:02:45 +00:00
choosefolder = false ;
2020-04-06 15:51:15 +00:00
}
return ret ;
}
2020-04-02 23:45:12 +00:00
public TKeys getTkey ( GameBases bases )
{
2020-04-17 01:28:14 +00:00
var temp = KeyFile . ReadBasesFromKeyFile ( $@"bin\keys\{GetConsoleOfBase(bases).ToString().ToLower()}.vck" ) ;
2020-04-02 23:45:12 +00:00
foreach ( TKeys t in temp )
{
if ( t . Base . Name = = bases . Name & & t . Base . Region = = bases . Region )
{
if ( t . Tkey ! = null )
{
return t ;
}
}
}
return null ;
2020-04-18 03:31:36 +00:00
}
public void ThreadDOwn ( )
{
2022-07-14 18:17:37 +00:00
2020-04-02 23:45:12 +00:00
}
2022-07-03 07:58:03 +00:00
public void Download ( )
2020-04-02 23:45:12 +00:00
{
2020-04-19 17:36:03 +00:00
ValidatePathsStillExist ( ) ;
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnection ( ) )
2020-04-17 17:15:27 +00:00
{
2022-07-03 04:06:25 +00:00
Task . Run ( ( ) = > { Injection . Download ( this ) ; } ) ;
2020-04-19 17:36:03 +00:00
DownloadWait dw = new DownloadWait ( "Downloading Base - Please Wait" , "" , this ) ;
try
{
2020-04-30 15:01:41 +00:00
dw . changeOwner ( mw ) ;
2020-04-19 17:36:03 +00:00
}
catch ( Exception ) { }
dw . ShowDialog ( ) ;
Progress = 0 ;
2020-04-17 17:15:27 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-02 23:45:12 +00:00
}
2020-03-13 22:35:20 +00:00
public GameConsoles GetConsoleOfBase ( GameBases gb )
{
GameConsoles ret = new GameConsoles ( ) ;
bool cont = false ;
2022-07-14 18:17:37 +00:00
foreach ( GameBases b in lNDS )
2020-03-13 22:35:20 +00:00
{
2022-07-14 18:17:37 +00:00
if ( b . Name = = gb . Name & & b . Region = = gb . Region )
2020-03-13 22:35:20 +00:00
{
ret = GameConsoles . NDS ;
cont = true ;
}
}
if ( ! cont )
{
foreach ( GameBases b in lN64 )
{
2020-04-04 22:16:55 +00:00
if ( b . Name = = gb . Name & & b . Region = = gb . Region )
2020-03-13 22:35:20 +00:00
{
ret = GameConsoles . N64 ;
cont = true ;
}
}
}
if ( ! cont )
{
foreach ( GameBases b in lNES )
{
2020-04-04 22:16:55 +00:00
if ( b . Name = = gb . Name & & b . Region = = gb . Region )
2020-03-13 22:35:20 +00:00
{
ret = GameConsoles . NES ;
cont = true ;
}
}
}
if ( ! cont )
{
foreach ( GameBases b in lSNES )
2022-07-14 18:17:37 +00:00
{
if ( b . Name = = gb . Name & & b . Region = = gb . Region )
2020-03-13 22:35:20 +00:00
{
ret = GameConsoles . SNES ;
cont = true ;
}
}
}
if ( ! cont )
{
foreach ( GameBases b in lGBA )
{
2020-04-04 22:16:55 +00:00
if ( b . Name = = gb . Name & & b . Region = = gb . Region )
2020-03-13 22:35:20 +00:00
{
ret = GameConsoles . GBA ;
cont = true ;
}
}
}
2020-04-06 13:50:54 +00:00
if ( ! cont )
{
foreach ( GameBases b in lTG16 )
{
if ( b . Name = = gb . Name & & b . Region = = gb . Region )
{
ret = GameConsoles . TG16 ;
cont = true ;
}
}
}
2020-04-07 01:09:05 +00:00
if ( ! cont )
{
foreach ( GameBases b in lMSX )
{
if ( b . Name = = gb . Name & & b . Region = = gb . Region )
{
ret = GameConsoles . MSX ;
cont = true ;
}
}
}
2020-04-16 04:41:25 +00:00
if ( ! cont )
{
foreach ( GameBases b in lWii )
{
if ( b . Name = = gb . Name & & b . Region = = gb . Region )
{
ret = GameConsoles . WII ;
cont = true ;
}
}
}
2020-03-13 22:35:20 +00:00
return ret ;
}
2020-03-31 23:48:50 +00:00
public List < bool > getInfoOfBase ( GameBases gb )
{
List < bool > info = new List < bool > ( ) ;
2022-07-14 18:17:37 +00:00
if ( Directory . Exists ( $@"{Settings.Default.BasePath}\{gb.Name.Replace(" : ", " ")} [{gb.Region}]" ) )
2020-03-31 23:48:50 +00:00
{
info . Add ( true ) ;
}
else
{
info . Add ( false ) ;
}
if ( isKeySet ( gb ) )
{
info . Add ( true ) ;
}
else
{
info . Add ( false ) ;
}
if ( isCkeySet ( ) )
{
info . Add ( true ) ;
}
else
{
info . Add ( false ) ;
}
return info ;
}
2020-04-02 19:45:24 +00:00
2022-07-14 18:17:37 +00:00
2020-04-02 19:45:24 +00:00
public void SetInjectPath ( )
{
2020-04-20 09:31:26 +00:00
using ( var dialog = new CommonOpenFileDialog ( ) )
2020-04-02 19:45:24 +00:00
{
2020-04-20 09:31:26 +00:00
dialog . IsFolderPicker = true ;
2022-07-14 18:17:37 +00:00
CommonFileDialogResult result = dialog . ShowDialog ( ) ;
if ( result = = CommonFileDialogResult . Ok )
2020-04-02 19:45:24 +00:00
{
try
{
2020-04-20 09:31:26 +00:00
if ( DirectoryIsEmpty ( dialog . FileName ) )
2020-04-02 19:45:24 +00:00
{
2020-04-20 09:31:26 +00:00
Settings . Default . OutPath = dialog . FileName ;
2020-04-02 19:45:24 +00:00
Settings . Default . SetOutOnce = true ;
Settings . Default . Save ( ) ;
UpdatePathSet ( ) ;
}
else
{
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Information" , " Folder contains Files or Subfolders, do you really want to use this folder as the Inject Folder? " ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-17 16:02:45 +00:00
if ( choosefolder )
2020-04-02 19:45:24 +00:00
{
2020-04-17 16:02:45 +00:00
choosefolder = false ;
2020-04-20 09:31:26 +00:00
Settings . Default . OutPath = dialog . FileName ;
2020-04-02 19:45:24 +00:00
Settings . Default . SetOutOnce = true ;
Settings . Default . Save ( ) ;
UpdatePathSet ( ) ;
2020-04-17 16:02:45 +00:00
2020-04-02 19:45:24 +00:00
}
else
{
SetInjectPath ( ) ;
}
}
2022-07-14 18:17:37 +00:00
}
catch ( Exception e )
2020-04-02 19:45:24 +00:00
{
Console . WriteLine ( e . Message ) ;
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Error" , " An Error occured, please try again! " ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-02 19:45:24 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-02 19:45:24 +00:00
}
}
ArePathsSet ( ) ;
}
public void SetBasePath ( )
{
2020-04-20 09:31:26 +00:00
using ( var dialog = new CommonOpenFileDialog ( ) )
2020-04-02 19:45:24 +00:00
{
2020-04-20 09:31:26 +00:00
dialog . IsFolderPicker = true ;
CommonFileDialogResult result = dialog . ShowDialog ( ) ;
if ( result = = CommonFileDialogResult . Ok )
2020-04-02 19:45:24 +00:00
{
try
{
2020-04-20 09:31:26 +00:00
if ( DirectoryIsEmpty ( dialog . FileName ) )
2020-04-02 19:45:24 +00:00
{
2020-04-20 09:31:26 +00:00
Settings . Default . BasePath = dialog . FileName ;
2020-04-02 19:45:24 +00:00
Settings . Default . SetBaseOnce = true ;
Settings . Default . Save ( ) ;
UpdatePathSet ( ) ;
}
else
{
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Information" , " Folder contains Files or Subfolders, do you really want to use this folder as the Bases Folder? " ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-17 16:02:45 +00:00
if ( choosefolder )
2020-04-02 19:45:24 +00:00
{
2020-04-17 16:02:45 +00:00
choosefolder = false ;
2020-04-20 09:31:26 +00:00
Settings . Default . BasePath = dialog . FileName ;
2020-04-02 19:45:24 +00:00
Settings . Default . SetBaseOnce = true ;
Settings . Default . Save ( ) ;
UpdatePathSet ( ) ;
2020-04-20 09:31:26 +00:00
2020-04-02 19:45:24 +00:00
}
else
{
2020-04-20 09:31:26 +00:00
SetInjectPath ( ) ;
2020-04-02 19:45:24 +00:00
}
}
}
catch ( Exception e )
{
Console . WriteLine ( e . Message ) ;
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Error" , " An Error occured, please try again! " ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2020-04-02 19:45:24 +00:00
}
}
}
ArePathsSet ( ) ;
}
public void ArePathsSet ( )
{
if ( ValidatePathsStillExist ( ) )
{
2022-07-14 18:17:37 +00:00
Settings . Default . PathsSet = true ;
2020-04-02 19:45:24 +00:00
Settings . Default . Save ( ) ;
}
UpdatePathSet ( ) ;
}
public bool DirectoryIsEmpty ( string path )
{
int fileCount = Directory . GetFiles ( path ) . Length ;
if ( fileCount > 0 )
{
return false ;
}
string [ ] dirs = Directory . GetDirectories ( path ) ;
foreach ( string dir in dirs )
{
if ( ! DirectoryIsEmpty ( dir ) )
{
return false ;
}
}
return true ;
}
2022-07-14 15:25:28 +00:00
public void getBootIMGGBA ( string rom )
2020-04-17 01:51:56 +00:00
{
2020-04-21 19:52:52 +00:00
string repoid = "" ;
2020-04-21 20:54:32 +00:00
string SystemType = "gba/" ;
2020-04-21 19:52:52 +00:00
using ( var fs = new FileStream ( rom ,
FileMode . Open ,
FileAccess . Read ) )
{
2020-04-21 20:54:32 +00:00
byte [ ] procode = new byte [ 4 ] ;
fs . Seek ( 0xAC , SeekOrigin . Begin ) ;
fs . Read ( procode , 0 , 4 ) ;
2020-04-21 19:52:52 +00:00
repoid = ByteArrayToString ( procode ) ;
Regex rgx = new Regex ( "[^a-zA-Z0-9 -]" ) ;
repoid = rgx . Replace ( repoid , "" ) ;
Console . WriteLine ( "prodcode before scramble: " + repoid ) ;
fs . Close ( ) ;
Console . WriteLine ( "prodcode after scramble: " + repoid ) ;
}
2020-05-06 21:53:52 +00:00
List < string > repoids = new List < string > ( ) ;
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnectionWOWarning ( ) )
2020-04-21 19:52:52 +00:00
{
2020-05-06 21:53:52 +00:00
repoids . Add ( SystemType + repoid ) ;
repoids . Add ( SystemType + repoid . Substring ( 0 , 3 ) + "E" ) ;
repoids . Add ( SystemType + repoid . Substring ( 0 , 3 ) + "P" ) ;
repoids . Add ( SystemType + repoid . Substring ( 0 , 3 ) + "J" ) ;
2022-07-14 15:25:28 +00:00
2022-07-14 18:17:37 +00:00
GetRepoImages ( SystemType , repoid ) ;
2022-07-14 15:25:28 +00:00
checkForAdditionalFiles ( GameConsoles . GBA , repoids ) ;
2020-04-21 20:54:32 +00:00
}
}
2022-07-14 15:25:28 +00:00
public void getBootIMGSNES ( string rom )
2020-06-13 07:27:42 +00:00
{
string SystemType = "snes/" ;
2022-02-10 22:51:09 +00:00
var repoid = GetFakeSNESProdcode ( rom ) ;
List < string > repoids = new List < string >
{
SystemType + repoid
} ;
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnectionWOWarning ( ) )
2020-06-13 07:27:42 +00:00
{
2022-07-14 18:17:37 +00:00
GetRepoImages ( SystemType , repoid ) ;
2022-07-14 15:25:28 +00:00
checkForAdditionalFiles ( GameConsoles . SNES , repoids ) ;
2020-06-13 07:27:42 +00:00
}
}
2022-07-14 15:25:28 +00:00
public void getBootIMGMSX ( string rom )
2020-06-13 07:27:42 +00:00
{
string SystemType = "msx/" ;
2022-07-14 18:17:37 +00:00
var repoid = GetFakeMSXTGProdcode ( rom , true ) ;
List < string > repoids = new List < string >
{
SystemType + repoid
} ;
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnectionWOWarning ( ) )
2020-06-13 07:27:42 +00:00
{
2022-07-14 18:17:37 +00:00
GetRepoImages ( SystemType , repoid ) ;
2022-07-14 15:25:28 +00:00
checkForAdditionalFiles ( GameConsoles . MSX , repoids ) ;
2020-06-13 07:27:42 +00:00
}
}
2022-07-14 15:25:28 +00:00
public void getBootIMGTG ( string rom )
2020-06-13 07:27:42 +00:00
{
string SystemType = "tg16/" ;
2022-07-14 18:17:37 +00:00
var repoid = GetFakeMSXTGProdcode ( rom , false ) ;
List < string > repoids = new List < string >
{
SystemType + repoid
} ;
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnectionWOWarning ( ) )
2020-06-13 07:27:42 +00:00
{
2022-07-14 18:17:37 +00:00
GetRepoImages ( SystemType , repoid ) ;
2022-07-14 15:25:28 +00:00
checkForAdditionalFiles ( GameConsoles . TG16 , repoids ) ;
2020-06-13 07:27:42 +00:00
}
}
private string GetFakeMSXTGProdcode ( string v , bool msx )
{
Regex rgx = new Regex ( "[^a-zA-Z0-9 -]" ) ;
Regex rgx2 = new Regex ( "[^0-9]" ) ;
byte [ ] procode = new byte [ 0x210 ] ;
using ( var md5 = MD5 . Create ( ) )
{
using ( var fs = new FileStream ( v ,
FileMode . Open ,
2020-07-14 19:03:30 +00:00
FileAccess . Read ) )
2020-06-13 07:27:42 +00:00
{
fs . Read ( procode , 0 , 0x210 ) ;
fs . Close ( ) ;
}
string hash = GetMd5Hash ( md5 , procode ) ;
//var number = /*hash.GetHashCode();*/ gamename.GetHashCode();
if ( msx ) Console . Write ( "MSX" ) ;
else Console . Write ( "TG16" ) ;
Console . WriteLine ( " PRODCODE:" ) ;
Console . WriteLine ( "File Name: " + new FileInfo ( v ) . Name ) ;
Console . WriteLine ( "MD5 of Code Snippet: " + hash ) ;
string hashonlynumbers = rgx2 . Replace ( hash , "" ) ;
do
{
if ( hashonlynumbers . Length < 10 )
{
hashonlynumbers + = 0 ;
}
} while ( hashonlynumbers . Length < 10 ) ;
string first10 = new string ( new char [ ] { hashonlynumbers [ 0 ] , hashonlynumbers [ 1 ] , hashonlynumbers [ 2 ] , hashonlynumbers [ 3 ] , hashonlynumbers [ 4 ] , hashonlynumbers [ 5 ] , hashonlynumbers [ 6 ] , hashonlynumbers [ 7 ] , hashonlynumbers [ 8 ] } ) ;
string prodcode = getCodeOfNumbers ( Convert . ToInt32 ( first10 ) ) ;
if ( msx ) prodcode + = "SX" ;
else prodcode + = "TG" ;
//Console.WriteLine("NumberHash of GameName: "+ number);
Console . WriteLine ( "Fake ProdCode: " + prodcode ) ;
Console . WriteLine ( "---------------------------------------------------" ) ;
return prodcode ;
}
}
private string GetFakeSNESProdcode ( string path )
{
Regex rgx = new Regex ( "[^a-zA-Z0-9 -]" ) ;
Regex rgx2 = new Regex ( "[^0-9]" ) ;
using ( var md5 = MD5 . Create ( ) )
{
var name = new byte [ ] { } ;
using ( var fs = new FileStream ( path ,
FileMode . Open ,
2020-07-14 19:03:30 +00:00
FileAccess . Read ) )
2020-06-13 07:27:42 +00:00
{
byte [ ] procode = new byte [ 4 ] ;
fs . Seek ( 0x7FB2 , SeekOrigin . Begin ) ;
fs . Read ( procode , 0 , 4 ) ;
string repoid = ByteArrayToString ( procode ) ;
repoid = rgx . Replace ( repoid , "" ) ;
2022-09-29 03:55:05 +00:00
if ( repoid . Length < 4 )
2020-06-13 07:27:42 +00:00
{
fs . Seek ( 0xFFC0 , SeekOrigin . Begin ) ;
procode = new byte [ 21 ] ;
fs . Read ( procode , 0 , 21 ) ;
name = procode ;
2022-09-29 03:55:05 +00:00
repoid = ByteArrayToString ( procode ) ;
repoid = rgx . Replace ( repoid , "" ) ;
2020-06-13 07:27:42 +00:00
}
2022-09-29 03:55:05 +00:00
if ( repoid . Length < 4 )
{
2020-06-13 07:27:42 +00:00
fs . Seek ( 0x7FC0 , SeekOrigin . Begin ) ;
procode = new byte [ 21 ] ;
fs . Read ( procode , 0 , 21 ) ;
name = procode ;
}
}
string gamenameo = ByteArrayToString ( name ) ;
string gamename = rgx . Replace ( gamenameo , "" ) ;
string hash = GetMd5Hash ( md5 , gamename ) ;
//var number = /*hash.GetHashCode();*/ gamename.GetHashCode();
Console . WriteLine ( "SNES PRODCODE:" ) ;
Console . WriteLine ( "GameName: " + gamename ) ;
Console . WriteLine ( "MD5 of Name: " + hash ) ;
string hashonlynumbers = rgx2 . Replace ( hash , "" ) ;
do
{
if ( hashonlynumbers . Length < 10 )
{
hashonlynumbers + = 0 ;
}
} while ( hashonlynumbers . Length < 10 ) ;
string first10 = new string ( new char [ ] { hashonlynumbers [ 0 ] , hashonlynumbers [ 1 ] , hashonlynumbers [ 2 ] , hashonlynumbers [ 3 ] , hashonlynumbers [ 4 ] , hashonlynumbers [ 5 ] , hashonlynumbers [ 6 ] , hashonlynumbers [ 7 ] , hashonlynumbers [ 8 ] } ) ;
//Console.WriteLine("NumberHash of GameName: "+ number);
Console . WriteLine ( "Fake ProdCode: " + getCodeOfNumbers ( Convert . ToInt32 ( first10 ) ) ) ;
Console . WriteLine ( "---------------------------------------------------" ) ;
2022-07-14 18:17:37 +00:00
return getCodeOfNumbers ( Convert . ToInt32 ( first10 ) ) ;
2020-06-13 07:27:42 +00:00
// Console.WriteLine(md5.ComputeHash(name));
// Console.WriteLine("NumberCode: "+hash.GetHashCode());
}
}
2022-07-14 15:25:28 +00:00
public void getBootIMGNES ( string rom )
2020-06-13 07:27:42 +00:00
{
string SystemType = "nes/" ;
2022-07-14 18:17:37 +00:00
var repoid = GetFakeNESProdcode ( rom ) ;
List < string > repoids = new List < string >
{
SystemType + repoid
} ;
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnectionWOWarning ( ) )
2020-06-13 07:27:42 +00:00
{
2022-07-14 18:17:37 +00:00
GetRepoImages ( SystemType , repoid ) ;
2022-07-14 15:25:28 +00:00
checkForAdditionalFiles ( GameConsoles . NES , repoids ) ;
2020-06-13 07:27:42 +00:00
}
}
static string GetMd5Hash ( MD5 md5Hash , byte [ ] input )
{
// Convert the input string to a byte array and compute the hash.
byte [ ] data = md5Hash . ComputeHash ( input ) ;
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder ( ) ;
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for ( int i = 0 ; i < data . Length ; i + + )
{
sBuilder . Append ( data [ i ] . ToString ( "x2" ) ) ;
}
// Return the hexadecimal string.
return sBuilder . ToString ( ) ;
}
static string GetMd5Hash ( MD5 md5Hash , string input )
{
// Convert the input string to a byte array and compute the hash.
byte [ ] data = md5Hash . ComputeHash ( Encoding . UTF8 . GetBytes ( input ) ) ;
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder ( ) ;
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for ( int i = 0 ; i < data . Length ; i + + )
{
sBuilder . Append ( data [ i ] . ToString ( "x2" ) ) ;
}
// Return the hexadecimal string.
return sBuilder . ToString ( ) ;
}
private string GetFakeNESProdcode ( string path )
{
Regex rgx = new Regex ( "[^a-zA-Z0-9 -]" ) ;
Regex rgx2 = new Regex ( "[^0-9]" ) ;
byte [ ] procode = new byte [ 0xB0 ] ;
using ( var md5 = MD5 . Create ( ) )
{
using ( var fs = new FileStream ( path ,
FileMode . Open ,
2020-07-14 19:03:30 +00:00
FileAccess . Read ) )
2020-06-13 07:27:42 +00:00
{
fs . Seek ( 0x8000 , SeekOrigin . Begin ) ;
fs . Read ( procode , 0 , 0xB0 ) ;
fs . Close ( ) ;
}
string hash = GetMd5Hash ( md5 , procode ) ;
//var number = /*hash.GetHashCode();*/ gamename.GetHashCode();
Console . WriteLine ( "NES PRODCODE:" ) ;
Console . WriteLine ( "File Name: " + new FileInfo ( path ) . Name ) ;
Console . WriteLine ( "MD5 of Code Snippet: " + hash ) ;
string hashonlynumbers = rgx2 . Replace ( hash , "" ) ;
do
{
if ( hashonlynumbers . Length < 10 )
{
hashonlynumbers + = 0 ;
}
} while ( hashonlynumbers . Length < 10 ) ;
string first10 = new string ( new char [ ] { hashonlynumbers [ 0 ] , hashonlynumbers [ 1 ] , hashonlynumbers [ 2 ] , hashonlynumbers [ 3 ] , hashonlynumbers [ 4 ] , hashonlynumbers [ 5 ] , hashonlynumbers [ 6 ] , hashonlynumbers [ 7 ] , hashonlynumbers [ 8 ] } ) ;
//Console.WriteLine("NumberHash of GameName: "+ number);
Console . WriteLine ( "Fake ProdCode: " + getCodeOfNumbers ( Convert . ToInt32 ( first10 ) ) ) ;
Console . WriteLine ( "---------------------------------------------------" ) ;
return getCodeOfNumbers ( Convert . ToInt32 ( first10 ) ) ;
}
}
static string getCodeOfNumbers ( int number )
{
string ts = number . ToString ( ) ;
int n1 = Convert . ToInt32 ( ts [ 0 ] + ts [ 1 ] ) ;
int n2 = Convert . ToInt32 ( ts [ 2 ] + ts [ 3 ] ) ;
int n3 = Convert . ToInt32 ( ts [ 4 ] + ts [ 5 ] ) ;
2020-07-31 13:31:22 +00:00
int n4 ;
try
{
2022-07-14 18:17:37 +00:00
n4 = Convert . ToInt32 ( ts [ 6 ] + ts [ 7 ] ) ;
}
2022-10-01 21:40:01 +00:00
catch ( Exception )
2020-07-31 13:31:22 +00:00
{
2022-07-14 18:17:37 +00:00
n4 = Convert . ToInt32 ( ts [ 6 ] ) ;
2020-07-31 13:31:22 +00:00
}
2022-07-14 18:17:37 +00:00
2020-06-13 07:27:42 +00:00
char [ ] letters = new char [ ] { 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' } ;
while ( n1 > 23 )
{
n1 - = 23 ;
}
while ( n2 > 23 )
{
n2 - = 23 ;
}
while ( n3 > 23 )
{
n3 - = 23 ;
}
while ( n4 > 23 )
{
n4 - = 23 ;
}
var toret = new char [ ] { letters [ n1 ] , letters [ n2 ] , letters [ n3 ] , letters [ n4 ] } ;
return new string ( toret ) . ToUpper ( ) ;
}
2022-07-14 15:25:28 +00:00
public void getBootIMGNDS ( string rom )
2020-04-21 20:54:32 +00:00
{
string repoid = "" ;
string SystemType = "nds/" ;
using ( var fs = new FileStream ( rom ,
FileMode . Open ,
FileAccess . Read ) )
{
byte [ ] procode = new byte [ 4 ] ;
fs . Seek ( 0xC , SeekOrigin . Begin ) ;
fs . Read ( procode , 0 , 4 ) ;
repoid = ByteArrayToString ( procode ) ;
Regex rgx = new Regex ( "[^a-zA-Z0-9 -]" ) ;
repoid = rgx . Replace ( repoid , "" ) ;
Console . WriteLine ( "prodcode before scramble: " + repoid ) ;
fs . Close ( ) ;
Console . WriteLine ( "prodcode after scramble: " + repoid ) ;
}
2020-05-06 21:53:52 +00:00
List < string > repoids = new List < string > ( ) ;
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnectionWOWarning ( ) )
2020-04-21 20:54:32 +00:00
{
2020-05-06 21:53:52 +00:00
repoids . Add ( SystemType + repoid ) ;
repoids . Add ( SystemType + repoid . Substring ( 0 , 3 ) + "E" ) ;
repoids . Add ( SystemType + repoid . Substring ( 0 , 3 ) + "P" ) ;
repoids . Add ( SystemType + repoid . Substring ( 0 , 3 ) + "J" ) ;
2022-07-14 18:17:37 +00:00
GetRepoImages ( SystemType , repoid ) ;
2022-07-14 15:25:28 +00:00
checkForAdditionalFiles ( GameConsoles . NDS , repoids ) ;
2020-04-21 19:52:52 +00:00
}
}
2022-07-14 15:25:28 +00:00
public void getBootIMGN64 ( string rom )
2020-04-21 19:52:52 +00:00
{
string repoid = "" ;
string SystemType = "n64/" ;
2020-05-06 21:53:52 +00:00
List < string > repoids = new List < string > ( ) ;
2020-04-21 19:52:52 +00:00
using ( var fs = new FileStream ( rom ,
FileMode . Open ,
FileAccess . Read ) )
{
byte [ ] procode = new byte [ 6 ] ;
fs . Seek ( 0x3A , SeekOrigin . Begin ) ;
fs . Read ( procode , 0 , 6 ) ;
repoid = ByteArrayToString ( procode ) ;
Regex rgx = new Regex ( "[^a-zA-Z0-9 -]" ) ;
repoid = rgx . Replace ( repoid , "" ) ;
2022-07-14 18:17:37 +00:00
Console . WriteLine ( "prodcode before scramble: " + repoid ) ;
2020-04-21 19:52:52 +00:00
fs . Close ( ) ;
2022-07-14 18:17:37 +00:00
Console . WriteLine ( "prodcode after scramble: " + repoid ) ;
2020-04-21 19:52:52 +00:00
}
2022-07-14 15:25:28 +00:00
if ( CheckForInternetConnectionWOWarning ( ) )
2020-04-21 19:52:52 +00:00
{
2020-05-06 21:53:52 +00:00
repoids . Add ( SystemType + repoid ) ;
repoids . Add ( SystemType + new string ( new char [ ] { repoid [ 0 ] , repoid [ 2 ] , repoid [ 1 ] , repoid [ 3 ] } ) ) ;
2022-07-14 15:25:28 +00:00
2022-07-14 18:17:37 +00:00
GetRepoImages ( SystemType , repoid ) ;
2022-07-14 15:25:28 +00:00
checkForAdditionalFiles ( GameConsoles . N64 , repoids ) ;
2020-04-21 19:52:52 +00:00
}
}
private string ByteArrayToString ( byte [ ] arr )
{
System . Text . ASCIIEncoding enc = new System . Text . ASCIIEncoding ( ) ;
return enc . GetString ( arr ) ;
}
2022-07-04 18:39:02 +00:00
public string getInternalWIIGCNName ( string OpenGame , bool gc )
2020-04-21 19:52:52 +00:00
{
2020-04-17 01:51:56 +00:00
string ret = "" ;
2020-04-17 16:02:45 +00:00
try
2020-04-17 01:51:56 +00:00
{
2020-04-17 16:02:45 +00:00
using ( var reader = new BinaryReader ( File . OpenRead ( OpenGame ) ) )
2020-04-17 01:51:56 +00:00
{
2020-04-19 22:53:34 +00:00
string TempString = "" ;
2020-04-21 19:52:52 +00:00
string SystemType = "wii/" ;
2020-04-19 22:53:34 +00:00
if ( gc )
{
2020-04-21 19:52:52 +00:00
SystemType = "gcn/" ;
2020-04-19 22:53:34 +00:00
}
2022-07-14 18:17:37 +00:00
var repoid = "" ;
2020-04-17 16:02:45 +00:00
reader . BaseStream . Position = 0x00 ;
char TempChar ;
//WBFS Check
2020-05-06 21:53:52 +00:00
List < string > repoids = new List < string > ( ) ;
2020-04-17 16:02:45 +00:00
if ( new FileInfo ( OpenGame ) . Extension . Contains ( "wbfs" ) ) //Performs actions if the header indicates a WBFS file
{
2020-04-17 01:51:56 +00:00
2020-04-17 16:02:45 +00:00
reader . BaseStream . Position = 0x200 ;
reader . BaseStream . Position = 0x218 ;
reader . BaseStream . Position = 0x220 ;
2022-10-01 21:43:11 +00:00
while ( ( TempChar = reader . ReadChar ( ) ) ! = 0 ) ret + = TempChar ;
2020-04-19 22:53:34 +00:00
reader . BaseStream . Position = 0x200 ;
2022-10-01 21:43:11 +00:00
while ( ( TempChar = reader . ReadChar ( ) ) ! = 0 ) TempString + = TempChar ;
2022-07-14 18:17:37 +00:00
repoid = TempString ;
2020-04-17 16:02:45 +00:00
}
else
{
2020-04-17 01:51:56 +00:00
reader . BaseStream . Position = 0x18 ;
2020-04-17 16:02:45 +00:00
2020-04-17 01:51:56 +00:00
reader . BaseStream . Position = 0x20 ;
2022-10-01 21:43:11 +00:00
while ( ( TempChar = reader . ReadChar ( ) ) ! = 0 ) ret + = TempChar ;
2020-04-19 22:53:34 +00:00
reader . BaseStream . Position = 0x00 ;
2022-10-01 21:43:11 +00:00
while ( ( TempChar = reader . ReadChar ( ) ) ! = 0 ) TempString + = TempChar ;
2022-07-14 18:17:37 +00:00
repoid = TempString ;
}
2020-05-06 21:53:52 +00:00
2022-07-14 18:17:37 +00:00
if ( CheckForInternetConnectionWOWarning ( ) )
{
repoids . Add ( SystemType + repoid ) ;
repoids . Add ( SystemType + repoid . Substring ( 0 , 3 ) + "E" + repoid . Substring ( 4 , 2 ) ) ;
repoids . Add ( SystemType + repoid . Substring ( 0 , 3 ) + "P" + repoid . Substring ( 4 , 2 ) ) ;
repoids . Add ( SystemType + repoid . Substring ( 0 , 3 ) + "J" + repoid . Substring ( 4 , 2 ) ) ;
2020-04-17 16:02:45 +00:00
2022-07-14 18:17:37 +00:00
GetRepoImages ( SystemType , repoid , repoids ) ;
checkForAdditionalFiles ( test = = GameConsoles . GCN ? GameConsoles . GCN : GameConsoles . WII , repoids ) ;
2020-04-17 16:02:45 +00:00
}
2020-04-17 01:51:56 +00:00
}
2022-07-14 18:17:37 +00:00
}
catch ( Exception )
2020-04-17 16:02:45 +00:00
{
2020-06-13 18:34:54 +00:00
Custom_Message cm = new Custom_Message ( "Unknown ROM" , " It seems that you inserted an unknown ROM as a Wii or GameCube game. \n It is not recommended continuing with said ROM!" ) ;
2020-04-18 03:31:36 +00:00
try
{
cm . Owner = mw ;
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2022-07-14 18:17:37 +00:00
2020-04-17 01:51:56 +00:00
}
2022-07-14 18:17:37 +00:00
2020-04-17 01:51:56 +00:00
return ret ;
}
2022-07-14 15:25:28 +00:00
public bool CheckForInternetConnection ( )
2020-04-19 17:36:03 +00:00
{
try
{
using ( var client = new WebClient ( ) )
2022-07-14 15:25:28 +00:00
using ( client . OpenRead ( "http://google.com/generate_204" ) )
return true ;
2020-04-19 17:36:03 +00:00
}
catch
{
2022-07-14 15:25:28 +00:00
Custom_Message cm = new Custom_Message ( "No Internet Connection" , " To Download Tools, Bases or required Files you need to be connected to the Internet. The Program will now terminate. " ) ;
2020-04-19 17:36:03 +00:00
try
{
cm . Owner = mw ;
2022-07-14 18:17:37 +00:00
2020-04-19 17:36:03 +00:00
}
catch ( Exception ) { }
cm . ShowDialog ( ) ;
2022-07-14 15:25:28 +00:00
Environment . Exit ( 1 ) ;
return false ;
2020-04-19 17:36:03 +00:00
}
}
2022-07-14 15:25:28 +00:00
public bool CheckForInternetConnectionWOWarning ( )
2020-04-19 17:36:03 +00:00
{
try
{
using ( var client = new WebClient ( ) )
2022-07-14 15:25:28 +00:00
using ( client . OpenRead ( "http://google.com/generate_204" ) )
2020-04-19 17:36:03 +00:00
return true ;
}
catch
{
2022-07-14 18:17:37 +00:00
2020-04-19 17:36:03 +00:00
return false ;
}
}
2022-07-14 15:25:28 +00:00
private void checkForAdditionalFiles ( GameConsoles console , List < string > repoids )
2020-05-06 21:53:52 +00:00
{
2020-10-02 00:38:48 +00:00
if ( ! Directory . Exists ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" ) ) )
2020-05-06 21:53:52 +00:00
{
2020-10-02 00:38:48 +00:00
Directory . CreateDirectory ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" ) ) ;
2020-05-06 21:53:52 +00:00
}
bool ini = false ;
bool btsnd = false ;
string inip = "" ;
string btsndp = "" ;
string exten = "" ;
2023-05-01 03:02:26 +00:00
string linkbase = "https://raw.githubusercontent.com/UWUVCI-PRIME/UWUVCI-IMAGES/master/" ;
2020-05-06 21:53:52 +00:00
if ( console = = GameConsoles . N64 )
{
2022-07-14 18:17:37 +00:00
foreach ( string repoid in repoids )
2020-05-06 21:53:52 +00:00
{
2022-07-14 15:25:28 +00:00
if ( RemoteFileExists ( linkbase + repoid + "/game.ini" ) )
2020-05-06 21:53:52 +00:00
{
ini = true ;
inip = linkbase + repoid + "/game.ini" ;
break ;
}
}
2022-07-14 18:17:37 +00:00
2020-05-06 21:53:52 +00:00
}
string [ ] ext = { "btsnd" } ;
foreach ( var e in ext )
2022-07-14 18:17:37 +00:00
{
foreach ( string repoid in repoids )
2020-05-06 21:53:52 +00:00
{
2022-07-14 15:25:28 +00:00
if ( RemoteFileExists ( linkbase + repoid + "/BootSound." + e ) )
2020-05-06 21:53:52 +00:00
{
btsnd = true ;
btsndp = linkbase + repoid + "/BootSound." + e ;
exten = e ;
break ;
}
if ( btsnd )
{
break ;
}
2022-07-14 18:17:37 +00:00
2020-05-06 21:53:52 +00:00
}
2022-07-14 18:17:37 +00:00
2020-05-06 21:53:52 +00:00
}
if ( ini | | btsnd )
{
2020-06-13 18:34:54 +00:00
string extra = " There are more additional files found. Do you want to download those? " ;
if ( ini & & ! btsnd ) { extra = " There is an additional INI file available for download. Do you want to download it? " ; }
if ( ! ini & & btsnd ) { extra = " There is an additional BootSound file available for download. Do you want to download it? " ; }
if ( ini & & btsnd ) { extra = " There is an adittional INI and BootSound file available for download. Do you want to download those? " ; }
2022-07-14 18:17:37 +00:00
2020-05-06 21:53:52 +00:00
Custom_Message cm = new Custom_Message ( "Found additional Files" , extra ) ;
try
{
cm . Owner = mw ;
}
catch ( Exception )
{
}
cm . ShowDialog ( ) ;
if ( addi )
{
var client = new WebClient ( ) ;
if ( ini )
{
2020-10-02 00:38:48 +00:00
client . DownloadFile ( inip , Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , "game.ini" ) ) ;
( Thing as N64Config ) . ini . Text = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , "game.ini" ) ;
GameConfiguration . N64Stuff . INIPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , "game.ini" ) ;
2020-05-06 21:53:52 +00:00
}
if ( btsnd )
{
2020-10-02 00:38:48 +00:00
client . DownloadFile ( btsndp , Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , $"bootSound.{exten}" ) ) ;
BootSound = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , $"bootSound.{exten}" ) ;
2020-05-06 21:53:52 +00:00
switch ( console )
{
case GameConsoles . NDS :
2020-06-13 07:27:42 +00:00
case GameConsoles . NES :
case GameConsoles . SNES :
case GameConsoles . MSX :
2020-10-02 00:38:48 +00:00
( Thing as OtherConfigs ) . sound . Text = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , $"bootSound.{exten}" ) ;
2020-05-06 21:53:52 +00:00
break ;
case GameConsoles . GBA :
2020-10-02 00:38:48 +00:00
( Thing as GBA ) . sound . Text = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , $"bootSound.{exten}" ) ;
2020-05-06 21:53:52 +00:00
break ;
case GameConsoles . N64 :
2020-10-02 00:38:48 +00:00
( Thing as N64Config ) . sound . Text = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , $"bootSound.{exten}" ) ;
2020-05-06 21:53:52 +00:00
break ;
case GameConsoles . WII :
if ( test = = GameConsoles . GCN )
{
2020-10-02 00:38:48 +00:00
( Thing as GCConfig ) . sound . Text = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , $"bootSound.{exten}" ) ;
2020-05-06 21:53:52 +00:00
}
else
{
2020-10-02 00:38:48 +00:00
( Thing as WiiConfig ) . sound . Text = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , $"bootSound.{exten}" ) ;
2020-05-06 21:53:52 +00:00
}
break ;
2020-06-13 07:27:42 +00:00
case GameConsoles . TG16 :
2020-10-02 00:38:48 +00:00
( Thing as TurboGrafX ) . sound . Text = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "repo" , $"bootSound.{exten}" ) ;
2020-06-13 07:27:42 +00:00
break ;
2020-05-06 21:53:52 +00:00
}
}
addi = false ;
}
}
}
2020-04-28 23:40:54 +00:00
public string GetURL ( string console )
{
2022-10-01 21:43:11 +00:00
string url ;
2022-07-14 18:17:37 +00:00
switch ( console . ToLower ( ) )
{
case "nds" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resources/nds/nds.html" ;
2022-07-14 18:17:37 +00:00
break ;
case "n64" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resourcesn64/n64.html" ;
2022-07-14 18:17:37 +00:00
break ;
case "nes" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resources/nes/nes.html" ;
2022-07-14 18:17:37 +00:00
break ;
case "snes" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resources/snes/snes.html" ;
2022-07-14 18:17:37 +00:00
break ;
case "gba" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resources/gba/gba.html" ;
2022-07-14 18:17:37 +00:00
break ;
case "tg16" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resources/tgfx/tgfx.html" ;
2022-07-14 18:17:37 +00:00
break ;
case "tgcd" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resources/tgfx/tgfx.html" ;
2022-07-14 18:17:37 +00:00
break ;
case "msx" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resources/msx/msx.html" ;
2022-07-14 18:17:37 +00:00
break ;
case "wii" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resources/wii/wii.html" ;
2022-07-14 18:17:37 +00:00
break ;
case "gcn" :
2023-05-01 03:02:26 +00:00
url = @"https://uwuvci-prime.github.io/UWUVCI-Resources/gcn/gcn.html" ;
2022-07-14 18:17:37 +00:00
break ;
default :
url = null ;
break ;
}
2020-12-27 13:53:41 +00:00
return url ;
2022-07-14 18:17:37 +00:00
2020-04-28 23:40:54 +00:00
}
2022-07-14 18:17:37 +00:00
WaveOutEvent waveOutEvent = new WaveOutEvent ( ) ;
2020-04-30 15:01:41 +00:00
AudioFileReader audioFileReader ;
public System . Timers . Timer t ;
2020-06-05 11:02:11 +00:00
public bool passtrough = true ;
2020-08-11 19:35:17 +00:00
internal bool enableWii = true ;
internal bool backupenableWii = true ;
2020-04-30 15:01:41 +00:00
public void PlaySound ( )
{
2022-07-14 18:17:37 +00:00
2020-04-30 15:01:41 +00:00
Task ts = new Task ( ( ) = >
{
try
{
t = new System . Timers . Timer ( 200 ) ;
t . Elapsed + = isDone ;
audioFileReader = new AudioFileReader ( BootSound ) ;
waveOutEvent . Init ( audioFileReader ) ;
t . Start ( ) ;
Console . WriteLine ( "Playing file.." ) ;
waveOutEvent . Play ( ) ;
}
catch ( Exception )
{
}
2022-07-14 18:17:37 +00:00
2020-04-30 15:01:41 +00:00
} ) ;
ts . Start ( ) ;
}
public void isDoneMW ( )
{
try
{
2022-07-14 18:17:37 +00:00
if ( waveOutEvent ! = null & & audioFileReader ! = null )
2020-04-30 15:01:41 +00:00
{
waveOutEvent . Stop ( ) ;
waveOutEvent . Dispose ( ) ;
audioFileReader . Dispose ( ) ;
t . Stop ( ) ;
}
2022-07-14 18:17:37 +00:00
2020-04-30 15:01:41 +00:00
}
catch ( Exception )
{
}
}
public void isDone ( Object source , ElapsedEventArgs e )
{
try
{
2022-07-14 18:17:37 +00:00
if ( waveOutEvent . PlaybackState = = PlaybackState . Stopped )
2020-04-30 15:01:41 +00:00
{
waveOutEvent . Dispose ( ) ;
audioFileReader . Dispose ( ) ;
t . Stop ( ) ;
}
if ( waveOutEvent . GetPositionTimeSpan ( ) > TimeSpan . FromSeconds ( 6 ) )
{
waveOutEvent . Stop ( ) ;
waveOutEvent . Dispose ( ) ;
audioFileReader . Dispose ( ) ;
t . Stop ( ) ;
}
}
catch ( Exception )
{
}
}
2020-06-24 15:54:51 +00:00
public void RestartIntoBypass ( )
{
2022-07-14 18:17:37 +00:00
using ( Process p = new Process ( ) )
2020-06-24 15:54:51 +00:00
{
p . StartInfo . FileName = System . Windows . Application . ResourceAssembly . Location ;
if ( debug )
{
if ( saveworkaround )
{
p . StartInfo . Arguments = "--debug --skip --spacebypass" ;
}
else
{
p . StartInfo . Arguments = "--debug --skip" ;
}
}
else
{
if ( saveworkaround )
{
p . StartInfo . Arguments = "--skip --spacebypass" ;
}
else
{
p . StartInfo . Arguments = "--skip" ;
}
}
p . Start ( ) ;
Environment . Exit ( 0 ) ;
}
2022-07-14 18:17:37 +00:00
2020-06-24 15:54:51 +00:00
}
2022-07-14 18:17:37 +00:00
2022-02-10 22:51:09 +00:00
/// <param name="SystemType"></param>
2022-07-14 15:25:28 +00:00
/// <param name="repoid"></param>
2022-07-14 18:17:37 +00:00
/// <param name="repoids"></param>
private void GetRepoImages ( string SystemType , string repoid , List < string > repoids = null )
2022-02-10 22:51:09 +00:00
{
2023-05-01 03:02:26 +00:00
string linkbase = "https://raw.githubusercontent.com/UWUVCI-PRIME/UWUVCI-IMAGES/master/" ;
2022-07-18 22:13:17 +00:00
string [ ] ext = { "png" , "jpg" , "jpeg" , "tga" } ;
2022-02-10 22:51:09 +00:00
2022-07-14 18:17:37 +00:00
if ( repoids = = null | | repoids ? . Count = = 0 )
{
var fakeId = new string ( new char [ ] { repoid [ 0 ] , repoid [ 2 ] , repoid [ 1 ] , repoid [ 3 ] } ) ;
repoids = new List < string >
{
SystemType + repoid ,
SystemType + repoid . Substring ( 0 , 3 ) + "E" ,
SystemType + repoid . Substring ( 0 , 3 ) + "P" ,
SystemType + repoid . Substring ( 0 , 3 ) + "J" ,
SystemType + fakeId ,
SystemType + fakeId . Substring ( 0 , 3 ) + "E" ,
SystemType + fakeId . Substring ( 0 , 3 ) + "P" ,
SystemType + fakeId . Substring ( 0 , 3 ) + "J"
} ;
}
2022-02-10 22:51:09 +00:00
foreach ( var e in ext )
{
2022-07-14 18:17:37 +00:00
foreach ( var id in repoids )
2022-02-10 22:51:09 +00:00
{
2022-07-14 18:17:37 +00:00
if ( RemoteFileExists ( linkbase + id + $"/iconTex.{e}" ) = = true )
2022-02-10 22:51:09 +00:00
{
2022-07-18 22:13:17 +00:00
if ( e . Contains ( "tga" ) )
{
2023-05-01 03:02:26 +00:00
var message = new Custom_Message ( "TGA Extension Warning" , "TGA files can't natively be rendered in UWUVCI, instead it will say something along the lines of the image not being able to be shown.\nThis is correct and is normal behavior.\n\nIf there are actual errors then grab the files from \"https://github.com/UWUVCI-PRIME/UWUVCI-IMAGES\", convert them to png, and then manually insert them." ) ;
2022-07-18 22:13:17 +00:00
try
{
message . Owner = mw ;
}
catch ( Exception )
{
}
message . ShowDialog ( ) ;
}
2022-10-01 21:43:11 +00:00
var img = new IMG_Message ( linkbase + id + $"/iconTex.{e}" , linkbase + id + $"/bootTvTex.{e}" , id ) ;
2022-07-14 18:17:37 +00:00
try
{
img . Owner = mw ;
}
catch ( Exception ) { }
img . ShowDialog ( ) ;
return ;
2022-02-10 22:51:09 +00:00
}
}
}
}
2020-03-01 15:07:22 +00:00
}
2022-07-14 18:17:37 +00:00
}