Skip to content

Commit

Permalink
Position handling, viewmodel scaling, bugs squashing etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sui committed Oct 23, 2016
1 parent ea322c8 commit 9382594
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 66 deletions.
Binary file modified AVPPH_CustomLauncher.sdf
Binary file not shown.
24 changes: 13 additions & 11 deletions MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

208 changes: 158 additions & 50 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,119 @@ public partial class mainform : Form
GameSettings _GraphicsSettings;
ConfigChoice _ConfigChoice;
GameHack _gamehack = new GameHack();
int _posX = 0;
int _posY = 0;

public mainform()
{
if (File.Exists("autoexecextended.cfg"))
{
setPositionFromConfig();
}
InitializeComponent();
}

private void mainform_Load(object sender, EventArgs e)
#region Functions
private void CheckForRequiredGameFiles()
{
CheckForRequiredGameFiles();
string[] files = { "lithtech.exe", "AVP2X.REZ", "AVP2DLL.REZ", "AVP2L.REZ", "DIALOGUE.REZ", "AVP2P1.REZ", "AVP2P.REZ", "binkw32.dll", "MULTI.REZ", "server.dll", "ltmsg.dll", "binkw32.dll" };

if(!File.Exists(@"autoexec.cfg"))
for (int i = 0; i < files.Length; i++)
{
_ConfigChoice = new ConfigChoice();
_ConfigChoice.ShowDialog();
if (!File.Exists(@files[i]))
{
MessageBox.Show("No " + files[i] + " found. Please place the custom launcher in the directory with the game!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
}
}

if (!File.Exists(@"avp2cmds.txt"))
if (!File.Exists(@"widescreenfix.dll"))
{
MessageBox.Show("No avp2cmds.txt found. The launcher will try to create it based on files in your current directory.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
CreateGenericAVP2Cmds();
MessageBox.Show("Widescreenfix.dll has not been found. This file is required for Widescreen support.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

_GraphicsSettings = new GameSettings(this);
}

private void CheckForRequiredGameFiles()
private void CreateGenericAVP2Cmds()
{
string[] files = { "lithtech.exe", "AVP2X.REZ", "AVP2DLL.REZ", "AVP2L.REZ", "DIALOGUE.REZ", "AVP2P1.REZ", "AVP2P.REZ", "binkw32.dll", "MULTI.REZ", "server.dll", "ltmsg.dll", "binkw32.dll"};
string basePath = "";
object key = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Monolith Productions\\Aliens vs. Predator 2\\1.0", "InstallDir", "");

for (int i=0; i<files.Length; i++)
if (key != null)
{
if (!File.Exists(@files[i]))
basePath = key.ToString();
}
else
{
MessageBox.Show("Launcher was not able to find the location of the base game. Please specify it manually.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
FolderBrowserDialog fld = new FolderBrowserDialog();
fld.ShowNewFolderButton = false;
fld.Description = "Select a folder where the base game is located.";
DialogResult result = fld.ShowDialog();

if (result == DialogResult.OK)
{
basePath = fld.SelectedPath;
}
else
{
MessageBox.Show("No " +files[i] + " found. Please place the custom launcher in the directory with the game!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
}
}

if (!File.Exists(@"widescreenfix.dll"))
string output = String.Format("-windowtitle \"Aliens versus Predator 2: Primal Hunt\" -rez \"{0}AVP2.rez\" -rez \"{0}sounds.rez\" -rez \"{0}Alien.rez\" -rez \"{0}Marine.rez\" -rez \"{0}Predator.rez\" -rez \"{0}Multi.rez\" -rez multi.rez -rez \"AVP2dll.rez\" -rez \"AVP2l.rez\" -rez dialogue.rez -rez avp2p.rez -rez avp2p1.rez -rez avp2x.rez -rez custom", basePath + "\\");

StreamWriter SW = new StreamWriter(@"avp2cmds.txt");
SW.WriteLine(output);
SW.Close();
}

private void setPositionFromConfig()
{
uint positionX = 0;
uint positionY = 0;
string[] setings = File.ReadAllLines("autoexecextended.cfg");
foreach (string line in setings)
{
MessageBox.Show("Widescreenfix.dll has not been found. This file is required for Widescreen support.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (line.StartsWith("PositionX:"))
{
positionX = parsePosition(line);
}
else if (line.StartsWith("PositionY:"))
{
positionY = parsePosition(line);
}
}

if (checkIfPosIsCorrect(positionX, positionY))
{
this.StartPosition = FormStartPosition.Manual;
this.SetDesktopLocation((int)positionX, (int)positionY);
}
else
{
this.StartPosition = FormStartPosition.CenterScreen;
}
}
#endregion

#region EventHandlers
private void mainform_Load(object sender, EventArgs e)
{
CheckForRequiredGameFiles();

if (!File.Exists(@"autoexec.cfg"))
{
_ConfigChoice = new ConfigChoice();
_ConfigChoice.ShowDialog();
}

if (!File.Exists(@"avp2cmds.txt"))
{
MessageBox.Show("No avp2cmds.txt found. The launcher will try to create it based on files in your current directory.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
CreateGenericAVP2Cmds();
}

_GraphicsSettings = new GameSettings(this);
}

private void B_StartGame_Click(object sender, EventArgs e)
Expand All @@ -74,7 +145,7 @@ private void B_StartGame_Click(object sender, EventArgs e)
if (_GraphicsSettings.windowed)
cmdlineparamters = cmdlineparamters + " +windowed 1";
else
cmdlineparamters = cmdlineparamters + " +windowed 0";
cmdlineparamters = cmdlineparamters + " +windowed 0";

if (_GraphicsSettings.disablesound)
cmdlineparamters = cmdlineparamters + " +DisableSound 1";
Expand Down Expand Up @@ -107,9 +178,6 @@ private void B_StartGame_Click(object sender, EventArgs e)
cmdlineparamters = cmdlineparamters + " +DisableHardwareCursor 0";

cmdlineparamters = cmdlineparamters + " " + _GraphicsSettings.T_CommandLine.Text;




Thread GameHackThread = new Thread(_gamehack.DoWork);
if (_GraphicsSettings.aspectratiohack)
Expand All @@ -119,25 +187,66 @@ private void B_StartGame_Click(object sender, EventArgs e)
}

try
{
{
Process gameProcess = new Process();
gameProcess.StartInfo.FileName = "Lithtech.exe";
gameProcess.StartInfo.Arguments = cmdlineparamters;
gameProcess.EnableRaisingEvents = true;
this.WindowState = FormWindowState.Minimized;

gameProcess.Start();
gameProcess.WaitForExit();
_gamehack.RequestStop();
this.Close();
}
catch(Exception ex)
catch (Exception ex)
{
Console.WriteLine("An error occurred!: " + ex.Message);
return;
}
}

private void mainform_FormClosing(object sender, FormClosingEventArgs e)
{
if (File.Exists("autoexecextended.cfg")) //well should have thought about this earlier... whatever
{
bool flagX = false;
bool flagY = false;
string[] settings = File.ReadAllLines("autoexecextended.cfg");
for (int i = 0; i < settings.Length; i++)
{
if (settings[i].StartsWith("PositionX:"))
{
settings[i] = "PositionX:" + _posX.ToString();
flagX = true;
}
else if (settings[i].StartsWith("PositionY:"))
{
settings[i] = "PositionY:" + _posY.ToString();
flagY = true;
}
}

string output = string.Join("\n", settings);

if (!flagX)
output += "\nPositionX:" + this._posX.ToString();
if (!flagY)
output += "\nPositionY:" + this._posY.ToString();

File.WriteAllText("autoexecextended.cfg", output);
}
}

private void mainform_LocationChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
_posX = this.DesktopLocation.X;
_posY = this.DesktopLocation.Y;
}
}

private void B_DisplaySettings_Click(object sender, EventArgs e)
{
_GraphicsSettings.SetDesktopLocation(this.DesktopLocation.X + 10, this.DesktopLocation.Y + 10);
Expand All @@ -149,39 +258,38 @@ private void B_Exit_Click(object sender, EventArgs e)
_gamehack.RequestStop();
this.Close();
}
#endregion

private void CreateGenericAVP2Cmds()
#region ParseFunctions
private uint parsePosition(string line)
{
string basePath = "";
object key = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Monolith Productions\\Aliens vs. Predator 2\\1.0", "InstallDir", "");

if(key != null)
uint outVal = 0;
string valText = line.Split(':')[1];
if (valText != String.Empty)
{
basePath = key.ToString();
}
else
{
MessageBox.Show("Launcher was not able to find the location of the base game. Please specify it manually.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
FolderBrowserDialog fld = new FolderBrowserDialog();
fld.ShowNewFolderButton = false;
fld.Description = "Select a folder where the base game is located.";
DialogResult result = fld.ShowDialog();

if(result == DialogResult.OK)
if (uint.TryParse(valText, out outVal))
{
basePath = fld.SelectedPath;
return outVal;
}
else
{
Close();
}
return 0;
}

string output = String.Format("-windowtitle \"Aliens versus Predator 2: Primal Hunt\" -rez \"{0}AVP2.rez\" -rez \"{0}sounds.rez\" -rez \"{0}Alien.rez\" -rez \"{0}Marine.rez\" -rez \"{0}Predator.rez\" -rez \"{0}Multi.rez\" -rez multi.rez -rez \"AVP2dll.rez\" -rez \"AVP2l.rez\" -rez dialogue.rez -rez avp2p.rez -rez avp2p1.rez -rez avp2x.rez -rez custom", basePath + "\\");

StreamWriter SW = new StreamWriter(@"avp2cmds.txt");
SW.WriteLine(output);
SW.Close();
else
return 0;
}

private bool checkIfPosIsCorrect(uint PosX, uint PosY)
{
Screen[] screens = Screen.AllScreens;
foreach (Screen screen in screens)
{
Rectangle scrRect = screen.WorkingArea;
if (PosX > scrRect.X && PosX < scrRect.X + scrRect.Width &&
PosY > scrRect.Y && PosY < scrRect.Y + scrRect.Height)
return true;
}
return false;
}
#endregion
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.6.0.0")]
[assembly: AssemblyFileVersion("0.6.0.0")]
[assembly: AssemblyVersion("0.6.1.0")]
[assembly: AssemblyFileVersion("0.6.1.0")]
Binary file modified Release/AVP2PH_CustomLauncher.exe
Binary file not shown.
Binary file modified Release/widescreenfix.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion SettingsForms/GameSettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public GameSettings(mainform parent)
}
else
readcustomconfig();

readfile();
}


Expand All @@ -55,7 +57,6 @@ struct autoexecstruct

private void GraphicsSettings_Load(object sender, EventArgs e)
{
readfile();
}

public void readcustomconfig()
Expand Down
Loading

0 comments on commit 9382594

Please sign in to comment.