void ImageLoader::RegisterExtraGfx(const std::string& folderName, const std::string& name)
{
    if (name.length() == 0) return;

    std::wstring wFolderName = Str2WStr(folderName);
    std::wstring wName = Str2WStr(name);
    std::vector<std::wstring> searchPath;
    if (!gIsOverworld)
        searchPath.push_back(normalizePathSlashes(getCustomFolderPath())); // Check custom folder
    searchPath.push_back(normalizePathSlashes(GM_FULLDIR)); // Check episode dir
    searchPath.push_back(normalizePathSlashes(GM_FULLDIR) + L"/graphics/" + wFolderName); // Check episode dir
    searchPath.push_back(normalizePathSlashes(gAppPathWCHAR) + L"/graphics/" + wFolderName); // Check base game

    std::shared_ptr<LunaImage> img = nullptr;
    for (auto pathIt = searchPath.cbegin(); pathIt != searchPath.cend(); pathIt++)
    {
        std::wstring imgPath = *pathIt + L"/" + wName + L".png";
        img = LunaImage::fromFile(imgPath.c_str());
        if (img)
        {
            break;
        }
    }
    
    // Add to map, even if null
    m_ExtraGfx[name] = img;
}
Example #2
0
void LuaProxy::playSFX(const std::string& filename)
{
#ifndef NO_SDL
	playSFXSDL(filename);
#else
	wstring full_path;
	if(!isAbsolutePath(filename)){
		full_path = getCustomFolderPath() + utf8_decode(filename);
	}else{
		full_path = utf8_decode(filename);
	}
	
	PlaySound(full_path.c_str(), 0, SND_FILENAME | SND_ASYNC);
#endif
}
std::shared_ptr<BMPBox> LuaProxy::Graphics::loadMedia(const std::string& filename) {
	std::wstring full_path;

	if (!isAbsolutePath(filename)) {
		full_path = getCustomFolderPath() + Str2WStr(filename);
	}
	else
	{
		full_path = Str2WStr(filename);
	}

	std::shared_ptr<BMPBox> img = std::make_shared<BMPBox>(full_path, gLunaRender.GetScreenDC());

	if (img->ImageLoaded() == false) {
		// If image loading failed, return null
		return NULL;
	}
	return img;
}
Example #4
0
luabind::object luabindResolveFile(std::string file, lua_State* L){
    std::vector<std::string> paths = {
        WStr2Str(getCustomFolderPath()),
        (std::string)GM_FULLDIR,
        WStr2Str(getModulePath()) + "\\LuaScriptsLib\\",
        WStr2Str(getModulePath()) + "\\"
    };



    for (std::string nextSearchPath : paths) {
        std::string nextEntry = nextSearchPath + file;
        DWORD objectAttributes = GetFileAttributesA(nextEntry.c_str());
        if(objectAttributes == INVALID_FILE_ATTRIBUTES)
            continue;
        if(objectAttributes & FILTER)
            return luabind::object(L, nextEntry);
    }

    return luabind::object();
}
void ImageLoader::Run(bool initialLoad)
{

    static std::unordered_map<std::wstring, ResourceFileInfo>* lastResources = nullptr;
    std::unordered_map<std::wstring, ResourceFileInfo>* foundResources = nullptr;
    foundResources = new std::unordered_map<std::wstring, ResourceFileInfo>();

    // Time to start figuring out our paths...

    std::wstring episodePath = normalizePathSlashes(GM_FULLDIR);
    std::wstring appPath = normalizePathSlashes(gAppPathWCHAR);
    std::wstring episodeGfxDir = L"";
    std::wstring appGfxDir = appPath + L"/graphics";
    std::wstring levelGfxDir = L"";

    // If we're not actually in an episode, make don't have an episode path
    if (appPath == episodePath)
    {
        episodePath = L"";
    }

    // Check if we have a graphics subdirectory in the episode
    if (episodePath.length() > 0)
    {
        std::wstring testSubdir = episodePath + L"/graphics";
        if (checkDirectoryExistance(testSubdir))
        {
            episodeGfxDir = testSubdir;
        }
    }

    // If not in the overworld, we have a level path, right?
    if (!gIsOverworld)
    {
        levelGfxDir = normalizePathSlashes(getCustomFolderPath());
    }
    
    // Done figuring out our paths!

    // Read level directory listing
    std::unordered_map<std::wstring, ResourceFileInfo> levelFiles;
    if (levelGfxDir.length() > 0)
    {
        ListResourceFilesFromDir(levelGfxDir.c_str(), levelFiles);
    }

    // Read episode directory listing
    std::unordered_map<std::wstring, ResourceFileInfo> episodeFiles;
    if (episodePath.length() > 0)
    {
        ListResourceFilesFromDir(episodePath.c_str(), episodeFiles);
    }

    // Resolve correct resource file info for each category
    for (int i = 0; smbxImageLoaderCategories[i] != nullptr; i++)
    {
        smbxImageLoaderCategories[i]->resolveResources(
            appGfxDir, episodeGfxDir, levelFiles, episodeFiles, *foundResources
            );
    }

    // Load each normal category's GFX
    for (int i = 0; smbxImageLoaderCategories[i] != nullptr; i++)
    {
        smbxImageLoaderCategories[i]->updateLoadedImages(foundResources, lastResources);
    }

    // Read 'hardcoded' GFX
    static bool loadedHardcoded = false; // TODO: Won't need this odd 'loadedHardcoded' shenanigans when the initial run of ImageLoader::Run is moved to after GM_FORM_GFX is initialized
    if (GM_FORM_GFX != nullptr)
    {
        ResolveHardcodedGfx(appGfxDir, episodeGfxDir, levelFiles, episodeFiles, *foundResources);
        LoadHardcodedGfx(foundResources, loadedHardcoded ? lastResources : nullptr);
        loadedHardcoded = true;
    }

    if (initialLoad)
    {
        for (int i = 0; i < smbxImageCategoryBackground.getArrayLength(); i++)
        {
            GM_GFX_BACKGROUND_W_UNK_PTR[i] = GM_GFX_BACKGROUND_W_PTR[i];
            GM_GFX_BACKGROUND_H_UNK_PTR[i] = GM_GFX_BACKGROUND_H_PTR[i];
        }
    }

    for (int i = 0; i < smbxImageCategoryBlock.getArrayLength(); i++)
    {
        GM_GFX_BLOCKS_NO_MASK[i] = (smbxImageCategoryBlock.getMaskPtr(i + smbxImageCategoryBlock.getFirstIdx()) == nullptr) ? -1 : 0;
    }

    delete lastResources;
    lastResources = foundResources;
}
Example #6
0
luabind::object LuaProxy::Misc::listLocalFiles(std::string path, lua_State* L)
{
    return listFiles(WStr2Str(getCustomFolderPath()) + path, L);
}
Example #7
0
// *EXPORT* On Level Load -- Run once as a level is loaded (including title screen level)
int OnLvlLoad() {

	// Restore some code the hook overwrote
	*(DWORD*)0x00B25958 = 0;
    
    ResetLunaModule();

    // WIP
    // dumpTypeLibrary((IDispatch*)*(DWORD*)0xB2D7E8, std::wcout);

    
    std::string custPath = WStr2Str(getCustomFolderPath());
    std::string wldPath = WStr2Str(GM_FULLDIR);
    std::string SndRoot = MusicManager::SndRoot();
    replaceSubStr(wldPath, "\"", "");
    replaceSubStr(wldPath, "\\\\", "\\");
    replaceSubStr(wldPath, "/", "\\");

    replaceSubStr(SndRoot, "\"", "");
    replaceSubStr(SndRoot, "\\\\", "\\");
    replaceSubStr(SndRoot, "/", "\\");

    bool doSoundLoading = false;

    if ((!custPath.empty()) && (file_existsX(custPath + "\\sounds.ini"))) {
        //If custom-level specific sounds.ini detected
        doSoundLoading = true;
        LevelCustomSounds = true;
    }
    else if (LevelCustomSounds) {
        //If custom-level specific sounds.ini was NOT detected, but was loaded recently - reload episode specific sounds
        doSoundLoading = true;
        LevelCustomSounds = false;
    }

    if (!episodeStarted) {
        //Load custom sounds if episode is not finally started
        if (wldPath != SndRoot) doSoundLoading = true;
    }

    if (doSoundLoading) MusicManager::loadCustomSounds(wldPath + "\\", custPath);
//	BMPBox::initMovieCache();
	if(gLunaEnabled) {
		// Load autocode
		gAutoMan.Clear(false);		
		gAutoMan.ReadFile((std::wstring)GM_FULLDIR);

		// Try to load world codes		
		gAutoMan.ReadWorld((std::wstring)GM_FULLDIR);

		// Init var bank
		gSavedVarBank.TryLoadWorldVars();
		gSavedVarBank.CheckSaveDeletion();
		gSavedVarBank.CopyBank(&gAutoMan.m_UserVars);

        //  Don't try to call the CLunaLua constructor... It's already
        //  constructed automatically once, and trying to do this will call
        //  the constructor extra times *without* ever calling the destructor,
        //  which can result in a memory leak of the whole Lua state!
		//    gLunaLua = CLunaLua();
		gLunaLua.init(CLunaLua::LUNALUA_LEVEL, (std::wstring)GM_FULLDIR, Level::GetName());
        gLunaLua.setReady(true);

		// Do some stuff
		gAutoMan.DoEvents(true); // do with init

		// Init some stuff
		InitLevel();	
		gAutoMan.m_Hearts = 2;	

		// Recount deaths
		gDeathCounter.Recount();
	}

    //PGE DBG STUFF
    //readAndWriteNPCSettings();
    //overwriteFunc();

	return 0;
}