Пример #1
0
HWND WINAPI CreateWindowExCenterA(ULONG dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, ULONG dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
    HWND    Window;
    RECT    rcWordArea;
    ULONG   Length;
    PWSTR   pszClassName, pszWindowName;

    Length = StrLengthA(lpClassName) + 1;
    pszClassName = (PWSTR)AllocStack(Length * sizeof(WCHAR));
    AnsiToUnicode(pszClassName, Length, lpClassName, Length);

    Length = StrLengthA(lpWindowName) + 1;
    pszWindowName = (PWSTR)AllocStack(Length * sizeof(WCHAR));
    AnsiToUnicode(pszWindowName, Length, lpWindowName, Length);

    if (SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWordArea, 0))
    {
        X = ((rcWordArea.right - rcWordArea.left) - nWidth) / 2;
        Y = ((rcWordArea.bottom - rcWordArea.top) - nHeight) / 2;
    }

    Window = CreateWindowExW(dwExStyle, pszClassName, pszWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
    ChangeMainWindowProc(Window);

    return Window;
}
Пример #2
0
Int WINAPI MyMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
    ULONG CodePage, Length;
    PWCHAR pWText, pWCaption;

    Length = StrLengthA(lpText);
    pWText = (PWCHAR)AllocStack(Length * sizeof(*pWText));

    if (IsShiftJISString(lpText, -1))
        CodePage = CP_SHIFTJIS;
    else
        CodePage = CP_GB2312;

    MultiByteToWideChar(CodePage, 0, lpText, -1, pWText, Length);

    Length = StrLengthA(lpCaption);
    pWCaption = (PWCHAR)AllocStack(Length * sizeof(*pWCaption));

    if (IsShiftJISString(lpCaption, -1))
        CodePage = CP_SHIFTJIS;
    else
        CodePage = CP_GB2312;

    MultiByteToWideChar(CodePage, 0, lpCaption, -1, pWCaption, Length);

    return MessageBoxW(hWnd, pWText, pWCaption, uType);
}
Пример #3
0
const char* TiXmlComment::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
	TiXmlDocument* document = GetDocument();
	value = "";

	p = SkipWhiteSpace( p, encoding );

	if ( data )
	{
		data->Stamp( p, encoding );
		location = data->Cursor();
	}
	const char* startTag = "<!--";
	const char* endTag   = "-->";

	if ( !StringEqual( p, startTag, false, encoding ) )
	{
		document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding );
		return 0;
	}
	p += StrLengthA( startTag );

	// [ 1475201 ] TinyXML parses entities in comments
	// Oops - ReadText doesn't work, because we don't want to parse the entities.
	// p = ReadText( p, &value, false, endTag, false, encoding );
	//
	// from the XML spec:
	/*
	 [Definition: Comments may appear anywhere in a document outside other markup; in addition, 
	              they may appear within the document type declaration at places allowed by the grammar. 
				  They are not part of the document's character data; an XML processor MAY, but need not, 
				  make it possible for an application to retrieve the text of comments. For compatibility, 
				  the string "--" (double-hyphen) MUST NOT occur within comments.] Parameter entity 
				  references MUST NOT be recognized within comments.

				  An example of a comment:

				  <!-- declarations for <head> & <body> -->
	*/

    value = "";
	// Keep all the white space.
	while (	p && *p && !StringEqual( p, endTag, false, encoding ) )
	{
		value.append( p, 1 );
		++p;
	}
	if ( p && *p ) 
		p += StrLengthA( endTag );

	return p;
}
Пример #4
0
HWND WINAPI MyCreateWindowExA(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
    PWCHAR pszClass, pszWindow;
    ULONG Length, CP;

    Length = StrLengthA(lpClassName);
    pszClass = (PWCHAR)AllocStack(Length * 2);
    CP = CP_SHIFTJIS;
    MultiByteToWideChar(CP, 0, lpClassName, Length + 1, pszClass, Length * 2);

    Length = StrLengthA(lpWindowName);
    pszWindow = (PWCHAR)AllocStack(Length * 2);
    MultiByteToWideChar(CP, 0, lpWindowName, Length + 1, pszWindow, Length * 2);

    return CreateWindowExW(dwExStyle, pszClass, pszWindow, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
}
Пример #5
0
HANDLE WINAPI MyCreateFileA(LPSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
    WCHAR szFile[MAX_PATH];
    DWORD dwLength;

    dwLength = StrLengthA(lpFileName);
    dwLength = MYAPI(MultiByteToWideChar)(CP_ACP, 0, lpFileName, dwLength + 1, szFile, countof(szFile)) - 1;

    do if ((dwDesiredAccess & GENERIC_WRITE) == 0)
    {
        if (dwLength < 3 ||
            szFile[dwLength - 4] != '.' ||
            (CHAR_UPPER3W(*(PULONG64)(&szFile[dwLength - 3]))) != TAG3W('DAT'))
        {
            break;
        }

        if (MYAPI(GetFileAttributesW)(szFile) != -1)
            break;

        dwLength -= 4;
        *(PULONG64)(szFile + dwLength) = TAG4W('_sc.');
        *(PULONG64)(szFile + dwLength + 4) = TAG3W('dat');

    } while (0);

    return MYAPI(CreateFileW)(szFile, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
Пример #6
0
Int32 WINAPI MylstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
{
    Int32  ret, bOgg;
    UInt32 Length, tag;
    Char   szFileName[MAX_PATH];

    ret = StrICompareA(lpString1, lpString2);
    if (!ret)
        return ret;

    Length = StrLengthA(lpString2);
    if (Length < 4 && Length != StrLengthA(lpString1))
        return ret;

    bOgg = False;
    Length -= 3;
    switch ((*(PUInt32)&lpString2[Length] & 0xDFDFDF))
    {
        case TAG3('EPA'):
            tag = TAG3('uci');
            break;

        case TAG3('OGG'):
            bOgg = True;
            tag = TAG3('m4a');
            break;

        case TAG3('WAV'):
            tag = TAG3('ogg');
            break;

        default:
            return ret;
    }

    MYAPI(lstrcpyA)(szFileName, lpString2);
    *(PUInt32)&szFileName[Length] = tag;

    ret = StrICompareA(lpString1, szFileName);
    if (ret && bOgg)
    {
        *(PUInt32)&szFileName[Length] = TAG3('uca');
        ret = StrICompareA(lpString1, szFileName);
    }

    return ret;
}
Пример #7
0
BOOL WINAPI MySetWindowTextA(HWND hWnd, LPCSTR lpString)
{
    ULONG Length, CP;
    PWCHAR pszString;

    Length = StrLengthA(lpString);
    pszString = (PWCHAR)AllocStack(Length * sizeof(*pszString));
    CP = IsShiftJISString(lpString, Length) ? CP_SHIFTJIS : CP_GB2312;
//    CP = CP_SHIFTJIS;
    MultiByteToWideChar(CP, 0, lpString, Length + 1, pszString, Length * 2);

    return SetWindowTextW(hWnd, pszString);
}
Пример #8
0
LONG NTAPI ShowExitMessageBox(HWND hWnd, PCSTR Text, PCSTR Caption, UINT Type)
{
    ULONG_PTR   Length;
    PSTR        Buffer;

    Length = StrLengthA(Text) + 1;
    Buffer = (PSTR)AllocStack(Length + 3);

    *(PULONG)&Buffer[0] = TAG3('#5C');
    CopyMemory(Buffer + 3, Text, Length);

    return EDAO::GlobalGetEDAO()->AoMessageBox(Buffer) == TRUE ? IDYES : IDNO;
}
Пример #9
0
const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
	value = "";
	TiXmlDocument* document = GetDocument();

	if ( data )
	{
		data->Stamp( p, encoding );
		location = data->Cursor();
	}

	const char* const startTag = "<![CDATA[";
	const char* const endTag   = "]]>";

	if ( cdata || StringEqual( p, startTag, false, encoding ) )
	{
		cdata = true;

		if ( !StringEqual( p, startTag, false, encoding ) )
		{
			document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding );
			return 0;
		}
		p += StrLengthA( startTag );

		// Keep all the white space, ignore the encoding, etc.
		while (	   p && *p
				&& !StringEqual( p, endTag, false, encoding )
			  )
		{
			value += *p;
			++p;
		}

		TIXML_STRING dummy; 
		p = ReadText( p, &dummy, false, endTag, false, encoding );
		return p;
	}
	else
	{
		bool ignoreWhite = true;

		const char* end = "<";
		p = ReadText( p, &value, ignoreWhite, end, false, encoding );
		if ( p )
			return p-1;	// don't truncate the '<'
		return 0;
	}
}
Пример #10
0
HWND WINAPI HookCreateWindowExA(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
    RECT    rcWordArea;
    ULONG   Length;
    LPWSTR  ClassName, WindowName;
    HWND    hWnd;

    Length = StrLengthA(lpClassName) + 1;
    ClassName = (LPWSTR)AllocStack(Length * sizeof(WCHAR));
    AnsiToUnicode(ClassName, Length * sizeof(WCHAR), lpClassName, Length);

    Length = StrLengthA(lpWindowName) + 1;
    WindowName = (LPWSTR)AllocStack(Length * sizeof(WCHAR));
    AnsiToUnicode(WindowName, Length * sizeof(WCHAR), lpWindowName, Length);

    hWnd = CreateWindowExW(dwExStyle, ClassName, WindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
    if (hWnd == NULL)
        return hWnd;

    OrigWndProc = (WNDPROC)SetWindowLongPtrA(hWnd, GWLP_WNDPROC, (LONG_PTR)CMVS_MainWindowProc);
    DragAcceptFiles(hWnd, TRUE);

    return hWnd;
}
Пример #11
0
UInt32 CSharu::CrcString(PCChar pszString, UInt32 Length)
{
    if (Length == -1)
        Length = StrLengthA(pszString);

    UInt32 Crc;

    Crc = 0;
    for (UInt32 i = 0; i != Length; )
    {
        UInt32 c = *pszString++;
        ++i;
        Crc += c * ((i ^ 0xE7) & 0xFF);
    }

    return Crc;
}
Пример #12
0
PWSTR MByteToWChar(PCSTR AnsiString, ULONG_PTR Length)
{
    PWSTR Unicode;

    if (Length == -1)
        Length = StrLengthA(AnsiString);

    ++Length;

    Unicode = (PWSTR)AllocateMemoryP(Length * sizeof(WCHAR));
    if (Unicode == NULL)
        return NULL;

    RtlMultiByteToUnicodeN(Unicode, Length * sizeof(WCHAR), NULL, AnsiString, Length);

    return Unicode;
}
Пример #13
0
UInt32 GetStringSubIndex(PCChar pszString, Int32 Length, UInt32 MaxIndex)
{
    if (MaxIndex == 0)
        return 0;
    if (Length == -1)
        Length = StrLengthA(pszString);

    UInt32 hash = 0;

    for (UInt32 i = 0; i != Length; ++i)
    {
        UInt32 b = *(PByte)pszString++;
        hash += b * ((i + 1) & 0xFF);
    }

    return hash % MaxIndex;
}
Пример #14
0
	static size_t StrLength(const char* lpData)
	{
		return StrLengthA(lpData);
	}
Пример #15
0
LONG CED6AsDecompiler::DumpToFile(ED6_ACTION_SCRIPT_INFO *pAsInfo, LPWSTR pszAsFile, LPWSTR pszOutput)
{
    LONG        Status;
    CHAR        Buffer[0x400];
    CFileDisk   file;

    Status = CreateDefinition(pszAsFile, Buffer);
    AS_IF_FAIL_RETURN(Status);

    Status = ASDECL_ERROR_UNKNOWN;
    LOOP_ONCE
    {
        if (!file.Create(pszOutput))
            AS_BREAK(Status, ASDECL_ERROR_CREATE_FILE);

        _wsetlocale(LC_CTYPE, L"");
        WriteScr(
            "@_FILE \"debug_%S\"\n"
            "@_INCLUDE \"%s\"\n"
            "\n",
            findnamew(pszAsFile), NAME_DEFINITION_FILE);

        WriteScr(
            "@%s %d\n"
            "\n",
            NAME_HEADER_UNKNOWN,
            pAsInfo->Unknown);

        WriteScr(
            "(%s:s)\n"
            "(%s:s)\n"
            "(%s:s)\n"
            "\n",
            LABEL_CRAFT_OFFSET_TABLE,
            LABEL_CRAFT_OFFSET_TABLE_END,
            NAME_HEADER_UNKNOWN);

        WriteScr("; Char chip pattern info  CH_Index, CH_DAT_Index, CP_Index, CP_DAT_Index\n");

        CHAR_CHIP_PATTERN_INFO *pChipPtn = pAsInfo->pChrChipPtnInfo;
        for (ULONG Index = 0, Count = pAsInfo->ChrChipPtnCount; Count; ++Index, --Count)
        {
            WriteScr(
                " (0x%04X:s, 0x%04X:s, 0x%04X:s, 0x%04X:s)",
                pChipPtn->CHIndex,
                pChipPtn->CHDatIndex,
                pChipPtn->CPIndex,
                pChipPtn->CPDatIndex);
            ++pChipPtn;

            if (Index & 1)
                WriteScr("\n");
        }
        WriteScr("\n[FF FF FF FF]\n\n");

        WriteScr("; 3d model file\n");

        for (LPSTR pszX3FileName = pAsInfo->pszXFileName; ; )
        {
            LPSTR pString;
            ULONG Length;

            Length  = StrLengthA(pszX3FileName) + 1;
            pString = *pszX3FileName == 0 ? NULL : AllocString(pszX3FileName, Length);
            WriteScr("\"%s\"\n", pString == NULL ? pszX3FileName : pString);
            FreeString(pString);

            if (*pszX3FileName == 0)
            {
                if (pszX3FileName != pAsInfo->pszXFileName)
                    WriteScr("[%02X %02X]\n", pszX3FileName[1], pszX3FileName[2]);
                break;
            }

            pszX3FileName += Length;
        }

        WriteScr("\n#%s\n", LABEL_CRAFT_OFFSET_TABLE);

        ED6_AS_CRAFT_INFO *pCraft;
        ED6_INSTRUCTION   *pInstruction;

        pCraft = pAsInfo->pCraftInfo;
        for (ULONG Index = 0, Count = pAsInfo->CraftCount; Count; ++pCraft, ++Index, --Count)
        {
            ULONG TrueIndex;

            if (pCraft->Offset == ED6_INVALID_OFFSET)
            {
                PBYTE p = (PBYTE)&pCraft->Offset;

                WriteScr("[%02X", *p++);
                for (ULONG Len = sizeof(ED6_INVALID_OFFSET) - 1; Len; --Len)
                    WriteScr(" %02X", *p++);
                WriteScr("]\n");

                continue;
            }

            pInstruction = UnlinkInstruction(pCraft->pInstruction);
            if (pInstruction == NULL)
                continue;

            TrueIndex = Index;
            for (ULONG i = 0; i != Index; ++i)
            {
                if (pInstruction->Offset == pAsInfo->pCraftInfo[i].Offset)
                {
                    TrueIndex = i;
                    break;
                }
            }

            GetCraftName(pAsInfo, TrueIndex, Buffer);
            WriteScr(" (%s:s)", Buffer);

            if (Index >=countof(g_szIntrinsicCraft) && (Index + 1 - countof(g_szIntrinsicCraft)) % 5 != 0)
                continue;

            WriteScr("\n");
        }
        WriteScr("\n#%s\n\n", LABEL_CRAFT_OFFSET_TABLE_END);

        PBYTE pbFlags = pAsInfo->pbAsBuffer + pAsInfo->CraftOffsetTableEndOffset;
        WriteScr(
            "[%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X]\n\n",
            pbFlags[0], pbFlags[1], pbFlags[2], pbFlags[3], pbFlags[4],
            pbFlags[5], pbFlags[6], pbFlags[7], pbFlags[8], pbFlags[9],
            pbFlags[10], pbFlags[11], pbFlags[12], pbFlags[13], pbFlags[14],
            pbFlags[15], pbFlags[16]);

        Status = DumpCrafts(pAsInfo, file, Buffer);
        AS_IF_FAIL_BREAK(Status);

        Status = DumpFunctions(pAsInfo, file, Buffer);
    }

    return Status;
}
Пример #16
0
const char* TiXmlBase::ReadText(	const char* p, 
									TIXML_STRING * text, 
									bool trimWhiteSpace, 
									const char* endTag, 
									bool caseInsensitive,
									TiXmlEncoding encoding )
{
    *text = "";
	if (    !trimWhiteSpace			// certain tags always keep whitespace
		 || !condenseWhiteSpace )	// if true, whitespace is always kept
	{
		// Keep all the white space.
		while (	   p && *p
				&& !StringEqual( p, endTag, caseInsensitive, encoding )
			  )
		{
			int len;
			char cArr[4] = { 0, 0, 0, 0 };
			p = GetChar( p, cArr, &len, encoding );
			text->append( cArr, len );
		}
	}
	else
	{
		bool whitespace = false;

		// Remove leading white space:
		p = SkipWhiteSpace( p, encoding );
		while (	   p && *p
				&& !StringEqual( p, endTag, caseInsensitive, encoding ) )
		{
			if ( *p == '\r' || *p == '\n' )
			{
				whitespace = true;
				++p;
			}
			else if ( IsWhiteSpace( *p ) )
			{
				whitespace = true;
				++p;
			}
			else
			{
				// If we've found whitespace, add it before the
				// new character. Any whitespace just becomes a space.
				if ( whitespace )
				{
					(*text) += ' ';
					whitespace = false;
				}
				int len;
				char cArr[4] = { 0, 0, 0, 0 };
				p = GetChar( p, cArr, &len, encoding );
				if ( len == 1 )
					(*text) += cArr[0];	// more efficient
				else
					text->append( cArr, len );
			}
		}
	}
	if ( p && *p ) 
		p += StrLengthA( endTag );
	return p;
}
Пример #17
0
const char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding )
{
	// Presume an entity, and pull it out.
    TIXML_STRING ent;
	int i;
	*length = 0;

	if ( *(p+1) && *(p+1) == '#' && *(p+2) )
	{
		unsigned long ucs = 0;
		ptrdiff_t delta = 0;
		unsigned mult = 1;

		if ( *(p+2) == 'x' )
		{
			// Hexadecimal.
			if ( !*(p+3) ) return 0;

			const char* q = p+3;
			q = strchr( q, ';' );

			if ( !q || !*q ) return 0;

			delta = q-p;
			--q;

			while ( *q != 'x' )
			{
				if ( *q >= '0' && *q <= '9' )
					ucs += mult * (*q - '0');
				else if ( *q >= 'a' && *q <= 'f' )
					ucs += mult * (*q - 'a' + 10);
				else if ( *q >= 'A' && *q <= 'F' )
					ucs += mult * (*q - 'A' + 10 );
				else 
					return 0;
				mult *= 16;
				--q;
			}
		}
		else
		{
			// Decimal.
			if ( !*(p+2) ) return 0;

			const char* q = p+2;
			q = strchr( q, ';' );

			if ( !q || !*q ) return 0;

			delta = q-p;
			--q;

			while ( *q != '#' )
			{
				if ( *q >= '0' && *q <= '9' )
					ucs += mult * (*q - '0');
				else 
					return 0;
				mult *= 10;
				--q;
			}
		}
		if ( encoding == TIXML_ENCODING_UTF8 )
		{
			// convert the UCS to UTF-8
			ConvertUTF32ToUTF8( ucs, value, length );
		}
		else
		{
			*value = (char)ucs;
			*length = 1;
		}
		return p + delta + 1;
	}

	// Now try to match it.
	for( i=0; i<NUM_ENTITY; ++i )
	{
		if ( strncmp( entity[i].str, p, entity[i].strLength ) == 0 )
		{
			assert( StrLengthA( entity[i].str ) == entity[i].strLength );
			*value = entity[i].chr;
			*length = 1;
			return ( p + entity[i].strLength );
		}
	}

	// So it wasn't an entity, its unrecognized, or something like that.
	*value = *p;	// Don't put back the last one, since we return it!
	//*length = 1;	// Leave unrecognized entities - this doesn't really work.
					// Just writes strange XML.
	return p+1;
}