-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ElaXan/master
UI Overhaul and Code Optimization
- Loading branch information
Showing
26 changed files
with
1,389 additions
and
1,565 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,62 +1,72 @@ | ||
public class HexUtility | ||
| ||
namespace YuukiPS_Launcher.Game.Genshin.Patch | ||
{ | ||
public static bool EqualsBytes(byte[] b1, params byte[] b2) | ||
public class HexUtility | ||
{ | ||
if (b1.Length != b2.Length) | ||
return false; | ||
for (int i = 0; i < b1.Length; i++) | ||
public static bool EqualsBytes(byte[] b1, params byte[] b2) | ||
{ | ||
if (b1[i] != b2[i]) | ||
if (b1.Length != b2.Length) | ||
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)) | ||
for (int i = 0; i < b1.Length; i++) | ||
{ | ||
continue; | ||
if (b1[i] != b2[i]) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
for (; offset < sourceByteArray.Length; offset++) | ||
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 (sourceByteArray[offset] == rep.oldValue[0]) | ||
if (EqualsBytes(rep.OldValue, rep.NewValue)) | ||
{ | ||
if (sourceByteArray.Length - offset < rep.oldValue.Length) | ||
break; | ||
continue; | ||
} | ||
|
||
bool find = true; | ||
for (int i = 1; i < rep.oldValue.Length - 1; i++) | ||
for (; offset < sourceByteArray.Length; offset++) | ||
{ | ||
if (sourceByteArray[offset] == rep.OldValue[0]) | ||
{ | ||
if (sourceByteArray[offset + i] != rep.oldValue[i]) | ||
if (sourceByteArray.Length - offset < rep.OldValue.Length) | ||
break; | ||
|
||
bool find = true; | ||
for (int i = 1; i < rep.OldValue.Length - 1; i++) | ||
{ | ||
find = false; | ||
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; | ||
} | ||
} | ||
if (find) | ||
{ | ||
Buffer.BlockCopy(rep.newValue, 0, newByteArray, offset, rep.newValue.Length); | ||
offset += (rep.newValue.Length - 1); | ||
break; | ||
} | ||
} | ||
} | ||
return newByteArray; | ||
} | ||
return newByteArray; | ||
} | ||
} | ||
|
||
public class HexReplaceEntity | ||
{ | ||
public byte[] oldValue { get; set; } | ||
public class HexReplaceEntity | ||
{ | ||
public byte[] OldValue { get; set; } = null!; | ||
public byte[] NewValue { get; set; } = null!; | ||
|
||
public byte[] newValue { get; set; } | ||
public HexReplaceEntity() { } | ||
|
||
} | ||
public HexReplaceEntity(byte[] oldValue, byte[] newValue) | ||
{ | ||
OldValue = oldValue; | ||
NewValue = newValue; | ||
} | ||
} | ||
} |
Oops, something went wrong.