Skip to content

Commit

Permalink
Added Patch GGPK Project
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuanhsing committed Feb 10, 2014
1 parent 24460fb commit d7e36f9
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 1 deletion.
6 changes: 6 additions & 0 deletions PatchGGPK/App.config
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>
68 changes: 68 additions & 0 deletions PatchGGPK/PatchGGPK.csproj
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>
172 changes: 172 additions & 0 deletions PatchGGPK/Program.cs
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.");
}
}
}
}
36 changes: 36 additions & 0 deletions PatchGGPK/Properties/AssemblyInfo.cs
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")]
16 changes: 15 additions & 1 deletion VisualGGPK.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisualGGPK", "VisualGGPK\VisualGGPK.csproj", "{5DEF5905-D80F-47BD-85DB-7B83B5815247}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibGGPK", "LibGGPK\LibGGPK.csproj", "{6D97AF87-4B0A-4F43-A209-801CC72ABE75}"
Expand All @@ -11,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibDat", "LibDat\LibDat.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoeStrings", "PoeStrings\PoeStrings.csproj", "{F6AB4750-B24F-47FD-9827-97FF93027444}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatchGGPK", "PatchGGPK\PatchGGPK.csproj", "{50574844-D4B9-44DF-A8D6-5CB6758528B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -71,6 +75,16 @@ Global
{F6AB4750-B24F-47FD-9827-97FF93027444}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F6AB4750-B24F-47FD-9827-97FF93027444}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F6AB4750-B24F-47FD-9827-97FF93027444}.Release|x86.ActiveCfg = Release|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Debug|x86.ActiveCfg = Debug|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Release|Any CPU.Build.0 = Release|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{50574844-D4B9-44DF-A8D6-5CB6758528B8}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit d7e36f9

Please sign in to comment.