コード例 #1
0
ファイル: Global10.cpp プロジェクト: otoboku/ao
PWSTR
GetFileName(
            PWSTR   HookedPath,
            ULONG   HookedPathCount,
            PWSTR   OriginalPath,
            ULONG   OriginalCount,
            LPCSTR  InputFileName,
            BOOL    IsInputUnicode = FALSE
            )
{
    ULONG_PTR   Length, AppPathLength;
    PWSTR       FileName;

    static WCHAR szDataPath[]   = L"data\\";
    static WCHAR szPatch[]      = L"patch\\\\";
    static WCHAR szPatch2[]     = L"patch2\\";

    if (IsInputUnicode)
    {
        StrCopyW(OriginalPath, (PWSTR)InputFileName);
    }
    else
    {
        AnsiToUnicode(OriginalPath, OriginalCount, (PSTR)InputFileName, -1);
    }

    PLDR_MODULE Module;

    Module = FindLdrModuleByHandle(NULL);
    AppPathLength = (Module->FullDllName.Length - Module->BaseDllName.Length) / sizeof(WCHAR);

    Length = RtlGetFullPathName_U(OriginalPath, HookedPathCount * sizeof(WCHAR), HookedPath, NULL);
    Length = Length / sizeof(WCHAR) + 1;
    FileName = HookedPath + AppPathLength;
    LOOP_ONCE
    {
        if (StrNICompareW(FileName, szDataPath, countof(szDataPath) - 1) ||
            StrNICompareW(Module->FullDllName.Buffer, HookedPath, AppPathLength))
        {
            FileName = OriginalPath;
            break;
        }

        FileName += countof(szDataPath) - 2;
        RtlMoveMemory(
            FileName + countof(szPatch) - countof(szDataPath),
            FileName,
            (Length - (FileName - HookedPath)) * sizeof(*FileName)
            );

        FileName -= countof(szDataPath) - 2;
        CopyStruct(FileName, szPatch, sizeof(szPatch) - sizeof(*szPatch));

        WriteLog(L"pass1: %s", HookedPath);

        if (IsPathExists(HookedPath))
        {
            FileName = HookedPath;
            break;
        }

        CopyStruct(FileName, szPatch2, sizeof(szPatch2) - sizeof(*szPatch2));
        FileName = IsPathExists(HookedPath) ? HookedPath : OriginalPath;

        WriteLog(L"pass2: %s", HookedPath);
    }

    WriteLog(L"%d, %s -> %s", FileName == HookedPath, OriginalPath, HookedPath);

    return FileName;
}
コード例 #2
0
ファイル: ModelScript.cpp プロジェクト: Emiyasviel/Arianrhod
Long CModelScript::ParseTranslationFile(PCTChar pszScriptPath)
{
    PTChar pszTransPath;
    WChar  szBuffer[0x1000];
    PVoid  pvBuffer;
    WChar  ch;
    PWChar pText, pEnd, pBuffer;
    CFileDisk file;

    pszTransPath = (PTChar)szBuffer;
    lstrcpy(pszTransPath, pszScriptPath);
    GenerateTranslationFileName(pszTransPath);

    if (!file.Open(pszTransPath))
    {
        m_VecTextTranslation = m_VecTextOrigianl;
        m_VecCharNameTranslation = m_VecCharNameOriginal;
        return SCR_ERROR_SUCCESS;
    }

    pvBuffer = m_mem.Alloc(file.GetSize());
    if (pvBuffer == NULL)
        return SCR_ERROR_OUT_OF_MEMORY;

    if (!file.Read(pvBuffer))
    {
        m_mem.Free(pvBuffer);
        return SCR_ERROR_IO_FAILED_READ;
    }

    pText = (PWChar)pvBuffer;
    if (*pText != BOM_UTF16_LE)
    {
        m_mem.Free(pvBuffer);
        return SCR_ERROR_INVALID_ENCODING;
    }

    SizeT PhysicalLine;
    StringW CharName;
    SScriptText ScrText;

    m_VecCharNameTranslation.clear();
    m_VecTextTranslation.clear();

    PhysicalLine = 0;
    pEnd = (PWChar)((PByte)pvBuffer + file.GetSize());
    while (pText < pEnd)
    {
        SizeT LineSize = sizeof(szBuffer);

        pText = PeekLine(pText, pEnd, szBuffer, &LineSize);
        if (pText == NULL)
            break;

        ++PhysicalLine;
        LineSize /= sizeof(*szBuffer);
        if (!StrNICompareW(szBuffer, L"@Text=", 6))
        {
            SizeT  Index;
            PWChar pStart;

            pStart = szBuffer + 6;
            pBuffer = pStart;
            for (Index = 3; Index; --Index)
            {
                while (ch = *pBuffer++)
                {
                    if (ch == ',')
                        break;
                }

                if (ch == 0)
                    break;

                switch (Index)
                {
                    case 3:
                        ScrText.PhysicalLine = StringToInt32W(pStart);
                        break;

                    case 2:
                        ScrText.LogicalLine = StringToInt32W(pStart);
                        break;

                    case 1:
                        ScrText.CharNameIndex = StringToInt32W(pStart);
                        break;
                }

                pStart = pBuffer;
            }

            if (Index != 0)
                goto CLEAR_THEN_RETURN;

            ScrText.Text = pStart;
            m_VecTextTranslation.push_back(ScrText);
        }
        else if (!StrNICompareW(szBuffer, L"@Name=", 6))
        {
            PWChar pStart;

            pStart = szBuffer + 6;
            pBuffer = pStart;
            while (ch = *pBuffer++)
            {
                if (ch != ',')
                    continue;

                pBuffer[-1] = 0;
                CharName = pStart;
                m_VecCharNameTranslation.push_back(CharName);
                pStart = pBuffer;
            }

            if (pStart + 1 != pBuffer)
            {
                CharName = pStart;
                m_VecCharNameTranslation.push_back(CharName);
            }
        }
    }

    m_mem.Free(pvBuffer);
    if (m_VecTextTranslation.size() != m_VecTextOrigianl.size())
        return SCR_ERROR_INVALID_TRANSLATION_FILE;

    return SCR_ERROR_SUCCESS;

CLEAR_THEN_RETURN:
    m_VecCharNameTranslation.clear();
    m_VecTextTranslation.clear();

    return SCR_ERROR_INVALID_TRANSLATION_FILE;
}
コード例 #3
0
ファイル: EDZero.cpp プロジェクト: QuocHuy7a10/Arianrhod
PWCHAR
GetFileName(
    PWCHAR  pszHooked,
    ULONG   HookedBufferCount,
    PWCHAR  pszOriginal,
    ULONG   OriginalCount,
    LPCSTR  lpFileName,
    BOOL    IsInputUnicode = FALSE
)
{
    ULONG   Length, AppPathLength;
    PWCHAR  pszFileName;

    static WCHAR szDataPath[]   = L"data\\";
    static WCHAR szPatch[]      = L"patch\\\\\\";
    static WCHAR szDataSc[]     = L"data_sc\\";

    if (IsInputUnicode)
    {
        lstrcpyW(pszOriginal, (LPWSTR)lpFileName);
    }
    else
    {
        Nt_AnsiToUnicode(pszOriginal, OriginalCount, (PCHAR)lpFileName, -1);
    }

    Length = RtlGetFullPathName_U(pszOriginal, HookedBufferCount * sizeof(WCHAR), pszHooked, NULL);
    Length = Length / sizeof(WCHAR) + 1;
    AppPathLength = g_AppPathLength;
    pszFileName = pszHooked + AppPathLength;
    LOOP_ONCE
    {
        if (StrNICompareW(pszFileName, szDataPath, countof(szDataPath) - 1) ||
            StrNICompareW((PWCHAR)g_AppPathBuffer, pszHooked, AppPathLength))
        {
            pszFileName = pszOriginal;
            break;
        }

        pszFileName += countof(szDataPath) - 2;
        RtlMoveMemory(
            pszFileName + countof(szDataSc) - countof(szDataPath),
            pszFileName,
            (Length - (pszFileName - pszHooked)) * sizeof(*pszFileName)
        );

        pszFileName -= countof(szDataPath) - 2;
        CopyStruct(pszFileName, szPatch, sizeof(szPatch) - sizeof(*szPatch));
        if (Nt_IsPathExists(pszHooked))
        {
            pszFileName = pszHooked;
            break;
        }

        CopyStruct(pszFileName, szDataSc, sizeof(szDataSc) - sizeof(*szDataSc));
        if (!Nt_IsPathExists(pszHooked))
            pszFileName = pszOriginal;
        else
            pszFileName = pszHooked;
    }
/*
    AllocConsole();
    PrintConsoleW(L"%s\n", pszFileName);
    if (!StrICompareW(findextw(pszFileName), L".it3"))
        __asm nop;
*/
#if CONSOLE_DEBUG
    PrintConsoleW(L"%s\n", pszFileName);
#endif

    return pszFileName;
}