Example #1
0
/*
 *  Check if the file is the one we're looking for
 */
bool CThePlugin::CheckFile(modloader::ModLoaderFile& file)
{
    if(!file.is_dir)
    {
        if(IsFileExtension(file.filext, "asi"))
        {
            // Don't load CLEO neither modloader!
            if(!strcmp(file.filename, "cleo.asi", false) || !strcmp(file.filename, "modloader.asi", false))
            {
                Log("Warning: Forbidden ASI file found \"%s\"", GetFilePath(file).c_str());
                return false;
            }
        }
        else if(strcmp(file.filename, "d3d9.dll", false) != 0)
            return false;
        
        // Check out if the file is incompatible
        std::string filename = file.filename;
        auto it = incompatible.find(modloader::tolower(filename));
        if(it != incompatible.end())
        {
            auto size = modloader::GetFileSize(file.filepath);
            if(size == it->second)
            {
                Error("Incompatible ASI file found: %s\nPlease install it at the game root directory.\nSkipping it!",
                      file.filename);
                return false;
            }
        }
        return true;
    }
    return false;
}
Example #2
0
/*
 *  Check if the file is the one we're looking for
 */
bool CThePlugin::CheckFile(modloader::ModLoaderFile& file)
{
    /* Check if handlable extension */
    for(const char** p = GetExtensionTable(); *p; ++p)
    {
        if(IsFileExtension(file.filext, *p))
            return true;
    }
    
    // Not found any extension compatible? If .txt (probably the readme), push it into the list of readmes for later procesing
    if(IsFileExtension(file.filext, "txt"))
    {
        file.call_me = true;
    }
    
    return false;
}
Example #3
0
int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib example - obj viewer");

    // Define the camera to look into our 3d world
    Camera camera = { { 30.0f, 30.0f, 30.0f }, { 0.0f, 10.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };

    Model model = LoadModel("resources/models/turret.obj");                     // Load default model obj
    Texture2D texture = LoadTexture("resources/models/turret_diffuse.png");     // Load default model texture
    model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Bind texture to model

    Vector3 position = { 0.0, 0.0, 0.0 };                   // Set model position
    BoundingBox bounds = MeshBoundingBox(model.meshes[0]);  // Set model bounds
    bool selected = false;                                  // Selected object flag

    SetCameraMode(camera, CAMERA_FREE);     // Set a free camera mode

    char objFilename[64] = "turret.obj";

    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        if (IsFileDropped())
        {
            int count = 0;
            char **droppedFiles = GetDroppedFiles(&count);

            if (count == 1)
            {
                if (IsFileExtension(droppedFiles[0], ".obj"))
                {
                    for (int i = 0; i < model.meshCount; i++) UnloadMesh(&model.meshes[i]);
                    model.meshes = LoadMeshes(droppedFiles[0], &model.meshCount);
                    bounds = MeshBoundingBox(model.meshes[0]);
                }
                else if (IsFileExtension(droppedFiles[0], ".png"))
                {
                    UnloadTexture(texture);
                    texture = LoadTexture(droppedFiles[0]);
                    model.materials[0].maps[MAP_DIFFUSE].texture = texture;
                }

                strcpy(objFilename, GetFileName(droppedFiles[0]));
            }

            ClearDroppedFiles();    // Clear internal buffers
        }

        UpdateCamera(&camera);

        // Select model on mouse click
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
        {
            // Check collision between ray and box
            if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) selected = !selected;
            else selected = false;
        }
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            BeginMode3D(camera);

                DrawModel(model, position, 1.0f, WHITE);   // Draw 3d model with texture

                DrawGrid(20.0, 10.0);        // Draw a grid

                if (selected) DrawBoundingBox(bounds, GREEN);

            EndMode3D();

            DrawText("Free camera default controls:", 10, 20, 10, DARKGRAY);
            DrawText("- Mouse Wheel to Zoom in-out", 20, 40, 10, GRAY);
            DrawText("- Mouse Wheel Pressed to Pan", 20, 60, 10, GRAY);
            DrawText("- Alt + Mouse Wheel Pressed to Rotate", 20, 80, 10, GRAY);
            DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 20, 100, 10, GRAY);

            DrawText("Drag & drop .obj/.png to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
            DrawText(FormatText("Current file: %s", objFilename), 250, GetScreenHeight() - 20, 10, GRAY);
            if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);

            DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadModel(model);         // Unload model

    ClearDroppedFiles();        // Clear internal buffers

    CloseWindow();              // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
Example #4
0
//----------------------------------------------------------------------------------
// Main entry point
//----------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
	// Initialization
	//---------------------------------------------------------
#if defined(PLATFORM_DESKTOP)
    // TODO: Support for dropped files on the exe
    
    // Support command line argument for custom music file
    if (argc > 1)
    {
        // Just supporting an input argument parameter!!! o__O
        
        if ((IsFileExtension(argv[1], ".ogg")) ||
            (IsFileExtension(argv[1], ".wav")))
        {
            if (sampleFilename != NULL) free(sampleFilename);
            
            sampleFilename = (char *)malloc(256);
            strcpy(sampleFilename, argv[1]);
            
            printf("Custom audio file: %s", sampleFilename);
        }
    }
#endif

#ifndef PLATFORM_ANDROID
    SetConfigFlags(FLAG_MSAA_4X_HINT);
#endif
    // Note windowTitle is unused on Android
    InitWindow(screenWidth, screenHeight, "GGJ17 - WAVE COLLECTOR");

    // Global data loading (assets that must be available in all screens, i.e. fonts)
    InitAudioDevice();

    font = LoadFont("resources/font.fnt");
    music = LoadMusicStream("resources/audio/wave.ogg");
    
    SetMusicVolume(music, 1.0f);

    // Setup and Init first screen
    currentScreen = LOGO;
    InitLogoScreen();
    //InitTitleScreen();
    //InitGameplayScreen();
    //InitEndingScreen();

#if defined(PLATFORM_WEB)
    emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else
    SetTargetFPS(60);   // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        UpdateDrawFrame();
    }
#endif

    // De-Initialization
    //--------------------------------------------------------------------------------------
    switch (currentScreen)
    {
        case LOGO: UnloadLogoScreen(); break;
        case TITLE: UnloadTitleScreen(); break;
        case GAMEPLAY: UnloadGameplayScreen(); break;
        case ENDING: UnloadEndingScreen(); break;
        default: break;
    }
    
    // Unload all global loaded data (i.e. fonts) here!
    UnloadFont(font);
    UnloadMusicStream(music);

    CloseAudioDevice();     // Close audio context
    
    CloseWindow();          // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
Example #5
0
/*
 * Process the replacement
 */
bool CThePlugin::ProcessFile(const modloader::ModLoaderFile& file)
{
    const char* filename = file.filename;
    
    if(IsFileExtension(file.filext, "txt"))
    {
        // Put in the front of the container, so the modloader overriding rule applies
        readme.emplace_front(GetFilePath(file));
    }
    if(IsFileExtension(file.filext, "dat"))
    {
        std::string filepath_buffer = GetFilePath(file);
        const char* filepath = filepath_buffer.c_str();

        if(!strcmp(filename, "gta.dat", false))
            traits.gta.AddFile(file, "data/gta.dat");
        else if(!strcmp(filename, "default.dat", false))
            traits.gta.AddFile(file, "data/default.dat");
        else if(!strcmp(filename, "carmods.dat", false))
            traits.carmods.AddFile(file, "data/carmods.dat");
        else if(!strcmp(filename, "timecyc.dat", false))
            RegisterReplacementFile(*this, "timecyc.dat", traits.timecyc, filepath);
        else if(!strcmp(filename, "popcycle.dat", false))
            RegisterReplacementFile(*this, "popcycle.dat", traits.popcycle, filepath);
        else if(!strcmp(filename, "fonts.dat", false))
            RegisterReplacementFile(*this, "fonts.dat", traits.fonts, filepath);
        else if(!strcmp(filename, "plants.dat", false))
            traits.plants.AddFile(file, "data/plants.dat");
        else if(!strcmp(filename, "water.dat", false))
            traits.water.AddFile(file, "data/water.dat");
        else if(!strcmp(filename, "roadblox.dat", false))
            RegisterReplacementFile(*this, "roadblox.dat", traits.roadblox, filepath);
        else if(!strcmp(filename, "tracks.dat", false))
            RegisterReplacementFile(*this, "tracks.dat", traits.tracks[0], filepath);
        else if(!strcmp(filename, "tracks2.dat", false))
            RegisterReplacementFile(*this, "tracks2.dat", traits.tracks[1], filepath);
        else if(!strcmp(filename, "tracks3.dat", false))
            RegisterReplacementFile(*this, "tracks3.dat", traits.tracks[2], filepath);
        else if(!strcmp(filename, "tracks4.dat", false))
            RegisterReplacementFile(*this, "tracks4.dat", traits.tracks[3], filepath);
        else
            return false;

        return true;
    }
    else if(IsFileExtension(file.filext, "cfg"))
    {
        if(!strcmp(filename, "handling.cfg", false))
        {
            traits.handling.AddFile(file, "data/handling.cfg");
            return true;
        }
    }
    else if(IsFileExtension(file.filext, "ide"))
    {
        const char* fsPath = nullptr;
        std::string fsPathAux;
        
        // In case of any of the basics ide file, let the user put it outside data folder
        // and it will be still detected as it should
        if(!strcmp(file.filename, "vehicles.ide", false)
        || !strcmp(file.filename, "default.ide", false)
        || !strcmp(file.filename, "peds.ide", false))
        {
            if(!IsFileInsideFolder(file.filepath, false, "data"))
            {
                fsPath = fsPathAux.assign("data/").append(file.filename).c_str();
            }
        }
        
        //
        traits.ide.AddFile(file);
        return true;
    }
    else if(IsFileExtension(file.filext, "ipl") || IsFileExtension(file.filext, "zon"))
    {
        traits.ipl.AddFile(file);
        return true;
    }
    return false;
}