Wiimote: Added decryption function, it could be useful for debugging real Wiimote extensions

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2099 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson 2009-02-04 00:06:11 +00:00
parent c10d69fe07
commit ec39c45dd5
8 changed files with 48 additions and 17 deletions

View File

@ -933,7 +933,7 @@ void ConfigDialog::UpdateGUI()
has been initialized. Functions for that are basically already in place so these two options has been initialized. Functions for that are basically already in place so these two options
could possibly be simplified to one option. */ could possibly be simplified to one option. */
m_ConnectRealWiimote->Enable(!g_EmulatorRunning); m_ConnectRealWiimote->Enable(!g_EmulatorRunning);
m_UseRealWiimote->Enable(g_RealWiiMotePresent && g_Config.bConnectRealWiimote); m_UseRealWiimote->Enable(!(g_EmulatorRunning && g_RealWiiMotePresent && g_Config.bConnectRealWiimote));
// Linux has no FindItem() // Linux has no FindItem()
#ifdef _WIN32 #ifdef _WIN32

View File

@ -503,11 +503,11 @@ void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size)
LOG(WII_IPC_WIIMOTE, " Error: 0x%x", pReply->error); LOG(WII_IPC_WIIMOTE, " Error: 0x%x", pReply->error);
LOG(WII_IPC_WIIMOTE, " Size: 0x%x", pReply->size); LOG(WII_IPC_WIIMOTE, " Size: 0x%x", pReply->size);
LOG(WII_IPC_WIIMOTE, " Address: 0x%04x", pReply->address); LOG(WII_IPC_WIIMOTE, " Address: 0x%04x", pReply->address);
/**/Console::Print(" SendReadDataReply()\n"); /*Console::Print(" SendReadDataReply()\n");
Console::Print(" dataOffset: 0x%x\n", dataOffset); Console::Print(" dataOffset: 0x%x\n", dataOffset);
Console::Print(" copySize: 0x%x\n", copySize); Console::Print(" copySize: 0x%x\n", copySize);
Console::Print(" Size: 0x%x\n", pReply->size); Console::Print(" Size: 0x%x\n", pReply->size);
Console::Print(" Address: 0x%04x\n", Common::swap16(pReply->address)); Console::Print(" Address: 0x%04x\n", Common::swap16(pReply->address));*/
//std::string Temp = ArrayToString(data, 0x40); //std::string Temp = ArrayToString(data, 0x40);
//Console::Print("Eeprom: %s\n", Temp.c_str()); //Console::Print("Eeprom: %s\n", Temp.c_str());

View File

@ -288,10 +288,16 @@ void wiimote_gen_key(wiimote_key *key, u8 *keydata)
// ---------------- // ----------------
void wiimote_encrypt(wiimote_key *key, u8 *data, int addr, u8 len) void wiimote_encrypt(wiimote_key *key, u8 *data, int addr, u8 len)
{ {
for(int i = 0; i < len; i++, addr++) for(int i = 0; i < len; i++, addr++)
{
//Console::Print("data[%i] from %02x ", i, data[i]);
data[i] = (data[i] - key->ft[addr%8]) ^ key->sb[addr%8]; data[i] = (data[i] - key->ft[addr%8]) ^ key->sb[addr%8];
//Console::Print("to %02x\n", data[i]);
}
} }
// ===================================================
/* Decrypt data */
// ----------------
void wiimote_decrypt(wiimote_key *key, u8 *data, int addr, u8 len)
{
for(int i = 0; i < len; i++, addr++)
data[i] = (data[i] ^ key->sb[addr%8]) + key->ft[addr%8];
}

View File

@ -31,6 +31,7 @@ typedef struct {
void wiimote_encrypt(wiimote_key *key, u8 *data, int addr, u8 len); void wiimote_encrypt(wiimote_key *key, u8 *data, int addr, u8 len);
void wiimote_decrypt(wiimote_key *key, u8 *data, int addr, u8 len);
void wiimote_gen_key(wiimote_key *key, u8 *keydata); void wiimote_gen_key(wiimote_key *key, u8 *keydata);

View File

@ -147,8 +147,17 @@ void handle_event(struct wiimote_t* wm)
Tmp += StringFromFormat("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y); Tmp += StringFromFormat("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y);
} }
Tmp += "\n";
Tmp += StringFromFormat("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y); Tmp += StringFromFormat("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y);
Tmp += StringFromFormat("IR z distance: %f\n", wm->ir.z); Tmp += StringFromFormat("IR z distance: %f\n", wm->ir.z);
if(wm->exp.type == EXP_NUNCHUK)
{
Tmp += "\n";
Tmp += StringFromFormat("Nunchuck accel x, y, z: %03i %03i %03i\n", nc->accel.x, nc->accel.y, nc->accel.z);
}
//Tmp += "\n";
//std::string TmpData = ArrayToString(g_EventBuffer, ReportSize, 0, 30); //std::string TmpData = ArrayToString(g_EventBuffer, ReportSize, 0, 30);
//Tmp += "Data: " + TmpData; //Tmp += "Data: " + TmpData;
@ -157,7 +166,7 @@ void handle_event(struct wiimote_t* wm)
if(frame) if(frame)
{ {
// Produce adjussted accelerometer values // Produce adjusted accelerometer values
u8 AccelX = 0, AccelY = 0, AccelZ = 0; u8 AccelX = 0, AccelY = 0, AccelZ = 0;
if((wm->accel.x + g_Config.iAccNunNeutralX) <= 255) AccelX = wm->accel.x + g_Config.iAccNeutralX; if((wm->accel.x + g_Config.iAccNunNeutralX) <= 255) AccelX = wm->accel.x + g_Config.iAccNeutralX;
if((wm->accel.y + g_Config.iAccNunNeutralY) <= 255) AccelY = wm->accel.y + g_Config.iAccNeutralY; if((wm->accel.y + g_Config.iAccNunNeutralY) <= 255) AccelY = wm->accel.y + g_Config.iAccNeutralY;

View File

@ -16,7 +16,9 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
//////////////////////////////////////////////////////////////////////////////////////////
// Includes // Includes
// ッッッッッッッッッッッッッ
#include "Common.h" // Common #include "Common.h" // Common
#include "StringUtil.h" #include "StringUtil.h"
#include "ConsoleWindow.h" // For Start, Print, GetHwnd #include "ConsoleWindow.h" // For Start, Print, GetHwnd

View File

@ -18,14 +18,23 @@
#ifndef MAIN_H #ifndef MAIN_H
#define MAIN_H #define MAIN_H
//////////////////////////////////////////////////////////////////////////////////////////
// Includes
// ¯¯¯¯¯¯¯¯¯¯¯¯¯
#include <iostream> // System #include <iostream> // System
////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// Definitions and declarations
// ¯¯¯¯¯¯¯¯¯
#ifdef _WIN32 #ifdef _WIN32
#define sleep(x) Sleep(x) #define sleep(x) Sleep(x)
#else #else
#define sleep(x) usleep(x*1000) #define sleep(x) usleep(x*1000)
#endif #endif
// Declarations
void DoInitialize(); void DoInitialize();
double GetDoubleTime(); double GetDoubleTime();
int GetUpdateRate(); int GetUpdateRate();
@ -33,6 +42,7 @@ void InterruptDebugging(bool Emu, const void* _pData);
void ReadDebugging(bool Emu, const void* _pData); void ReadDebugging(bool Emu, const void* _pData);
bool IsFocus(); bool IsFocus();
// Movement recording // Movement recording
#define RECORDING_ROWS 15 #define RECORDING_ROWS 15
#define WM_RECORDING_WIIMOTE 0 #define WM_RECORDING_WIIMOTE 0

View File

@ -16,7 +16,9 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
//////////////////////////////////////////////////////////////////////////////////////////
// Includes // Includes
// ¯¯¯¯¯¯¯¯¯¯¯¯¯
#include <iostream> // System #include <iostream> // System
#include "pluginspecs_wiimote.h" #include "pluginspecs_wiimote.h"
@ -437,16 +439,17 @@ int Initialize()
// Remove the wiiuse_poll() threshold // Remove the wiiuse_poll() threshold
wiiuse_set_accel_threshold(g_WiiMotesFromWiiUse[0], 0); wiiuse_set_accel_threshold(g_WiiMotesFromWiiUse[0], 0);
// Set the sensor bar position, this only affects the internal wiiuse api functions // Set the sensor bar position, this should only affect the internal wiiuse api functions
wiiuse_set_ir_position(g_WiiMotesFromWiiUse[0], WIIUSE_IR_ABOVE); wiiuse_set_ir_position(g_WiiMotesFromWiiUse[0], WIIUSE_IR_ABOVE);
// I don't seem to need wiiuse_connect() // I don't seem to need wiiuse_connect() in Windows. But Linux needs it.
// Linux needs it #ifndef _WIN32
int Connect = wiiuse_connect(g_WiiMotesFromWiiUse, MAX_WIIMOTES); int Connect = wiiuse_connect(g_WiiMotesFromWiiUse, MAX_WIIMOTES);
Console::Print("Connected: %i\n", Connect); Console::Print("Connected: %i\n", Connect);
#endif
// If we are connecting from the config window without a game running we flash the lights // If we are connecting from the config window without a game running we flash the lights
if (!g_EmulatorRunning) FlashLights(true); if (!g_EmulatorRunning && g_RealWiiMotePresent) FlashLights(true);
// Create Wiimote classes // Create Wiimote classes
for (int i = 0; i < g_NumberOfWiiMotes; i++) for (int i = 0; i < g_NumberOfWiiMotes; i++)
@ -499,7 +502,7 @@ void Shutdown(void)
} }
// Flash flights // Flash flights
if (!g_EmulatorRunning) FlashLights(false); if (!g_EmulatorRunning && g_RealWiiMotePresent) FlashLights(false);
// Clean up wiiuse // Clean up wiiuse
wiiuse_cleanup(g_WiiMotesFromWiiUse, g_NumberOfWiiMotes); wiiuse_cleanup(g_WiiMotesFromWiiUse, g_NumberOfWiiMotes);