forwarding build fix when MUIA_Scrollgroup_AutoBars is defined (NicJA).
[AROS-Contrib.git] / scalos / main / Patches-classic.c
blob4dc9255aa375f8503fc682889e0d2f4ef6a13814
1 // Patches-classic.c
2 // $Date$
3 // $Revision$
6 #include <exec/types.h>
7 #include <graphics/rastport.h>
8 #include <utility/hooks.h>
9 #include <intuition/gadgetclass.h>
10 #include <workbench/workbench.h>
11 #include <workbench/startup.h>
12 #include <workbench/icon.h>
13 #include <libraries/gadtools.h>
14 #include <libraries/iffparse.h>
15 #include <datatypes/pictureclass.h>
16 #include <dos/dostags.h>
17 #include <guigfx/guigfx.h>
19 #define __USE_SYSBASE
21 #include <proto/dos.h>
22 #include <proto/exec.h>
23 #include <proto/layers.h>
24 #include <proto/intuition.h>
25 #include <proto/graphics.h>
26 #include <proto/utility.h>
27 #include <proto/icon.h>
28 #include <proto/iconobject.h>
29 #include <proto/guigfx.h>
30 #include <proto/datatypes.h>
31 #include <proto/gadtools.h>
32 #include "debug.h"
33 #include <proto/scalos.h>
35 #include <clib/alib_protos.h>
37 #include <defs.h>
38 #include <datatypes/iconobject.h>
39 #include <scalos/palette.h>
40 #include <scalos/pattern.h>
41 #include <scalos/scalos.h>
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <string.h>
47 #include "scalos_structures.h"
48 #include "functions.h"
49 #include "Variables.h"
50 #include "Patches.h"
52 //----------------------------------------------------------------------------
54 // local data structures
56 #if defined(__MORPHOS__)
57 #define PPATCHFUNC(x) { TRAP_LIB, 0, (APTR) x }
58 #define PPATCH_NEWFUNC(ple) (APTR) &ple->pe_EmulEntry
59 #else
60 #define PPATCHFUNC(x) (APTR) x
61 #define PPATCH_NEWFUNC(ple) ple->pe_NewFunction
62 #endif
64 struct PatchEntry
66 struct Library **pe_Library;
67 ULONG pe_MinVersion;
68 LONG pe_LibOffset;
69 #ifdef __MORPHOS__
70 struct EmulLibEntry pe_EmulEntry;
71 #else
72 APTR pe_NewFunction;
73 #endif
74 APTR *pe_OldFunction;
77 //----------------------------------------------------------------------------
79 // local functions
81 static void SetPatches(const struct PatchEntry *PatchList);
82 static BOOL RemovePatches(const struct PatchEntry *PatchList);
84 //----------------------------------------------------------------------------
86 // public data items
88 //----------------------------------------------------------------------------
90 // local data items
92 //----------------------------------------------------------------------------
94 #define LVOCloseWorkBench -13 * LIB_VECTSIZE
95 #define LVOOpenWorkBench -35 * LIB_VECTSIZE
96 #define LVOOpenScreenTagList -102 * LIB_VECTSIZE
97 #define LVOOpenWindowTagList -101 * LIB_VECTSIZE
99 #define LVOUpdateWorkbench -5 * LIB_VECTSIZE /* private1 */
100 #define LVOwbPrivate2 -6 * LIB_VECTSIZE
101 #define LVOAddAppWindowA -8 * LIB_VECTSIZE
102 #define LVORemoveAppWindow -9 * LIB_VECTSIZE
103 #define LVOAddAppIconA -10 * LIB_VECTSIZE
104 #define LVORemoveAppIcon -11 * LIB_VECTSIZE
105 #define LVOAddAppMenuItemA -12 * LIB_VECTSIZE
106 #define LVORemoveAppMenuItem -13 * LIB_VECTSIZE
107 #define LVOSetBackFill -14 * LIB_VECTSIZE
108 #define LVOWBInfo -15 * LIB_VECTSIZE
110 #define LVOPutDiskObject -14 * LIB_VECTSIZE
111 #define LVODeleteDiskObject -23 * LIB_VECTSIZE
112 #define LVOPutIconTagList -31 * LIB_VECTSIZE
114 #define LVODeleteFile -12 * LIB_VECTSIZE
115 #define LVORename -13 * LIB_VECTSIZE
116 #define LVOOpen -5 * LIB_VECTSIZE
117 #define LVOClose -6 * LIB_VECTSIZE
118 #define LVOCreateDir -20 * LIB_VECTSIZE
120 //----------------------------------------------------------------------------
122 static const struct PatchEntry EmulationPatches[] =
124 #ifdef TEST_OPENWINDOWTAGLIST
125 { (struct Library **) &IntuitionBase, 39, LVOOpenWindowTagList, PPATCHFUNC(sca_OpenWindowTagList), (APTR) &OldOpenWindowTagList },
126 #endif /* TEST_OPENWINDOWTAGLIST */
127 { (struct Library **) &IntuitionBase, 39, LVOCloseWorkBench, PPATCHFUNC(sca_CloseWorkBench), (APTR) &OldCloseWB },
128 { (struct Library **) &IntuitionBase, 39, LVOOpenWorkBench, PPATCHFUNC(sca_OpenWorkBench), (APTR) &OldOpenWB },
129 { (struct Library **) &IntuitionBase, 39, LVOOpenScreenTagList, PPATCHFUNC(sca_OpenScreenTagList), (APTR) &OldOpenScreenTagList },
130 { (struct Library **) &WorkbenchBase, 39, LVOAddAppIconA, PPATCHFUNC(sca_AddAppIconA), (APTR) &OldAddAppIconA },
131 { (struct Library **) &WorkbenchBase, 39, LVORemoveAppIcon, PPATCHFUNC(sca_RemoveAppIcon), (APTR) &OldRemoveAppIcon },
132 { (struct Library **) &WorkbenchBase, 39, LVOAddAppWindowA, PPATCHFUNC(sca_AddAppWindowA), (APTR) &OldAddAppWindowA },
133 { (struct Library **) &WorkbenchBase, 39, LVORemoveAppWindow, PPATCHFUNC(sca_RemoveAppWindow), (APTR) &OldRemoveAppWindow },
134 { (struct Library **) &WorkbenchBase, 39, LVOAddAppMenuItemA, PPATCHFUNC(sca_AddAppMenuItemA), (APTR) &OldAppAppMenuItemA },
135 { (struct Library **) &WorkbenchBase, 39, LVORemoveAppMenuItem, PPATCHFUNC(sca_RemoveAppMenuItem), (APTR) &OldRemoveAppMenuItem },
136 // { (struct Library **) &WorkbenchBase, 39, LVOwbPrivate2, PPATCHFUNC(sca_GetLocString), (APTR) &OldwbPrivate2 },
137 { NULL, 0, 0, PPATCHFUNC(NULL), NULL },
139 static const struct PatchEntry StandardPatches[] =
141 { (struct Library **) &IconBase, 39, LVOPutDiskObject, PPATCHFUNC(sca_PutDiskObject), (APTR) &OldPutDiskObject },
142 { (struct Library **) &IconBase, 39, LVODeleteDiskObject, PPATCHFUNC(sca_DeleteDiskObject), (APTR) &OldDeleteDiskObject },
143 { (struct Library **) &IconBase, 44, LVOPutIconTagList, PPATCHFUNC(sca_PutIconTagList), (APTR) &OldPutIconTagList},
145 { (struct Library **) &DOSBase, 39, LVODeleteFile, PPATCHFUNC(sca_DeleteFile), (APTR) &OldDeleteFile },
146 { (struct Library **) &DOSBase, 39, LVORename, PPATCHFUNC(sca_Rename), (APTR) &OldRename },
147 { (struct Library **) &DOSBase, 39, LVOCreateDir, PPATCHFUNC(sca_CreateDir), (APTR) &OldCreateDir },
148 { (struct Library **) &DOSBase, 39, LVOOpen, PPATCHFUNC(sca_Open), (APTR) &OldOpen },
149 { (struct Library **) &DOSBase, 39, LVOClose, PPATCHFUNC(sca_Close), (APTR) &OldClose },
150 { NULL, 0, 0, PPATCHFUNC(NULL), NULL },
152 static const struct PatchEntry HardEmulationPatches[] =
154 { (struct Library **) &WorkbenchBase, 39, LVOUpdateWorkbench, PPATCHFUNC(sca_UpdateWorkbench), (APTR) &OldUpdateWorkbench },
155 { (struct Library **) &WorkbenchBase, 39, LVOSetBackFill, PPATCHFUNC(sca_SetBackFill), (APTR) &OldSetBackFill },
156 { (struct Library **) &WorkbenchBase, 39, LVOWBInfo, PPATCHFUNC(sca_WBInfo), (APTR) &OldWBInfo },
157 { NULL, 0, 0, PPATCHFUNC(NULL), NULL },
160 //----------------------------------------------------------------------------
162 void SetAllPatches(struct MainTask *mt)
164 PatchInit();
166 SetPatches(StandardPatches);
168 if (mt->emulation)
170 if (CurrentPrefs.pref_HardEmulation)
171 SetPatches(HardEmulationPatches);
173 SetPatches(EmulationPatches);
179 ULONG RemoveAllPatches(struct MainTask *mt)
181 if (!RemovePatches(StandardPatches))
182 return FALSE;
184 if (mt->emulation)
186 if (!RemovePatches(EmulationPatches))
188 SetPatches(StandardPatches);
189 return FALSE;
192 if (CurrentPrefs.pref_HardEmulation)
194 if (!RemovePatches(HardEmulationPatches))
196 SetPatches(EmulationPatches);
197 SetPatches(StandardPatches);
203 PatchCleanup();
205 return TRUE;
209 static void SetPatches(const struct PatchEntry *PatchList)
211 Forbid();
213 d1(KPrintF("%s/%s/%ld: PatchList=%08lx\n", __FILE__, __FUNC__, __LINE__, PatchList));
215 while (PatchList->pe_Library)
217 if (NULL == *PatchList->pe_OldFunction
218 && (*PatchList->pe_Library)->lib_Version >= PatchList->pe_MinVersion)
220 *PatchList->pe_OldFunction = SetFunction(*PatchList->pe_Library,
221 PatchList->pe_LibOffset, PPATCH_NEWFUNC(PatchList));
223 d1(KPrintF("%s/%s/%ld: Library=%08lx LVO=%ld NewFunc=%08lx OldFunc=%08lx\n", \
224 __FILE__, __FUNC__, __LINE__, *PatchList->pe_Library, \
225 PatchList->pe_LibOffset, PPATCH_NEWFUNC(PatchList), \
226 *PatchList->pe_OldFunction));
229 PatchList++;
232 // CacheClearU();
233 Permit();
237 static BOOL RemovePatches(const struct PatchEntry *PatchList)
239 const struct PatchEntry *pl = PatchList;
240 BOOL Success = TRUE;
242 d1(KPrintF("%s/%s/%ld: PatchList=%08lx\n", __FILE__, __FUNC__, __LINE__, PatchList));
244 Forbid();
246 while (pl->pe_Library)
248 if (pl->pe_OldFunction)
250 APTR patchedFunction;
252 patchedFunction = SetFunction(*pl->pe_Library,
253 pl->pe_LibOffset, *pl->pe_OldFunction);
254 *pl->pe_OldFunction = NULL;
256 d1(KPrintF("%s/%s/%ld: Library=%08lx LVO=%ld NewFunc=%08lx patchedFunc=%08lx\n", \
257 __FILE__, __FUNC__, __LINE__, *PatchList->pe_Library, \
258 PatchList->pe_LibOffset, PPATCH_NEWFUNC(pl), patchedFunction));
259 #if !defined(__MORPHOS__)
260 if (patchedFunction != PPATCH_NEWFUNC(pl))
262 *pl->pe_OldFunction = SetFunction(*pl->pe_Library,
263 pl->pe_LibOffset, patchedFunction);
265 Success = FALSE;
267 #endif /* __MORPHOS__ */
270 pl++;
273 // CacheClearU();
274 Permit();
276 d1(KPrintF("%s/%s/%ld: Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
278 if (!Success)
279 SetPatches(PatchList);
281 return Success;