1
0
mirror of synced 2024-11-27 15:00:49 +01:00

mxStartup; micekeychip fix; SDCM fix

This commit is contained in:
Bottersnike 2023-07-16 22:13:34 +01:00
parent 3565da0040
commit cae05bde85
No known key found for this signature in database
53 changed files with 3180 additions and 379 deletions

336
lib/ewfapi.h Normal file
View File

@ -0,0 +1,336 @@
/****************************************************************************
Copyright (c) 2003 Microsoft Corporation
Module Name:
ewfapi.h
Abstract:
Defines the EWF APIs
Environment:
User mode
Revision History:
****************************************************************************/
#ifndef __EWFAPI_H__
#define __EWFAPI_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef EWFIMP
#define EWFIMP __declspec(dllimport)
#endif
typedef struct _EWF_VOLUME_NAME_ENTRY
{
struct _EWF_VOLUME_NAME_ENTRY * Next;
WCHAR Name[1];
} EWF_VOLUME_NAME_ENTRY, *PEWF_VOLUME_NAME_ENTRY;
typedef enum
{
EWF_NO_CMD = 0, // no pending command
EWF_ENABLE, // overlay will be enabled
EWF_DISABLE, // overlay will be disabled
EWF_SET_LEVEL, // overlay level will be set
EWF_COMMIT // current level will be committed to the protected volume
} EWF_CMD;
typedef enum
{
EWF_ENABLED, // The overlay is enabled on the volume
EWF_DISABLED // The overlay is disabled on the volume
} EWF_STATE;
typedef enum
{
EWF_DISK, // DISK overlay
EWF_RAM, // RAM overlay, with an associated overlay volume store
EWF_RAM_REG, // RAM overlay, without an associated overlay volume store
} EWF_TYPE, *PEWF_TYPE;
#define EWF_MAX_DEVICE_NAME_LENGTH (256)
#define EWF_VOLUME_ID_SIZE (16)
typedef struct _EWF_VOLUME_DESC
{
WCHAR DeviceName[EWF_MAX_DEVICE_NAME_LENGTH]; // Device name of the volume
UCHAR VolumeID[EWF_VOLUME_ID_SIZE]; // 16 byte volume identifier
} EWF_VOLUME_DESC, * PEWF_VOLUME_DESC;
//
// This is a variable size structure depending on how many protected overlay
// volumes there are.
//
typedef struct _EWF_OVERLAY_STORE_CONFIG
{
ULONG FormatVersion; // Version of Overlay-Store format
LONGLONG VolumeSize; // Size of the overlay volume in bytes
ULONG NumSegments; // Number of segments that the volume is divided into
ULONG FreeSegments; // Number of segments that are free
ULONG SegmentSize; // Size of each segment in bytes
ULONG MaxVolumes; // Maximum number of protected volumes
ULONG NumVolumes; // Number of currently protected volumes
USHORT MaxLevels; // Maximum number of overlay levels
EWF_VOLUME_DESC VolumeDescArray[1];
// The array holds NumVolume count volume descriptions
} EWF_OVERLAY_STORE_CONFIG, * PEWF_OVERLAY_STORE_CONFIG;
typedef struct _EWF_COMMAND
{
EWF_CMD Command; // ENABLE, DISABLE, etc..
ULONG Param1; // command first parameter.
ULONG Param2; // command second parameter.
} EWF_COMMAND, *PEWF_COMMAND;
#define EWF_MAX_LEVEL_NAME_LENGTH (64)
typedef struct _EWF_LEVEL_DESC
{
WCHAR LevelName[EWF_MAX_LEVEL_NAME_LENGTH];
// friendly name of the level
// If the length is equal to EWF_MAX_LEVEL_NAME_LENGTH
// then no null terminator is stored.
FILETIME LevelEndTime; // time at which the level was ended
LONGLONG LevelDataSize; // Size of the data in the level in bytes
} EWF_LEVEL_DESC, * PEWF_LEVEL_DESC;
#define EWF_MAX_PERSISTENT_DATA (32) // maximum number of bytes that can be persisted
typedef struct _EWF_VOLUME_CONFIG
{
EWF_TYPE Type; // Type of overlay for this volume
EWF_STATE State; // state of the overlay for this volume, ENABLED or DISABLED
EWF_COMMAND BootCommand; // Command to execute on next restart
UCHAR PersistentData[EWF_MAX_PERSISTENT_DATA];
// Small amount of persistent data that survives a restore
USHORT MaxLevels; // Maximum number of checkpoint levels for this volume
ULONG ClumpSize; // 512 bytes
USHORT CurrentLevel; // Current checkpoint level
union
{
struct
{
LONGLONG DiskMapSize; // Size of the mapping data on disk
LONGLONG DiskDataSize; // Size of the data stored on disk for this protected volume
} DiskOverlay;
struct
{
LONGLONG RamDataSize; // Size of the data stored in RAM for this protected volume
} RamOverlay;
};
ULONG MemMapSize; // Size of the mapping data in memory
EWF_VOLUME_DESC VolumeDesc; // volume device name, and volume ID
EWF_LEVEL_DESC LevelDescArray[1]; // Level descripton and end time, and level data size
} EWF_VOLUME_CONFIG, * PEWF_VOLUME_CONFIG;
EWFIMP
WCHAR
WINAPI
EwfMgrGetDriveLetterFromVolumeName(
IN LPCWSTR lpVolumeName
);
EWFIMP
BOOL
WINAPI
EwfMgrVolumeNameListIsEmpty(
IN PEWF_VOLUME_NAME_ENTRY pVolumeNameList
);
EWFIMP
VOID
WINAPI
EwfMgrVolumeNameEntryPop(
IN PEWF_VOLUME_NAME_ENTRY * ppVolumeNameList
);
EWFIMP
VOID
WINAPI
EwfMgrVolumeNameListDelete(
IN PEWF_VOLUME_NAME_ENTRY pVolumeNameList
);
EWFIMP
HANDLE
WINAPI
EwfMgrOpenProtected(
IN LPCWSTR lpVolume
);
EWFIMP
BOOL
WINAPI
EwfMgrClose(
IN HANDLE hDevice
);
EWFIMP
BOOL
WINAPI
EwfMgrClearCommand(
IN HANDLE hDevice
);
EWFIMP
BOOL
WINAPI
EwfMgrSetPersistentData(
IN HANDLE hDevice,
IN LPBYTE lpPersistentData,
IN DWORD cbPersistentData
);
EWFIMP
BOOL
WINAPI
EwfMgrGetPersistentData(
IN HANDLE hDevice,
OUT LPBYTE lpPersistentData,
IN DWORD cbPersistentData
);
EWFIMP
BOOL
WINAPI
EwfMgrCheckpoint(
IN HANDLE hDevice,
IN OPTIONAL LPCWSTR lpDescription
);
EWFIMP
BOOL
WINAPI
EwfMgrRestore(
IN HANDLE hDevice
);
EWFIMP
BOOL
WINAPI
EwfMgrDisable(
IN HANDLE hDevice,
IN BOOL fCommit
);
EWFIMP
BOOL
WINAPI
EwfMgrEnable(
IN HANDLE hDevice
);
EWFIMP
BOOL
WINAPI
EwfMgrCommit(
IN HANDLE hDevice
);
EWFIMP
BOOL
WINAPI
EwfMgrCommitAndDisableLive(
IN HANDLE hDevice
);
EWFIMP
BOOL
WINAPI
EwfMgrCommitFile(
IN HANDLE hDevice,
IN LPWSTR lpFile
);
EWFIMP
BOOL
WINAPI
EwfMgrSetLevel(
IN HANDLE hDevice,
IN OPTIONAL LPCWSTR lpDescription,
IN int Level,
IN BOOL fDeleteLevel
);
EWFIMP
PEWF_VOLUME_CONFIG
WINAPI
EwfMgrGetProtectedVolumeConfig(
IN HANDLE hDevice
);
EWFIMP
PEWF_VOLUME_NAME_ENTRY
WINAPI
EwfMgrGetProtectedVolumeList(
VOID
);
EWFIMP
HANDLE
WINAPI
EwfMgrOpenOverlayStore(
IN BOOL fOpenForAsyncIO
);
EWFIMP
PEWF_OVERLAY_STORE_CONFIG
WINAPI
EwfMgrGetOverlayStoreConfig(
IN HANDLE hDevice
);
EWFIMP
BOOL
WINAPI
EwfMgrRegisterLowSpaceNotification(
IN HANDLE hDevice,
IN LONGLONG FreeBytesRemaining,
IN LPOVERLAPPED lpOverlapped
);
#ifdef __cplusplus
}
#endif
#endif // __EWFAPI_H__

BIN
lib/ewfapi.lib Normal file

Binary file not shown.

View File

@ -39,6 +39,9 @@ else
endif
assert(openssl_lib.found(), 'Please download openssl!')
ewfapi_lib = meson.get_compiler('c').find_library('ewfapi', dirs: [
join_paths(meson.source_root(), 'lib')
], required: true)
freeglut_lib = meson.get_compiler('c').find_library('freeglut', dirs: [
join_paths(meson.source_root(), 'lib')
], required: true)

View File

@ -144,13 +144,9 @@ typedef struct {
typedef struct {
uint32_t m_Crc;
uint32_t m_Uk1;
uint32_t m_Uk2;
uint32_t m_Uk3;
uint32_t m_Uk4;
uint32_t m_Uk5;
uint32_t m_Uk6;
uint32_t m_Uk7;
uint8_t m_Uk04[4];
char m_Name[16];
uint8_t m_Uk18[8];
} AM_SYSDATAwH_ALPB_COMPUTER_NAME, *PAM_SYSDATAwH_ALPB_COMPUTER_NAME;
#pragma pack(pop)

View File

@ -1,17 +1,16 @@
#include "mx.h"
BOOL WINAPI mxhwreset_DeviceIoControl(file_context_t* ctx, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize,
LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped) {
BOOL WINAPI mxhwreset_DeviceIoControl(file_context_t* ctx, DWORD dwIoControlCode, LPVOID lpInBuffer,
DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize,
LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped) {
switch (dwIoControlCode) {
case IOCTL_MXHWRESET_RESET:
if (lpBytesReturned) *lpBytesReturned = 0;
break;
ExitProcess(-1);
default:
log_warning(plfMxHwreset, "unhandled 0x%08x", dwIoControlCode);
return FALSE;
}
return TRUE;
}
void setup_mxhwreset() {

View File

@ -61,6 +61,8 @@ void mxjvs_handle(unsigned char* lpMaskedIn, short nMaskedCount, unsigned char*
if ((++jvsDTHCount) > _countof(jvsDTHistory)) jvsDTHCount = _countof(jvsDTHistory);
jvsRate = (jvsRateAccum > 0.0f) ? (1.0f / (jvsRateAccum / (float)jvsDTHCount)) : FLT_MAX;
// log_game(plfAime, "jvs rate: %.2fHz", jvsRate);
}
last_tick = now;

View File

@ -168,7 +168,7 @@ void hud_fps() {
igText("FPS: %.1f", io->Framerate);
igText(" dT: %.2fms", 1000 / io->Framerate);
igText("JVS Rate: %.2f", jvsRate);
igText("JVS Rate: %.2fHz", jvsRate);
}
igEnd();
@ -957,8 +957,7 @@ void tab_system_buttons() {
igTextUnformatted(keyName, NULL);
}
igNextColumn();
if (igButton("Bind##Bind1P", vec0))
igOpenPopup_Str("BindSys1P", ImGuiPopupFlags_None);
if (igButton("Bind##Bind1P", vec0)) igOpenPopup_Str("BindSys1P", ImGuiPopupFlags_None);
if (MiceConfig.keys.card_p1) {
igSameLine(0, -1);
if (igButton("Clear##Clear1P", vec0)) {
@ -984,8 +983,7 @@ void tab_system_buttons() {
igTextUnformatted(keyName, NULL);
}
igNextColumn();
if (igButton("Bind##Bind2P", vec0))
igOpenPopup_Str("BindSys2P", ImGuiPopupFlags_None);
if (igButton("Bind##Bind2P", vec0)) igOpenPopup_Str("BindSys2P", ImGuiPopupFlags_None);
if (MiceConfig.keys.card_p2) {
igSameLine(0, -1);
if (igButton("Clear##Clear2P", vec0)) {
@ -1090,11 +1088,12 @@ void hud_control(ImGuiKey open_key) {
void __stdcall hud_gui(unsigned int hookType, IDirect3DDevice9* dev) {
static bool lastAnyOpen = false;
bool anyOpen = showControl || showEeprom || showSram || showCardP1;
bool anyOpen = showControl || showEeprom || showSram || showCardP1 || showFps;
if (anyOpen != lastAnyOpen) {
changeCursorState = anyOpen ? 1 : 0;
lastAnyOpen = anyOpen;
}
// if (!anyOpen) return;
static bool initialized = false;
if (!initialized) {
@ -1123,8 +1122,10 @@ void __stdcall hud_gui(unsigned int hookType, IDirect3DDevice9* dev) {
if (hookType == UI_HOOK_DX9) {
igEndFrame();
igRender();
ImGui_ImplDX9_RenderDrawData(igGetDrawData());
if (anyOpen) {
igRender();
ImGui_ImplDX9_RenderDrawData(igGetDrawData());
}
} else if (hookType == UI_HOOK_GLUT) {
igRender();
ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData());

View File

@ -373,6 +373,7 @@ char matchWorkFilename[MAX_PATH + 1];
inline static BOOL matchVolume(disk_volume_t* volume, LPCSTR lpRootPathName, DWORD match) {
if (match & VOL_MATCH_GUID) {
strcpy_s(matchWorkFilename, sizeof matchWorkFilename, volume->m_FilenameA);
if (strcmp(matchWorkFilename, lpRootPathName) == 0) return TRUE;
strcat_s(matchWorkFilename, sizeof matchWorkFilename, "\\");
if (strcmp(matchWorkFilename, lpRootPathName) == 0) return TRUE;
}
@ -385,6 +386,12 @@ inline static BOOL matchVolume(disk_volume_t* volume, LPCSTR lpRootPathName, DWO
"\\\\.\\%c:", char_upper(volume->m_MountPoint));
if (strstr(lpRootPathName, matchWorkFilename) == lpRootPathName) return TRUE;
}
if (match & VOL_MATCH_PATH && volume->m_pDrive && volume->m_pPartition) {
sprintf_s(matchWorkFilename, sizeof matchWorkFilename, "\\device\\harddisk%d\\partition%d",
volume->m_pDrive->m_DriveNumber, volume->m_pPartition->m_PartitionNumber);
if (_stricmp(lpRootPathName, matchWorkFilename) == 0) return TRUE;
}
if (match & VOL_MATCH_DOS_DEVICE && volume->m_MountPoint) {
if (char_lower(volume->m_MountPoint) == char_lower(lpRootPathName[0])) {
if (lpRootPathName[1] == ':' && lpRootPathName[2] == '\0') return TRUE;
@ -779,6 +786,7 @@ void hook_drives() {
NULL);
hook("Kernel32.dll", "DeleteVolumeMountPointA", &FakeDeleteVolumeMountPointA, NULL);
hook("Kernel32.dll", "SetVolumeMountPointA", &FakeSetVolumeMountPointA, NULL);
hook("Kernel32.dll", "DefineDosDeviceA", &FakeDefineDosDeviceA, NULL);
hook("Kernel32.dll", "GetDriveTypeA", &FakeGetDriveTypeA, (void**)&TrueGetDriveTypeA);
hook("Kernel32.dll", "GetDiskFreeSpaceExA", &FakeGetDiskFreeSpaceExA,
(void**)&TrueGetDiskFreeSpaceExA);

View File

@ -78,6 +78,7 @@ BOOL WINAPI FakeGetVolumePathNamesForVolumeNameA(LPCSTR lpszVolumeName, LPCH lps
DWORD cchBufferLength, PDWORD lpcchReturnLength);
BOOL WINAPI FakeDeleteVolumeMountPointA(LPCSTR lpszVolumeMountPoint);
BOOL WINAPI FakeSetVolumeMountPointA(LPCSTR lpszVolumeMountPoint, LPCSTR lpszVolumeName);
BOOL WINAPI FakeDefineDosDeviceA(DWORD dwFlags, LPCSTR lpDeviceName, LPCSTR lpTargetPath);
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);

View File

@ -19,26 +19,28 @@ disk_volume_t* incrementFindIndex(HANDLE hFindVolume) {
continue;
}
if (find_index->partition > 3) {
if (AVAILABLE_DISKS[find_index->disk].m_Disk
->m_Extended[find_index->partition - 4]
if (AVAILABLE_DISKS[find_index->disk]
.m_Disk->m_Extended[find_index->partition - 4]
.m_PartitionNumber == 0) {
find_index->disk++;
find_index->partition = 0;
continue;
}
return &(AVAILABLE_DISKS[find_index->disk].m_Disk
->m_Extended[(find_index->partition++) - 4]
return &(AVAILABLE_DISKS[find_index->disk]
.m_Disk->m_Extended[(find_index->partition++) - 4]
.m_Volume);
}
if (AVAILABLE_DISKS[find_index->disk].m_Disk
->m_Partitions[find_index->partition]
if (AVAILABLE_DISKS[find_index->disk]
.m_Disk->m_Partitions[find_index->partition]
.m_PartitionNumber == 0) {
find_index->partition = 4;
continue;
}
return &(AVAILABLE_DISKS[find_index->disk].m_Disk->m_Partitions[find_index->partition++].m_Volume);
return &(AVAILABLE_DISKS[find_index->disk]
.m_Disk->m_Partitions[find_index->partition++]
.m_Volume);
}
}
@ -182,9 +184,10 @@ BOOL WINAPI FakeDeleteVolumeMountPointA(LPCSTR lpszVolumeMountPoint) {
return TRUE;
}
BOOL WINAPI FakeSetVolumeMountPointA(LPCSTR lpszVolumeMountPoint, LPCSTR lpszVolumeName) {
log_trace(plfDrive, "SetVolumeMountPointA(%s)", lpszVolumeMountPoint);
log_misc(plfDrive, "SetVolumeMountPointA(%s, %s)", lpszVolumeMountPoint, lpszVolumeName);
disk_volume_t* volume = getVolumeByPath(lpszVolumeName, VOL_MATCH_GUID);
if (volume == NULL) {
log_error(plfDrive, "No match found for %s", lpszVolumeName);
SetLastError(ERROR_FILE_NOT_FOUND);
return FALSE;
}
@ -197,6 +200,12 @@ BOOL WINAPI FakeSetVolumeMountPointA(LPCSTR lpszVolumeMountPoint, LPCSTR lpszVol
volume->m_MountPoint = cMountPoint;
return TRUE;
}
if (sscanf_s(lpszVolumeMountPoint, "\\\\.\\%c:\\%n", &cMountPoint, 1, &nScan) == 1 &&
nScan == 7) {
log_info(plfDrive, "Mounting %s at %c:\\", volume->m_Name, cMountPoint);
volume->m_MountPoint = cMountPoint;
return TRUE;
}
if (sscanf_s(lpszVolumeMountPoint, "%c:\\%n", &cMountPoint, 1, &nScan) == 1 && nScan == 3) {
log_info(plfDrive, "Mounting %s at %c:\\", volume->m_Name, cMountPoint);
volume->m_MountPoint = cMountPoint;
@ -206,6 +215,32 @@ BOOL WINAPI FakeSetVolumeMountPointA(LPCSTR lpszVolumeMountPoint, LPCSTR lpszVol
return FALSE;
}
BOOL WINAPI FakeDefineDosDeviceA(DWORD dwFlags, LPCSTR lpDeviceName, LPCSTR lpTargetPath) {
disk_volume_t* volume = NULL;
if (dwFlags & DDD_REMOVE_DEFINITION) {
if (dwFlags & DDD_EXACT_MATCH_ON_REMOVE) {
volume = getVolumeByPath(lpTargetPath, VOL_MATCH_PATH);
} else {
volume = getVolumeByPath(lpDeviceName, VOL_MATCH_ALL);
}
if (!volume) {
log_trace(plfDrive, "DDDA-: Unmatched: %s | %s", lpTargetPath, lpDeviceName);
return FALSE;
}
volume->m_MountPoint = '\0';
return TRUE;
}
volume = getVolumeByPath(lpTargetPath, VOL_MATCH_ALL);
if (!volume) {
log_error(plfDrive, "DDDA+: Unmatched: %s | %s", lpTargetPath, lpDeviceName);
return FALSE;
}
volume->m_MountPoint = lpDeviceName[0]; // Awful? Yes.
return TRUE;
}
DWORD WINAPI FakeQueryDosDeviceA(LPCSTR lpDeviceName, LPSTR lpTargetPath, DWORD ucchMax) {
log_warning(plfDrive, "QueryDosDeviceA(%s, -, %d)", lpDeviceName, ucchMax);
if (lpDeviceName != NULL) {
@ -338,8 +373,8 @@ BOOL WINAPI FakeGetDiskFreeSpaceExA(LPCSTR lpDirectoryName,
// return FALSE;
// }
// We're going to be remapping the drive to ./mice/dev/, so the free bytes are whatever the current
// real drive has free. No point claiming we have more than we do!
// We're going to be remapping the drive to ./mice/dev/, so the free bytes are whatever the
// current real drive has free. No point claiming we have more than we do!
return TrueGetDiskFreeSpaceExA(NULL, lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes,
lpTotalNumberOfFreeBytes);
}

View File

@ -293,13 +293,48 @@ DWORD WINAPI FakeGetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize) {
return file_hook->GetFileSizeEx(&(pHData->ctx), lpFileSize);
}
CHAR stdoutBuffer[256];
DWORD stdoutCount = 0;
CHAR stderrBuffer[256];
DWORD stderrCount = 0;
DWORD WINAPI FakeWriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped) {
if (hFile == GetStdHandle(STD_OUTPUT_HANDLE) || hFile == GetStdHandle(STD_ERROR_HANDLE)) {
return TrueWriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten,
lpOverlapped);
if (hFile == GetStdHandle(STD_OUTPUT_HANDLE)) {
for (DWORD_PTR i = 0; i < nNumberOfBytesToWrite; i++) {
stdoutBuffer[stdoutCount] = ((CHAR*)lpBuffer)[i];
if (stdoutBuffer[stdoutCount] == '\n' || stdoutBuffer[stdoutCount] == '\r') {
if (stdoutCount) log_game(plfStdout, "%.*s", stdoutCount, stdoutBuffer);
stdoutCount = 0;
} else if (stdoutCount == _countof(stdoutBuffer)) {
log_game(plfStdout, "%.*s", _countof(stdoutBuffer), stdoutBuffer);
stdoutCount = 0;
} else {
stdoutCount++;
}
}
return TRUE;
} else if (hFile == GetStdHandle(STD_ERROR_HANDLE)) {
for (DWORD_PTR i = 0; i < nNumberOfBytesToWrite; i++) {
stderrBuffer[stderrCount] = ((CHAR*)lpBuffer)[i];
if (stderrBuffer[stderrCount] == '\n' || stderrBuffer[stderrCount] == '\r') {
if (stderrCount) log_game(plfStderr, "%.*s", stderrCount, stderrBuffer);
stderrCount = 0;
} else if (stderrCount == _countof(stderrBuffer) - 1) {
log_game(plfStderr, "%.*s", _countof(stderrBuffer), stderrBuffer);
stderrCount = 0;
} else {
stderrCount++;
}
}
return TRUE;
}
// if (hFile == GetStdHandle(STD_OUTPUT_HANDLE) || hFile == GetStdHandle(STD_ERROR_HANDLE)) {
// log_game(plfFile, "Temp STDIO %.*s", nNumberOfBytesToWrite, lpBuffer);
// return TrueWriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten,
// lpOverlapped);
// }
open_hook_t* pHData = GetDataForHandle(hFile);
if (pHData == NULL) {
return TrueWriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten,

View File

@ -104,6 +104,7 @@ extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam
HWND mainWindow = NULL;
static unsigned int hookType;
static IDirect3DDevice9* g_pd3dDevice = NULL;
static HWND window;
BOOL CALLBACK EnumWindowsCallback(HWND handle, LPARAM lParam) {
@ -178,7 +179,7 @@ BOOL UnadjustWindowRect(LPRECT prc, DWORD dwStyle, BOOL fMenu) {
return fRc;
}
BOOL GetD3D9Device(void** pTable, size_t Size) {
BOOL GetD3D9Device(IDirect3DDevice9Vtbl* pTable, size_t Size) {
if (!pTable) return false;
IDirect3D9* pD3D =
@ -214,7 +215,9 @@ BOOL GetD3D9Device(void** pTable, size_t Size) {
return true;
}
static HRESULT(WINAPI* TrueEndScene)(IDirect3DDevice9*);
static STDMETHOD(TruePresent)(IDirect3DDevice9* This, CONST RECT* pSourceRect,
CONST RECT* pDestRect, HWND hDestWindowOverride,
CONST RGNDATA* pDirtyRegion);
void draw_rect(IDirect3DDevice9* dev, int x, int y, int w, int h, unsigned char r, unsigned char g,
unsigned char b) {
@ -224,16 +227,22 @@ void draw_rect(IDirect3DDevice9* dev, int x, int y, int w, int h, unsigned char
dev->lpVtbl->Clear(dev, 1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_TARGET, rectColor, 0, 0);
}
HRESULT __stdcall hkEndScene(IDirect3DDevice9* pDevice) {
static bool showMenu = false;
HRESULT STDMETHODCALLTYPE hkPresent(IDirect3DDevice9* This, CONST RECT* pSourceRect,
CONST RECT* pDestRect, HWND hDestWindowOverride,
CONST RGNDATA* pDirtyRegion) {
hookType = UI_HOOK_DX9;
if (g_pd3dDevice != NULL) g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice);
end_scene_hook_t* head = end_scene_hook_list;
while (head != NULL) {
head->hook(hookType, pDevice);
head->hook(hookType, This);
head = head->next;
}
return TrueEndScene(pDevice);
if (g_pd3dDevice != NULL) g_pd3dDevice->lpVtbl->EndScene(g_pd3dDevice);
return TruePresent(This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
}
void register_gui_hook(FnEndScene* end_scene) {
@ -326,18 +335,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UIN
void post_win_create(HWND hWnd) {
// Don't double-hook!
if (TrueEndScene != NULL) return;
if (TruePresent != NULL) return;
mainWindow = hWnd;
if (hookType == UI_HOOK_DX9) {
void* d3d9Device[119];
if (GetD3D9Device(d3d9Device, sizeof(d3d9Device))) {
TrueEndScene = d3d9Device[42];
IDirect3DDevice9Vtbl d3d9Device;
if (GetD3D9Device(&d3d9Device, sizeof(d3d9Device))) {
TruePresent = d3d9Device.Present;
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&TrueEndScene, hkEndScene);
DetourAttach((PVOID*)&TruePresent, hkPresent);
DetourTransactionCommit();
}
// MiceInputInit will be called by our D3D9 hooks instead
@ -474,11 +483,13 @@ HRESULT STDMETHODCALLTYPE FakeCreateDevice(IDirect3D9* this, UINT Adapter, D3DDE
IDirect3DDevice9** ppReturnedDeviceInterface) {
if (MiceConfig.window.windowed) {
pPresentationParameters->Windowed = TRUE;
pPresentationParameters->FullScreen_RefreshRateInHz = 0;
} else if (pPresentationParameters->Windowed) {
pPresentationParameters->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
pPresentationParameters->FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
} else /* if (pPresentationParameters->Windowed) */ {
D3DDISPLAYMODE d3ddm;
this->lpVtbl->GetAdapterDisplayMode(this, Adapter, &d3ddm);
pPresentationParameters->Windowed = FALSE;
pPresentationParameters->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
pPresentationParameters->FullScreen_RefreshRateInHz = d3ddm.RefreshRate;
}
@ -520,6 +531,8 @@ HRESULT STDMETHODCALLTYPE FakeCreateDevice(IDirect3D9* this, UINT Adapter, D3DDE
log_error(plfD3D9, "CreateDevice failed: %08x", res);
break;
}
} else {
g_pd3dDevice = *ppReturnedDeviceInterface;
}
log_info(plfD3D9, "Device created: %d", res);

View File

@ -30,23 +30,34 @@ int WINAPIV Fakeprintf(const char* _Format, ...) {
va_list args;
va_start(args, _Format);
int ret = vlog_game(plfPrintf, _Format, args);
int ret = vlog_game(plfStdout, _Format, args);
va_end(args);
return ret;
}
int WINAPIV Fakefprintf(FILE* _File, const char* _Format, ...) {
size_t flen = strlen(_Format);
if (flen == strcspn(_Format, "\n") + 1 && flen < (sizeof format_buf)) {
strcpy_s(format_buf, WORK_FORMAT_MAX, _Format);
format_buf[flen - 1] = 0;
_Format = format_buf;
}
va_list args;
va_start(args, _Format);
int ret;
int ret = vlog_game(plfFprintf, _Format, args);
// log_game(plfStdout, "file: %d %p %p %p", _fileno(_File), _File, stdout, stderr);
// STDOUT_FILENO
// TODO: wtf.
_File = stdout;
if (_File != stdout && _File != stderr) {
// ret = vfprintf(_File, _Format, args);
ret = 0;
} else {
size_t flen = strlen(_Format);
if (flen == strcspn(_Format, "\n") + 1 && flen < (sizeof format_buf)) {
strcpy_s(format_buf, WORK_FORMAT_MAX, _Format);
format_buf[flen - 1] = 0;
_Format = format_buf;
}
ret = vlog_game(_File == stdout ? plfStdout : plfStderr, _Format, args);
}
va_end(args);
return ret;

View File

@ -120,8 +120,18 @@ BOOL WINAPI FakeGetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode) {
return TRUE;
}
HINSTANCE WINAPI FakeShellExecuteA(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile,
LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd) {
MiceFSRedirectPathA(lpFile, &lpFile);
if (lpDirectory) MiceFSRedirectPathA(lpDirectory, &lpDirectory);
return TrueShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd);
}
void hook_processes() {
hook("Kernel32.dll", "CreateProcessW", FakeCreateProcessW, (void**)&TrueCreateProcessW);
hook("Kernel32.dll", "CreateProcessA", FakeCreateProcessA, (void**)&TrueCreateProcessA);
hook("Kernel32.dll", "GetExitCodeProcess", FakeGetExitCodeProcess, NULL);
// hook("Shell32.dll", "ShellExecuteA", FakeShellExecuteA, (void**)TrueShellExecuteA);
// TODO: ShellExecuteA
}

View File

@ -15,5 +15,7 @@ static BOOL(WINAPI* TrueCreateProcessA)(LPCSTR lpApplicationName, LPSTR lpComman
LPVOID lpEnvironment, LPCSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation);
static HINSTANCE(WINAPI* TrueShellExecuteA)(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile,
LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd);
void hook_processes();

View File

@ -106,9 +106,11 @@ void hook_system() {
// hook("User32.dll", "DeleteObject", FakeDeleteObject, NULL);
const char* SystemVersion = "00691001\r\n";
const char* DefaultSystemVersion = "00000303\r\n";
const char* UpdateVersion = "0000\r\n";
HANDLE hGM = CreateFileA("GrooveMaster.ini", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
HANDLE hGM = CreateFileA("GrooveMaster.ini", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
0, NULL);
BOOL bGmIs1P = FALSE;
if (hGM != INVALID_HANDLE_VALUE) {
CHAR line[256];
@ -137,7 +139,7 @@ void hook_system() {
if (bGmIs1P) {
const char* GrooveMaster1P =
("# TODO: Get maimai_deliver not rebooting the cab\r\n"
"NO_DELIVER 1\r\n"
// "NO_DELIVER 1\r\n"
"# TODO: figure out how to do this without also needing a USB\r\n"
"USB_DL_DISABLE 1\r\n"
"# These are just easier to do via GM than a patch\r\n"
@ -149,14 +151,14 @@ void hook_system() {
} else {
const char* GrooveMaster =
("# TODO: Get maimai_deliver not rebooting the cab\r\n"
"NO_DELIVER 1\r\n"
// "NO_DELIVER 1\r\n"
"# TODO: figure out how to do this without also needing a USB\r\n"
"USB_DL_DISABLE 1\r\n"
"# These are just easier to do via GM than a patch\r\n"
"NO_REBOOT 1\r\n"
"ROTATE 1\r\n");
hook_file_with_buffer(L"GrooveMaster.ini", (LPBYTE)GrooveMaster,
strlen(GrooveMaster) + 1, GENERIC_READ);
hook_file_with_buffer(L"GrooveMaster.ini", (LPBYTE)GrooveMaster, strlen(GrooveMaster) + 1,
GENERIC_READ);
}
const char* RingmasterPub =
@ -172,6 +174,8 @@ void hook_system() {
// more generic.
hook_file_with_buffer(L"C:\\System\\SystemVersion.txt", (LPBYTE)SystemVersion,
strlen(SystemVersion) + 1, GENERIC_READ);
hook_file_with_buffer(L"C:\\System\\DefaultSystemVersion.txt", (LPBYTE)DefaultSystemVersion,
strlen(DefaultSystemVersion) + 1, GENERIC_READ);
hook_file_with_buffer(L"C:\\System\\UpdateVersion.txt", (LPBYTE)UpdateVersion,
strlen(UpdateVersion) + 1, GENERIC_READ);
hook_file_with_buffer(L"c:\\System\\Execute\\ringmaster_pub.pem", (LPBYTE)RingmasterPub,

View File

@ -351,7 +351,7 @@ BOOL MiceFSRedirectPathA(LPCSTR lpFilename, LPCSTR* pszRedirected) {
MultiByteToWideChar(0, 0, _redirected_path, -1, szwPath, _countof(szwPath));
if (FileExistsW(szwPath)) {
if (FileOrFolderExistsW(szwPath)) {
MiceReleaseLockShared(miceFsLockCount);
return TRUE;
}
@ -414,7 +414,7 @@ BOOL MiceFSDebugTraceRedirectPathA(LPCSTR lpFilename, LPCSTR* pszRedirected) {
MultiByteToWideChar(0, 0, _redirected_path, -1, szwPath, _countof(szwPath));
printf("-> %s\n", _redirected_path);
if (FileExistsW(szwPath)) {
if (FileOrFolderExistsW(szwPath)) {
MiceReleaseLockShared(miceFsLockCount);
printf(":: Redirect ended with valid redirection found.");
return TRUE;

View File

@ -2,6 +2,7 @@
#include "hook.h"
BOOL FileOrFolderExistsW(const wchar_t* szPath);
BOOL FileExistsW(const wchar_t* szPath);
BOOL FileExistsA(const char* szPath);
PVOID GetDataForHandle(HANDLE hObject);

View File

@ -31,6 +31,10 @@ void PrintStack(void) {
free(symbol);
}
BOOL FileOrFolderExistsW(const wchar_t* szPath) {
DWORD dwAttrib = _GetFileAttributesW(szPath);
return (dwAttrib != INVALID_FILE_ATTRIBUTES);
}
BOOL FileExistsW(const wchar_t* szPath) {
DWORD dwAttrib = _GetFileAttributesW(szPath);
return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));

View File

@ -20,6 +20,7 @@ executable(
dummyinstaller,
dummygdeliver,
dummynetwork,
dummystorage,
amSerialId,
],

View File

@ -9,6 +9,7 @@ spawn_t mxspawns[] = {
{ "installer", SPAWN_DUMMY, MdiThreadProc, NULL },
{ "network", SPAWN_DUMMY, MdnThreadProc, NULL },
{ "gdeliver", SPAWN_DUMMY, MdgdThreadProc, NULL },
{ "storage", SPAWN_DUMMY, MdsThreadProc, NULL },
};
int mxkMain();
@ -17,6 +18,7 @@ int miceDummyMaster(unsigned short textPort, unsigned short binaryPort, bool glo
int miceDummyInstaller(unsigned short textPort, unsigned short binaryPort, bool global);
int miceDummyNetwork(unsigned short textPort, unsigned short binaryPort, bool global);
int miceDummyGDeliver(unsigned short textPort, unsigned short binaryPort, bool global);
int miceDummyStorage(unsigned short textPort, unsigned short binaryPort, bool global);
DWORD WINAPI MdkThreadProc(LPVOID lpParameter) {
miceDummyKeychip(40106, 40107, false);
return 0;
@ -41,6 +43,10 @@ DWORD WINAPI MdgdThreadProc(LPVOID lpParameter) {
miceDummyGDeliver(40108, 40112, false);
return 0;
}
DWORD WINAPI MdsThreadProc(LPVOID lpParameter) {
miceDummyStorage(40114, 40115, false);
return 0;
}
static inline void spawn_one(spawn_t* spawn) {
if (spawn->mode == SPAWN_NONE) {

View File

@ -12,7 +12,7 @@ typedef struct {
#define SPAWN_REAL 2
#define SPAWN_BOTH (SPAWN_DUMMY | SPAWN_REAL)
extern spawn_t mxspawns[5];
extern spawn_t mxspawns[6];
DWORD WINAPI MxkThreadProc(LPVOID lpParameter);
DWORD WINAPI MdkThreadProc(LPVOID lpParameter);
@ -20,5 +20,6 @@ DWORD WINAPI MdmThreadProc(LPVOID lpParameter);
DWORD WINAPI MdiThreadProc(LPVOID lpParameter);
DWORD WINAPI MdnThreadProc(LPVOID lpParameter);
DWORD WINAPI MdgdThreadProc(LPVOID lpParameter);
DWORD WINAPI MdsThreadProc(LPVOID lpParameter);
void spawn_pcp_processes(void);

View File

@ -1,3 +1,7 @@
#ifndef MICE_VERSION
#define MICE_VERSION "Unk"
#endif
#define AM_LIB_C_HEADER(name, storage_type) \
int name##DebugLevel = 0; \
struct storage_type name; \

View File

@ -4,3 +4,4 @@
#include "amOemstring.h"
#include "amPlatform.h"
#include "amSram.h"
#include "amLog.h"

View File

@ -0,0 +1,407 @@
#include "amBackup.h"
#include "../ami/amiCrc.h"
#include "../ami/amiDebug.h"
AM_LIB_C_HEADER(amBackup, AM_BACKUP)
AM_BACKUP_STATUS amBackupInit(void) {
if (amBackup.m_Init) return AM_BACKUP_STATUS_ALREADY_INIT;
ZeroMemory(&amBackup, sizeof amBackup);
amiCrc32RCreateTable(amBackup.m_CrcTable);
amBackup.m_Init = TRUE;
return AM_BACKUP_STATUS_OK;
}
AM_BACKUP_STATUS amBackupExit(void) {
if (!amBackup.m_Init) return AM_BACKUP_STATUS_NO_INIT;
ZeroMemory(&amBackup, sizeof amBackup);
return AM_BACKUP_STATUS_OK;
}
static BOOL amBackupValidateAddress(AM_PLATFORM_NV_DEVICE_CONFIG *lpConfig, DWORD wAddress,
WORD wCount) {
if (lpConfig == NULL) return FALSE;
if (wAddress < lpConfig->m_Base) return FALSE;
if (wAddress + wCount > lpConfig->m_Base + lpConfig->m_Size) return FALSE;
DWORD mask = lpConfig->m_BlockSize - 1;
if ((wAddress & mask) != 0) return FALSE;
if ((wCount & mask) != 0) return FALSE;
if (wCount > lpConfig->m_Size) return FALSE;
return TRUE;
}
AM_BACKUP_STATUS amBackupWrite(AM_PLATFORM_NV_DEVICE_CONFIG *lpConfig, LPVOID lpBuffer,
WORD wAddress, WORD wCount) {
if (amBackup.m_Init == 0) return AM_BACKUP_STATUS_NO_INIT;
if (lpConfig == NULL || lpBuffer == NULL) return AM_BACKUP_STATUS_INVALID_PARAM;
if (!amBackupValidateAddress(lpConfig, wAddress, wCount)) {
if (amBackupDebugLevel > 0) amiDebugLog("invalid address.");
return AM_BACKUP_STATUS_INVALID_ADDR;
}
if (lpConfig->m_WriteFunc == NULL) {
if (amBackupDebugLevel > 0) amiDebugLog("No Write Function Error!.");
return AM_BACKUP_STATUS_INVALID_STORAGE;
}
return (lpConfig->m_WriteFunc)(wAddress, lpBuffer, wCount);
}
AM_BACKUP_STATUS amBackupRecordCheckValid(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer) {
if (!amBackup.m_Init) return AM_BACKUP_STATUS_NO_INIT;
if (lpConfig == NULL || lpBuffer == NULL) return AM_BACKUP_STATUS_INVALID_PARAM;
LPDWORD bufferAsDW = (LPDWORD)lpBuffer;
if (lpConfig->m_bHasCrc) {
DWORD calcCrc =
amiCrc32RGet(amBackup.m_CrcTable, lpConfig->m_wCount - 4, bufferAsDW + 1, 0);
if (calcCrc != bufferAsDW[0]) {
if (amBackupDebugLevel > 0)
amiDebugLog("crc error. NewCrc=%08X OrgCrc=%08X", calcCrc, bufferAsDW[0]);
return AM_BACKUP_STATUS_BAD_CRC;
}
bufferAsDW++;
}
if (lpConfig->m_bHasID) {
if (*(LPDWORD)(lpConfig->m_sID) != bufferAsDW[0]) {
if (amBackupDebugLevel > 0)
amiDebugLog("id error. NewId=%08x OrgId=%08x", *(LPDWORD)lpConfig->m_sID,
bufferAsDW[0]);
return AM_BACKUP_STATUS_BAD_ID;
}
}
return AM_BACKUP_STATUS_OK;
}
AM_BACKUP_STATUS amBackupRead(AM_PLATFORM_NV_DEVICE_CONFIG *lpConfig, WORD wAddress,
LPVOID lpBuffer, WORD wCount) {
if (!amBackup.m_Init) return AM_BACKUP_STATUS_NO_INIT;
if (lpConfig == NULL || lpBuffer == NULL) return AM_BACKUP_STATUS_INVALID_PARAM;
if (!amBackupValidateAddress(lpConfig, wAddress, wCount)) {
if (amBackupDebugLevel > 0) amiDebugLog("invalid address.");
return AM_BACKUP_STATUS_INVALID_ADDR;
}
if (lpConfig->m_ReadFunc == NULL) {
if (amBackupDebugLevel > 0) amiDebugLog("No Read Function Error!.");
return AM_BACKUP_STATUS_INVALID_STORAGE;
}
return (lpConfig->m_ReadFunc)(wAddress, lpBuffer, wCount);
}
AM_BACKUP_STATUS amBackupRecordRead(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer) {
if (!amBackup.m_Init) return AM_BACKUP_STATUS_NO_INIT;
if (lpConfig == NULL || lpBuffer == NULL) return AM_BACKUP_STATUS_INVALID_PARAM;
AM_PLATFORM_NV_DEVICE_CONFIG *device = amPlatformGetNvDevice(lpConfig->m_Device);
if (device == NULL) return AM_BACKUP_STATUS_NO_DEVICE;
int err = amBackupRead(device, lpConfig->m_wAddress, lpBuffer, lpConfig->m_wCount);
if (err < 0) return err;
err = amBackupRecordCheckValid(lpConfig, lpBuffer);
return err >= 0 ? AM_BACKUP_STATUS_OK : err;
}
AM_BACKUP_STATUS amBackupRecordReadDup(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer) {
if (!amBackup.m_Init) return AM_BACKUP_STATUS_NO_INIT;
if (lpConfig == NULL || lpBuffer == NULL) return AM_BACKUP_STATUS_INVALID_PARAM;
int err = amBackupRecordRead(lpConfig, lpBuffer);
if (err > -1) return AM_BACKUP_STATUS_OK;
if (err < -19) {
err = amBackupRecordRead(lpConfig + 1, lpBuffer);
if (-1 < err) return amBackupRecordWrite(lpConfig, lpBuffer);
}
return err;
}
AM_BACKUP_STATUS amBackupRecordValidate(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer) {
if (!amBackup.m_Init) return AM_BACKUP_STATUS_NO_INIT;
if (lpConfig == NULL || lpBuffer == NULL) return AM_BACKUP_STATUS_INVALID_PARAM;
LPBYTE lpData = (LPBYTE)lpBuffer;
WORD wCount = lpConfig->m_wCount;
if (lpConfig->m_bHasCrc) {
wCount -= 4;
lpData += 4;
}
if (lpConfig->m_bHasID) {
*((LPDWORD)lpData) = *(LPDWORD)lpConfig->m_sID;
lpData += 4;
wCount -= 4;
}
if (lpConfig->m_bHasCrc) {
*((LPDWORD)lpBuffer) = amiCrc32RGet(amBackup.m_CrcTable, wCount, lpData, 0);
}
return AM_BACKUP_STATUS_OK;
}
AM_BACKUP_STATUS amBackupRecordWrite(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer) {
if (!amBackup.m_Init) return AM_BACKUP_STATUS_NO_INIT;
if (lpConfig == NULL || lpBuffer == NULL) return AM_BACKUP_STATUS_INVALID_PARAM;
AM_PLATFORM_NV_DEVICE_CONFIG *device = amPlatformGetNvDevice(lpConfig->m_Device);
if (device == NULL) return AM_BACKUP_STATUS_NO_DEVICE;
int err = amBackupRecordValidate(lpConfig, lpBuffer);
if (err < 0) return err;
err = amBackupWrite(device, lpBuffer, lpConfig->m_wAddress, lpConfig->m_wCount);
return err >= 0 ? AM_BACKUP_STATUS_OK : err;
}
AM_BACKUP_STATUS amBackupRecordWriteDup(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer) {
if (!amBackup.m_Init) return AM_BACKUP_STATUS_NO_INIT;
if (lpConfig == NULL || lpBuffer == NULL) return AM_BACKUP_STATUS_INVALID_PARAM;
int err = amBackupRecordWrite(&(lpConfig[1]), lpBuffer);
if (err + 19 <= 18) return err;
return amBackupRecordWrite(&(lpConfig[0]), lpBuffer);
}
static AM_BACKUP_RECORD _amBackupStructs[12][2] = {
// AM_BACKUP_RECORD_STATIC
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x000,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x200,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_CREDIT
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x020,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x220,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_NETWORK_ETH0
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x040,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x240,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_NETWORK_ETH1
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x060,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x260,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_HISTORY
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x080,
.m_wCount = 0x10,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x280,
.m_wCount = 0x10,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_ALPB_CARD_ID
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x090,
.m_wCount = 0x10,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x290,
.m_wCount = 0x10,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_ALPB_COMPUTER_NAME
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x0a0,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x2a0,
.m_wCount = 0x20,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_BACKUP
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_SRAM,
.m_wAddress = 0x0000,
.m_wCount = 0x200,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_SRAM,
.m_wAddress = 0x1000,
.m_wCount = 0x200,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_HM_PEAK
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_SRAM,
.m_wAddress = 0x0200,
.m_wCount = 0x200,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_SRAM,
.m_wAddress = 0x1200,
.m_wCount = 0x200,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_TIMEZONE
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_SRAM,
.m_wAddress = 0x0400,
.m_wCount = 0x200,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_SRAM,
.m_wAddress = 0x1400,
.m_wCount = 0x200,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_ERROR_LOG
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_SRAM,
.m_wAddress = 0x0600,
.m_wCount = 0x200,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_SRAM,
.m_wAddress = 0x1600,
.m_wCount = 0x200,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
// AM_BACKUP_RECORD_ALPB_DEV_CONFIG
{
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x0c0,
.m_wCount = 0x40,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
{
.m_Device = AM_PLATFORM_NV_DEVICE_EEPROM,
.m_wAddress = 0x2c0,
.m_wCount = 0x40,
.m_bHasCrc = TRUE,
.m_bHasID = FALSE,
.m_sID = 0,
},
},
};
AM_BACKUP_RECORD *amBackupGetRecord(DWORD dwWhich) {
if (dwWhich < 12) return (AM_BACKUP_RECORD *)&(_amBackupStructs[dwWhich]);
return NULL;
}

View File

@ -1,10 +1,67 @@
void amBackupInit(void);
void amBackupExit(void);
void amBackupRead(void);
void amBackupRecordCheckValid(void);
void amBackupRecordReadDup(void);
void amBackupRecordWriteDup(void);
void amBackupRecordValidate(void);
void amBackupRecordWrite(void);
void amBackupRecordWriteDup(void);
void amBackupWrite(void);
#pragma once
#include <Windows.h>
#include <stdint.h>
#include "../_am.h"
#include "amPlatform.h"
AM_LIB_H_HEADER(amBackup, AM_BACKUP)
typedef struct AM_BACKUP {
BOOL m_Init;
uint32_t m_CrcTable[256];
} AM_BACKUP;
typedef enum AM_BACKUP_STATUS {
AM_BACKUP_STATUS_OK = 0,
AM_BACKUP_STATUS_NO_DEVICE = -21,
AM_BACKUP_STATUS_INVALID_ADDR = -22,
AM_BACKUP_STATUS_BAD_CRC = -23,
AM_BACKUP_STATUS_BAD_ID = -24,
AM_BACKUP_STATUS_INVALID_STORAGE = -25,
AM_BACKUP_STATUS_INVALID_PARAM = -27,
AM_BACKUP_STATUS_NO_INIT = -28,
AM_BACKUP_STATUS_ALREADY_INIT = -29,
} AM_BACKUP_STATUS;
typedef struct AM_BACKUP_RECORD {
AM_PLATFORM_NV_DEVICE m_Device;
WORD m_wAddress;
WORD m_wCount;
BOOL m_bHasCrc;
BOOL m_bHasID;
CHAR m_sID[4];
} AM_BACKUP_RECORD;
typedef enum AM_BACKUP_RECORD_N {
AM_BACKUP_RECORD_STATIC = 0,
AM_BACKUP_RECORD_CREDIT = 1,
AM_BACKUP_RECORD_NETWORK_ETH0 = 2,
AM_BACKUP_RECORD_NETWORK_ETH1 = 3,
AM_BACKUP_RECORD_HISTORY = 4,
AM_BACKUP_RECORD_ALPB_CARD_ID = 5,
AM_BACKUP_RECORD_ALPB_COMPUTER_NAME = 6,
AM_BACKUP_RECORD_BACKUP = 7,
AM_BACKUP_RECORD_HM_PEAK = 8,
AM_BACKUP_RECORD_TIMEZONE = 9,
AM_BACKUP_RECORD_ERROR_LOG = 10,
AM_BACKUP_RECORD_ALPB_DEV_CONFIG = 11,
} AM_BACKUP_RECORD_N;
AM_BACKUP_STATUS amBackupInit(void);
AM_BACKUP_STATUS amBackupExit(void);
AM_BACKUP_STATUS amBackupWrite(AM_PLATFORM_NV_DEVICE_CONFIG *lpConfig, LPVOID lpBuffer,
WORD wAddress, WORD wCount);
AM_BACKUP_STATUS amBackupRecordWrite(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer);
AM_BACKUP_STATUS amBackupRecordWriteDup(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer);
AM_BACKUP_STATUS amBackupRecordValidate(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer);
AM_BACKUP_STATUS amBackupRead(AM_PLATFORM_NV_DEVICE_CONFIG *lpConfig, WORD wAddress,
LPVOID lpBuffer, WORD wCount);
AM_BACKUP_STATUS amBackupRecordRead(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer);
AM_BACKUP_STATUS amBackupRecordReadDup(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer);
AM_BACKUP_STATUS amBackupRecordCheckValid(AM_BACKUP_RECORD *lpConfig, LPVOID lpBuffer);
AM_BACKUP_RECORD *amBackupGetRecord(DWORD dwWhich);

View File

@ -1,25 +1,27 @@
#include "amCmos.h"
#include "../mice/ioctl.h"
AM_LIB_C_HEADER(amCmos, AM_CMOS)
AM_CMOS_STATUS amCmosInit(AM_CMOS_CONFIG *lpConfig) {
AM_CMOS_STATUS amCmosInit(AM_PLATFORM_CMOS_PARAM *lpParam) {
if (amCmos.m_bInit != 0) return AM_CMOS_STATUS_ERR_ALREADY_INIT;
if (lpConfig == NULL) return AM_CMOS_STATUS_ERR_INVALID_PARAM;
if (lpParam == NULL) return AM_CMOS_STATUS_ERR_INVALID_PARAM;
HANDLE hMutex = CreateMutexA(NULL, 0, "AM_CMOS_MUTEX");
if (hMutex == NULL) return AM_CMOS_STATUS_ERR_SYS;
HANDLE hCmos = CreateFileA("\\\\.\\mxcmos", 0xc0000000, 3, NULL, 3, 0, NULL);
if (hCmos == INVALID_HANDLE_VALUE) {
HANDLE hDriver = CreateFileA("\\\\.\\mxcmos", 0xc0000000, 3, NULL, 3, 0, NULL);
if (hDriver == INVALID_HANDLE_VALUE) {
CloseHandle(hMutex);
return AM_CMOS_STATUS_ERR_OPEN_FAILED;
}
amCmos.m_bInit = TRUE;
amCmos.m_hMutex = hMutex;
amCmos.m_hCmos = hCmos;
amCmos.m_hDriver = hDriver;
memcpy(&amCmos.m_Config, lpConfig, sizeof *lpConfig);
memcpy(&amCmos.m_Param, lpParam, sizeof *lpParam);
return AM_CMOS_STATUS_OK;
}
@ -31,29 +33,28 @@ AM_CMOS_STATUS amCmosExit(void) {
CloseHandle(amCmos.m_hMutex);
amCmos.m_hMutex = NULL;
}
if (amCmos.m_hCmos != INVALID_HANDLE_VALUE) {
CloseHandle(amCmos.m_hCmos);
amCmos.m_hCmos = INVALID_HANDLE_VALUE;
if (amCmos.m_hDriver != INVALID_HANDLE_VALUE) {
CloseHandle(amCmos.m_hDriver);
amCmos.m_hDriver = INVALID_HANDLE_VALUE;
}
amCmos.m_bInit = FALSE;
return AM_CMOS_STATUS_OK;
}
AM_CMOS_STATUS amCmosReadByteInRearpart(BYTE nIndex, LPBYTE lpData) {
AM_CMOS_STATUS amCmosReadByteInRearpart(BYTE addr, LPBYTE lpValue) {
if (amCmos.m_bInit == 0) return AM_CMOS_STATUS_ERR_NO_INIT;
if (lpData == NULL || nIndex > 0x7f) return AM_CMOS_STATUS_ERR_INVALID_PARAM;
if (lpValue == NULL || addr > 0x7f) return AM_CMOS_STATUS_ERR_INVALID_PARAM;
if (WaitForSingleObject(amCmos.m_hMutex, 0) != WAIT_OBJECT_0) return AM_CMOS_STATUS_ERR_LOCK;
BYTE request[2];
request[0] = nIndex;
request[0] = addr;
request[1] = 0;
DWORD nBytesReturned;
BOOL bErr = DeviceIoControl(amCmos.m_hCmos, IOCTL_MXCMOS_READ, request, sizeof request, lpData,
1, &nBytesReturned, NULL);
BOOL bErr = DeviceIoControl(amCmos.m_hDriver, IOCTL_MXCMOS_READ, request, sizeof request,
lpValue, 1, &nBytesReturned, NULL);
int iRet = 0;
if (!bErr) {
@ -69,3 +70,85 @@ AM_CMOS_STATUS amCmosReadByteInRearpart(BYTE nIndex, LPBYTE lpData) {
}
return iRet;
}
AM_CMOS_STATUS amCmosWriteByteInRearpart(BYTE addr, BYTE value) {
if (amCmos.m_bInit == 0) return AM_CMOS_STATUS_ERR_NO_INIT;
if (addr > 0x7f) return AM_CMOS_STATUS_ERR_INVALID_PARAM;
if (WaitForSingleObject(amCmos.m_hMutex, 0) != WAIT_OBJECT_0) return AM_CMOS_STATUS_ERR_LOCK;
BYTE request[2];
request[0] = addr;
request[1] = value;
DWORD nBytesReturned;
BOOL bErr = DeviceIoControl(amCmos.m_hDriver, IOCTL_MXCMOS_READ, request, sizeof request,
NULL, 0, &nBytesReturned, NULL);
if (!ReleaseMutex(amCmos.m_hMutex)) {
if (amCmosDebugLevel > 0)
amiDebugLog("ReleaseMutex Error!! Error Code is %ld!!", GetLastError());
return AM_CMOS_STATUS_ERR_SYS;
}
return bErr ? AM_CMOS_STATUS_OK : AM_CMOS_STATUS_ERR_SYS;
}
AM_CMOS_STATUS amCmosSetPartition(BYTE addr, BYTE bitOffset, BYTE mbrCount, BYTE partition) {
if (!amCmos.m_bInit) return AM_CMOS_STATUS_ERR_NO_INIT;
if (partition > 4) return AM_CMOS_STATUS_ERR_INVALID_PARAM;
if (addr == 0 || bitOffset > 8) return AM_CMOS_STATUS_NG;
BYTE bValue;
AM_CMOS_STATUS err = amCmosReadByteInRearpart(addr, &bValue);
if (amCmosReadByteInRearpart(addr, &bValue)) {
if (amCmosDebugLevel >= 1) amiDebugLog("Error: amCmosReadByteInRearpart()");
return err;
}
if (partition < mbrCount) partition += 5;
/*
parition range: 0, 1, 2, 3, 4, [5]
mbrCount values: 0, 1
-> if partition == 0 && mbrCount == 1 ::-> partition = 5
value range: 0, 1, 2, 3, 4
bO | mask
0 | 11111000 <--
1 | 11110001
2 | 11100011
3 | 11000111
4 | 10001111
5 | 00011111 <--
6 | 00111111
7 | 01111111
bO | value
0 | 00 01 02 03 04 <--
1 | 00 02 04 06 08
2 | 00 04 08 0c 10
3 | 00 08 10 18 20
4 | 00 10 20 30 40
5 | 00 20 40 60 80 <--
6 | 00 40 80 c0 00
7 | 00 80 00 80 00
*/
byte value = partition - mbrCount;
byte mask = 0b11111000;
for (int uVar4 = bitOffset; uVar4 != 0; uVar4--) {
mask = (mask << 1) | 1;
value <<= 1;
}
return amCmosWriteByteInRearpart(addr, (bValue & mask) | value);
}
AM_CMOS_STATUS amCmosSetPartition_0(byte partition) {
return amCmosSetPartition(amCmos.m_Param.index[0][0], amCmos.m_Param.index[0][1],
amCmos.m_Param.m_MbrCount, partition);
}
AM_CMOS_STATUS amCmosSetPartition_1(byte partition) {
return amCmosSetPartition(amCmos.m_Param.index[1][0], amCmos.m_Param.index[1][1],
amCmos.m_Param.m_MbrCount, partition);
}

View File

@ -4,6 +4,7 @@
#include "../../dll/smbus.h"
#include "../_am.h"
#include "./amPlatform.h"
AM_LIB_H_HEADER(amCmos, AM_CMOS)
@ -18,22 +19,20 @@ typedef enum {
AM_CMOS_STATUS_ERR_LOCK = -7,
} AM_CMOS_STATUS;
typedef struct AM_CMOS_CONFIG {
BYTE index[4];
BYTE m_MbrCount;
} AM_CMOS_CONFIG;
typedef struct AM_CMOS {
BOOL m_bInit;
HANDLE m_hMutex;
HANDLE m_hCmos;
AM_CMOS_CONFIG m_Config;
HANDLE m_hDriver;
AM_PLATFORM_CMOS_PARAM m_Param;
} AM_CMOS;
AM_CMOS_STATUS amCmosInit(AM_CMOS_CONFIG* lpConfig);
AM_CMOS_STATUS amCmosInit(AM_PLATFORM_CMOS_PARAM* lpParam);
AM_CMOS_STATUS amCmosExit(void);
AM_CMOS_STATUS amCmosReadByteInRearpart(BYTE param_1, LPBYTE param_2);
void amCmosWriteByteInRearpart(void);
void amCmosSetPartition(void);
AM_CMOS_STATUS amCmosReadByteInRearpart(BYTE addr, LPBYTE lpValue);
AM_CMOS_STATUS amCmosWriteByteInRearpart(BYTE addr, BYTE value);
AM_CMOS_STATUS amCmosSetPartition(BYTE addr, BYTE bitOffset, BYTE mbrCount, BYTE partition);
AM_CMOS_STATUS amCmosSetPartition_0(byte partition);
AM_CMOS_STATUS amCmosSetPartition_1(byte partition);

View File

@ -18,8 +18,7 @@ HANDLE amEepromCreateDeviceFile(const GUID *guid, LPCSTR resource, DWORD member_
HDEVINFO DeviceInfoSet =
SetupDiGetClassDevsA(guid, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
if (DeviceInfoSet == INVALID_HANDLE_VALUE) {
if (amEepromDebugLevel > 0)
amiDebugLog("SetupDiGetClassDevs Error(%ld).", GetLastError());
if (amEepromDebugLevel > 0) amiDebugLog("SetupDiGetClassDevs Error(%ld).", GetLastError());
return INVALID_HANDLE_VALUE;
}
@ -96,8 +95,7 @@ AM_EEPROM_STATUS amEepromCreateMutex(AM_EEPROM *device) {
idAuth.Value[5] = 1;
if (!AllocateAndInitializeSid(&idAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, pSid)) {
if (amEepromDebugLevel > 0)
amiDebugLog("AllocateAndInitializeSid Error in amEepromInit.");
if (amEepromDebugLevel > 0) amiDebugLog("AllocateAndInitializeSid Error in amEepromInit.");
*pSid = NULL;
goto amEepromCreateMutexError;
}
@ -109,8 +107,7 @@ AM_EEPROM_STATUS amEepromCreateMutex(AM_EEPROM *device) {
}
if (!SetSecurityDescriptorDacl(&securityDescriptor, TRUE, NULL, FALSE)) {
if (amEepromDebugLevel > 0)
amiDebugLog("SetSecurityDescriptorDacl Error in amEepromInit.");
if (amEepromDebugLevel > 0) amiDebugLog("SetSecurityDescriptorDacl Error in amEepromInit.");
goto amEepromCreateMutexError;
}
@ -159,8 +156,7 @@ AM_EEPROM_STATUS amEepromInit(AM_EEPROM_TIMEOUT *timeout) {
amEeprom.m_superio = amEepromCreateDeviceFile(&MXSMBUS_GUID, 0, 0);
if (amEeprom.m_superio == INVALID_HANDLE_VALUE) {
if (amEepromDebugLevel > 0)
amiDebugLog("amEepromCreateDeviceFile Error in amEepromInit.");
if (amEepromDebugLevel > 0) amiDebugLog("amEepromCreateDeviceFile Error in amEepromInit.");
ret = AM_EEPROM_STATUS_ERR_SYS;
goto amEepromInitError;
}
@ -176,7 +172,7 @@ AM_EEPROM_STATUS amEepromInit(AM_EEPROM_TIMEOUT *timeout) {
if (amEepromDebugLevel > 0)
amiDebugLog(
"Unknown SMBUS Driver Protocol(0x%08x). Please update SMBUS driver or user "
"program.\n",
"program.",
driverVersion);
ret = AM_EEPROM_STATUS_ERR_PROTOCOL_VER;
@ -238,8 +234,8 @@ BOOL amEepromI2CReadBlock(AM_EEPROM *device, WORD reg, BYTE nBytes, LPBYTE buffe
if (packet.status != 0) {
if (amEepromDebugLevel > 0)
amiDebugLog(" .. SMBus read error. prt=0x%02x addr=0x%02x reg=0x%04x",
packet.command, packet.v_addr, packet.command_code);
amiDebugLog(" .. SMBus read error. prt=0x%02x addr=0x%02x reg=0x%04x", packet.command,
packet.v_addr, packet.command_code);
return false;
}
@ -269,9 +265,8 @@ BOOL amEepromI2CWriteBlock(AM_EEPROM *device, WORD reg, BYTE nBytes, LPBYTE buff
if (packet.status != 0) {
if (amEepromDebugLevel > 0)
amiDebugLog(
" .. SMBus write error. status=0x%02x, prt=0x%02x addr=0x%02x reg=0x%04x\n",
packet.status, packet.command, packet.v_addr, packet.command_code);
amiDebugLog(" .. SMBus write error. status=0x%02x, prt=0x%02x addr=0x%02x reg=0x%04x\n",
packet.status, packet.command, packet.v_addr, packet.command_code);
return false;
}
@ -314,16 +309,14 @@ AM_EEPROM_STATUS amEepromRead(WORD reg, LPBYTE buf, DWORD length) {
DWORD err = WaitForSingleObject(amEeprom.m_mutex, 256);
if (err == WAIT_FAILED) {
if (amEepromDebugLevel > 0)
amiDebugLog("WaitForSingleObject Error(%ld).", GetLastError());
if (amEepromDebugLevel > 0) amiDebugLog("WaitForSingleObject Error(%ld).", GetLastError());
return AM_EEPROM_STATUS_ERR_SYS;
}
if (err == WAIT_TIMEOUT) return AM_EEPROM_STATUS_ERR_GET_MUTEX;
if (!(err == WAIT_OBJECT_0 || err == WAIT_ABANDONED)) {
if (amEepromDebugLevel > 0)
amiDebugLog("WaitForSingleObject Error(%ld). Return Value is %d.", GetLastError(),
err);
amiDebugLog("WaitForSingleObject Error(%ld). Return Value is %d.", GetLastError(), err);
return AM_EEPROM_STATUS_ERR_SYS;
}
@ -359,16 +352,14 @@ AM_EEPROM_STATUS amEepromWrite(WORD reg, LPBYTE buf, DWORD length) {
DWORD err = WaitForSingleObject(amEeprom.m_mutex, 256);
if (err == WAIT_FAILED) {
if (amEepromDebugLevel > 0)
amiDebugLog("WaitForSingleObject Error(%ld).", GetLastError());
if (amEepromDebugLevel > 0) amiDebugLog("WaitForSingleObject Error(%ld).", GetLastError());
return AM_EEPROM_STATUS_ERR_SYS;
}
if (err == WAIT_TIMEOUT) return AM_EEPROM_STATUS_ERR_GET_MUTEX;
if (!(err == WAIT_OBJECT_0 || err == WAIT_ABANDONED)) {
if (amEepromDebugLevel > 0)
amiDebugLog("WaitForSingleObject Error(%ld). Return Value is %d.", GetLastError(),
err);
amiDebugLog("WaitForSingleObject Error(%ld). Return Value is %d.", GetLastError(), err);
return AM_EEPROM_STATUS_ERR_SYS;
}

View File

@ -0,0 +1,69 @@
#include "amLog.h"
AM_LIB_C_HEADER(amLog, AM_LOG)
int amLogInit(void) {
if (amLog.m_Init) return AM_LOG_STATUS_ERR_ALREADY_INIT;
amLog.m_Option.m_EventSource = "am";
amLog.m_Option.m_EventType = 1;
amLog.m_Option.m_EventCategory = 0;
amLog.m_Option.m_EventId = 0;
amLog.m_Init = TRUE;
return AM_LOG_STATUS_OK;
}
int amLogFinalize(void) {
if (!amLog.m_Init) return AM_LOG_STATUS_ERR_INVALID_PARAM;
amLog.m_Option.m_EventSource = NULL;
amLog.m_Option.m_EventType = 0;
amLog.m_Option.m_EventCategory = 0;
amLog.m_Option.m_EventId = 0;
amLog.m_Init = FALSE;
return AM_LOG_STATUS_OK;
}
int amLogSetEventOption(AM_LOG_OPTION* lpOption) {
if (!amLog.m_Init) return AM_LOG_STATUS_ERR_INVALID_PARAM;
if (lpOption == NULL) return AM_LOG_STATUS_ERR_NO_INIT;
memcpy_s(&amLog.m_Option, sizeof amLog.m_Option, lpOption, sizeof *lpOption);
return AM_LOG_STATUS_OK;
}
int amLogReportEvent(LPCSTR lpMsg) {
if (!amLog.m_Init) return AM_LOG_STATUS_ERR_INVALID_PARAM;
if (lpMsg == NULL) return AM_LOG_STATUS_ERR_NO_INIT;
HANDLE hEventLog = RegisterEventSourceA(NULL, amLog.m_Option.m_EventSource);
if (hEventLog == INVALID_HANDLE_VALUE) return AM_LOG_STATUS_ERR_REGISTER;
WORD wType;
switch (amLog.m_Option.m_EventType) {
case 0:
wType = 0;
break;
default:
wType = 1;
break;
case 2:
wType = 2;
break;
case 3:
wType = 4;
break;
case 4:
wType = 8;
break;
case 5:
wType = 16;
}
BOOL suc = ReportEventA(hEventLog, wType, amLog.m_Option.m_EventCategory,
amLog.m_Option.m_EventId, NULL, 1, 0, &lpMsg, NULL);
if (!suc) {
DeregisterEventSource(hEventLog);
return AM_LOG_STATUS_ERR_REPORT;
}
DeregisterEventSource(hEventLog);
return AM_LOG_STATUS_OK;
}

View File

@ -1,2 +1,34 @@
void amLogInit(void);
void amLogSetEventOption(void);
#pragma once
#include <Windows.h>
#include "../_am.h"
AM_LIB_H_HEADER(amLog, AM_LOG)
typedef struct AM_LOG_OPTION {
LPCSTR m_EventSource;
DWORD m_EventType;
WORD m_EventId;
WORD m_EventCategory;
} AM_LOG_OPTION;
typedef struct AM_LOG {
BOOL m_Init;
AM_LOG_OPTION m_Option;
} AM_LOG;
typedef enum {
AM_LOG_STATUS_OK = 0,
AM_LOG_STATUS_NG = -1,
AM_LOG_STATUS_ERR_INVALID_PARAM = -2,
AM_LOG_STATUS_ERR_NO_INIT = -3,
AM_LOG_STATUS_ERR_ALREADY_INIT = -4,
AM_LOG_STATUS_ERR_REGISTER = -5,
AM_LOG_STATUS_ERR_REPORT = -6,
} AM_LOG_STATUS;
int amLogInit(void);
int amLogFinalize(void);
int amLogSetEventOption(AM_LOG_OPTION* lpOption);
int amLogReportEvent(LPCSTR lpMsg);

View File

@ -22,6 +22,8 @@ typedef struct AM_OEMSTRING {
CHAR m_strings[5][32];
} AM_OEMSTRING;
#define OEMSTRING_PLATFORM 2
#define OEMSTRING_BOARD_TYPE 4
typedef enum {
AM_OEMSTRING_STATUS_OK = 0,
@ -30,7 +32,6 @@ typedef enum {
AM_OEMSTRING_STATUS_ERR_SYS = -3,
} AM_OEMSTRING_STATUS;
void amiOemstringLocateDMITable(HANDLE hColumba, LPDWORD lpDmiBase, LPWORD lpDmiLength);
void amiOemstringStoreString(BYTE type, int stringno, LPSTR string);
BOOL amiOemstringLoadStrings(void);

View File

@ -16,94 +16,94 @@ AM_PLATFORM_NV_DEVICE_CONFIG amPlatformNvDevices[3][4] = {
// RingEdge 1
{
{
.m_base = 0x0,
.m_size = 0x1000,
.m_blockSize = 1,
.m_read = _amEepromRead,
.m_write = _amEepromWrite,
.m_Base = 0x0,
.m_Size = 0x1000,
.m_BlockSize = 1,
.m_ReadFunc = _amEepromRead,
.m_WriteFunc = _amEepromWrite,
},
{
.m_base = 0x1000,
.m_size = 0x1000,
.m_blockSize = 1,
.m_read = _amEepromRead,
.m_write = _amEepromWrite,
.m_Base = 0x1000,
.m_Size = 0x1000,
.m_BlockSize = 1,
.m_ReadFunc = _amEepromRead,
.m_WriteFunc = _amEepromWrite,
},
{
.m_base = 0,
.m_size = 0x4000,
.m_blockSize = 512,
.m_read = _amSramRead,
.m_write = _amSramWrite,
.m_Base = 0,
.m_Size = 0x4000,
.m_BlockSize = 512,
.m_ReadFunc = _amSramRead,
.m_WriteFunc = _amSramWrite,
},
{
.m_base = 0x4000,
.m_size = 0x1FC000,
.m_blockSize = 512,
.m_read = _amSramRead,
.m_write = _amSramWrite,
.m_Base = 0x4000,
.m_Size = 0x1FC000,
.m_BlockSize = 512,
.m_ReadFunc = _amSramRead,
.m_WriteFunc = _amSramWrite,
},
},
// RingEdge 2
{
{
.m_base = 0x0,
.m_size = 0x1000,
.m_blockSize = 1,
.m_read = _amEepromRead,
.m_write = _amEepromWrite,
.m_Base = 0x0,
.m_Size = 0x1000,
.m_BlockSize = 1,
.m_ReadFunc = _amEepromRead,
.m_WriteFunc = _amEepromWrite,
},
{
.m_base = 0x1000,
.m_size = 0x1000,
.m_blockSize = 1,
.m_read = _amEepromRead,
.m_write = _amEepromWrite,
.m_Base = 0x1000,
.m_Size = 0x1000,
.m_BlockSize = 1,
.m_ReadFunc = _amEepromRead,
.m_WriteFunc = _amEepromWrite,
},
{
.m_base = 0,
.m_size = 0x4000,
.m_blockSize = 4,
.m_read = _amSramRead,
.m_write = _amSramWrite,
.m_Base = 0,
.m_Size = 0x4000,
.m_BlockSize = 4,
.m_ReadFunc = _amSramRead,
.m_WriteFunc = _amSramWrite,
},
{
.m_base = 0x4000,
.m_size = 0x1FC000,
.m_blockSize = 4,
.m_read = _amSramRead,
.m_write = _amSramWrite,
.m_Base = 0x4000,
.m_Size = 0x1FC000,
.m_BlockSize = 4,
.m_ReadFunc = _amSramRead,
.m_WriteFunc = _amSramWrite,
},
},
// RingWide
{
{
.m_base = 0x0,
.m_size = 0x1000,
.m_blockSize = 1,
.m_read = _amEepromRead,
.m_write = _amEepromWrite,
.m_Base = 0x0,
.m_Size = 0x1000,
.m_BlockSize = 1,
.m_ReadFunc = _amEepromRead,
.m_WriteFunc = _amEepromWrite,
},
{
.m_base = 0x1000,
.m_size = 0x1000,
.m_blockSize = 1,
.m_read = _amEepromRead,
.m_write = _amEepromWrite,
.m_Base = 0x1000,
.m_Size = 0x1000,
.m_BlockSize = 1,
.m_ReadFunc = _amEepromRead,
.m_WriteFunc = _amEepromWrite,
},
{
.m_base = 0,
.m_size = 0x4000,
.m_blockSize = 512,
.m_read = _amSramRead,
.m_write = _amSramWrite,
.m_Base = 0,
.m_Size = 0x4000,
.m_BlockSize = 512,
.m_ReadFunc = _amSramRead,
.m_WriteFunc = _amSramWrite,
},
{
.m_base = 0x4000,
.m_size = 0x3C000,
.m_blockSize = 512,
.m_read = _amSramRead,
.m_write = _amSramWrite,
.m_Base = 0x4000,
.m_Size = 0x3C000,
.m_BlockSize = 512,
.m_ReadFunc = _amSramRead,
.m_WriteFunc = _amSramWrite,
},
},
};
@ -135,21 +135,21 @@ AM_PLATFORM_STATUS amPlatformGetPlatformId(AM_PLATFORM_PLATFORM_ID *platformId)
char oemstringManufacturer[32];
/**
* If platform starts with "AAM" (RW) or "AAL" (RE):
* If platform starts with PLATFORM_RINGWIDE (RW) or PLATFORM_RINGEDGE (RE):
* copy it into m_platformId verbatim
* Otherwise
* fetch the manufacturer name
* If manufacturer is "NEC"
* m_platformId = "AAL" (RE)
* If manufacturer if "Supermicro" or "Advantech"
* m_platformId = "AAM" (RW)
* If manufacturer is MANUFACTURER_RE
* m_platformId = PLATFORM_RINGEDGE (RE)
* If manufacturer if MANUFACTURER_RW_1 or MANUFACTURER_RW_2
* m_platformId = PLATFORM_RINGWIDE (RW)
*/
if (!amPlatform.m_platformIdCached) {
if (amOemstringGetOemstring(oemstringPlatform, 2) != AM_OEMSTRING_STATUS_OK) {
if (amOemstringGetOemstring(oemstringPlatform, OEMSTRING_PLATFORM) !=
AM_OEMSTRING_STATUS_OK) {
if (amPlatformDebugLevel > 0)
amiDebugLog("amOemstringGetOemstring Error!! (%d)",
AM_PLATFORM_STATUS_ERR_SYS);
amiDebugLog("amOemstringGetOemstring Error!! (%d)", AM_PLATFORM_STATUS_ERR_SYS);
return AM_PLATFORM_STATUS_ERR_SYS;
}
@ -214,7 +214,8 @@ AM_PLATFORM_STATUS amPlatformGetBoardType(AM_PLATFORM_BOARD_TYPE *boardType) {
if (strcmp(oemstringManufacturer, MANUFACTURER_RE) == 0) {
ZeroMemory(oemstring4, sizeof oemstring4);
if (amOemstringGetOemstring(oemstring4, 4) != AM_OEMSTRING_STATUS_OK) {
if (amOemstringGetOemstring(oemstring4, OEMSTRING_BOARD_TYPE) !=
AM_OEMSTRING_STATUS_OK) {
*boardType = amPlatform.m_boardType = AM_PLATFORM_BOARD_TYPE_UNKNOWN;
return AM_PLATFORM_STATUS_ERR_SYS;
}
@ -237,3 +238,220 @@ AM_PLATFORM_STATUS amPlatformGetBoardType(AM_PLATFORM_BOARD_TYPE *boardType) {
amPlatform.m_boardTypeCached = TRUE;
return AM_PLATFORM_STATUS_OK;
}
AM_PLATFORM_STATUS amPlatformGetPlatformIdEx(AM_PLATFORM_PLATFORM_ID_EX *lpPlatform) {
char oemstring[32];
char manufacturer[32];
if (lpPlatform == NULL) {
if (amPlatformDebugLevel > 0) amiDebugLog("PARAM Error!!");
return AM_PLATFORM_STATUS_ERR_INVALID_PARAM;
}
static char m_strPlatformId[4];
static DWORD m_dwPlatformId;
static bool m_platformIdCached = false;
int err;
ZeroMemory(oemstring, sizeof oemstring);
if (!m_platformIdCached) {
err = amOemstringGetOemstring(oemstring, OEMSTRING_PLATFORM);
if (err != AM_OEMSTRING_STATUS_OK) {
if (amPlatformDebugLevel > 0) amiDebugLog("amOemstringGetOemstring Error!! (%d)", err);
goto oemstring_bad;
}
if (strcmp(oemstring, PLATFORM_RINGEDGE) == 0 ||
strcmp(oemstring, PLATFORM_RINGWIDE) == 0) {
strncpy_s(m_strPlatformId, sizeof m_strPlatformId, oemstring, 0xFFFFFFFF);
} else if (!amOemstringGetManufacturer(manufacturer)) {
if (strcmp(manufacturer, MANUFACTURER_RE) == 0) {
strncpy_s(m_strPlatformId, sizeof m_strPlatformId, PLATFORM_RINGEDGE, 0xFFFFFFFF);
} else if (strcmp(manufacturer, MANUFACTURER_RW_1) == 0 ||
strcmp(manufacturer, MANUFACTURER_RW_2) == 0) {
strncpy_s(m_strPlatformId, sizeof m_strPlatformId, PLATFORM_RINGWIDE, 0xFFFFFFFF);
}
}
oemstring[0] = 0;
err = amOemstringGetOemstring(oemstring, OEMSTRING_BOARD_TYPE);
if (err != AM_OEMSTRING_STATUS_OK) {
if (amPlatformDebugLevel > 0) amiDebugLog("amOemstringGetOemstring Error!! (%d)", err);
goto oemstring_bad;
}
size_t boardTypeLen = strlen(oemstring);
m_dwPlatformId = 0;
if (strcmp(m_strPlatformId, PLATFORM_RINGEDGE) == 0) {
if (boardTypeLen == 0) {
m_dwPlatformId = 1;
m_platformIdCached = true;
goto LABEL_11;
} else if (boardTypeLen == 1) {
if (strcmp(oemstring, " ") == 0) {
m_dwPlatformId = 1;
m_platformIdCached = true;
goto LABEL_11;
}
if (amPlatformDebugLevel > 0) amiDebugLog("Oemstring length Error!!");
goto oemstring_bad;
}
} else if (strcmp(m_strPlatformId, PLATFORM_RINGWIDE) == 0 && boardTypeLen == 0) {
m_dwPlatformId = 1;
m_platformIdCached = true;
goto LABEL_11;
}
if (boardTypeLen < 3) {
if (amPlatformDebugLevel > 0) amiDebugLog("Oemstring length Error!!");
goto oemstring_bad;
}
if (strncmp(m_strPlatformId, oemstring, 3) != 0) {
if (amPlatformDebugLevel > 0) amiDebugLog("Oemstring compare Error!!");
goto oemstring_bad;
}
if (boardTypeLen > 3) {
for (size_t i = 3; i < boardTypeLen; i++) {
if (oemstring[i] < '0' || oemstring[i] > '9') {
if (amPlatformDebugLevel > 0) amiDebugLog("Oemstring format Error!!");
goto oemstring_bad;
}
}
}
m_dwPlatformId = atoi(&oemstring[3]);
if (!m_dwPlatformId) goto oemstring_bad;
m_platformIdCached = true;
}
LABEL_11:
memcpy(lpPlatform->strPlatformId, m_strPlatformId, 4);
lpPlatform->platformId = m_dwPlatformId;
return m_platformIdCached ? AM_PLATFORM_STATUS_OK : AM_PLATFORM_STATUS_ERR_SYS;
oemstring_bad:
if (!m_platformIdCached) {
ZeroMemory(m_strPlatformId, sizeof m_strPlatformId);
m_dwPlatformId = 0;
}
goto LABEL_11;
}
int amPlatformGetBiosInfo(AM_PLATFORM_BIOS_INFO *lpInfo) {
if (lpInfo == NULL) {
if (amPlatformDebugLevel > 0) amiDebugLog("PARAM Error!!");
return AM_PLATFORM_STATUS_ERR_INVALID_PARAM;
}
CHAR biosVer[32];
int err = amOemstringGetSBiosVer(biosVer);
if (err < 0) {
if (amPlatformDebugLevel > 0) amiDebugLog("amOemstringGetSBiosVer Error!! (%d)", err);
return AM_PLATFORM_STATUS_ERR_SYS;
}
CHAR biosReleaseDate[12];
err = amOemstringGetSBiosReleaseDate(biosReleaseDate);
if (err < 0) {
if (amPlatformDebugLevel > 0)
amiDebugLog("amOemstringGetSBiosReleaseDate Error!! (%d)", err);
return AM_PLATFORM_STATUS_ERR_SYS;
}
strncpy_s(lpInfo->m_BiosVer, sizeof lpInfo->m_BiosVer, biosVer, 0xffffffff);
strncpy_s(lpInfo->m_BiosReleaseDate, sizeof lpInfo->m_BiosReleaseDate, biosReleaseDate,
0xffffffff);
return AM_PLATFORM_STATUS_OK;
}
int amPlatformGetOsVersion(DWORD *lpVersion) {
if (lpVersion == NULL) {
if (amPlatformDebugLevel > 0) amiDebugLog("PARAM Error!!");
return AM_PLATFORM_STATUS_ERR_INVALID_PARAM;
}
static DWORD osVersion = 0;
if (osVersion == 0) {
HANDLE hSysver = CreateFileW(L"C:\\System\\SystemVersion.txt", GENERIC_READ, 1, NULL,
OPEN_EXISTING, FILE_SHARE_READ, NULL);
if (hSysver == INVALID_HANDLE_VALUE) {
if (amPlatformDebugLevel > 0)
amiDebugLog("CreateFile Error!! Error Code is %d", GetLastError());
} else {
DWORD nRead = 0;
char buffer[8];
if (!ReadFile(hSysver, buffer, 8, &nRead, NULL)) {
if (amPlatformDebugLevel > 0)
amiDebugLog("ReadFile Error!! Error Code is %d", GetLastError());
} else if (nRead != 8) {
if (amPlatformDebugLevel > 0)
amiDebugLog("ReadFile Error!! Error Code is %d", GetLastError());
} else {
WORD ver1 = (((buffer[0] - '0') * 1000) + ((buffer[1] - '0') * 100) +
(buffer[2] - '0') * 10 + (buffer[3] - '0'));
BYTE ver2 = (buffer[4] - '0') * 10 + (buffer[5] - '0');
BYTE ver3 = (buffer[6] - '0') * 10 + (buffer[7] - '0');
osVersion = (((ver1 << 16) | ver2) << 8) | ver3;
}
CloseHandle(hSysver);
}
}
*lpVersion = osVersion;
return osVersion == 0 ? AM_PLATFORM_STATUS_ERR_SYS : AM_PLATFORM_STATUS_OK;
}
int amPlatformGetMemorySize(PLARGE_INTEGER size) {
if (size == NULL) {
if (amPlatformDebugLevel > 0) amiDebugLog("PARAM Error!!");
return AM_PLATFORM_STATUS_ERR_INVALID_PARAM;
}
MEMORYSTATUSEX statex;
statex.dwLength = sizeof statex;
if (!GlobalMemoryStatusEx((LPMEMORYSTATUSEX)&statex)) {
if (amPlatformDebugLevel > 0)
amiDebugLog("GlobalMemoryStatusEx Error!! (%d)", GetLastError());
size->QuadPart = 0;
return AM_PLATFORM_STATUS_ERR_SYS;
}
size->QuadPart = statex.ullTotalPhys;
return AM_PLATFORM_STATUS_OK;
}
static AM_PLATFORM_CMOS_PARAM _cmosParam[5] = {
// RE
{
.index = { { 0x60, 0x00 }, { 0x61, 0x00 } },
.m_MbrCount = 0,
},
// RW 1
{
.index = { { 0x3a, 0x05 }, { 0x3a, 0x02 } },
.m_MbrCount = 1,
},
// RW 2
{
.index = { { 0x28, 0x00 }, { 0x28, 0x00 } },
.m_MbrCount = 1,
},
// RE 2
{
.index = { { 0x60, 0x00 }, { 0x61, 0x00 } },
.m_MbrCount = 1,
},
{
.index = { { 0x00, 0x00 }, { 0x00, 0x00 } },
.m_MbrCount = 0,
},
};
AM_PLATFORM_CMOS_PARAM *amPlatformGetCmosParam(AM_PLATFORM_BOARD_TYPE boardType) {
if (boardType < 5) return &_cmosParam[boardType];
return NULL;
}

View File

@ -17,6 +17,10 @@ AM_LIB_H_HEADER(amPlatform, AM_PLATFORM)
typedef struct {
char strPlatformId[4];
} AM_PLATFORM_PLATFORM_ID;
typedef struct {
char strPlatformId[4];
int platformId;
} AM_PLATFORM_PLATFORM_ID_EX;
typedef enum {
AM_PLATFORM_BOARD_TYPE_RINGEDGE = 0,
@ -33,7 +37,7 @@ typedef struct AM_PLATFORM {
AM_PLATFORM_PLATFORM_ID m_platformId;
} AM_PLATFORM;
typedef struct {
typedef struct AM_PLATFORM_ID_GROUP {
char strVendorId[5];
char strDeviceId[5];
char strSubId[9];
@ -67,24 +71,42 @@ typedef enum {
typedef int(amPlatformRead_t)(WORD addr, LPBYTE buf, DWORD length);
typedef int(amPlatformWrite_t)(WORD addr, LPBYTE buf, DWORD length);
typedef struct {
DWORD m_base;
DWORD m_size;
DWORD m_blockSize;
amPlatformRead_t* m_read;
amPlatformWrite_t* m_write;
typedef struct AM_PLATFORM_NV_DEVICE_CONFIG {
DWORD m_Base;
DWORD m_Size;
DWORD m_BlockSize;
amPlatformRead_t* m_ReadFunc;
amPlatformWrite_t* m_WriteFunc;
} AM_PLATFORM_NV_DEVICE_CONFIG;
typedef struct AM_PLATFORM_BIOS_INFO {
CHAR m_BiosVer[64];
CHAR m_BiosReleaseDate[11];
} AM_PLATFORM_BIOS_INFO;
typedef struct AM_PLATFORM_CMOS_PARAM {
// [address, bit offset][2]
BYTE index[2][2];
BYTE m_MbrCount;
} AM_PLATFORM_CMOS_PARAM;
AM_PLATFORM_NV_DEVICE_CONFIG* amPlatformGetNvDevice(AM_PLATFORM_NV_DEVICE device);
AM_PLATFORM_STATUS amPlatformGetBoardType(AM_PLATFORM_BOARD_TYPE* boardType);
AM_PLATFORM_STATUS amPlatformGetPlatformId(AM_PLATFORM_PLATFORM_ID* platformId);
AM_PLATFORM_STATUS amPlatformGetPlatformIdEx(AM_PLATFORM_PLATFORM_ID_EX* platformId);
int amPlatformGetBiosInfo(AM_PLATFORM_BIOS_INFO* lpInfo);
int amPlatformGetOsVersion(DWORD* lpVersion); // Reads SystemVersion.txt
int amPlatformGetMemorySize(PLARGE_INTEGER size);
AM_PLATFORM_CMOS_PARAM* amPlatformGetCmosParam(AM_PLATFORM_BOARD_TYPE boardType);
// TODO:
void amPlatformAsyncClose(void);
void amPlatformAsyncReqUsbDeviceCount(void);
void amPlatformAsyncResUsbDeviceCount(void);
// usbDongle.exe -> see in maimai 1.90 folder
void amPlatformAsyncClose(void); // usbDongle.exe
void amPlatformAsyncReqUsbDeviceCount(void); // usbDongle.exe
void amPlatformAsyncResUsbDeviceCount(void); // usbDongle.exe
void amPlatformChangeDisplayModeAmd(void);
void amPlatformChangeDisplayModeNvidia(void);
void amPlatformChangeDisplayModeNvidiaEx(void);
@ -93,23 +115,19 @@ void amPlatformChangeDisplayResolutionNvidia(void);
void amPlatformChangeDisplayResolutionNvidiaEx(void);
void amPlatformChangeDisplayResolutionWinAPI(void);
void amPlatformDestroyCheckInterfaceHandle(void);
void amPlatformGetAvailableAmdDriver(void);
void amPlatformGetAvailableNvidiaDriver(void);
void amPlatformGetBiosInfo(void);
void amPlatformGetCheckInterfaceHandle(void);
void amPlatformGetComInfo(void);
void amPlatformGetDevInfo(void);
void amPlatformGetGpuPstate(void);
void amPlatformGetGraphicInfo(void);
void amPlatformGetMemorySize(void);
void amPlatformGetOsVersion(void);
void amPlatformGetPartitionInfo(void);
void amPlatformGetPlatformIdEx(void);
void amPlatformGetPortName(void);
void amPlatformGetSearchDevInfo(void);
void amPlatformGetSoundInfo(void);
void amPlatformGetStorageInfo(void);
void amPlatformNvapiInit(void);
void amPlatformGetAvailableAmdDriver(void); // usbDongle.exe
void amPlatformGetAvailableNvidiaDriver(void); // usbDongle.exe
void amPlatformGetCheckInterfaceHandle(void); // usbDongle.exe
void amPlatformGetComInfo(void); // usbDongle.exe
void amPlatformGetDevInfo(void); // usbDongle.exe
void amPlatformGetGpuPstate(void); // usbDongle.exe
void amPlatformGetGraphicInfo(void); // usbDongle.exe
void amPlatformGetPartitionInfo(void); // usbDongle.exe
void amPlatformGetPortName(void); // usbDongle.exe
void amPlatformGetSearchDevInfo(void); // usbDongle.exe
void amPlatformGetSoundInfo(void); // usbDongle.exe
void amPlatformGetStorageInfo(void); // usbDongle.exe
void amPlatformNvapiInit(void); // usbDongle.exe
void amPlatformSetDisplayMode(void);
void amPlatformSetDisplayResolution(void);
void amPlatformSetDisplayResolutionAndMode(void);

View File

@ -13,6 +13,7 @@ amEeprom = static_library(
link_with: [
amiDebug,
amiCrc,
amiTimer,
],
)
@ -35,6 +36,7 @@ amPlatform = static_library(
amiDebug,
amSram,
amEeprom,
amOemstring,
],
)
@ -78,3 +80,20 @@ amCmos = static_library(
amiDebug,
],
)
amLog = static_library(
'amLog',
sources: [
'amLog.c',
],
)
amBackup = static_library(
'amBackup',
sources: [
'amBackup.c',
],
link_with: [
amiDebug,
amiCrc,
],
)

View File

@ -449,7 +449,8 @@ e_pcpa_t pcpaServer(pcpa_t *stream, timeout_t timeout_ms) {
case 10:
// TODO: Figure out why recv_buf is empty at this point in the FSM
if (stream->before_cb != NULL)
stream->before_cb(stream, stream->pcpp.sock.recv_buf);
stream->before_cb(stream, (char *)stream->pcpp.sock.recv_buf,
*stream->pcpp.sock.recv_buf_count);
if (stream->callback_table == NULL) {
amiDebugLog("error Callback_table buffer isn't set");

View File

@ -45,6 +45,7 @@ e_pcpa_t _pcpaGetErrorFromPcpp(e_pcpp_t err);
struct pcpa;
typedef void(pcpa_callback)(struct pcpa* stream, void* data);
typedef void(pcpa_log_callback)(struct pcpa* stream, char* data, size_t nData);
typedef struct pcpa_cb_table {
char keyword[PCP_KEYWORD_MAX];
@ -73,7 +74,7 @@ typedef struct pcpa {
pcp_send_data_t send_data;
// Our additions
pcpa_callback* before_cb;
pcpa_log_callback* before_cb;
} pcpa_t;
void pcpaClose(pcpa_t* stream);
@ -81,7 +82,8 @@ void pcpaCloseBinary(pcpa_t* stream);
char* pcpaGetKeyword(pcpa_t* stream, uint keyword_num);
e_pcpa_t pcpaInitStream(pcpa_t* stream);
e_pcpa_t pcpaOpenClient(pcpa_t* stream, char* ipAddr, ushort port, uint param_4, timeout_t timeout);
e_pcpa_t pcpaOpenServerWithBinary(pcpa_t* stream, int open_mode, ushort port, ushort binary_port, timeout_t param_5);
e_pcpa_t pcpaOpenServerWithBinary(pcpa_t* stream, int open_mode, ushort port, ushort binary_port,
timeout_t param_5);
e_pcpa_t pcpaRecvBinary(pcpa_t* stream, timeout_t something);
e_pcpa_t pcpaSendBinary(pcpa_t* stream, timeout_t something);
e_pcpa_t pcpaServer(pcpa_t* stream, timeout_t timeout_ms);
@ -89,15 +91,16 @@ e_pcpa_t pcpaSetAfterBinaryModeCallBackFunc(pcpa_t* stream, pcpa_callback* callb
e_pcpa_t pcpaSetBeforeBinaryModeCallBackFunc(pcpa_t* stream, pcpa_callback* callback, void* data);
e_pcpa_t pcpaSetBinaryMode(pcpa_t* stream, binary_mode_t binary_mode);
e_pcpa_t pcpaSetCallbackFunc(pcpa_t* stream, char* keyword, pcpa_callback* callback, void* data);
e_pcpa_t pcpaSetCallbackFuncBuffer(pcpa_t* stream, pcpa_cb_table_t* callback_table, uint callbacks_max);
e_pcpa_t pcpaSetCallbackFuncBuffer(pcpa_t* stream, pcpa_cb_table_t* callback_table,
uint callbacks_max);
e_pcpa_t pcpaSetRecvBinaryBuffer(pcpa_t* stream, unsigned char* recv_buffer, size_t len);
e_pcpa_t pcpaSetSendBinaryBuffer(pcpa_t* stream, const unsigned char* send_buffer, size_t len);
pcp_send_data_t* pcpaSetSendPacket(pcpa_t* stream, char* keyword, char* value);
pcp_send_data_t *pcpaAddSendPacket(pcpa_t *stream, char *keyword, char *value);
pcp_send_data_t* pcpaAddSendPacket(pcpa_t* stream, char* keyword, char* value);
char* pcpaGetCommand(pcpa_t* pcpa, char* command);
e_pcpa_t pcpaIsBusy(pcpa_t *pcpa, timeout_t timeout);
e_pcpa_t pcpaSendRequest(pcpa_t *stream, timeout_t timeout);
e_pcpa_t pcpaRecvResponse(pcpa_t *stream, timeout_t timeout);
e_pcpa_t pcpaOpenBinaryClient(pcpa_t *stream, ushort port, timeout_t timeout);
e_pcpa_t pcpaIsBusy(pcpa_t* pcpa, timeout_t timeout);
e_pcpa_t pcpaSendRequest(pcpa_t* stream, timeout_t timeout);
e_pcpa_t pcpaRecvResponse(pcpa_t* stream, timeout_t timeout);
e_pcpa_t pcpaOpenBinaryClient(pcpa_t* stream, ushort port, timeout_t timeout);
e_pcpa_t pcpaAccessClient(pcpa_t* stream, timeout_t timeout);

View File

@ -56,10 +56,8 @@ void pcpaPrint(pcpa_t* stream) {
printf(" %d commands:\n", stream->recv_data.cmd_count);
for (size_t i = 0; i < stream->recv_data.cmd_count; i++) {
byte kwd = stream->recv_data.keywords[i];
if (kwd != 0) kwd++;
printf(" & %02d '%s'\n", kwd, stream->recv_data.strings + kwd);
byte value = stream->recv_data.values[i];
if (value != 0) value++;
printf(" = %02d '%s'\n", value, stream->recv_data.strings + value);
if (stream->recv_data.strings[kwd] == 0) break;
}

View File

@ -3,7 +3,8 @@ _LF(Internal, Hooks, "hooks")
_LF(Internal, Misc, "misc")
_LF(Misc, Tea, "tea")
_LF(Misc, Printf, "printf")
_LF(Misc, Stdout, "stdout")
_LF(Misc, Stderr, "stderr")
_LF(Misc, Fprintf, "fprintf")
_LF(Misc, Fprintf_s, "fprintf_s")
_LF(Misc, Vfprintf_s, "vfprintf_s")

View File

@ -11,6 +11,21 @@ executable(
win_subsystem: subsystem,
sources: [
'mxstartup.c',
'osu.c',
'osg.c',
],
link_with: [
amLog,
amiDebug,
amiCrc,
amBackup,
amEeprom,
amBackup,
amCmos,
amPlatform,
],
dependencies: [
ewfapi_lib,
],
)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,348 @@
#include "osg.h"
#include <memory.h>
#include <stdlib.h>
mxdraw *mxdrawZero(mxdraw *this, OSU *osu) {
this->hasState = 0;
this->s1 = NULL;
this->s2 = NULL;
this->hInstance = NULL;
this->nCmdShow = 0;
this->hWnd = NULL;
this->hBitmap = NULL;
this->hDc = NULL;
this->dispWidth = 0;
this->dispHeight = 0;
this->font1 = NULL;
this->font2 = NULL;
this->font3 = NULL;
ShowCursor(0);
if (osu != NULL) {
this->hInstance = osu->hInstance;
this->nCmdShow = osu->nShowCmd;
this->s1 = osu->s1;
this->s2 = osu->s2;
this->hasState = 1;
}
return this;
}
void mxdrawCleanup(mxdraw *this) {
ShowCursor(1);
DeleteObject(this->font1);
DeleteObject(this->font2);
DeleteObject(this->font3);
DeleteObject(this->hBitmap);
ReleaseDC(this->hWnd, this->hDc);
}
void peekDispatchLoop(void) {
MSG msg;
PeekMessageA(&msg, NULL, 0, 0, 0);
while (msg.message != WM_QUIT) {
if (PeekMessageA(&msg, NULL, 0, 0, 1)) {
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
}
}
COLORREF GetColour(colour col) {
switch (col) {
case Black:
return 0x000000;
case Red:
return 0x0000ff;
case Blue:
return 0xc80000;
case Green:
return 0xb4ffb4;
case Grey:
return 0x646464;
default:
return 0xffffff;
}
}
void mxdrawR1(mxdraw *this) {
RECT rect;
rect.bottom = this->dispHeight;
rect.left = 0;
rect.top = 0;
rect.right = this->dispWidth;
EnterCriticalSection(&this->s1->criticalSection);
HBRUSH hbr = CreateSolidBrush(GetColour(this->s2->backgroundColour));
LeaveCriticalSection(&this->s1->criticalSection);
FillRect(this->hDc, &rect, hbr);
DeleteObject(hbr);
}
void mxdrawR2(mxdraw *this) {
if (!this->s1->show_top) return;
switch (this->s1->top_text_font) {
case 1:
SelectObject(this->hDc, this->font3);
break;
case 2:
SelectObject(this->hDc, this->font1);
break;
default:
SelectObject(this->hDc, this->font2);
break;
}
SetTextAlign(this->hDc, TA_CENTER + TA_BASELINE);
SetTextColor(this->hDc, GetColour(this->s1->top_text_colour));
SetBkMode(this->hDc, TRANSPARENT);
EnterCriticalSection(&this->s1->criticalSection);
if (this->s1->str1)
TextOutA(this->hDc, this->dispWidth / 2, this->dispHeight / 6, this->s1->str1,
strlen(this->s1->str1));
LeaveCriticalSection(&this->s1->criticalSection);
}
void mxdrawR3(mxdraw *this) {
if (!this->s1->show_top) return;
switch (this->s1->top_text_font) {
case 1:
SelectObject(this->hDc, this->font3);
break;
case 2:
SelectObject(this->hDc, this->font1);
break;
default:
SelectObject(this->hDc, this->font2);
break;
}
SetTextAlign(this->hDc, TA_CENTER + TA_BASELINE);
SetTextColor(this->hDc, GetColour(this->s1->top_text_colour));
SetBkMode(this->hDc, TRANSPARENT);
EnterCriticalSection(&this->s1->criticalSection);
if (this->s1->str2)
TextOutA(this->hDc, this->dispWidth / 2, this->dispHeight / 3, this->s1->str2,
strlen(this->s1->str2));
LeaveCriticalSection(&this->s1->criticalSection);
}
void mxdrawR4(mxdraw *this) {
static int _counter = 0;
SetTextAlign(this->hDc, TA_CENTER + TA_BASELINE);
switch (this->s2->status_font) {
case 1:
SelectObject(this->hDc, this->font3);
break;
case 2:
SelectObject(this->hDc, this->font1);
break;
default:
SelectObject(this->hDc, this->font2);
break;
}
SetTextColor(this->hDc, GetColour(this->s2->status_colour));
SetBkMode(this->hDc, TRANSPARENT);
EnterCriticalSection(&this->s1->criticalSection);
if (this->s2->status_use_counter == 0 || _counter > 1) {
if (this->s2->status_str)
TextOutA(this->hDc, this->dispWidth / 2, this->dispHeight / 2, this->s2->status_str,
strlen(this->s2->status_str));
}
LeaveCriticalSection(&this->s1->criticalSection);
_counter = (_counter + 1) % 7;
}
void mxdrawR5(mxdraw *this) {
static int _counter = 0;
SetTextAlign(this->hDc, TA_CENTER + TA_TOP);
switch (this->s2->power_font) {
case 1:
SelectObject(this->hDc, this->font3);
break;
case 2:
SelectObject(this->hDc, this->font1);
break;
default:
SelectObject(this->hDc, this->font2);
break;
}
SetTextColor(this->hDc, GetColour(this->s2->power_colour));
EnterCriticalSection(&this->s1->criticalSection);
if (this->s2->hide_power != 1 || _counter > 1) {
if (this->s2->str2)
TextOutA(this->hDc, (int)this->dispWidth / 2, (this->dispHeight * 4) / 6,
this->s2->str2, strlen(this->s2->str2));
}
LeaveCriticalSection(&this->s1->criticalSection);
_counter = (_counter + 1) % 7;
}
void mxdrawR6(mxdraw *this) {
if (!this->s1->debugEnable) return;
SetTextAlign(this->hDc, TA_LEFT + TA_BASELINE);
SelectObject(this->hDc, this->font3);
SetTextColor(this->hDc, GetColour(this->s2->debug_colour));
EnterCriticalSection(&this->s1->criticalSection);
if (this->s2->debug_text)
TextOutA(this->hDc, this->dispWidth / 10, (this->dispHeight * 10) / 11,
this->s2->debug_text, strlen(this->s2->debug_text));
LeaveCriticalSection(&this->s1->criticalSection);
}
void mxdrawR7(mxdraw *this) {
SetTextAlign(this->hDc, TA_LEFT + TA_BASELINE);
SelectObject(this->hDc, this->font3);
SetTextColor(this->hDc, GetColour(this->s2->line5_colour));
EnterCriticalSection(&this->s1->criticalSection);
if (this->s2->line5)
TextOutA(this->hDc, 0, this->dispHeight, this->s2->line5, strlen(this->s2->line5));
LeaveCriticalSection(&this->s1->criticalSection);
}
void mxdrawRender(mxdraw *this) {
this->dispWidth = GetSystemMetrics(0);
this->dispHeight = GetSystemMetrics(1);
if (this->dispWidth != 640 || this->dispHeight != 480) {
// iVar1 = amSysDataGetDotClockTiming(640, 480, local_38);
// if (iVar1 == 0) {
// amPlatformSetDisplayResolution(local_38, extraout_EDX, (ushort *)local_38);
// }
}
mxdrawR1(this); // Clear background
mxdrawR2(this); // s1, str1
mxdrawR3(this); // s1, str2
mxdrawR4(this); // s2, status_str
mxdrawR5(this); // s2, str2
mxdrawR6(this); // s2, debug_text
mxdrawR7(this); // s2, line5
HDC hdc = GetDC(this->hWnd);
BitBlt(hdc, 0, 0, this->dispWidth, this->dispHeight, this->hDc, 0, 0, SRCCOPY);
ReleaseDC(this->hWnd, hdc);
SetWindowPos(this->hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
}
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
if (uMsg == WM_CREATE) {
SetTimer(hWnd, 15000, 0x80, NULL);
} else if (uMsg == WM_DESTROY) {
RemovePropA(hWnd, "prp");
PostQuitMessage(0);
} else if (uMsg == WM_TIMER) {
mxdraw *this = (mxdraw *)GetPropA(hWnd, "prp");
mxdrawRender(this);
if (this->s2->only_sends_if == 1) {
SendMessageA(hWnd, WM_DESTROY, 0, 0);
}
}
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
int mxdrawSetup(mxdraw *this) {
if (this->hasState == 0) return 1;
WNDCLASSEXA class;
class.hInstance = this->hInstance;
class.cbSize = 0x30;
class.style = 3;
class.lpfnWndProc = WndProc;
class.cbClsExtra = 0;
class.cbWndExtra = 0;
class.hIcon = LoadIconA(NULL, IDI_APPLICATION);
class.hCursor = LoadCursorA(NULL, IDC_ARROW);
class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
class.lpszMenuName = NULL;
class.lpszClassName = "MxDraw";
class.hIconSm = LoadIconA(NULL, IDI_APPLICATION);
if (!RegisterClassExA(&class)) {
if (GetLastError() != ERROR_CLASS_ALREADY_EXISTS) return 2;
}
this->dispWidth = GetSystemMetrics(SM_CXSCREEN);
this->dispHeight = GetSystemMetrics(SM_CYSCREEN);
if (this->dispWidth != 640 || this->dispHeight != 480) {
// TODO: This
// setres_640_480();
this->dispWidth = GetSystemMetrics(SM_CXSCREEN);
this->dispHeight = GetSystemMetrics(SM_CYSCREEN);
}
this->hWnd =
CreateWindowExA(0, "MxDraw", "MxDraw", WS_DISABLED | WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
this->dispWidth, this->dispHeight, NULL, NULL, this->hInstance, NULL);
SetPropA(this->hWnd, "prp", this);
this->font1 = CreateFontA((int)(this->dispHeight * 0.125f), 0, 0, 0, 700, FALSE, FALSE, FALSE,
0, 7, 0, 0, 1, "Tahoma bold");
this->font2 = CreateFontA((int)(this->dispHeight * 0.09f), 0, 0, 0, 700, FALSE, FALSE, FALSE, 0,
7, 0, 0, 1, "Tahoma bold");
this->font3 = CreateFontA((int)(this->dispHeight * 0.03125f), 0, 0, 0, 700, FALSE, FALSE, FALSE,
0, 7, 0, 0, 1, "Tahoma bold");
ShowWindow(this->hWnd, this->nCmdShow);
UpdateWindow(this->hWnd);
HDC hdc = GetDC(this->hWnd);
this->hBitmap = CreateCompatibleBitmap(hdc, this->dispWidth, this->dispHeight);
this->hDc = CreateCompatibleDC(hdc);
ReleaseDC(this->hWnd, hdc);
SelectObject(this->hDc, this->hBitmap);
return 0;
}
DWORD mxdrawThread(OSU *osu) {
mxdraw *this = (mxdraw *)malloc(sizeof *this);
if (this != NULL) mxdrawZero(this, osu);
mxdrawSetup(this);
peekDispatchLoop();
if (this != NULL) {
mxdrawCleanup(this);
free(this);
}
ExitThread(1);
}
BOOL osgInitDraw(OSU *lpOsu) {
OSU *lpParameter;
HANDLE pvVar1;
lpParameter = lpOsu;
if (lpOsu == NULL) return FALSE;
InitializeCriticalSection(&lpOsu->s1->criticalSection);
EnterCriticalSection(&lpParameter->s1->criticalSection);
lpParameter->s2->only_sends_if = 0;
LeaveCriticalSection(&lpParameter->s1->criticalSection);
pvVar1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mxdrawThread, lpParameter, 0,
(LPDWORD)&lpOsu);
lpParameter->handle = pvVar1;
if (pvVar1 == NULL) {
lpParameter->field3_0xc = 0;
return FALSE;
}
lpParameter->field3_0xc = 1;
return TRUE;
}
BOOL osgExit(OSU *this) {
if (this->field3_0xc != 1) return FALSE;
EnterCriticalSection(&this->s1->criticalSection);
this->s2->only_sends_if = 1;
LeaveCriticalSection(&this->s1->criticalSection);
WaitForSingleObject(this->handle, INFINITE);
CloseHandle(this->handle);
DeleteCriticalSection(&this->s1->criticalSection);
this->field3_0xc = 0;
return TRUE;
}

View File

@ -0,0 +1,72 @@
#include <Windows.h>
typedef enum colour {
White = 0,
Black = 1,
Red = 2,
Blue = 3,
Green = 4,
Grey = 5,
} colour;
typedef struct OSU_TOP {
BOOL show_top;
BOOL debugEnable;
char *str1;
char *str2;
colour top_text_colour;
DWORD top_text_font;
CRITICAL_SECTION criticalSection;
} OSU_TOP;
typedef struct OSU_BOTTOM {
colour backgroundColour;
char *status_str;
colour status_colour;
DWORD status_font;
DWORD status_use_counter;
char *str2;
colour power_colour;
DWORD power_font;
DWORD hide_power;
char *line5;
colour line5_colour;
char *debug_text;
colour debug_colour;
DWORD only_sends_if;
} OSU_BOTTOM;
typedef struct OSU {
HINSTANCE hInstance;
int nShowCmd;
HANDLE handle;
unsigned int field3_0xc;
OSU_TOP *s1;
OSU_BOTTOM *s2;
} OSU;
typedef struct mxdraw {
unsigned int hasState;
OSU_TOP *s1;
OSU_BOTTOM *s2;
HINSTANCE hInstance;
unsigned int nCmdShow;
HWND hWnd;
HBITMAP hBitmap;
HDC hDc;
unsigned int dispWidth;
unsigned int dispHeight;
HGDIOBJ font1;
HGDIOBJ font2;
HGDIOBJ font3;
} mxdraw;
mxdraw *mxdrawZero(mxdraw *this, OSU *osu);
void mxdrawCleanup(mxdraw *this);
void peekDispatchLoop(void);
void mxdrawRender(mxdraw *this);
int mxdrawSetup(mxdraw *this);
DWORD mxdrawThread(OSU *osu);
BOOL osgInitDraw(OSU *lpOsu);
BOOL osgExit(OSU *lpOsu);

View File

@ -0,0 +1,126 @@
#include "osu.h"
#include <stdio.h>
#include "../lib/am/amCmos.h"
#include "../lib/am/amPlatform.h"
int osuExecProcess(LPSTR command) {
PROCESS_INFORMATION processInformation = { 0 };
STARTUPINFOA startupInfo = {
.cb = 68,
.dwFlags = STARTF_USESHOWWINDOW,
.wShowWindow = SW_HIDE,
};
if (command == NULL) return -150;
BOOL spanwed = CreateProcessA(NULL, command, NULL, NULL, 0, 0, NULL, NULL, &startupInfo,
&processInformation);
DWORD wait = WaitForSingleObject(processInformation.hProcess, INFINITE);
int ret;
if (!spanwed) {
ret = -140;
} else if (wait == WAIT_OBJECT_0) {
DWORD exitCode;
GetExitCodeProcess(processInformation.hProcess, &exitCode);
ret = exitCode == 0 ? 0 : -141;
} else {
ret = -141;
}
CloseHandle(processInformation.hProcess);
CloseHandle(processInformation.hThread);
return ret;
}
int osuMountPartition(LPCSTR lpTargetPath, LPCSTR lpszVolumeMountPoint) {
if (lpTargetPath == NULL || lpszVolumeMountPoint == NULL) return -150;
DefineDosDeviceA(DDD_RAW_TARGET_PATH, "B:", lpTargetPath);
char szVolumeName[256];
GetVolumeNameForVolumeMountPointA("B:\\", szVolumeName, sizeof szVolumeName);
DefineDosDeviceA(DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE,
"B:", lpTargetPath);
if (!SetVolumeMountPointA(lpszVolumeMountPoint, szVolumeName)) return -129;
for (int i = 0; i < 100; i++)
if (DefineDosDeviceA(DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION, "B:", NULL)) break;
char szDeviceName[260];
sprintf_s(szDeviceName, sizeof szDeviceName, "%c:", lpszVolumeMountPoint[4]);
if (!DefineDosDeviceA(DDD_RAW_TARGET_PATH, szDeviceName, lpTargetPath)) return -130;
return 0;
}
int osuOpenDevice(DWORD dwDrive, LPHANDLE lphDevice) {
char szFileName[32];
sprintf_s(szFileName, sizeof szFileName, "\\\\.\\PhysicalDrive%d", dwDrive);
HANDLE hDevice = *lphDevice = CreateFileA(szFileName, 0xc0000000, 3, NULL, 3, 0x80, NULL);
if (hDevice == INVALID_HANDLE_VALUE) return -123;
return 0;
}
int osuReadSector(HANDLE hDevice, DWORD dwLBA, DWORD dwSectors, LPVOID lpBuffer) {
LARGE_INTEGER liPointer;
liPointer.QuadPart = (unsigned long long)dwLBA * 0x200;
if (!SetFilePointerEx(hDevice, liPointer, NULL, FILE_BEGIN)) return -124;
if (lpBuffer == NULL) return -150;
DWORD nNumberOfBytesToRead = dwSectors * 0x200;
DWORD nRead = 0;
if (!ReadFile(hDevice, lpBuffer, nNumberOfBytesToRead, &nRead, NULL)) return -125;
if (nRead != nNumberOfBytesToRead || ((dwSectors * 0x200) >> 32) != 0) return -126;
return 0;
}
int osuSystemReboot(void) {
int eCode = 0;
HANDLE hToken = INVALID_HANDLE_VALUE;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
eCode = -142;
goto _end;
}
TOKEN_PRIVILEGES privileges;
if (!LookupPrivilegeValueA(NULL, "SeShutdownPrivilege", &privileges.Privileges[0].Luid)) {
eCode = -143;
goto _end;
}
privileges.PrivilegeCount = 1;
privileges.Privileges[0].Attributes = 2;
if (!AdjustTokenPrivileges(hToken, 0, &privileges, 0, NULL, NULL)) {
eCode = -144;
goto _end;
}
if (!ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0)) {
eCode = -145;
goto _end;
}
_end:
if (hToken != INVALID_HANDLE_VALUE) CloseHandle(hToken);
return eCode;
}
int osuSetActivePartition(BYTE partition) {
AM_PLATFORM_BOARD_TYPE board_type;
if (amPlatformGetBoardType(&board_type) != AM_PLATFORM_STATUS_OK) return -110;
AM_PLATFORM_CMOS_PARAM* lpParam = amPlatformGetCmosParam(board_type);
if (amCmosInit(lpParam) != 0) return -114;
if (amCmosSetPartition_0(partition) != 0) {
amCmosExit();
return -111;
}
amCmosExit();
return 0;
}

View File

@ -0,0 +1,8 @@
#include <Windows.h>
int osuExecProcess(LPSTR command);
int osuMountPartition(LPCSTR lpTargetPath, LPCSTR lpszVolumeMountPoint);
int osuOpenDevice(DWORD dwDrive, LPHANDLE lphDevice);
int osuReadSector(HANDLE hDevice, DWORD dwLBA, DWORD dwSectors, LPVOID lpBuffer);
int osuSystemReboot(void);
int osuSetActivePartition(BYTE partition);

View File

@ -13,34 +13,37 @@ void mxkPcpTdRestore(pcpa_t* stream, void* data) {
}
}
void mxkPcpTdPut(pcpa_t* stream, void* data) {
char* sPut = pcpaGetCommand(stream, TRA_PUT);
// char* sPut = pcpaGetCommand(stream, TRA_PUT);
if (strcmp(sPut, "?")) {
pcpaSetSendPacket(stream, TRA_PUT, "0");
return;
}
// if (strcmp(sPut, "?")) {
// pcpaSetSendPacket(stream, TRA_PUT, "0");
// return;
// }
// Process packet maybe?
pcpaSetSendPacket(stream, TRA_PUT, "0");
// // Process packet maybe?
// pcpaSetSendPacket(stream, TRA_PUT, "0");
pcpaSetSendPacket(stream, TRA_PUT, "6410");
}
void mxkPcpTdGet(pcpa_t* stream, void* data) {
char* sPut = pcpaGetCommand(stream, TRA_GET);
pcpaSetSendPacket(stream, TRA_GET, "0");
if (sPut && strcmp(sPut, "?") == 0) {
pcpaAddSendPacket(stream, "address", "0");
} else {
pcpaSetBinaryMode(stream, binary_mode_send);
pcpaSetBeforeBinaryModeCallBackFunc(stream, mxkBinaryCallback, NULL);
// char* sPut = pcpaGetCommand(stream, TRA_GET);
// pcpaSetSendPacket(stream, TRA_GET, "0");
// if (sPut && strcmp(sPut, "?") == 0) {
// pcpaAddSendPacket(stream, "address", "0");
// } else {
// pcpaSetBinaryMode(stream, binary_mode_send);
// pcpaSetBeforeBinaryModeCallBackFunc(stream, mxkBinaryCallback, NULL);
BINARY_DATA_LEN = 0;
pcpaSetRecvBinaryBuffer(stream, BINARY_DATA, BINARY_DATA_LEN);
pcpaAddSendPacket(stream, "port", "40107");
pcpaAddSendPacket(stream, "size", "0");
}
// BINARY_DATA_LEN = 0;
// pcpaSetRecvBinaryBuffer(stream, BINARY_DATA, BINARY_DATA_LEN);
// pcpaAddSendPacket(stream, "port", "40107");
// pcpaAddSendPacket(stream, "size", "0");
// }
pcpaSetSendPacket(stream, TRA_GET, "0");
pcpaAddSendPacket(stream, "address", "0");
}
void mxkPcpTdLogicalErase(pcpa_t* stream, void* data) {
pcpaSetSendPacket(stream, TRA_LOGICALERASE, "");
pcpaSetSendPacket(stream, TRA_LOGICALERASE, "0");
}
void mxkPcpTdSectorErase(pcpa_t* stream, void* data) {
pcpaSetSendPacket(stream, TRA_SECTOREERASE, "");
pcpaSetSendPacket(stream, TRA_SECTOREERASE, "0");
}

View File

@ -26,11 +26,25 @@ int mxkInit() {
return err;
}
void log_callback(struct pcpa *stream, void *data) {
void log_callback(struct pcpa *stream, char *data, size_t nData) {
FILE *log_file;
fopen_s(&log_file, "pcp.log", "a");
for (uint i = 0; i < stream->recv_data.cmd_count; i++) {
if (i != 0) fprintf(stderr, "&");
fprintf(stderr, "%s=%s", stream->recv_data.strings + stream->recv_data.keywords[i],
stream->recv_data.strings + stream->recv_data.values[i]);
if (log_file != NULL) {
if (i != 0) fprintf(log_file, "&");
fprintf(log_file, "%s=%s", stream->recv_data.strings + stream->recv_data.keywords[i],
stream->recv_data.strings + stream->recv_data.values[i]);
}
}
fprintf(stderr, "\n");
if (log_file != NULL) {
fprintf(log_file, "%s\n", (char *)data);
fprintf(log_file, "\n");
fclose(log_file);
}
}

View File

@ -0,0 +1,93 @@
#include "dummystorage.h"
#include "../../lib/ami/amiLog.h"
#include "../../lib/libpcp/libpcp.h"
typedef struct {
pcpa_t m_pcp;
pcpa_cb_table_t m_pcpCallbacks[1];
} mdsd_t;
void mdsdRequest(pcpa_t* stream, void* mdsd) {
char* szRequest = pcpaGetCommand(stream, pcpaGetKeyword(stream, 0));
if (szRequest == NULL) {
pcpaSetSendPacket(stream, "result", "invalid_request");
return;
}
pcpaSetSendPacket(stream, "response", szRequest);
if (strcmp(szRequest, "query_storage_status") == 0) {
// pcpaAddSendPacket(stream, "result", "success");
pcpaAddSendPacket(stream, "result", "notask");
} else if (strcmp(szRequest, "query_storage_count") == 0) {
pcpaAddSendPacket(stream, "result", "success");
// Under normal operation, this is 0 (no USB inserted).
pcpaAddSendPacket(stream, "count", "1");
} else if (strcmp(szRequest, "get_volume") == 0) {
pcpaAddSendPacket(stream, "result", "success");
pcpaAddSendPacket(stream, "volume", "SEGA_DL");
} else {
pcpaAddSendPacket(stream, "result", "invalid_request");
// TODO: Remove this once enough has been implemented for most games?
pcpaPrint(stream);
}
}
e_pcpa_t mdsPcpStreamInit(mdsd_t* mdsd, unsigned short textPort, unsigned short binaryPort,
bool global) {
e_pcpa_t err;
err = pcpaInitStream(&mdsd->m_pcp);
if (err != e_pcpa_ok) {
amiDebugLog("pcpaInitStream Error. Code:%d", err);
return err;
}
err = pcpaSetCallbackFuncBuffer(&mdsd->m_pcp, mdsd->m_pcpCallbacks, 1);
if (err != e_pcpa_ok) {
amiDebugLog("pcpaSetCallBackFuncBuffer Error. Code:%d", err);
return err;
}
pcpaSetCallbackFunc(&mdsd->m_pcp, "request", mdsdRequest, mdsd);
err = pcpaOpenServerWithBinary(&mdsd->m_pcp, global ? OPEN_MODE_GLOBAL : OPEN_MODE_LOCAL,
textPort, binaryPort, 300000);
if (err != e_pcpa_ok && err != e_pcpa_to) {
amiDebugLog("pcpaOpenServerWithBinary Error. Code %d", err);
return e_pcpa_not_open;
}
if (global)
amiDebugLog("Listening on 0.0.0.0:%d (:%d)", textPort, binaryPort);
else
amiDebugLog("Listening on 127.0.0.1:%d (:%d)", textPort, binaryPort);
return e_pcpa_ok;
}
void miceDummyStorage(unsigned short textPort, unsigned short binaryPort, bool global) {
mdsd_t* mdsd = malloc(sizeof *mdsd);
e_pcpa_t err;
WSADATA wsaData;
if (WSAStartup(2, &wsaData)) {
amiDebugLog("WSAStartup Error. Code %d", GetLastError());
return;
}
err = mdsPcpStreamInit(mdsd, textPort, binaryPort, global);
if (err != e_pcpa_ok) {
amiDebugLog("mdsdPcpStreamInit Error. Code %d", err);
return;
}
while (1) {
err = pcpaServer(&mdsd->m_pcp, 16);
if (err == e_pcpa_to || err == e_pcpa_closed) err = e_pcpa_ok;
if (err != e_pcpa_ok) {
amiDebugLog("Error pcpaServer. Code %d", err);
pcpaClose(&mdsd->m_pcp);
return;
}
}
}

View File

@ -0,0 +1,3 @@
#include <stdbool.h>
void miceDummyStorage(unsigned short textPort, unsigned short binaryPort, bool global);

View File

@ -0,0 +1,3 @@
#include "dummystorage.h"
int main() { miceDummyStorage(40114, 40115, false); }

View File

@ -0,0 +1,7 @@
dummystorage = static_library(
'dummystorage',
sources: [
'dummystorage.c',
],
link_with: [libpcp, amiDebug],
)

View File

@ -3,3 +3,4 @@ subdir('dummymaster')
subdir('dummyinstaller')
subdir('dummygdeliver')
subdir('dummynetwork')
subdir('dummystorage')

View File

@ -27,9 +27,10 @@ Cmos:
*/
#include "../lib/am/amCmos.h"
#include "../lib/am/amPlatform.h"
AM_CMOS_CONFIG config = {
.index = { 0, 0, 0, 0 },
AM_PLATFORM_CMOS_PARAM config = {
.index = { { 0, 0 }, { 0, 0 } },
.m_MbrCount = 0,
};