Raised This Month: $7 Target: $400
 1% 

[CS:GO] Precache from mdl & pcf & vmt


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 07-24-2018 , 01:07   [CS:GO] Precache from mdl & pcf & vmt
Reply With Quote #1

That i got in console (CS:GO Game test) :
PHP Code:
zombie/zombieclaw/zombie_infection_male.mp3
zombie
/zombieclaw/npc_zombie_male01_idle.mp3
zombie
/zombieclaw/npc_zombie_male01_idle.mp3
zombie
/zombieclaw/zombi_swing_1.mp3
zombie
/zombieclaw/zombi_swing_2.mp3
zombie
/zombieclaw/player_zombie_normal_male_attack1.mp3
zombie
/zombieclaw/player_zombie_normal_male_attack2.mp3
zombie
/zombieclaw/zombi_attack_1.mp3
zombie
/zombieclaw/zombi_attack_2.mp3
zombie
/zombieclaw/zombi_swing_3.mp3
zombie
/zombieclaw/zombi_attack_1.mp3
zombie
/zombieclaw/zombi_attack_2.mp3
zombie
/zombieclaw/npc_zombie_male01_idle.mp3
weapons
/eminem/ethereal/ethereal_reload.wav
weapons
/eminem/ethereal/ethereal_draw.wav
zombie
/bazooka/bazooka_1.mp3
zombie
/bazooka/bazooka_draw.mp3
zombie
/bazooka/bazooka_clipout.mp3
Initializing Steam libraries 
for secure Internet server
[S_API FAILSteamAPI_Init() failedSteamAPI_IsSteamRunning() failed.
Setting breakpad minidump AppID 730
dlopen failed trying to load
:
/
home/server2470/.steam/sdk32/steamclient.so
with error
:
/
home/server2470/.steam/sdk32/steamclient.socannot open shared object fileNo such file or directory
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
Setting breakpad minidump AppID 
740
Logging into Steam gameserver account with logon token 
'A11CA100xxxxxxxxxxxxxxxxxxxxxxxx'
GOTV is disabled on this server
Code:
PHP Code:

/**
 * Precache models and return model index.
 *  NOTE: Precache with engine 'hide' models included.
 *
 * @param sModel            The model path.
 * @return                  The model index if was precached, 0 otherwise.
 **/
stock int ModelsPrecacheStatic(const char[] sModel)
{
    
// If model path is empty, then stop
    
if(!strlen(sModel))
    {
        return 
0;
    }
    
    
// If model didn't exist, then
    
if(!FileExists(sModel))
    {
        
// Try to find model in game folder by name
        
return ModelsPrecacheStandart(sModel);
    }
    
    
// If model doesn't precache yet, then continue
    
if(!IsModelPrecached(sModel))
    {
        
// Precache model materails
        
ModelsPrecacheMaterials(sModel);

        
// Precache model resources
        
ModelsPrecacheResources(sModel);
    }
    
    
// Return on the success
    
return PrecacheModel(sModeltrue);
}

/**
 * Precache weapon models and return model index.
 *
 * @param sModel            The model path. 
 * @return                  The model index if was precached, 0 otherwise.
 **/
stock int ModelsPrecacheWeapon(const char[] sModel)
{
    
// If model path is empty, then stop
    
if(!strlen(sModel))
    {
        return 
0;
    }
    
    
// If model didn't exist, then
    
if(!FileExists(sModel))
    {
        
// Return error
        
LogEvent(falseLogType_FatalLOG_CORE_EVENTSLogModule_Models"Config Validation""Invalid model path. File not found: \"%s\""sModel);
    }

    
// If model doesn't precache yet, then continue
    
if(!IsModelPrecached(sModel))
    {
        
// Precache model sounds
        
ModelsPrecacheSounds(sModel);
        
        
// Precache model materails
        
ModelsPrecacheMaterials(sModel);
        
        
// Precache model resources
        
ModelsPrecacheResources(sModel);
    }
    
    
// Return the model index
    
return PrecacheModel(sModeltrue);
}

/**
 * Reads the current model and precache its resources.
 *
 * @param sModel            The model path.
 **/
stock void ModelsPrecacheResources(const char[] sModel)
{
    
// Add file to download table
    
AddFileToDownloadsTable(sModel);

    
// Initialize some variables
    
static char sResource[PLATFORM_MAX_PATH];
    static const 
char sTypes[3][SMALL_LINE_LENGTH] = { ".dx90.vtx"".phy"".vvd" };

    
// Finds the first occurrence of a character in a string
    
int iFormat FindCharInString(sModel'.'true);
    
    
// i = resource type
    
int iSize sizeof(sTypes);
    for(
int i 0iSizei++)
    {
        
// Extract value string
        
StrExtract(sResourcesModel0iFormat);
        
        
// Format full path to file 
        
Format(sResourcesizeof(sResource), "%s%s"sResourcesTypes[i]);
        
        
// Validate resource
        
if(FileExists(sResource)) 
        {
            
// Add file to download table
            
AddFileToDownloadsTable(sResource);
        }
    }
}

/**
 * Reads the current model and precache its sounds.
 *
 * @param sModel            The model path.
 * @return                  True if was precached, false otherwise.
 **/
stock bool ModelsPrecacheSounds(const char[] sModel)
{
    
// Open the file
    
File hFile OpenFile(sModel"rb");

    
// If doesn't exist stop
    
if(hFile == INVALID_HANDLE)
    {
        
LogEvent(falseLogType_FatalLOG_CORE_EVENTSLogModule_Models"Config Validation""Error opening file: \"%s\""sModel);
        return 
false;
    }
    
    
// Initialize some variables
    
static char sPath[PLATFORM_MAX_PATH]; int iChar

    do 
/// Reads a single binary char
    
{
        
hFile.Seek(2SEEK_CUR);
        
hFile.ReadInt8(iChar);
    } 
    while(
iChar == 0);

    
// Shift the cursor a bit
    
hFile.Seek(1SEEK_CUR);

    do 
/// Reads a single binary char
    
{
        
hFile.Seek(2SEEK_CUR);
        
hFile.ReadInt8(iChar);
    } 
    while(
iChar != 0);

    
// Loop throught the binary
    
while(!hFile.EndOfFile())
    {
        
// Reads a UTF8 or ANSI string from a file
        
hFile.ReadString(sPathsizeof(sPath));
        
        
// Validate string
        
if(!IsByteString(sPath)) 
        {
            
// Finds the first occurrence of a character in a string
            
int iFormat FindCharInString(sPath'.'true);

            
// If file path is don't have format, then skip
            
if(iFormat == -1
            {
                continue;
            }
            
            
// Validate sound format
            
if(!strcmp(sPath[iFormat], ".mp3"false) || !strcmp(sPath[iFormat], ".wav"false))
            {
                
// Format full path to file
                
Format(sPathsizeof(sPath), "sound/%s"sPath);
                
                
// Add file to download table
                
fnPrecacheSoundQuirk(sPath);
            }
        }
    }

    
// Close file
    
delete hFile
    return 
true;
}

/**
 * Reads the current model and precache its materials.
 *
 * @param sModel            The model path.
 * @return                  True if was precached, false otherwise.
 **/
stock bool ModelsPrecacheMaterials(const char[] sModel)
{
    
// Open the file
    
File hFile OpenFile(sModel"rb");

    
// If doesn't exist stop
    
if(hFile == INVALID_HANDLE)
    {
        
LogEvent(falseLogType_FatalLOG_CORE_EVENTSLogModule_Models"Config Validation""Error opening file: \"%s\""sModel);
        return 
false;
    }
    
    
// Initialize some variables
    
static char sMaterial[PLATFORM_MAX_PATH]; static char sPath[PLATFORM_MAX_PATH]; int iNumMatint iChar;

    
// Find the total materials amount
    
hFile.Seek(204SEEK_SET);
    
hFile.ReadInt32(iNumMat);
    
hFile.Seek(0SEEK_END);
    
    do 
/// Reads a single binary char
    
{
        
hFile.Seek(-2SEEK_CUR);
        
hFile.ReadInt8(iChar);
    } 
    while(
iChar == 0);

    
// Shift the cursor a bit
    
hFile.Seek(SEEK_CUR);

    do 
/// Reads a single binary char
    
{
        
hFile.Seek(-2SEEK_CUR);
        
hFile.ReadInt8(iChar);
    } 
    while(
iChar != 0);

    
// Reads a UTF8 or ANSI string from a file
    
int iPosIndex hFile.Position;
    
hFile.ReadString(sMaterialsizeof(sMaterial));
    
hFile.Seek(iPosIndexSEEK_SET);
    
hFile.Seek(-1SEEK_CUR);

    
// i = material index
    
for(int i 0iNumMati++)
    {
        do 
/// Reads a single binary char
        
{
            
hFile.Seek(-2SEEK_CUR);
            
hFile.ReadInt8(iChar);
        } 
        while(
iChar != 0);

        
// Reads a UTF8 or ANSI string from a file
        
iPosIndex hFile.Position;
        
hFile.ReadString(sPathsizeof(sPath));
        
hFile.Seek(iPosIndexSEEK_SET);
        
        
// Validate size
        
if(!strlen(sPath))
        {
            continue;
        }

        
// Finds the first occurrence of a character in a string
        
int iFormat FindCharInString(sPath'\\'true);

        
// Validate no format
        
if(iFormat != -1)
        {
            
// Format full path to directory
            
Format(sPathsizeof(sPath), "materials\\%s"sPath);
    
            
// Open the directory
            
DirectoryListing hDirectory OpenDirectory(sPath);
            
            
// If doesn't exist stop
            
if(hDirectory == INVALID_HANDLE)
            {
                continue;
            }
            
            
// Initialize variables
            
static char sFile[PLATFORM_MAX_PATH];
            
            
// Initialize types
            
FileType hType;
            
            
// Search any files in the directory and precache them
            
while(hDirectory.GetNext(sFilesizeof(sFile), hType)) 
            {
                
// Validate what found
                
if(hType == FileType_File
                {
                    
// Finds the first occurrence of a character in a string
                    
iFormat FindCharInString(sFile'.'true);
            
                    
// If file path is don't have format, then skip
                    
if(iFormat == -1
                    {
                        continue;
                    }
                    
                    
// Validate material format
                    
if(!strcmp(sFile[iFormat], ".vmt"false))
                    {
                        
// Format full path to file
                        
Format(sFilesizeof(sFile), "%s%s"sPathsFile);
                        
                        
// Precache model textures
                        
ModelsPrecacheTextures(sFile);
                    }
                }
            }

            
// Close directory
            
delete hDirectory;
        }
        else
        {
            
// Format full path to file
            
Format(sPathsizeof(sPath), "materials\\%s%s.vmt"sMaterialsPath);
            
            
// Precache model textures
            
ModelsPrecacheTextures(sPath);
        }
    }
    
    
// Close file
    
delete hFile
    return 
true;
}

/**
 * Reads the current particle and precache its textures.
 *
 * @param sModel            The model path.
 * @return                  True if was precached, false otherwise.
 **/
stock bool ModelsPrecacheParticle(const char[] sModel)
{
    
// Open the file
    
File hFile OpenFile(sModel"rb");

    
// If doesn't exist stop
    
if(hFile == INVALID_HANDLE)
    {
        
LogEvent(falseLogType_FatalLOG_CORE_EVENTSLogModule_Models"Config Validation""Error opening file: \"%s\""sModel);
        return 
false;
    }
    
    
// Add file to download table
    
AddFileToDownloadsTable(sModel);

    
// Precache generic
    
PrecacheGeneric(sModeltrue); //! Precache only here

    // Initialize some variables
    
static char sPath[PLATFORM_MAX_PATH]; int iChar;

    
/// https://github.com/VSES/SourceEngine2007/blob/master/src_main/movieobjects/dmeparticlesystemdefinition.cpp
    /*static const char sParticleFuncTypes[48][SMALL_LINE_LENGTH] =
    {
        "DmeParticleSystemDefinition", "DmElement", "DmeParticleChild", "DmeParticleOperator", "particleSystemDefinitions",
        "preventNameBasedLookup", "particleSystemDefinitionDict", "snapshot", "untitled", "child", "drag", "delay", "name",
        "renderers", "operators", "initializers", "emitters", "children", "force", "constraints", "body", "duration", "DEBRIES",
        "color", "render", "radius", "lifetime", "type", "emit", "distance", "rotation", "speed", "fadeout", "DEBRIS", "size",
        "material", "function", "tint", "max", "min", "gravity", "scale", "rate", "time", "fade", "length", "definition", "thickness"
    };*/

    
do /// Reads a single binary char
    
{
        
hFile.Seek(2SEEK_CUR);
        
hFile.ReadInt8(iChar);
    } 
    while(
iChar == 0);

    
// Shift the cursor a bit
    
hFile.Seek(1SEEK_CUR);

    do 
/// Reads a single binary char
    
{
        
hFile.Seek(2SEEK_CUR);
        
hFile.ReadInt8(iChar);
    } 
    while(
iChar != 0);

    
// Loop throught the binary
    
while(!hFile.EndOfFile())
    {
        
// Reads a UTF8 or ANSI string from a file
        
hFile.ReadString(sPathsizeof(sPath));

        
// Validate string
        
if(!IsByteString(sPath)) 
        {
            
// Finds the first occurrence of a character in a string
            
int iFormat FindCharInString(sPath'.'true);

            
// Validate format
            
if(iFormat != -1)
            {
                
// Validate material format
                
if(!strcmp(sPath[iFormat], ".vmt"false))
                {
                    
// Format full path to file
                    
Format(sPathsizeof(sPath), "materials\\%s"sPath);
                    
                    
// Precache model textures
                    
ModelsPrecacheTextures(sPath);
                }
            }
            
/*else
            {
                // Initialize variable
                bool bLookup;
                
                // i = type index
                for(int i = 0; i < sizeof(sParticleFuncTypes); i++)
                {
                    // Validate the common structure types
                    if(StrContains(sPath, sParticleFuncTypes[i], false) != -1)
                    {
                        bLookup = true; /// If was found, then stop
                        break;
                    }
                }
                
                // Validate search
                if(!bLookup)
                {
                    // Precache particle
                    fnPrecacheParticleEffect(sPath);
                }
            }*/
        
}
    }

    
// Close file
    
delete hFile;
    return 
true;
}

/**
 * Reads the current material and precache its textures.
 *
 * @param sPath             The texture path.
 * @param bDecal            (Optional) If true, the texture will be precached like a decal.
 * @return                  True if was precached, false otherwise.
 **/
stock bool ModelsPrecacheTextures(const char[] sPath)
{
    
// Extract value string
    
static char sTexture[PLATFORM_MAX_PATH];
    
StrExtract(sTexturesPath0PLATFORM_MAX_PATH);

    
// If doesn't exist stop
    
if(!FileExists(sTexture))
    {
        
///LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Models, "Config Validation", "Invalid material path. File not found: \"%s\"", sPath);
        
return false;
    }

    
// Add file to download table
    
AddFileToDownloadsTable(sTexture);
    
    
// Initialize some variables
    
static const char sTypes[4][SMALL_LINE_LENGTH] = { "$baseTexture""$bumpmap""$lightwarptexture""$REFRACTTINTtexture}; bool bFound[sizeof(sTypes)]; static int iShiftint iSize sizeof(sTypes);
    
    
// Open the file
    
File hFile OpenFile(sTexture"rt");
    
    
// If doesn't exist stop
    
if(hFile == INVALID_HANDLE)
    {
        
LogEvent(falseLogType_FatalLOG_CORE_EVENTSLogModule_Models"Config Validation""Error opening file: \"%s\""sTexture);
    }
    
    
// Search textures lines in the file and precache it
    
while(hFile.ReadLine(sTexturesizeof(sTexture)))
    {
        
// Cut out comments at the end of a line
        
if(StrContains(sTexture"//") != -1)
        {
            
SplitString(sTexture"//"sTexturesizeof(sTexture));
        }
        
        
// i = texture type
        
for(int x 0iSizex++)
        {
            
// Avoid the reoccurrence 
            
if(bFound[x]) 
            {
                continue;
            }
            
            
// Validate type
            
if((iShift StrContains(sTexturesTypes[x], false)) != -1)
            {
                
// Shift the type away
                
iShift += strlen(sTypes[x]) + 1;
        
                
// Gets quotes at the beginning and at the end
                
int iQuote1 FindCharInString(sTexture[iShift], '"'true);
                
int iQuote2 FindCharInString(sTexture[iShift], '"'false);
                
                
// Check if string without quote, then stop
                
if(iQuote1 == -|| iQuote2 == -|| iQuote1 == iQuote2)
                {
                    
LogEvent(falseLogType_FatalLOG_CORE_EVENTSLogModule_Models"Config Validation""Error with parsing \"%s\" in file: \"%s\""sTypes[x], sPath);
                }
                else
                {
                    
// Sets on the success
                    
bFound[x] = true;
                    
                    
// Extract value string
                    
StrExtract(sTexturesTexture[iShift], iQuote2 1iQuote1);
                    
                    
// Format full path to file
                    
Format(sTexturesizeof(sTexture), "materials\\%s.vtf"sTexture);
                    
                    
// Validate size
                    
if(!strlen(sTexture))
                    {
                        continue;
                    }
                    
                    
// Validate material
                    
if(FileExists(sTexture))
                    {
                        
// Add file to download table
                        
AddFileToDownloadsTable(sTexture);
                    }
                    else
                    {
                        
LogEvent(falseLogType_FatalLOG_CORE_EVENTSLogModule_Models"Config Validation""Invalid texture path. File not found: \"%s\""sTexture);
                    }
                }
            }
        }
    }

    
// Close file
    
delete hFile
    return 
true;
}

/**
 * Validates the specified standart models.
 *
 * @param sModel            The model path for validation.
 * @return                  The model index if was precached, 0 otherwise.
 **/
stock int ModelsPrecacheStandart(const char[] sModel)
{
    
// Validate path
    
if(!strncmp(sModel"models/player/"14true))
    {
        
// If path contains standart path
        
if(!strncmp(sModel[14], "custom_player/legacy/"21true))
        {
            
// If path contains standart path
            
if(!strncmp(sModel[35], "ctm_"4true) || !strncmp(sModel[35], "tm_"3true))
            {
                
// Precache model
                
return PrecacheModel(sModeltrue);
            }
        }
        else
        {
            
// If path contains standart path
            
if(!strncmp(sModel[14], "ctm_"4true) || !strncmp(sModel[14], "tm_"3true))
            {
                
// Precache model
                
return PrecacheModel(sModeltrue);
            }
        }
    }
    else if(!
strncmp(sModel"models/weapons/"15true))
    {
        
// If path contains standart path
        
if(!strncmp(sModel[15], "ct_arms_"8true) || !strncmp(sModel[15], "t_arms_"7true))
        {
            
// Precache model
            
return PrecacheModel(sModeltrue);
        }
    }

    
// Model didn't exist, then stop
    
LogEvent(falseLogType_FatalLOG_CORE_EVENTSLogModule_Models"Config Validation""Invalid model path. File not found: \"%s\""sModel);
    return 
0;

Effeciency per model in avg
Quote:
TIME 0.001301

Last edited by gubka; 08-11-2018 at 14:20.
gubka is offline
Send a message via ICQ to gubka
milutinke
AlliedModders Donor
Join Date: Jun 2012
Location: Serbia
Old 08-07-2018 , 06:46   Re: [CS:GO] Precache from mdl & pcf & vmt
Reply With Quote #2

Nice.
Thank you for sharing, it will be useful to me
milutinke is offline
Send a message via Skype™ to milutinke
SHUFEN
Senior Member
Join Date: Jun 2014
Location: Japan, Tokyo
Old 08-07-2018 , 07:57   Re: [CS:GO] Precache from mdl & pcf & vmt
Reply With Quote #3

What is difference between ModelsPrecacheParticle and PrecacheGeneric? As capability.
PrecacheGeneric is famous way for all times and there is no problem for CS:GO.
I don't understand why you extract textures path from pcf with decoding binary.
And reason of why re writing to ParticleEffectNames. Effect names are registered automatically when PrecacheGeneric.
SHUFEN is offline
Send a message via Skype™ to SHUFEN
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 08-11-2018 , 14:20   Re: [CS:GO] Precache from mdl & pcf & vmt
Reply With Quote #4

Quote:
Originally Posted by SHUFEN.jp View Post
What is difference between ModelsPrecacheParticle and PrecacheGeneric? As capability.
PrecacheGeneric is famous way for all times and there is no problem for CS:GO.
I don't understand why you extract textures path from pcf with decoding binary.
And reason of why re writing to ParticleEffectNames. Effect names are registered automatically when PrecacheGeneric.
Ok thanks, i wont extract names
__________________
gubka is offline
Send a message via ICQ to gubka
kossolax
AlliedModders Donor
Join Date: Jan 2008
Location: Belgium
Old 05-30-2019 , 07:33   Re: [CS:GO] Precache from mdl & pcf & vmt
Reply With Quote #5

Hello gubka,

Can you please provide "StrExtract" and "IsByteString" ?

EDIT: Updated code is here: https://github.com/qubka/Zombie-Plag.../decryptor.cpp

Many thanks.

Last edited by kossolax; 05-30-2019 at 12:20.
kossolax is offline
Reply


Thread Tools
Display Modes

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 06:07.


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