RA_Interface.h (13893B)
1 #ifndef RA_INTERFACE_H 2 #define RA_INTERFACE_H 3 4 #include <wtypes.h> /* HWND */ 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 /****************************** 11 * Initialization * 12 ******************************/ 13 14 /** 15 * Loads and initializes the DLL. 16 * 17 * Must be called before using any of the other functions. Will automatically download the DLL 18 * if not found, or prompt the user to upgrade if a newer version is available 19 * 20 * @param hMainHWND the handle of the main window 21 * @param nEmulatorID the unique idenfier of the emulator 22 * @param sClientVersion the current version of the emulator (will be validated against the minimum version for the specified emulator ID) 23 */ 24 extern void RA_Init(HWND hMainHWND, int nEmulatorID, const char* sClientVersion); 25 26 /** 27 * Loads and initializes the DLL. 28 * 29 * Must be called before using any of the other functions. Will automatically download the DLL 30 * if not found, or prompt the user to upgrade if a newer version is available 31 * 32 * @param hMainHWND the handle of the main window 33 * @param sClientName the name of the client, displayed in the title bar and included in the User-Agent for API calls 34 * @param sClientVersion the current version of the client 35 */ 36 extern void RA_InitClient(HWND hMainHWND, const char* sClientName, const char* sClientVersion); 37 38 /** 39 * Defines callbacks that the DLL can use to interact with the client. 40 * 41 * @param fpUnusedIsActive [no longer used] returns non-zero if a game is running 42 * @param fpCauseUnpause unpauses the emulator 43 * @param fpCausePause pauses the emulator 44 * @param fpRebuildMenu notifies the client that the popup menu has changed (@see RA_CreatePopupMenu) 45 * @param fpEstimateTitle gets a short description for the game being loaded (parameter is a 256-byte buffer to fill) 46 * @param fpResetEmulator resets the emulator 47 * @param fpLoadROM [currently unused] tells the emulator to load a specific game 48 */ 49 extern void RA_InstallSharedFunctions(int (*fpUnusedIsActive)(void), 50 void (*fpCauseUnpause)(void), void (*fpCausePause)(void), void (*fpRebuildMenu)(void), 51 void (*fpEstimateTitle)(char*), void (*fpResetEmulator)(void), void (*fpLoadROM)(const char*)); 52 53 /** 54 * Tells the DLL to use UpdateWindow instead of InvalidateRect when the UI needs to be repainted. This is primarily 55 * necessary when integrating with an emulator using the SDL library as it keeps the message queue flooded so the 56 * InvalidateRect messages never get turned into WM_PAINT messages. 57 * 58 * @param bEnable non-zero if InvalidateRect calls should be replaced with UpdateWindow 59 */ 60 extern void RA_SetForceRepaint(int bEnable); 61 62 /** 63 * Creates a popup menu that can be appended to the main menu of the emulator. 64 * 65 * @return handle to the menu. if not attached to the program menu, caller must destroy it themselves. 66 */ 67 extern HMENU RA_CreatePopupMenu(void); 68 69 /* Resource values for menu items - needed by MFC ON_COMMAND_RANGE macros or WM_COMMAND WndProc handlers 70 * they're not all currently used, allowing additional items without forcing recompilation of the emulators 71 */ 72 #define IDM_RA_MENUSTART 1700 73 #define IDM_RA_MENUEND 1739 74 75 typedef struct RA_MenuItem 76 { 77 LPCWSTR sLabel; 78 LPARAM nID; 79 int bChecked; 80 } RA_MenuItem; 81 82 /** 83 * Gets items for building a popup menu. 84 * 85 * @param pItems Pre-allocated array to populate [should contain space for at least 32 items] 86 * @return Number of items populated in the items array 87 */ 88 extern int RA_GetPopupMenuItems(RA_MenuItem *pItems); 89 90 /** 91 * Called when a menu item in the popup menu is selected. 92 * 93 * @param nID the ID of the menu item (will be between IDM_RA_MENUSTART and IDM_RA_MENUEND) 94 */ 95 extern void RA_InvokeDialog(LPARAM nID); 96 97 /** 98 * Provides additional information to include in the User-Agent string for API calls. 99 * 100 * This is primarily used to identify dependencies or configurations (such as libretro core versions) 101 * 102 * @param sDetail the additional information to include 103 */ 104 extern void RA_SetUserAgentDetail(const char* sDetail); 105 106 /** 107 * Attempts to log in to the retroachievements.org site. 108 * 109 * Prompts the user for their login credentials and performs the login. If they've previously logged in and have 110 * chosen to store their credentials, the login occurs without prompting. 111 * 112 * @param bBlocking if zero, control is returned to the calling process while the login request is processed by the server. 113 */ 114 extern void RA_AttemptLogin(int bBlocking); 115 116 /** 117 * Specifies the console associated to the emulator. 118 * 119 * May be called just before loading a game if the emulator supports multiple consoles. 120 * 121 * @param nConsoleID the unique identifier of the console associated to the game being loaded. 122 */ 123 extern void RA_SetConsoleID(unsigned int nConsoleID); 124 125 /** 126 * Resets memory references created by previous calls to RA_InstallMemoryBank. 127 */ 128 extern void RA_ClearMemoryBanks(void); 129 130 typedef unsigned char (RA_ReadMemoryFunc)(unsigned int nAddress); 131 typedef void (RA_WriteMemoryFunc)(unsigned int nAddress, unsigned char nValue); 132 /** 133 * Exposes a block of memory to the DLL. 134 * 135 * The blocks of memory expected by the DLL are unique per console ID. To identify the correct map for a console, 136 * view the consoleinfo.c file in the rcheevos repository. 137 * 138 * @param nBankID the index of the bank to update. will replace any existing bank at that index. 139 * @param pReader a function to read from the bank. parameter is the offset within the bank to read from. 140 * @param pWriter a function to write to the bank. parameters are the offset within the bank to write to and an 8-bit value to write. 141 * @param nBankSize the size of the bank. 142 */ 143 extern void RA_InstallMemoryBank(int nBankID, RA_ReadMemoryFunc pReader, RA_WriteMemoryFunc pWriter, int nBankSize); 144 145 typedef unsigned int (RA_ReadMemoryBlockFunc)(unsigned int nAddress, unsigned char* pBuffer, unsigned int nBytes); 146 extern void RA_InstallMemoryBankBlockReader(int nBankID, RA_ReadMemoryBlockFunc pReader); 147 148 /** 149 * Deinitializes and unloads the DLL. 150 */ 151 extern void RA_Shutdown(void); 152 153 154 155 /****************************** 156 * Overlay * 157 ******************************/ 158 159 /** 160 * Determines if the overlay is fully visible. 161 * 162 * Precursor check before calling RA_NavigateOverlay 163 * 164 * @return non-zero if the overlay is fully visible, zero if it is not. 165 */ 166 extern int RA_IsOverlayFullyVisible(void); 167 168 /** 169 * Called to show or hide the overlay. 170 * 171 * @param bIsPaused true to show the overlay, false to hide it. 172 */ 173 extern void RA_SetPaused(bool bIsPaused); 174 175 struct ControllerInput 176 { 177 int m_bUpPressed; 178 int m_bDownPressed; 179 int m_bLeftPressed; 180 int m_bRightPressed; 181 int m_bConfirmPressed; /* Usually C or A */ 182 int m_bCancelPressed; /* Usually B */ 183 int m_bQuitPressed; /* Usually Start */ 184 }; 185 186 /** 187 * Passes controller input to the overlay. 188 * 189 * Does nothing if the overlay is not fully visible. 190 * 191 * @param pInput pointer to a ControllerInput structure indicating which inputs are active. 192 */ 193 extern void RA_NavigateOverlay(struct ControllerInput* pInput); 194 195 /** 196 * [deprecated] Updates the overlay for a single frame. 197 * 198 * This function just calls RA_NavigateOverlay. Updating and rendering is now handled internally to the DLL. 199 */ 200 extern void RA_UpdateRenderOverlay(HDC, struct ControllerInput* pInput, float, RECT*, bool, bool); 201 202 /** 203 * Updates the handle to the main window. 204 * 205 * The main window handle is used to anchor the overlay. If the client recreates the handle as the result of switching 206 * from windowed mode to full screen, or for any other reason, it should call this to reattach the overlay. 207 * 208 * @param hMainHWND the new handle of the main window 209 */ 210 extern void RA_UpdateHWnd(HWND hMainHWND); 211 212 213 214 /****************************** 215 * Game Management * 216 ******************************/ 217 218 /** 219 * Identifies the game associated to a block of memory. 220 * 221 * The block of memory is the fully buffered game file. If more complicated identification is required, the caller 222 * needs to link against rcheevos/rhash directly to generate the hash, and call RA_IdentifyHash with the result. 223 * Can be called when switching discs to ensure the additional discs are still associated to the loaded game. 224 * 225 * @param pROMData the contents of the game file 226 * @param nROMSize the size of the game file 227 * @return the unique identifier of the game, 0 if no association available. 228 */ 229 extern unsigned int RA_IdentifyRom(BYTE* pROMData, unsigned int nROMSize); 230 231 /** 232 * Identifies the game associated to a pre-generated hash. 233 * 234 * Used when the hash algorithm is something other than full file. 235 * Can be called when switching discs to ensure the additional discs are still associated to the loaded game. 236 * 237 * @param sHash the hash generated by rcheevos/rhash 238 * @return the unique identifier of the game, 0 if no association available. 239 */ 240 extern unsigned int RA_IdentifyHash(const char* sHash); 241 242 /** 243 * Fetches all retroachievements related data for the specified game. 244 * 245 * @param nGameId the unique identifier of the game to activate 246 */ 247 extern void RA_ActivateGame(unsigned int nGameId); 248 249 /** 250 * Identifies and activates the game associated to a block of memory. 251 * 252 * Functions as a call to RA_IdentifyRom followed by a call to RA_ActivateGame. 253 * 254 * @param pROMData the contents of the game file 255 * @param nROMSize the size of the game file 256 */ 257 extern void RA_OnLoadNewRom(BYTE* pROMData, unsigned int nROMSize); 258 259 /** 260 * Called before unloading the game to allow the user to save any changes they might have. 261 * 262 * @param bIsQuitting non-zero to change the messaging to indicate the emulator is closing. 263 * @return zero to abort the unload. non-zero to continue. 264 */ 265 extern int RA_ConfirmLoadNewRom(int bIsQuitting); 266 267 268 269 /****************************** 270 * Runtime Functionality * 271 ******************************/ 272 273 /** 274 * Does all achievement-related processing for a single frame. 275 */ 276 extern void RA_DoAchievementsFrame(void); 277 278 /** 279 * Temporarily disables forced updating of tool windows. 280 * 281 * Primarily used while fast-forwarding. 282 */ 283 extern void RA_SuspendRepaint(void); 284 285 /** 286 * Resumes forced updating of tool windows. 287 */ 288 extern void RA_ResumeRepaint(void); 289 290 /** 291 * [deprecated] Used to be used to ensure the asynchronous server calls are processed on the UI thread. 292 * That's all managed within the DLL now. Calling this function does nothing. 293 */ 294 extern void RA_HandleHTTPResults(void); 295 296 /** 297 * Adds flavor text to the application title bar. 298 * 299 * Application title bar is managed by the DLL. Value will be "ClientName - Version - Flavor Text - Username" 300 * 301 * @param sCustomMessage the flavor text to include in the title bar. 302 */ 303 extern void RA_UpdateAppTitle(const char* sCustomMessage); 304 305 /** 306 * Get the user name of the currently logged in user. 307 * 308 * @return user name of the currently logged in user, empty if no user is logged in. 309 */ 310 const char* RA_UserName(void); 311 312 /** 313 * Determines if the user is currently playing with hardcore enabled. 314 * 315 * The client should disable any features that would give the player an unfair advantage if this returns non-zero. 316 * Things like loading states, using cheats, modifying RAM, disabling rendering layers, viewing decoded tilemaps, etc. 317 * 318 * @return non-zero if hardcore mode is currently active. 319 */ 320 extern int RA_HardcoreModeIsActive(void); 321 322 /** 323 * Warns the user they're about to do something that will disable hardcore mode. 324 * 325 * @param sActivity what the user is about to do (i.e. "load a state"). 326 * @return non-zero if the user disabled hardcore and the activity is allowed. 327 * zero if the user declined to disable hardcore and the activity should be aborted. 328 */ 329 extern int RA_WarnDisableHardcore(const char* sActivity); 330 331 /** 332 * Disables hardcore mode without prompting or notifying the user. 333 * 334 * Should only be called if the client does its own prompting/notification. 335 * Typically used when an activity cannot be aborted. 336 */ 337 extern void RA_DisableHardcore(void); 338 339 /** 340 * Notifies the DLL that the game has been reset. 341 * 342 * Disables active leaderboards and resets hit counts on all active achievements. 343 */ 344 extern void RA_OnReset(void); 345 346 /** 347 * Notifies the DLL that a save state has been created. 348 * 349 * Creates a .rap file next to the state file that contains achievement-related information for the save state. 350 * 351 * @param sFilename full path to the save state file. 352 */ 353 extern void RA_OnSaveState(const char* sFilename); 354 355 /** 356 * Notifies the DLL that a save state has been loaded. 357 * 358 * Loads the .rap file next to the state file that contains achievement-related information for the save state being loaded. 359 * 360 * @param sFilename full path to the save state file. 361 */ 362 extern void RA_OnLoadState(const char* sFilename); 363 364 /** 365 * Captures the current state of the achievement runtime for inclusion in a save state. 366 * 367 * @param pBuffer buffer to write achievement state information to 368 * @param nBufferSize the size of the buffer 369 * @return the number of bytes needed to capture the achievement state. if less than nBufferSize, pBuffer 370 * will not be populated. the function should be called again with a larger buffer. 371 */ 372 extern int RA_CaptureState(char* pBuffer, int nBufferSize); 373 374 /** 375 * Restores the state of the achievement runtime from a previously captured state. 376 * 377 * @param pBuffer buffer containing previously serialized achievement state information 378 */ 379 extern void RA_RestoreState(const char* pBuffer); 380 381 382 #ifdef __cplusplus 383 } /* extern "C" */ 384 #endif 385 386 #endif // !RA_INTERFACE_H