AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Bot Mimic: Enum Structs (Invalid Handle) (https://forums.alliedmods.net/showthread.php?t=323354)

LeeStrong 04-17-2020 14:06

Bot Mimic: Enum Structs (Invalid Handle)
 
Hi all,
I am working on a project at the moment that uses "Bot Mimic" to record and play replay bots.

The coded has been updated to the new syntax however the following error gets tripped;

ERROR
Code:

[SM] Exception reported: Invalid Handle 0 (error: 4)
[SM] Blaming: surftimer.smx
[SM] Call stack trace:
[SM]  [0] PushArrayArray
[SM]  [1] Line 644, surftimer/replay.sp::LoadRecordFromFile
[SM]  [2] Line 432, surftimer/replay.sp::PlayRecord
[SM]  [3] Line 721, surftimer/replay.sp::LoadRecordReplay
[SM]  [4] Line 683, surftimer/replay.sp::RefreshBot

I was wondering if anyone could possibly look at these segments of code, before/after the new syntax and ask if you would have done anything differently, or spot something I perhaps didn't that may cause the above error?

Quote:

Originally Posted by BEFORE
Code:

        Handle hRecordFrames = CreateArray(view_as<int>(FrameInfo));
        Handle hAdditionalTeleport = CreateArray(AT_SIZE);

        int iFrame[FRAME_INFO_SIZE];
        for (int i = 0; i < iTickCount; i++)
        {
                ReadFile(hFile, iFrame, view_as<int>(FrameInfo), 4);
                PushArrayArray(hRecordFrames, iFrame, view_as<int>(FrameInfo));


Quote:

Originally Posted by AFTER
Code:

        Handle hRecordFrames = CreateArray(sizeof(FrameInfo));
        Handle hAdditionalTeleport = CreateArray(sizeof(AdditionalTeleport));
        FrameInfo iFrame;
        for (int i = 0; i < iTickCount; i++)
        {
                ReadFile(hFile, iFrame.PlayerButtons, sizeof(FrameInfo), 4);
                ReadFile(hFile, iFrame.PlayerImpulse, sizeof(FrameInfo), 4);
                ReadFile(hFile, view_as<int>(iFrame.ActualVelocity), sizeof(FrameInfo), 4);
                ReadFile(hFile, view_as<int>(iFrame.PredictedVelocity), sizeof(FrameInfo), 4);
                ReadFile(hFile, view_as<int>(iFrame.PredictedAngles), sizeof(FrameInfo), 4);
                ReadFile(hFile, view_as<int>(iFrame.NewWeapon), sizeof(FrameInfo), 4);
                ReadFile(hFile, iFrame.PlayerSubtype, sizeof(FrameInfo), 4);
                ReadFile(hFile, iFrame.PlayerSeed, sizeof(FrameInfo), 4);
                ReadFile(hFile, iFrame.AdditionalFields, sizeof(FrameInfo), 4);
                ReadFile(hFile, iFrame.Pause, sizeof(FrameInfo), 4);
                PushArrayArray(hRecordFrames, iFrame, sizeof(FrameInfo));


Quote:

Originally Posted by BEFORE
Code:

enum FrameInfo
{
        playerButtons = 0,
        playerImpulse,
        Float:actualVelocity[3],
        Float:predictedVelocity[3],
        Float:predictedAngles[2],
        CSWeaponID:newWeapon,
        playerSubtype,
        playerSeed,
        additionalFields,
        pause,
}


Quote:

Originally Posted by AFTER
Code:

enum struct FrameInfo
{
        int PlayerButtons;
        int PlayerImpulse;
        float ActualVelocity[3];
        float PredictedVelocity[3];
        float PredictedAngles[2];
        CSWeaponID NewWeapon;
        int PlayerSubtype;
        int PlayerSeed;
        int AdditionalFields;
        int Pause;
}



Fyren 04-18-2020 00:37

Re: Bot Mimic: Enum Structs (Invalid Handle)
 
ReadFile is int ReadFile(Handle hndl, int[] items, int num_items, int size). It reads the given number of things, each of the given size.

In your original code, you do ReadFile(hFile, iFrame, view_as<int>(FrameInfo), 4) which essentially says to read as many bytes as a FrameInfo is large.

In your changed code, you split it up to read each member one at a time, but you're not giving it the proper size of each. The obvious fix is to give it the right size for each. Off the top of my head, though, you can still use one ReadFile call since an enum struct is still really an array.

LeeStrong 04-18-2020 04:50

Re: Bot Mimic: Enum Structs (Invalid Handle)
 
--Please remove--


All times are GMT -4. The time now is 12:51.

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