Skip to content

Commit a3b8be2

Browse files
author
xausky
committed
2.5.1 修复UC服补丁无效问题,修复一个崩溃问题。
1 parent 929d494 commit a3b8be2

File tree

6 files changed

+142
-34
lines changed

6 files changed

+142
-34
lines changed

app/src/main/cpp/libuabe/FolderFile.cc

+19-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace xausky {
1010
char FolderPathBuffer[PATH_BUFFER_SIZE];
11-
char indentifier[5];
11+
char indentifier[7];
1212

1313
void RestoreTarget(string targetPath, string backupPath){
1414
__LIBUABE_LOG("RestoreTarget: targetPath=%s,backupPath=%s\n", targetPath.c_str(), backupPath.c_str());
@@ -33,19 +33,19 @@ namespace xausky {
3333
sprintf(FolderPathBuffer, "%s/%s", modsPath.c_str(), matchName.c_str());
3434
if(stat(FolderPathBuffer,&modStat)==0){
3535
if(S_ISDIR(modStat.st_mode)){
36-
memset(indentifier, 0, 5);
36+
memset(indentifier, 0, 7);
3737
binary_stream_t input;
3838
if(binary_stream_create_file(&input, (targetPath + '/' + filename).c_str(), BINARY_STREAM_ORDER_LITTLE_ENDIAN) != 0){
3939
__LIBUABE_LOG("binary_stream_create_file failed.");
4040
return;
4141
}
42-
if(binary_stream_read(&input, indentifier, 4) != 4) {
42+
if(binary_stream_read(&input, indentifier, 7) != 7) {
4343
__LIBUABE_LOG("binary_stream_read failed.");
4444
return;
4545
}
4646
BackupFile(filename, targetPath, backupPath);
47-
if(strcmp(indentifier, "AKPK")){
48-
__LIBUABE_LOG("AKPK patch: %s\n", matchName.c_str());
47+
if(memcmp(indentifier, "AKPK", 4) == 0){
48+
__LIBUABE_LOG("Wwise patch: %s\n", matchName.c_str());
4949
wwise_akpk_t akpk;
5050
wwise_akpk_patch_t patch;
5151
binary_stream_seek(&input, 0, SEEK_SET);
@@ -75,16 +75,20 @@ namespace xausky {
7575
binary_stream_destory(&input);
7676
} else {
7777
binary_stream_destory(&input);
78-
__LIBUABE_LOG("bundle patch: %s\n", matchName.c_str());
79-
BinaryStream bundle(targetPath + '/' + filename, true);
80-
BinaryStream patchedBundle(targetPath + '/' + filename, true);
81-
BundleFile bundleFile;
82-
bundleFile.open(bundle);
83-
map<string, map<int64_t, BinaryStream *> *> *patch = Utils::MakeBundlePatch(
84-
FolderPathBuffer);
85-
bundleFile.patch(*patch);
86-
bundleFile.save(patchedBundle);
87-
Utils::FreeBundlePatch(patch);
78+
if(memcmp(indentifier, "UnityFS", 7) == 0){
79+
__LIBUABE_LOG("Bundle patch: %s\n", matchName.c_str());
80+
BinaryStream bundle(targetPath + '/' + filename, true);
81+
BinaryStream patchedBundle(targetPath + '/' + filename, true);
82+
BundleFile bundleFile;
83+
bundleFile.open(bundle);
84+
map<string, map<int64_t, BinaryStream *> *> *patch = Utils::MakeBundlePatch(
85+
FolderPathBuffer);
86+
bundleFile.patch(*patch);
87+
bundleFile.save(patchedBundle);
88+
Utils::FreeBundlePatch(patch);
89+
} else {
90+
__LIBUABE_LOG("Unknown patch: %s\n", filename.c_str());
91+
}
8892
}
8993
}else if(S_ISREG(modStat.st_mode)){
9094
__LIBUABE_LOG("copy patch: %s\n", filename.c_str());

app/src/main/cpp/libuabe/Utils.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "Utils.hh"
2-
#include "LogUtils.hh"
32
#include <iostream>
43
#include <dirent.h>
54
#include <sys/stat.h>
@@ -49,6 +48,9 @@ namespace xausky {
4948
while (!folders.empty()){
5049
string current = folders.back();folders.pop_back();
5150
DIR *folder = opendir((path + "/" + current).c_str());
51+
if(folder == NULL){
52+
continue;
53+
}
5254
struct dirent *rent = NULL;
5355
while((rent = readdir(folder)) != NULL){
5456
if(strcmp(rent->d_name,".")==0 || strcmp(rent->d_name,"..")==0){

app/src/main/cpp/libuabe/ZipFile.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace xausky {
3030
if(mz_zip_reader_extract_to_mem(zip, i, target.data, target.capacity, 0)){
3131
target.size = entrityStat->m_uncomp_size;
3232
if(memcmp(target.data, "AKPK", 4) == 0){
33-
__LIBUABE_LOG("AKPK patch: %s\n", entrityStat->m_filename);
33+
__LIBUABE_LOG("Wwise patch: %s\n", entrityStat->m_filename);
3434
wwise_akpk_t akpk;
3535
wwise_akpk_patch_t patch;
3636
binary_stream_seek(&target, 0, SEEK_SET);
@@ -56,8 +56,8 @@ namespace xausky {
5656
}
5757
wwise_akpk_destory_patch(&patch);
5858
mz_zip_writer_add_mem(out, entrityStat->m_filename, target.data, target.size, MZ_NO_COMPRESSION);
59-
} else {
60-
__LIBUABE_LOG("bundle patch: %s\n", entrityStat->m_filename);
59+
} else if(memcmp(target.data, "UnityFS", 7) == 0) {
60+
__LIBUABE_LOG("Bundle patch: %s\n", entrityStat->m_filename);
6161
BinaryStream bundle((char *)target.data, entrityStat->m_uncomp_size, true);
6262
BinaryStream patchedBundle(true);
6363
BundleFile bundleFile;
@@ -69,12 +69,14 @@ namespace xausky {
6969
int len = patchedBundle.size();
7070
patchedBundle.ReadData(dataBuffer, len);
7171
mz_zip_writer_add_mem(out, entrityStat->m_filename, dataBuffer, len, MZ_NO_COMPRESSION);
72+
} else {
73+
__LIBUABE_LOG("Unknown patch: %s\n", entrityStat->m_filename);
7274
}
75+
binary_stream_destory(&target);
7376
return;
7477
} else {
7578
__LIBUABE_LOG("mz_zip_reader_extract_to_mem() failed!\n");
7679
}
77-
binary_stream_destory(&target);
7880
}
7981
if(S_ISREG(modStat.st_mode)){
8082
mz_zip_writer_add_file(out, entrityStat->m_filename, pathBuffer, NULL, 0, MZ_NO_COMPRESSION);

app/src/main/cpp/libuabe/libumm/utils.c

+11
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,15 @@ klist_t(utils_file_list)* utils_file_list_make(const char *path){
2020

2121
void utils_file_list_destory(klist_t(utils_file_list)* list){
2222
kl_destroy(utils_file_list, list);
23+
}
24+
25+
void utils_file_stream_dump(binary_stream_t *stream, int len, uint32_t id){
26+
char name[1024];
27+
binary_stream_t out;
28+
int64_t pos = binary_stream_seek(stream, 0, SEEK_CUR);
29+
sprintf(name, "%u-%u.dump", id, rand());
30+
binary_stream_create_file(&out, name, BINARY_STREAM_ORDER_LITTLE_ENDIAN);
31+
binary_stream_copy(&out, stream, len);
32+
binary_stream_destory(&out);
33+
binary_stream_seek(stream, pos, SEEK_SET);
2334
}

app/src/main/cpp/libuabe/libumm/utils.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,24 @@ extern "C" {
66

77
#include <dirent.h>
88
#include <string.h>
9-
#include <climits>
9+
#include <limits.h>
1010

1111
#include "klist.h"
12+
#include "binary_stream.h"
13+
14+
#ifdef __ANDROID__
15+
#include <android/log.h>
16+
#define __LIBUABE_LOG(str, args...) __android_log_print(ANDROID_LOG_DEBUG, "NativeUtils", str, ##args)
17+
#define __LIBUABE_DEBUG(str, args...)
18+
#else
19+
#include <stdio.h>
20+
#define __LIBUABE_LOG(str, args...) printf(str, ##args)
21+
#ifdef DEBUG
22+
#define __LIBUABE_DEBUG(str, args...) printf(str, ##args)
23+
#else
24+
#define __LIBUABE_DEBUG(str, args...)
25+
#endif
26+
#endif
1227

1328
#define __unuse_free(x)
1429

@@ -22,6 +37,8 @@ klist_t(utils_file_list) *utils_file_list_make(const char *path);
2237

2338
void utils_file_list_destory(klist_t(utils_file_list) *list);
2439

40+
void utils_file_stream_dump(binary_stream_t *stream, int len, uint32_t id);
41+
2542
#endif
2643
#if defined (__cplusplus)
2744
}

app/src/main/cpp/libuabe/libumm/wwise_bank.c

+85-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "wwise_bank.h"
2+
#include "utils.h"
23

34
int8_t wwise_bank_parser_event_voice(kbtree_t(wwise_bank_key_value_map) *map, binary_stream_t *stream){
45
uint32_t id, wem;
@@ -21,6 +22,7 @@ int8_t wwise_bank_parser_event_voice(kbtree_t(wwise_bank_key_value_map) *map, bi
2122
if(type == 0){
2223
kb_put(wwise_bank_key_value_map, map, entity);
2324
}
25+
__LIBUABE_DEBUG("voice:%u,%u,%u\n", id, type, wem);
2426
return 0;
2527
}
2628

@@ -43,6 +45,7 @@ int8_t wwise_bank_parser_event_action(kbtree_t(wwise_bank_key_value_map) *map, b
4345
entity.key = id;
4446
entity.value = voice;
4547
kb_put(wwise_bank_key_value_map, map, entity);
48+
__LIBUABE_DEBUG("action:%u,%u,%u,%u\n", id, scope, type, voice);
4649
return 0;
4750
}
4851

@@ -57,43 +60,97 @@ int8_t wwise_bank_parser_event_event(kbtree_t(wwise_bank_key_values_map) *map, b
5760
}
5861
entity.key = id;
5962
entity.size = number;
63+
__LIBUABE_DEBUG("event:%u\n", id);
6064
for(int i = 0; i < number; ++i){
6165
if(i >= EVENT_MAX_ACTION_BUMBER){
62-
puts("EVENT_MAX_ACTION_BUMBER error.\n");
66+
__LIBUABE_DEBUG("EVENT_MAX_ACTION_BUMBER error.\n");
6367
break;
6468
}
6569
if(binary_stream_read_uint32(stream, &action) != 0){
6670
return -3;
6771
}
72+
__LIBUABE_DEBUG("--action:%u\n", action);
6873
entity.values[i] = action;
6974
}
7075
kb_put(wwise_bank_key_values_map, map, entity);
7176
return 0;
7277
}
7378

74-
int8_t wwise_bank_parser_event_container(kbtree_t(wwise_bank_key_values_map) *map, binary_stream_t *stream){
75-
uint32_t id, number, voice;
79+
int8_t wwise_bank_parser_event_sequence(kbtree_t(wwise_bank_key_values_map) *map, binary_stream_t *stream){
80+
uint16_t check = 0;
81+
uint32_t id, number, object;
7682
wwise_bank_key_values_t entity;
7783
uint64_t start = binary_stream_seek(stream, 0, SEEK_CUR);
7884
if(binary_stream_read_uint32(stream, &id) != 0){
7985
return -1;
8086
}
81-
if(binary_stream_seek(stream, 0x34, SEEK_CUR) == -1){
87+
do {
88+
if(binary_stream_read_uint16(stream, &check) != 0){
89+
return -2;
90+
}
91+
if(binary_stream_seek(stream, -1, SEEK_CUR) == -1){
92+
return -2;
93+
}
94+
} while(check != 0x447A);
95+
if(binary_stream_seek(stream, 15, SEEK_CUR) == -1){
96+
return -2;
97+
}
98+
if(binary_stream_read_uint32(stream, &number) != 0){
99+
return -2;
100+
}
101+
if(number > EVENT_MAX_ACTION_BUMBER){
102+
__LIBUABE_DEBUG("sequence number too more.\n");
103+
return 0;
104+
}
105+
entity.key = id;
106+
entity.size = number;
107+
__LIBUABE_DEBUG("sequence:%u\n", id);
108+
for(int i = 0; i < number; ++i){
109+
if(binary_stream_read_uint32(stream, &object) != 0){
110+
return -3;
111+
}
112+
__LIBUABE_DEBUG("--object:%u\n", object);
113+
entity.values[i] = object;
114+
}
115+
if(number > 0){
116+
kb_put(wwise_bank_key_values_map, map, entity);
117+
}
118+
return 0;
119+
}
120+
121+
int8_t wwise_bank_parser_event_switch(kbtree_t(wwise_bank_key_values_map) *map, binary_stream_t *stream){
122+
uint8_t skip;
123+
uint32_t id, number, object;
124+
wwise_bank_key_values_t entity;
125+
uint64_t start = binary_stream_seek(stream, 0, SEEK_CUR);
126+
if(binary_stream_read_uint32(stream, &id) != 0){
127+
return -1;
128+
}
129+
if(binary_stream_seek(stream, 0x0C, SEEK_CUR) == -1){
130+
return -2;
131+
}
132+
if(binary_stream_read_uint8(stream, &skip) != 0){
133+
return -2;
134+
}
135+
if(binary_stream_seek(stream, 0x19 + 5 * skip, SEEK_CUR) == -1){
82136
return -2;
83137
}
84138
if(binary_stream_read_uint32(stream, &number) != 0){
85139
return -2;
86140
}
87141
if(number > EVENT_MAX_ACTION_BUMBER){
142+
__LIBUABE_DEBUG("switch number too more.\n");
88143
return 0;
89144
}
90145
entity.key = id;
91146
entity.size = number;
147+
__LIBUABE_DEBUG("switch:%u\n", id);
92148
for(int i = 0; i < number; ++i){
93-
if(binary_stream_read_uint32(stream, &voice) != 0){
149+
if(binary_stream_read_uint32(stream, &object) != 0){
94150
return -3;
95151
}
96-
entity.values[i] = voice;
152+
__LIBUABE_DEBUG("--object:%u\n", object);
153+
entity.values[i] = object;
97154
}
98155
if(number > 0){
99156
kb_put(wwise_bank_key_values_map, map, entity);
@@ -102,11 +159,11 @@ int8_t wwise_bank_parser_event_container(kbtree_t(wwise_bank_key_values_map) *ma
102159
}
103160

104161
int8_t wwise_bank_parser_event(wwise_bank_t *bank, binary_stream_t *stream){
105-
bank->voice_wem_map = kb_init(wwise_bank_key_value_map, KB_DEFAULT_SIZE);
106-
bank->event_wems_map = kb_init(wwise_bank_key_values_map, KB_DEFAULT_SIZE);
107-
bank->action_object_map = kb_init(wwise_bank_key_value_map, KB_DEFAULT_SIZE);
108-
bank->event_actions_map = kb_init(wwise_bank_key_values_map, KB_DEFAULT_SIZE);
109-
bank->object_voices_map = kb_init(wwise_bank_key_values_map, KB_DEFAULT_SIZE);
162+
bank->voice_wem_map = kb_init(wwise_bank_key_value_map, KB_DEFAULT_SIZE * sizeof(wwise_bank_key_value_t));
163+
bank->event_wems_map = kb_init(wwise_bank_key_values_map, KB_DEFAULT_SIZE* sizeof(wwise_bank_key_values_t));
164+
bank->action_object_map = kb_init(wwise_bank_key_value_map, KB_DEFAULT_SIZE* sizeof(wwise_bank_key_value_t));
165+
bank->event_actions_map = kb_init(wwise_bank_key_values_map, KB_DEFAULT_SIZE* sizeof(wwise_bank_key_values_t));
166+
bank->object_voices_map = kb_init(wwise_bank_key_values_map, KB_DEFAULT_SIZE* sizeof(wwise_bank_key_values_t));
110167
uint8_t type;
111168
uint32_t number, length, id;
112169
int64_t end;
@@ -125,6 +182,15 @@ int8_t wwise_bank_parser_event(wwise_bank_t *bank, binary_stream_t *stream){
125182
if(end < 0){
126183
return -3;
127184
}
185+
/*
186+
if(binary_stream_read_uint32(stream, &id) != 0){
187+
return -2;
188+
}
189+
binary_stream_seek(stream, -4, SEEK_CUR);
190+
__LIBUABE_DEBUG("object:%u,%u,%u\n", id, type, length);
191+
if(id == 151993151 || id == 606474963 || id == 698201592 || id == 462587676){
192+
utils_file_stream_dump(stream, length, id);
193+
}*/
128194
switch(type){
129195
case 4: //Event
130196
if(wwise_bank_parser_event_event(bank->event_actions_map, stream)!=0){
@@ -142,7 +208,12 @@ int8_t wwise_bank_parser_event(wwise_bank_t *bank, binary_stream_t *stream){
142208
}
143209
break;
144210
case 5: //Random Container or Sequence Container
145-
if(wwise_bank_parser_event_container(bank->object_voices_map, stream)!=0){
211+
if(wwise_bank_parser_event_sequence(bank->object_voices_map, stream)!=0){
212+
return -7;
213+
}
214+
break;
215+
case 6: //Switch
216+
if(wwise_bank_parser_event_switch(bank->object_voices_map, stream)!=0){
146217
return -7;
147218
}
148219
break;
@@ -212,6 +283,7 @@ int8_t wwise_bank_parser_didx(wwise_bank_t *bank, binary_stream_t *stream, uint3
212283
if(current < 0){
213284
return -6;
214285
}
286+
__LIBUABE_DEBUG("wem:%u,%u\n", put.key, put.length);
215287
}
216288
return 0;
217289
}
@@ -221,7 +293,7 @@ int8_t wwise_bank_parser_data(wwise_bank_t *bank, binary_stream_t *stream){
221293
int32_t start;
222294
wwise_bank_key_stream_t put;
223295
if(bank->wem_stream_map == 0){
224-
printf("wwise_bank_parser_data not didx.");
296+
__LIBUABE_DEBUG("wwise_bank_parser_data not didx.");
225297
return 0;
226298
}
227299
start = binary_stream_seek(stream, 0, SEEK_CUR);

0 commit comments

Comments
 (0)