Skip to content

Commit

Permalink
Please download this and use it without "Online Mode" for direct manu…
Browse files Browse the repository at this point in the history
…al patch testing
  • Loading branch information
akbaryahya committed Nov 2, 2022
1 parent 0cab08d commit 70dbfc4
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 67 deletions.
62 changes: 62 additions & 0 deletions Game/Genshin/Patch/HexUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
public class HexUtility
{
public static bool EqualsBytes(byte[] b1, params byte[] b2)
{
if (b1.Length != b2.Length)
return false;
for (int i = 0; i < b1.Length; i++)
{
if (b1[i] != b2[i])
return false;
}
return true;
}

public static byte[] Replace(byte[] sourceByteArray, List<HexReplaceEntity> replaces)
{
byte[] newByteArray = new byte[sourceByteArray.Length];
Buffer.BlockCopy(sourceByteArray, 0, newByteArray, 0, sourceByteArray.Length);
int offset = 0;
foreach (HexReplaceEntity rep in replaces)
{
if (EqualsBytes(rep.oldValue, rep.newValue))
{
continue;
}

for (; offset < sourceByteArray.Length; offset++)
{
if (sourceByteArray[offset] == rep.oldValue[0])
{
if (sourceByteArray.Length - offset < rep.oldValue.Length)
break;

bool find = true;
for (int i = 1; i < rep.oldValue.Length - 1; i++)
{
if (sourceByteArray[offset + i] != rep.oldValue[i])
{
find = false;
break;
}
}
if (find)
{
Buffer.BlockCopy(rep.newValue, 0, newByteArray, offset, rep.newValue.Length);
offset += (rep.newValue.Length - 1);
break;
}
}
}
}
return newByteArray;
}
}

public class HexReplaceEntity
{
public byte[] oldValue { get; set; }

public byte[] newValue { get; set; }

}
54 changes: 40 additions & 14 deletions Game/Genshin/Patch/UserAssembly.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text;
using YuukiPS_Launcher.patch;

namespace YuukiPS_Launcher.Game.Genshin.Patch
{
Expand All @@ -11,30 +10,57 @@ public static class UserAssembly

public static string Do(string original_file, string patch_file, string keynopatch, string keypatch)
{
//Console.WriteLine("KeyNopatch" + "\n" + keynopatch);
//Console.WriteLine("KeyPatch" + "\n" + keypatch);

if (!File.Exists(original_file))
{
return "UserAssembly file not found";
}
byte[] data = File.ReadAllBytes(original_file);

int count = 0;
string str;
byte[] UA_Original = Encoding.ASCII.GetBytes(keynopatch);
byte[] UA_key = Encoding.ASCII.GetBytes(keypatch);

// Get Byte file original
byte[] UA = File.ReadAllBytes(original_file);

data = Methods.ReplaceBytes(data, ToUABytes(keynopatch), ToUABytes(keypatch), ref count);
int Offset = 0;
int DataLength;

if (count != 0)
List<HexReplaceEntity> UA_list = new List<HexReplaceEntity>();

while ((DataLength = UA_Original.Length - Offset) > 0)
{
str = "";
FileStream stream = File.Create(patch_file);
stream.Write(data, 0, data.Length);
stream.Close();
if (DataLength > 8)
DataLength = 8;

HexReplaceEntity hexReplaceEntity = new HexReplaceEntity();

hexReplaceEntity.oldValue = new byte[8];
Buffer.BlockCopy(UA_Original, Offset, hexReplaceEntity.oldValue, 0, DataLength);

hexReplaceEntity.newValue = new byte[8];
Buffer.BlockCopy(UA_key, Offset, hexReplaceEntity.newValue, 0, DataLength);

UA_list.Add(hexReplaceEntity);
Offset += DataLength;
}
else

byte[] UA_OS_patched = HexUtility.Replace(UA, UA_list);

if (!HexUtility.EqualsBytes(UA, UA_OS_patched))
{
str = "Patch UserAssembly Failed";
try
{
File.WriteAllBytes(patch_file, UA_OS_patched);
return "";
}
catch (IOException e)
{
return e.Message + "\n Cannot write to file.";
}
}

return str;
return "Patch UserAssembly Failed";
}

public static byte[] ToUABytes(string key)
Expand Down
6 changes: 3 additions & 3 deletions Json/GS.cs → Json/GameClient/Cient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace YuukiPS_Launcher.Json
namespace YuukiPS_Launcher.Json.GameClient
{
public class Data
{
Expand Down Expand Up @@ -27,7 +27,7 @@ public class DeprecatedPackage
public class Diff
{
public string name { get; set; }
public string version { get; set; }
public string version { get; set; } = "0.0.0";
public string path { get; set; }
public string size { get; set; }
public string md5 { get; set; }
Expand Down Expand Up @@ -72,7 +72,7 @@ public class Plugin2
public string entry { get; set; }
}

public class GS
public class Cient
{
public int retcode { get; set; }
public string message { get; set; }
Expand Down
56 changes: 56 additions & 0 deletions Json/GameClient/Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace YuukiPS_Launcher.Json.GameClient
{
public class Cn
{
public string userassembly { get; set; }
public string metadata { get; set; }
}

public class KeyFind
{
public string cn { get; set; }
public string os { get; set; }
}

public class Md5Check
{
public Os os { get; set; }
public Cn cn { get; set; }
}

public class Md5Vaild
{
public string os { get; set; }
public string cn { get; set; }
}

public class Original
{
public string resources { get; set; }
public KeyFind key_find { get; set; }
public Md5Check md5_check { get; set; }
}

public class Os
{
public string userassembly { get; set; }
public string metadata { get; set; }
}

public class Patched
{
public string metode { get; set; }
public string resources { get; set; }
public string key_patch { get; set; }
public Md5Vaild md5_vaild { get; set; }
}

public class Patch
{
public string version { get; set; } = "0.0.0";
public string channel { get; set; } = "Global";
public string release { get; set; } = "Official";
public Patched? patched { get; set; }
public Original? original { get; set; }
}
}
Loading

0 comments on commit 70dbfc4

Please sign in to comment.