-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24460fb
commit d7e36f9
Showing
5 changed files
with
297 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{50574844-D4B9-44DF-A8D6-5CB6758528B8}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>PatchGGPK</RootNamespace> | ||
<AssemblyName>PatchGGPK</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Ionic.Zip"> | ||
<HintPath>..\Ionic.Zip.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\LibDat\LibDat.csproj"> | ||
<Project>{8f9fc78e-6181-4447-ac45-56173c16a0fa}</Project> | ||
<Name>LibDat</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\LibGGPK\LibGGPK.csproj"> | ||
<Project>{6D97AF87-4B0A-4F43-A209-801CC72ABE75}</Project> | ||
<Name>LibGGPK</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using LibGGPK; | ||
using System.IO; | ||
using System.Linq.Expressions; | ||
using LibDat; | ||
using LibDat.Files; | ||
using Ionic.Zip; | ||
|
||
namespace PatchGGPK | ||
{ | ||
class Program | ||
{ | ||
static void Output(string msg) | ||
{ | ||
Console.Write(msg); | ||
} | ||
|
||
public class DatFile | ||
{ | ||
public string Name { get; set; } | ||
} | ||
|
||
private static string ggpkPath = @"o:\Program Files (x86)\Grinding Gear Games\Path of Exile\content.ggpk"; | ||
private static Dictionary<string, FileRecord> RecordsByPath; | ||
private static GGPK content; | ||
|
||
public static void Main(string[] args) | ||
{ | ||
if (args.Length != 1) | ||
{ | ||
Console.WriteLine("Derp"); | ||
Console.ReadLine(); | ||
return; | ||
} | ||
InitGGPK(); | ||
PatchGGPK(args[0]); | ||
Console.WriteLine("Press any key to continue..."); | ||
Console.ReadLine(); //new Program(); | ||
} | ||
|
||
private static void InitGGPK() | ||
{ | ||
if (!File.Exists(ggpkPath)) | ||
{ | ||
Microsoft.Win32.RegistryKey start = Microsoft.Win32.Registry.CurrentUser; | ||
Microsoft.Win32.RegistryKey programName = start.OpenSubKey("Software\\GrindingGearGames\\Path of Exile"); | ||
if (programName != null) | ||
{ | ||
string pathString = (string)programName.GetValue("InstallLocation"); | ||
if (pathString != string.Empty && File.Exists(pathString + "Content.ggpk")) | ||
{ | ||
ggpkPath = pathString + "Content.ggpk"; | ||
} | ||
} | ||
} | ||
|
||
content = new GGPK(); | ||
content.Read(ggpkPath, Output); | ||
|
||
RecordsByPath = new Dictionary<string, FileRecord>(content.RecordOffsets.Count); | ||
DirectoryTreeNode.TraverseTreePostorder(content.DirectoryRoot, null, n => RecordsByPath.Add(n.GetDirectoryPath() + n.Name, n as FileRecord)); | ||
|
||
//DumpGGPK(); | ||
} | ||
|
||
private static void DumpGGPK() | ||
{ | ||
foreach (var item in RecordsByPath) | ||
{ | ||
Console.WriteLine(item.Key + " -> " + item.Value.Name); | ||
} | ||
} | ||
|
||
private static void PatchGGPK(string archivePath) | ||
{ | ||
if (content.IsReadOnly) | ||
{ | ||
Console.WriteLine("Content.ggpk is Read Only."); | ||
} | ||
else if (File.Exists(archivePath)) | ||
{ | ||
HandlePatchArchive(archivePath); | ||
} | ||
} | ||
|
||
private static void HandlePatchArchive(string archivePath) | ||
{ | ||
using (ZipFile zipFile = new ZipFile(archivePath)) | ||
{ | ||
bool VersionCheck = false; | ||
bool NeedVersionCheck = false; | ||
foreach (var item in zipFile.Entries) | ||
{ | ||
if (item.FileName.Equals("version.txt")) | ||
{ | ||
using (var reader = item.OpenReader()) | ||
{ | ||
byte[] versionData = new byte[item.UncompressedSize]; | ||
reader.Read(versionData, 0, versionData.Length); | ||
string versionStr = Encoding.UTF8.GetString(versionData, 0, versionData.Length); | ||
foreach (var recordOffset in content.RecordOffsets) | ||
{ | ||
FileRecord record = recordOffset.Value as FileRecord; | ||
if (record == null || record.ContainingDirectory == null) | ||
{ | ||
continue; | ||
} | ||
if (record.Name.Equals("patch_notes.rtf")) | ||
{ | ||
string Hash = BitConverter.ToString(record.Hash); | ||
if (versionStr.Substring(0, Hash.Length).Equals(Hash)) | ||
{ | ||
VersionCheck = true; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
break; | ||
} | ||
else if (Path.GetExtension(item.FileName).ToLower() == ".dat" || Path.GetExtension(item.FileName).ToLower() == ".txt") | ||
{ | ||
NeedVersionCheck = true; | ||
} | ||
} | ||
if (NeedVersionCheck && !VersionCheck) | ||
{ | ||
Console.WriteLine("Version Check Failed"); | ||
return; | ||
} | ||
|
||
foreach (var item in zipFile.Entries) | ||
{ | ||
if (item.IsDirectory) | ||
{ | ||
continue; | ||
} | ||
if (item.FileName.Equals("version.txt")) | ||
{ | ||
continue; | ||
} | ||
|
||
string fixedFileName = item.FileName; | ||
if (Path.DirectorySeparatorChar != '/') | ||
{ | ||
fixedFileName = fixedFileName.Replace('/', Path.DirectorySeparatorChar); | ||
} | ||
|
||
if (!RecordsByPath.ContainsKey(fixedFileName)) | ||
{ | ||
Console.WriteLine("Failed {0}", fixedFileName); | ||
continue; | ||
} | ||
Console.WriteLine("Replace {0}", fixedFileName); | ||
|
||
using (var reader = item.OpenReader()) | ||
{ | ||
byte[] replacementData = new byte[item.UncompressedSize]; | ||
reader.Read(replacementData, 0, replacementData.Length); | ||
|
||
RecordsByPath[fixedFileName].ReplaceContents(ggpkPath, replacementData, content.FreeRoot); | ||
} | ||
} | ||
Console.WriteLine("Content.ggpk is Fine."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("PatchGGPK")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("PatchGGPK")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("9a902539-8192-442f-a631-8c649adcc9f7")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// 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("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters