2020-04-02 23:45:12 +00:00
using GameBaseClassLibrary ;
2020-04-25 06:40:38 +00:00
using NAudio.Wave ;
2020-04-02 23:45:12 +00:00
using System ;
2020-04-04 22:16:55 +00:00
using System.Collections.Generic ;
2020-03-01 13:45:00 +00:00
using System.Diagnostics ;
using System.IO ;
using System.IO.Compression ;
2020-04-21 02:05:19 +00:00
using System.Linq ;
2020-04-19 17:36:03 +00:00
using System.Net ;
2020-05-30 22:35:01 +00:00
using System.Runtime.CompilerServices ;
using System.Runtime.InteropServices ;
2020-03-01 13:45:00 +00:00
using System.Text ;
2020-04-22 00:24:35 +00:00
using System.Text.RegularExpressions ;
2020-04-17 01:28:14 +00:00
using System.Threading ;
2020-04-18 03:31:36 +00:00
using System.Threading.Tasks ;
2020-04-04 22:16:55 +00:00
using System.Windows ;
2020-05-30 22:35:01 +00:00
using System.Windows.Forms ;
using System.Windows.Media.Imaging ;
2020-04-18 03:31:36 +00:00
using System.Windows.Threading ;
2020-03-01 13:45:00 +00:00
using System.Xml ;
2020-04-02 23:45:12 +00:00
using UWUVCI_AIO_WPF.Classes ;
2020-03-01 13:45:00 +00:00
using UWUVCI_AIO_WPF.Properties ;
2020-04-16 04:41:25 +00:00
using UWUVCI_AIO_WPF.UI.Windows ;
2020-05-30 22:35:01 +00:00
using MessageBox = System . Windows . MessageBox ;
2020-03-01 13:45:00 +00:00
2020-03-01 13:45:18 +00:00
namespace UWUVCI_AIO_WPF
2020-03-01 13:45:00 +00:00
{
2020-05-30 22:35:01 +00:00
2020-03-01 13:45:00 +00:00
internal static class Injection
{
2020-05-30 22:35:01 +00:00
[DllImport("User32.dll")]
static extern int SetForegroundWindow ( IntPtr point ) ;
[DllImport("user32.dll")]
public static extern int SendMessage (
int hWnd , // handle to destination window
uint Msg , // message
long wParam , // first message parameter
long lParam // second message parameter
) ;
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage ( IntPtr hWnd , int Msg , System . Windows . Forms . Keys wParam , int lParam ) ;
2020-06-11 08:12:03 +00:00
private static Int32 WM_KEYUP = 0x101 ;
2020-04-17 01:28:14 +00:00
private static readonly string tempPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "temp" ) ;
2020-03-01 13:45:00 +00:00
private static readonly string baseRomPath = Path . Combine ( tempPath , "baserom" ) ;
private static readonly string imgPath = Path . Combine ( tempPath , "img" ) ;
2020-04-17 01:28:14 +00:00
private static readonly string toolsPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" , "Tools" ) ;
2020-04-16 04:41:25 +00:00
static string code = null ;
2020-04-16 18:52:26 +00:00
static MainViewModel mvvm ;
2020-03-01 13:45:00 +00:00
/ *
2020-04-06 15:51:15 +00:00
* GameConsole : Can either be NDS , N64 , GBA , NES , SNES or TG16
2020-03-01 13:45:00 +00:00
* baseRom = Name of the BaseRom , which is the folder name too ( example : Super Metroid EU will be saved at the BaseRom path under the folder SMetroidEU , so the BaseRom is in this case SMetroidEU ) .
* customBasePath = Path to the custom Base . Is null if no custom base is used .
* injectRomPath = Path to the Rom to be injected into the Base Game .
* bootImages = String array containing the paths for
* bootTvTex : PNG or TGA ( PNG gets converted to TGA using UPNG ) . Needs to be in the dimensions 1280 x720 and have a bit depth of 24. If null , the original BootImage will be used .
* bootDrcTex : PNG or TGA ( PNG gets converted to TGA using UPNG ) . Needs to be in the dimensions 854 x480 and have a bit depth of 24. If null , the original BootImage will be used .
* iconTex : PNG or TGA ( PNG gets converted to TGA using UPNG ) . Needs to be in the dimensions 128 x128 and have a bit depth of 32. If null , the original BootImage will be used .
* bootLogoTex : PNG or TGA ( PNG gets converted to TGA using UPNG ) . Needs to be in the dimensions 170 x42 and have a bit depth of 32. If null , the original BootImage will be used .
* gameName = The name of the final game to be entered into the . xml files .
* iniPath = Only used for N64 . Path to the INI configuration . If "blank" , a blank ini will be used .
* darkRemoval = Only used for N64 . Indicates whether the dark filter should be removed .
* /
2020-04-21 02:05:19 +00:00
static List < int > fiind ( this byte [ ] buffer , byte [ ] pattern , int startIndex )
{
List < int > positions = new List < int > ( ) ;
int i = Array . IndexOf < byte > ( buffer , pattern [ 0 ] , startIndex ) ;
while ( i > = 0 & & i < = buffer . Length - pattern . Length )
{
byte [ ] segment = new byte [ pattern . Length ] ;
Buffer . BlockCopy ( buffer , i , segment , 0 , pattern . Length ) ;
if ( segment . SequenceEqual < byte > ( pattern ) )
positions . Add ( i ) ;
i = Array . IndexOf < byte > ( buffer , pattern [ 0 ] , i + 1 ) ;
}
return positions ;
}
static void PokePatch ( string rom )
{
byte [ ] search = { 0xD0 , 0x88 , 0x8D , 0x83 , 0x42 } ;
byte [ ] test ;
test = new byte [ new FileInfo ( rom ) . Length ] ;
using ( var fs = new FileStream ( rom ,
FileMode . Open ,
FileAccess . ReadWrite ) )
{
try
{
fs . Read ( test , 0 , test . Length - 1 ) ;
var l = fiind ( test , search , 0 ) ;
byte [ ] check = new byte [ 4 ] ;
fs . Seek ( l [ 0 ] + 5 , SeekOrigin . Begin ) ;
fs . Read ( check , 0 , 4 ) ;
fs . Seek ( 0 , SeekOrigin . Begin ) ;
if ( check [ 3 ] ! = 0x24 )
{
fs . Seek ( l [ 0 ] + 5 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x00 , 0x00 , 0x00 , 0x00 } , 0 , 4 ) ;
}
else
{
fs . Seek ( l [ 0 ] + 5 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x00 , 0x00 , 0x00 } , 0 , 3 ) ;
}
check = new byte [ 4 ] ;
fs . Seek ( l [ 1 ] + 5 , SeekOrigin . Begin ) ;
fs . Read ( check , 0 , 4 ) ;
fs . Seek ( 0 , SeekOrigin . Begin ) ;
if ( check [ 3 ] ! = 0x24 )
{
fs . Seek ( l [ 1 ] + 5 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x00 , 0x00 , 0x00 , 0x00 } , 0 , 4 ) ;
}
else
{
fs . Seek ( l [ 1 ] + 5 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x00 , 0x00 , 0x00 } , 0 , 3 ) ;
}
}
2020-06-11 08:12:03 +00:00
catch ( Exception )
2020-04-21 02:05:19 +00:00
{
}
fs . Close ( ) ;
}
}
2020-04-19 17:36:03 +00:00
private static string FormatBytes ( long bytes )
{
string [ ] Suffix = { "B" , "KB" , "MB" , "GB" , "TB" } ;
int i ;
double dblSByte = bytes ;
for ( i = 0 ; i < Suffix . Length & & bytes > = 1024 ; i + + , bytes / = 1024 )
{
dblSByte = bytes / 1024.0 ;
}
2020-04-18 03:31:36 +00:00
2020-04-19 17:36:03 +00:00
return String . Format ( "{0:0.##} {1}" , dblSByte , Suffix [ i ] ) ;
}
2020-04-17 01:28:14 +00:00
[STAThread]
2020-04-16 04:41:25 +00:00
public static bool Inject ( GameConfig Configuration , string RomPath , MainViewModel mvm , bool force )
2020-04-04 22:16:55 +00:00
{
2020-05-30 22:35:01 +00:00
2020-04-19 17:36:03 +00:00
Clean ( ) ;
long gamesize = new FileInfo ( RomPath ) . Length ;
var drive = new DriveInfo ( tempPath ) ;
long neededspace = 0 ;
long freeSpaceInBytes = drive . AvailableFreeSpace ;
2020-04-16 18:52:26 +00:00
mvvm = mvm ;
2020-04-18 03:31:36 +00:00
2020-04-20 09:31:26 +00:00
if ( Directory . Exists ( tempPath ) )
{
Directory . Delete ( tempPath , true ) ;
}
2020-04-16 04:41:25 +00:00
Directory . CreateDirectory ( tempPath ) ;
2020-04-18 03:31:36 +00:00
2020-04-16 18:52:26 +00:00
mvm . msg = "Checking Tools..." ;
2020-04-10 20:23:49 +00:00
mvm . InjcttoolCheck ( ) ;
2020-04-16 18:52:26 +00:00
mvm . Progress = 5 ;
2020-04-18 03:31:36 +00:00
2020-04-16 18:52:26 +00:00
mvm . msg = "Copying Base..." ;
2020-04-06 15:51:15 +00:00
try
2020-04-04 22:16:55 +00:00
{
2020-04-19 17:36:03 +00:00
if ( Configuration . Console = = GameConsoles . WII | | Configuration . Console = = GameConsoles . GCN )
{
2020-04-10 18:48:12 +00:00
2020-04-19 17:36:03 +00:00
if ( mvm . GC )
{
neededspace = 10000000000 ;
}
else
{
2020-04-22 00:24:35 +00:00
neededspace = 15000000000 ;
2020-04-19 17:36:03 +00:00
}
if ( freeSpaceInBytes < neededspace )
{
throw new Exception ( "12G" ) ;
}
}
2020-04-20 09:31:26 +00:00
if ( Configuration . BaseRom = = null | | Configuration . BaseRom . Name = = null )
{
throw new Exception ( "BASE" ) ;
}
2020-04-06 15:51:15 +00:00
if ( Configuration . BaseRom . Name ! = "Custom" )
{
//Normal Base functionality here
CopyBase ( $"{Configuration.BaseRom.Name.Replace(" : ", " ")} [{Configuration.BaseRom.Region.ToString()}]" , null ) ;
}
else
{
//Custom Base Functionality here
CopyBase ( $"Custom" , Configuration . CBasePath ) ;
}
2020-04-16 18:52:26 +00:00
mvm . Progress = 10 ;
mvm . msg = "Injecting ROM..." ;
2020-04-16 04:41:25 +00:00
if ( mvm . GC )
{
RunSpecificInjection ( Configuration , GameConsoles . GCN , RomPath , force , mvm ) ;
}
else
{
RunSpecificInjection ( Configuration , Configuration . Console , RomPath , force , mvm ) ;
}
2020-04-16 18:52:26 +00:00
mvm . msg = "Editing XML..." ;
2020-04-16 04:41:25 +00:00
EditXML ( Configuration . GameName , mvm . Index , code ) ;
2020-04-16 18:52:26 +00:00
mvm . Progress = 90 ;
mvm . msg = "Changing Images..." ;
2020-04-06 15:51:15 +00:00
Images ( Configuration ) ;
2020-04-25 06:40:38 +00:00
if ( File . Exists ( mvm . BootSound ) )
{
mvm . Progress = 95 ;
mvm . msg = "Adding BootSound..." ;
bootsound ( mvm . BootSound ) ;
}
2020-04-16 18:52:26 +00:00
mvm . Progress = 100 ;
2020-04-17 01:28:14 +00:00
2020-04-16 04:41:25 +00:00
code = null ;
2020-04-06 15:51:15 +00:00
return true ;
} catch ( Exception e )
2020-04-04 22:16:55 +00:00
{
2020-04-17 16:02:45 +00:00
mvm . Progress = 100 ;
2020-04-19 17:36:03 +00:00
2020-04-16 04:41:25 +00:00
code = null ;
2020-04-06 15:51:15 +00:00
if ( e . Message . Contains ( "Images" ) ) {
2020-05-30 22:35:01 +00:00
2020-04-19 17:36:03 +00:00
MessageBox . Show ( "Injection Failed due to wrong BitDepth, please check if your Files are in a different bitdepth than 32bit or 24bit" , "Injection Failed" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
2020-04-06 15:51:15 +00:00
}
else if ( e . Message . Contains ( "Size" ) )
{
2020-04-19 17:36:03 +00:00
MessageBox . Show ( "Injection Failed due to Image Issues.Please check if your Images are made using following Information:\n\niconTex: \nDimensions: 128x128\nBitDepth: 32\n\nbootDrcTex: \nDimensions: 854x480\nBitDepth: 24\n\nbootTvTex: \nDimensions: 1280x720\nBitDepth: 24\n\nbootLogoTex: \nDimensions: 170x42\nBitDepth: 32" , "Injection Failed" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
2020-04-17 16:02:45 +00:00
2020-04-06 15:51:15 +00:00
}
2020-04-08 21:48:11 +00:00
else if ( e . Message . Contains ( "retro" ) )
{
2020-04-19 17:36:03 +00:00
MessageBox . Show ( "The ROM you want to Inject is to big for selected Base!\nPlease try again with different Base" , "Injection Failed" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
2020-04-17 16:02:45 +00:00
}
2020-04-20 09:31:26 +00:00
else if ( e . Message . Contains ( "BASE" ) )
{
MessageBox . Show ( "If you import a config you NEED to reselect a base" , "Injection Failed" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
}
2020-04-17 16:02:45 +00:00
else if ( e . Message . Contains ( "WII" ) )
{
2020-04-19 17:36:03 +00:00
MessageBox . Show ( $"{e.Message.Replace(" WII ", " ")}\nPlease make sure that your ROM isn't flawed and that you have atleast 12 GB of free Storage left." , "Injection Failed" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
}
else if ( e . Message . Contains ( "12G" ) )
{
2020-04-22 00:24:35 +00:00
MessageBox . Show ( $"\nPlease make sure to have atleast {FormatBytes(15000000000)} of storage left on the drive where you stored the Injector." , "Injection Failed" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
} else if ( e . Message . Contains ( "nkit" ) )
{
MessageBox . Show ( $"\nPlease make sure that you have a genuine NKIT ROM." , "Injection Failed" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
2020-04-08 21:48:11 +00:00
}
2020-04-06 15:51:15 +00:00
else
{
2020-04-19 17:36:03 +00:00
MessageBox . Show ( "Injection Failed due to unknown circumstances, please contact us on the UWUVCI discord" , "Injection Failed" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
2020-04-06 15:51:15 +00:00
}
2020-04-08 21:48:11 +00:00
Clean ( ) ;
2020-04-06 15:51:15 +00:00
return false ;
2020-04-04 22:16:55 +00:00
}
2020-04-16 04:41:25 +00:00
finally
{
2020-04-17 16:02:45 +00:00
2020-04-16 04:41:25 +00:00
mvm . Index = - 1 ;
mvm . LR = false ;
2020-04-17 01:28:14 +00:00
mvm . msg = "" ;
2020-04-18 03:31:36 +00:00
2020-04-16 04:41:25 +00:00
}
2020-04-06 15:51:15 +00:00
2020-04-04 22:16:55 +00:00
}
2020-05-30 22:35:01 +00:00
public static void SendKey ( IntPtr hWnd , System . Windows . Forms . Keys key )
{
PostMessage ( hWnd , WM_KEYUP , key , 0 ) ;
}
2020-04-25 06:40:38 +00:00
static void bootsound ( string sound )
{
FileInfo soundFile = new FileInfo ( sound ) ;
if ( soundFile . Extension . Contains ( "mp3" ) | | soundFile . Extension . Contains ( "wav" ) )
{
//Do Bootsound stuff
if ( soundFile . Extension . Contains ( "mp3" ) )
{
using ( Mp3FileReader mp3 = new Mp3FileReader ( sound ) )
{
using ( WaveStream pcm = WaveFormatConversionStream . CreatePcmStream ( mp3 ) )
{
WaveFileWriter . CreateWaveFile ( Path . Combine ( tempPath , "in.wav" ) , pcm ) ;
}
}
}
else
{
File . Copy ( sound , Path . Combine ( tempPath , "in.wav" ) ) ;
}
sound = Path . Combine ( tempPath , "in.wav" ) ;
//extract SOX.zip
using ( Process zip = new Process ( ) )
{
if ( Directory . Exists ( Path . Combine ( toolsPath , "SOX" ) ) ) { Directory . Delete ( Path . Combine ( toolsPath , "SOX" ) , true ) ; }
if ( ! mvvm . debug )
{
zip . StartInfo . UseShellExecute = false ;
zip . StartInfo . CreateNoWindow = true ;
}
zip . StartInfo . FileName = Path . Combine ( toolsPath , "7za.exe" ) ;
zip . StartInfo . Arguments = $"x \" { Path . Combine ( toolsPath , "SOX.zip" ) } \ " -o\"{Path.Combine(toolsPath, " SOX ")}\"" ;
zip . Start ( ) ;
zip . WaitForExit ( ) ;
}
//Convert stuff
using ( Process p = new Process ( ) )
{
p . StartInfo . FileName = Path . Combine ( toolsPath , "SOX" , "sox.exe" ) ;
p . StartInfo . Arguments = $"\" { Path . Combine ( tempPath , "in.wav" ) } \ " -b 16 \"{Path.Combine(tempPath, " converted . wav ")}\" channels 2 rate 48k trim 0 6" ;
p . Start ( ) ;
p . WaitForExit ( ) ;
File . Delete ( "in.wav" ) ;
}
//Delete SOX Folder
Directory . Delete ( Path . Combine ( toolsPath , "SOX" ) , true ) ;
//extract IKVM.zip
using ( Process zip = new Process ( ) )
{
if ( Directory . Exists ( Path . Combine ( toolsPath , "IKVMW" ) ) ) { Directory . Delete ( Path . Combine ( toolsPath , "IKVMW" ) , true ) ; }
if ( ! mvvm . debug )
{
zip . StartInfo . UseShellExecute = false ;
zip . StartInfo . CreateNoWindow = true ;
}
zip . StartInfo . FileName = Path . Combine ( toolsPath , "7za.exe" ) ;
zip . StartInfo . Arguments = $"x \" { Path . Combine ( toolsPath , "IKVMW.zip" ) } \ " -o\"{Path.Combine(toolsPath, " IKVMW ")}\"" ;
zip . Start ( ) ;
zip . WaitForExit ( ) ;
}
//convert to btsnd
using ( Process wav2btsnd = new Process ( ) )
{
wav2btsnd . StartInfo . FileName = Path . Combine ( toolsPath , "IKVMW" , "wav2btsnd.exe" ) ;
wav2btsnd . StartInfo . Arguments = $"-in \" { Path . Combine ( tempPath , "converted.wav" ) } \ " -out \"{Path.Combine(tempPath, " sound . btsnd ")}\"" ;
wav2btsnd . Start ( ) ;
wav2btsnd . WaitForExit ( ) ;
sound = Path . Combine ( tempPath , "sound.btsnd" ) ;
}
//Delete IKVM.zip
Directory . Delete ( Path . Combine ( toolsPath , "IKVMW" ) , true ) ;
}
//Copy BootSound to location
File . Delete ( Path . Combine ( baseRomPath , "meta" , "bootSound.btsnd" ) ) ;
File . Copy ( sound , Path . Combine ( baseRomPath , "meta" , "bootSound.btsnd" ) ) ;
}
2020-04-18 03:31:36 +00:00
static void timer_Tick ( object sender , EventArgs e )
{
if ( mvvm . Progress < 50 )
{
2020-04-19 17:36:03 +00:00
mvvm . Progress + = 1 ;
2020-04-18 03:31:36 +00:00
}
}
2020-04-16 04:41:25 +00:00
private static void RunSpecificInjection ( GameConfig cfg , GameConsoles console , string RomPath , bool force , MainViewModel mvm )
2020-04-04 22:16:55 +00:00
{
2020-04-16 04:41:25 +00:00
switch ( console )
2020-04-04 22:16:55 +00:00
{
case GameConsoles . NDS :
NDS ( RomPath ) ;
break ;
case GameConsoles . N64 :
2020-04-16 04:41:25 +00:00
N64 ( RomPath , cfg . N64Stuff ) ;
2020-04-04 22:16:55 +00:00
break ;
2020-04-04 22:30:01 +00:00
case GameConsoles . GBA :
2020-04-04 22:16:55 +00:00
GBA ( RomPath ) ;
break ;
2020-04-06 13:50:54 +00:00
case GameConsoles . NES :
2020-04-04 22:16:55 +00:00
NESSNES ( RomPath ) ;
break ;
case GameConsoles . SNES :
NESSNES ( RemoveHeader ( RomPath ) ) ;
2020-04-06 13:50:54 +00:00
break ;
case GameConsoles . TG16 :
TG16 ( RomPath ) ;
break ;
2020-04-07 01:09:05 +00:00
case GameConsoles . MSX :
MSX ( RomPath ) ;
break ;
2020-04-16 04:41:25 +00:00
case GameConsoles . WII :
2020-06-05 11:02:11 +00:00
if ( RomPath . ToLower ( ) . EndsWith ( ".dol" ) )
{
WiiHomebrew ( RomPath , mvm ) ;
2020-06-13 08:11:28 +00:00
} else if ( RomPath . ToLower ( ) . EndsWith ( ".wad" ) )
{
WiiForwarder ( RomPath , mvm ) ;
2020-06-05 11:02:11 +00:00
}
else
{
WII ( RomPath , mvm ) ;
}
2020-04-16 04:41:25 +00:00
break ;
case GameConsoles . GCN :
2020-04-19 17:36:03 +00:00
GC ( RomPath , mvm , force ) ;
2020-04-16 04:41:25 +00:00
break ;
}
}
2020-06-13 08:11:28 +00:00
private static string ByteArrayToString ( byte [ ] arr )
{
System . Text . ASCIIEncoding enc = new System . Text . ASCIIEncoding ( ) ;
return enc . GetString ( arr ) ;
}
private static void WiiForwarder ( string romPath , MainViewModel mvm )
{
string savedir = Directory . GetCurrentDirectory ( ) ;
mvvm . msg = "Extracting Forwarder Base..." ;
if ( Directory . Exists ( Path . Combine ( tempPath , "TempBase" ) ) ) Directory . Delete ( Path . Combine ( tempPath , "TempBase" ) , true ) ;
Directory . CreateDirectory ( Path . Combine ( tempPath , "TempBase" ) ) ;
using ( Process zip = new Process ( ) )
{
if ( ! mvm . debug )
{
zip . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
zip . StartInfo . FileName = Path . Combine ( toolsPath , "7za.exe" ) ;
zip . StartInfo . Arguments = $"x \" { Path . Combine ( toolsPath , "BASE.zip" ) } \ " -o\"{Path.Combine(tempPath)}\"" ;
zip . Start ( ) ;
zip . WaitForExit ( ) ;
}
DirectoryCopy ( Path . Combine ( tempPath , "BASE" ) , Path . Combine ( tempPath , "TempBase" ) , true ) ;
mvvm . Progress = 20 ;
mvvm . msg = "Setting up Forwarder..." ;
byte [ ] test = new byte [ 4 ] ;
using ( FileStream fs = new FileStream ( romPath , FileMode . Open ) )
{
fs . Seek ( 0xC20 , SeekOrigin . Begin ) ;
fs . Read ( test , 0 , 4 ) ;
fs . Close ( ) ;
}
string [ ] id = { ByteArrayToString ( test ) } ;
File . WriteAllLines ( Path . Combine ( tempPath , "TempBase" , "files" , "title.txt" ) , id ) ;
mvm . Progress = 30 ;
mvm . msg = "Copying Forwarder..." ;
File . Copy ( Path . Combine ( toolsPath , "forwarder.dol" ) , Path . Combine ( tempPath , "TempBase" , "sys" , "main.dol" ) ) ;
mvm . Progress = 40 ;
mvvm . msg = "Creating Injectable file..." ;
using ( Process wit = new Process ( ) )
{
if ( ! mvm . debug )
{
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
wit . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
wit . StartInfo . Arguments = $"copy \" { Path . Combine ( tempPath , "TempBase" ) } \ " --DEST \"{Path.Combine(tempPath, " game . iso ")}\" -ovv --links --iso" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
}
Thread . Sleep ( 6000 ) ;
if ( ! File . Exists ( Path . Combine ( tempPath , "game.iso" ) ) )
{
Console . Clear ( ) ;
throw new Exception ( "WIIAn error occured while Creating the ISO" ) ;
}
Directory . Delete ( Path . Combine ( tempPath , "TempBase" ) , true ) ;
romPath = Path . Combine ( tempPath , "game.iso" ) ;
mvvm . Progress = 50 ;
mvm . msg = "Replacing TIK and TMD..." ;
using ( Process extract = new Process ( ) )
{
if ( ! mvm . debug )
{
extract . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
extract . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
extract . StartInfo . Arguments = $"extract \" { Path . Combine ( tempPath , "game.iso" ) } \ " --psel data --files +tmd.bin --files +ticket.bin --DEST \"{Path.Combine(tempPath, " TIKTMD ")}\" -vv1" ;
extract . Start ( ) ;
extract . WaitForExit ( ) ;
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "code" ) , "rvlt.*" ) )
{
File . Delete ( sFile ) ;
}
File . Copy ( Path . Combine ( tempPath , "TIKTMD" , "tmd.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) ;
File . Copy ( Path . Combine ( tempPath , "TIKTMD" , "ticket.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) ;
Directory . Delete ( Path . Combine ( tempPath , "TIKTMD" ) , true ) ;
}
mvm . Progress = 60 ;
mvm . msg = "Injecting ROM..." ;
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "content" ) , "*.nfs" ) )
{
File . Delete ( sFile ) ;
}
File . Move ( Path . Combine ( tempPath , "game.iso" ) , Path . Combine ( baseRomPath , "content" , "game.iso" ) ) ;
File . Copy ( Path . Combine ( toolsPath , "nfs2iso2nfs.exe" ) , Path . Combine ( baseRomPath , "content" , "nfs2iso2nfs.exe" ) ) ;
Directory . SetCurrentDirectory ( Path . Combine ( baseRomPath , "content" ) ) ;
using ( Process iso2nfs = new Process ( ) )
{
if ( ! mvm . debug )
{
iso2nfs . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
iso2nfs . StartInfo . FileName = "nfs2iso2nfs.exe" ;
string extra = "" ;
if ( mvm . Index = = 2 )
{
extra = "-horizontal " ;
}
if ( mvm . Index = = 3 ) { extra = "-wiimote " ; }
if ( mvm . Index = = 4 ) { extra = "-instantcc " ; }
if ( mvm . Index = = 5 ) { extra = "-nocc " ; }
if ( mvm . LR ) { extra + = "-lrpatch " ; }
iso2nfs . StartInfo . Arguments = $"-enc -homebrew {extra}-iso game.iso" ;
iso2nfs . Start ( ) ;
iso2nfs . WaitForExit ( ) ;
File . Delete ( "nfs2iso2nfs.exe" ) ;
File . Delete ( "game.iso" ) ;
}
Directory . SetCurrentDirectory ( savedir ) ;
mvm . Progress = 80 ;
}
2020-06-05 11:02:11 +00:00
private static void WiiHomebrew ( string romPath , MainViewModel mvm )
{
string savedir = Directory . GetCurrentDirectory ( ) ;
mvvm . msg = "Extracting Homebrew Base..." ;
if ( Directory . Exists ( Path . Combine ( tempPath , "TempBase" ) ) ) Directory . Delete ( Path . Combine ( tempPath , "TempBase" ) , true ) ;
Directory . CreateDirectory ( Path . Combine ( tempPath , "TempBase" ) ) ;
using ( Process zip = new Process ( ) )
{
if ( ! mvm . debug )
{
zip . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
zip . StartInfo . FileName = Path . Combine ( toolsPath , "7za.exe" ) ;
zip . StartInfo . Arguments = $"x \" { Path . Combine ( toolsPath , "BASE.zip" ) } \ " -o\"{Path.Combine(tempPath)}\"" ;
zip . Start ( ) ;
zip . WaitForExit ( ) ;
}
DirectoryCopy ( Path . Combine ( tempPath , "BASE" ) , Path . Combine ( tempPath , "TempBase" ) , true ) ;
mvvm . Progress = 20 ;
mvvm . msg = "Injecting DOL..." ;
File . Copy ( romPath , Path . Combine ( tempPath , "TempBase" , "sys" , "main.dol" ) ) ;
mvm . Progress = 30 ;
mvvm . msg = "Creating Injectable file..." ;
using ( Process wit = new Process ( ) )
{
if ( ! mvm . debug )
{
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
wit . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
wit . StartInfo . Arguments = $"copy \" { Path . Combine ( tempPath , "TempBase" ) } \ " --DEST \"{Path.Combine(tempPath, " game . iso ")}\" -ovv --links --iso" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
}
Thread . Sleep ( 6000 ) ;
if ( ! File . Exists ( Path . Combine ( tempPath , "game.iso" ) ) )
{
Console . Clear ( ) ;
throw new Exception ( "WIIAn error occured while Creating the ISO" ) ;
}
Directory . Delete ( Path . Combine ( tempPath , "TempBase" ) , true ) ;
romPath = Path . Combine ( tempPath , "game.iso" ) ;
mvvm . Progress = 50 ;
mvm . msg = "Replacing TIK and TMD..." ;
using ( Process extract = new Process ( ) )
{
if ( ! mvm . debug )
{
extract . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
extract . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
extract . StartInfo . Arguments = $"extract \" { Path . Combine ( tempPath , "game.iso" ) } \ " --psel data --files +tmd.bin --files +ticket.bin --DEST \"{Path.Combine(tempPath, " TIKTMD ")}\" -vv1" ;
extract . Start ( ) ;
extract . WaitForExit ( ) ;
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "code" ) , "rvlt.*" ) )
{
File . Delete ( sFile ) ;
}
File . Copy ( Path . Combine ( tempPath , "TIKTMD" , "tmd.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) ;
File . Copy ( Path . Combine ( tempPath , "TIKTMD" , "ticket.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) ;
Directory . Delete ( Path . Combine ( tempPath , "TIKTMD" ) , true ) ;
}
mvm . Progress = 60 ;
mvm . msg = "Injecting ROM..." ;
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "content" ) , "*.nfs" ) )
{
File . Delete ( sFile ) ;
}
File . Move ( Path . Combine ( tempPath , "game.iso" ) , Path . Combine ( baseRomPath , "content" , "game.iso" ) ) ;
File . Copy ( Path . Combine ( toolsPath , "nfs2iso2nfs.exe" ) , Path . Combine ( baseRomPath , "content" , "nfs2iso2nfs.exe" ) ) ;
Directory . SetCurrentDirectory ( Path . Combine ( baseRomPath , "content" ) ) ;
using ( Process iso2nfs = new Process ( ) )
{
if ( ! mvm . debug )
{
iso2nfs . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
iso2nfs . StartInfo . FileName = "nfs2iso2nfs.exe" ;
string pass = "-passthrough " ;
if ( mvm . passtrough ! = true )
{
pass = "" ;
}
iso2nfs . StartInfo . Arguments = $"-enc -homebrew {pass}-iso game.iso" ;
iso2nfs . Start ( ) ;
iso2nfs . WaitForExit ( ) ;
File . Delete ( "nfs2iso2nfs.exe" ) ;
File . Delete ( "game.iso" ) ;
}
Directory . SetCurrentDirectory ( savedir ) ;
mvm . Progress = 80 ;
2020-05-30 22:35:01 +00:00
2020-06-05 11:02:11 +00:00
}
2020-04-19 17:36:03 +00:00
private static void WII ( string romPath , MainViewModel mvm )
{
string savedir = Directory . GetCurrentDirectory ( ) ;
2020-05-06 21:53:52 +00:00
if ( romPath . Contains ( "nkit" ) | | mvm . NKITFLAG )
2020-04-19 17:36:03 +00:00
{
using ( Process toiso = new Process ( ) )
{
2020-04-22 00:24:35 +00:00
mvm . msg = "Converting NKIT to ISO" ;
2020-04-19 17:36:03 +00:00
if ( ! mvm . debug )
{
2020-04-22 00:24:35 +00:00
toiso . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
// toiso.StartInfo.CreateNoWindow = true;
2020-04-19 17:36:03 +00:00
}
2020-04-22 00:24:35 +00:00
toiso . StartInfo . FileName = Path . Combine ( toolsPath , "ConvertToIso.exe" ) ;
toiso . StartInfo . Arguments = $"\" { romPath } \ "" ;
2020-04-19 17:36:03 +00:00
toiso . Start ( ) ;
toiso . WaitForExit ( ) ;
2020-04-22 00:24:35 +00:00
if ( ! File . Exists ( Path . Combine ( toolsPath , "out.iso" ) ) )
{
throw new Exception ( "nkit" ) ;
}
File . Move ( Path . Combine ( toolsPath , "out.iso" ) , Path . Combine ( tempPath , "pre.iso" ) ) ;
mvm . Progress = 15 ;
2020-04-19 17:36:03 +00:00
}
}
2020-04-22 00:24:35 +00:00
else
2020-04-19 17:36:03 +00:00
{
2020-04-22 00:24:35 +00:00
if ( new FileInfo ( romPath ) . Extension . Contains ( "wbfs" ) )
{
mvm . msg = "Converting WBFS to ISO..." ;
using ( Process toiso = new Process ( ) )
{
if ( ! mvm . debug )
{
toiso . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
// toiso.StartInfo.CreateNoWindow = true;
}
toiso . StartInfo . FileName = Path . Combine ( toolsPath , "wbfs_file.exe" ) ;
toiso . StartInfo . Arguments = $"\" { romPath } \ " convert \"{Path.Combine(tempPath, " pre . iso ")}\" -t" ;
toiso . Start ( ) ;
toiso . WaitForExit ( ) ;
mvm . Progress = 15 ;
}
}
else if ( new FileInfo ( romPath ) . Extension . Contains ( "iso" ) )
{
mvm . msg = "Copying ROM..." ;
File . Copy ( romPath , Path . Combine ( tempPath , "pre.iso" ) ) ;
mvm . Progress = 15 ;
}
2020-04-19 17:36:03 +00:00
}
2020-05-04 16:20:21 +00:00
if ( ! mvm . donttrim )
2020-04-19 17:36:03 +00:00
{
2020-06-13 19:52:39 +00:00
if ( mvm . regionfrii )
{
if ( mvm . regionfriius )
{
using ( FileStream fs = new FileStream ( Path . Combine ( tempPath , "pre.iso" ) , FileMode . Open ) )
{
fs . Seek ( 0x4E003 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x01 } , 0 , 1 ) ;
fs . Seek ( 0x4E010 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x80 , 0x06 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 } , 0 , 16 ) ;
fs . Close ( ) ;
}
}
else if ( mvm . regionfriijp )
{
using ( FileStream fs = new FileStream ( Path . Combine ( tempPath , "pre.iso" ) , FileMode . Open ) )
{
fs . Seek ( 0x4E003 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x00 } , 0 , 1 ) ;
fs . Seek ( 0x4E010 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x00 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 } , 0 , 16 ) ;
fs . Close ( ) ;
}
}
else
{
using ( FileStream fs = new FileStream ( Path . Combine ( tempPath , "pre.iso" ) , FileMode . Open ) )
{
fs . Seek ( 0x4E003 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x02 } , 0 , 1 ) ;
fs . Seek ( 0x4E010 , SeekOrigin . Begin ) ;
fs . Write ( new byte [ ] { 0x80 , 0x80 , 0x80 , 0x00 , 0x03 , 0x03 , 0x04 , 0x03 , 0x00 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 } , 0 , 16 ) ;
fs . Close ( ) ;
}
}
}
2020-05-04 16:20:21 +00:00
using ( Process trimm = new Process ( ) )
2020-04-19 17:36:03 +00:00
{
2020-05-04 16:20:21 +00:00
if ( ! mvm . debug )
{
trimm . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
mvm . msg = "Trimming ROM..." ;
trimm . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
trimm . StartInfo . Arguments = $"extract \" { Path . Combine ( tempPath , "pre.iso" ) } \ " --DEST \"{Path.Combine(tempPath, " TEMP ")}\" --psel data -vv1" ;
trimm . Start ( ) ;
trimm . WaitForExit ( ) ;
mvm . Progress = 30 ;
}
if ( mvm . Index = = 4 )
{
mvvm . msg = "Patching ROM (Force CC)..." ;
Console . WriteLine ( "Patching the ROM to force Classic Controller input" ) ;
using ( Process tik = new Process ( ) )
{
tik . StartInfo . FileName = Path . Combine ( toolsPath , "GetExtTypePatcher.exe" ) ;
tik . StartInfo . Arguments = $"\" { Path . Combine ( tempPath , "TEMP" , "sys" , "main.dol" ) } \ " -nc" ;
tik . StartInfo . UseShellExecute = false ;
tik . StartInfo . CreateNoWindow = true ;
tik . StartInfo . RedirectStandardOutput = true ;
tik . StartInfo . RedirectStandardInput = true ;
tik . Start ( ) ;
Thread . Sleep ( 2000 ) ;
tik . StandardInput . WriteLine ( ) ;
tik . WaitForExit ( ) ;
mvm . Progress = 35 ;
}
2020-04-19 17:36:03 +00:00
}
2020-05-30 22:35:01 +00:00
if ( mvm . jppatch )
{
mvm . msg = "Language Patching ROM..." ;
using ( BinaryWriter writer = new BinaryWriter ( new FileStream ( Path . Combine ( tempPath , "TEMP" , "sys" , "main.dol" ) , FileMode . Open ) ) )
{
byte [ ] stuff = new byte [ ] { 0x38 , 0x60 } ;
writer . Seek ( 0x4CBDAC , SeekOrigin . Begin ) ;
writer . Write ( stuff ) ;
writer . Seek ( 0x4CBDAF , SeekOrigin . Begin ) ;
stuff = new byte [ ] { 0x00 } ;
writer . Write ( stuff ) ;
writer . Close ( ) ;
}
mvm . Progress = 37 ;
}
2020-05-04 16:20:21 +00:00
if ( mvm . Patch )
2020-04-19 17:36:03 +00:00
{
2020-05-30 22:35:01 +00:00
2020-05-04 16:20:21 +00:00
mvm . msg = "Video Patching ROM..." ;
using ( Process vmc = new Process ( ) )
{
File . Copy ( Path . Combine ( toolsPath , "wii-vmc.exe" ) , Path . Combine ( tempPath , "TEMP" , "sys" , "wii-vmc.exe" ) ) ;
Directory . SetCurrentDirectory ( Path . Combine ( tempPath , "TEMP" , "sys" ) ) ;
vmc . StartInfo . FileName = "wii-vmc.exe" ;
vmc . StartInfo . Arguments = "main.dol" ;
vmc . StartInfo . UseShellExecute = false ;
vmc . StartInfo . CreateNoWindow = true ;
vmc . StartInfo . RedirectStandardOutput = true ;
vmc . StartInfo . RedirectStandardInput = true ;
vmc . Start ( ) ;
Thread . Sleep ( 1000 ) ;
vmc . StandardInput . WriteLine ( "a" ) ;
Thread . Sleep ( 2000 ) ;
if ( mvm . toPal ) vmc . StandardInput . WriteLine ( "1" ) ;
else vmc . StandardInput . WriteLine ( "2" ) ;
Thread . Sleep ( 2000 ) ;
vmc . StandardInput . WriteLine ( ) ;
vmc . WaitForExit ( ) ;
File . Delete ( "wii-vmc.exe" ) ;
Directory . SetCurrentDirectory ( savedir ) ;
mvm . Progress = 40 ;
}
2020-04-19 17:36:03 +00:00
}
2020-05-04 16:20:21 +00:00
mvm . msg = "Creating ISO from trimmed ROM..." ;
using ( Process repack = new Process ( ) )
{
if ( ! mvm . debug )
{
2020-04-16 04:41:25 +00:00
2020-05-04 16:20:21 +00:00
repack . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
repack . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
repack . StartInfo . Arguments = $"copy \" { Path . Combine ( tempPath , "TEMP" ) } \ " --DEST \"{Path.Combine(tempPath, " game . iso ")}\" -ovv --links --iso" ;
repack . Start ( ) ;
repack . WaitForExit ( ) ;
Directory . Delete ( Path . Combine ( tempPath , "TEMP" ) , true ) ;
File . Delete ( Path . Combine ( tempPath , "pre.iso" ) ) ;
}
2020-04-19 17:36:03 +00:00
}
2020-05-04 16:20:21 +00:00
else
2020-04-19 17:36:03 +00:00
{
2020-05-04 16:20:21 +00:00
/ * if ( mvm . Index = = 4 | | mvm . Patch )
2020-04-19 17:36:03 +00:00
{
2020-05-04 16:20:21 +00:00
using ( Process trimm = new Process ( ) )
{
if ( ! mvm . debug )
{
trimm . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
mvm . msg = "Trimming ROM..." ;
trimm . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
trimm . StartInfo . Arguments = $"extract \" { Path . Combine ( tempPath , "pre.iso" ) } \ " --DEST \"{Path.Combine(tempPath, " TEMP ")}\" --psel WHOLE -vv1" ;
trimm . Start ( ) ;
trimm . WaitForExit ( ) ;
mvm . Progress = 30 ;
}
if ( mvm . Index = = 4 )
{
mvvm . msg = "Patching ROM (Force CC)..." ;
Console . WriteLine ( "Patching the ROM to force Classic Controller input" ) ;
using ( Process tik = new Process ( ) )
{
tik . StartInfo . FileName = Path . Combine ( toolsPath , "GetExtTypePatcher.exe" ) ;
tik . StartInfo . Arguments = $"\" { Path . Combine ( tempPath , "TEMP" , "DATA" , "sys" , "main.dol" ) } \ " -nc" ;
tik . StartInfo . UseShellExecute = false ;
tik . StartInfo . CreateNoWindow = true ;
tik . StartInfo . RedirectStandardOutput = true ;
tik . StartInfo . RedirectStandardInput = true ;
tik . Start ( ) ;
Thread . Sleep ( 2000 ) ;
tik . StandardInput . WriteLine ( ) ;
tik . WaitForExit ( ) ;
mvm . Progress = 35 ;
}
}
if ( mvm . Patch )
{
mvm . msg = "Video Patching ROM..." ;
using ( Process vmc = new Process ( ) )
{
File . Copy ( Path . Combine ( toolsPath , "wii-vmc.exe" ) , Path . Combine ( tempPath , "TEMP" , "DATA" , "sys" , "wii-vmc.exe" ) ) ;
Directory . SetCurrentDirectory ( Path . Combine ( tempPath , "TEMP" , "DATA" , "sys" ) ) ;
vmc . StartInfo . FileName = "wii-vmc.exe" ;
vmc . StartInfo . Arguments = "main.dol" ;
vmc . StartInfo . UseShellExecute = false ;
vmc . StartInfo . CreateNoWindow = true ;
vmc . StartInfo . RedirectStandardOutput = true ;
vmc . StartInfo . RedirectStandardInput = true ;
vmc . Start ( ) ;
Thread . Sleep ( 1000 ) ;
vmc . StandardInput . WriteLine ( "a" ) ;
Thread . Sleep ( 2000 ) ;
if ( mvm . toPal ) vmc . StandardInput . WriteLine ( "1" ) ;
else vmc . StandardInput . WriteLine ( "2" ) ;
Thread . Sleep ( 2000 ) ;
vmc . StandardInput . WriteLine ( ) ;
vmc . WaitForExit ( ) ;
File . Delete ( "wii-vmc.exe" ) ;
Directory . SetCurrentDirectory ( savedir ) ;
mvm . Progress = 40 ;
}
}
mvm . msg = "Creating ISO from patched ROM..." ;
using ( Process repack = new Process ( ) )
{
if ( ! mvm . debug )
{
repack . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
repack . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
repack . StartInfo . Arguments = $"copy \" { Path . Combine ( tempPath , "TEMP" ) } \ " --DEST \"{Path.Combine(tempPath, " game . iso ")}\" -ovv --psel WHOLE --iso" ;
repack . Start ( ) ;
repack . WaitForExit ( ) ;
Directory . Delete ( Path . Combine ( tempPath , "TEMP" ) , true ) ;
File . Delete ( Path . Combine ( tempPath , "pre.iso" ) ) ;
}
}
else
{ * /
File . Move ( Path . Combine ( tempPath , "pre.iso" ) , Path . Combine ( tempPath , "game.iso" ) ) ;
// }
2020-04-19 17:36:03 +00:00
}
2020-05-04 16:20:21 +00:00
2020-04-19 17:36:03 +00:00
mvm . Progress = 50 ;
mvm . msg = "Replacing TIK and TMD..." ;
using ( Process extract = new Process ( ) )
{
if ( ! mvm . debug )
{
2020-04-19 19:15:00 +00:00
extract . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
2020-04-19 17:36:03 +00:00
}
extract . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
extract . StartInfo . Arguments = $"extract \" { Path . Combine ( tempPath , "game.iso" ) } \ " --psel data --files +tmd.bin --files +ticket.bin --DEST \"{Path.Combine(tempPath, " TIKTMD ")}\" -vv1" ;
extract . Start ( ) ;
extract . WaitForExit ( ) ;
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "code" ) , "rvlt.*" ) )
{
File . Delete ( sFile ) ;
}
File . Copy ( Path . Combine ( tempPath , "TIKTMD" , "tmd.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) ;
File . Copy ( Path . Combine ( tempPath , "TIKTMD" , "ticket.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) ;
Directory . Delete ( Path . Combine ( tempPath , "TIKTMD" ) , true ) ;
}
mvm . Progress = 60 ;
mvm . msg = "Injecting ROM..." ;
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "content" ) , "*.nfs" ) )
{
File . Delete ( sFile ) ;
}
File . Move ( Path . Combine ( tempPath , "game.iso" ) , Path . Combine ( baseRomPath , "content" , "game.iso" ) ) ;
File . Copy ( Path . Combine ( toolsPath , "nfs2iso2nfs.exe" ) , Path . Combine ( baseRomPath , "content" , "nfs2iso2nfs.exe" ) ) ;
Directory . SetCurrentDirectory ( Path . Combine ( baseRomPath , "content" ) ) ;
using ( Process iso2nfs = new Process ( ) )
{
if ( ! mvm . debug )
{
2020-04-19 19:15:00 +00:00
iso2nfs . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
2020-04-19 17:36:03 +00:00
}
iso2nfs . StartInfo . FileName = "nfs2iso2nfs.exe" ;
string extra = "" ;
if ( mvm . Index = = 2 )
{
extra = "-horizontal " ;
}
if ( mvm . Index = = 3 ) { extra = "-wiimote " ; }
if ( mvm . Index = = 4 ) { extra = "-instantcc " ; }
if ( mvm . Index = = 5 ) { extra = "-nocc " ; }
if ( mvm . LR ) { extra + = "-lrpatch " ; }
iso2nfs . StartInfo . Arguments = $"-enc {extra}-iso game.iso" ;
iso2nfs . Start ( ) ;
iso2nfs . WaitForExit ( ) ;
File . Delete ( "nfs2iso2nfs.exe" ) ;
File . Delete ( "game.iso" ) ;
}
Directory . SetCurrentDirectory ( savedir ) ;
mvm . Progress = 80 ;
}
private static void GC ( string romPath , MainViewModel mvm , bool force )
{
string savedir = Directory . GetCurrentDirectory ( ) ;
mvvm . msg = "Extracting Nintendont Base..." ;
if ( Directory . Exists ( Path . Combine ( tempPath , "TempBase" ) ) ) Directory . Delete ( Path . Combine ( tempPath , "TempBase" ) , true ) ;
Directory . CreateDirectory ( Path . Combine ( tempPath , "TempBase" ) ) ;
using ( Process zip = new Process ( ) ) {
if ( ! mvm . debug )
{
2020-04-19 19:15:00 +00:00
zip . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
2020-04-19 17:36:03 +00:00
}
zip . StartInfo . FileName = Path . Combine ( toolsPath , "7za.exe" ) ;
zip . StartInfo . Arguments = $"x \" { Path . Combine ( toolsPath , "BASE.zip" ) } \ " -o\"{Path.Combine(tempPath)}\"" ;
zip . Start ( ) ;
zip . WaitForExit ( ) ;
}
DirectoryCopy ( Path . Combine ( tempPath , "BASE" ) , Path . Combine ( tempPath , "TempBase" ) , true ) ;
mvvm . Progress = 20 ;
mvvm . msg = "Applying Nintendont" ;
if ( force )
{
mvvm . msg + = " force 4:3..." ;
File . Copy ( Path . Combine ( toolsPath , "nintendont_force.dol" ) , Path . Combine ( tempPath , "TempBase" , "sys" , "main.dol" ) ) ;
}
else
{
mvvm . msg + = "..." ;
File . Copy ( Path . Combine ( toolsPath , "nintendont.dol" ) , Path . Combine ( tempPath , "TempBase" , "sys" , "main.dol" ) ) ;
}
mvm . Progress = 40 ;
mvvm . msg = "Injecting GameCube Game into NintendontBase..." ;
2020-05-04 16:20:21 +00:00
if ( mvm . donttrim )
2020-04-22 00:24:35 +00:00
{
2020-05-04 16:20:21 +00:00
if ( romPath . ToLower ( ) . Contains ( "nkit.iso" ) )
2020-04-22 00:24:35 +00:00
{
2020-05-04 16:20:21 +00:00
using ( Process wit = new Process ( ) )
2020-04-22 00:24:35 +00:00
{
2020-05-04 16:20:21 +00:00
if ( ! mvm . debug )
{
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
wit . StartInfo . FileName = Path . Combine ( toolsPath , "ConvertToIso.exe" ) ;
wit . StartInfo . Arguments = $"\" { romPath } \ "" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
if ( ! File . Exists ( Path . Combine ( toolsPath , "out.iso" ) ) )
{
throw new Exception ( "nkit" ) ;
}
File . Move ( Path . Combine ( toolsPath , "out.iso" ) , Path . Combine ( tempPath , "TempBase" , "files" , "game.iso" ) ) ;
2020-04-22 00:24:35 +00:00
}
2020-05-04 16:20:21 +00:00
}
else
{
2020-05-06 21:53:52 +00:00
if ( romPath . ToLower ( ) . Contains ( "gcz" ) )
{
//Convert to nkit.iso
using ( Process wit = new Process ( ) )
{
if ( ! mvm . debug )
{
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
wit . StartInfo . FileName = Path . Combine ( toolsPath , "ConvertToIso.exe" ) ;
wit . StartInfo . Arguments = $"\" { romPath } \ "" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
if ( ! File . Exists ( Path . Combine ( toolsPath , "out.iso" ) ) )
{
throw new Exception ( "nkit" ) ;
}
File . Move ( Path . Combine ( toolsPath , "out.iso" ) , Path . Combine ( tempPath , "TempBase" , "files" , "game.iso" ) ) ;
}
}
else
{
File . Copy ( romPath , Path . Combine ( tempPath , "TempBase" , "files" , "game.iso" ) ) ;
}
2020-04-22 00:24:35 +00:00
}
}
else
{
2020-05-04 16:20:21 +00:00
if ( romPath . ToLower ( ) . Contains ( "iso" ) | | romPath . ToLower ( ) . Contains ( "gcm" ) )
2020-04-22 00:24:35 +00:00
{
2020-05-04 16:20:21 +00:00
//convert to nkit
2020-04-22 00:24:35 +00:00
using ( Process wit = new Process ( ) )
{
if ( ! mvm . debug )
{
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
2020-05-04 16:20:21 +00:00
wit . StartInfo . FileName = Path . Combine ( toolsPath , "ConvertToNKit.exe" ) ;
2020-04-22 00:24:35 +00:00
wit . StartInfo . Arguments = $"\" { romPath } \ "" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
2020-05-04 16:20:21 +00:00
if ( ! File . Exists ( Path . Combine ( toolsPath , "out.nkit.iso" ) ) )
2020-04-22 00:24:35 +00:00
{
throw new Exception ( "nkit" ) ;
}
2020-05-04 16:20:21 +00:00
File . Move ( Path . Combine ( toolsPath , "out.nkit.iso" ) , Path . Combine ( tempPath , "TempBase" , "files" , "game.iso" ) ) ;
2020-04-22 00:24:35 +00:00
}
2020-05-04 16:20:21 +00:00
2020-04-22 00:24:35 +00:00
}
else
{
2020-05-06 21:53:52 +00:00
if ( romPath . ToLower ( ) . Contains ( "gcz" ) )
{
//Convert to nkit.iso
using ( Process wit = new Process ( ) )
{
if ( ! mvm . debug )
{
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
wit . StartInfo . FileName = Path . Combine ( toolsPath , "ConvertToNKit.exe" ) ;
wit . StartInfo . Arguments = $"\" { romPath } \ "" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
if ( ! File . Exists ( Path . Combine ( toolsPath , "out.nkit.iso" ) ) )
{
throw new Exception ( "nkit" ) ;
}
File . Move ( Path . Combine ( toolsPath , "out.nkit.iso" ) , Path . Combine ( tempPath , "TempBase" , "files" , "game.iso" ) ) ;
}
}
else
{
File . Copy ( romPath , Path . Combine ( tempPath , "TempBase" , "files" , "game.iso" ) ) ;
}
2020-05-04 16:20:21 +00:00
}
}
if ( mvm . gc2rom ! = "" & & File . Exists ( mvm . gc2rom ) )
{
if ( mvm . donttrim )
{
2020-05-07 20:00:24 +00:00
if ( mvm . gc2rom . Contains ( "nkit" ) )
2020-05-04 16:20:21 +00:00
{
using ( Process wit = new Process ( ) )
{
if ( ! mvm . debug )
{
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
wit . StartInfo . FileName = Path . Combine ( toolsPath , "ConvertToIso.exe" ) ;
wit . StartInfo . Arguments = $"\" { mvm . gc2rom } \ "" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
2020-05-07 20:00:24 +00:00
if ( ! File . Exists ( Path . Combine ( toolsPath , "out(Disc 1).iso" ) ) )
2020-05-04 16:20:21 +00:00
{
throw new Exception ( "nkit" ) ;
}
2020-05-07 20:00:24 +00:00
File . Move ( Path . Combine ( toolsPath , "out(Disc 1).iso" ) , Path . Combine ( tempPath , "TempBase" , "files" , "disc2.iso" ) ) ;
2020-05-04 16:20:21 +00:00
}
}
else
{
2020-05-07 20:00:24 +00:00
2020-05-06 21:53:52 +00:00
File . Copy ( mvm . gc2rom , Path . Combine ( tempPath , "TempBase" , "files" , "disc2.iso" ) ) ;
2020-05-07 20:00:24 +00:00
2020-05-06 21:53:52 +00:00
2020-05-04 16:20:21 +00:00
}
2020-04-22 00:24:35 +00:00
}
2020-05-04 16:20:21 +00:00
else {
if ( mvm . gc2rom . ToLower ( ) . Contains ( "iso" ) | | mvm . gc2rom . ToLower ( ) . Contains ( "gcm" ) )
{
//convert to nkit
using ( Process wit = new Process ( ) )
{
if ( ! mvm . debug )
{
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
wit . StartInfo . FileName = Path . Combine ( toolsPath , "ConvertToNKit.exe" ) ;
wit . StartInfo . Arguments = $"\" { mvm . gc2rom } \ "" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
2020-05-07 20:00:24 +00:00
if ( ! File . Exists ( Path . Combine ( toolsPath , "out(Disc 1).nkit.iso" ) ) )
2020-05-04 16:20:21 +00:00
{
throw new Exception ( "nkit" ) ;
}
2020-05-07 20:00:24 +00:00
File . Move ( Path . Combine ( toolsPath , "out(Disc 1).nkit.iso" ) , Path . Combine ( tempPath , "TempBase" , "files" , "disc2.iso" ) ) ;
2020-05-04 16:20:21 +00:00
}
}
else
{
2020-05-06 21:53:52 +00:00
if ( romPath . ToLower ( ) . Contains ( "gcz" ) )
{
//Convert to nkit.iso
using ( Process wit = new Process ( ) )
{
if ( ! mvm . debug )
{
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
}
wit . StartInfo . FileName = Path . Combine ( toolsPath , "ConvertToNKit.exe" ) ;
wit . StartInfo . Arguments = $"\" { romPath } \ "" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
2020-05-07 20:00:24 +00:00
if ( ! File . Exists ( Path . Combine ( toolsPath , "out(Disc 1).nkit.iso" ) ) )
2020-05-06 21:53:52 +00:00
{
throw new Exception ( "nkit" ) ;
}
2020-05-07 20:00:24 +00:00
File . Move ( Path . Combine ( toolsPath , "out(Disc 1).nkit.iso" ) , Path . Combine ( tempPath , "TempBase" , "files" , "disc2.iso" ) ) ;
2020-05-06 21:53:52 +00:00
}
}
else
{
File . Copy ( romPath , Path . Combine ( tempPath , "TempBase" , "files" , "disc2.iso" ) ) ;
}
2020-05-04 16:20:21 +00:00
}
}
2020-04-22 00:24:35 +00:00
}
2020-04-19 17:36:03 +00:00
using ( Process wit = new Process ( ) )
{
if ( ! mvm . debug )
{
2020-04-19 19:15:00 +00:00
wit . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
2020-04-19 17:36:03 +00:00
}
wit . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
wit . StartInfo . Arguments = $"copy \" { Path . Combine ( tempPath , "TempBase" ) } \ " --DEST \"{Path.Combine(tempPath, " game . iso ")}\" -ovv --links --iso" ;
wit . Start ( ) ;
wit . WaitForExit ( ) ;
}
Thread . Sleep ( 6000 ) ;
if ( ! File . Exists ( Path . Combine ( tempPath , "game.iso" ) ) )
{
Console . Clear ( ) ;
throw new Exception ( "WIIAn error occured while Creating the ISO" ) ;
}
Directory . Delete ( Path . Combine ( tempPath , "TempBase" ) , true ) ;
romPath = Path . Combine ( tempPath , "game.iso" ) ;
mvvm . Progress = 50 ;
mvm . msg = "Replacing TIK and TMD..." ;
using ( Process extract = new Process ( ) )
{
if ( ! mvm . debug )
{
2020-04-19 19:15:00 +00:00
extract . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
2020-04-19 17:36:03 +00:00
}
extract . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
extract . StartInfo . Arguments = $"extract \" { Path . Combine ( tempPath , "game.iso" ) } \ " --psel data --files +tmd.bin --files +ticket.bin --DEST \"{Path.Combine(tempPath, " TIKTMD ")}\" -vv1" ;
extract . Start ( ) ;
extract . WaitForExit ( ) ;
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "code" ) , "rvlt.*" ) )
{
File . Delete ( sFile ) ;
}
File . Copy ( Path . Combine ( tempPath , "TIKTMD" , "tmd.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) ;
File . Copy ( Path . Combine ( tempPath , "TIKTMD" , "ticket.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) ;
Directory . Delete ( Path . Combine ( tempPath , "TIKTMD" ) , true ) ;
}
mvm . Progress = 60 ;
mvm . msg = "Injecting ROM..." ;
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "content" ) , "*.nfs" ) )
{
File . Delete ( sFile ) ;
}
File . Move ( Path . Combine ( tempPath , "game.iso" ) , Path . Combine ( baseRomPath , "content" , "game.iso" ) ) ;
File . Copy ( Path . Combine ( toolsPath , "nfs2iso2nfs.exe" ) , Path . Combine ( baseRomPath , "content" , "nfs2iso2nfs.exe" ) ) ;
Directory . SetCurrentDirectory ( Path . Combine ( baseRomPath , "content" ) ) ;
using ( Process iso2nfs = new Process ( ) )
{
if ( ! mvm . debug )
{
2020-04-19 19:15:00 +00:00
iso2nfs . StartInfo . WindowStyle = System . Diagnostics . ProcessWindowStyle . Hidden ;
2020-04-19 17:36:03 +00:00
}
iso2nfs . StartInfo . FileName = "nfs2iso2nfs.exe" ;
iso2nfs . StartInfo . Arguments = $"-enc -homebrew -passthrough -iso game.iso" ;
iso2nfs . Start ( ) ;
iso2nfs . WaitForExit ( ) ;
File . Delete ( "nfs2iso2nfs.exe" ) ;
File . Delete ( "game.iso" ) ;
}
Directory . SetCurrentDirectory ( savedir ) ;
mvm . Progress = 80 ;
}
private static void WIIold ( string romPath , MainViewModel mvm , bool force )
2020-04-16 04:41:25 +00:00
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Removing unnecessary Files..." ;
2020-04-16 04:41:25 +00:00
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "content" ) , "*.nfs" ) )
{
File . Delete ( sFile ) ;
}
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "meta" ) , "*.jpg" ) )
{
File . Delete ( sFile ) ;
}
foreach ( string sFile in Directory . GetFiles ( Path . Combine ( baseRomPath , "meta" ) , "*.bfma" ) )
{
File . Delete ( sFile ) ;
}
if ( File . Exists ( Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) ) File . Delete ( Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) ;
if ( File . Exists ( Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) ) File . Delete ( Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 15 ;
2020-04-16 04:41:25 +00:00
Console . WriteLine ( "Finished removing Files" ) ;
using ( Process tik = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
if ( ! mvm . debug )
{
tik . StartInfo . UseShellExecute = false ;
tik . StartInfo . CreateNoWindow = true ;
}
2020-04-16 04:41:25 +00:00
if ( ! mvm . GC )
{
if ( new FileInfo ( romPath ) . Extension . Contains ( "wbfs" ) )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Converting WBFS to ISO..." ;
2020-04-16 04:41:25 +00:00
Console . WriteLine ( "Converting WBFS to ISO..." ) ;
2020-04-16 18:52:26 +00:00
tik . StartInfo . FileName = Path . Combine ( toolsPath , "wbfs_file.exe" ) ;
2020-04-16 04:41:25 +00:00
tik . StartInfo . Arguments = $"\" { romPath } \ " convert \"{Path.Combine(tempPath, " pre . iso ")}\"" ;
tik . Start ( ) ;
tik . WaitForExit ( ) ;
if ( ! File . Exists ( Path . Combine ( tempPath , "pre.iso" ) ) )
{
2020-04-17 16:02:45 +00:00
throw new Exception ( "WIIAn error occured while converting WBFS to ISO" ) ;
2020-04-16 04:41:25 +00:00
}
if ( File . Exists ( Path . Combine ( tempPath , "rom.wbfs" ) ) ) { File . Delete ( Path . Combine ( tempPath , "rom.wbfs" ) ) ; }
romPath = Path . Combine ( tempPath , "pre.iso" ) ;
Console . WriteLine ( "Finished Conversion" ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 20 ;
2020-04-16 04:41:25 +00:00
}
tik . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
2020-04-16 18:52:26 +00:00
mvvm . msg = "Trimming ROM..." ;
2020-04-16 04:41:25 +00:00
Console . WriteLine ( "Trimming ROM..." ) ;
tik . StartInfo . Arguments = $"extract \" { romPath } \ " --DEST \"{Path.Combine(tempPath, " IsoExt ")}\" --psel data -vv1" ;
tik . Start ( ) ;
tik . WaitForExit ( ) ;
if ( ! Directory . Exists ( Path . Combine ( tempPath , "IsoExt" ) ) )
{
2020-04-17 16:02:45 +00:00
throw new Exception ( "WIIAn error occured while trimming the ROM" ) ;
2020-04-16 04:41:25 +00:00
}
2020-04-16 18:52:26 +00:00
mvvm . Progress = 40 ;
2020-04-16 04:41:25 +00:00
Console . WriteLine ( "Finished trimming" ) ;
if ( mvm . Index = = 4 )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Patching ROM (Force CC)..." ;
2020-04-16 04:41:25 +00:00
Console . WriteLine ( "Patching the ROM to force Classic Controller input" ) ;
tik . StartInfo . FileName = Path . Combine ( toolsPath , "GetExtTypePatcher.exe" ) ;
tik . StartInfo . Arguments = $"\" { Path . Combine ( tempPath , "IsoExt" , "sys" , "main.dol" ) } \ "" ;
tik . Start ( ) ;
tik . WaitForExit ( ) ;
tik . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 45 ;
2020-04-16 04:41:25 +00:00
}
2020-04-17 01:28:14 +00:00
if ( mvm . Patch )
{
mvvm . msg = "Video Patching ROM..." ;
using ( Process process = new Process ( ) )
{
2020-04-18 03:31:36 +00:00
process . StartInfo . FileName = Path . Combine ( toolsPath , "wii-vmc.exe" ) ;
2020-04-17 01:28:14 +00:00
process . StartInfo . Arguments = $"\" { Path . Combine ( tempPath , "IsoExt" , "sys" , "main.dol" ) } \ "" ;
2020-04-19 17:36:03 +00:00
//process.StartInfo.RedirectStandardInput = true;
// process.StartInfo.UseShellExecute = false;
// process.StartInfo.CreateNoWindow = true;
2020-04-18 03:31:36 +00:00
2020-04-17 01:28:14 +00:00
process . Start ( ) ;
2020-04-19 17:36:03 +00:00
/ * Thread . Sleep ( 2000 ) ;
2020-04-17 01:28:14 +00:00
process . StandardInput . WriteLine ( "a" ) ;
2020-04-18 03:31:36 +00:00
Thread . Sleep ( 2000 ) ;
2020-04-17 01:28:14 +00:00
if ( mvm . toPal )
{
process . StandardInput . WriteLine ( "1" ) ;
}
else
{
process . StandardInput . WriteLine ( "2" ) ;
}
2020-04-18 03:31:36 +00:00
Thread . Sleep ( 2000 ) ;
2020-04-17 01:28:14 +00:00
process . StandardInput . WriteLine ( ) ;
2020-04-19 17:36:03 +00:00
* /
2020-04-17 01:28:14 +00:00
process . WaitForExit ( ) ;
}
mvvm . Progress = 50 ;
}
2020-04-16 18:52:26 +00:00
mvvm . msg = "Creating ISO from trimmed ROM..." ;
2020-04-16 04:41:25 +00:00
Console . WriteLine ( "Creating ISO from trimmed ROM..." ) ;
tik . StartInfo . Arguments = $"copy \" { Path . Combine ( tempPath , "IsoExt" ) } \ " --DEST \"{Path.Combine(tempPath, " game . iso ")}\" -ovv --links --iso" ;
tik . Start ( ) ;
tik . WaitForExit ( ) ;
if ( ! File . Exists ( Path . Combine ( tempPath , "game.iso" ) ) )
{
2020-04-17 16:02:45 +00:00
throw new Exception ( "WIIAn error occured while Creating the ISO" ) ;
2020-04-16 04:41:25 +00:00
}
romPath = Path . Combine ( tempPath , "game.iso" ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 60 ;
2020-04-16 04:41:25 +00:00
}
else
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Extracting Nintendont Base..." ;
2020-04-16 04:41:25 +00:00
if ( Directory . Exists ( Path . Combine ( tempPath , "TempBase" ) ) ) Directory . Delete ( Path . Combine ( tempPath , "TempBase" ) , true ) ;
Directory . CreateDirectory ( Path . Combine ( tempPath , "TempBase" ) ) ;
tik . StartInfo . FileName = Path . Combine ( toolsPath , "7za.exe" ) ;
tik . StartInfo . Arguments = $"x \" { Path . Combine ( toolsPath , "BASE.zip" ) } \ " -o\"{Path.Combine(tempPath)}\"" ;
tik . Start ( ) ;
tik . WaitForExit ( ) ;
DirectoryCopy ( Path . Combine ( tempPath , "BASE" ) , Path . Combine ( tempPath , "TempBase" ) , true ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 30 ;
mvvm . msg = "Applying Nintendont" ;
2020-04-16 04:41:25 +00:00
if ( force )
{
2020-04-16 18:52:26 +00:00
mvvm . msg + = " force 4:3..." ;
2020-04-16 04:41:25 +00:00
File . Copy ( Path . Combine ( toolsPath , "nintendont_force.dol" ) , Path . Combine ( tempPath , "TempBase" , "sys" , "main.dol" ) ) ;
}
else
{
2020-04-16 18:52:26 +00:00
mvvm . msg + = "..." ;
2020-04-16 04:41:25 +00:00
File . Copy ( Path . Combine ( toolsPath , "nintendont.dol" ) , Path . Combine ( tempPath , "TempBase" , "sys" , "main.dol" ) ) ;
}
2020-04-16 18:52:26 +00:00
mvm . Progress = 40 ;
mvvm . msg = "Injecting GameCube Game into NintendontBase..." ;
2020-04-16 04:41:25 +00:00
File . Copy ( romPath , Path . Combine ( tempPath , "TempBase" , "files" , "game.iso" ) ) ;
2020-04-18 03:31:36 +00:00
Thread . Sleep ( 6000 ) ;
2020-04-16 04:41:25 +00:00
tik . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
tik . StartInfo . Arguments = $"copy \" { Path . Combine ( tempPath , "TempBase" ) } \ " --DEST \"{Path.Combine(tempPath, " game . iso ")}\" -ovv --links --iso" ;
tik . Start ( ) ;
tik . WaitForExit ( ) ;
2020-04-18 03:31:36 +00:00
Thread . Sleep ( 6000 ) ;
2020-04-16 04:41:25 +00:00
if ( ! File . Exists ( Path . Combine ( tempPath , "game.iso" ) ) )
{
Console . Clear ( ) ;
2020-04-17 16:02:45 +00:00
throw new Exception ( "WIIAn error occured while Creating the ISO" ) ;
2020-04-16 04:41:25 +00:00
}
romPath = Path . Combine ( tempPath , "game.iso" ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 60 ;
2020-04-16 04:41:25 +00:00
}
2020-04-16 18:52:26 +00:00
mvvm . msg = "Extracting Ticket and TMD from ISO..." ;
2020-04-16 04:41:25 +00:00
tik . StartInfo . FileName = Path . Combine ( toolsPath , "wit.exe" ) ;
tik . StartInfo . Arguments = $"extract \" { romPath } \ " --psel data --files +tmd.bin --files +ticket.bin --dest \"{Path.Combine(tempPath, " tik ")}\" -vv1" ;
tik . Start ( ) ;
tik . WaitForExit ( ) ;
if ( ! Directory . Exists ( Path . Combine ( tempPath , "tik" ) ) | | ! File . Exists ( Path . Combine ( tempPath , "tik" , "tmd.bin" ) ) | | ! File . Exists ( Path . Combine ( tempPath , "tik" , "ticket.bin" ) ) )
{
2020-04-17 16:02:45 +00:00
throw new Exception ( "WIIAn error occured while extracting the Ticket and TMD" ) ;
2020-04-16 04:41:25 +00:00
}
Console . WriteLine ( "Finished extracting" ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 65 ;
mvvm . msg = "Copying TIK and TMD..." ;
2020-04-16 04:41:25 +00:00
Console . WriteLine ( "Copying TIK and TMD..." ) ;
if ( File . Exists ( Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) ) { File . Delete ( Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) ; }
File . Copy ( Path . Combine ( tempPath , "tik" , "tmd.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) ;
if ( File . Exists ( Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) ) { File . Delete ( Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) ; }
File . Copy ( Path . Combine ( tempPath , "tik" , "ticket.bin" ) , Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) ;
if ( ! File . Exists ( Path . Combine ( baseRomPath , "code" , "rvlt.tik" ) ) | | ! File . Exists ( Path . Combine ( baseRomPath , "code" , "rvlt.tmd" ) ) )
{
Console . Clear ( ) ;
2020-04-17 16:02:45 +00:00
throw new Exception ( "WIIAn error occured while copying the Ticket and TMD" ) ;
2020-04-16 04:41:25 +00:00
}
Console . WriteLine ( "Finished Copying" ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 70 ;
2020-04-18 03:31:36 +00:00
Thread . Sleep ( 6000 ) ;
2020-04-16 18:52:26 +00:00
mvvm . msg = "Injecting ROM..." ;
2020-04-16 04:41:25 +00:00
Console . WriteLine ( "Converting Game to NFS format..." ) ;
string olddir = Directory . GetCurrentDirectory ( ) ;
Directory . SetCurrentDirectory ( Path . Combine ( baseRomPath , "content" ) ) ;
tik . StartInfo . FileName = Path . Combine ( toolsPath , "nfs2iso2nfs.exe" ) ;
if ( ! mvm . GC )
{
string extra = "" ;
if ( mvm . Index = = 2 )
{
extra = "-horizontal " ;
}
if ( mvm . Index = = 3 ) { extra = "-wiimote " ; }
if ( mvm . Index = = 4 ) { extra = "-instantcc " ; }
if ( mvm . Index = = 5 ) { extra = "-nocc " ; }
if ( mvm . LR ) { extra + = "-lrpatch " ; }
Console . WriteLine ( extra ) ;
Console . ReadLine ( ) ;
tik . StartInfo . Arguments = $"-enc {extra}-iso \" { romPath } \ "" ;
}
else
{
tik . StartInfo . Arguments = $"-enc -homebrew -passthrough -iso \" { romPath } \ "" ;
}
tik . Start ( ) ;
tik . WaitForExit ( ) ;
Console . WriteLine ( "Finished Conversion" ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 80 ;
2020-04-16 04:41:25 +00:00
Directory . SetCurrentDirectory ( olddir ) ;
2020-04-04 22:16:55 +00:00
}
2020-04-07 01:09:05 +00:00
}
2020-04-16 04:41:25 +00:00
2020-04-07 01:09:05 +00:00
public static void MSX ( string injectRomPath )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Reading Header from Base..." ;
2020-04-07 02:21:27 +00:00
byte [ ] test = new byte [ 0x580B3 ] ;
using ( var fs = new FileStream ( Path . Combine ( baseRomPath , "content" , "msx" , "msx.pkg" ) ,
FileMode . Open ,
FileAccess . ReadWrite ) )
{
fs . Read ( test , 0 , 0x580B3 ) ;
fs . Close ( ) ;
File . Delete ( Path . Combine ( baseRomPath , "content" , "msx" , "msx.pkg" ) ) ;
}
2020-04-16 18:52:26 +00:00
mvvm . Progress = 20 ;
mvvm . msg = "Creating new PKG with read Header..." ;
2020-04-07 02:21:27 +00:00
using ( var fs = new FileStream ( Path . Combine ( baseRomPath , "content" , "msx" , "msx.pkg" ) ,
FileMode . OpenOrCreate ,
FileAccess . ReadWrite ) )
{
2020-04-07 01:09:05 +00:00
2020-04-07 02:21:27 +00:00
fs . Write ( test , 0 , 0x580B3 ) ;
fs . Close ( ) ;
}
2020-04-16 18:52:26 +00:00
mvvm . Progress = 30 ;
mvvm . msg = "Reading ROM content..." ;
2020-04-07 02:21:27 +00:00
using ( var fs = new FileStream ( injectRomPath ,
FileMode . OpenOrCreate ,
FileAccess . ReadWrite ) )
{
test = new byte [ fs . Length ] ;
fs . Read ( test , 0 , test . Length - 1 ) ;
}
2020-04-16 18:52:26 +00:00
mvvm . Progress = 50 ;
mvvm . msg = "Injecting ROM into new PKG..." ;
2020-04-07 02:21:27 +00:00
using ( var fs = new FileStream ( Path . Combine ( baseRomPath , "content" , "msx" , "msx.pkg" ) ,
FileMode . Append ) )
{
fs . Write ( test , 0 , test . Length ) ;
}
2020-04-16 18:52:26 +00:00
mvvm . Progress = 80 ;
2020-03-01 13:45:00 +00:00
}
2020-04-16 04:41:25 +00:00
2020-03-01 13:45:00 +00:00
public static void Clean ( )
{
if ( Directory . Exists ( tempPath ) )
{
Directory . Delete ( tempPath , true ) ;
}
}
2020-04-17 01:28:14 +00:00
[STAThread]
2020-03-01 13:45:00 +00:00
public static void Loadiine ( string gameName )
{
2020-04-04 22:16:55 +00:00
if ( gameName = = null | | gameName = = string . Empty ) gameName = "NoName" ;
2020-04-22 00:24:35 +00:00
Regex reg = new Regex ( "[^a-zA-Z0-9 é -]" ) ;
2020-03-01 13:45:00 +00:00
//string outputPath = Path.Combine(Properties.Settings.Default.InjectionPath, gameName);
2020-05-22 09:36:31 +00:00
string outputPath = Path . Combine ( Properties . Settings . Default . OutPath , $"[LOADIINE]{reg.Replace(gameName,"")} [{mvvm.prodcode}]" ) ;
2020-05-24 20:59:09 +00:00
mvvm . foldername = $"[LOADIINE]{reg.Replace(gameName, "")} [{mvvm.prodcode}]" ;
2020-03-01 13:45:00 +00:00
int i = 0 ;
while ( Directory . Exists ( outputPath ) )
{
2020-05-22 09:36:31 +00:00
outputPath = Path . Combine ( Properties . Settings . Default . OutPath , $"[LOADIINE]{reg.Replace(gameName, "")} [{mvvm.prodcode}]_{i}" ) ;
2020-05-24 20:59:09 +00:00
mvvm . foldername = $"[LOADIINE]{reg.Replace(gameName, "")} [{mvvm.prodcode}]_{i}" ;
2020-03-01 13:45:00 +00:00
i + + ;
}
2020-05-24 20:59:09 +00:00
2020-04-04 22:16:55 +00:00
DirectoryCopy ( baseRomPath , outputPath , true ) ;
2020-03-01 13:45:00 +00:00
2020-06-14 17:18:28 +00:00
Custom_Message cm = new Custom_Message ( "Injection Complete" , $"To Open the Location of the Inject press Open Folder.\nIf you want the inject to be put on your SD now, press Copy to SD." , Settings . Default . OutPath ) ;
2020-05-06 21:53:52 +00:00
try
{
cm . Owner = mvvm . mw ;
2020-06-11 08:12:03 +00:00
} catch ( Exception )
2020-05-06 21:53:52 +00:00
{
}
cm . ShowDialog ( ) ;
2020-03-01 13:45:00 +00:00
Clean ( ) ;
}
2020-04-17 01:28:14 +00:00
[STAThread]
2020-04-10 20:23:49 +00:00
public static void Packing ( string gameName , MainViewModel mvm )
2020-03-01 13:45:00 +00:00
{
2020-04-16 18:52:26 +00:00
mvm . msg = "Checking Tools..." ;
2020-04-10 20:23:49 +00:00
mvm . InjcttoolCheck ( ) ;
2020-04-16 18:52:26 +00:00
mvm . Progress = 20 ;
mvm . msg = "Creating Outputfolder..." ;
2020-04-22 00:24:35 +00:00
Regex reg = new Regex ( "[^a-zA-Z0-9 -]" ) ;
2020-04-04 22:16:55 +00:00
if ( gameName = = null | | gameName = = string . Empty ) gameName = "NoName" ;
2020-03-01 13:45:00 +00:00
//string outputPath = Path.Combine(Properties.Settings.Default.InjectionPath, gameName);
2020-04-22 00:24:35 +00:00
string outputPath = Path . Combine ( Properties . Settings . Default . OutPath , $"[WUP]{reg.Replace(gameName,"")}" ) ;
2020-05-24 20:59:09 +00:00
mvvm . foldername = $"[WUP]{reg.Replace(gameName, "")}" ;
2020-03-01 13:45:00 +00:00
int i = 0 ;
while ( Directory . Exists ( outputPath ) )
{
2020-04-22 00:24:35 +00:00
outputPath = Path . Combine ( Properties . Settings . Default . OutPath , $"[WUP]{reg.Replace(gameName,"")}_{i}" ) ;
2020-05-24 20:59:09 +00:00
mvvm . foldername = $"[WUP]{reg.Replace(gameName, "")}_{i}" ;
2020-03-01 13:45:00 +00:00
i + + ;
}
2020-05-24 20:59:09 +00:00
2020-04-16 18:52:26 +00:00
mvm . Progress = 40 ;
mvm . msg = "Packing..." ;
2020-03-01 13:45:00 +00:00
using ( Process cnuspacker = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
if ( ! mvm . debug )
{
cnuspacker . StartInfo . UseShellExecute = false ;
cnuspacker . StartInfo . CreateNoWindow = true ;
}
2020-03-01 13:45:00 +00:00
cnuspacker . StartInfo . FileName = Path . Combine ( toolsPath , "CNUSPACKER.exe" ) ;
2020-04-04 22:16:55 +00:00
cnuspacker . StartInfo . Arguments = $"-in \" { baseRomPath } \ " -out \"{outputPath}\" -encryptKeyWith {Properties.Settings.Default.Ckey}" ;
2020-03-01 13:45:00 +00:00
cnuspacker . Start ( ) ;
cnuspacker . WaitForExit ( ) ;
}
2020-04-16 18:52:26 +00:00
mvm . Progress = 90 ;
mvm . msg = "Cleaning..." ;
Clean ( ) ;
mvm . Progress = 100 ;
2020-04-17 01:28:14 +00:00
mvm . msg = "" ;
2020-03-01 13:45:00 +00:00
}
2020-04-02 23:45:12 +00:00
public static void Download ( MainViewModel mvm )
2020-04-16 04:41:25 +00:00
2020-03-01 13:45:00 +00:00
{
2020-04-16 18:52:26 +00:00
2020-04-19 17:36:03 +00:00
mvm . InjcttoolCheck ( ) ;
GameBases b = mvm . getBasefromName ( mvm . SelectedBaseAsString ) ;
//GetKeyOfBase
TKeys key = mvm . getTkey ( b ) ;
if ( mvm . GameConfiguration . Console = = GameConsoles . WII | | mvm . GameConfiguration . Console = = GameConsoles . GCN )
2020-04-16 04:41:25 +00:00
{
2020-04-19 17:36:03 +00:00
using ( Process zip = new Process ( ) )
{
if ( Directory . Exists ( tempPath ) ) Directory . Delete ( tempPath , true ) ;
Directory . CreateDirectory ( tempPath ) ;
using ( Process download = new Process ( ) )
{
if ( ! mvm . debug )
{
download . StartInfo . UseShellExecute = false ;
download . StartInfo . CreateNoWindow = true ;
}
download . StartInfo . FileName = Path . Combine ( toolsPath , "WiiUDownloader.exe" ) ;
download . StartInfo . Arguments = $"{b.Tid} {key.Tkey} \" { Path . Combine ( tempPath , "download" ) } \ "" ;
download . Start ( ) ;
download . WaitForExit ( ) ;
}
mvm . Progress = 75 ;
using ( Process decrypt = new Process ( ) )
{
if ( ! mvm . debug )
{
decrypt . StartInfo . UseShellExecute = false ;
decrypt . StartInfo . CreateNoWindow = true ;
}
decrypt . StartInfo . FileName = Path . Combine ( toolsPath , "Cdecrypt.exe" ) ;
decrypt . StartInfo . Arguments = $"{Properties.Settings.Default.Ckey} \" { Path . Combine ( tempPath , "download" ) } \ " \"{Path.Combine(Properties.Settings.Default.BasePath, $" { b . Name . Replace ( ":" , "" ) } [ { b . Region . ToString ( ) } ] ")}\"" ;
decrypt . Start ( ) ;
decrypt . WaitForExit ( ) ;
}
mvm . Progress + = 10 ;
File . Delete ( Path . Combine ( Properties . Settings . Default . BasePath , $"{b.Name.Replace(" : ", " ")} [{b.Region.ToString()}]" , "code" , "fw.img" ) ) ;
File . Delete ( Path . Combine ( Properties . Settings . Default . BasePath , $"{b.Name.Replace(" : ", " ")} [{b.Region.ToString()}]" , "code" , "fw.tmd" ) ) ;
if ( Directory . Exists ( Path . Combine ( toolsPath , "IKVM" ) ) ) { Directory . Delete ( Path . Combine ( toolsPath , "IKVM" ) , true ) ; }
if ( ! mvm . debug )
{
zip . StartInfo . UseShellExecute = false ;
zip . StartInfo . CreateNoWindow = true ;
}
zip . StartInfo . FileName = Path . Combine ( toolsPath , "7za.exe" ) ;
zip . StartInfo . Arguments = $"x \" { Path . Combine ( toolsPath , "IKVM.zip" ) } \ " -o\"{Path.Combine(toolsPath, " IKVM ")}\"" ;
zip . Start ( ) ;
zip . WaitForExit ( ) ;
mvm . Progress + = 10 ;
string [ ] JNUSToolConfig = { "http://ccs.cdn.wup.shop.nintendo.net/ccs/download" , Properties . Settings . Default . Ckey } ;
string savedir = Directory . GetCurrentDirectory ( ) ;
File . WriteAllLines ( Path . Combine ( toolsPath , "IKVM" , "config" ) , JNUSToolConfig ) ;
Directory . SetCurrentDirectory ( Path . Combine ( toolsPath , "IKVM" ) ) ;
zip . StartInfo . FileName = "JNUSTool.exe" ;
zip . StartInfo . Arguments = $"{b.Tid} {key.Tkey} -file /code/fw.img" ;
zip . Start ( ) ;
zip . WaitForExit ( ) ;
zip . StartInfo . Arguments = $"{b.Tid} {key.Tkey} -file /code/fw.tmd" ;
zip . Start ( ) ;
zip . WaitForExit ( ) ;
Directory . SetCurrentDirectory ( savedir ) ;
var directories = Directory . GetDirectories ( Path . Combine ( toolsPath , "IKVM" ) ) ;
string name = "" ;
foreach ( var s in directories )
{
if ( s . Contains ( b . Name ) )
{
var split = s . Split ( '\\' ) ;
name = split [ split . Length - 1 ] ;
}
}
File . Copy ( Path . Combine ( toolsPath , "IKVM" , name , "code" , "fw.img" ) , Path . Combine ( Properties . Settings . Default . BasePath , $"{b.Name.Replace(" : ", " ")} [{b.Region.ToString()}]" , "code" , "fw.img" ) ) ;
File . Copy ( Path . Combine ( toolsPath , "IKVM" , name , "code" , "fw.tmd" ) , Path . Combine ( Properties . Settings . Default . BasePath , $"{b.Name.Replace(" : ", " ")} [{b.Region.ToString()}]" , "code" , "fw.tmd" ) ) ;
Directory . Delete ( Path . Combine ( toolsPath , "IKVM" ) , true ) ;
mvm . Progress + = 5 ;
}
}
else
{
2020-04-16 18:52:26 +00:00
if ( Directory . Exists ( tempPath ) ) Directory . Delete ( tempPath , true ) ;
Directory . CreateDirectory ( tempPath ) ;
using ( Process download = new Process ( ) )
{
if ( ! mvm . debug )
{
download . StartInfo . UseShellExecute = false ;
download . StartInfo . CreateNoWindow = true ;
}
2020-04-19 17:36:03 +00:00
2020-04-16 18:52:26 +00:00
download . StartInfo . FileName = Path . Combine ( toolsPath , "WiiUDownloader.exe" ) ;
download . StartInfo . Arguments = $"{b.Tid} {key.Tkey} \" { Path . Combine ( tempPath , "download" ) } \ "" ;
download . Start ( ) ;
download . WaitForExit ( ) ;
}
2020-04-18 03:31:36 +00:00
mvm . Progress = 75 ;
2020-04-16 18:52:26 +00:00
using ( Process decrypt = new Process ( ) )
{
if ( ! mvm . debug )
{
decrypt . StartInfo . UseShellExecute = false ;
decrypt . StartInfo . CreateNoWindow = true ;
}
decrypt . StartInfo . FileName = Path . Combine ( toolsPath , "Cdecrypt.exe" ) ;
decrypt . StartInfo . Arguments = $"{Properties.Settings.Default.Ckey} \" { Path . Combine ( tempPath , "download" ) } \ " \"{Path.Combine(Properties.Settings.Default.BasePath, $" { b . Name . Replace ( ":" , "" ) } [ { b . Region . ToString ( ) } ] ")}\"" ;
decrypt . Start ( ) ;
decrypt . WaitForExit ( ) ;
}
2020-04-19 17:36:03 +00:00
mvm . Progress = 100 ;
2020-04-16 04:41:25 +00:00
}
2020-04-19 17:36:03 +00:00
2020-04-16 04:41:25 +00:00
//GetCurrentSelectedBase
2020-03-01 13:45:00 +00:00
}
2020-04-06 17:50:12 +00:00
public static string ExtractBase ( string path , GameConsoles console )
{
if ( ! Directory . Exists ( Path . Combine ( Properties . Settings . Default . BasePath , "CustomBases" ) ) )
{
Directory . CreateDirectory ( Path . Combine ( Properties . Settings . Default . BasePath , "CustomBases" ) ) ;
}
string outputPath = Path . Combine ( Properties . Settings . Default . BasePath , "CustomBases" , $"[{console.ToString()}] Custom" ) ;
int i = 0 ;
while ( Directory . Exists ( outputPath ) )
{
outputPath = Path . Combine ( Properties . Settings . Default . BasePath , $"[{console.ToString()}] Custom_{i}" ) ;
i + + ;
}
using ( Process decrypt = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
decrypt . StartInfo . UseShellExecute = false ;
decrypt . StartInfo . CreateNoWindow = true ;
2020-04-06 17:50:12 +00:00
decrypt . StartInfo . FileName = Path . Combine ( toolsPath , "Cdecrypt.exe" ) ;
decrypt . StartInfo . Arguments = $"{Properties.Settings.Default.Ckey} \" { path } \ " \"{outputPath}" ;
2020-03-01 13:45:00 +00:00
2020-04-06 17:50:12 +00:00
decrypt . Start ( ) ;
decrypt . WaitForExit ( ) ;
}
return outputPath ;
}
2020-03-01 13:45:00 +00:00
// This function changes TitleID, ProductCode and GameName in app.xml (ID) and meta.xml (ID, ProductCode, Name)
2020-04-22 00:24:35 +00:00
private static void EditXML ( string gameNameOr , int index , string code )
2020-03-01 13:45:00 +00:00
{
2020-04-25 06:40:38 +00:00
string gameName = string . Empty ;
if ( gameNameOr ! = string . Empty & & gameNameOr ! = null )
{
2020-06-14 17:05:01 +00:00
Regex reg = new Regex ( "[^a-zA-Z0-9 éÉ - |]" ) ;
2020-04-28 23:40:54 +00:00
gameName = reg . Replace ( gameNameOr , "" ) ;
if ( gameName . Contains ( '|' ) )
{
var split = gameName . Split ( '|' ) ;
gameName = split [ 0 ] + ", " + split [ 1 ] ;
}
2020-04-25 06:40:38 +00:00
}
2020-03-01 13:45:00 +00:00
string metaXml = Path . Combine ( baseRomPath , "meta" , "meta.xml" ) ;
string appXml = Path . Combine ( baseRomPath , "code" , "app.xml" ) ;
Random random = new Random ( ) ;
2020-05-15 21:20:24 +00:00
string ID = $"{random.Next(0x3000, 0x10000):X4}{random.Next(0x3000, 0x10000):X4}" ;
2020-05-22 09:36:31 +00:00
string ID2 = $"{random.Next(0x3000, 0x10000):X4}" ;
mvvm . prodcode = ID2 ;
2020-05-15 21:20:24 +00:00
XmlDocument doc = new XmlDocument ( ) ;
2020-04-16 04:41:25 +00:00
try
2020-04-04 22:16:55 +00:00
{
2020-04-16 04:41:25 +00:00
doc . Load ( metaXml ) ;
if ( gameName ! = null & & gameName ! = string . Empty )
{
2020-04-28 23:40:54 +00:00
doc . SelectSingleNode ( "menu/longname_ja" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_en" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_fr" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_de" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_it" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_es" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_zhs" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_ko" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_nl" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_pt" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_ru" ) . InnerText = gameName . Replace ( "," , "" ) ;
doc . SelectSingleNode ( "menu/longname_zht" ) . InnerText = gameName . Replace ( "," , "" ) ;
2020-04-16 04:41:25 +00:00
}
if ( code ! = null )
{
doc . SelectSingleNode ( "menu/product_code" ) . InnerText = $"WUP-N-{code}" ;
}
else
{
2020-05-15 21:20:24 +00:00
doc . SelectSingleNode ( "menu/product_code" ) . InnerText = $"WUP-N-{ID2}" ;
2020-04-16 04:41:25 +00:00
}
if ( index > 0 )
{
doc . SelectSingleNode ( "menu/drc_use" ) . InnerText = "65537" ;
}
2020-05-15 21:20:24 +00:00
doc . SelectSingleNode ( "menu/title_id" ) . InnerText = $"00050002{ID}" ;
doc . SelectSingleNode ( "menu/group_id" ) . InnerText = $"0000{ID2}" ;
2020-04-16 04:41:25 +00:00
if ( gameName ! = null & & gameName ! = string . Empty )
{
2020-04-28 23:40:54 +00:00
doc . SelectSingleNode ( "menu/shortname_ja" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_fr" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_de" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_en" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_it" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_es" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_zhs" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_ko" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_nl" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_pt" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_ru" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
doc . SelectSingleNode ( "menu/shortname_zht" ) . InnerText = gameName . Split ( ',' ) [ 0 ] ;
2020-04-16 04:41:25 +00:00
}
doc . Save ( metaXml ) ;
}
catch ( NullReferenceException )
2020-04-04 22:16:55 +00:00
{
2020-04-17 16:02:45 +00:00
2020-04-04 22:16:55 +00:00
}
2020-03-01 13:45:00 +00:00
2020-04-16 04:41:25 +00:00
try
{
doc . Load ( appXml ) ;
2020-05-15 21:20:24 +00:00
doc . SelectSingleNode ( "app/title_id" ) . InnerText = $"00050002{ID}" ;
//doc.SelectSingleNode("app/title_id").InnerText = $"0005000247414645";
doc . SelectSingleNode ( "app/group_id" ) . InnerText = $"0000{ID2}" ;
2020-04-16 04:41:25 +00:00
doc . Save ( appXml ) ;
}
catch ( NullReferenceException )
{
2020-04-17 16:02:45 +00:00
2020-04-16 04:41:25 +00:00
}
2020-03-01 13:45:00 +00:00
}
//This function copies the custom or normal Base to the working directory
private static void CopyBase ( string baserom , string customPath )
{
if ( Directory . Exists ( baseRomPath ) ) // sanity check
{
Directory . Delete ( baseRomPath , true ) ;
}
if ( baserom = = "Custom" )
{
DirectoryCopy ( customPath , baseRomPath , true ) ;
}
else
{
2020-04-04 22:16:55 +00:00
DirectoryCopy ( Path . Combine ( Properties . Settings . Default . BasePath , baserom ) , baseRomPath , true ) ;
2020-03-01 13:45:00 +00:00
}
}
2020-04-06 13:50:54 +00:00
private static void TG16 ( string injectRomPath )
{
2020-04-07 03:55:44 +00:00
//checking if folder
if ( Directory . Exists ( injectRomPath ) )
{
DirectoryCopy ( injectRomPath , "test" , true ) ;
//TurboGrafCD
using ( Process TurboInject = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Creating TurboCD Pkg..." ;
2020-04-07 03:55:44 +00:00
TurboInject . StartInfo . UseShellExecute = false ;
TurboInject . StartInfo . CreateNoWindow = true ;
TurboInject . StartInfo . FileName = Path . Combine ( toolsPath , "BuildTurboCDPcePkg.exe" ) ;
TurboInject . StartInfo . Arguments = $"test" ;
TurboInject . Start ( ) ;
TurboInject . WaitForExit ( ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 70 ;
2020-04-07 03:55:44 +00:00
}
Directory . Delete ( "test" , true ) ;
}
else
2020-04-06 13:50:54 +00:00
{
2020-04-07 03:55:44 +00:00
//creating pkg file including the TG16 rom
using ( Process TurboInject = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Creating Turbo16 Pkg..." ;
2020-04-07 03:55:44 +00:00
TurboInject . StartInfo . UseShellExecute = false ;
TurboInject . StartInfo . CreateNoWindow = true ;
TurboInject . StartInfo . FileName = Path . Combine ( toolsPath , "BuildPcePkg.exe" ) ;
TurboInject . StartInfo . Arguments = $"\" { injectRomPath } \ "" ;
TurboInject . Start ( ) ;
TurboInject . WaitForExit ( ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 70 ;
2020-04-07 03:55:44 +00:00
}
2020-04-06 13:50:54 +00:00
}
2020-04-16 18:52:26 +00:00
mvvm . msg = "Injecting ROM..." ;
2020-04-06 13:50:54 +00:00
//replacing tg16 rom
File . Delete ( Path . Combine ( baseRomPath , "content" , "pceemu" , "pce.pkg" ) ) ;
File . Copy ( "pce.pkg" , Path . Combine ( baseRomPath , "content" , "pceemu" , "pce.pkg" ) ) ;
File . Delete ( "pce.pkg" ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 80 ;
2020-04-06 13:50:54 +00:00
}
2020-03-01 13:45:00 +00:00
private static void NESSNES ( string injectRomPath )
{
string rpxFile = Directory . GetFiles ( Path . Combine ( baseRomPath , "code" ) , "*.rpx" ) [ 0 ] ; //To get the RPX path where the NES/SNES rom needs to be Injected in
2020-04-16 18:52:26 +00:00
mvvm . msg = "Decompressing RPX..." ;
2020-03-01 13:45:00 +00:00
RPXdecomp ( rpxFile ) ; //Decompresses the RPX to be able to write the game into it
2020-04-16 18:52:26 +00:00
mvvm . Progress = 20 ;
2020-06-11 08:17:25 +00:00
if ( mvvm . pixelperfect )
{
using ( Process retroinject = new Process ( ) )
{
mvvm . msg = "Applying Pixel Perfect Patches..." ;
retroinject . StartInfo . UseShellExecute = false ;
retroinject . StartInfo . CreateNoWindow = true ;
retroinject . StartInfo . RedirectStandardOutput = true ;
retroinject . StartInfo . RedirectStandardError = true ;
retroinject . StartInfo . FileName = Path . Combine ( toolsPath , "ChangeAspectRatio.exe" ) ;
retroinject . StartInfo . Arguments = $"\" { rpxFile } \ "" ;
retroinject . Start ( ) ;
retroinject . WaitForExit ( ) ;
mvvm . Progress = 30 ;
}
}
2020-03-01 13:45:00 +00:00
using ( Process retroinject = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Injecting ROM..." ;
2020-03-01 13:45:00 +00:00
retroinject . StartInfo . UseShellExecute = false ;
retroinject . StartInfo . CreateNoWindow = true ;
2020-04-08 21:48:11 +00:00
retroinject . StartInfo . RedirectStandardOutput = true ;
retroinject . StartInfo . RedirectStandardError = true ;
2020-03-01 13:45:00 +00:00
retroinject . StartInfo . FileName = Path . Combine ( toolsPath , "retroinject.exe" ) ;
retroinject . StartInfo . Arguments = $"\" { rpxFile } \ " \"{injectRomPath}\" \"{rpxFile}\"" ;
retroinject . Start ( ) ;
retroinject . WaitForExit ( ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 70 ;
2020-04-08 21:48:11 +00:00
var s = retroinject . StandardOutput . ReadToEnd ( ) ;
var e = retroinject . StandardError . ReadToEnd ( ) ;
if ( e . Contains ( "is too large" ) | | s . Contains ( "is too large" ) )
{
2020-04-16 18:52:26 +00:00
mvvm . Progress = 100 ;
2020-04-08 21:48:11 +00:00
throw new Exception ( "retro" ) ;
}
2020-04-10 18:48:12 +00:00
2020-03-01 13:45:00 +00:00
}
2020-04-16 18:52:26 +00:00
mvvm . msg = "Compressing RPX..." ;
2020-03-01 13:45:00 +00:00
RPXcomp ( rpxFile ) ; //Compresses the RPX
2020-04-16 18:52:26 +00:00
mvvm . Progress = 80 ;
2020-03-01 13:45:00 +00:00
}
private static void GBA ( string injectRomPath )
{
2020-04-07 21:21:38 +00:00
bool delete = false ;
if ( ! new FileInfo ( injectRomPath ) . Extension . Contains ( "gba" ) )
{
//it's a GBC or GB rom so it needs to be copied into goomba.gba and then padded to 32Mb (16 would work too but just ot be save)
using ( Process goomba = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Injecting GB/GBC ROM into goomba..." ;
2020-04-07 21:21:38 +00:00
goomba . StartInfo . UseShellExecute = false ;
goomba . StartInfo . CreateNoWindow = true ;
goomba . StartInfo . FileName = "cmd.exe" ;
goomba . StartInfo . Arguments = $"/c copy /b \" { Path . Combine ( toolsPath , "goomba.gba" ) } \ "+\"{injectRomPath}\" \"{Path.Combine(toolsPath, " goombamenu . gba ")}\"" ;
goomba . Start ( ) ;
goomba . WaitForExit ( ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 20 ;
2020-04-07 21:21:38 +00:00
}
2020-04-16 18:52:26 +00:00
mvvm . msg = "Padding goomba ROM..." ;
2020-04-07 21:21:38 +00:00
//padding
byte [ ] rom = new byte [ 33554432 ] ;
FileStream fs = new FileStream ( Path . Combine ( toolsPath , "goombamenu.gba" ) , FileMode . Open ) ;
fs . Read ( rom , 0 , ( int ) fs . Length ) ;
fs . Close ( ) ;
File . WriteAllBytes ( Path . Combine ( toolsPath , "goombaPadded.gba" ) , rom ) ;
Console . ReadLine ( ) ;
injectRomPath = Path . Combine ( toolsPath , "goombaPadded.gba" ) ;
delete = true ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 40 ;
2020-04-07 21:21:38 +00:00
}
2020-04-21 02:05:19 +00:00
if ( mvvm . PokePatch )
{
mvvm . msg = "Applying PokePatch" ;
File . Copy ( injectRomPath , Path . Combine ( tempPath , "rom.gba" ) ) ;
injectRomPath = Path . Combine ( tempPath , "rom.gba" ) ;
PokePatch ( injectRomPath ) ;
delete = true ;
mvvm . PokePatch = false ;
mvvm . Progress = 40 ;
}
2020-04-07 21:21:38 +00:00
2020-03-01 13:45:00 +00:00
using ( Process psb = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Injecting ROM..." ;
2020-03-01 13:45:00 +00:00
psb . StartInfo . UseShellExecute = false ;
psb . StartInfo . CreateNoWindow = true ;
psb . StartInfo . FileName = Path . Combine ( toolsPath , "psb.exe" ) ;
psb . StartInfo . Arguments = $"\" { Path . Combine ( baseRomPath , "content" , "alldata.psb.m" ) } \ " \"{injectRomPath}\" \"{Path.Combine(baseRomPath, " content ", " alldata . psb . m ")}\"" ;
psb . Start ( ) ;
psb . WaitForExit ( ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 80 ;
2020-03-01 13:45:00 +00:00
}
2020-04-07 21:21:38 +00:00
if ( delete )
{
File . Delete ( injectRomPath ) ;
2020-04-21 02:05:19 +00:00
if ( File . Exists ( Path . Combine ( toolsPath , "goombamenu.gba" ) ) ) File . Delete ( Path . Combine ( toolsPath , "goombamenu.gba" ) ) ;
2020-04-07 21:21:38 +00:00
}
2020-03-01 13:45:00 +00:00
}
2020-04-16 04:41:25 +00:00
private static void DownloadSysTitle ( MainViewModel mvm )
{
if ( mvm . SysKeyset ( ) & & mvm . SysKey1set ( ) )
{
using ( Process download = new Process ( ) )
{
download . StartInfo . FileName = Path . Combine ( toolsPath , "WiiUDownloader.exe" ) ;
download . StartInfo . Arguments = $"0005001010004001 {Properties.Settings.Default.SysKey} \" { Path . Combine ( tempPath , "download" ) } \ "" ;
download . Start ( ) ;
download . WaitForExit ( ) ;
}
using ( Process decrypt = new Process ( ) )
{
decrypt . StartInfo . FileName = Path . Combine ( toolsPath , "Cdecrypt.exe" ) ;
decrypt . StartInfo . Arguments = $"{Properties.Settings.Default.Ckey} \" { Path . Combine ( tempPath , "download" ) } \ " \"{Path.Combine(Properties.Settings.Default.BasePath, $" vwiisys ")}\"" ;
decrypt . Start ( ) ;
decrypt . WaitForExit ( ) ;
}
using ( Process download = new Process ( ) )
{
Directory . Delete ( Path . Combine ( tempPath , "download" ) , true ) ;
download . StartInfo . FileName = Path . Combine ( toolsPath , "WiiUDownloader.exe" ) ;
download . StartInfo . Arguments = $"0005001010004000 {Properties.Settings.Default.SysKey1} \" { Path . Combine ( tempPath , "download" ) } \ "" ;
2020-03-01 13:45:00 +00:00
2020-04-16 04:41:25 +00:00
download . Start ( ) ;
download . WaitForExit ( ) ;
}
using ( Process decrypt = new Process ( ) )
{
decrypt . StartInfo . FileName = Path . Combine ( toolsPath , "Cdecrypt.exe" ) ;
decrypt . StartInfo . Arguments = $"{Properties.Settings.Default.Ckey} \" { Path . Combine ( tempPath , "download" ) } \ " \"{Path.Combine(tempPath, " tempd ")}\"" ;
decrypt . Start ( ) ;
decrypt . WaitForExit ( ) ;
File . Copy ( Path . Combine ( tempPath , "tempd" , "code" , "font.bin" ) , Path . Combine ( Properties . Settings . Default . BasePath , $"vwiisys" , "code" , "font.bin" ) ) ;
File . Copy ( Path . Combine ( tempPath , "tempd" , "code" , "deint.txt" ) , Path . Combine ( Properties . Settings . Default . BasePath , $"vwiisys" , "code" , "deint.txt" ) ) ;
File . Delete ( Path . Combine ( Properties . Settings . Default . BasePath , $"vwiisys" , "code" , "app.xml" ) ) ;
}
}
}
2020-03-01 13:45:00 +00:00
private static void NDS ( string injectRomPath )
{
2020-04-04 22:16:55 +00:00
string RomName = string . Empty ;
using ( Process getRomName = new Process ( ) )
2020-03-01 13:45:00 +00:00
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Getting BaseRom Name..." ;
2020-04-04 22:16:55 +00:00
getRomName . StartInfo . UseShellExecute = false ;
getRomName . StartInfo . CreateNoWindow = false ;
getRomName . StartInfo . RedirectStandardOutput = true ;
getRomName . StartInfo . FileName = "cmd.exe" ;
Console . WriteLine ( Directory . GetCurrentDirectory ( ) ) ;
//getRomName.StartInfo.Arguments = $"/c \"Tools\\7za.exe\" l \"temp\\baserom\\content\\0010\\rom.zip\" | findstr \"WUP\"";
2020-04-19 19:15:00 +00:00
getRomName . StartInfo . Arguments = "/c bin\\Tools\\7za.exe l bin\\temp\\baserom\\content\\0010\\rom.zip | findstr WUP" ;
2020-04-04 22:16:55 +00:00
getRomName . Start ( ) ;
getRomName . WaitForExit ( ) ;
var s = getRomName . StandardOutput . ReadToEnd ( ) ;
var split = s . Split ( ' ' ) ;
RomName = split [ split . Length - 1 ] . Replace ( "\r\n" , "" ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 15 ;
2020-03-01 13:45:00 +00:00
}
2020-04-04 22:16:55 +00:00
using ( Process RomEdit = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Removing BaseRom..." ;
2020-04-04 22:16:55 +00:00
RomEdit . StartInfo . UseShellExecute = false ;
RomEdit . StartInfo . CreateNoWindow = true ;
RomEdit . StartInfo . RedirectStandardOutput = true ;
RomEdit . StartInfo . FileName = Path . Combine ( toolsPath , "7za.exe" ) ;
//d Path.Combine(baseRomPath, "content", "0010", "rom.zip")
2020-04-19 19:15:00 +00:00
RomEdit . StartInfo . Arguments = $"d bin\\temp\\baserom\\content\\0010\\rom.zip" ;
2020-04-04 22:16:55 +00:00
RomEdit . Start ( ) ;
RomEdit . WaitForExit ( ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 40 ;
mvvm . msg = "Injecting ROM..." ;
2020-04-04 22:16:55 +00:00
File . Copy ( injectRomPath , $"{RomName}" ) ;
2020-04-19 19:15:00 +00:00
RomEdit . StartInfo . Arguments = $"u bin\\temp\\baserom\\content\\0010\\rom.zip {RomName}" ;
2020-04-04 22:16:55 +00:00
RomEdit . Start ( ) ;
RomEdit . WaitForExit ( ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 80 ;
2020-04-04 22:16:55 +00:00
}
File . Delete ( RomName ) ;
2020-03-01 13:45:00 +00:00
}
2020-04-04 22:16:55 +00:00
private static void N64 ( string injectRomPath , N64Conf config )
2020-03-01 13:45:00 +00:00
{
string mainRomPath = Directory . GetFiles ( Path . Combine ( baseRomPath , "content" , "rom" ) ) [ 0 ] ;
string mainIni = Path . Combine ( baseRomPath , "content" , "config" , $"{Path.GetFileName(mainRomPath)}.ini" ) ;
using ( Process n64convert = new Process ( ) )
{
2020-04-16 18:52:26 +00:00
mvvm . msg = "Injecting ROM..." ;
2020-03-01 13:45:00 +00:00
n64convert . StartInfo . UseShellExecute = false ;
n64convert . StartInfo . CreateNoWindow = true ;
n64convert . StartInfo . FileName = Path . Combine ( toolsPath , "N64Converter.exe" ) ;
n64convert . StartInfo . Arguments = $"\" { injectRomPath } \ " \"{mainRomPath}\"" ;
n64convert . Start ( ) ;
n64convert . WaitForExit ( ) ;
2020-04-16 18:52:26 +00:00
mvvm . Progress = 60 ;
2020-03-01 13:45:00 +00:00
}
2020-04-16 18:52:26 +00:00
if ( config . DarkFilter )
{
mvvm . msg = "Removing Dark Filter..." ;
string filePath = Path . Combine ( baseRomPath , "content" , "FrameLayout.arc" ) ;
using ( BinaryWriter writer = new BinaryWriter ( new FileStream ( filePath , FileMode . Open ) ) )
{
writer . Seek ( 0x1AD8 , SeekOrigin . Begin ) ;
writer . Write ( 0L ) ;
}
mvvm . Progress = 70 ;
}
mvvm . msg = "Copying INI..." ;
2020-04-06 19:30:31 +00:00
if ( config . INIBin = = null )
2020-04-04 22:16:55 +00:00
{
2020-04-06 19:30:31 +00:00
if ( config . INIPath = = null )
{
File . Delete ( mainIni ) ;
File . Copy ( Path . Combine ( toolsPath , "blank.ini" ) , mainIni ) ;
}
else
{
File . Delete ( mainIni ) ;
File . Copy ( config . INIPath , mainIni ) ;
}
2020-04-04 22:16:55 +00:00
}
else
2020-03-01 13:45:00 +00:00
{
2020-04-06 19:30:31 +00:00
ReadFileFromBin ( config . INIBin , "custom.ini" ) ;
2020-03-01 13:45:00 +00:00
File . Delete ( mainIni ) ;
2020-04-06 19:30:31 +00:00
File . Move ( "custom.ini" , mainIni ) ;
2020-03-01 13:45:00 +00:00
}
2020-04-16 18:52:26 +00:00
mvvm . Progress = 80 ;
2020-04-06 19:30:31 +00:00
2020-03-01 13:45:00 +00:00
2020-04-16 18:52:26 +00:00
2020-03-01 13:45:00 +00:00
}
//Compressed or decompresses the RPX using wiiurpxtool
private static void RPXdecomp ( string rpxpath )
{
using ( Process rpxtool = new Process ( ) )
{
rpxtool . StartInfo . UseShellExecute = false ;
rpxtool . StartInfo . CreateNoWindow = true ;
rpxtool . StartInfo . FileName = Path . Combine ( toolsPath , "wiiurpxtool.exe" ) ;
rpxtool . StartInfo . Arguments = $"-d \" { rpxpath } \ "" ;
rpxtool . Start ( ) ;
rpxtool . WaitForExit ( ) ;
}
}
private static void RPXcomp ( string rpxpath )
{
using ( Process rpxtool = new Process ( ) )
{
rpxtool . StartInfo . UseShellExecute = false ;
rpxtool . StartInfo . CreateNoWindow = true ;
rpxtool . StartInfo . FileName = Path . Combine ( toolsPath , "wiiurpxtool.exe" ) ;
rpxtool . StartInfo . Arguments = $"-c \" { rpxpath } \ "" ;
rpxtool . Start ( ) ;
rpxtool . WaitForExit ( ) ;
}
}
2020-04-06 15:51:15 +00:00
private static void ReadFileFromBin ( byte [ ] bin , string output )
2020-03-01 13:45:00 +00:00
{
2020-04-06 15:51:15 +00:00
File . WriteAllBytes ( output , bin ) ;
}
private static void Images ( GameConfig config )
{
2020-04-19 22:53:34 +00:00
bool usetemp = false ;
2020-04-20 09:31:26 +00:00
bool readbin = false ;
2020-04-06 15:51:15 +00:00
try
2020-03-01 13:45:00 +00:00
{
2020-04-06 15:51:15 +00:00
//is an image embedded? yes => export them and check for issues
//no => using path
if ( Directory . Exists ( imgPath ) ) // sanity check
{
Directory . Delete ( imgPath , true ) ;
}
Directory . CreateDirectory ( imgPath ) ;
//ICON
List < bool > Images = new List < bool > ( ) ;
if ( config . TGAIco . ImgBin = = null )
{
//use path
if ( config . TGAIco . ImgPath ! = null )
{
Images . Add ( true ) ;
CopyAndConvertImage ( config . TGAIco . ImgPath , Path . Combine ( imgPath ) , false , 128 , 128 , 32 , "iconTex.tga" ) ;
}
else
{
2020-04-17 01:28:14 +00:00
if ( File . Exists ( Path . Combine ( toolsPath , "iconTex.tga" ) ) )
{
CopyAndConvertImage ( Path . Combine ( toolsPath , "iconTex.tga" ) , Path . Combine ( imgPath ) , false , 128 , 128 , 32 , "iconTex.tga" ) ;
2020-04-20 09:31:26 +00:00
2020-04-17 01:28:14 +00:00
Images . Add ( true ) ;
}
else
{
Images . Add ( false ) ;
}
2020-04-06 15:51:15 +00:00
}
}
else
{
ReadFileFromBin ( config . TGAIco . ImgBin , $"iconTex.{config.TGAIco.extension}" ) ;
CopyAndConvertImage ( $"iconTex.{config.TGAIco.extension}" , Path . Combine ( imgPath ) , true , 128 , 128 , 32 , "iconTex.tga" ) ;
Images . Add ( true ) ;
}
2020-04-17 01:28:14 +00:00
if ( config . TGATv . ImgBin = = null )
2020-03-01 13:45:00 +00:00
{
2020-04-06 15:51:15 +00:00
//use path
2020-04-17 01:28:14 +00:00
if ( config . TGATv . ImgPath ! = null )
2020-04-06 15:51:15 +00:00
{
Images . Add ( true ) ;
2020-04-17 01:28:14 +00:00
CopyAndConvertImage ( config . TGATv . ImgPath , Path . Combine ( imgPath ) , false , 1280 , 720 , 24 , "bootTvTex.tga" ) ;
config . TGATv . ImgPath = Path . Combine ( imgPath , "bootTvTex.tga" ) ;
2020-04-06 15:51:15 +00:00
}
else
{
2020-04-19 19:15:00 +00:00
if ( File . Exists ( Path . Combine ( toolsPath , "bootTvTex.png" ) ) )
2020-04-17 01:28:14 +00:00
{
2020-04-19 19:15:00 +00:00
CopyAndConvertImage ( Path . Combine ( toolsPath , "bootTvTex.png" ) , Path . Combine ( imgPath ) , false , 1280 , 720 , 24 , "bootTvTex.tga" ) ;
2020-04-20 09:31:26 +00:00
usetemp = true ;
2020-04-17 01:28:14 +00:00
Images . Add ( true ) ;
2020-04-19 22:53:34 +00:00
2020-04-17 01:28:14 +00:00
}
else
{
Images . Add ( false ) ;
}
2020-04-06 15:51:15 +00:00
}
}
else
{
2020-04-17 01:28:14 +00:00
ReadFileFromBin ( config . TGATv . ImgBin , $"bootTvTex.{config.TGATv.extension}" ) ;
CopyAndConvertImage ( $"bootTvTex.{config.TGATv.extension}" , Path . Combine ( imgPath ) , true , 1280 , 720 , 24 , "bootTvTex.tga" ) ;
config . TGATv . ImgPath = Path . Combine ( imgPath , "bootTvTex.tga" ) ;
2020-04-06 15:51:15 +00:00
Images . Add ( true ) ;
2020-04-20 09:31:26 +00:00
readbin = true ;
2020-04-06 15:51:15 +00:00
}
2020-03-01 13:45:00 +00:00
2020-04-17 01:28:14 +00:00
//Drc
if ( config . TGADrc . ImgBin = = null )
2020-04-06 15:51:15 +00:00
{
//use path
2020-04-17 01:28:14 +00:00
if ( config . TGADrc . ImgPath ! = null )
2020-04-06 15:51:15 +00:00
{
Images . Add ( true ) ;
2020-04-17 01:28:14 +00:00
CopyAndConvertImage ( config . TGADrc . ImgPath , Path . Combine ( imgPath ) , false , 854 , 480 , 24 , "bootDrcTex.tga" ) ;
2020-04-06 15:51:15 +00:00
}
else
{
2020-04-17 01:28:14 +00:00
if ( Images [ 1 ] )
{
using ( Process conv = new Process ( ) )
{
2020-04-19 22:53:34 +00:00
2020-04-19 19:15:00 +00:00
if ( ! mvvm . debug )
2020-04-17 01:28:14 +00:00
{
conv . StartInfo . UseShellExecute = false ;
conv . StartInfo . CreateNoWindow = true ;
}
2020-04-19 22:53:34 +00:00
if ( usetemp )
{
File . Copy ( Path . Combine ( toolsPath , "bootTvTex.png" ) , Path . Combine ( tempPath , "bootDrcTex.png" ) ) ;
}
else
{
2020-04-17 01:28:14 +00:00
2020-04-20 09:31:26 +00:00
conv . StartInfo . FileName = Path . Combine ( toolsPath , "tga2png.exe" ) ;
if ( ! readbin )
{
conv . StartInfo . Arguments = $"-i \" { config . TGATv . ImgPath } \ " -o \"{Path.Combine(tempPath)}\"" ;
}
else
{
if ( config . TGATv . extension . Contains ( "tga" ) )
{
ReadFileFromBin ( config . TGATv . ImgBin , $"bootTvTex.{config.TGATv.extension}" ) ;
conv . StartInfo . Arguments = $"-i \" bootTvTex . { config . TGATv . extension } \ " -o \"{Path.Combine(tempPath)}\"" ;
}
else
{
ReadFileFromBin ( config . TGATv . ImgBin , Path . Combine ( tempPath , "bootTvTex.png" ) ) ;
}
}
if ( ! readbin | | config . TGATv . extension . Contains ( "tga" ) )
{
conv . Start ( ) ;
conv . WaitForExit ( ) ;
}
2020-04-19 22:53:34 +00:00
File . Copy ( Path . Combine ( tempPath , "bootTvTex.png" ) , Path . Combine ( tempPath , "bootDrcTex.png" ) ) ;
2020-04-20 09:31:26 +00:00
if ( File . Exists ( Path . Combine ( tempPath , "bootTvTex.png" ) ) ) File . Delete ( Path . Combine ( tempPath , "bootTvTex.png" ) ) ;
if ( File . Exists ( $"bootTvTex.{config.TGATv.extension}" ) ) File . Delete ( $"bootTvTex.{config.TGATv.extension}" ) ;
2020-04-19 22:53:34 +00:00
}
2020-04-17 01:28:14 +00:00
CopyAndConvertImage ( Path . Combine ( tempPath , "bootDrcTex.png" ) , Path . Combine ( imgPath ) , false , 854 , 480 , 24 , "bootDrcTex.tga" ) ;
Images . Add ( true ) ;
}
}
else
{
Images . Add ( false ) ;
}
2020-04-06 15:51:15 +00:00
}
}
else
{
2020-04-17 01:28:14 +00:00
ReadFileFromBin ( config . TGADrc . ImgBin , $"bootDrcTex.{config.TGADrc.extension}" ) ;
CopyAndConvertImage ( $"bootDrcTex.{config.TGADrc.extension}" , Path . Combine ( imgPath ) , true , 854 , 480 , 24 , "bootDrcTex.tga" ) ;
2020-04-06 15:51:15 +00:00
Images . Add ( true ) ;
2020-03-01 13:45:00 +00:00
}
2020-04-17 01:28:14 +00:00
//tv
2020-04-06 15:51:15 +00:00
//logo
if ( config . TGALog . ImgBin = = null )
2020-03-01 13:45:00 +00:00
{
2020-04-06 15:51:15 +00:00
//use path
if ( config . TGALog . ImgPath ! = null )
{
Images . Add ( true ) ;
CopyAndConvertImage ( config . TGALog . ImgPath , Path . Combine ( imgPath ) , false , 170 , 42 , 32 , "bootLogoTex.tga" ) ;
}
else
{
Images . Add ( false ) ;
}
2020-03-01 13:45:00 +00:00
}
2020-04-06 15:51:15 +00:00
else
2020-03-01 13:45:00 +00:00
{
2020-04-06 15:51:15 +00:00
ReadFileFromBin ( config . TGALog . ImgBin , $"bootLogoTex.{config.TGALog.extension}" ) ;
CopyAndConvertImage ( $"bootLogoTex.{config.TGALog.extension}" , Path . Combine ( imgPath ) , true , 170 , 42 , 32 , "bootLogoTex.tga" ) ;
Images . Add ( true ) ;
2020-03-01 13:45:00 +00:00
}
2020-04-06 15:51:15 +00:00
//Fixing Images + Injecting them
if ( Images [ 0 ] | | Images [ 1 ] | | Images [ 2 ] | | Images [ 3 ] )
2020-03-01 13:45:00 +00:00
{
2020-04-06 15:51:15 +00:00
using ( Process checkIfIssue = new Process ( ) )
{
checkIfIssue . StartInfo . UseShellExecute = false ;
checkIfIssue . StartInfo . CreateNoWindow = false ;
checkIfIssue . StartInfo . RedirectStandardOutput = true ;
checkIfIssue . StartInfo . RedirectStandardError = true ;
checkIfIssue . StartInfo . FileName = $"{Path.Combine(toolsPath," tga_verify . exe ")}" ;
Console . WriteLine ( Directory . GetCurrentDirectory ( ) ) ;
checkIfIssue . StartInfo . Arguments = $"\" { imgPath } \ "" ;
checkIfIssue . Start ( ) ;
checkIfIssue . WaitForExit ( ) ;
var s = checkIfIssue . StandardOutput . ReadToEnd ( ) ;
if ( s . Contains ( "width" ) | | s . Contains ( "height" ) | | s . Contains ( "depth" ) )
{
throw new Exception ( "Size" ) ;
}
var e = checkIfIssue . StandardError . ReadToEnd ( ) ;
if ( e . Contains ( "width" ) | | e . Contains ( "height" ) | | e . Contains ( "depth" ) )
{
throw new Exception ( "Size" ) ;
}
2020-04-09 18:40:48 +00:00
if ( e . Contains ( "TRUEVISION" ) | | s . Contains ( "TRUEVISION" ) )
{
checkIfIssue . StartInfo . UseShellExecute = false ;
checkIfIssue . StartInfo . CreateNoWindow = false ;
checkIfIssue . StartInfo . RedirectStandardOutput = true ;
checkIfIssue . StartInfo . RedirectStandardError = true ;
checkIfIssue . StartInfo . FileName = $"{Path.Combine(toolsPath, " tga_verify . exe ")}" ;
Console . WriteLine ( Directory . GetCurrentDirectory ( ) ) ;
checkIfIssue . StartInfo . Arguments = $"--fixup \" { imgPath } \ "" ;
checkIfIssue . Start ( ) ;
checkIfIssue . WaitForExit ( ) ;
}
2020-04-06 15:51:15 +00:00
Console . ReadLine ( ) ;
}
2020-04-17 01:28:14 +00:00
if ( Images [ 1 ] )
2020-04-06 15:51:15 +00:00
{
File . Delete ( Path . Combine ( baseRomPath , "meta" , "bootTvTex.tga" ) ) ;
File . Move ( Path . Combine ( imgPath , "bootTvTex.tga" ) , Path . Combine ( baseRomPath , "meta" , "bootTvTex.tga" ) ) ;
}
2020-04-17 01:28:14 +00:00
if ( Images [ 2 ] )
2020-04-06 15:51:15 +00:00
{
File . Delete ( Path . Combine ( baseRomPath , "meta" , "bootDrcTex.tga" ) ) ;
File . Move ( Path . Combine ( imgPath , "bootDrcTex.tga" ) , Path . Combine ( baseRomPath , "meta" , "bootDrcTex.tga" ) ) ;
}
if ( Images [ 0 ] )
{
File . Delete ( Path . Combine ( baseRomPath , "meta" , "iconTex.tga" ) ) ;
File . Move ( Path . Combine ( imgPath , "iconTex.tga" ) , Path . Combine ( baseRomPath , "meta" , "iconTex.tga" ) ) ;
}
if ( Images [ 3 ] )
{
File . Delete ( Path . Combine ( baseRomPath , "meta" , "bootLogoTex.tga" ) ) ;
File . Move ( Path . Combine ( imgPath , "bootLogoTex.tga" ) , Path . Combine ( baseRomPath , "meta" , "bootLogoTex.tga" ) ) ;
}
2020-03-01 13:45:00 +00:00
}
2020-04-06 15:51:15 +00:00
}
catch ( Exception e )
{
if ( e . Message . Contains ( "Size" ) )
2020-03-01 13:45:00 +00:00
{
2020-04-06 15:51:15 +00:00
throw e ;
2020-03-01 13:45:00 +00:00
}
2020-04-06 15:51:15 +00:00
throw new Exception ( "Images" ) ;
2020-03-01 13:45:00 +00:00
}
2020-04-06 15:51:15 +00:00
}
private static void CopyAndConvertImage ( string inputPath , string outputPath , bool delete , int widht , int height , int bit , string newname )
2020-03-01 13:45:00 +00:00
{
if ( inputPath . EndsWith ( ".tga" ) )
{
2020-04-06 15:51:15 +00:00
File . Copy ( inputPath , Path . Combine ( outputPath , newname ) ) ;
2020-03-01 13:45:00 +00:00
}
else
{
using ( Process png2tga = new Process ( ) )
{
png2tga . StartInfo . UseShellExecute = false ;
png2tga . StartInfo . CreateNoWindow = true ;
2020-04-28 23:40:54 +00:00
if ( new FileInfo ( inputPath ) . Extension . Contains ( "png" ) )
{
png2tga . StartInfo . FileName = Path . Combine ( toolsPath , "png2tga.exe" ) ;
} else if ( new FileInfo ( inputPath ) . Extension . Contains ( "jpg" ) )
{
png2tga . StartInfo . FileName = Path . Combine ( toolsPath , "jpg2tga.exe" ) ;
} else if ( new FileInfo ( inputPath ) . Extension . Contains ( "bmp" ) )
{
png2tga . StartInfo . FileName = Path . Combine ( toolsPath , "bmp2tga.exe" ) ;
}
2020-04-06 15:51:15 +00:00
png2tga . StartInfo . Arguments = $"-i \" { inputPath } \ " -o \"{outputPath}\" --width={widht} --height={height} --tga-bpp={bit} --tga-compression=none" ;
2020-03-01 13:45:00 +00:00
png2tga . Start ( ) ;
png2tga . WaitForExit ( ) ;
}
2020-04-06 15:51:15 +00:00
string name = Path . GetFileNameWithoutExtension ( inputPath ) ;
if ( File . Exists ( Path . Combine ( outputPath , name + ".tga" ) ) )
{
File . Move ( Path . Combine ( outputPath , name + ".tga" ) , Path . Combine ( outputPath , newname ) ) ;
}
}
if ( delete )
{
File . Delete ( inputPath ) ;
2020-03-01 13:45:00 +00:00
}
}
private static string RemoveHeader ( string filePath )
{
// logic taken from snesROMUtil
using ( FileStream inStream = new FileStream ( filePath , FileMode . Open ) )
{
byte [ ] header = new byte [ 512 ] ;
inStream . Read ( header , 0 , 512 ) ;
string string1 = BitConverter . ToString ( header , 8 , 3 ) ;
string string2 = Encoding . ASCII . GetString ( header , 0 , 11 ) ;
string string3 = BitConverter . ToString ( header , 30 , 16 ) ;
if ( string1 ! = "AA-BB-04" & & string2 ! = "GAME DOCTOR" & & string3 ! = "00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00" )
return filePath ;
string newFilePath = Path . Combine ( tempPath , Path . GetFileName ( filePath ) ) ;
using ( FileStream outStream = new FileStream ( newFilePath , FileMode . OpenOrCreate ) )
{
inStream . CopyTo ( outStream ) ;
}
return newFilePath ;
}
}
2020-04-17 01:28:14 +00:00
public static void DirectoryCopy ( string sourceDirName , string destDirName , bool copySubDirs )
2020-03-01 13:45:00 +00:00
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo ( sourceDirName ) ;
if ( ! dir . Exists )
{
throw new DirectoryNotFoundException ( $"Source directory does not exist or could not be found: {sourceDirName}" ) ;
}
// If the destination directory doesn't exist, create it.
if ( ! Directory . Exists ( destDirName ) )
{
Directory . CreateDirectory ( destDirName ) ;
}
// Get the files in the directory and copy them to the new location.
foreach ( FileInfo file in dir . EnumerateFiles ( ) )
{
file . CopyTo ( Path . Combine ( destDirName , file . Name ) , false ) ;
}
// If copying subdirectories, copy them and their contents to new location.
if ( copySubDirs )
{
foreach ( DirectoryInfo subdir in dir . EnumerateDirectories ( ) )
{
DirectoryCopy ( subdir . FullName , Path . Combine ( destDirName , subdir . Name ) , copySubDirs ) ;
}
}
}
2020-04-19 17:36:03 +00:00
2020-03-01 13:45:00 +00:00
}
}