/* * Copyright (c) 2007, Insomniac Games * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY INSOMNIAC GAMES ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL INSOMNIAC GAMES BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ //////////////////////////////////////////////////////////////////////////////////////////////////// #define WIN32_LEAN_AND_MEAN #include #include #include //////////////////////////////////////////////////////////////////////////////////////////////////// typedef signed int i32; typedef unsigned int u32; typedef unsigned short u16; typedef unsigned char u8; //////////////////////////////////////////////////////////////////////////////////////////////////// void Usage(const char* name_) { printf("usage: %s shuffle\n", name_); } //////////////////////////////////////////////////////////////////////////////////////////////////// bool CopyToClipboard(const char* str_) { if (OpenClipboard(NULL)) { if (EmptyClipboard()) { HGLOBAL h_cb_data = GlobalAlloc(GMEM_DDESHARE, strlen(str_)+1); char* cb_data = (char*)GlobalLock(h_cb_data); strcpy(cb_data, LPCSTR(str_)); if (GlobalUnlock(h_cb_data)) { if (SetClipboardData(CF_TEXT, h_cb_data)) { if (CloseClipboard()) { return true; } } } } } return false; } //////////////////////////////////////////////////////////////////////////////////////////////////// i32 main(i32 argc_, char* argv_[]) { printf("\n%s (built %s)\n", argv_[0], __DATE__ " " __TIME__); if (argc_ != 2) { Usage(argv_[0]); return -1; } u32 len = strlen(argv_[1]); if ((len != 4) && (len != 8) && (len != 16)) { Usage(argv_[0]); return -1; } union { u32 m_u32[4]; u16 m_u16[8]; u8 m_u8[16]; } shuf; u32 c; u32 i; u32 val; if (len == 4) { for(i = 0; i < 4; i++) { c = argv_[1][i]; val = (c >= 'A' && c<='D') ? (0x00010203 + (0x04040404 * (c-'A'))) : (c >= 'a' && c<='d') ? (0x10111213 + (0x04040404 * (c-'a'))) : (c == '0') ? (0x80808080) : (c == 'x' || c=='X') ? (0xc0c0c0c0) : (c == '8') ? (0xe0e0e0e0) : (0xdeaddead); if (val == 0xdeaddead) { break; } shuf.m_u8[(i<<2)+0] = (val>>24); shuf.m_u8[(i<<2)+1] = (val>>16) & 0xff; shuf.m_u8[(i<<2)+2] = (val>>8) & 0xff; shuf.m_u8[(i<<2)+3] = (val>>0) & 0xff; } } else if (len == 8) { for(i = 0; i < 8; i++) { c = argv_[1][i]; val = (c >= 'A' && c <= 'H') ? (0x0001 + (0x0202 * (c-'A'))) : (c >= 'a' && c <= 'h') ? (0x1011 + (0x0202 * (c-'a'))) : (c == '0') ? (0x8080) : (c == 'x' || c == 'X') ? (0xc0c0) : (c == '8') ? (0xe0e0) : (0xdeaddead); if (val == 0xdeaddead) { break; } shuf.m_u8[(i<<1)+0] = (val>>8); shuf.m_u8[(i<<1)+1] = (val>>0) & 0xff; } } else if (len == 16) { for(i = 0; i < 16; i++) { c = argv_[1][i]; val = (c >= 'A' && c <= 'P') ? (0x00 + (0x01 * (c-'A'))) : (c >= 'a' && c <= 'p') ? (0x10 + (0x01 * (c-'a'))) : (c == '0') ? (0x80) : (c == 'x' || c == 'X') ? (0xc0) : (c == '8') ? (0xe0) : (0xdeaddead); if (val == 0xdeaddead) { break; } shuf.m_u8[i] = (u8)val; } } if (val == 0xdeaddead) { printf("invalid id '%c' at position %d\n", c, i); return -1; } char shuf_str[256]; shuf_str[0] = 0; for(u32 i = 0; i < 16; i++) { char str[8]; sprintf(str, "0x%02x", shuf.m_u8[i]); strcat (shuf_str, str); if (i < 15) { strcat(shuf_str, ", "); } } CopyToClipboard(shuf_str); printf("\nshuffle (also copied to clipboard):\n %s\n", shuf_str); printf("\n\n"); } ////////////////////////////////////////////////////////////////////////////////////////////////////