1
0
mirror of synced 2024-11-24 05:50:11 +01:00

Fix a bunch of stuff based on the official factory tool

This commit is contained in:
Bottersnike 2023-03-19 19:01:12 +00:00
parent 38ccd51217
commit 82847164b2
No known key found for this signature in database
21 changed files with 236 additions and 119 deletions

View File

@ -1,5 +1,7 @@
#include "comdevice.h"
#define RESERVED_JVS_COM_PORT 4
com_device_t* GetComDevice(HANDLE hFile) {
open_hook_t* pHData = GetDataForHandle(hFile, HDATA_FILE);
return pHData->hook->com_hook->com_device;
@ -14,12 +16,15 @@ BOOL DevPurgeComm(HANDLE hFile, DWORD dwFlags) {
if (dwFlags & PURGE_RXCLEAR) ringbuf_purge(&(GetComDevice(hFile)->out));
return TRUE;
}
BOOL DevGetCommModemStatus(HANDLE hFile, LPDWORD lpModelStat) {
// TODO: JVS SENSE
BOOL DevGetCommModemStatus(HANDLE hFile, LPDWORD lpModemStatus) {
if (!lpModemStatus) return FALSE;
com_device_t* dev = GetComDevice(hFile);
if (!dev) return false;
*lpModemStatus = dev->modemStatus;
return TRUE;
}
BOOL DevWaitCommEvent(HANDLE hFile, LPDWORD lpEvtMask, LPOVERLAPPED lpOverlapped) {
WaitForSingleObject(GetComDevice(hFile)->event, INFINITE);
WaitForSingleObject(GetComDevice(hFile)->dataOutReady, INFINITE);
if (lpOverlapped != NULL) SetEvent(lpOverlapped->hEvent);
return TRUE;
}
@ -43,8 +48,10 @@ BOOL DevClearCommError(HANDLE hFile, LPDWORD lpErrors, LPCOMSTAT lpStat) {
BOOL DevWriteFile(file_context_t* ctx, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped) {
if (nNumberOfBytesToWrite > 0xffff) return FALSE;
com_device_t* dev = GetComDevice(ctx->m_Handle);
// Ignore overflow
ringbuf_write(&(GetComDevice(ctx->m_Handle)->in), lpBuffer, nNumberOfBytesToWrite & 0xffff);
ringbuf_write(&(dev->in), lpBuffer, nNumberOfBytesToWrite & 0xffff);
SetEvent(dev->dataInReady);
if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten = nNumberOfBytesToWrite;
return TRUE;
}
@ -60,18 +67,18 @@ BOOL DevReadFile(file_context_t* ctx, LPVOID lpBuffer, DWORD nNumberOfBytesToRea
short read = ringbuf_read(&(comdev->out), lpBuffer, nNumberOfBytesToRead & 0xffff);
if (lpNumberOfBytesRead) *lpNumberOfBytesRead = read;
if (read != 0) {
// log_info("drf", "%d", read);
// for (int i = 0; i < read; i++) {
// printf("%02x ", ((LPBYTE)lpBuffer)[i]);
// }
// puts("");
if (lpOverlapped) {
lpOverlapped->InternalHigh = read;
SetEvent(lpOverlapped->hEvent);
}
return TRUE;
}
short comdev_read_blocking(com_device_t* com, unsigned char* buffer, short bytes) {
while (comdev_available(com) < bytes) SwitchToThread();
while (comdev_available(com) < bytes) {
WaitForSingleObject(com->dataInReady, INFINITE);
SwitchToThread();
}
return ringbuf_read(&com->in, buffer, bytes);
}
short comdev_read(com_device_t* com, unsigned char* buffer, short bytes) {
@ -79,7 +86,7 @@ short comdev_read(com_device_t* com, unsigned char* buffer, short bytes) {
}
bool comdev_write(com_device_t* com, const unsigned char* buffer, short bytes) {
bool ret = ringbuf_write(&com->out, buffer, bytes);
SetEvent(com->event);
SetEvent(com->dataOutReady);
return ret;
}
short comdev_available(com_device_t* com) { return ringbuf_available(&com->in); }
@ -164,7 +171,10 @@ BOOL attach_com_device(BYTE port, FnComDeviceThread* thread) {
return FALSE;
}
com_device_t* com = com_devices[port - 1];
if (com->thread != INVALID_HANDLE_VALUE) {
if (port == RESERVED_JVS_COM_PORT) return FALSE;
// No need to change what's assigned!
if (com->thread_worker == thread) return TRUE;
@ -179,8 +189,8 @@ BOOL attach_com_device(BYTE port, FnComDeviceThread* thread) {
}
void detach_com_device(BYTE port) {
// If the port is out of range, there's guaranteeably nothing attached
if (port < 1 || port > NUM_COM_PORTS)
return;
if (port < 1 || port > NUM_COM_PORTS) return;
if (port == RESERVED_JVS_COM_PORT) return;
com_device_t* com = com_devices[port - 1];
if (!com->thread) return;
@ -190,6 +200,8 @@ void detach_com_device(BYTE port) {
}
void detach_all_com_devices(void) {
for (int i = 0; i < NUM_COM_PORTS; i++) {
if (i == RESERVED_JVS_COM_PORT - 1) continue;
if (com_devices[i]->thread != INVALID_HANDLE_VALUE) {
TerminateThread(com_devices[i]->thread, (DWORD)-1);
com_devices[i]->thread = INVALID_HANDLE_VALUE;
@ -223,7 +235,7 @@ com_device_t* new_com_device(BYTE port) {
ringbuf_purge(&com_device->in);
ringbuf_purge(&com_device->out);
com_device->event = CreateEventW(NULL, TRUE, FALSE, com_device->com->wName);
com_device->dataOutReady = CreateEventW(NULL, TRUE, FALSE, com_device->com->wName);
com_device->thread = INVALID_HANDLE_VALUE;
hook_file(file);

View File

@ -14,7 +14,9 @@ struct com_device {
ring_buffer_t in;
ring_buffer_t out;
HANDLE event;
DWORD modemStatus;
HANDLE dataInReady;
HANDLE dataOutReady;
HANDLE thread;
FnComDeviceThread* thread_worker;
};

View File

@ -19,7 +19,6 @@ inline void start_device(const char* name, FnComDeviceThread* thread) {
_start_device_n(1);
_start_device_n(2);
_start_device_n(3);
_start_device_n(4);
_start_device_n(5);
_start_device_n(6);
_start_device_n(7);
@ -33,7 +32,6 @@ inline void stop_old_devices() {
_stop_if_unregistered(1);
_stop_if_unregistered(2);
_stop_if_unregistered(3);
_stop_if_unregistered(4);
_stop_if_unregistered(5);
_stop_if_unregistered(6);
_stop_if_unregistered(7);

View File

@ -15,7 +15,6 @@ BYTE extra[0xff];
* TODO: Validate against a real board
*/
enum TN32_Opcode {
TN32Op_Unknown20 = 0x20, // where did this come from??
TN32Op_GetFWVersion = 0x30,
TN32Op_GetHWVersion = 0x32,
@ -23,34 +22,35 @@ enum TN32_Opcode {
TN32Op_RadioOff = 0x41,
TN32Op_Poll = 0x42,
TN32Op_MifareSelectTag = 0x43,
TN32Op_Unknown44 = 0x44, // Present in code, not seen used
TN32Op_CardHalt = 0x44,
TN32Op_SetKeyBana = 0x50,
TN32Op_GetKeyBana = 0x51,
TN32Op_ReadBlock = 0x52,
TN32Op_Unknown53 = 0x53, // Present in code, not seen used
TN32Op_WriteBlock = 0x53,
TN32Op_SetKeyAime = 0x54,
TN32Op_GetKeyAime = 0x55,
// Firmware update (I think)
TN32Op_Unknown60 = 0x60, // Present in code, not seen used
TN32Op_Unknown61 = 0x61, // Present in code, not seen used
// Firmware update
TN32Op_EnterUpdaterMode = 0x60,
TN32Op_SendHex = 0x61,
TN32Op_Reset = 0x62,
TN32Op_Unknown63 = 0x63,
TN32Op_Unknown64 = 0x64,
TN32Op_SendBindata = 0x63,
TN32Op_BindataExec = 0x64,
TN32Op_Unknown70 = 0x70, // Present in code, not seen used
// Felica
TN32Op_FelicaPush = 0x70,
TN32Op_FelicaEncap = 0x71,
// No responses to either
LedUnknown80 = 0x80,
LedSetColour = 0x81,
Led_SetColour = 0x80,
Led_SetColourRGB = 0x81,
LedGetInfo = 0xf0,
LedF2 = 0xf2,
LedF3 = 0xf3,
LedF4 = 0xf4,
LedReset = 0xf5,
Led_GetInfo = 0xf0,
Led_FirmwareSum = 0xf2,
Led_SendHex = 0xf3,
Led_EnterBootMode = 0xf4,
Led_Reset = 0xf5,
};
char* OpcodeNames[256];
@ -282,26 +282,24 @@ DWORD WINAPI aime_bd_thread(com_device_t* dev) {
//
}
case TN32Op_Unknown44:
case TN32Op_CardHalt:
case TN32Op_MifareSelectTag:
comio_reply(dev, &req, COMIO_STATUS_OK, 0, NULL);
break;
case TN32Op_Unknown60:
// req.length == 0; start firmware update?
case TN32Op_EnterUpdaterMode:
comio_reply(dev, &req, COMIO_STATUS_OK, 0, NULL);
break;
case TN32Op_Unknown61:
case TN32Op_SendHex:
// null-terminated line of the firmware hex!
comio_reply(dev, &req, COMIO_STATUS_OK, 0, NULL);
log_info(plfAime, "Recv firmware: %s", extra);
break;
case TN32Op_Unknown63:
// req.length == 0; start binary firmware update?
case TN32Op_SendBindata:
fwNumBytes = 0;
comio_reply(dev, &req, COMIO_STATUS_OK, 0, NULL);
break;
case TN32Op_Unknown64:
case TN32Op_BindataExec:
// Raw binary firmware data
// [req.length == 256 -> wraps to 00] [256 bytes]
if (req.length == 0) {
@ -335,15 +333,15 @@ DWORD WINAPI aime_bd_thread(com_device_t* dev) {
} else if (req.dst == 0x08 || req.dst == 0x09) {
// LED sub-boards
switch (req.op) {
case LedReset:
case Led_Reset:
comio_reply(dev, &req, COMIO_STATUS_OK, 0, NULL);
break;
case LedGetInfo:
case Led_GetInfo:
// TODO: I'm not sure what this actually means.
// 838-15084 is probably a part number
comio_reply(dev, &req, COMIO_STATUS_OK, 9, (BYTE*)"15084\xff\x10\x00\x12");
break;
case LedSetColour:
case Led_SetColourRGB:
log_misc(plfAime, "Set LED: #%02x%02x%02x", extra[0], extra[1], extra[2]);
printf(
"\033[48;2;%d;%d;%dm "
@ -360,29 +358,29 @@ DWORD WINAPI aime_bd_thread(com_device_t* dev) {
void install_aime_bd() {
ZeroMemory(OpcodeNames, sizeof OpcodeNames);
OpcodeNames[TN32Op_Unknown20] = "Unknown20";
OpcodeNames[TN32Op_GetFWVersion] = "GetFWVersion";
OpcodeNames[TN32Op_GetHWVersion] = "GetHWVersion";
OpcodeNames[TN32Op_RadioOn] = "RadioOn";
OpcodeNames[TN32Op_RadioOff] = "RadioOff";
OpcodeNames[TN32Op_Poll] = "Poll";
OpcodeNames[TN32Op_MifareSelectTag] = "MifareSelectTag";
OpcodeNames[TN32Op_Unknown44] = "Unknown44";
OpcodeNames[TN32Op_CardHalt] = "CardHalt";
OpcodeNames[TN32Op_SetKeyBana] = "SetKeyBana";
OpcodeNames[TN32Op_GetKeyBana] = "GetKeyBana";
OpcodeNames[TN32Op_ReadBlock] = "ReadBlock";
OpcodeNames[TN32Op_Unknown53] = "Unknown53";
OpcodeNames[TN32Op_WriteBlock] = "WriteBlock";
OpcodeNames[TN32Op_SetKeyAime] = "SetKeyAime";
OpcodeNames[TN32Op_GetKeyAime] = "GetKeyAime";
OpcodeNames[TN32Op_Unknown60] = "Unknown60";
OpcodeNames[TN32Op_Unknown61] = "Unknown61";
OpcodeNames[TN32Op_EnterUpdaterMode] = "EnterUpdaterMode";
OpcodeNames[TN32Op_SendHex] = "SendHex";
OpcodeNames[TN32Op_Reset] = "Reset";
OpcodeNames[TN32Op_Unknown70] = "Unknown70";
OpcodeNames[TN32Op_FelicaPush] = "FelicaPush";
OpcodeNames[TN32Op_FelicaEncap] = "FelicaEncap";
OpcodeNames[LedReset] = "LedReset";
OpcodeNames[LedGetInfo] = "LedGetInfo";
OpcodeNames[LedSetColour] = "LedSetColour";
OpcodeNames[Led_Reset] = "Led_Reset";
OpcodeNames[Led_GetInfo] = "Led_GetInfo";
OpcodeNames[Led_SetColour] = "Led_SetColour";
OpcodeNames[Led_SetColourRGB] = "Led_SetColourRGB";
register_device("aime_tn32msec", aime_bd_thread);
}

View File

@ -49,6 +49,7 @@ void set_eeprom_static_config() {
}
void build_eeprom() {
return;
log_info(plfEeprom, "Building default EEPROM file");
memset(EEPROM_DATA, 0xff, EEPROM_SIZE);

View File

@ -14,45 +14,6 @@ static uint8_t inv[2] = { 0x00, 0x00 };
*/
static uint8_t config[2] = { 0xFF, 0xFF };
BOOL smbus_PCA9535_write(ich9_cmd_t cmd, WORD code, BYTE dlen, BYTE* data) {
switch (cmd) {
case ICH9_CMD_BYTE_DATA:
switch (code) {
case PCA9535_REG_IN0:
return FALSE;
case PCA9535_REG_IN1:
return FALSE;
case PCA9535_REG_OUT0:
out[0] = data[0];
return TRUE;
case PCA9535_REG_OUT1:
out[1] = data[0];
return TRUE;
case PCA9535_REG_INV0:
inv[0] = data[0];
return TRUE;
case PCA9535_REG_INV1:
inv[1] = data[0];
return TRUE;
case PCA9535_REG_CONF0:
config[0] = data[0];
return TRUE;
case PCA9535_REG_CONF1:
config[1] = data[0];
return TRUE;
default:
log_error(plfPCA9535, "Unknown write command: %02x", code);
return FALSE;
}
default:
log_error(plfPCA9535, "Unsupported write mode: %01x (%02x)", cmd, code);
return FALSE;
}
}
/**
* Supported resolutions by amPlatform:
* 640x480: VGA
@ -93,6 +54,45 @@ BOOL smbus_PCA9535_write(ich9_cmd_t cmd, WORD code, BYTE dlen, BYTE* data) {
#define DIPSW_RES_1360x768 0b0'110'0000
#define DIPSW_RES_1920x1080 0b0'111'0000
BOOL smbus_PCA9535_write(ich9_cmd_t cmd, WORD code, BYTE dlen, BYTE* data) {
switch (cmd) {
case ICH9_CMD_BYTE_DATA:
switch (code) {
case PCA9535_REG_IN0:
return FALSE;
case PCA9535_REG_IN1:
return FALSE;
case PCA9535_REG_OUT0:
out[0] = data[0];
return TRUE;
case PCA9535_REG_OUT1:
out[1] = data[0];
return TRUE;
case PCA9535_REG_INV0:
inv[0] = data[0];
return TRUE;
case PCA9535_REG_INV1:
inv[1] = data[0];
return TRUE;
case PCA9535_REG_CONF0:
config[0] = data[0];
return TRUE;
case PCA9535_REG_CONF1:
config[1] = data[0];
return TRUE;
default:
log_error(plfPCA9535, "Unknown write command: %02x", code);
return FALSE;
}
default:
log_error(plfPCA9535, "Unsupported write mode: %01x (%02x)", cmd, code);
return FALSE;
}
}
BOOL smbus_PCA9535_read(ich9_cmd_t cmd, WORD code, BYTE dlen, BYTE* data) {
switch (cmd) {
case ICH9_CMD_BYTE_DATA:
@ -148,7 +148,7 @@ BOOL smbus_PCA9535_read(ich9_cmd_t cmd, WORD code, BYTE dlen, BYTE* data) {
case PCA9535_REG_OUT0:
data[0] = out[0] & ~config[0];
return FALSE;
return TRUE;
case PCA9535_REG_OUT1:
data[0] = out[1] & ~config[1];
return TRUE;

View File

@ -95,7 +95,6 @@ void apply_patches(HMODULE hModule) {
void prebind_hooks() {
hook_all();
init_com_devices();
install_devices();
// TODO: Figure out why we're needing to call this manually (medium priority)
if (wcscmp(exeName, L"ALLNetProc.exe") == 0) {
@ -116,6 +115,8 @@ void init_injection(HMODULE hModule) {
setup_logging();
log_info(plfBoot, "Handover complete. Now executing within %ls", exeName);
init_com_devices();
if (MiceConfig.mice.apply_patches) apply_patches(hModule);
// Columba: Driver-level memory access, used to read the DMI tables

View File

@ -1,5 +1,6 @@
#include <Windows.h>
#include "../comdevice.h"
#include "../common.h"
#include "../key_config.h"
#include "jvs.h"
@ -659,6 +660,36 @@ void init_jvs_boards() {
}
}
DWORD __stdcall mxjvs_comdev_thread(com_device_t* com) {
BYTE inBuffer[512];
BYTE outBuffer[512];
DWORD bytesReturned;
while (1) {
do {
comdev_read_blocking(com, inBuffer, 1);
} while (inBuffer[0] != 0xE0);
comdev_read_blocking(com, inBuffer + 1, 2);
BYTE nbytes = inBuffer[2];
BYTE* bufferPtr = inBuffer + 3;
if (nbytes == 0xD0) {
comdev_read_blocking(com, bufferPtr++, 1);
nbytes = *bufferPtr;
}
while (nbytes) {
comdev_read_blocking(com, bufferPtr++, 1);
if (bufferPtr[-1] == 0xD0) comdev_read_blocking(com, bufferPtr++, 1);
nbytes--;
}
short packetSize = bufferPtr - inBuffer;
mxjvs_handle(inBuffer, packetSize, outBuffer, _countof(outBuffer), &bytesReturned);
com->modemStatus = !JVS_SENSE ? MS_DSR_ON : 0;
comdev_write(com, outBuffer, bytesReturned & 0xFFFF);
}
}
void setup_mxjvs() {
init_jvs_boards();
@ -679,6 +710,5 @@ void setup_mxjvs() {
mxjvs->com_hook = jvscom;
// TODO: Looks like some things might use JVS on COM4. We should setup a comdevice for this!
file_hook_t* jvscom_file = new_file_hook(jvscom->wName);
hook_file(jvscom_file);
attach_com_device(4, mxjvs_comdev_thread);
}

View File

@ -19,10 +19,11 @@ HANDLE SRAM_FILE_MAPPING = INVALID_HANDLE_VALUE;
(block).m_Crc = amiCrc32RCalc(sizeof(block) - 4, (BYTE*)(&(block)) + 4, 0); \
} while (0)
int build_sram() {
void build_sram() {
log_info(plfMxSram, "Building default SRAM file");
memset(SRAM_DATA, 0xff, SRAM_SIZE);
return;
AM_SYSDATAwH_BACKUP Backup = { 0 };
fix_crc(Backup);
@ -44,7 +45,7 @@ int build_sram() {
memcpy(SRAM_DATA + ADDR_ERROR_LOG, (unsigned char*)&ErrorLog, sizeof ErrorLog);
memcpy(SRAM_DATA + ADDR_ERROR_LOG + ADDR_DUP, (unsigned char*)&ErrorLog, sizeof ErrorLog);
return 1;
return;
}
void ensure_valid_sram() {

View File

@ -71,7 +71,7 @@ BYTE hwmon_read(superio_packet* packet) {
// TODO: No idea how to read any of these. Pulled from real system
case W83791D_REG_TEMP1_0:
return 0x1a;
return 26; // Chasis temp
case W83791D_RAM_VCOREA:
return 0x76;
case W83791D_RAM_VNIR0:
@ -118,8 +118,11 @@ BYTE hwmon_read(superio_packet* packet) {
case W83791D_CRIT_TEMP_3:
return w83791d_crit_t3;
case W83791D_VIN0:
return W83791D_ENTITY_CPU;
// TODO: Figure out what's going on with this discrepency!
case 0x50:
return 35; // CPU temp
// case W83791D_VIN0:
// return W83791D_ENTITY_CPU;
case W83791D_VIN1:
return W83791D_ENTITY_SYSTEM;

View File

@ -22,7 +22,6 @@ void mice_got_game_id(char game_id[4]) {
MiceConfig.devices.com1 = "";
MiceConfig.devices.com2 = "aime_tn32msec";
MiceConfig.devices.com3 = "maitouch";
MiceConfig.devices.com4 = "";
MiceConfig.devices.com5 = "";
MiceConfig.devices.com6 = "mailed";
MiceConfig.devices.com7 = "";
@ -60,7 +59,6 @@ void mice_got_game_id(char game_id[4]) {
MiceConfig.devices.com1 = "";
MiceConfig.devices.com2 = "";
MiceConfig.devices.com3 = "";
MiceConfig.devices.com4 = "";
MiceConfig.devices.com5 = "";
MiceConfig.devices.com6 = "";
MiceConfig.devices.com7 = "";

View File

@ -128,6 +128,6 @@ physical_disk_t* PHYSICAL_DISKS[] = {
&UPDATE_USB,
&APM_HDD,
// &LOG_USB,
&ALPHA_DVD,
&LOG_USB,
// &ALPHA_DVD,
};

View File

@ -721,6 +721,9 @@ void hook_drives() {
hook("Kernel32.dll", "SetVolumeLabelA", &FakeSetVolumeLabelA, NULL);
hook("Kernel32.dll", "GetVolumeInformationA", &FakeGetVolumeInformationA, NULL);
hook("Kernel32.dll", "QueryDosDeviceA", &FakeQueryDosDeviceA, NULL);
hook("Kernel32.dll", "QueryDosDeviceW", &FakeQueryDosDeviceW, NULL);
hook("Kernel32.dll", "DefineDosDeviceW", &FakeDefineDosDeviceW, NULL);
hook("Kernel32.dll", "SetVolumeMountPointW", &FakeSetVolumeMountPointW, NULL);
hook("Kernel32.dll", "GetVolumeNameForVolumeMountPointA",
&FakeGetVolumeNameForVolumeMountPointA, NULL);

View File

@ -81,6 +81,9 @@ BOOL WINAPI FakeGetVolumePathNamesForVolumeNameA(LPCSTR lpszVolumeName, LPCH lps
BOOL WINAPI FakeDeleteVolumeMountPointA(LPCSTR lpszVolumeMountPoint);
BOOL WINAPI FakeSetVolumeMountPointA(LPCSTR lpszVolumeMountPoint, LPCSTR lpszVolumeName);
DWORD WINAPI FakeQueryDosDeviceA(LPCSTR lpDeviceName, LPSTR lpTargetPath, DWORD ucchMax);
DWORD WINAPI FakeQueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax);
BOOL WINAPI FakeDefineDosDeviceW(DWORD dwFlags, LPCWSTR lpDeviceName, LPCWSTR lpTargetPath);
BOOL WINAPI FakeSetVolumeMountPointW(LPCWSTR lpszVolumeMountPoint, LPCWSTR lpszVolumeName);
MCIERROR WINAPI Fake_mciSendStringA(LPCTSTR lpszCommand, LPTSTR lpszReturnString, UINT cchReturn,
HANDLE hwndCallback);
UINT WINAPI FakeGetDriveTypeA(LPCSTR lpRootPathName);

View File

@ -200,6 +200,7 @@ BOOL WINAPI FakeSetVolumeMountPointA(LPCSTR lpszVolumeMountPoint, LPCSTR lpszVol
}
DWORD WINAPI FakeQueryDosDeviceA(LPCSTR lpDeviceName, LPSTR lpTargetPath, DWORD ucchMax) {
log_warning(plfDrive, "QueryDosDeviceA(%s, -, %d)", lpDeviceName, ucchMax);
if (lpDeviceName != NULL) {
disk_volume_t* volume = getVolumeByPath(lpDeviceName, VOL_MATCH_DOS_DEVICE);
if (volume == NULL) {
@ -218,6 +219,48 @@ DWORD WINAPI FakeQueryDosDeviceA(LPCSTR lpDeviceName, LPSTR lpTargetPath, DWORD
return 0;
}
const wchar_t* DUMMY_USB_RM = L"STORAGE#RemovableMedia#0&75ad516&0&rm#{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}";
DWORD WINAPI FakeQueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax) {
log_warning(plfDrive, "QueryDosDeviceW(%ls, -, %d)", lpDeviceName, ucchMax);
if (lpDeviceName != NULL) {
if (wcscmp(lpTargetPath, DUMMY_USB_RM) == 0) {
swprintf_s(lpTargetPath, ucchMax, L"\\Device\\Harddisk69");
return ucchMax;
}
char deviceName[MAX_PATH];
WideCharToMultiByte(CP_ACP, 0, lpDeviceName, wcslen(lpDeviceName), deviceName,
_countof(deviceName), NULL, NULL);
disk_volume_t* volume = getVolumeByPath(deviceName, VOL_MATCH_DOS_DEVICE);
if (volume == NULL) {
swprintf_s(lpTargetPath, ucchMax, L"\\Device\\Ttest");
SetLastError(ERROR_FILE_NOT_FOUND);
return 0;
}
size_t mountLen = wcslen(volume->m_DeviceName);
if (ucchMax < mountLen + 1) {
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return 0;
}
swprintf_s(lpTargetPath, ucchMax, L"\\Device\\%ls", volume->m_DeviceName);
return ucchMax;
} else {
// TODO: This, properly!!
ZeroMemory(lpTargetPath, ucchMax);
swprintf_s(lpTargetPath, ucchMax, DUMMY_USB_RM);
}
return 0;
}
// TODO:
BOOL WINAPI FakeDefineDosDeviceW(DWORD dwFlags, LPCWSTR lpDeviceName, LPCWSTR lpTargetPath) {
return TRUE;
}
BOOL WINAPI FakeSetVolumeMountPointW(LPCWSTR lpszVolumeMountPoint, LPCWSTR lpszVolumeName) {
return TRUE;
}
MCIERROR WINAPI Fake_mciSendStringA(LPCTSTR lpszCommand, LPTSTR lpszReturnString, UINT cchReturn,
HANDLE hwndCallback) {
if (strcmp(lpszCommand, "open cdaudio") == 0) {

View File

@ -35,7 +35,12 @@ BOOL WINAPI pd_DeviceIoControl(file_context_t* ctx, DWORD dwIoControlCode, LPVOI
return TRUE;
}
if (command != 0xC1) {
/**
* C1: Seen by mxkeychip
* C2: Seen by factorytest
*/
if (command != 0xC1 && command != 0xC2) {
log_error(plfDrive, "PD0:Unimplemented ATA command: %02x", command);
return FALSE;
@ -60,9 +65,11 @@ BOOL WINAPI pd_DeviceIoControl(file_context_t* ctx, DWORD dwIoControlCode, LPVOI
// It looks like mxkeychip never actually checks the response buffer,
// as long as the ioctl succeeds! Saves us a lot of work here!
// TODO: factorytest.exe _does_ check this!
return TRUE;
}
log_error(plfDrive, "Unimeplemented ATA C1 command: %02x", data);
log_error(plfDrive, "Unimeplemented ATA %02X command: %02x", command, data);
return FALSE;
case IOCTL_DISK_GET_LENGTH_INFO:
PGET_LENGTH_INFORMATION pLi = (PGET_LENGTH_INFORMATION)lpOutBuffer;

View File

@ -358,9 +358,11 @@ DWORD WINAPI FakeWriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesT
log_error(plfHooks, "WriteFile(%ls) unimplemented", file_hook->filename);
return FALSE;
}
BOOL ret = file_hook->WriteFile(&(pHData->ctx), lpBuffer, nNumberOfBytesToWrite,
lpNumberOfBytesWritten, lpOverlapped);
if (ret) pHData->ctx.m_Pointer.QuadPart += *lpNumberOfBytesWritten;
DWORD wrote;
BOOL ret =
file_hook->WriteFile(&(pHData->ctx), lpBuffer, nNumberOfBytesToWrite, &wrote, lpOverlapped);
if (ret) pHData->ctx.m_Pointer.QuadPart += wrote;
if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten = wrote;
return ret;
}
@ -384,9 +386,11 @@ BOOL WINAPI FakeReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRe
log_error(plfHooks, "ReadFile(%ls) unimplemented", file_hook->filename);
return FALSE;
}
BOOL ret = file_hook->ReadFile(&(pHData->ctx), lpBuffer, nNumberOfBytesToRead,
lpNumberOfBytesRead, lpOverlapped);
if (ret) pHData->ctx.m_Pointer.QuadPart += *lpNumberOfBytesRead;
DWORD read;
BOOL ret =
file_hook->ReadFile(&(pHData->ctx), lpBuffer, nNumberOfBytesToRead, &read, lpOverlapped);
if (ret) pHData->ctx.m_Pointer.QuadPart += read;
if (lpNumberOfBytesRead) *lpNumberOfBytesRead = read;
return ret;
}
@ -420,6 +424,15 @@ DWORD WINAPI FakeGetFileAttributesW(LPCWSTR lpFileName) {
}
return TrueGetFileAttributesW(lpFileName);
}
HANDLE WINAPI FakeFindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData) {
printf("FakeFindFirstFileA(%s)\n", lpFileName);
LPCSTR redirected;
if (redirect_path(lpFileName, &redirected)) {
printf("->FakeFindFirstFileA(%s)\n", redirected);
return TrueFindFirstFileA(redirected, lpFindFileData);
}
return TrueFindFirstFileA(lpFileName, lpFindFileData);
}
void hook_io() {
hook("Kernel32.dll", "DeviceIoControl", FakeDeviceIoControl, (void**)&TrueDeviceIoControl);
@ -439,6 +452,8 @@ void hook_io() {
hook("Kernel32.dll", "DeleteFileA", FakeDeleteFileA, (void**)&TrueDeleteFileA);
hook("Kernel32.dll", "DeleteFileW", FakeDeleteFileW, (void**)&TrueDeleteFileW);
hook("Kernel32.dll", "FindFirstFileA", FakeFindFirstFileA, (void**)&TrueFindFirstFileA);
hook("Kernel32.dll", "GetFileAttributesA", FakeGetFileAttributesA,
(void**)&TrueGetFileAttributesA);
hook("Kernel32.dll", "GetFileAttributesW", FakeGetFileAttributesW,

View File

@ -38,6 +38,7 @@ _MICE_FILES BOOL(WINAPI* TruePathFileExistsA)(LPCSTR pszPath);
_MICE_FILES BOOL(WINAPI* TruePathFileExistsW)(LPCWSTR pszPath);
_MICE_FILES BOOL(WINAPI* TrueDeleteFileA)(LPCSTR lpFileName);
_MICE_FILES BOOL(WINAPI* TrueDeleteFileW)(LPCWSTR lpFileName);
_MICE_FILES HANDLE(WINAPI* TrueFindFirstFileA)(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData);
_MICE_FILES DWORD(WINAPI* TrueGetFileAttributesA)(LPCSTR lpFileName);
_MICE_FILES DWORD(WINAPI* TrueGetFileAttributesW)(LPCWSTR lpFileName);

View File

@ -192,7 +192,7 @@ void SetupWindowPosition(LPRECT lpRect, DWORD dwStyle) {
lpRect->top = y;
lpRect->bottom = y + h;
AdjustWindowRect(lpRect, dwStyle, FALSE);
// AdjustWindowRect(lpRect, dwStyle, FALSE);
}
HWND WINAPI FakeCreateWindowExA(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName,
@ -372,6 +372,7 @@ void hook_gui() {
hook("User32.dll", "ChangeDisplaySettingsExW", FakeChangeDisplaySettingsExW,
(void**)&TrueChangeDisplaySettingsExW);
hook("D3d9.dll", "Direct3DCreate9", FakeDirect3DCreate9, (void**)&TrueDirect3DCreate9);
if (PathFileExistsA("FREEGLUT.DLL")) {
// Hooked as a way to identify use of GLUT
hook("FREEGLUT.DLL", "glutInitDisplayMode", Fake_glutInitDisplayMode,

View File

@ -80,6 +80,7 @@ static void dmi_append_with_strings(void* data, WORD size, int num_strings, ...)
void dmi_build_default() {
dmi_init();
// BIOS version
dmi_append_with_strings(&default_dmi_bios, sizeof default_dmi_bios, 3,
"American Megatrends Inc.", "080015 ", "07/28/2011");

View File

@ -96,12 +96,11 @@ CFG_int(keys, board_count, 1, "")
CFG_str(keys, keys, 0, "")
ENDSECTION(keys)
SECTION(devices, "Register attached hardware devices")
CFG_bool(devices, do_auto, true, "When true, if the running game is identified, the following 8 values are overwritten")
SECTION(devices, "Register attached hardware devices. COM4 is reserved for JVS.")
CFG_bool(devices, do_auto, true, "When true, if the running game is identified, the following 7 values are overwritten.")
CFG_str(devices, com1, "", "")
CFG_str(devices, com2, "", "")
CFG_str(devices, com3, "", "")
CFG_str(devices, com4, "", "")
CFG_str(devices, com5, "", "")
CFG_str(devices, com6, "", "")
CFG_str(devices, com7, "", "")