def test_R6_MAP_Materials(self):
        """Tests reading materials from an R6 MAP file"""
        settings = load_settings(TEST_SETTINGS_FILE)

        map_filepath = path.join(settings["gamePath_R6_EW"], "data", "map", "m02", "mansion.map")

        loadedFile = MAPLevelReader.MAPLevelFile()
        loadedFile.read_file(map_filepath)

        #TODO: This is currently disabled as this file has an unread part at the end, but the rest of this test is meaninful
        #self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")
        #self.check_section_strings(loadedFile)

        self.assertEqual(loadedFile.materialListHeader.numMaterials, 137, "Unexpected number of materials")

        firstMaterial = loadedFile.materials[0]
        self.assertEqual(firstMaterial.get_material_game_version(), RSEGameVersions.RAINBOW_SIX, "Wrong material format detected")
        self.assertEqual(firstMaterial.versionNumber, 1, "Wrong material version number")
        self.assertEqual(firstMaterial.material_name.string, "WI_plain5", "Wrong material name")
        self.assertEqual(firstMaterial.texture_name.string, "Wl_paper_congo_tan_leaves1.BMP", "Wrong texture name")

        self.assertAlmostEqual(firstMaterial.opacity, 1.0, 3, "Wrong opacity value")
        self.assertAlmostEqual(firstMaterial.emissiveStrength, 0.0, 3, "Wrong emissive strength value")
        self.assertEqual(firstMaterial.textureAddressMode, 3, "Wrong texture address mode value")
        self.assertEqual(firstMaterial.ambientColorUInt, [25, 25, 25], "Wrong ambient color")
        self.assertEqual(firstMaterial.diffuseColorUInt, [255, 255, 255], "Wrong diffuse color")
        self.assertEqual(firstMaterial.specularColorUInt, [229, 229, 229], "Wrong specular color")
        self.assertEqual(firstMaterial.normalizedColors, False, "Incorrectly determined whether colors are normalized in the file")
        self.assertAlmostEqual(firstMaterial.specularLevel, 0.0, 3, "Wrong specular value")
        self.assertEqual(firstMaterial.twoSided, False, "Wrong two sided material flag value")
    def test_R6_SOB_Structure(self):
        """Tests reading an R6 SOB file, specifically ak47.sob"""
        settings = load_settings(TEST_SETTINGS_FILE)

        sob_filepath = path.join(settings["gamePath_R6"], "data", "model",
                                 "ak47.sob")

        loadedFile = SOBModelReader.SOBModelFile()
        readSucessfullyToEOF = loadedFile.read_file(sob_filepath)

        self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")

        self.check_section_strings(loadedFile)

        self.assertEqual(loadedFile.materialListHeader.numMaterials, 7,
                         "Unexpected number of materials in header")

        self.assertEqual(len(loadedFile.materials), 7,
                         "Unexpected number of materials read")

        self.assertEqual(loadedFile.materials[0].material_name.string,
                         "aK barell", "Unexpected material name")

        self.assertEqual(loadedFile.materials[0].texture_name.string,
                         "AK47_BARREL_32.BMP", "Unexpected material name")

        self.assertEqual(len(loadedFile.geometryObjects), 1,
                         "Unexpected number of geometry objects")

        self.assertEqual(loadedFile.geometryObjects[0].name_string.string,
                         "AK47", "Unexpected object name")

        self.assertEqual(loadedFile.geometryObjects[0].vertexCount, 81,
                         "Unexpected number of vertices")
    def test_full_color_image(self):
        """Tests reading an image that does not contain a palette"""
        settings = load_settings(TEST_SETTINGS_FILE)

        RSB_filepath = path.join(settings["gamePath_R6_EW"], "data", "shell",
                                 "briefing", "Ac_a13.RSB")

        loadedFile = RSBImageReader.RSBImageFile()
        readSucessfullyToEOF = loadedFile.read_file(RSB_filepath)

        self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")

        self.assertEqual(loadedFile.header.width, 38, "Unexpected image width")

        self.assertEqual(loadedFile.header.height, 46,
                         "Unexpected image height")

        self.assertEqual(
            loadedFile.header.containsPalette, 0,
            "Detected palette in image that does not contain a palette")

        fullColorImage = loadedFile.convert_full_color_image()

        self.assertEqual(fullColorImage.width, loadedFile.header.width,
                         "Widths do not match on full color image")

        self.assertEqual(fullColorImage.height, loadedFile.header.height,
                         "Heights do not match on full color image")
    def test_R6_MAP_Structure(self):
        """Tests reading an R6 MAP file, specifically M01"""
        settings = load_settings(TEST_SETTINGS_FILE)

        map_filepath = path.join(settings["gamePath_R6_EW"], "data", "map", "m01", "M01.map")

        loadedFile = MAPLevelReader.MAPLevelFile()
        readSucessfullyToEOF = loadedFile.read_file(map_filepath)

        self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")

        self.check_section_strings(loadedFile)

        self.assertEqual(loadedFile.materialListHeader.numMaterials, 263, "Unexpected number of materials")

        self.assertEqual(loadedFile.geometryListHeader.count, 57, "Unexpected number of geometry objects")

        self.assertEqual(loadedFile.portalList.portalCount, 65, "Unexpected number of portals")

        self.assertEqual(loadedFile.lightList.lightCount, 162, "Unexpected number of lights")

        self.assertEqual(loadedFile.objectList.objectCount, 38, "Unexpected number of objects")

        self.assertEqual(loadedFile.roomList.roomCount, 47, "Unexpected number of rooms")

        self.assertEqual(loadedFile.planningLevelList.planningLevelCount, 4, "Unexpected number of planning levels")
Esempio n. 5
0
def main():
    """Main function that converts test data files"""
    settings = load_settings()

    fp = DirectoryProcessor.DirectoryProcessor()
    fp.paths.append(settings["gamePath"])
    fp.fileExt = ".SOB"

    fp.processFunction = convert_SOB

    fp.run(mode=settings["runMode"])
    def test_load_all_R6_SOBs(self):
        """Attempt to load and validate the sections of each map in the directory"""
        settings = load_settings(TEST_SETTINGS_FILE)

        discovered_files = gather_files_in_path(".SOB",
                                                settings["gamePath_R6_EW"])

        for sob_filepath in discovered_files:
            loadedFile = SOBModelReader.SOBModelFile()
            readSucessfullyToEOF = loadedFile.read_file(sob_filepath)

            self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")

            self.check_section_strings(loadedFile)
def main():
    """Main function that converts a test file"""
    settings = load_settings()

    fp = DirectoryProcessor.DirectoryProcessor()
    fp.paths.append(settings["gamePath"])
    fp.fileExt = ".MAP"

    fp.processFunction = convert_MAP

    fp.run(mode=settings["runMode"])

    log.info("Light Types: ")
    log.info(lightTypes)
    def test_random_colors_ARGB_4444(self):
        """ Tests both lookup and brute force methods with random colors in ARGB_4444 format """
        settings = load_settings(TEST_SETTINGS_FILE)

        for _ in range(settings["random_color_test_count"]):
            random_color = random.randint(0, 65535)
            random_color_4444_brute = ColorConversionUtilities.read_bitmask_ARGB_color(
                random_color, 4, 4, 4, 4)
            random_color_4444_lookup = ColorConversionUtilities.COLOR_LOOKUPS[
                ColorConversionUtilities.ColorFormats.
                CF_ARGB_4444][random_color]
            self.assertEqual(
                random_color_4444_brute, random_color_4444_lookup,
                "Lookup and brute force color conversion methods don't match with ARGB_4444 format"
            )
    def test_eagle_watch_detection(self):
        """Tests recognising Eagle Watch"""
        settings = load_settings(TEST_SETTINGS_FILE)

        eagleWatchGame = RSEGameLoader.RSEGameLoader()
        loadedGameSuccessfully = eagleWatchGame.load_game(
            settings["gamePath_R6_EW"])
        self.assertTrue(loadedGameSuccessfully,
                        "Failed to load game with Eagle Watch")
        self.assertEqual(eagleWatchGame.get_mod_list(), ["Eagle Watch"],
                         "Failed to detect eagle watch")

        normalGame = RSEGameLoader.RSEGameLoader()
        loadedGameSuccessfully = normalGame.load_game(settings["gamePath_R6"])
        self.assertTrue(loadedGameSuccessfully, "Failed to load original game")
        self.assertEqual(normalGame.get_mod_list(), [],
                         "Detected a mod where there shouldn't be one")
    def test_impossible_mip_map_generation(self):
        """Tests reading a non-power-of-2 image, and tries to generate mipmaps for it. This shouldn't be possible"""
        settings = load_settings(TEST_SETTINGS_FILE)

        RSB_filepath = path.join(settings["gamePath_R6_EW"], "data", "shell",
                                 "briefing", "Ac_a13.RSB")

        loadedFile = RSBImageReader.RSBImageFile()
        readSucessfullyToEOF = loadedFile.read_file(RSB_filepath)

        self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")

        fullColorImage = loadedFile.convert_full_color_image()

        mips = generate_mip_maps(fullColorImage)

        self.assertIsNone(mips,
                          "Did not return None, instead generated mip-maps")
    def test_mip_map_generation(self):
        """Tests reading an image and generating mip maps for it"""
        settings = load_settings(TEST_SETTINGS_FILE)

        RSB_filepath = path.join(settings["gamePath_R6_EW"], "data", "texture",
                                 "08_engine.RSB")

        loadedFile = RSBImageReader.RSBImageFile()
        readSucessfullyToEOF = loadedFile.read_file(RSB_filepath)

        self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")

        fullColorImage = loadedFile.convert_full_color_image()

        mips = generate_mip_maps(fullColorImage)

        self.assertEqual(len(mips), 8,
                         "Failed to generate correct number of mipmaps")
    def test_load_all_R6_maps(self):
        """Attempt to load and validate the sections of each map in the directory"""
        settings = load_settings(TEST_SETTINGS_FILE)

        discovered_files = gather_files_in_path(".MAP", settings["gamePath_R6_EW"])

        for map_filepath in discovered_files:
            if map_filepath.endswith("obstacletest.map") or map_filepath.endswith("mansion.map") or map_filepath.endswith("m8.map") or map_filepath.endswith("m14.map"):
                #TODO: remove all of these maps, except obstacletest.map from this skip, once the last data structure is deciphered
                #I believe this is an early test map that was shipped by accident.
                # It's data structures are not consistent with the rest of the map files
                # and it is not used anywhere so it is safe to skip
                continue

            loadedFile = MAPLevelReader.MAPLevelFile()
            readSucessfullyToEOF = loadedFile.read_file(map_filepath)

            self.assertTrue(readSucessfullyToEOF, f'Failed to read whole file: {map_filepath}')

            self.check_section_strings(loadedFile)
    def test_game_detection(self):
        """Tests recognising Rainbow Six"""
        settings = load_settings(TEST_SETTINGS_FILE)

        invalidGame = RSEGameLoader.RSEGameLoader()
        loadedGameSuccessfully = invalidGame.load_game(
            "/ThisPathWillNEverWork/")
        self.assertFalse(loadedGameSuccessfully,
                         "Incorrectly reported that an invalid game loaded")

        normalGame = RSEGameLoader.RSEGameLoader()
        loadedGameSuccessfully = normalGame.load_game(settings["gamePath_R6"])
        self.assertTrue(loadedGameSuccessfully, "Failed to load original game")

        self.assertEqual(normalGame.game_name, "Rainbow Six",
                         "Didn't recognise game name")
        self.assertEqual(normalGame.game_version, RSEGameVersions.RAINBOW_SIX,
                         "Didn't recognise game version")
        self.assertEqual(normalGame.engine_version, RSEEngineVersions.SHERMAN,
                         "Didn't recognise engine version")
Esempio n. 14
0
    def test_eagle_watch_cxp(self):
        """Tests reading the CXP file from eagle watch"""

        settings = load_settings(TEST_SETTINGS_FILE)

        CXPpath = path.join(settings["gamePath_R6_EW"], "data", "texture",
                            "Sherman.CXP")

        manuallyLoadedCXPDefs = CXPMaterialPropertiesReader.read_cxp(CXPpath)

        # 395 manually verified in TXT file
        self.assertEqual(len(manuallyLoadedCXPDefs), 395,
                         "Unexpected number of definitions in CXP File")

        CXPpath = path.join(settings["gamePath_R6_EW"], "data")

        autoLoadedCXPDefs = CXPMaterialPropertiesReader.load_relevant_cxps(
            CXPpath)
        self.assertEqual(
            len(autoLoadedCXPDefs), 395,
            "Unexpected number of definitions in Auto loaded CXP File")
    def test_palette_image(self):
        """Tests reading an image that contains a palette"""
        settings = load_settings(TEST_SETTINGS_FILE)

        RSB_filepath = path.join(settings["gamePath_R6_EW"], "data", "texture",
                                 "08_engine.RSB")

        loadedFile = RSBImageReader.RSBImageFile()
        readSucessfullyToEOF = loadedFile.read_file(RSB_filepath)

        self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")

        self.assertEqual(loadedFile.header.width, 128,
                         "Unexpected image width")

        self.assertEqual(loadedFile.header.height, 128,
                         "Unexpected image height")

        self.assertEqual(
            loadedFile.header.containsPalette, 1,
            "Did not detect palette in image which contains a palette")

        paletteImage = loadedFile.convert_palette_image()

        self.assertEqual(paletteImage.width, loadedFile.header.width,
                         "Widths do not match on palette image")

        self.assertEqual(paletteImage.height, loadedFile.header.height,
                         "Heights do not match on palette image")

        fullColorImage = loadedFile.convert_full_color_image()

        self.assertEqual(fullColorImage.width, loadedFile.header.width,
                         "Widths do not match on full color image")

        self.assertEqual(fullColorImage.height, loadedFile.header.height,
                         "Heights do not match on full color image")
Esempio n. 16
0
"""A quick sample program to try loading games and listing missions"""

import logging

from RainbowFileReaders.RSEGameLoader import RSEGameLoader
from RainbowFileReaders.R6MissionReader import R6MissionFile
from FileUtilities.Settings import load_settings

log = logging.getLogger(__name__)

logging.basicConfig(level=logging.INFO)

if __name__ == "__main__":
    settings = load_settings()
    game = RSEGameLoader()
    game.load_game(settings["gamePath"])
    game.print_game_info()

    missions = game.get_mission_list()

    for _, missionPath in missions.items():
        mission = R6MissionFile()
        log.info("Loading: %s", missionPath)
        mission.load_mission(missionPath)

        log.info("Hardware far clip: %f", mission.render_hardware_far_clip)
        log.info("List of rooms with fog:")
        for fogroom in mission.fog_rooms:
            log.info("\t- %s", fogroom)