Skip to content

Commit

Permalink
A bunch of changes over the course of a year. I'm bad at version cont…
Browse files Browse the repository at this point in the history
…rol, sorry.
  • Loading branch information
TinkerWorX committed Sep 18, 2015
1 parent 9ba2ede commit 72d37c2
Show file tree
Hide file tree
Showing 19 changed files with 648 additions and 481 deletions.
101 changes: 70 additions & 31 deletions TinkerWorX.SharpCraft.Launcher/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,94 @@
using System.Text;
using EasyHook;
using Microsoft.Win32;
using System.Windows;

namespace TinkerWorX.SharpCraft.Launcher
{
internal static class Common
{
public static Boolean IsInitialized { get; private set; }
public static Boolean IsInitialized
{ get; private set; }

public static String InstallPath { get; private set; }
public static String InstallPath
{ get; private set; }

public static String GamePath { get; private set; }
public static String GamePath
{ get; private set; }

public static String EditorPath { get; private set; }
public static String EditorPath
{ get; private set; }

public static String Version { get { return FileVersionInfo.GetVersionInfo(typeof(SharpCraftApplication).Assembly.Location).FileVersion; } }
public static String Version
{ get { return FileVersionInfo.GetVersionInfo(typeof(SharpCraftApplication).Assembly.Location).FileVersion; } }

public static void Initialize()
public static Boolean Initialize()
{
if (Common.IsInitialized)
return;

var key = Registry.CurrentUser.OpenSubKey(@"Software\Blizzard Entertainment\Warcraft III");
if (key == null)
throw new KeyNotFoundException("Could not find Warcraft III key in registry!" + Environment.NewLine + "To fix this, make sure you've launched Warcraft III at least once.");
var value = key.GetValue("InstallPath");
if (value == null)
if (!Common.IsInitialized)
{
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Blizzard Entertainment\Warcraft III");
value = key.GetValue("InstallPath");
Console.WriteLine("Locating InstallPath . . . ");
if (File.Exists(Path.Combine(Environment.CurrentDirectory, @"..\war3.exe")))
{
Console.WriteLine("Found war3.exe in parent folder, using local InstallPath.");
Common.InstallPath = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.LastIndexOf("\\") + 1);
}
else
{
Console.WriteLine("Using registry to locate InstallPath.");
var key = Registry.CurrentUser.OpenSubKey(@"Software\Blizzard Entertainment\Warcraft III");
if (key != null && key.GetValue("InstallPath") != null)
Common.InstallPath = (key.GetValue("InstallPath") as String);
if (String.IsNullOrEmpty(Common.InstallPath))
{
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Blizzard Entertainment\Warcraft III");
if (key != null && key.GetValue("InstallPath") != null)
Common.InstallPath = (key.GetValue("InstallPath") as String);
}
if (String.IsNullOrEmpty(Common.InstallPath))
{
var dialog = new OpenFileDialog();
dialog.Filter = "Warcraft III|war3.exe";
var result = dialog.ShowDialog();
if (result.HasValue && result.Value)
{
Common.InstallPath = Path.GetDirectoryName(dialog.FileName);

var doInstall = MessageBox.Show("Install path into registry?", "SharpCraft", MessageBoxButton.YesNo);
if (doInstall == MessageBoxResult.Yes)
{
key = Registry.CurrentConfig.CreateSubKey(@"Software\Blizzard Entertainment\Warcraft III");
key.SetValue("InstallPath", Common.InstallPath);
}
}
else
{
return false;
}

}
}
Common.GamePath = Path.Combine(InstallPath, "war3.exe");
Common.EditorPath = Path.Combine(InstallPath, "worldedit.exe");

Common.IsInitialized = true;
}
Common.InstallPath = (value as String);
if (String.IsNullOrEmpty(InstallPath))
throw new KeyNotFoundException("Could not find InstallPath value in registry!" + Environment.NewLine + "To fix this, make sure you've launched Warcraft III at least once.");
Common.GamePath = Path.Combine(InstallPath, "war3.exe");
Common.EditorPath = Path.Combine(InstallPath, "worldedit.exe");

Common.IsInitialized = true;
return true;
}

public static void StartGame(String[] args)
{
if (!Common.IsInitialized)
Common.Initialize();
if (!Common.Initialize())
return;

if (!File.Exists(Common.GamePath))
throw new FileNotFoundException("Could not find war3.exe!" + Environment.NewLine + "You may need to verify your registry settings are correct.", "war3.exe");
if (!File.Exists(Path.Combine(Environment.CurrentDirectory, "SharpCraft.dll")))
throw new FileNotFoundException("Could not find SharpCraft.dll!" + Environment.NewLine + "You may need to redownload SharpCraft.", "SharpCraft.dll");

Boolean kill = false;
Boolean debug = false;
Boolean valid = true;
var kill = false;
var debug = false;
var valid = true;
while (valid && args.Length > 0)
{
switch (args[0])
Expand Down Expand Up @@ -86,7 +123,8 @@ public static void StartGame(String[] args)
foreach (var war3 in war3s)
war3.Kill();
}
else throw new InvalidOperationException("Warcraft III is already running!" + Environment.NewLine + "You may need to check Task Manager for \"war3.exe\", and kill it.");
else
throw new InvalidOperationException("Warcraft III is already running!" + Environment.NewLine + "You may need to check Task Manager for \"war3.exe\", and kill it.");
}

Console.Write("Creating and injecting into Warcraft III . . . ");
Expand All @@ -101,8 +139,8 @@ public static void StartGame(String[] args)

public static void StartEditor(String[] args)
{
if (!Common.IsInitialized)
Common.Initialize();
if (!Common.Initialize())
return;

if (!File.Exists(Common.EditorPath))
throw new FileNotFoundException("Could not find worldedit.exe!" + Environment.NewLine + "You may need to verify your registry settings are correct.", "worldedit.exe");
Expand Down Expand Up @@ -140,7 +178,8 @@ public static void StartEditor(String[] args)
foreach (var worldedit in worldedits)
worldedit.Kill();
}
else throw new InvalidOperationException("World Editor is already running!" + Environment.NewLine + "You may need to check Task Manager for \"worldedit.exe\", and kill it.");
else
throw new InvalidOperationException("World Editor is already running!" + Environment.NewLine + "You may need to check Task Manager for \"worldedit.exe\", and kill it.");
}

Console.Write("Creating and injecting into World Editor . . . ");
Expand Down
4 changes: 2 additions & 2 deletions TinkerWorX.SharpCraft.Launcher/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,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("3.0.1.135")]
[assembly: AssemblyFileVersion("3.0.1.135")]
[assembly: AssemblyVersion("4.0.0.136")]
[assembly: AssemblyFileVersion("4.0.0.136")]
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<PropertyGroup>
<StartupObject>TinkerWorX.SharpCraft.Launcher.SharpCraftApplication</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Accessibility" />
<Reference Include="EasyHook">
Expand Down Expand Up @@ -93,6 +96,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.manifest" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
58 changes: 58 additions & 0 deletions TinkerWorX.SharpCraft.Launcher/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel node will disable file and registry virtualization.
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with.
Windows will automatically select the most compatible environment.-->

<!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->

<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->

<!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->

<!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->

</application>
</compatibility>

<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!-- <dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>-->

</asmv1:assembly>
55 changes: 55 additions & 0 deletions TinkerWorX.SharpCraft/Addresses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TinkerWorX.SharpCraft
{
internal static class Addresses
{
// === INSTRUCTIONS ===
// 1. Hit "Alt + B" to search for the following byte sequence,
// including the quotes: ".?AUAgent2HandleReg@@". This should return one
// result, looking similar to this:
// .data:6FA7951C a_?auagent2hand db '.?AUAgent2HandleReg@@',0
// 2. Double click the result. (Only in IDAPro 5.5)
// 3. Place the cursor in the following part of the line:
// .data:6FA7951C a_?auagent2hand db '.?AUAgent2HandleReg@@',0
// ^^^^^^^^^^^^^^^
// 4. Press "x", to cross reference the string.
// This should give you several results. Four of them are functions.
// 5. One of the functions will look like this (first one likely):
// -> .text:6F3A465F call sub_6F3A3AD0
// .text:6F3A4664 push 1
// .text:6F3A4666 push 0FFFFFFFEh
// .text:6F3A4668 push offset a_?auagent2hand ; ".?AUAgent2HandleReg@@"
// 6. Double click sub_6F3A3AD0.
// 7. You are now in a function that looks like this:
// .text:6F3A3AD0 sub_6F3A3AD0 proc near
// .text:6F3A3AD0
// .text:6F3A3AD0
// .text:6F3A3AD0 arg_0 = dword ptr 4
// .text:6F3A3AD0 arg_4 = dword ptr 8
// .text:6F3A3AD0
// .text:6F3A3AD0 push ebx
// .text:6F3A3AD1 push edi
// .text:6F3A3AD2 mov edi, edx
// .text:6F3A3AD4 mov ebx, ecx
// .text:6F3A3AD6 call sub_6F442670
// .text:6F3A3ADB mov ecx, 0Dh
// .text:6F3A3AE0 call sub_6F4C34D0
// .text:6F3A3AE5 mov eax, [eax+10h]
// .text:6F3A3AE8 mov ecx, [eax+18h]
// .text:6F3A3AEB test ecx, ecx
// .text:6F3A3AED jz short loc_6F3A3AFE
// .text:6F3A3AEF mov edx, [esp+8+arg_4]
// .text:6F3A3AF3 mov eax, [esp+8+arg_0]
// .text:6F3A3AF7 push edx
// .text:6F3A3AF8 push eax
// -> .text:6F3A3AF9 call sub_6F3A2EC0
// 8. sub_6F3A2EC0 is the game_state function.
// 7. Using the image base, you rebase this address like this:
// 6F3A2EC0 - 6F000000 = 003A2EC0
public const Int32 Unknown__SetStateOffset = 0x3A2EC0;
}
}
Loading

0 comments on commit 72d37c2

Please sign in to comment.