alloc(newmem,2048,"DiabloImmortal.exe"+748302)
label(returnhere)
label(exit)
label(if01)
label(check_history)
label(setup_02)
label(setup_03)
label(shift_queue)
label(do_shift)
label(save_to_history)
label(find_free_history)
label(next_slot_ok)

newmem:


// new 2
// test byte ptr [rdi+00000208],20 = bat 00 = tat
// byte ptr [rdi+158],3F > 0F tat fog

//[rdi+270] = float X LEFT+UP 511
//[rdi+274] = float Y LEFT+UP 510

//[rdi+2B8] = float X RIGHT+DOWN 677
//[rdi+2BC] = float Y RIGHT+DOWN 383

//[rdi+218] = float 572
//[rdi+78] = float (float)0.42


// new 3 cach tim float x cua mini map rui tim 00 00 3F 00 00 thu 3F > 0F

// byte ptr [r14+18],3F > 0F tat fog
// byte ptr [r14+38],1F = bat 00 tat
// byte ptr [r14+50],40 = bat

//x RIGHT [r14-10] float 685 autoit 655
//y DOWN [r14-C] float 508  autoit 75
//x LEFT [r14-8] float 559 autoit 585
//y_max [r14-4] float 382 autoit 10



// mov eax,[rdi+28]
cmp qword ptr [r14+18],10
// cmp qword ptr [r14+18],10
// mov ecx,eax
// mov rax,[rsi]
//mov r15,[rax+rcx*8]
// mov rax,[r15]
// mov rbp,[rax+00000130]

//jb 7FF6FFDA8333 > ja no fog hoac mov rcx,[r14] > nop no fog






push rax
push rbx
push rcx

// Memory buffer management:
// [rax+0], [rax+8], [rax+10] -> Shift Queue (3 slots)
// [rax+50] to [rax+C8] -> History Storage (16 slots)
mov rax,newmem+500

// =========================================================================
// 1. AUTO REMOVE FOG FOR ALL TILES
// =========================================================================
cmp r14,0
je if01
cmp byte ptr [r14+18],3F
jne if01
cmp byte ptr [r14+38],1F
jne if01
cmp byte ptr [r14+50],40
jne if01
mov byte ptr [r14+18],0F
if01:

// =========================================================================
// [HARD STOP]: CHECK SLOT 26 (C8 HEX) TO STOP ALL PROCESSING
// =========================================================================
// If slot 26 (C8 Hex) is not 0 -> History is full (16 tiles) -> Stop!
cmp qword ptr [rax+C8],0
jne exit

// =========================================================================
// 2. SIGNATURE & COORDINATE FILTERS (ONLY RUN IF NOT FULL)
// =========================================================================
cmp r14,0
je exit

// Base Map Signature check
cmp byte ptr [r14+18],0F
jne exit
cmp byte ptr [r14+38],1F
jne exit
cmp byte ptr [r14+50],40
jne exit

// Bounding box coordinates filter
cmp dword ptr [r14-10],(float)655
jb exit
cmp dword ptr [r14-10],(float)715
ja exit
cmp dword ptr [r14-C],(float)478
jb exit
cmp dword ptr [r14-C],(float)538
ja exit

// =========================================================================
// 3. CHECK HISTORY LOOP (SCAN SLOT 11 TO 26 TO PREVENT DUPLICATES)
// =========================================================================
mov rcx,10                 // 10 Hex = loop 16 times
check_history:
cmp [rax+48+rcx*8],r14     // Scan memory from 50 Hex to C8 Hex
je exit                    // Exit if current flat is already in history
loop check_history

// =========================================================================
// 4. CHECK SHIFT QUEUE (SLOT 1-3) & INITIALIZE EMPTY SLOTS
// =========================================================================
cmp [rax+0],r14
je exit
cmp [rax+8],r14
je exit
cmp [rax+10],r14
je exit

// Initialize empty slots on start
cmp qword ptr [rax+0],0
jne setup_02
mov [rax+0],r14
jmp save_to_history

setup_02:
cmp qword ptr [rax+8],0
jne setup_03
mov [rax+8],r14
jmp save_to_history

setup_03:
cmp qword ptr [rax+10],0
jne shift_queue
mov [rax+10],r14
jmp save_to_history

// =========================================================================
// 5. SHIFT QUEUE: HIDE OLDEST FLAT & SHIFT SLOTS
// =========================================================================
shift_queue:
mov rbx,[rax+0]            // Get oldest map (Slot 1)
cmp rbx,0
je do_shift
mov byte ptr [rbx+38],00   // Hide oldest map

do_shift:
// Shift positions
mov rbx,[rax+8]
mov [rax+0],rbx            // Slot 2 to Slot 1

mov rbx,[rax+10]
mov [rax+8],rbx            // Slot 3 to Slot 2

mov [rax+10],r14           // Newest map to Slot 3

// =========================================================================
// 6. FORWARD LOOP: SAVE NEW MAP TO HISTORY (SLOT 11 TO 26)
// =========================================================================
save_to_history:
xor rcx,rcx                // Initialize index rcx = 0
find_free_history:
cmp qword ptr [rax+50+rcx*8],0 // Check from lowest slot (50 Hex) upwards
je next_slot_ok            // Jump if empty slot is found
inc rcx                    // Increment index if slot is occupied
cmp rcx,10                 // Max 16 slots (10 Hex)
jl find_free_history
jmp exit

next_slot_ok:
mov [rax+50+rcx*8],r14     // Save flat address to the empty slot

exit:
pop rcx
pop rbx
pop rax
jmp returnhere

"DiabloImmortal.exe"+748302:
jmp newmem
returnhere:
