Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Fix encoding in some countries
Browse files Browse the repository at this point in the history
  • Loading branch information
aianlinb committed Feb 1, 2021
1 parent f24d64f commit 0497c26
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
5 changes: 1 addition & 4 deletions LibBundle/BundleContainer.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

namespace LibBundle {
public class BundleContainer {
[DllImport("oo2core_8_win64.dll")]
[SuppressMessage("Interoperability", "CA1401:不應看得見 P/Invoke")]
public static extern int OodleLZ_Decompress(byte[] buffer, int bufferSize, byte[] result, long outputBufferSize, int a, int b, int c, IntPtr d, long e, IntPtr f, IntPtr g, IntPtr h, long i, int ThreadModule);
[DllImport("oo2core_8_win64.dll")]
[SuppressMessage("Interoperability", "CA1401:不應看得見 P/Invoke")]
public static extern int OodleLZ_Compress(ENCODE_TYPES format, byte[] buffer, long bufferSize, byte[] outputBuffer, COMPRESSTION_LEVEL level, IntPtr opts, long offs, long unused, IntPtr scratch, long scratch_size);
public enum ENCODE_TYPES {
LZH = 0,
Expand Down Expand Up @@ -118,7 +115,7 @@ public virtual MemoryStream Read(BinaryReader br) {
var b = br.ReadBytes(chunks[i]);
var size = (i + 1 == entry_count) ? uncompressed_size - (chunk_size * (entry_count - 1)) : chunk_size; // isLast ?
var toSave = new byte[size + 64];
OodleLZ_Decompress(b, b.Length, toSave, size, 0, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0, 3);
_ = OodleLZ_Decompress(b, b.Length, toSave, size, 0, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0, 3);
data.Write(toSave, 0, size);
}

Expand Down
10 changes: 5 additions & 5 deletions LibBundle/IndexContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IndexContainer(BinaryReader br)
databr.BaseStream.Seek(tmp, SeekOrigin.Begin);

var directoryBundle = new BundleContainer(databr);
var br2 = new BinaryReader(directoryBundle.Read(databr));
var br2 = new BinaryReader(directoryBundle.Read(databr), Encoding.UTF8);
// Array.Sort(Directorys, new Comparison<DirectoryRecord>((dr1, dr2) => { return dr1.Offset > dr2.Offset ? 1 : -1; }));
foreach (var d in Directorys)
{
Expand Down Expand Up @@ -183,15 +183,15 @@ public BundleRecord GetSmallestBundle(IList<BundleRecord> Bundles = null)
public static ulong FNV1a64Hash(string str)
{
if (str.EndsWith('/'))
str = str.TrimEnd(new char[] { '/' }) + "++";
str = str.TrimEnd('/') + "++";
else
str = str.ToLower() + "++";

var bs = Encoding.UTF8.GetBytes(str);
var hash = 0xcbf29ce484222325L;
var hash = 0xCBF29CE484222325UL;
foreach (var by in bs)
hash = (hash ^ by) * 0x100000001b3;
// Equal to: bs.Aggregate(0xcbf29ce484222325, (current, by) => (current ^ by) * 0x100000001b3);
hash = (hash ^ by) * 0x100000001B3UL;
// Equal to: bs.Aggregate(0xCBF29CE484222325UL, (current, by) => (current ^ by) * 0x100000001B3);
return hash;
}
}
Expand Down
3 changes: 2 additions & 1 deletion LibBundle/LibBundle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<TargetFramework>net5.0</TargetFramework>
<Authors>aianlinb</Authors>
<Copyright>Copyright © 2020 aianlinb.</Copyright>
<AssemblyVersion>2.4.1.0</AssemblyVersion>
<AssemblyVersion>2.4.2.0</AssemblyVersion>
<Platforms>x64</Platforms>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down
6 changes: 4 additions & 2 deletions LibBundle/Records/BundleRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public void Read(BinaryReader br = null, long? Offset = null)
public void Save(string newPath = null, string originalPath = null)
{
if (newPath == null && originalPath == null && Bundle.path == null)
throw new ArgumentNullException();
var data = new MemoryStream();
#pragma warning disable CA2208 // 正確地將引數例外狀況具現化
throw new ArgumentNullException();
#pragma warning restore CA2208 // 正確地將引數例外狀況具現化
var data = new MemoryStream();
foreach (var d in FileToAdd)
{
d.Key.Offset = (int)data.Position + Bundle.uncompressed_size;
Expand Down

0 comments on commit 0497c26

Please sign in to comment.