Raised This Month: $51 Target: $400
 12% 

Is there file current position has limitation


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
OrangePeel
Junior Member
Join Date: Aug 2019
Old 09-24-2020 , 03:51   Is there file current position has limitation
Reply With Quote #1

i make a plugin read .nav file, but when file current position >= 4096 then read wrong data (i guess)

Code:
#include <amxmodx>

#define CONSOLE_ECHO(%0) log_amx(%0)

// ie: "no place"
#define UNDEFINED_PLACE		0
#define ANY_PLACE		0xFFFF
#define NAV_MAGIC_NUMBER    0xFEEDFACE

// enum Extent
// {
//     Float:lo[3],
//     Float:hi[3]

//     float SizeX() const        { return hi.x - lo.x; }
//     float SizeY() const        { return hi.y - lo.y;}
//     float SizeZ() const        { return hi.z - lo.z; }
//     float Area() const        { return SizeX() * SizeY(); }

//     // return true if 'pos' is inside of this extent
//     bool Contains(const Vector *pos) const
//     {
//         return (pos->x >= lo.x && pos->x <= hi.x &&
//             pos->y >= lo.y && pos->y <= hi.y &&
//             pos->z >= lo.z && pos->z <= hi.z);
//     }
// };

enum _:LadderDirectionType
{
    LADDER_UP = 0,
    LADDER_DOWN,
    NUM_LADDER_DIRECTIONS
};

enum
{
    IN_COVER = 0x01,
    GOOD_SNIPER_SPOT = 0x02,
    IDEAL_SNIPER_SPOT = 0x04
};
// enum NavConnect
// {
//     connect_id,
//     area_id,

//     // bool operator==(const NavConnect &other) const { return (area == other.area) ? true : false; }
// };

enum _:NavDirType
{
    NORTH = 0,
    EAST,
    SOUTH,
    WEST,

    NUM_DIRECTIONS
};

enum _:NavAreaData
{
    m_id,
    m_nextID,
    m_place,
    
    // height of the implicit corners
    Float:m_neZ,
    Float:m_swZ,

    Float:m_center[3],
    m_attributeFlags,
    m_approachCount,
    Float:m_extent_lo[3],
    Float:m_extent_hi[3],
    
    // // connections to adjacent areas
    // m_connect[ NUM_DIRECTIONS ],        // a list of adjacent areas for each direction
    // m_connect_id[ NUM_DIRECTIONS ],        // a list of adjacent areas for each direction
    // m_connect_area[ NUM_DIRECTIONS ],        // a list of adjacent areas for each direction
    // m_ladder[ NUM_LADDER_DIRECTIONS ],    // list of ladders leading up and down from this area
    // m_ladder_dir[ NUM_LADDER_DIRECTIONS ],    // list of ladders leading up and down from this area
}

// new g_iNavArea, g_eNavArea[32][NavAreaData]
new Array:g_aNavArea
public plugin_init() 
{
    register_plugin("Nav Reader", "1.0", "OrangePeel")
    register_clcmd("/nav", "clcmd_test")
    g_aNavArea = ArrayCreate(NavAreaData)
    clcmd_test(0)
}

public plugin_end()
{
    ArrayDestroy(g_aNavArea)
}

public clcmd_test(id)
{
    new const szNavFile[] = "maps/fy_iceworld.nav"
    new const szMapFile[] = "maps/fy_iceworld.bsp"
    new iFile;
    if ((iFile = fopen(szNavFile, "rt")))
    {
        new result
        new magic
        
        result = fread(iFile, magic, BLOCK_INT);
        CONSOLE_ECHO("NavReader magic: '%d'", magic);
        if (!result || magic != NAV_MAGIC_NUMBER)
        {
            CONSOLE_ECHO("ERROR: Invalid navigation file '%s'", szNavFile);
        }

        new version
        result = fread(iFile, version, BLOCK_INT);
        CONSOLE_ECHO("NavReader version: '%d'", version);
        if (!result || version > 5)
        {
            CONSOLE_ECHO("ERROR: Unknown navigation file version '%d'", version);
        }

        if (version >= 4)
        {
            new saveBspSize
            fread(iFile, saveBspSize, BLOCK_INT);
            CONSOLE_ECHO("NavReader saveBspSize: '%d' %d", saveBspSize, filesize(szMapFile));
            if (filesize(szMapFile) != saveBspSize)
            {
                CONSOLE_ECHO("^n-----------------^n");
                CONSOLE_ECHO("*** WARNING ***^nThe AI navigation data is from a different version of this map.^nThe CPU players will likely not perform well.^n");
                CONSOLE_ECHO("-----------------^n^n");
            }
        }

        // load Place directory
        if (version >= 5)
        {
            PlaceDirectory_Load(iFile);
        }

        // get number of areas
        new count;
        result = fread(iFile, count, BLOCK_INT);
        CONSOLE_ECHO("NavReader AreaCount: '%d'", count);
        // count = 1
        for (new i = 0; i < count; ++i)
        {
            CNavArea_Load(iFile, version)
        }
    }
    
    fclose(iFile);
}

public CNavArea_Load(iFile, version)
{

    // load ID
    new areaData[NavAreaData]
    fread(iFile, areaData[m_id], BLOCK_INT);
    CONSOLE_ECHO("CNavArea_Load - ID: '%d'", areaData[m_id]);

    // update nextID to avoid collisions
    if (areaData[m_id] >= areaData[m_nextID])
        areaData[m_nextID] = areaData[m_id] + 1;

    // load attribute flags
    fread(iFile, areaData[m_attributeFlags], BLOCK_CHAR);
    // fread_blocks(iFile, areaData[m_attributeFlags], 1, BLOCK_CHAR);
    CONSOLE_ECHO("CNavArea_Load - flags: '%d'", areaData[m_attributeFlags]);

    // load extent of area
    // file->Read(&m_extent, 6 * sizeof(float));
    // fread(iFile, areaData[m_extent], 6 * BLOCK_INT);
    fread_vector(iFile, areaData[m_extent_lo]);
    fread_vector(iFile, areaData[m_extent_hi]);
    // fread_blocks(iFile, areaData[m_extent_lo], 3, BLOCK_INT);
    // fread_blocks(iFile, areaData[m_extent_hi], 3, BLOCK_INT);
    // CONSOLE_ECHO("CNavArea_Load - extent: '%.2f %.2f %.2f | %.2f %.2f %.2f'", areaData[m_extent][lo][0], areaData[m_extent][lo][1], areaData[m_extent][lo][2], areaData[m_extent][hi][0], areaData[m_extent][hi][1], areaData[m_extent][hi][2]);
    CONSOLE_ECHO("CNavArea_Load - extent: '%.2f %.2f %.2f | %.2f %.2f %.2f'", areaData[m_extent_lo][0], areaData[m_extent_lo][1], areaData[m_extent_lo][2], areaData[m_extent_hi][0], areaData[m_extent_hi][1], areaData[m_extent_hi][2]);

    // m_center.x = (m_extent.lo.x + m_extent.hi.x) / 2.0f;
    // m_center.y = (m_extent.lo.y + m_extent.hi.y) / 2.0f;
    // m_center.z = (m_extent.lo.z + m_extent.hi.z) / 2.0f;

    // load heights of implicit corners
    // fread(iFile, any:areaData[m_neZ], BLOCK_INT);
    // fread(iFile, any:areaData[m_swZ], BLOCK_INT);
    fread_float(iFile, any:areaData[m_neZ])
    fread_float(iFile, any:areaData[m_swZ])
    CONSOLE_ECHO("CNavArea_Load - m_neZ m_swZ: '%.2f %.2f'", areaData[m_neZ], areaData[m_swZ]);

    // load connections (IDs) to adjacent areas
    // in the enum order NORTH, EAST, SOUTH, WEST
    new count, connect_id;
    for (new d = 0; d < NUM_DIRECTIONS; ++d)
    {
        // load number of connections for this direction
        fread(iFile, count, BLOCK_INT);
        for (new i = 0; i < count; ++i)
        {
            // You need to save with Array (connect_id, area_id)
            fread(iFile, connect_id, BLOCK_INT);
            CONSOLE_ECHO("CNavArea_Load - connections: '%d %d %d'", d, i, connect_id);
        }
    }

    // Load hiding spots
    // load number of hiding spots
    // new hidingSpotCount[1];
    new hidingSpotCount;
    fread(iFile, hidingSpotCount, BLOCK_CHAR);
    // fread_blocks(iFile, hidingSpotCount, 1, BLOCK_CHAR);
    CONSOLE_ECHO("CNavArea_Load - hidingSpotCount: '%d'", hidingSpotCount);
    // file->Read(&hidingSpotCount, sizeof(unsigned char));

    new Float:pos[3];
    if (version == 1)
    {
        // load simple vector array
        for (new h = 0; h < hidingSpotCount; ++h)
        {
            fread_vector(iFile, pos);
            CONSOLE_ECHO("CNavArea_Load - hidingSpotPos: '%d %.2f %.2f %.2f'", h, pos[0], pos[1], pos[2]);

            // // create new hiding spot and put on master list
            // HidingSpot *spot = new HidingSpot(&pos, HidingSpot::IN_COVER);

            // m_hidingSpotList.AddToTail(spot);
        }
    }
    else
    {
        // load HidingSpot objects for this area
        for (new h = 0; h < hidingSpotCount; ++h)
        {
            // create new hiding spot and put on master list
            // HidingSpot *spot = new HidingSpot;

            HidingSpot_Load(iFile);

            // m_hidingSpotList.FindAndRemove(spot);
        }
    }

    // Load number of approach areas
    fread(iFile, areaData[m_approachCount], BLOCK_CHAR);
    // fread_blocks(iFile, hidingSpotCount, 1, BLOCK_CHAR);
    // file->Read(&m_approachCount, sizeof(unsigned char));

    // load approach area info (IDs)
    new type, here_id, prev_id, next_id;
    for (new a = 0; a < areaData[m_approachCount]; ++a)
    {
        fread(iFile, here_id, BLOCK_INT);
        fread(iFile, prev_id, BLOCK_INT);
        // file->Read(&m_approach[a].here.id, sizeof(unsigned int));
        // file->Read(&m_approach[a].prev.id, sizeof(unsigned int));
        // file->Read(&type, sizeof(unsigned char) );
        fread(iFile, type, BLOCK_CHAR);
        // m_approach[a].prevToHereHow = (NavTraverseType)type;

        fread(iFile, next_id, BLOCK_INT);
        CONSOLE_ECHO("CNavArea_Load - approach: '%d here_id:%d prev_id:%d type:%d next_id:%d'", a, here_id, prev_id, type, next_id);
        fread(iFile, type, BLOCK_CHAR);
        // file->Read(&m_approach[a].next.id, sizeof(unsigned int));
        // file->Read(&type, sizeof(unsigned char));
        // m_approach[a].hereToNextHow = (NavTraverseType)type;
    }

    // Load encounter paths for this area
    fread(iFile, count, BLOCK_INT);
    CONSOLE_ECHO("CNavArea_Load - encounter count: '%d '", count);

    if (version < 3)
    {
        new from_id, to_id, Float:path_from_x[3], Float:path_to_x[3]
        // old data, read and discard
        for (new e = 0; e < count; ++e)
        {
            // SpotEncounter encounter;

            fread(iFile, from_id, BLOCK_INT);
            fread(iFile, to_id, BLOCK_INT);
            fread_vector(iFile, path_from_x);
            fread_vector(iFile, path_to_x);
            // file->Read(&encounter.from.id, sizeof(unsigned int));
            // file->Read(&encounter.to.id, sizeof(unsigned int));

            // file->Read(&encounter.path.from.x, 3 * sizeof(float));
            // file->Read(&encounter.path.to.x, 3 * sizeof(float));

            // read list of spots along this path
            new spotCount;
            fread(iFile, spotCount, BLOCK_CHAR);
            // file->Read(&spotCount, sizeof(unsigned char));

            for (new s = 0; s < spotCount; ++s)
            {
                fread_vector(iFile, pos);
                fread_float(iFile, pos[0]);
                // file->Read(&pos, 3 * sizeof(float));
                // file->Read(&pos, sizeof(float));
            }
        }
        return;
    }

    for (new e = 0; e < count; ++e)
    {
        new from_id, to_id, order_id
        // SpotEncounter *encounter = new SpotEncounter;

        fread(iFile, from_id, BLOCK_INT);

        // file->Read(&encounter->from.id, sizeof(unsigned int));

        new dir;
        fread(iFile, dir, BLOCK_CHAR);
        // file->Read(&dir, sizeof(unsigned char));
        // encounter->fromDir = static_cast<NavDirType>(dir);

        fread(iFile, to_id, BLOCK_INT);
        // file->Read(&encounter->to.id, sizeof(unsigned int));

        fread(iFile, dir, BLOCK_CHAR);
        // file->Read(&dir, sizeof(unsigned char));
        // encounter->toDir = static_cast<NavDirType>(dir);

        // read list of spots along this path
        new spotCount;
        fread(iFile, spotCount, BLOCK_CHAR);
        CONSOLE_ECHO("CNavArea_Load - Cur: '%d'", ftell(iFile));
        CONSOLE_ECHO("CNavArea_Load - encounter: 'from_id:%d dir:%d to_id:%d spotCount:%d'", from_id, dir, to_id, spotCount);
        // file->Read(&spotCount, sizeof(unsigned char));

        // SpotOrder order;
        for (new s = 0; s < spotCount; ++s)
        {
            fread(iFile, order_id, BLOCK_INT);
            // file->Read(&order.id, sizeof(unsigned int));

            new t;
            fread(iFile, t, BLOCK_CHAR);
            CONSOLE_ECHO("CNavArea_Load - SpotOrder: 'order_id:%d t:%.2f'", order_id, float(t) / 255.0);

            // file->Read(&t, sizeof(unsigned char));

            // order.t = (float)t / 255.0f;

            // encounter->spotList.AddToTail(order);
        }

        // m_spotEncounterList.AddToTail(encounter);
    }

    if (version < 5)
        return;

    // Load Place data
    new entry
    fread(iFile, entry, BLOCK_SHORT);
    CONSOLE_ECHO("CNavArea_Load - entry: '%d'", entry);
    // file->Read(&entry, sizeof(entry));
/*
    // convert entry to actual Place
    SetPlace(placeDirectory.EntryToPlace(entry));
    */
    ArrayPushArray(g_aNavArea, areaData)
}

// public PlaceDirectory_EntryToPlace(entry)
// {
// 	if (entry == 0)
// 		return UNDEFINED_PLACE;

// 	new i = entry - 1;

// 	if (i > m_directory.Count())
// 	{
// 		// assert(false && "PlaceDirectory::EntryToPlace: Invalid entry");
// 		return UNDEFINED_PLACE;
// 	}

// 	return m_directory[i];
// }

public HidingSpot_Load(iFile)
{
    new id, Float:pos[3], flags
    fread(iFile, id, BLOCK_INT);
    fread_vector(iFile, pos)
    // fread_blocks(iFile, any:pos, 3, BLOCK_INT);
    // fread_blocks(iFile, flags, 1, BLOCK_CHAR);
    fread(iFile, flags, BLOCK_CHAR);
    CONSOLE_ECHO("CNavArea_Load - hidingSpotPos: '%d %.2f %.2f %.2f %d'", id, pos[0], pos[1], pos[2], flags);
    // file->Read(&m_id, sizeof(unsigned int));
    // file->Read(&m_pos, 3 * sizeof(float));
    // file->Read(&m_flags, sizeof(unsigned char));

    // // update next ID to avoid ID collisions by later spots
    // if (m_id >= m_nextID)
    //     m_nextID = m_id + 1;
}

public PlaceDirectory_Load(iFile)
{
    // read number of entries
    new count;
    fread(iFile, count, BLOCK_SHORT);
    CONSOLE_ECHO("PlaceDirectory_Load - count: '%d'", count);

    // m_directory.RemoveAll ();

    // read each entry
    static placeName[256];
    new len;
    for (new i = 0; i < count; ++i)
    {
        fread(iFile, len, BLOCK_SHORT);
        fread_blocks(iFile, placeName, len, BLOCK_CHAR);
        CONSOLE_ECHO("PlaceDirectory_Load: %s (%d)", placeName, len);

        // AddPlace(TheBotPhrases->NameToID(placeName));
    }
}

stock fread_float(iFile, &Float:val)
{
    fread(iFile, any:val, BLOCK_INT);
}

stock fread_vector(iFile, Float:vec[])
{
    fread_blocks(iFile, any:vec, 3, BLOCK_INT);
}
OrangePeel is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:08.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode