Skip to content

Commit

Permalink
Merge pull request #80 from VFansss/developer
Browse files Browse the repository at this point in the history
From Developer, with love ❤️
  • Loading branch information
VFansss authored Feb 24, 2019
2 parents 4033aba + 663ddb5 commit 438f1b1
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 36 deletions.
9 changes: 9 additions & 0 deletions mgs2 v's fix/Flags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public enum FATALERRORSFOUND
ErrorWhileReadingFile
}

public enum SAVEGAMEMOVING
{
NoSuccesfulEvaluationPerformed = 0,
NoSavegame2Move,
BothFolderExist,
MovingPossible

};

public static class FlagExtension
{

Expand Down
45 changes: 22 additions & 23 deletions mgs2 v's fix/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Drawing.Text;
Expand Down Expand Up @@ -254,36 +250,39 @@ private void btn_settings_Click(object sender, EventArgs e)

}

// Check if savegame must be moved to the new location in "My Games", and warn the user if yes
// Check if savegame will be moved to the new location in "My Games", and warn the user if there are issues

if (Directory.Exists(Application.StartupPath + "\\..\\savedata"))
{
// Must move things
SAVEGAMEMOVING evaluationResult = Ocelot.SavegameMustBeMoved();

string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Ocelot.PrintToDebugConsole("[!] SavegameMustBeMoved evaluation result is "+ evaluationResult);

if (Directory.Exists(Path.Combine(myDocumentsPath + "\\My Games\\METAL GEAR SOLID 2 SUBSTANCE")))
{
// Trouble incoming...
if (evaluationResult == SAVEGAMEMOVING.NoSuccesfulEvaluationPerformed)
{
Ocelot.showMessage("UAC_error");

Ocelot.showMessage("savegameCantBeMoved");
// Abort everything until user manually solve the situation

// Abort everything until user manually solve the situation
Program.ForceClosing();

Application.Exit();
}

}
else if (evaluationResult == SAVEGAMEMOVING.MovingPossible)
{
Ocelot.showMessage("savegameWillBeMoved");
}

else
{
// Situation is clear...
else if (evaluationResult == SAVEGAMEMOVING.BothFolderExist)
{
Ocelot.showMessage("savegameCantBeMoved");

Ocelot.showMessage("savegameWillBeMoved");
// Abort everything until user manually solve the situation

Ocelot.MoveSavegamesToNewLocation();
Program.ForceClosing();
}

}

else
{
// The last remaining evaluation is SAVEGAMEMOVING.NoSavegame2Move, and doesn't require any warning
}

Ocelot.PrintToDebugConsole("[+] Settings has been displayed.");
Expand Down
161 changes: 150 additions & 11 deletions mgs2 v's fix/Ocelot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Ocelot
{

// Internal version of the V's Fix - Format is YYMMDD
public const string VERSION = "190104";
public const string VERSION = "190224";

// Hide background images and more "appariscent" graphical things
public static bool NOSYMODE = false;
Expand Down Expand Up @@ -254,7 +254,8 @@ internal static void load_InternalConfig_SetTo_INI()
// !!!! Big function that apply V's Fix settings !!!!!!!!!!!!!!!!!!!!!!!!!!!
internal static void load_InternalConfig_SetTo_MGS()
{

PrintToDebugConsole("[ SET TO MGS METHOD ] Method starting...");

// Delete already existing mgs.ini

try
Expand Down Expand Up @@ -307,6 +308,33 @@ internal static void load_InternalConfig_SetTo_MGS()

}

// Move savegames from 'savedata' folder inside 'My Games', if needed

SAVEGAMEMOVING evaluationResult = Ocelot.SavegameMustBeMoved();

Ocelot.PrintToDebugConsole("[!] SavegameMustBeMoved evaluation result is " + evaluationResult);

if (evaluationResult == SAVEGAMEMOVING.NoSuccesfulEvaluationPerformed)
{
throw new Exception();

}

else if (evaluationResult == SAVEGAMEMOVING.MovingPossible)
{
MoveSavegamesToNewLocation();
}

else if (evaluationResult == SAVEGAMEMOVING.BothFolderExist)
{
throw new Exception();
}

else
{
// The last remaining evaluation is SAVEGAMEMOVING.NoSavegame2Move, and doesn't require any warning
}

// Extract SavegameLocationChanger.asi

if (File.Exists(Application.StartupPath + "\\scripts\\SavegameLocationChanger.asi"))
Expand All @@ -320,6 +348,7 @@ internal static void load_InternalConfig_SetTo_MGS()

#endregion


//////
//--------- Resolution
//////
Expand Down Expand Up @@ -439,6 +468,8 @@ internal static void load_InternalConfig_SetTo_MGS()

// FIX FOR ATI/NVIDIA

PrintToDebugConsole("[ SET TO MGS METHOD ] Fixing exe based on VGA Model...");

#region TANTAROBA
using (var stream = new FileStream(Application.StartupPath + "\\mgs2_sse.exe", FileMode.Open, FileAccess.ReadWrite))
{
Expand Down Expand Up @@ -501,6 +532,8 @@ internal static void load_InternalConfig_SetTo_MGS()
stream.Position = 0x5FD839;
stream.WriteByte(0x63);

PrintToDebugConsole("[ SET TO MGS METHOD ] NVIDIA card fix chosen");

}

if (Ocelot.InternalConfiguration.Resolution["GraphicAdapterName"].Contains("Radeon"))
Expand Down Expand Up @@ -531,6 +564,8 @@ internal static void load_InternalConfig_SetTo_MGS()
stream.Position = 0x5FD839;
stream.WriteByte(0x6E);

PrintToDebugConsole("[ SET TO MGS METHOD ] RADEON card fix chosen");

}

if (Ocelot.InternalConfiguration.Resolution["GraphicAdapterName"].Contains("Intel"))
Expand Down Expand Up @@ -561,6 +596,8 @@ internal static void load_InternalConfig_SetTo_MGS()
stream.Position = 0x5FD839;
stream.WriteByte(0x28);

PrintToDebugConsole("[ SET TO MGS METHOD ] INTEL card fix chosen");

}

// Laptop FIX
Expand Down Expand Up @@ -1339,8 +1376,9 @@ public static DialogResult showMessage(string code)
case "savegameWillBeMoved":

answer = MessageBox.Show(
"This version of the V's Fix will patch the game to search savedata inside 'My Documents\\My Games'" + "\n\n" +
"From now on, your save data will be storaged inside this folder:" + "\n\n"+
"From the next time you press 'SAVE', the V's Fix will patch the game to search savedata inside the 'My Games' folder!" + "\n\n" +
"This will also enhance game compatibility with modern systems!" + "\n\n"+
"Your save data will be stored inside this folder:" + "\n\n"+
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\My Games\\METAL GEAR SOLID 2 SUBSTANCE",
"Improvement incoming...", MessageBoxButtons.OK, MessageBoxIcon.Information);

Expand Down Expand Up @@ -1714,10 +1752,12 @@ private static void SetCompatibilityFlags()

}

catch
catch(Exception ex)
{
// Signal to debugger

Ocelot.PrintToDebugConsole("[ EXCEPTION ] " + ex.Message);

PrintToDebugConsole("[ :( ] Exception while setting compatibility flags!");

}
Expand Down Expand Up @@ -1762,10 +1802,12 @@ public static bool CheckForCompabilityFlags()

}

catch
catch(Exception ex)
{
// Signal to debugger

PrintToDebugConsole("[ EXCEPTION ] " + ex.Message);

PrintToDebugConsole("[C.FLAGS CHECK] Exception while checking compatibility flags!");

}
Expand Down Expand Up @@ -1793,10 +1835,12 @@ private static void RemoveCompatibilityFlags()

}

catch
catch(Exception ex)
{
// Signal to debugger

Ocelot.PrintToDebugConsole("[ EXCEPTION ] " + ex.Message);

PrintToDebugConsole("[C.FLAGS REMOVAL] Exception while removing compatibility flags!");

}
Expand All @@ -1808,23 +1852,39 @@ private static void RemoveCompatibilityFlags()
public static void MoveSavegamesToNewLocation()
{

Ocelot.PrintToDebugConsole("[MOVE SAVEGAME TO NEW LOCATION] Method starting...");

try
{
string oldSavedataPath = Directory.GetParent(Application.StartupPath).FullName + "\\savedata";
string newSavedataPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\My Games\\METAL GEAR SOLID 2 SUBSTANCE";

Directory.CreateDirectory(newSavedataPath);
Ocelot.PrintToDebugConsole("[MOVE SAVEGAME TO NEW LOCATION] old: " + oldSavedataPath+" | new: "+ newSavedataPath);

Directory.Move(oldSavedataPath, newSavedataPath);

Ocelot.PrintToDebugConsole("[MOVE SAVEGAME TO NEW LOCATION] Folder moved :)");

// Set savedata folder permission to 'inerithed'

var fs = File.GetAccessControl(newSavedataPath);
fs.SetAccessRuleProtection(false, false);
File.SetAccessControl(newSavedataPath, fs);

Ocelot.PrintToDebugConsole("[MOVE SAVEGAME TO NEW LOCATION] Permission inerithing just set!");

// Create a file to remember the user to check to new location

File.Create(Directory.GetParent(Application.StartupPath).FullName + "\\SAVEDATA ARE INSIDE 'MY GAMES' FOLDER");

Ocelot.PrintToDebugConsole("[MOVE SAVEGAME TO NEW LOCATION] Reminder file just created!");

}

catch
catch(Exception ex)
{
Ocelot.PrintToDebugConsole("[ EXCEPTION ] " + ex.Message);

showMessage("UAC_error");

Application.Exit();
Expand Down Expand Up @@ -2480,11 +2540,90 @@ public static string Sanitize_pathForCMD(string originalPath)
}

// Check if a directory is empty
public static bool IsDirectoryEmpty(string path)
public static bool IsThisDirectoryEmpty(string path)
{
return !Directory.EnumerateFileSystemEntries(path).Any();
// I prefere to return true in case of sudden exceptions...
bool isEmpty = true;

try
{
string[] filesAndDir = Directory.EnumerateFileSystemEntries(path, "*", SearchOption.AllDirectories).ToArray<string>();
isEmpty = !filesAndDir.Any();
}
catch
{
// Who cares...
}

return isEmpty;

}

// Check if savegames will be moved to 'My Games' directory
public static SAVEGAMEMOVING SavegameMustBeMoved()
{

try
{
string originalSavegameFolder = Application.StartupPath + "\\..\\savedata";

string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string newSavegameFolder = Path.Combine(myDocumentsPath + "\\My Games\\METAL GEAR SOLID 2 SUBSTANCE");

// CHECK: One/both folder exist but are empty?

if (Directory.Exists(originalSavegameFolder) && IsThisDirectoryEmpty(originalSavegameFolder))
{
// Directory esist, but there aren't files inside the old savegame folder
Directory.Delete(originalSavegameFolder, true);
PrintToDebugConsole("[ SAVEGAMEMUSTBEMOVED ] " + originalSavegameFolder + " folder is empty, and has been deleted");
}

if (Directory.Exists(newSavegameFolder) && IsThisDirectoryEmpty(newSavegameFolder))
{
// Directory esist, but there aren't files inside the new savegame folder
Directory.Delete(newSavegameFolder, true);
PrintToDebugConsole("[ SAVEGAMEMUSTBEMOVED ] " + newSavegameFolder + " folder is empty, and has been deleted");
}

// Now both folder has been purged, and if they exist mean that they contain files that I can't arbitrary delete

// Check if savegame can be moved to the new location in "My Games"
if (Directory.Exists(originalSavegameFolder))
{

// There are files inside the old savegame directory. Must move things!

// Check if the new location already have savegames...

if (Directory.Exists(newSavegameFolder))
{
return SAVEGAMEMOVING.BothFolderExist;

}

return SAVEGAMEMOVING.MovingPossible;

}

else
{
return SAVEGAMEMOVING.NoSavegame2Move;
}


}
catch (Exception ex)
{
Ocelot.PrintToDebugConsole("[ EXCEPTION ] " + ex.Message);
}

// It shoudn't even come so far.
return SAVEGAMEMOVING.NoSuccesfulEvaluationPerformed;

}


}// END CLASS

}
Binary file modified mgs2 v's fix/PAPERS/Contacts.txt
Binary file not shown.
10 changes: 8 additions & 2 deletions mgs2 v's fix/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

using System.IO;
Expand Down Expand Up @@ -300,5 +298,13 @@ static void Main(string[] args)

}

public static void ForceClosing()
{
Ocelot.PrintToDebugConsole("[!] App is going to close. IGNORE FURTHER DEBUG LINES...");

Application.Exit();

}

}
}

0 comments on commit 438f1b1

Please sign in to comment.