Created
April 13, 2020 19:47
-
-
Save BenLubar/78cb598f06e78694319668bb9c588c9e to your computer and use it in GitHub Desktop.
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
int32_t add_to_vector(building *item,vector<building *> *vec) | |
{ | |
int32_t size; | |
int32_t current_index; | |
int32_t current_index_00; | |
building **new_start; | |
building **new_start_00; | |
size_t old_size; | |
size_t old_size_00; | |
int32_t target_id_00; | |
int32_t last_index; | |
size_t new_size; | |
int32_t first_index; | |
size_t new_size_00; | |
size_t first_index_00; | |
building **old_start; | |
building **old_start_00; | |
size_t size_00; | |
building **new_finish; | |
building **new_finish_00; | |
building *item_00; | |
building **finish; | |
building **start; | |
int32_t item_id; | |
int32_t target_id_01; | |
int32_t target_id; | |
finish = vec->_M_finish; | |
start = vec->_M_start; | |
size_00 = (long)((long)finish - (long)start) >> 3; | |
size = (int32_t)size_00; | |
item_00 = item; | |
if (size == 0) { | |
if ((building *)finish != (building *)vec->_M_end_of_storage) { | |
if (finish == (building **)0x0) { | |
start = (building **)0x0; | |
} | |
else { | |
*finish = item; | |
start = vec->_M_finish; | |
} | |
*(building **)&vec->_M_finish = (building *)(start + 1); | |
return 1; | |
} | |
new_size = 8; | |
if (size_00 != 0) { | |
if (size_00 * 2 < size_00) { | |
new_size = 0xfffffffffffffff8; | |
} | |
else { | |
new_size = 0xfffffffffffffff8; | |
if (size_00 * 2 < 0x2000000000000000) { | |
new_size = size_00 << 4; | |
} | |
} | |
} | |
new_start = (building **)operator.new(new_size); | |
old_start = vec->_M_start; | |
old_size = (long)((long)vec->_M_finish - (long)old_start) >> 3; | |
if (new_start + old_size == (building **)0x0) { | |
new_finish = (building **)0x0; | |
} | |
else { | |
new_start[old_size] = item_00; | |
old_start = vec->_M_start; | |
old_size = (long)((long)vec->_M_finish - (long)old_start) >> 3; | |
new_finish = new_start + old_size; | |
} | |
if (old_size != 0) { | |
memmove(new_start,old_start,old_size * 8); | |
old_start = vec->_M_start; | |
} | |
if (old_start != (building **)0x0) { | |
operator.delete(old_start); | |
} | |
vec->_M_start = new_start; | |
*(building **)&vec->_M_finish = (building *)(new_finish + 1); | |
vec->_M_end_of_storage = (building **)(new_size + (long)new_start); | |
current_index_00 = 1; | |
} | |
else { | |
last_index = size + -1; | |
item_id = item->id; | |
if (start[last_index]->id < item_id) { | |
if ((building *)finish != (building *)vec->_M_end_of_storage) { | |
if (finish == (building **)0x0) { | |
start = (building **)0x0; | |
} | |
else { | |
*finish = item; | |
start = vec->_M_finish; | |
} | |
*(building **)&vec->_M_finish = (building *)(start + 1); | |
return size; | |
} | |
if (size_00 * 2 < size_00) { | |
new_size_00 = 0xfffffffffffffff8; | |
} | |
else { | |
new_size_00 = 0xfffffffffffffff8; | |
if (size_00 * 2 < 0x2000000000000000) { | |
new_size_00 = size_00 << 4; | |
} | |
} | |
new_start_00 = (building **)operator.new(new_size_00); | |
old_start_00 = vec->_M_start; | |
old_size_00 = (long)((long)vec->_M_finish - (long)old_start_00) >> 3; | |
if (new_start_00 + old_size_00 == (building **)0x0) { | |
new_finish_00 = (building **)0x0; | |
} | |
else { | |
new_start_00[old_size_00] = item_00; | |
old_start_00 = vec->_M_start; | |
old_size_00 = (long)((long)vec->_M_finish - (long)old_start_00) >> 3; | |
new_finish_00 = new_start_00 + old_size_00; | |
} | |
if (old_size_00 != 0) { | |
memmove(new_start_00,old_start_00,old_size_00 * 8); | |
old_start_00 = vec->_M_start; | |
} | |
if (old_start_00 != (building **)0x0) { | |
operator.delete(old_start_00); | |
} | |
vec->_M_start = new_start_00; | |
*(building **)&vec->_M_finish = (building *)(new_finish_00 + 1); | |
vec->_M_end_of_storage = (building **)((long)new_start_00 + new_size_00); | |
return size; | |
} | |
if (last_index < 0) { | |
first_index_00 = 0; | |
first_index = 0; | |
LAB_004e2f63: | |
target_id = (*(building **)(first_index_00 + (long)start))->id; | |
if (item_id <= target_id) { | |
if (item_id < target_id) { | |
vector_insert_cheap(vec,(building **)(first_index_00 + (long)start),&item_00); | |
return first_index; | |
} | |
return -1; | |
} | |
} | |
else { | |
current_index = last_index >> 1; | |
target_id_00 = start[current_index]->id; | |
if (item_id == target_id_00) { | |
return -1; | |
} | |
first_index = 0; | |
if (last_index == 0) { | |
first_index = 0; | |
} | |
else { | |
do { | |
if (item_id < target_id_00) { | |
last_index = current_index + -1; | |
if (last_index < first_index) goto LAB_004e2e1e; | |
} | |
else { | |
first_index = current_index + 1; | |
if (last_index < first_index) { | |
LAB_004e2e1e: | |
first_index_00 = (long)first_index << 3; | |
if (-1 < last_index) { | |
if (size <= last_index) { | |
return -1; | |
} | |
target_id_01 = start[(long)last_index]->id; | |
if (target_id_01 < item_id) { | |
if (last_index + 1 < size) { | |
vector_insert_cheap(vec,start + (long)last_index + 1,&item_00); | |
return last_index + 1; | |
} | |
return -1; | |
} | |
if (item_id < target_id_01) { | |
vector_insert_cheap(vec,start + (long)last_index,&item_00); | |
return last_index; | |
} | |
return -1; | |
} | |
goto LAB_004e2f63; | |
} | |
} | |
current_index = first_index + last_index >> 1; | |
target_id_00 = start[current_index]->id; | |
if (item_id == target_id_00) { | |
return -1; | |
} | |
} while (first_index != last_index); | |
} | |
if (item_id <= target_id_00) { | |
if (target_id_00 <= item_id) { | |
return -1; | |
} | |
goto LAB_004e2ed1; | |
} | |
} | |
first_index = first_index + 1; | |
current_index_00 = -1; | |
if (first_index < size) { | |
LAB_004e2ed1: | |
vector_insert_cheap(vec,start + first_index,&item_00); | |
return first_index; | |
} | |
} | |
return current_index_00; | |
} | |
building ** vector_insert_cheap(vector<building *> *vec,building **target_slot,building **item) | |
{ | |
building **finish; | |
building **start; | |
size_t move_count; | |
size_t index; | |
building *item_value; | |
building **new_finish; | |
start = vec->_M_start; | |
finish = vec->_M_finish; | |
index = (long)((long)target_slot - (long)start) >> 3; | |
if ((building *)finish == (building *)vec->_M_end_of_storage) { | |
vector_insert_expensive(vec,target_slot,item); | |
return vec->_M_start + index; | |
} | |
if (finish != target_slot) { | |
item_value = *item; | |
*(building **)&((building *)finish)->_vtable = *(building **)((building *)finish + -1 + 0x26); | |
new_finish = vec->_M_finish; | |
*(building **)&vec->_M_finish = (building *)(new_finish + 1); | |
move_count = (long)new_finish + (-8 - (long)target_slot) >> 3; | |
if (move_count != 0) { | |
memmove(new_finish + move_count * 0x1fffffffffffffff,target_slot,move_count * 8); | |
} | |
*target_slot = item_value; | |
return vec->_M_start + index; | |
} | |
if (finish != (building **)0x0) { | |
*(building **)&((building *)finish)->_vtable = *item; | |
finish = vec->_M_finish; | |
start = vec->_M_start; | |
} | |
finish = finish + 1; | |
vec->_M_finish = finish; | |
return start + index; | |
} | |
void vector_insert_expensive(vector<building *> *vec,building **target_slot,building **item) | |
{ | |
size_t move_count; | |
size_t size; | |
size_t index_00; | |
building **new_target_slot_next; | |
size_t move_count_00; | |
ulong count; | |
size_t byte_index_00; | |
size_t move_count_bytes_00; | |
size_t index; | |
size_t new_size; | |
building **new_start; | |
building **finish; | |
building **finish_00; | |
building **start; | |
finish = vec->_M_finish; | |
if ((building *)finish != (building *)vec->_M_end_of_storage) { | |
*finish = finish[-1]; | |
finish_00 = vec->_M_finish; | |
*(building **)&vec->_M_finish = (building *)(finish_00 + 1); | |
move_count = (long)finish_00 + (-8 - (long)target_slot) >> 3; | |
if (move_count != 0) { | |
memmove(finish_00 + move_count * 0x1fffffffffffffff,target_slot,move_count * 8); | |
} | |
*target_slot = *item; | |
return; | |
} | |
start = vec->_M_start; | |
size = (long)((long)finish - (long)start) >> 3; | |
if (size == 0) { | |
new_size = 8; | |
count = 1; | |
index = (long)((long)target_slot - (long)start) >> 3; | |
} | |
else { | |
count = size * 2; | |
if ((count < size) || (0x1fffffffffffffff < count)) { | |
new_size = 0xfffffffffffffff8; | |
count = 0x1fffffffffffffff; | |
index = (long)((long)target_slot - (long)start) >> 3; | |
} | |
else { | |
new_start = (building **)0x0; | |
new_size = size << 4; | |
index = (long)((long)target_slot - (long)start) >> 3; | |
if (count == 0) goto LAB_004dd613; | |
} | |
} | |
new_start = (building **)alloc_pointer_array(count); | |
LAB_004dd613: | |
if (new_start + index != (building **)0x0) { | |
new_start[index] = *item; | |
} | |
byte_index_00 = 0; | |
index_00 = (long)((long)target_slot - (long)vec->_M_start) >> 3; | |
if (index_00 != 0) { | |
byte_index_00 = index_00 * 8; | |
memmove(new_start,vec->_M_start,byte_index_00); | |
} | |
new_target_slot_next = (building **)((long)new_start + byte_index_00 + 8); | |
move_count_bytes_00 = 0; | |
move_count_00 = (long)((long)vec->_M_finish - (long)target_slot) >> 3; | |
if (move_count_00 != 0) { | |
move_count_bytes_00 = move_count_00 * 8; | |
new_target_slot_next = | |
(building **)memmove(new_target_slot_next,target_slot,move_count_bytes_00); | |
} | |
if (vec->_M_start != (building **)0x0) { | |
operator.delete(vec->_M_start); | |
} | |
vec->_M_start = new_start; | |
vec->_M_finish = (building **)(move_count_bytes_00 + (long)new_target_slot_next); | |
vec->_M_end_of_storage = (building **)(new_size + (long)new_start); | |
return; | |
} | |
void ** alloc_pointer_array(size_t count) | |
{ | |
void **array; | |
if (count < 0x2000000000000000) { | |
array = (void **)operator.new(count << 3); | |
return array; | |
} | |
/* WARNING: Subroutine does not return */ | |
__throw_bad_alloc(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment