Skip to content

Commit 8daf15a

Browse files
authored
Merge branch 'master' into Restored_behavior_of_.__filepath_prefix_in_legacy_compat_modes_
2 parents 520a374 + e5d0b2e commit 8daf15a

13 files changed

Lines changed: 404 additions & 101 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
## 5.0.1
2+
- cleo.log file moved back to the game root (as in CLEO4)
23
- Restored behavior of '.\\' prefix for scripts in legacy compat mode
4+
- fixed **0AB9 ([get_audio_stream_state](https://library.sannybuilder.com/#/sa/audio/0AB9))** not always returning Stopped, despite playback ended
5+
- fixed **2507 ([get_audio_stream_progress](https://library.sannybuilder.com/#/sa/audio/2507))** sometimes returning values smaller than 1.0, despite playback ended
6+
- fixed progress set with **2508 ([set_audio_stream_progress](https://library.sannybuilder.com/#/sa/audio/2508))** being ignored by stopped streams
37

48
## 5.0.0
5-
69
- support for CLEO modules feature https://github.com/sannybuilder/dev/issues/264
710
- new [Audio](https://github.com/cleolibrary/CLEO5/tree/master/cleo_plugins/Audio) plugin
811
- audio related opcodes moved from CLEO core into separated plugin
@@ -106,8 +109,7 @@
106109
- some errors now cause the script to pause, instead of crashing the game
107110
- updated included Silent's ASI Loader to version 1.3
108111

109-
### Bug Fixes
110-
112+
#### Bug Fixes
111113
- fixed error in **004E (terminate_this_script)** allowing to run multiple missions
112114
- fixed handling of strings longer than 128 characters causing errors in some cases
113115
- fixed error in handling of first string argument in **0AF5 (write_string to_ini_file)**
@@ -117,8 +119,7 @@
117119
- fixed invalid 7 characters length limit of **0AAA (get_script_struct_named)**
118120
- fixed an undefined behavior caused by **0459 (terminate_all_scripts_with_this_name)** when the name matches a custom script
119121

120-
#### SDK AND PLUGINS
121-
122+
#### SDK and plugins
122123
- now all opcodes in range **0-7FFF** can be registered by plugins
123124
- plugins moved to _cleo\cleo_plugins_ directory
124125
- new SDK methods:
@@ -154,19 +155,17 @@
154155
- CLEO_Log
155156

156157
#### CLEO internal
157-
158158
- introduced unit test scripts
159159
- project migrated to VS 2022
160160
- configured game debugging settings
161161
- plugins moved into single solution
162162
- configured automatic releases on GitHub
163163
- added setup_env.bat script
164164

165-
#### Special Thanks
166-
167-
- **123nir** for the alpha-testing, troubleshooting and valuable bug reports
168-
- **Hamal** for the beta-testing, troubleshooting and valuable bug reports
169-
170165
## Older
171-
172166
For previous changes, see [CLEO4 changelog](https://github.com/cleolibrary/CLEO4/blob/master/CHANGELOG.md)
167+
168+
## Special Thanks
169+
- **123nir** for the v5.0.0-alpha testing, troubleshooting and valuable bug reports
170+
- **Hamal** for the v5.0.0-beta testing, troubleshooting and valuable bug reports
171+

README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,27 @@ Follow the instructions on the [release page](https://github.com/cleolibrary/CLE
1010

1111
The ASI Loader replaces one original game file: `vorbisFile.dll` - be sure to make a backup of this file.
1212
CLEO itself does not replace any game file, however the following files and folders are added:
13-
14-
- cleo\ (CLEO script directory)
15-
- cleo\\.cleo.log (main log file)
16-
- cleo\\.config\sa.json (opcodes info file)
17-
- cleo\cleo_plugins\SA.Audio.cleo (audio playback utilities powered by BASS.dll library)
18-
- cleo\cleo_plugins\SA.DebugUtils.cleo (script debugging utilities plugin)
19-
- cleo\cleo_plugins\SA.FileSystemOperations.cleo (disk drive files related operations plugin)
20-
- cleo\cleo_plugins\SA.IniFiles.cleo (.ini config files handling plugin)
21-
- cleo\cleo_plugins\SA.Math.cleo (additional math operations plugin)
22-
- cleo\cleo_plugins\SA.MemoryOperations.cleo (memory and .dll libraries utilities plugin)
23-
- cleo\cleo_plugins\SA.Text.cleo (text processing plugin)
24-
- cleo\cleo_saves\ (CLEO save directory)
25-
- cleo\cleo_text\ (CLEO text directory)
2613
- cleo.asi (core library)
14+
- cleo.log (main log file)
2715
- bass.dll (audio engine library)
16+
- cleo\\ (CLEO script directory)
17+
- cleo\\.config\\sa.json (opcodes info file)
18+
- cleo\\cleo_plugins\\SA.Audio.cleo (audio playback utilities powered by BASS.dll library)
19+
- cleo\\cleo_plugins\\SA.DebugUtils.cleo (script debugging utilities plugin)
20+
- cleo\\cleo_plugins\\SA.FileSystemOperations.cleo (disk drive files related operations plugin)
21+
- cleo\\cleo_plugins\\SA.IniFiles.cleo (.ini config files handling plugin)
22+
- cleo\\cleo_plugins\\SA.Math.cleo (additional math operations plugin)
23+
- cleo\\cleo_plugins\\SA.MemoryOperations.cleo (memory and .dll libraries utilities plugin)
24+
- cleo\\cleo_plugins\\SA.Text.cleo (text processing plugin)
25+
- cleo\\cleo_saves\\ (CLEO save directory)
26+
- cleo\\cleo_text\\ (CLEO text directory)
2827

2928
All plugins are optional, however they may be required by various CLEO scripts.
3029

3130
## CLEO Scripts
3231

3332
CLEO allows the installation of 'CLEO scripts', which often use the extension '.cs'. These third-party scripts are entirely user-made and are in no way supported by the developers of this library. While CLEO itself should work in a wide range of game installations, individual scripts are known to have their own compatibility restrictions and can not be guaranteed to work.
3433
CLEO scripts can be found on Grand Theft Auto fansites and modding sites such as:
35-
3634
- https://libertycity.net/files/gta-san-andreas/mods/cleo-scripts/
3735
- https://www.gtainside.com/en/sanandreas/mods-322/
3836
- http://hotmist.ddo.jp/cleomod/index.html

cleo_plugins/Audio/CAudioStream.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CAudioStream::CAudioStream(const char* filepath)
1515
return;
1616
}
1717

18-
unsigned flags = BASS_SAMPLE_SOFTWARE;
18+
unsigned flags = BASS_SAMPLE_SOFTWARE | BASS_STREAM_PRESCAN;
1919
if (CSoundSystem::useFloatAudio) flags |= BASS_SAMPLE_FLOAT;
2020

2121
if (!(streamInternal = BASS_StreamCreateFile(FALSE, filepath, 0, 0, flags)) &&
@@ -71,22 +71,27 @@ float CAudioStream::GetLength() const
7171

7272
void CAudioStream::SetProgress(float value)
7373
{
74+
if (GetState() == Stopped)
75+
{
76+
state = Paused; // resume from set progress
77+
}
78+
7479
value = std::clamp(value, 0.0f, 1.0f);
75-
auto total = BASS_ChannelGetLength(streamInternal, BASS_POS_BYTE);
76-
auto bytePos = QWORD(value * total);
80+
auto bytePos = BASS_ChannelSeconds2Bytes(streamInternal, GetLength() * value);
81+
7782
BASS_ChannelSetPosition(streamInternal, bytePos, BASS_POS_BYTE);
7883
}
7984

8085
float CAudioStream::GetProgress() const
8186
{
82-
auto total = BASS_ChannelGetLength(streamInternal, BASS_POS_BYTE); // returns -1 on error
83-
auto bytePos = BASS_ChannelGetPosition(streamInternal, BASS_POS_BYTE); // returns -1 on error
84-
87+
auto bytePos = BASS_ChannelGetPosition(streamInternal, BASS_POS_BYTE);
8588
if (bytePos == -1) bytePos = 0; // error or not available yet
89+
auto pos = BASS_ChannelBytes2Seconds(streamInternal, bytePos);
8690

87-
float progress = (float)bytePos / total;
88-
progress = std::clamp(progress, 0.0f, 1.0f);
89-
return progress;
91+
auto byteTotal = BASS_ChannelGetLength(streamInternal, BASS_POS_BYTE);
92+
auto total = BASS_ChannelBytes2Seconds(streamInternal, byteTotal);
93+
94+
return (float)(pos / total);
9095
}
9196

9297
CAudioStream::eStreamState CAudioStream::GetState() const
@@ -240,10 +245,12 @@ void CAudioStream::Process()
240245
BASS_ChannelPlay(streamInternal, FALSE);
241246
state = Playing;
242247
}
243-
244-
if (!GetLooping() && GetProgress() >= 1.0f) // end reached
248+
else
245249
{
246-
state = Stopped;
250+
if (state == Playing && BASS_ChannelIsActive(streamInternal) == BASS_ACTIVE_STOPPED) // end reached
251+
{
252+
state = Stopped;
253+
}
247254
}
248255

249256
if (state != Playing) return; // done

cleo_plugins/Audio/CAudioStream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace CLEO
77
{
8+
#pragma pack(push,4)
89
class CAudioStream
910
{
1011
public:
@@ -73,4 +74,5 @@ namespace CLEO
7374
void UpdateVolume();
7475
void UpdateSpeed();
7576
};
77+
#pragma pack(pop)
7678
}

cleo_plugins/Audio/SA.Audio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[General]
2-
; Manually select audio device. See `.cleo.log` file to check list of available options. -1 for automatic
2+
; Manually select audio device. See `cleo.log` file to check list of available options. -1 for automatic
33
AudioDevice=-1
44

55
; Allow playing streams from http(s) locations

examples/Color_Blend.txt

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// CLEO5 example script
2+
// Sanny Builder 4
3+
// mode: GTA SA (v1.0 - SBL)
4+
{$CLEO .cs}
5+
6+
script_name {name} 'colgrad'
7+
8+
const Panel_Count = 120 // limit is 128 per script
9+
const Panel_Width = 5.2
10+
11+
int lastPanelIdx = Panel_Count - 1
12+
int middleKeyIdx
13+
int colorStart[3] // red, green, blue
14+
int colormiddle[3] // red, green, blue
15+
int colorEnd[3] // red, green, blue
16+
17+
int iTmp
18+
float fTmp
19+
20+
TimerA = 3000
21+
while true
22+
wait {time} 0
23+
24+
// randomize colors every 3 seconds
25+
if
26+
TimerA > 3000
27+
then
28+
colorStart[0] = generate_random_int_in_range {min} 0x00 {max} 0xFF
29+
colorStart[1] = generate_random_int_in_range {min} 0x00 {max} 0xFF
30+
colorStart[2] = generate_random_int_in_range {min} 0x00 {max} 0xFF
31+
32+
colormiddle[0] = generate_random_int_in_range {min} 0x00 {max} 0xFF
33+
colormiddle[1] = generate_random_int_in_range {min} 0x00 {max} 0xFF
34+
colormiddle[2] = generate_random_int_in_range {min} 0x00 {max} 0xFF
35+
36+
colorEnd[0] = generate_random_int_in_range {min} 0x00 {max} 0xFF
37+
colorEnd[1] = generate_random_int_in_range {min} 0x00 {max} 0xFF
38+
colorEnd[2] = generate_random_int_in_range {min} 0x00 {max} 0xFF
39+
40+
middleKeyIdx = generate_random_int_in_range {min} 0 {max} lastPanelIdx
41+
42+
TimerA = 0
43+
end
44+
45+
// draw on screen
46+
use_text_commands {state} true
47+
48+
float posX = 10.0 // start pos
49+
int i = 0
50+
while i < Panel_Count
51+
// select color
52+
int color[3]
53+
switch i
54+
case 0 // start panel
55+
color[0] = colorStart[0]
56+
color[1] = colorStart[1]
57+
color[2] = colorStart[2]
58+
59+
case middleKeyIdx // middle color
60+
color[0] = colormiddle[0]
61+
color[1] = colormiddle[1]
62+
color[2] = colormiddle[2]
63+
64+
case lastPanelIdx
65+
color[0] = colorEnd[0]
66+
color[1] = colorEnd[1]
67+
color[2] = colorEnd[2]
68+
69+
default // for other panels we have to calculate blend color
70+
float progress
71+
if
72+
i < middleKeyIdx
73+
then
74+
// blending start to middle
75+
progress =# i // current
76+
fTmp =# middleKeyIdx // total
77+
progress /= fTmp // 0.0 - 1.0 range
78+
79+
color[0] = LERP_INT(colorStart[0], colormiddle[0], progress) // red
80+
color[1] = LERP_INT(colorStart[1], colormiddle[1], progress) // green
81+
color[2] = LERP_INT(colorStart[2], colormiddle[2], progress) // blue
82+
else
83+
// blending middle to end
84+
iTmp = i - middleKeyIdx
85+
progress =# iTmp // current
86+
87+
iTmp = lastPanelIdx - middleKeyIdx
88+
fTmp =# iTmp // total
89+
90+
progress /= fTmp // 0.0 - 1.0 range
91+
92+
color[0] = LERP_INT(colormiddle[0], colorEnd[0], progress) // red
93+
color[1] = LERP_INT(colormiddle[1], colorEnd[1], progress) // green
94+
color[2] = LERP_INT(colormiddle[2], colorEnd[2], progress) // blue
95+
end
96+
end
97+
98+
// draw
99+
if or
100+
i == 0 // start panel
101+
i == middleKeyIdx
102+
i == lastPanelIdx
103+
then
104+
draw_rect {pos} posX 240.0 {size} Panel_Width 80.0 {rgb} color[0] color[1] color[2] {alpha} 240 // tall panel
105+
else
106+
draw_rect {pos} posX 240.0 {size} Panel_Width 40.0 {rgb} color[0] color[1] color[2] {alpha} 240 // regular panel
107+
end
108+
109+
// prepare next
110+
i += 1
111+
posX += Panel_Width
112+
end
113+
114+
end
115+
terminate_this_custom_script
116+
117+
118+
// linear interpolation (or extrapolation) of two float values
119+
function LERP_FLOAT(valueA :float, valueB :float, progress :float): float
120+
float invProgress = 1.0
121+
invProgress -= progress
122+
123+
valueA *= invProgress
124+
valueB *= progress
125+
126+
float result
127+
result += valueA
128+
result += valueB
129+
130+
return result
131+
end
132+
133+
134+
// linear interpolation (or extrapolation) of two integer values
135+
function LERP_INT(valueA: int, valueB: int, progress: float): int
136+
float aF =# valueA // to float
137+
float bF =# valueB // to float
138+
139+
float fResult = LERP_FLOAT(aF, bF, progress)
140+
141+
int result =# fResult // to integer
142+
143+
return result
144+
end

examples/Pickup_Shirt.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// CLEO5 example script
12
// Sanny Builder 4
23
// mode: GTA SA (v1.0 - SBL)
34

source/stdafx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ inline const std::string Filepath_Game = GetGameDirectory();
5858
inline const std::string Filepath_User = GetUserDirectory();
5959
inline const std::string Filepath_Cleo = Filepath_Game + "\\cleo";
6060
inline const std::string Filepath_Config = Filepath_Cleo + "\\.cleo_config.ini";
61-
inline const std::string Filepath_Log = Filepath_Cleo + "\\.cleo.log";
61+
inline const std::string Filepath_Log = Filepath_Game + "\\cleo.log";
6262

6363
#define NUM_SCAN_ENTITIES 16
6464

tests/.cleo_tests_runner.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ clear_prints
1313

1414
RUN_TESTS_DIR("cleo:", "cleo_tests")
1515

16+
trace ""
17+
trace "All tests done"
1618
print_big_string {text} "DONE" {time} 5000 {style} TextStyle.MiddleSmaller
1719

1820
terminate_this_custom_script

0 commit comments

Comments
 (0)